olabusayoT commented on code in PR #1604:
URL: https://github.com/apache/daffodil/pull/1604#discussion_r2669918241


##########
daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/AlignedMixin.scala:
##########
@@ -228,29 +235,161 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
       }
     }.value
 
+  private lazy val separatorPrefixMTAApprox =
+    this.optLexicalParent match {
+      case Some(s: SequenceTermBase) if s.hasSeparator =>
+        import SeparatorPosition.*
+        s.separatorPosition match {
+          case Prefix | Infix => 
LengthMultipleOf(s.knownEncodingAlignmentInBits)
+          case Postfix => LengthMultipleOf(0)
+        }
+      case _ => LengthMultipleOf(0)
+    }
+
+  private lazy val separatorPostfixMTAApprox =
+    this.optLexicalParent match {
+      case Some(s: SequenceTermBase) if s.hasSeparator =>
+        import SeparatorPosition.*
+        s.separatorPosition match {
+          case Prefix | Infix => LengthMultipleOf(0)
+          case Postfix => LengthMultipleOf(s.knownEncodingAlignmentInBits)
+        }
+      case _ => LengthMultipleOf(0)
+    }
+
+  private lazy val separatorLengthApprox = this.optLexicalParent match {
+    case Some(s: SequenceTermBase) if s.hasSeparator =>
+      getEncodingLengthApprox(s)
+    case _ => LengthMultipleOf(0)
+  }
+
+  private lazy val initiatorMTAApprox =
+    if (this.hasInitiator) {
+      AlignmentMultipleOf(this.knownEncodingAlignmentInBits)
+    } else {
+      AlignmentMultipleOf(0)
+    }
+
+  private lazy val initiatorLengthApprox = if (this.hasInitiator) {
+    getEncodingLengthApprox(this)
+  } else {
+    LengthMultipleOf(0)
+  }
+
+  private lazy val terminatorMTAApprox =
+    if (this.hasTerminator) {
+      AlignmentMultipleOf(this.knownEncodingAlignmentInBits)
+    } else {
+      AlignmentMultipleOf(0)
+    }
+
+  private lazy val terminatorLengthApprox = if (this.hasTerminator) {
+    getEncodingLengthApprox(this)
+  } else {
+    LengthMultipleOf(0)
+  }
+
+  private def getEncodingLengthApprox(t: Term) = {
+    if (t.isKnownEncoding) {
+      val dfdlCharset = t.charsetEv.optConstant.get
+      val fixedWidth =
+        if (dfdlCharset.maybeFixedWidth.isDefined) 
dfdlCharset.maybeFixedWidth.get else 8
+      LengthMultipleOf(fixedWidth)
+    } else {
+      // runtime encoding, which must be a byte-length encoding
+      LengthMultipleOf(8)
+    }
+  }
+
+  /**
+   * prior alignment with leading skip includes the prefix/infix separator MTA 
and length,
+   * any leading skips
+   */
   private lazy val priorAlignmentWithLeadingSkipApprox: AlignmentMultipleOf = {
-    priorAlignmentApprox + leadingSkipApprox
+    val priorAlignmentWithSeparatorApprox = priorAlignmentApprox
+      + separatorPrefixMTAApprox
+      + separatorLengthApprox
+    val leadingAlignmentApprox = (priorAlignmentWithSeparatorApprox
+      + leadingSkipApprox)
+    leadingAlignmentApprox
+  }
+
+  /**
+   * The length of the prefix length quasi element.
+   *
+   * This is only relevant for quasi elements, or prefixed terms.
+   */
+  private lazy val prefixLengthElementLength = {
+    this match {
+      case eb: ElementBase => {
+        if (eb.isInstanceOf[QuasiElementDeclBase])
+          LengthExact(
+            
eb.asInstanceOf[QuasiElementDeclBase].elementLengthInBitsEv.constValue.get
+          )
+        else if (eb.lengthKind == Prefixed)
+          LengthExact(
+            this
+              .asInstanceOf[ElementBase]
+              .prefixedLengthElementDecl
+              .elementLengthInBitsEv
+              .constValue
+              .get
+          )

Review Comment:
   So I updated the code to recursively call prefixLengthElementLength for 
elements with LK=prefixed to get the length of it's prefix length, though we 
don't currently support nested prefixed elements in Daffodil as it's a subset 
error. I left the fix in regardless for when we do implement that. Added 
test_prefix_alignment_3 test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to