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 57ee5a1ea..8fcc66ae1 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 @@ -25,12 +25,11 @@ trait CommonReads extends LanguageCompiler { normalIO } - val needsDebug = attrDebugNeeded(id) + val needsArrayDebug = attrDebugNeeded(id) && attr.cond.repeat != NoRepeat - if (needsDebug) { + if (needsArrayDebug) { attrDebugStart(id, attr.dataType, Some(io), NoRepeat) - if (attr.cond.repeat != NoRepeat) - attrDebugArrInit(id, attr.dataType) + attrDebugArrInit(id, attr.dataType) } defEndian match { @@ -45,7 +44,7 @@ trait CommonReads extends LanguageCompiler { attrParse0(id, attr, io, Some(fe)) } - if (needsDebug) + if (needsArrayDebug) attrDebugEnd(id, attr.dataType, io, NoRepeat) // More position management + set calculated flag after parsing for ParseInstanceSpecs @@ -75,7 +74,16 @@ trait CommonReads extends LanguageCompiler { condRepeatUntilHeader(id, io, attr.dataType, untilExpr) case NoRepeat => } + + val needsDebug = attrDebugNeeded(id) + if (needsDebug) + attrDebugStart(id, attr.dataType, Some(io), attr.cond.repeat) + attrParse2(id, attr.dataType, io, attr.cond.repeat, false, defEndian) + + if (needsDebug) + attrDebugEnd(id, attr.dataType, io, attr.cond.repeat) + attrValidateAll(attr) attr.cond.repeat match { case RepeatEos => @@ -94,7 +102,15 @@ trait CommonReads extends LanguageCompiler { def attrDebugArrInit(attrId: Identifier, attrType: DataType): Unit = {} def attrDebugEnd(attrName: Identifier, attrType: DataType, io: String, repeat: RepeatSpec): Unit = {} - def attrDebugNeeded(attrId: Identifier): Boolean = false + def attrDebugNeeded(attrId: Identifier): Boolean = { + if (!config.readStoresPos) + return false + + attrId match { + case _: NamedIdentifier | _: NumberedIdentifier | _: InstanceIdentifier => true + case _ => false + } + } /** * Runs all validation procedures requested for an attribute. 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 85eda7842..887239370 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,10 +31,6 @@ trait EveryReadIsExpression assignTypeOpt: Option[DataType] = None ): Unit = { val assignType = assignTypeOpt.getOrElse(dataType) - val needsDebug = attrDebugNeeded(id) && rep != NoRepeat - - if (needsDebug) - attrDebugStart(id, dataType, Some(io), rep) dataType match { case t: UserType => @@ -61,9 +57,6 @@ trait EveryReadIsExpression val expr = parseExpr(dataType, assignType, io, defEndian) handleAssignment(id, expr, rep, isRaw) } - - if (needsDebug) - attrDebugEnd(id, dataType, io, rep) } def attrBytesTypeParse( @@ -255,14 +248,4 @@ trait EveryReadIsExpression 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) - } - } }