From 5f728aeca3be364d462e6e20f41cb5cdba5e99d4 Mon Sep 17 00:00:00 2001 From: olabusayoT <50379531+olabusayoT@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:07:37 -0400 Subject: [PATCH] fixup! Add support for lengthUnit=bits for any type - remove no-op checkLengthUnits function - allow lengthUnits bits for binarySeconds/milliSeconds for xs:datetime - remove SDE for requirement that lengthUnit=bytes for binarySeconds/milliSeconds - add tests for xs:double/xs:float verifying LU=bits - add tests for double/float showing runtime lengths not allowed - add tests for xs:dateTime with binaryCalendarRep set to binarySeconds/milliSeconds - add test for xs:date with binaryCalendarRep set to binarySeconds/milliSeconds (SDEs) DAFFODIL-2931 --- .../grammar/ElementBaseGrammarMixin.scala | 24 +--- .../section05/simple_types/SimpleTypes.tdml | 56 +++++++- .../section12/lengthKind/ExplicitTests.tdml | 133 ++++++++++++++++++ .../simple_types/TestSimpleTypes.scala | 3 + .../lengthKind/TestLengthKindExplicit.scala | 21 ++- 5 files changed, 211 insertions(+), 26 deletions(-) diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala index 43589cd096..c9ca196cd2 100644 --- a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala +++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala @@ -110,7 +110,6 @@ trait ElementBaseGrammarMixin lazy val prefixedLengthElementDecl: PrefixLengthQuasiElementDecl = LV('prefixedLengthElementDecl) { Assert.invariant(lengthKind == LengthKind.Prefixed) - checkLengthUnits() val detachedNode = .copy(scope = prefixLengthTypeGSTD.xml.scope) @@ -591,7 +590,6 @@ trait ElementBaseGrammarMixin val lengthFromProp: JLong = repElement.lengthEv.optConstant.get val nbits = repElement.lengthUnits match { case LengthUnits.Bits => - checkLengthUnits(repElement) lengthFromProp.longValue() case LengthUnits.Bytes => lengthFromProp.longValue() * 8 case LengthUnits.Characters => @@ -1069,10 +1067,8 @@ trait ElementBaseGrammarMixin (primType, binaryCalendarRep) match { case (PrimType.DateTime, BinaryCalendarRep.BinarySeconds) => (lengthUnits, binaryNumberKnownLengthInBits) match { - case (LengthUnits.Bytes, 32) => + case (LengthUnits.Bytes | LengthUnits.Bits, 32) => new ConvertBinaryDateTimeSecMilliPrim(this, binaryNumberKnownLengthInBits) - case (_, 32) => - SDE("lengthUnits must be 'bytes' when binaryCalendarRep='binarySeconds'") case (_, n) => SDE( "binary xs:dateTime must be 32 bits when binaryCalendarRep='binarySeconds'. Length in bits was %s.", @@ -1083,10 +1079,8 @@ trait ElementBaseGrammarMixin SDE("binaryCalendarRep='binarySeconds' is not allowed with type %s", primType.name) case (PrimType.DateTime, BinaryCalendarRep.BinaryMilliseconds) => (lengthUnits, binaryNumberKnownLengthInBits) match { - case (LengthUnits.Bytes, 64) => + case (LengthUnits.Bytes | LengthUnits.Bits, 64) => new ConvertBinaryDateTimeSecMilliPrim(this, binaryNumberKnownLengthInBits) - case (_, 64) => - SDE("lengthUnits must be 'bytes' when binaryCalendarRep='binaryMilliseconds'") case (_, n) => SDE( "binary xs:dateTime must be 64 bits when binaryCalendarRep='binaryMilliseconds'. Length in bits was %s.", @@ -1713,18 +1707,4 @@ trait ElementBaseGrammarMixin prod("mandatoryTextAlignment", impliedRepresentation eq Representation.Text) { mtaBase } - - private def checkLengthUnits(elem: ElementBase = context): Unit = { - elem.lengthUnits match { - case LengthUnits.Bits => - elem.optPrimType match { - case Some(_) => { - // allow all types to use lengthUnits bits - // PORTABILITY: See https://github.com/OpenGridForum/DFDL/issues/12 - } - case None => // do nothing - } - case _ => - } - } } diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml index 8593f015de..91ad8fb287 100644 --- a/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml +++ b/daffodil-test/src/test/resources/org/apache/daffodil/section05/simple_types/SimpleTypes.tdml @@ -276,6 +276,12 @@ dfdl:binaryCalendarRep="binarySeconds" dfdl:binaryCalendarEpoch="01-01-2000T00:00:00"/> + + + @@ -2413,9 +2419,11 @@ 00000000 00000000 00000000 00111101 - - Schema Definition Error: lengthUnits must be 'bytes' when binaryCalendarRep='binarySeconds' - + + + 1970-01-01T00:01:01 + + + + + + 00000000 00000000 00000000 00000001 + + + + 2018-01-01T09:13:43+09:00 + + + + + + + + 00000000 00000000 00000000 00000000 11111111 11111111 11111111 11111111 + + + + 2000-08-03T20:28:06.295000 + + + + + + + + 00000000 00000000 00000000 00000000 11111111 11111111 11111111 11111111 + + + binaryCalendarRep='binaryMilliseconds' + not allowed + type date + + + diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/ExplicitTests.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/ExplicitTests.tdml index 2af41931b8..d55a92948c 100644 --- a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/ExplicitTests.tdml +++ b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/ExplicitTests.tdml @@ -1050,6 +1050,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 42 f6 e9 79 + + + + + 123.456 + + + + + + + + + 42 f6 e9 79 + + + + Schema Definition Error + must be 32 bits + + + + + + + + 42 f6 e9 79 + + + + floating point binary numbers + may not have runtime-specified lengths + + + + + + + + 40 5e dd 2f 1a 9f be 77 + + + + + 123.456 + + + + + + + + + 40 5e dd 2f 1a 9f be 77 + + + + Schema Definition Error + must be 64 bits + + + + + + + + 40 5e dd 2f 1a 9f be 77 + + + + floating point binary numbers + may not have runtime-specified lengths + + +