Skip to content

Commit

Permalink
fixup! fixup! fixup! Fix Bug with valueLength being overwritten after…
Browse files Browse the repository at this point in the history
… Trim

- rename custom prefixedlength parsers to *BitLengthParsers to more accurately reflect what they're doing
- rename custom prefixedlength unparsers to MinimumLengthUnparsers to more accurately reflect what they're doing
- rename PrefixedLengthParserMixin2 to BitLengthFromBitLimitMixin to more accurately reflect what it is
- got rid of HexBinaryLengthPrefixed since it is the same as HexBinaryEndOfBitLimit

DAFFODIL-2658
  • Loading branch information
olabusayoT committed Nov 4, 2024
1 parent 78050c8 commit ccdc433
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import org.apache.daffodil.core.grammar.primitives.ChoiceCombinator
import org.apache.daffodil.core.grammar.primitives.ElementCombinator
import org.apache.daffodil.core.grammar.primitives.ElementParseAndUnspecifiedLength
import org.apache.daffodil.core.grammar.primitives.ElementUnused
import org.apache.daffodil.core.grammar.primitives.HexBinaryLengthPrefixed
import org.apache.daffodil.core.grammar.primitives.HexBinaryEndOfBitLimit
import org.apache.daffodil.core.grammar.primitives.HexBinarySpecifiedLength
import org.apache.daffodil.core.grammar.primitives.OrderedSequence
import org.apache.daffodil.core.grammar.primitives.RepOrderedExactlyNSequenceChild
Expand Down Expand Up @@ -289,7 +289,8 @@ object DaffodilCCodeGenerator
case g: ElementParseAndUnspecifiedLength =>
elementParseAndUnspecifiedLengthGenerateCode(g, cgState)
case g: ElementUnused => noop(g)
case g: HexBinaryLengthPrefixed => hexBinaryLengthPrefixedGenerateCode(g.e, cgState)
case g: HexBinaryEndOfBitLimit if g.e.isPrefixed =>
hexBinaryLengthPrefixedGenerateCode(g.e, cgState)
case g: HexBinarySpecifiedLength => hexBinarySpecifiedLengthGenerateCode(g.e, cgState)
case g: OrderedSequence => orderedSequenceGenerateCode(g, cgState)
case g: Prod => prod(g, cgState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,15 @@ trait ElementBaseGrammarMixin
}
}

protected lazy val isPrefixed: Boolean = {
import LengthKind._
lengthKind match {
case Prefixed => true
case _ => false
}
}
lazy val isPrefixed: Boolean = lengthKind == LengthKind.Prefixed

protected lazy val isDelimitedPrefixedPattern: Boolean = {
import LengthKind._
lengthKind match {
case Delimited =>
true // don't test for hasDelimiters because it might not be our delimiter, but a surrounding group's separator, or it's terminator, etc.
case Pattern => true
case Prefixed => isPrefixed
case Prefixed => true
case _ => false
}
}
Expand Down Expand Up @@ -661,7 +655,7 @@ trait ElementBaseGrammarMixin
}

private lazy val hexBinaryLengthPrefixed = prod("hexBinaryLengthPrefixed") {
new HexBinaryLengthPrefixed(this)
new HexBinaryEndOfBitLimit(this)
}

private lazy val hexBinaryValue = prod("hexBinaryValue") {
Expand Down Expand Up @@ -1387,14 +1381,15 @@ trait ElementBaseGrammarMixin
}
case LengthKind.Implicit if isSimpleType && primType == PrimType.String =>
new SpecifiedLengthImplicitCharacters(this, body, this.maxLength.longValue)

case LengthKind.Implicit if isSimpleType && primType == PrimType.HexBinary =>
new SpecifiedLengthImplicit(this, body, this.maxLength.longValue * bitsMultiplier)
case LengthKind.Implicit
if isSimpleType && impliedRepresentation == Representation.Binary =>
if isSimpleType &&
impliedRepresentation == Representation.Binary &&
primType != PrimType.HexBinary =>
new SpecifiedLengthImplicit(this, body, implicitBinaryLengthInBits)
case LengthKind.Implicit if isComplexType =>
case LengthKind.Implicit =>
body // for complex types, implicit means "roll up from the bottom"
// for simple types, the primitives have custom parsers that handle implicit length logic
// and don't use the limit provided by the SpecifiedLengthImplicit parser
case LengthKind.EndOfParent if isComplexType =>
notYetImplemented("lengthKind='endOfParent' for complex type")
case LengthKind.EndOfParent =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ package org.apache.daffodil.core.grammar.primitives

