tuxji commented on a change in pull request #373:
URL: https://github.com/apache/incubator-daffodil/pull/373#discussion_r416792544
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/FNFunctions.scala
##########
@@ -706,6 +706,92 @@ case class FNLocalName1(recipe: CompiledDPath, argType:
NodeInfo.Kind)
}
}
+/**
+ * Returns the namespace URI of the name of \$arg as an xs:anyURI
+ * value.
+ *
+ * If the argument is omitted, it defaults to the context item (.).
+ * The behavior of the function if the argument is omitted is
+ * exactly the same as if the context item had been passed as
+ * the argument.
+ *
+ * If the node identified by \$arg is neither an element nor an
+ * attribute node, or it is an element or attribute node whose
+ * expanded-QName is in no namespace, then the function returns
+ * the zero-length xs:anyURI value.
+ *
+ * Otherwise, the result will be the namespace URI of the
+ * expanded-QName of the node identified by \$arg returned as an
+ * xs:anyURI value.
+ *
+ * The following errors may be raised when \$arg is omitted:
+ * - If the context item is absent, dynamic error [err:XPDY002]
+ * - If the context item is not a node, type error [err:XPTY004]
+ *
+ * This function is called when 0 arguments are provided. We
+ * treat this as if the argument passed was "." to denote self.
+ */
+case class FNNamespaceUri0(recipe: CompiledDPath, argType: NodeInfo.Kind)
+ extends RecipeOpWithSubRecipes(recipe) {
+ override def run(dstate: DState) {
+ // Hook so we can insist this is non-constant at compile time
+ dstate.fnExists()
Review comment:
To answer your question, FNLocalName0's code, which calls
dstate.currentElement.name, must be working OK even when dstate is a
DStateForConstantFolding object. I was getting a NullPointerException when
trying to call dstate.currentNode.namedQName in FNNamespaceUri0 because that
call goes through erd in dstate.currentNode, but DStateForConstantFolding
leaves erd null.
However, I notice that the zero-arg functions in DFDLXTypeCalcFunctions are
using a clearer and more logical way than fstate.fnExists() to terminate such
DStateForConstantFolding calls:
```
if (dstate.isCompile) {
throw new IllegalStateException()
}
```
I like that way better so I'll use it if we still need it. Not sure if
passing the argType as NodeInfo.Exists would prevent DStateForConstantFolding
calls entirely, but I'll find out.
----------------------------------------------------------------
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]