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_r275519612
 
 

 ##########
 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:
   I'm not actually sure. I assume we thought this through back when this was 
added. Regardless, most of the annotation logic is not relevant to Enumerations 
as the only meaningful place to put annotations is on the object itself.
   
   In fact, because these annotations need to be accessed from the factory 
object, we cannot use most of the annotation logic, which is probably what led 
us to dissallow  these methods in the first place.
   
   The only potential problem that I can imagine is that these methods are 
needed for long-form annotations. To get language lawery, I do not believe 
Enumerations are defined as "annotation points", so a longform annotation might 
not be technically allowed there anyway (although now that we can annotate 
them, they ought to be annotation points). Regardless, I can't imagine someone 
wanting to do a longform annotation on them.

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