import org.apache.daffodil.core.dsom.ElementBase
import org.apache.daffodil.core.grammar.Terminal
import org.apache.daffodil.runtime1.processors.parsers.BCDDecimalBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDDecimalKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDDecimalPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDDecimalRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDIntegerBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDIntegerKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDIntegerPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BCDIntegerRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.unparsers.Unparser
import org.apache.daffodil.unparsers.runtime1.BCDDecimalKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDDecimalPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDDecimalMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDDecimalRuntimeLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDIntegerKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDIntegerPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDIntegerMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BCDIntegerRuntimeLengthUnparser

class BCDIntegerRuntimeLength(val e: ElementBase) extends Terminal(e, true) {
Expand All @@ -52,9 +52,9 @@ class BCDIntegerKnownLength(val e: ElementBase, lengthInBits: Long) extends Term

class BCDIntegerPrefixedLength(val e: ElementBase) extends Terminal(e, true) {

override lazy val parser = new BCDIntegerPrefixedLengthParser(e.elementRuntimeData)
override lazy val parser = new BCDIntegerBitLimitLengthParser(e.elementRuntimeData)

override lazy val unparser: Unparser = new BCDIntegerPrefixedLengthUnparser(
override lazy val unparser: Unparser = new BCDIntegerMinimumLengthUnparser(
e.elementRuntimeData
)
}
Expand Down Expand Up @@ -93,8 +93,8 @@ class BCDDecimalKnownLength(val e: ElementBase, lengthInBits: Long) extends Term
class BCDDecimalPrefixedLength(val e: ElementBase) extends Terminal(e, true) {

override lazy val parser =
new BCDDecimalPrefixedLengthParser(e.elementRuntimeData, e.binaryDecimalVirtualPoint)
new BCDDecimalBitLimitLengthParser(e.elementRuntimeData, e.binaryDecimalVirtualPoint)

override lazy val unparser: Unparser =
new BCDDecimalPrefixedLengthUnparser(e.elementRuntimeData, e.binaryDecimalVirtualPoint)
new BCDDecimalMinimumLengthUnparser(e.elementRuntimeData, e.binaryDecimalVirtualPoint)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package org.apache.daffodil.core.grammar.primitives

import org.apache.daffodil.core.dsom.ElementBase
import org.apache.daffodil.core.grammar.Terminal
import org.apache.daffodil.runtime1.processors.parsers.BinaryBooleanBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryBooleanParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryBooleanPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.unparsers.Unparser
import org.apache.daffodil.unparsers.runtime1.BinaryBooleanPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryBooleanMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryBooleanUnparser

class BinaryBoolean(val e: ElementBase) extends Terminal(e, true) {
Expand All @@ -46,14 +46,14 @@ class BinaryBoolean(val e: ElementBase) extends Terminal(e, true) {
}

class BinaryBooleanPrefixedLength(val e: ElementBase) extends Terminal(e, true) {
override lazy val parser = new BinaryBooleanPrefixedLengthParser(
override lazy val parser = new BinaryBooleanBitLimitLengthParser(
e.elementRuntimeData,
e.binaryBooleanTrueRep,
e.binaryBooleanFalseRep,
e.lengthUnits
)

override lazy val unparser: Unparser = new BinaryBooleanPrefixedLengthUnparser(
override lazy val unparser: Unparser = new BinaryBooleanMinimumLengthUnparser(
e.elementRuntimeData,
e.binaryBooleanTrueRep,
e.binaryBooleanFalseRep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import org.apache.daffodil.core.grammar.Terminal
import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.util.MaybeInt
import org.apache.daffodil.runtime1.dpath.NodeInfo
import org.apache.daffodil.runtime1.processors.parsers.BinaryDecimalBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryDecimalKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryDecimalPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryDecimalRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryDoubleParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryFloatParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryIntegerBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryIntegerKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryIntegerPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.BinaryIntegerRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.unparsers.Unparser
import org.apache.daffodil.unparsers.runtime1.BinaryDecimalKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryDecimalPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryDecimalMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryDecimalRuntimeLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryDoubleUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryFloatUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryIntegerKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryIntegerPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryIntegerMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.BinaryIntegerRuntimeLengthUnparser

class BinaryIntegerRuntimeLength(val e: ElementBase, signed: Boolean)
Expand Down Expand Up @@ -77,7 +77,7 @@ class BinaryIntegerPrefixedLength(val e: ElementBase, signed: Boolean)
private lazy val pladj = e.prefixedLengthAdjustmentInUnits

override lazy val parser =
new BinaryIntegerPrefixedLengthParser(erd, signed)
new BinaryIntegerBitLimitLengthParser(erd, signed)

override lazy val unparser: Unparser = {
val maybeNBits = e.primType match {
Expand All @@ -89,7 +89,7 @@ class BinaryIntegerPrefixedLength(val e: ElementBase, signed: Boolean)
case _ =>
Assert.invariantFailed("Only integer base types should be used for this primitive")
}
new BinaryIntegerPrefixedLengthUnparser(erd, maybeNBits, signed)
new BinaryIntegerMinimumLengthUnparser(erd, maybeNBits, signed)
}
}

Expand Down Expand Up @@ -134,14 +134,14 @@ class BinaryDecimalKnownLength(val e: ElementBase, lengthInBits: Long)
class BinaryDecimalPrefixedLength(val e: ElementBase) extends Terminal(e, true) {

override lazy val parser =
new BinaryDecimalPrefixedLengthParser(
new BinaryDecimalBitLimitLengthParser(
e.elementRuntimeData,
e.decimalSigned,
e.binaryDecimalVirtualPoint
)

override lazy val unparser: Unparser =
new BinaryDecimalPrefixedLengthUnparser(
new BinaryDecimalMinimumLengthUnparser(
e.elementRuntimeData,
e.decimalSigned,
e.binaryDecimalVirtualPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ package org.apache.daffodil.core.grammar.primitives

import org.apache.daffodil.core.dsom.ElementBase
import org.apache.daffodil.core.grammar.Terminal
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedDecimalBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedDecimalKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedDecimalPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedDecimalRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedIntegerBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedIntegerKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedIntegerPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedIntegerRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.unparsers.Unparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedDecimalKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedDecimalPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedDecimalMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedDecimalRuntimeLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedIntegerKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedIntegerPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedIntegerMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.IBM4690PackedIntegerRuntimeLengthUnparser

class IBM4690PackedIntegerRuntimeLength(val e: ElementBase, signed: Boolean)
Expand Down Expand Up @@ -62,9 +62,9 @@ class IBM4690PackedIntegerKnownLength(val e: ElementBase, signed: Boolean, lengt
class IBM4690PackedIntegerPrefixedLength(val e: ElementBase, signed: Boolean)
extends Terminal(e, true) {
override lazy val parser =
new IBM4690PackedIntegerPrefixedLengthParser(e.elementRuntimeData, signed)
new IBM4690PackedIntegerBitLimitLengthParser(e.elementRuntimeData, signed)

override lazy val unparser: Unparser = new IBM4690PackedIntegerPrefixedLengthUnparser(
override lazy val unparser: Unparser = new IBM4690PackedIntegerMinimumLengthUnparser(
e.elementRuntimeData
)
}
Expand Down Expand Up @@ -102,12 +102,12 @@ class IBM4690PackedDecimalKnownLength(val e: ElementBase, lengthInBits: Long)
}

class IBM4690PackedDecimalPrefixedLength(val e: ElementBase) extends Terminal(e, true) {
override lazy val parser = new IBM4690PackedDecimalPrefixedLengthParser(
override lazy val parser = new IBM4690PackedDecimalBitLimitLengthParser(
e.elementRuntimeData,
e.binaryDecimalVirtualPoint
)

override lazy val unparser: Unparser = new IBM4690PackedDecimalPrefixedLengthUnparser(
override lazy val unparser: Unparser = new IBM4690PackedDecimalMinimumLengthUnparser(
e.elementRuntimeData,
e.binaryDecimalVirtualPoint
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.apache.daffodil.runtime1.processors.parsers.BCDIntegerDelimitedParser
import org.apache.daffodil.runtime1.processors.parsers.BlobSpecifiedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.HexBinaryDelimitedParser
import org.apache.daffodil.runtime1.processors.parsers.HexBinaryEndOfBitLimitParser
import org.apache.daffodil.runtime1.processors.parsers.HexBinaryLengthPrefixedParser
import org.apache.daffodil.runtime1.processors.parsers.HexBinarySpecifiedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedDecimalDelimitedParser
import org.apache.daffodil.runtime1.processors.parsers.IBM4690PackedIntegerDelimitedParser
Expand Down Expand Up @@ -182,16 +181,6 @@ case class HexBinaryEndOfBitLimit(e: ElementBase) extends Terminal(e, true) {
new HexBinaryMinLengthInBytesUnparser(e.minLength.longValue, e.elementRuntimeData)
}

case class HexBinaryLengthPrefixed(e: ElementBase) extends Terminal(e, true) {

override lazy val parser: DaffodilParser = new HexBinaryLengthPrefixedParser(
e.elementRuntimeData
)

override lazy val unparser: DaffodilUnparser =
new HexBinaryMinLengthInBytesUnparser(e.minLength.longValue, e.elementRuntimeData)
}

abstract class PackedIntegerDelimited(
e: ElementBase,
signed: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ package org.apache.daffodil.core.grammar.primitives
import org.apache.daffodil.core.dsom.ElementBase
import org.apache.daffodil.core.grammar.Terminal
import org.apache.daffodil.lib.util.PackedSignCodes
import org.apache.daffodil.runtime1.processors.parsers.PackedDecimalBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedDecimalKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedDecimalPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedDecimalRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedIntegerBitLimitLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedIntegerKnownLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedIntegerPrefixedLengthParser
import org.apache.daffodil.runtime1.processors.parsers.PackedIntegerRuntimeLengthParser
import org.apache.daffodil.runtime1.processors.unparsers.Unparser
import org.apache.daffodil.unparsers.runtime1.PackedDecimalKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedDecimalPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedDecimalMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedDecimalRuntimeLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedIntegerKnownLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedIntegerPrefixedLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedIntegerMinimumLengthUnparser
import org.apache.daffodil.unparsers.runtime1.PackedIntegerRuntimeLengthUnparser

class PackedIntegerRuntimeLength(
Expand Down Expand Up @@ -83,10 +83,10 @@ class PackedIntegerPrefixedLength(
) extends Terminal(e, true) {

override lazy val parser =
new PackedIntegerPrefixedLengthParser(e.elementRuntimeData, signed, packedSignCodes)
new PackedIntegerBitLimitLengthParser(e.elementRuntimeData, signed, packedSignCodes)

override lazy val unparser: Unparser =
new PackedIntegerPrefixedLengthUnparser(e.elementRuntimeData, packedSignCodes)
new PackedIntegerMinimumLengthUnparser(e.elementRuntimeData, packedSignCodes)
}

class PackedDecimalRuntimeLength(val e: ElementBase, packedSignCodes: PackedSignCodes)
Expand Down Expand Up @@ -132,13 +132,13 @@ class PackedDecimalKnownLength(
class PackedDecimalPrefixedLength(val e: ElementBase, packedSignCodes: PackedSignCodes)
extends Terminal(e, true) {

override lazy val parser = new PackedDecimalPrefixedLengthParser(
override lazy val parser = new PackedDecimalBitLimitLengthParser(
e.elementRuntimeData,
e.binaryDecimalVirtualPoint,
packedSignCodes
)

override lazy val unparser: Unparser = new PackedDecimalPrefixedLengthUnparser(
override lazy val unparser: Unparser = new PackedDecimalMinimumLengthUnparser(
e.elementRuntimeData,
e.binaryDecimalVirtualPoint,
packedSignCodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class BCDIntegerDelimitedUnparser(e: ElementRuntimeData)
override def getBitLength(state: ParseOrUnparseState): Int = { 0 }
}

final class BCDIntegerPrefixedLengthUnparser(e: ElementRuntimeData)
final class BCDIntegerMinimumLengthUnparser(e: ElementRuntimeData)
extends BCDIntegerBaseUnparser(e) {

override lazy val runtimeDependencies = Vector()
Expand Down Expand Up @@ -100,7 +100,7 @@ final class BCDDecimalDelimitedUnparser(e: ElementRuntimeData, binaryDecimalVirt
override def getBitLength(state: ParseOrUnparseState): Int = { 0 }
}

final class BCDDecimalPrefixedLengthUnparser(
final class BCDDecimalMinimumLengthUnparser(
e: ElementRuntimeData,
binaryDecimalVirtualPoint: Int
) extends BCDDecimalBaseUnparser(e, binaryDecimalVirtualPoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class BinaryBooleanUnparser(
}
}

class BinaryBooleanPrefixedLengthUnparser(
class BinaryBooleanMinimumLengthUnparser(
e: ElementRuntimeData,
binaryBooleanTrueRep: MaybeULong,
binaryBooleanFalseRep: ULong,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BinaryIntegerRuntimeLengthUnparser(
override val runtimeDependencies = Vector(lengthEv)
}

class BinaryIntegerPrefixedLengthUnparser(
class BinaryIntegerMinimumLengthUnparser(
e: ElementRuntimeData,
maybeNBits: MaybeInt,
signed: Boolean
Expand Down Expand Up @@ -196,7 +196,7 @@ class BinaryDecimalRuntimeLengthUnparser(
override val runtimeDependencies = Vector(lengthEv)
}

class BinaryDecimalPrefixedLengthUnparser(
class BinaryDecimalMinimumLengthUnparser(
e: ElementRuntimeData,
signed: YesNo,
binaryDecimalVirtualPoint: Int
Expand Down
Loading

0 comments on commit ccdc433

Please sign in to comment.