/** * Optimize an expression, via the ExpressionVisitor * @param exp the expression to be typechecked * @param contextItemType the static type of the context item for this expression * @return the rewritten expression * @throws XPathException */ public Expression optimize(Expression exp, ItemType contextItemType) throws XPathException { if (exp != null) { stack.push(exp); Expression exp2 = exp.optimize(this, contextItemType); stack.pop(); return exp2; } else { return null; } }
/** * Optimize an expression, via the ExpressionVisitor * @param exp the expression to be typechecked * @param contextItemType the static type of the context item for this expression * @return the rewritten expression * @throws XPathException */ public Expression optimize(Expression exp, ItemType contextItemType) throws XPathException { if (exp != null) { stack.push(exp); Expression exp2 = exp.optimize(this, contextItemType); stack.pop(); return exp2; } else { return null; } }
@Override public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e = super.optimize(visitor, contextInfo); if (e != this) { return e; } return preEvaluate(visitor); }
@Override public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e = super.optimize(visitor, contextInfo); if (e != this) { return e; } return preEvaluate(visitor); }
@Override public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { if (getBaseExpression() instanceof HomogeneityChecker) { return getBaseExpression().optimize(visitor, contextInfo); } return super.optimize(visitor, contextInfo); }
@Override public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { if (getBaseExpression() instanceof HomogeneityChecker) { return getBaseExpression().optimize(visitor, contextInfo); } return super.optimize(visitor, contextInfo); }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { //function.setOnFirstCall(new DeferredAction(visitor, contextItemType)); Expression e = super.optimize(visitor, contextItemType); if (e == this && function != null) { Expression e2 = visitor.obtainOptimizer().tryInlineFunctionCall( this, visitor, contextItemType); if (e2 != this) { return e2.optimize(visitor, contextItemType); } return e2; } return e; }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { //function.setOnFirstCall(new DeferredAction(visitor, contextItemType)); Expression e = super.optimize(visitor, contextItemType); if (e == this && function != null) { Expression e2 = visitor.obtainOptimizer().tryInlineFunctionCall( this, visitor, contextItemType); if (e2 != this) { return e2.optimize(visitor, contextItemType); } return e2; } return e; }
@Override public Pattern optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { ContextItemStaticInfo cit = visitor.getConfiguration().getDefaultContextItemStaticInfo(); expressionOp.setChildExpression(getPredicate().optimize(visitor, cit)); return this; }
@Override public Pattern optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { ContextItemStaticInfo cit = visitor.getConfiguration().getDefaultContextItemStaticInfo(); expressionOp.setChildExpression(getPredicate().optimize(visitor, cit)); return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { select = visitor.optimize(select, contextItemType); adoptChildExpression(select); regex = visitor.optimize(regex, contextItemType); adoptChildExpression(regex); flags = visitor.optimize(flags, contextItemType); adoptChildExpression(flags); if (matching != null) { matching = matching.optimize(visitor, BuiltInAtomicType.STRING); adoptChildExpression(matching); } if (nonMatching != null) { nonMatching = nonMatching.optimize(visitor, BuiltInAtomicType.STRING); adoptChildExpression(nonMatching); } return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); select = visitor.optimize(select, contextItemType); adoptChildExpression(select); action = action.optimize(visitor, select.getItemType(th)); adoptChildExpression(action); finallyExp = finallyExp.optimize(visitor, select.getItemType(th)); adoptChildExpression(finallyExp); if (Literal.isEmptySequence(select)) { return select; } if (Literal.isEmptySequence(action)) { return action; } return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); setStartExpression(visitor.optimize(start, contextItemType)); setStepExpression(step.optimize(visitor, start.getItemType(th))); return promoteFocusIndependentSubexpressions(visitor, contextItemType); }
/** * Type-check the expression. */ /*@NotNull*/ public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression exp = super.typeCheck(visitor, contextInfo); if (exp instanceof IntegratedFunctionCall) { Expression exp2 = ((IntegratedFunctionCall) exp).function.rewrite(visitor.getStaticContext(), getArguments()); if (exp2 == null) { return exp; } else { ExpressionTool.copyLocationInfo(this, exp2); return exp2.simplify().typeCheck(visitor, contextInfo).optimize(visitor, contextInfo); } } return exp; }
/** * Type-check the expression. */ /*@NotNull*/ public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression exp = super.typeCheck(visitor, contextInfo); if (exp instanceof IntegratedFunctionCall) { Expression exp2 = ((IntegratedFunctionCall) exp).function.rewrite(visitor.getStaticContext(), getArguments()); if (exp2 == null) { return exp; } else { ExpressionTool.copyLocationInfo(this, exp2); return exp2.simplify().typeCheck(visitor, contextInfo).optimize(visitor, contextInfo); } } return exp; }
public Expression optimize(/*@NotNull*/ ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { Expression e = super.optimize(visitor, contextItemType); if (e == this) { Expression ebv = rewriteEffectiveBooleanValue(getArg(0), visitor, contextItemType); if (ebv != null) { ebv = ebv.optimize(visitor, contextItemType); if (ebv.getItemType() == BuiltInAtomicType.BOOLEAN && ebv.getCardinality() == StaticProperty.EXACTLY_ONE) { ebv.setParentExpression(getParentExpression()); return ebv; } else { setArg(0, ebv); adoptChildExpression(ebv); return this; } } } return e; }
public Expression optimize(/*@NotNull*/ ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { Expression e = super.optimize(visitor, contextItemType); if (e == this) { Expression ebv = rewriteEffectiveBooleanValue(getArg(0), visitor, contextItemType); if (ebv != null) { ebv = ebv.optimize(visitor, contextItemType); if (ebv.getItemType() == BuiltInAtomicType.BOOLEAN && ebv.getCardinality() == StaticProperty.EXACTLY_ONE) { ebv.setParentExpression(getParentExpression()); return ebv; } else { setArg(0, ebv); adoptChildExpression(ebv); return this; } } } return e; }
/** * Allow the function to create an optimized call based on the values of the actual arguments * * @param visitor the expression visitor * @param contextInfo information about the context item * @param arguments the supplied arguments to the function call * @return either a function call on this function, or an expression that delivers * the same result, or null indicating that no optimization has taken place * @throws net.sf.saxon.trans.XPathException if an error is detected */ @Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { TypeHierarchy th = visitor.getStaticContext().getConfiguration().getTypeHierarchy(); if (arguments[0] instanceof Negatable && ((Negatable) arguments[0]).isNegatable(th)) { return ((Negatable) arguments[0]).negate(); } if (arguments[0].getItemType() instanceof NodeTest) { SystemFunction empty = SystemFunction.makeFunction("empty", getRetainedStaticContext(), 1); return empty.makeFunctionCall(arguments[0]).optimize(visitor, contextInfo); } return null; }
public void optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { try { setChildExpression(getChildExpression().optimize(visitor, contextInfo)); } catch (XPathException e) { e.maybeSetLocation(getChildExpression().getLocation()); if (!e.isReportableStatically()) { visitor.getStaticContext().issueWarning( "Evaluation will always throw a dynamic error: " + e.getMessage(), getChildExpression().getLocation()); setChildExpression(new ErrorExpression(e)); } else { throw e; } } }
public void optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { try { setChildExpression(getChildExpression().optimize(visitor, contextInfo)); } catch (XPathException e) { e.maybeSetLocation(getChildExpression().getLocation()); if (!e.isReportableStatically()) { visitor.getStaticContext().issueWarning( "Evaluation will always throw a dynamic error: " + e.getMessage(), getChildExpression().getLocation()); setChildExpression(new ErrorExpression(e)); } else { throw e; } } }