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

 ##########
 File path: 
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SimpleTypes.scala
 ##########
 @@ -259,26 +591,91 @@ final class GlobalSimpleTypeDefFactory(xmlArg: Node, 
schemaDocumentArg: SchemaDo
 
 final class GlobalSimpleTypeDef(
   derivedType: Option[SimpleTypeDefBase],
-  val factory: GlobalSimpleTypeDefFactory,
+  factory: GlobalSimpleTypeDefFactory,
   val referringElement: Option[ElementDeclMixin])
-  extends SimpleTypeDefBase(factory.xml, factory.schemaDocument)
+  extends SimpleTypeDefBase(factory.xml, factory.schemaDocument, factory)
   with GlobalNonElementComponentMixin
   with NestingTraversesToReferenceMixin {
 
   // override def term = element
 
+  override lazy val primType = factory.primType
+
   override lazy val referringComponent: Option[SchemaComponent] =
     (derivedType, referringElement) match {
       case (Some(dt), None) => derivedType
       case (None, Some(elem)) => referringElement
-      case _ => Assert.impossible("SimpleType must either have a derivedType 
or an element. Not both.")
+      case (Some(_), Some(_)) => Assert.impossible("SimpleType must either 
have a derivedType or an element. Not both.")
+      case (None, None)       => None
     }
 
   override lazy val elementDecl: ElementDeclMixin = referringComponent match {
     case Some(dt: SimpleTypeDefBase) => dt.elementDecl
-    case Some(e: ElementDeclMixin) => e
-    case _ => Assert.invariantFailed("unexpected referringComponent")
+    case Some(e: ElementDeclMixin)   => e
+    case _                           => Assert.invariantFailed("unexpected 
referringComponent")
   }
 
 }
 
+final class EnumerationDefFactory(
+  xml:               Node,
+  parentTypeFactory: SimpleTypeDefFactory)
+  extends SchemaComponentFactory(xml, parentTypeFactory.schemaDocument)
+  with NestingLexicalMixin
+  with HasRepValueAttributes
+  with ResolvesProperties {
+
+  Assert.invariant(xml.label == "enumeration")
+
+  def enumerationDef(parentType: SimpleTypeDefBase) = {
+    Assert.invariant(parentType.factory == parentTypeFactory)
+    new EnumerationDef(parentType, this)
+  }
+
+  override lazy val optRepTypeFactory = parentTypeFactory.optRepTypeFactory
+
+  lazy val enumValueRaw: String = (xml \ "@value").head.text
+  lazy val enumValueCooked: AnyRef = 
parentTypeFactory.primType.fromXMLString(enumValueRaw)
+
+  override lazy val optRepValueSet: Option[RepValueSet[AnyRef]] = 
optRepValueSetFromAttribute
+  lazy val logicalValueSet: RepValueSet[AnyRef] = 
RepValueSetCompiler.compile(Seq(enumValueCooked), Seq())
+  lazy val canonicalRepValue: Option[AnyRef] = {
+    val ans1 = repValuesAttrCooked.headOption
+    val ans2 = repValueRangesAttrCooked.headOption.map(_._1).flatMap(asBound 
=> {
+      //TODO, currently, if the first repValue comes from an exclusive 
restriction we cannot
+      //infer a canonical repValue
+      if (asBound.isInclusive) (Some(asBound.maybeBound.get)) else None
+    })
+    val ans = ans1.orElse(ans2)
+    Assert.invariant(ans.isDefined == optRepValueSet.isDefined)
+    ans
+  }
+
+  override protected val optReferredToComponent = None
+
+  protected def annotationFactory(node: Node): Option[DFDLAnnotation] = 
Assert.invariantFailed("Should not be called")
+  protected def emptyFormatFactory: DFDLFormatAnnotation = new 
DFDLEnumerationFactory(newDFDLAnnotationXML("enumeration"), this)
+  protected def isMyFormatAnnotation(a: DFDLAnnotation): Boolean = 
Assert.invariantFailed("Should not be called")
+
+}
+
+final class EnumerationDef(
+  parent:  SimpleTypeDefBase,
+  factory: EnumerationDefFactory)
+  extends AnnotatedSchemaComponentImpl(factory.xml, parent)
+  with Enumeration_AnnotationMixin
+  with ResolvesProperties {
+
+  // Members declared in org.apache.daffodil.dsom.AnnotatedMixin
+  protected def annotationFactory(node: Node): Option[DFDLAnnotation] = 
Assert.invariantFailed("Should not be called")
 
 Review comment:
   What are the implications of not having annotationFactory and 
isMyFormatAnnotation? This means, I think, that you can't have actual DFDL 
properties here that are found by way of the normal scoping rules. That may be 
fine for these enumerations, as the properties may not make sense to be scoped 
anyway. 

----------------------------------------------------------------
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