mbeckerle commented on code in PR #1070:
URL: https://github.com/apache/daffodil/pull/1070#discussion_r1303615295


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/TypeCalculator.scala:
##########
@@ -223,159 +186,34 @@ class KeysetValueTypeCalculatorUnordered(
   override def inputTypeCalc(
     x: DataValuePrimitive,
     xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) = {
+  ): Either[Error, DataValuePrimitiveNullable] = {
     valueMap.get(x) match {
-      case Some(a) => (a, Maybe.Nope)
-      case None =>
-        (DataValue.NoValue, One(s"Value ${x} not found in enumeration 
dfdlx:repValues"))
+      case Some(a) => Right(a)
+      case None => Left(s"Value ${x} not found in enumeration dfdlx:repValues")
     }
   }
 
   override def outputTypeCalc(
     x: DataValuePrimitive,
     xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) = {
+  ): Either[Error, DataValuePrimitiveNullable] = {
     unparseMap.get(x) match {
-      case Some(v) => (v, Maybe.Nope)
-      case None => (DataValue.NoValue, One(s"Value ${x} not found in 
enumeration"))
+      case Some(v) => Right(v)
+      case None => Left(s"Value ${x} not found in enumeration")
     }
   }
 
 }
 
-class ExpressionTypeCalculator(
-  private val maybeInputTypeCalcDelay: 
Delay[Maybe[CompiledExpression[AnyRef]]],
-  private val maybeOutputTypeCalcDelay: 
Delay[Maybe[CompiledExpression[AnyRef]]],
-  srcType: NodeInfo.Kind,
-  dstType: NodeInfo.Kind,
-) extends TypeCalculator(srcType, dstType) {
-
-  /*
-   * objects with Delay arguments for functional programming construction of
-   * cyclic graphs, need a way to force the delays, resulting in an ordinary
-   * (though cyclic) data structure.
-   */
-  final override def initialize(): Unit = {
-    super.initialize()
-    maybeInputTypeCalc
-    maybeOutputTypeCalc
-  }
-
-  override def supportsParse = maybeInputTypeCalc.isDefined
-  override def supportsUnparse = maybeOutputTypeCalc.isDefined
-
-  /*
-   * Compiling DPath expressions may need to evaluate typeCalculators in order 
to lookup their srcType and dstType.
-   * To prevent circular dependencies, this means that the underlying 
expressions must be lazy.
-   *
-   * Since these fields must be lazy, we cannot use them to determine 
supportsParse or supportUnparse
-   */
-  lazy val maybeInputTypeCalc = maybeInputTypeCalcDelay.value
-  lazy val maybeOutputTypeCalc = maybeOutputTypeCalcDelay.value
-
-  // The class TypeValueCalc will verify that supports(Un)Parse is true when 
nessasary
-  // Therefore, if we ever call the below functions, we know that the relevent 
Maybe object is defined.
-
-  // TODO, pass x into DPath state
-
+class IdentityTypeCalculator(srcType: NodeInfo.Kind) extends 
TypeCalculator(srcType, srcType) {
   override def inputTypeCalc(
     x: DataValuePrimitive,
     xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) =
-    Assert.invariantFailed(
-      "inputTypeCalc not implemented on ExpressionTypeCalculator. Call the 
more specialized forms directly",
-    )
+  ): Either[Error, DataValuePrimitiveNullable] = Right(x)
   override def outputTypeCalc(
     x: DataValuePrimitive,
     xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) =
-    Assert.invariantFailed(
-      "outputTypeCalc not implemented on ExpressionTypeCalculator. Call the 
more specialized forms directly",
-    )
-
-  override def inputTypeCalcParse(
-    state: PState,
-    context: RuntimeData,
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): DataValuePrimitiveNullable = {
-    val dstate = state.dState
-    val oldRepValue = dstate.repValue
-    val oldLogicalValue = dstate.logicalValue
-    dstate.repValue = x
-    dstate.logicalValue = DataValue.NoValue
-
-    val ans = Maybe(maybeInputTypeCalc.get.evaluate(state))
-
-    dstate.repValue = oldRepValue
-    dstate.logicalValue = oldLogicalValue
-    if (ans.isDefined) {
-      DataValue.unsafeFromAnyRef(ans.get)
-    } else {
-      DataValue.NoValue;
-    }
-  }
-  override def outputTypeCalcUnparse(
-    state: UState,
-    context: RuntimeData,
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): DataValuePrimitiveNullable = {
-    val dstate = state.dState
-    val oldRepValue = dstate.repValue
-    val oldLogicalValue = dstate.logicalValue
-    dstate.repValue = DataValue.NoValue
-    dstate.logicalValue = x
-
-    val ans = maybeOutputTypeCalc.get.evaluate(state)
-
-    dstate.repValue = oldRepValue
-    dstate.logicalValue = oldLogicalValue
-    DataValue.unsafeFromAnyRef(ans)
-  }
-
-  override def inputTypeCalcRun(
-    dstate: DState,
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): Unit = {
-    val oldRepValue = dstate.repValue
-    val oldLogicalValue = dstate.logicalValue
-    dstate.repValue = x
-    dstate.logicalValue = DataValue.NoValue
-
-    maybeInputTypeCalc.get.run(dstate)
-
-    dstate.repValue = oldRepValue
-    dstate.logicalValue = oldLogicalValue
-
-  }
-  override def outputTypeCalcRun(
-    dstate: DState,
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): Unit = {
-    val oldRepValue = dstate.repValue
-    val oldLogicalValue = dstate.logicalValue
-    dstate.repValue = DataValue.NoValue
-    dstate.logicalValue = x
-
-    maybeOutputTypeCalc.get.run(dstate)
-
-    dstate.repValue = oldRepValue
-    dstate.logicalValue = oldLogicalValue
-  }
-}
-
-class IdentifyTypeCalculator(srcType: NodeInfo.Kind) extends 
TypeCalculator(srcType, srcType) {
-  override def inputTypeCalc(
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) = (x, Maybe.Nope)
-  override def outputTypeCalc(
-    x: DataValuePrimitive,
-    xType: NodeInfo.Kind,
-  ): (DataValuePrimitiveNullable, Maybe[Error]) = (x, Maybe.Nope)
+  ): Either[Error, DataValuePrimitiveNullable] = Right(x)
 }
 
 class UnionTypeCalculator(

Review Comment:
   That said, are we sure we're not introducing yet another backward 
incompatibility.. We need to look at the complex schemas that were using 
inputTypeCalc et al, and see if they're using these union features. 



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

Reply via email to