bsloane1650 commented on a change in pull request #207: Added support for 
enumerations and TypeValueCalc
URL: https://github.com/apache/incubator-daffodil/pull/207#discussion_r279915094
 
 

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/dsom/RestrictionUnion.scala
 ##########
 @@ -166,16 +175,121 @@ final class Restriction(xmlArg: Node, val simpleType: 
SimpleTypeDefBase)
       case None => Nil
     }
   }.value
+
+  lazy val enumerations: Seq[EnumerationDefFactory] = (xml \ 
"enumeration").map(new EnumerationDefFactory(_, simpleTypeFactory))
+
+  lazy val facetValueSet: RepValueSet[AnyRef] = {
+    val initAns: (RangeBound[BigInt], RangeBound[BigInt]) = (new 
RangeBound(Maybe.Nope, false), new RangeBound(Maybe.Nope, false))
+    val range = combinedBaseFacets.foldLeft(initAns)({
+      case (acc, (facetType, facetValue)) =>
+        lazy val valueAsBigInt = BigInt(facetValue)
+        val (maybeBound, isMax, isInclusive) = facetType match {
+          case Facet.maxExclusive => (Maybe(valueAsBigInt), true, false)
+          case Facet.maxInclusive => (Maybe(valueAsBigInt), true, true)
+          case Facet.minExclusive => (Maybe(valueAsBigInt), false, false)
+          case Facet.minInclusive => (Maybe(valueAsBigInt), false, true)
+          case _                  => (Maybe.Nope, false, false)
+        }
+        if (maybeBound.isEmpty) {
+          acc
+        } else {
+          if (isMax) {
+            val oldMax = acc._2
+            if (!oldMax.isEmpty) {
+              SDE("Cannot define multiple max bounds on restriction")
+            }
+            val newMax = new RangeBound(maybeBound, isInclusive)
+            (acc._1, newMax)
+          } else {
+            val oldMin = acc._1
+            if (!oldMin.isEmpty) {
+              SDE("Cannot define multiple min bounds on restriction")
+            }
+            val newMin = new RangeBound(maybeBound, isInclusive)
+            (newMin, acc._2)
+          }
+        }
+    })
+    RepValueSetCompiler.compile(Seq(), 
Seq(range.asInstanceOf[(RangeBound[AnyRef], RangeBound[AnyRef])]))
+  }
+  lazy val repValueSet: RepValueSet[AnyRef] = {
+    val subsets = 
enumerations.map(_.optRepValueSet).filter(_.isDefined).map(_.get)
+    if (subsets.length != 0 && subsets.length != enumerations.length) {
+      context.SDE("If one enumeration value defines a repValue, then all must 
define a repValue")
+    }
+    val fromEnums = subsets.fold(RepValueSetCompiler.empty)((a, b) => 
a.merge(b))
+    if (enumerations.length > 0) {
+      fromEnums
+    } else {
+      //We are some form of identity mapping, so our facetValues are also our 
repValues
+      facetValueSet
+    }
+  }
+  lazy val optRepValueSet = if (repValueSet.isEmpty) None else 
Some(repValueSet)
+
+  lazy val logicalValueSet: RepValueSet[AnyRef] = {
+    val subsets = enumerations.map(_.logicalValueSet)
+    if (subsets.length != 0 && subsets.length != enumerations.length) {
 
 Review comment:
   I'm not entirely sure what I was getting at here. The logicalValueSet 
shouldn't care about weather or not the enumerations define a repValue. 
Regardless, If I was trying to check for something here, I clearly am not 
succeeding, so might as well remove the spurious check.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to