You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2018/12/21 19:40:27 UTC

[incubator-daffodil] branch master updated: Handle computed fields inside of choice elements.

This is an automated email from the ASF dual-hosted git repository.

mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a8103b  Handle computed fields inside of choice elements.
7a8103b is described below

commit 7a8103bfab5ba0866d6e57a79fe2076075e5de1f
Author: Brandon Sloane <bs...@tresys.com>
AuthorDate: Fri Dec 21 13:48:33 2018 -0500

    Handle computed fields inside of choice elements.
---
 .../src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala       | 7 ++++++-
 .../src/main/scala/org/apache/daffodil/grammar/AlignedMixin.scala  | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala
index ece2326..b953f75 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/dsom/ModelGroup.scala
@@ -256,7 +256,12 @@ abstract class ModelGroup
         case _ => true
       }
     }
-    (potentialLastRepresented, allOptional)
+    if(potentialLastRepresented.isEmpty){
+      //If there are no children, by definition, all children are optional.
+      (Seq(),true)
+    }else{
+      (potentialLastRepresented, allOptional)
+    }
   }
 
   final def allSelfContainedTermsTerminatedByRequiredElement: Seq[Term] =
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/AlignedMixin.scala b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/AlignedMixin.scala
index 69f7bf8..40e2135 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/AlignedMixin.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/AlignedMixin.scala
@@ -26,6 +26,7 @@ import org.apache.daffodil.schema.annotation.props.gen.LengthKind
 import org.apache.daffodil.schema.annotation.props.gen.LengthUnits
 import org.apache.daffodil.util.Math
 import org.apache.daffodil.dsom.Root
+import org.apache.daffodil.exceptions.Assert
 
 case class AlignmentMultipleOf(nBits: Long) {
   def *(that: AlignmentMultipleOf) = AlignmentMultipleOf(Math.gcd(nBits, that.nBits))
@@ -200,6 +201,8 @@ trait AlignedMixin extends GrammarMixin { self: Term =>
       case mg: ModelGroup => {
         val (lastChildren, couldBeLast) = mg.potentialLastChildren
         val lastApprox = lastChildren.map(_.endingAlignmentApprox + trailingSkipApprox) ++ (if (couldBeLast) Seq(contentStartAlignment + trailingSkipApprox) else Seq())
+        
+        Assert.invariant(!lastApprox.isEmpty)
         lastApprox.reduce { _ * _ }
       }
     }