Skip to content

Commit

Permalink
Delete unused FixedContentsUsingArrayByteLiteral trait
Browse files Browse the repository at this point in the history
Its usage was removed in 3fcc700

Need to delete method `ensureFixedContents` from runtime libraries as no longer used
  • Loading branch information
Mingun committed Jul 16, 2024
1 parent 54524e1 commit b359866
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CSharpCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with AllocateIOLocalVar
with EveryReadIsExpression
with UniversalDoc
with FixedContentsUsingArrayByteLiteral
with SwitchIfOps
with NoNeedForFullClassPath {
import CSharpCompiler._
Expand Down Expand Up @@ -193,9 +192,6 @@ class CSharpCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = $normalIO.EnsureFixedContents($contents);")

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class CppCompiler(
) extends LanguageCompiler(typeProvider, config)
with ObjectOrientedLanguage
with AllocateAndStoreIO
with FixedContentsUsingArrayByteLiteral
with UniversalDoc
with SwitchIfOps
with EveryReadIsExpression {
Expand Down Expand Up @@ -442,9 +441,6 @@ class CppCompiler(
outSrc.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
outSrc.puts(s"${privateMemberName(attrName)} = $normalIO->ensure_fixed_contents($contents);")

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
19 changes: 0 additions & 19 deletions shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,6 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: Array[Byte]): Unit = {
out.puts(s"${privateMemberName(attrName)}, err = $normalIO.ReadBytes(${contents.length})")

out.puts(s"if err != nil {")
out.inc
out.puts("return err")
out.dec
out.puts("}")

importList.add("bytes")
importList.add("errors")
val expected = translator.resToStr(translator.doByteArrayLiteral(contents))
out.puts(s"if !bytes.Equal(${privateMemberName(attrName)}, $expected) {")
out.inc
out.puts("return errors.New(\"Unexpected fixed contents\")")
out.dec
out.puts("}")
}

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with UniversalFooter
with UniversalDoc
with AllocateIOLocalVar
with FixedContentsUsingArrayByteLiteral
with SwitchIfOps
with NoNeedForFullClassPath {
import JavaCompiler._
Expand Down Expand Up @@ -233,10 +232,6 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit = {
out.puts(s"${privateMemberName(attrName)} = $normalIO.ensureFixedContents($contents);")
}

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with UniversalDoc
with AllocateIOLocalVar
with EveryReadIsExpression
with SwitchIfOps
with FixedContentsUsingArrayByteLiteral {
with SwitchIfOps {
import JavaScriptCompiler._

override val translator = new JavaScriptTranslator(typeProvider, importList)
Expand Down Expand Up @@ -189,11 +188,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit = {
out.puts(s"${privateMemberName(attrName)} = " +
s"$normalIO.ensureFixedContents($contents);")
}

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
extends LanguageCompiler(typeProvider, config)
with AllocateIOLocalVar
with EveryReadIsExpression
with FixedContentsUsingArrayByteLiteral
with ObjectOrientedLanguage
with SingleOutputFile
with UniversalDoc
Expand Down Expand Up @@ -154,9 +153,6 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("end")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = self._io:ensure_fixed_contents($contents)")

override def condIfHeader(expr: Ast.expr): Unit = {
out.puts(s"if ${expression(expr)} then")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with SingleOutputFile
with EveryReadIsExpression
with UpperCamelCaseClasses
with FixedContentsUsingArrayByteLiteral
with UniversalFooter
with AllocateIOLocalVar
with SwitchIfOps
Expand Down Expand Up @@ -83,10 +82,6 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)

// Members declared in io.kaitai.struct.languages.components.LanguageCompiler
override def alignToByte(io: String): Unit = out.puts(s"alignToByte($io)")
override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit = {
out.puts(s"this.${idToStr(attrName)} = $normalIO.ensureFixedContents($contents)")
}
// def attrParse(attr: AttrLikeSpec, id: Identifier, defEndian: Option[Endianness]): Unit = ???
override def attrParseHybrid(leProc: () => Unit, beProc: () => Unit): Unit = {
out.puts("if this.isLe:")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class PHPCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with AllocateIOLocalVar
with UniversalFooter
with UniversalDoc
with FixedContentsUsingArrayByteLiteral
with EveryReadIsExpression {

import PHPCompiler._
Expand Down Expand Up @@ -203,9 +202,6 @@ class PHPCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = $normalIO->ensureFixedContents($contents);")

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with UniversalFooter
with UpperCamelCaseClasses
with AllocateIOLocalVar
with FixedContentsUsingArrayByteLiteral
with SwitchIfOps
with EveryReadIsExpression {

Expand Down Expand Up @@ -170,10 +169,6 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit = {
out.puts(s"${privateMemberName(attrName)} = $normalIO->ensure_fixed_contents($contents);")
}

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with UniversalFooter
with EveryReadIsExpression
with AllocateIOLocalVar
with FixedContentsUsingArrayByteLiteral
with UniversalDoc
with SwitchIfOps
with NoNeedForFullClassPath {
Expand Down Expand Up @@ -175,9 +174,6 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.putsLines("", "\"\"\"" + docStr + refStr + "\"\"\"")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = self._io.ensure_fixed_contents($contents)")

override def attrParseHybrid(leProc: () => Unit, beProc: () => Unit): Unit = {
out.puts("if self._is_le:")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with UpperCamelCaseClasses
with AllocateIOLocalVar
with EveryReadIsExpression
with FixedContentsUsingArrayByteLiteral
with NoNeedForFullClassPath {

import RubyCompiler._
Expand Down Expand Up @@ -202,9 +201,6 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("end")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = $normalIO.ensure_fixed_contents($contents)")

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
with AllocateIOLocalVar
with UniversalFooter
with UniversalDoc
with FixedContentsUsingArrayByteLiteral
with EveryReadIsExpression {

import RustCompiler._
Expand Down Expand Up @@ -170,9 +169,6 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("}")
}

override def attrFixedContentsParse(attrName: Identifier, contents: String): Unit =
out.puts(s"${privateMemberName(attrName)} = $normalIO.ensureFixedContents($contents);")

override def attrProcess(proc: ProcessExpr, varSrc: Identifier, varDest: Identifier, rep: RepeatSpec): Unit = {
val srcExpr = getRawIdExpr(varSrc, rep)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ abstract class LanguageCompiler(
def attrInit(attr: AttrLikeSpec): Unit = {}
def attrDestructor(attr: AttrLikeSpec, id: Identifier): Unit = {}

// TODO: delete
def attrFixedContentsParse(attrName: Identifier, contents: Array[Byte]): Unit

def condIfSetNull(instName: Identifier): Unit = {}
def condIfSetNonNull(instName: Identifier): Unit = {}
def condIfHeader(expr: Ast.expr): Unit
Expand Down

0 comments on commit b359866

Please sign in to comment.