From b3598665cc2628e82764f339a11d42970ea28b6e Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 29 Mar 2024 23:43:30 +0500 Subject: [PATCH] Delete unused FixedContentsUsingArrayByteLiteral trait Its usage was removed in 3fcc700017d4add59724338230604977952dbaec Need to delete method `ensureFixedContents` from runtime libraries as no longer used --- .../struct/languages/CSharpCompiler.scala | 4 ---- .../kaitai/struct/languages/CppCompiler.scala | 4 ---- .../kaitai/struct/languages/GoCompiler.scala | 19 ----------------- .../struct/languages/JavaCompiler.scala | 5 ----- .../struct/languages/JavaScriptCompiler.scala | 8 +------ .../kaitai/struct/languages/LuaCompiler.scala | 4 ---- .../kaitai/struct/languages/NimCompiler.scala | 5 ----- .../kaitai/struct/languages/PHPCompiler.scala | 4 ---- .../struct/languages/PerlCompiler.scala | 5 ----- .../struct/languages/PythonCompiler.scala | 4 ---- .../struct/languages/RubyCompiler.scala | 4 ---- .../struct/languages/RustCompiler.scala | 4 ---- .../FixedContentsUsingArrayByteLiteral.scala | 21 ------------------- .../components/LanguageCompiler.scala | 3 --- 14 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 shared/src/main/scala/io/kaitai/struct/languages/components/FixedContentsUsingArrayByteLiteral.scala diff --git a/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala index ecc8c0795..927b69652 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala @@ -17,7 +17,6 @@ class CSharpCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with AllocateIOLocalVar with EveryReadIsExpression with UniversalDoc - with FixedContentsUsingArrayByteLiteral with SwitchIfOps with NoNeedForFullClassPath { import CSharpCompiler._ @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala index 882c476c8..63ee25346 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala @@ -16,7 +16,6 @@ class CppCompiler( ) extends LanguageCompiler(typeProvider, config) with ObjectOrientedLanguage with AllocateAndStoreIO - with FixedContentsUsingArrayByteLiteral with UniversalDoc with SwitchIfOps with EveryReadIsExpression { @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala index 9829a0435..af8d8e6a6 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/GoCompiler.scala @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala index 6b05e034e..4ea6dc4b3 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala @@ -18,7 +18,6 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with UniversalFooter with UniversalDoc with AllocateIOLocalVar - with FixedContentsUsingArrayByteLiteral with SwitchIfOps with NoNeedForFullClassPath { import JavaCompiler._ @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala index 6d397f268..dc6a99544 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -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) @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala index 1093caf1b..c65255a0d 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala @@ -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 @@ -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 diff --git a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala index b5ac4366b..232c31efc 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala @@ -13,7 +13,6 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with SingleOutputFile with EveryReadIsExpression with UpperCamelCaseClasses - with FixedContentsUsingArrayByteLiteral with UniversalFooter with AllocateIOLocalVar with SwitchIfOps @@ -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 diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala index d3f11a74a..67e0137e3 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala @@ -16,7 +16,6 @@ class PHPCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with AllocateIOLocalVar with UniversalFooter with UniversalDoc - with FixedContentsUsingArrayByteLiteral with EveryReadIsExpression { import PHPCompiler._ @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala index 041c75cea..97a009b8b 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala @@ -16,7 +16,6 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with UniversalFooter with UpperCamelCaseClasses with AllocateIOLocalVar - with FixedContentsUsingArrayByteLiteral with SwitchIfOps with EveryReadIsExpression { @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala index 18b5d1299..f27ded894 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala @@ -17,7 +17,6 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with UniversalFooter with EveryReadIsExpression with AllocateIOLocalVar - with FixedContentsUsingArrayByteLiteral with UniversalDoc with SwitchIfOps with NoNeedForFullClassPath { @@ -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 diff --git a/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala index 28573e8ff..469d427ee 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala @@ -18,7 +18,6 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with UpperCamelCaseClasses with AllocateIOLocalVar with EveryReadIsExpression - with FixedContentsUsingArrayByteLiteral with NoNeedForFullClassPath { import RubyCompiler._ @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala index 17be18991..1b6d7741a 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala @@ -16,7 +16,6 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) with AllocateIOLocalVar with UniversalFooter with UniversalDoc - with FixedContentsUsingArrayByteLiteral with EveryReadIsExpression { import RustCompiler._ @@ -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) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/components/FixedContentsUsingArrayByteLiteral.scala b/shared/src/main/scala/io/kaitai/struct/languages/components/FixedContentsUsingArrayByteLiteral.scala deleted file mode 100644 index c5d4abd9b..000000000 --- a/shared/src/main/scala/io/kaitai/struct/languages/components/FixedContentsUsingArrayByteLiteral.scala +++ /dev/null @@ -1,21 +0,0 @@ -package io.kaitai.struct.languages.components - -import io.kaitai.struct.exprlang.Ast -import io.kaitai.struct.format.Identifier - -/** - * Allows uniform implementation of attrFixedContentsParse by enforcing usage - * of doByteArrayLiteral in relevant language's translator. - */ -trait FixedContentsUsingArrayByteLiteral extends LanguageCompiler { - def attrFixedContentsParse(attrName: Identifier, contents: Array[Byte]) = - attrFixedContentsParse( - attrName, - translator.translate( - Ast.expr.List( - contents.map(x => Ast.expr.IntNum(BigInt(x & 0xff))) - ) - ) - ) - def attrFixedContentsParse(attrName: Identifier, contents: String): Unit -} diff --git a/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala index 9beb9f707..4877b5db9 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala @@ -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