jadams-tresys commented on a change in pull request #450:
URL: https://github.com/apache/incubator-daffodil/pull/450#discussion_r539448867
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/VariableMap1.scala
##########
@@ -232,19 +345,33 @@ class VariableMap private(vTable: Map[GlobalQName,
MStackOf[VariableInstance]])
*/
def readVariable(vrd: VariableRuntimeData, referringContext: ThrowsSDE,
maybePstate: Maybe[ParseOrUnparseState]): DataValuePrimitive = {
val varQName = vrd.globalQName
- val stack = vTable.get(varQName)
- if (stack.isDefined) {
- val variable = stack.get.top
- variable.state match {
- case VariableRead if (variable.value.isDefined) =>
variable.value.getNonNullable
- case VariableDefined | VariableSet if (variable.value.isDefined) => {
+ val abuf = vTable.get(varQName)
+ if (abuf.isDefined) {
+ val variable = abuf.get.last
+ (variable.state, variable.value.isDefined,
variable.defaultValueExpr.isDefined) match {
+ case (VariableRead, true, _) => variable.value.getNonNullable
+ case (VariableDefined | VariableSet, true, _) => {
if (maybePstate.isDefined && maybePstate.get.isInstanceOf[PState])
maybePstate.get.asInstanceOf[PState].markVariableRead(vrd)
variable.setState(VariableRead)
variable.value.getNonNullable
}
- case _ => throw new VariableHasNoValue(varQName, vrd)
+ case (VariableDefined, false, true) => {
+ Assert.invariant(maybePstate.isDefined)
+ variable.setState(VariableInProcess)
+ val pstate = maybePstate.get
+ val res =
DataValue.unsafeFromAnyRef(variable.defaultValueExpr.get.evaluate(pstate))
+
+ // Need to update the variable's value with the result of the
+ // expression
+ variable.setState(VariableRead)
+ variable.setValue(res)
+
+ res
+ }
+ case (VariableInProcess, _, _) => throw new
VariableCircularDefinition(varQName, vrd)
+ case (_, _, _) => throw new VariableHasNoValue(varQName, vrd)
Review comment:
This is covered by the tests that were mentioned in DAFFODIL-2443 which,
thanks to the changes you suggested for moving the forceExpressionEvaluations
inside the doParse try block, now work as expected and hit these cases.
----------------------------------------------------------------
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]