/** * Type-check the pattern. This is needed for patterns that contain * variable references or function calls. * * @return the optimised Pattern */ public Pattern analyze(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { keyexp = visitor.typeCheck(keyexp, contextItemType); RoleLocator role = new RoleLocator(RoleLocator.FUNCTION, "key", 2, visitor.getConfiguration().getNamePool()); keyexp = TypeChecker.staticTypeCheck(keyexp, SequenceType.ATOMIC_SEQUENCE, false, role, visitor); keySet = visitor.getExecutable().getKeyManager().getKeyDefinitionSet(keyName); return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { select = visitor.optimize(select, contextItemType); separator = visitor.optimize(separator, contextItemType); if (select instanceof Literal && separator instanceof Literal) { XPathContext c = visitor.getStaticContext().makeEarlyEvaluationContext(); return Literal.makeLiteral(Value.asValue(evaluateItem(c))); } return this; }
/** * Type-check the expression. At this stage details of the static type must be known. * If the variable has a compile-time value, this is substituted for the variable reference */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { if (constantValue != null) { binding = null; return Literal.makeLiteral(constantValue); } // if (staticType == null) { // throw new IllegalStateException("Variable $" + getDisplayName() + " has not been fixed up"); // } if (binding instanceof Expression) { inLoop = visitor.isLoopingSubexpression((Expression)binding); // following code removed because it causes error181 to blow the stack - need to check for circularities well // if (binding instanceof GlobalVariable) { // ((GlobalVariable)binding).typeCheck(visitor, AnyItemType.getInstance()); // } } else if (binding instanceof UserFunctionParameter) { inLoop = visitor.isLoopingSubexpression(null); } return this; }
/** * Make an expression visitor * @return the expression visitor */ public ExpressionVisitor makeExpressionVisitor() { ExpressionVisitor visitor = ExpressionVisitor.make(staticContext); visitor.setExecutable(getExecutable()); return visitor; }
/** * Simplify and validate. * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { Atomizer a = new Atomizer(argument[0], visitor.getConfiguration()); ExpressionTool.copyLocationInfo(this, a); return visitor.simplify(a); }
/** * If any subexpressions within the step are not dependent on the focus, * and if they are not "creative" expressions (expressions that can create new nodes), then * promote them: this causes them to be evaluated once, outside the path expression * @param visitor the expression visitor * @param contextItemType the type of the context item for evaluating the start expression * @return the rewritten expression, or the original expression if no rewrite was possible */ protected Expression promoteFocusIndependentSubexpressions( ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { Optimizer opt = visitor.getConfiguration().getOptimizer(); PromotionOffer offer = new PromotionOffer(opt); offer.action = PromotionOffer.FOCUS_INDEPENDENT; offer.promoteDocumentDependent = (start.getSpecialProperties() & StaticProperty.CONTEXT_DOCUMENT_NODESET) != 0; offer.containingExpression = this; setStepExpression(doPromotion(step, offer)); visitor.resetStaticProperties(); if (offer.containingExpression != this) { offer.containingExpression = visitor.optimize(visitor.typeCheck(offer.containingExpression, contextItemType), contextItemType); return offer.containingExpression; } return this; }
NamePool namePool = visitor.getConfiguration().getNamePool(); StaticContext env = visitor.getStaticContext(); if (contextItemType == null) { XPathException err = new XPathException("Axis step " + toString(namePool) + (visitor.getParentExpression() instanceof Atomizer)) { env.issueWarning("Selecting the text nodes of an element with simple content may give the " + "wrong answer in the presence of comments or processing instructions. It is usually " + } else if (((ComplexType)contentType).isEmptyContent() && (axis==Axis.CHILD || axis==Axis.DESCENDANT || axis==Axis.DESCENDANT_OR_SELF)) { for (Iterator iter=visitor.getConfiguration().getExtensionsOfType(contentType); iter.hasNext();) { ComplexType extension = (ComplexType)iter.next(); if (!extension.isEmptyContent()) { new ContentTypeTest(Type.ELEMENT, schemaType, env.getConfiguration())); computedCardinality = ((ComplexType)contentType).getElementParticleCardinality(childElement); visitor.resetStaticProperties(); if (!Cardinality.allowsMany(computedCardinality)) { NodeTest childTest = makeUnionNodeTest(usefulChildren, visitor.getConfiguration().getNamePool()); AxisExpression first = new AxisExpression(Axis.CHILD, childTest); ExpressionTool.copyLocationInfo(this, first);
/** * Type-check the expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.typeCheck(operand, contextItemType); // If the configuration allows typed data, check whether the content type of these particular nodes is untyped final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); computeSingleValued(th); visitor.resetStaticProperties(); if (th.isSubType(operand.getItemType(th), BuiltInAtomicType.ANY_ATOMIC)) { return operand; } operand.setFlattened(true); return this; }
StaticContext env = visitor.getStaticContext(); Optimizer opt = visitor.getConfiguration().getOptimizer(); return visitor.optimize(sequence, contextItemType); Expression a = visitor.optimize(action, contextItemType); ExpressionTool.copyLocationInfo(this, a); return a; return visitor.optimize(action, contextItemType); Expression seq2 = visitor.optimize(sequence, contextItemType); if (seq2 == sequence) { break; visitor.resetStaticProperties(); Expression act2 = visitor.optimize(action, contextItemType); if (act2 == action) { break; visitor.resetStaticProperties();
/** * 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; }
checked = true; super.checkArguments(visitor); Optimizer opt = visitor.getConfiguration().getOptimizer(); argument[1] = ExpressionTool.unsorted(opt, argument[1], false); if (argument[0] instanceof StringLiteral) { keyName = ((ExpressionContext)visitor.getStaticContext()).getStructuredQName( ((StringLiteral)argument[0]).getStringValue(), false); } catch (XPathException e) { throw err; staticKeySet = visitor.getExecutable().getKeyManager().getKeyDefinitionSet(keyName); if (staticKeySet == null) { XPathException err = new XPathException("Key " + nsContext = visitor.getStaticContext().getNamespaceResolver();
/** * 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()); }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.optimize(operand, contextItemType); if ((operand.getSpecialProperties() & StaticProperty.ORDERED_NODESET) != 0) { // this can happen as a result of further simplification return operand; } if (operand instanceof PathExpression) { return visitor.getConfiguration().getOptimizer().makeConditionalDocumentSorter( this, (PathExpression)operand); } return this; }
public void checkArguments(ExpressionVisitor visitor) throws XPathException { if (expressionBaseURI == null) { // only do this once. The second call supplies an env pointing to the containing // xsl:template, which has a different base URI (and in a simplified stylesheet, has no base URI) super.checkArguments(visitor); expressionBaseURI = visitor.getStaticContext().getBaseURI(); Optimizer opt = visitor.getConfiguration().getOptimizer(); argument[0] = ExpressionTool.unsorted(opt, argument[0], false); } }
final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); Optimizer opt = visitor.getConfiguration().getOptimizer(); operand0 = ExpressionTool.unsortedIfHomogeneous(opt, operand0); operand1 = ExpressionTool.unsortedIfHomogeneous(opt, operand1); operand1 instanceof UserFunctionCall && th.isSubType(operand1.getItemType(th), BuiltInAtomicType.BOOLEAN) && !visitor.isLoopingSubexpression(null)) { Expression cond = Choose.makeConditional(operand0, operand1, Literal.makeLiteral(BooleanValue.FALSE)); ExpressionTool.copyLocationInfo(this, cond);
/** * Optimize the expression */ public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.optimize(operand, contextItemType); return this; }
/** * Simplify an expression * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { operand = visitor.simplify(operand); if (operand instanceof Literal) { return Literal.makeLiteral( new SequenceExtent(iterate(visitor.getStaticContext().makeEarlyEvaluationContext()))); } return this; }
public Expression simplify(ExpressionVisitor visitor) throws XPathException { if (select != null) { select = visitor.simplify(select); } return this; }
/** * Pre-evaluate the function * @param visitor an expression visitor */ public Expression preEvaluate(ExpressionVisitor visitor) throws XPathException { String s = visitor.getStaticContext().getDefaultCollationName(); return new StringLiteral(s); }