mbeckerle commented on code in PR #1158:
URL: https://github.com/apache/daffodil/pull/1158#discussion_r1488258992
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/CompiledExpression.scala:
##########
@@ -251,33 +252,35 @@ class ExpressionCompiler[T <: AnyRef] extends
ExpressionCompilerBase[T] {
// required. If something is passed in that does not convert to the
// expected type it will result in error.
- // must be able to convert this to a primitive type
- val maybePrimType = PrimType.fromNodeInfo(nodeInfoKind)
- if (maybePrimType.isEmpty) {
- val msg = "No known primitive type to convert logical value to: %s"
- compileInfoWhereExpressionWasLocated.SDE(msg, nodeInfoKind)
- }
+ nodeInfoKind match {
+ case atomic: AnyAtomic.Kind => {
- // remove the leading escape curly brace if it exists
- val literal =
- if (exprOrLiteral.startsWith("{{")) exprOrLiteral.tail
- else exprOrLiteral
+ // remove the leading escape curly brace if it exists
+ val literal =
+ if (exprOrLiteral.startsWith("{{")) exprOrLiteral.tail
+ else exprOrLiteral
- val logical: DataValuePrimitive =
- try {
- maybePrimType.get.fromXMLString(literal)
- } catch {
- case e: Exception => {
- val msg = "Unable to convert logical value \"%s\" to %s: %s"
- compileInfoWhereExpressionWasLocated.SDE(
- msg,
- exprOrLiteral,
- nodeInfoKind,
- e.getMessage,
- )
- }
- }
+ val logical: DataValuePrimitive =
+ try {
+ atomic.primType.fromXMLString(literal)
+ } catch {
+ case e: Exception => {
+ val msg = "Unable to convert logical value \"%s\" to %s: %s"
+ compileInfoWhereExpressionWasLocated.SDE(
+ msg,
+ exprOrLiteral,
+ nodeInfoKind,
+ e.getMessage,
+ )
+ }
+ }
- new ConstantExpression[T](qn, nodeInfoKind,
logical.getAnyRef.asInstanceOf[T])
+ new ConstantExpression[T](qn, nodeInfoKind,
logical.getAnyRef.asInstanceOf[T])
+ }
+ case _ => {
+ val msg = "No known primitive type to convert logical value to: %s"
+ compileInfoWhereExpressionWasLocated.SDE(msg, nodeInfoKind)
Review Comment:
Change to an assert, and put the coverage suppression around it.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala:
##########
@@ -298,36 +279,36 @@ object NodeInfo extends Enum {
def fromObject(a: Any) = {
a match {
- case x: String => NodeInfo.String
Review Comment:
Removing.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala:
##########
@@ -298,36 +279,36 @@ object NodeInfo extends Enum {
def fromObject(a: Any) = {
a match {
- case x: String => NodeInfo.String
- case x: Int => NodeInfo.Int
- case x: Byte => NodeInfo.Byte
- case x: Short => NodeInfo.Short
- case x: Long => NodeInfo.Long
- case x: JBigInt => NodeInfo.Integer
- case x: JBigDecimal => NodeInfo.Decimal
- case x: Double => NodeInfo.Double
- case x: Float => NodeInfo.Float
- case x: Array[Byte] => NodeInfo.HexBinary
- case x: URI => NodeInfo.AnyURI
- case x: Boolean => NodeInfo.Boolean
- case x: DFDLCalendar => NodeInfo.DateTime
+ case x: String => PrimType.String
+ case x: Int => PrimType.Int
+ case x: Byte => PrimType.Byte
+ case x: Short => PrimType.Short
+ case x: Long => PrimType.Long
+ case x: JBigInt => PrimType.Integer
+ case x: JBigDecimal => PrimType.Decimal
+ case x: Double => PrimType.Double
+ case x: Float => PrimType.Float
+ case x: Array[Byte] => PrimType.HexBinary
+ case x: URI => PrimType.AnyURI
+ case x: Boolean => PrimType.Boolean
+ case x: DFDLCalendar => PrimType.DateTime
case _ => Assert.usageError("Unsupported object representation type:
%s".format(a))
}
}
def fromClass(jc: Class[_]) = {
val ni = jc match {
- case ClassIntBoxed | ClassIntPrim => Some(NodeInfo.Int)
- case ClassByteBoxed | ClassBytePrim => Some(NodeInfo.Byte)
- case ClassShortBoxed | ClassShortPrim => Some(NodeInfo.Short)
- case ClassLongBoxed | ClassLongPrim => Some(NodeInfo.Long)
- case ClassDoubleBoxed | ClassDoublePrim => Some(NodeInfo.Double)
- case ClassFloatBoxed | ClassFloatPrim => Some(NodeInfo.Float)
- case ClassBooleanBoxed | ClassBooleanPrim => Some(NodeInfo.Boolean)
- case ClassString => Some(NodeInfo.String)
- case ClassJBigInt => Some(NodeInfo.Integer)
- case ClassJBigDecimal => Some(NodeInfo.Decimal)
- case ClassPrimByteArray => Some(NodeInfo.HexBinary)
+ case ClassIntBoxed | ClassIntPrim => Some(PrimType.Int)
+ case ClassByteBoxed | ClassBytePrim => Some(PrimType.Byte)
+ case ClassShortBoxed | ClassShortPrim => Some(PrimType.Short)
+ case ClassLongBoxed | ClassLongPrim => Some(PrimType.Long)
+ case ClassDoubleBoxed | ClassDoublePrim => Some(PrimType.Double)
+ case ClassFloatBoxed | ClassFloatPrim => Some(PrimType.Float)
+ case ClassBooleanBoxed | ClassBooleanPrim => Some(PrimType.Boolean)
+ case ClassString => Some(PrimType.String)
+ case ClassJBigInt => Some(PrimType.Integer)
+ case ClassJBigDecimal => Some(PrimType.Decimal)
+ case ClassPrimByteArray => Some(PrimType.HexBinary)
case _ => None
}
Review Comment:
Will add comments.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/NodeInfo.scala:
##########
@@ -509,53 +491,28 @@ object NodeInfo extends Enum {
val Date = PrimType.Date
val Time = PrimType.Time
- /**
- * This list of types must be in order of most specific to least, i.e. Byte
- * inherits from Short, which inherits from Int etc. This is becasue
- * fromNodeInfo does a find on this list based on isSubtypeOf, which will
- * return the first successful result.
- */
- val allPrims = List(
- String,
- Byte,
- Short,
- Int,
- Long,
- UnsignedByte,
- UnsignedShort,
- UnsignedInt,
- UnsignedLong,
- NonNegativeInteger,
- Integer,
- Float,
- Double,
- Decimal,
- HexBinary,
- AnyURI,
- Boolean,
- DateTime,
- Date,
- Time,
- )
+ protected sealed trait PrimTypeKind extends AnyAtomic.Kind
/**
* The PrimType objects are a child enum within the overall NodeInfo
* enum.
*/
object PrimType {
+ type Kind = PrimTypeKind
- def fromRefQName(refQName: RefQName): Option[PrimType] = {
- allPrims.find { prim => refQName.matches(prim.globalQName) }
- }
+ private lazy val nameToPrimType: Map[String, PrimType] =
+ (new LinkedHashMap() ++= allDFDLTypes.map { ptn =>
+ (ptn.name, ptn)
+ }).toMap // to immutable
Review Comment:
Arrrrgh. The point was to get an immutable map that is order preserving.
No such thing. Will just have to use a regular map then.
##########
daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Delay.scala:
##########
@@ -104,7 +104,7 @@ final class Delay[T] private (private var box:
Delay.Box[T], sym: Symbol)
else {
box
}
- "Delay(" + sym + ", " + objString + bodyString + ")"
+ "Delay(" + sym.toString + ", " + objString + bodyString + ")"
Review Comment:
Add coverage suppression. These are only for debugging purposes.
##########
daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Delay.scala:
##########
@@ -130,23 +130,27 @@ object Delay {
* @tparam T type of the argument. (Usually inferred by Scala.)
* @return the Delay object
*/
- def apply[T](sym: Symbol, obj: AnyRef, delayedExpression: => T) = {
- new Delay(new Box(sym, obj, delayedExpression), sym)
+ def apply[T](sym: AnyRef, context: AnyRef, delayedExpression: => T) = {
+ new Delay(new Box(sym, context, delayedExpression), sym)
+ }
+
+ def apply[T](sym: AnyRef, delayedExpression: => T) = {
+ new Delay(new Box(sym, null, delayedExpression), sym)
}
/**
* Specifically, this is NOT serializable.
* Serialization must force all Delay objects.
*/
- private class Box[T](val sym: Symbol, val obj: AnyRef, delayedExpression: =>
T) {
+ private class Box[T](val obj: AnyRef, val context: AnyRef,
delayedExpression: => T) {
lazy val value = delayedExpression
override def toString() = {
val desc = obj match {
case d: NamedMixinBase => "(" + d.diagnosticDebugName + ")"
case _ => ""
}
- "box(" + obj.hashCode() + desc + ")"
+ "box(" + obj.toString + desc + ")"
Review Comment:
Add coverage suppression. These are only for debugging.
##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/JDOMInfosetOutputter.scala:
##########
@@ -56,7 +56,7 @@ class JDOMInfosetOutputter extends InfosetOutputter {
if (!simple.isNilled) {
val text =
- if (simple.metadata.primitiveType == PrimitiveType.String) {
+ if (simple.metadata.jPrimType == JPrimType.String) {
Review Comment:
However, there already is a dsom.PrimitiveType in the daffodil-core, which
is an encapsulation around runtime1.PrimType, which is an encapsulation around
JPrimType.
Changing them all to PrimitiveType, and making people understand what
context they are in is going to be problematic.
I can make the method name primitiveType, and the type of the enum be
PrimTypeEnum?
--
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]