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 c7dcc0a13..09be52792 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala @@ -912,7 +912,7 @@ class CppCompiler( outSrc.puts(s"return ${nonOwningPointer(instName, attrType)};") override def instanceCalculate(instName: Identifier, dataType: DataType, value: Ast.expr): Unit = { - if (config.readStoresPos) + if (attrDebugNeeded(instName)) attrDebugStart(instName, dataType, None, NoRepeat) val valExpr = expression(value) val isOwningInExpr = dataType match { 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 585475fa7..3a5faac8a 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala @@ -308,10 +308,7 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = { ios.foreach { (io) => - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts("_attrStart.put(\"" + name + "\", " + io + ".pos());") @@ -322,10 +319,7 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) } override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = { - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts("_attrEnd.put(\"" + name + "\", " + io + ".pos());") 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 cf7cbaf0c..b3286138a 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -260,9 +260,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts(s"$io.alignToByte();") override def attrDebugStart(attrId: Identifier, attrType: DataType, io: Option[String], rep: RepeatSpec): Unit = { - if (!attrDebugNeeded(attrId)) - return - val debugName = attrDebugName(attrId, rep, false) val ioProps = io match { @@ -279,8 +276,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) } override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = { - if (!attrDebugNeeded(attrId)) - return val debugName = attrDebugName(attrId, rep, true) out.puts(s"$debugName.end = $io.pos;") @@ -580,12 +575,6 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts("}") } - private - def attrDebugNeeded(attrId: Identifier) = attrId match { - case _: NamedIdentifier | _: NumberedIdentifier | _: InstanceIdentifier => true - case _: RawIdentifier | _: SpecialIdentifier => false - } - def attrDebugName(attrId: Identifier, rep: RepeatSpec, end: Boolean) = { val arrIndexExpr = rep match { case NoRepeat => "" 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 2d5c1044b..6bb20f03a 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala @@ -271,10 +271,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = { ios.foreach { (io) => - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts(s"self._debug['$name']['start'] = $io.pos()") @@ -291,10 +288,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) } override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = { - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts(s"self._debug['$name']['end'] = $io.pos()") 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 25f957d61..ac2736270 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/RubyCompiler.scala @@ -243,10 +243,7 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) override def attrDebugStart(attrId: Identifier, attrType: DataType, ios: Option[String], rep: RepeatSpec): Unit = { ios.foreach { (io) => - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts(s"(@_debug['$name'] ||= {})[:start] = $io.pos") @@ -259,10 +256,7 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) } override def attrDebugEnd(attrId: Identifier, attrType: DataType, io: String, rep: RepeatSpec): Unit = { - val name = attrId match { - case _: RawIdentifier | _: SpecialIdentifier => return - case _ => idToStr(attrId) - } + val name = idToStr(attrId) rep match { case NoRepeat => out.puts(s"(@_debug['$name'] ||= {})[:end] = $io.pos") diff --git a/shared/src/main/scala/io/kaitai/struct/languages/components/CommonReads.scala b/shared/src/main/scala/io/kaitai/struct/languages/components/CommonReads.scala index 899585e67..04893b030 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/components/CommonReads.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/components/CommonReads.scala @@ -26,7 +26,7 @@ trait CommonReads extends LanguageCompiler { normalIO } - if (config.readStoresPos) + if (attrDebugNeeded(id)) attrDebugStart(id, attr.dataType, Some(io), NoRepeat) defEndian match { @@ -107,9 +107,11 @@ trait CommonReads extends LanguageCompiler { } } - def attrDebugStart(attrName: Identifier, attrType: DataType, io: Option[String], repeat: RepeatSpec): Unit = {} + def attrDebugStart(attrId: Identifier, attrType: DataType, io: Option[String], repeat: RepeatSpec): Unit = {} def attrDebugEnd(attrName: Identifier, attrType: DataType, io: String, repeat: RepeatSpec): Unit = {} + def attrDebugNeeded(attrId: Identifier): Boolean = false + /** * Runs all validation procedures requested for an attribute. * @param attr attribute to run validations for diff --git a/shared/src/main/scala/io/kaitai/struct/languages/components/EveryReadIsExpression.scala b/shared/src/main/scala/io/kaitai/struct/languages/components/EveryReadIsExpression.scala index 5259812b4..1bc427c6f 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/components/EveryReadIsExpression.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/components/EveryReadIsExpression.scala @@ -31,8 +31,9 @@ trait EveryReadIsExpression assignTypeOpt: Option[DataType] = None ): Unit = { val assignType = assignTypeOpt.getOrElse(dataType) + val needsDebug = attrDebugNeeded(id) && rep != NoRepeat - if (config.readStoresPos && rep != NoRepeat) + if (needsDebug) attrDebugStart(id, dataType, Some(io), rep) dataType match { @@ -61,7 +62,7 @@ trait EveryReadIsExpression handleAssignment(id, expr, rep, isRaw) } - if (config.readStoresPos && rep != NoRepeat) + if (needsDebug) attrDebugEnd(id, dataType, io, rep) } @@ -250,8 +251,18 @@ trait EveryReadIsExpression def userTypeDebugRead(id: String, dataType: DataType, assignType: DataType): Unit = ??? def instanceCalculate(instName: Identifier, dataType: DataType, value: Ast.expr): Unit = { - if (config.readStoresPos) + if (attrDebugNeeded(instName)) attrDebugStart(instName, dataType, None, NoRepeat) handleAssignmentSimple(instName, expression(value)) } + + override def attrDebugNeeded(attrId: Identifier): Boolean = { + if (!config.readStoresPos) + return false + + attrId match { + case _: NamedIdentifier | _: NumberedIdentifier | _: InstanceIdentifier => true + case _ => super.attrDebugNeeded(attrId) + } + } }