/** * Make an expression visitor * @return the expression visitor */ public ExpressionVisitor makeExpressionVisitor() { ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); return visitor; }
/** * Make an expression visitor * @return the expression visitor */ public ExpressionVisitor makeExpressionVisitor() { ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); return visitor; }
/** * Perform type checking on global variables. * <p>This method is intended for internal use</p> * @param compiledVars a list of {@link GlobalVariableDefinition} objects to be checked */ public void typeCheckGlobalVariables(List compiledVars) throws XPathException { ExpressionVisitor visitor = ExpressionVisitor.make(this); visitor.setExecutable(getExecutable()); Iterator iter = compiledVars.iterator(); //Stack stack = new Stack(); while (iter.hasNext()) { GlobalVariableDefinition gvd = (GlobalVariableDefinition)iter.next(); //GlobalVariable gv = gvd.getCompiledVariable(); //gv.lookForCycles(stack); gvd.typeCheck(visitor); } }
/** * Perform type checking on global variables. * <p>This method is intended for internal use</p> * @param compiledVars a list of {@link GlobalVariableDefinition} objects to be checked */ public void typeCheckGlobalVariables(List compiledVars) throws XPathException { ExpressionVisitor visitor = ExpressionVisitor.make(this); visitor.setExecutable(getExecutable()); Iterator iter = compiledVars.iterator(); //Stack stack = new Stack(); while (iter.hasNext()) { GlobalVariableDefinition gvd = (GlobalVariableDefinition)iter.next(); //GlobalVariable gv = gvd.getCompiledVariable(); //gv.lookForCycles(stack); gvd.typeCheck(visitor); } }
/** * Fixup all references to global functions. This method is called * on completion of query parsing. Each XQueryFunction is required to * bind all references to that function to the object representing the run-time * executable code of the function. * <p> * This method is for internal use. * @param env the static context for the main query body. */ protected void fixupGlobalFunctions(QueryModule env) throws XPathException { ExpressionVisitor visitor = ExpressionVisitor.make(env); Iterator iter = functions.values().iterator(); while (iter.hasNext()) { XQueryFunction fn = (XQueryFunction)iter.next(); fn.compile(); } iter = functions.values().iterator(); while (iter.hasNext()) { XQueryFunction fn = (XQueryFunction)iter.next(); visitor.setExecutable(fn.getExecutable()); fn.checkReferences(visitor); } }
/** * Fixup all references to global functions. This method is called * on completion of query parsing. Each XQueryFunction is required to * bind all references to that function to the object representing the run-time * executable code of the function. * <p> * This method is for internal use. * @param env the static context for the main query body. */ protected void fixupGlobalFunctions(QueryModule env) throws XPathException { ExpressionVisitor visitor = ExpressionVisitor.make(env); Iterator iter = functions.values().iterator(); while (iter.hasNext()) { XQueryFunction fn = (XQueryFunction)iter.next(); fn.compile(); } iter = functions.values().iterator(); while (iter.hasNext()) { XQueryFunction fn = (XQueryFunction)iter.next(); visitor.setExecutable(fn.getExecutable()); fn.checkReferences(visitor); } }
Expression exp = ExpressionTool.make(expression, staticContext,0,-1,1, false); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); exp = visitor.typeCheck(exp, Type.ITEM_TYPE); SlotManager map = staticContext.getConfiguration().makeSlotManager();
/** * Static method to make a Pattern by parsing a String. <br> * @param pattern The pattern text as a String * @param env An object defining the compile-time context for the expression * @param exec The executable containing this pattern * @return The pattern object */ public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); pat.setSystemId(env.getSystemId()); pat.setLineNumber(env.getLineNumber()); // System.err.println("Simplified [" + pattern + "] to " + pat.getClass() + " default prio = " + pat.getDefaultPriority()); // set the pattern text for use in diagnostics pat.setOriginalText(pattern); pat.setExecutable(exec); ExpressionVisitor visitor = ExpressionVisitor.make(env); visitor.setExecutable(exec); pat = pat.simplify(visitor); return pat; }
/** * Prepare (compile) an XPath expression for subsequent evaluation. * @param expression The XPath expression to be compiled, supplied as a string. * @return an XPathExpression object representing the prepared expression * @throws XPathException if the syntax of the expression is wrong, or if it references namespaces, * variables, or functions that have not been declared. */ public XPathExpression createExpression(String expression) throws XPathException { Expression exp = ExpressionTool.make(expression, staticContext, 0, -1, 1, false); exp.setContainer(staticContext); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); exp = visitor.typeCheck(exp, Type.ITEM_TYPE); SlotManager map = staticContext.getStackFrameMap(); int numberOfExternalVariables = map.getNumberOfVariables(); ExpressionTool.allocateSlots(exp, numberOfExternalVariables, map); XPathExpression xpe = new XPathExpression(this, exp); xpe.setStackFrameMap(map, numberOfExternalVariables); return xpe; }
/** * Static method to make a Pattern by parsing a String. <br> * @param pattern The pattern text as a String * @param env An object defining the compile-time context for the expression * @param exec The executable containing this pattern * @return The pattern object */ public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); pat.setSystemId(env.getSystemId()); pat.setLineNumber(env.getLineNumber()); // System.err.println("Simplified [" + pattern + "] to " + pat.getClass() + " default prio = " + pat.getDefaultPriority()); // set the pattern text for use in diagnostics pat.setOriginalText(pattern); pat.setExecutable(exec); ExpressionVisitor visitor = ExpressionVisitor.make(env); visitor.setExecutable(exec); pat = pat.simplify(visitor); return pat; }
/** * Static method to make a Pattern by parsing a String. <br> * @param pattern The pattern text as a String * @param env An object defining the compile-time context for the expression * @param exec The executable containing this pattern * @return The pattern object */ public static Pattern make(String pattern, StaticContext env, Executable exec) throws XPathException { Pattern pat = (new ExpressionParser()).parsePattern(pattern, env); pat.setSystemId(env.getSystemId()); pat.setLineNumber(env.getLineNumber()); // System.err.println("Simplified [" + pattern + "] to " + pat.getClass() + " default prio = " + pat.getDefaultPriority()); // set the pattern text for use in diagnostics pat.setOriginalText(pattern); pat.setExecutable(exec); ExpressionVisitor visitor = ExpressionVisitor.make(env); visitor.setExecutable(exec); pat = pat.simplify(visitor); return pat; }
private XPathExpressionImpl createExpressionInternal(String expression) throws net.sf.saxon.trans.XPathException { Expression exp = ExpressionTool.make(expression, staticContext, 0, -1, 1, false); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); exp = visitor.typeCheck(exp, Type.ITEM_TYPE); SlotManager map = staticContext.getConfiguration().makeSlotManager(); ExpressionTool.allocateSlots(exp, 0, map); exp.setContainer(staticContext); XPathExpressionImpl xpe = new XPathExpressionImpl(exp, getExecutable()); xpe.setStackFrameMap(map); if (contextNode != null) { xpe.privatelySetContextNode(contextNode); } return xpe; }
/** * Prepare (compile) an XPath expression for subsequent evaluation. * @param expression The XPath expression to be compiled, supplied as a string. * @return an XPathExpression object representing the prepared expression * @throws XPathException if the syntax of the expression is wrong, or if it references namespaces, * variables, or functions that have not been declared. */ public XPathExpression createExpression(String expression) throws XPathException { Expression exp = ExpressionTool.make(expression, staticContext, 0, -1, 1, false); exp.setContainer(staticContext); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); exp = visitor.typeCheck(exp, Type.ITEM_TYPE); exp = visitor.optimize(exp, Type.ITEM_TYPE); SlotManager map = staticContext.getStackFrameMap(); int numberOfExternalVariables = map.getNumberOfVariables(); ExpressionTool.allocateSlots(exp, numberOfExternalVariables, map); XPathExpression xpe = new XPathExpression(this, exp); xpe.setStackFrameMap(map, numberOfExternalVariables); return xpe; }
/** * Optimize the body of this function */ public void optimize() throws XPathException { ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); // body = visitor.simplify(body); // body = visitor.typeCheck(body, null); body = visitor.optimize(body, null); // Try to extract new global variables from the body of the function body = staticContext.getConfiguration().getOptimizer().promoteExpressionsToGlobal(body, visitor); // mark tail calls within the function body int arity = arguments.size(); int tailCalls = ExpressionTool.markTailFunctionCalls(body, functionName, arity); if (tailCalls != 0) { compiledFunction.setBody(body); compiledFunction.setTailRecursive(tailCalls > 0, tailCalls > 1); body = new TailCallLoop(compiledFunction); } body.setContainer(this); compiledFunction.setBody(body); compiledFunction.computeEvaluationMode(); ExpressionTool.allocateSlots(body, arity, compiledFunction.getStackFrameMap()); }
ufc.setFunction(fn); ExpressionVisitor visitor = ExpressionVisitor.make(fd.getStaticContext()); visitor.setExecutable(fd.getExecutable()); ufc.checkFunctionCall(fn, visitor);
ufc.setFunction(fn); ExpressionVisitor visitor = ExpressionVisitor.make(fd.getStaticContext()); visitor.setExecutable(fd.getExecutable()); ufc.checkFunctionCall(fn, visitor);
/** * Prepare and execute an XPath expression, supplied as a string, and returning the first * item in the result. This is useful where it is known that the expression will only return * a singleton value (for example, a single node, or a boolean). * @param expression The XPath expression to be evaluated, supplied as a string. * @return The first item in the sequence returned by the expression. If the expression * returns an empty sequence, this method returns null. Otherwise, it returns the first * item in the result sequence, represented as a Java object using the same mapping as for * the evaluate() method * @deprecated since Saxon 8.9 - use the methods defined in the JAXP interface */ public Object evaluateSingle(String expression) throws net.sf.saxon.trans.XPathException { Expression exp = ExpressionTool.make(expression, staticContext,0,-1,1, false); ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); exp = visitor.typeCheck(exp, Type.ITEM_TYPE); SlotManager map = staticContext.getConfiguration().makeSlotManager(); ExpressionTool.allocateSlots(exp, 0, map); XPathContextMajor context = new XPathContextMajor(contextNode, staticContext.getExecutable()); context.openStackFrame(map); SequenceIterator iterator = exp.iterate(context); Item item = iterator.next(); if (item == null) { return null; } else { return Value.convertToJava(item); } }
visitor.setExecutable(getExecutable()); body = visitor.optimize(body, null);
try { ExpressionVisitor visitor = ExpressionVisitor.make(mainModule); visitor.setExecutable(exec); exp = visitor.simplify(exp); exp = visitor.typeCheck(exp, mainModule.getUserQueryContext().getRequiredContextItemType());
try { ExpressionVisitor visitor = ExpressionVisitor.make(mainModule); visitor.setExecutable(exec); exp = visitor.simplify(exp); exp.checkForUpdatingSubexpressions();