/** * Construct a list containing the "anded" subexpressions of an expression: * if the expression is (A and B and C), this returns (A, B, C). * * @param exp the expression to be decomposed * @param list the list to which the subexpressions are to be added. */ public static void listAndComponents(Expression exp, List<Expression> list) { if (exp instanceof BooleanExpression && ((BooleanExpression) exp).getOperator() == Token.AND) { for (Operand o : exp.operands()) { listAndComponents(o.getChildExpression(), list); } } else { list.add(exp); } }
/** * Evaluate the expression */ public BooleanValue evaluateItem(XPathContext context) throws XPathException { return BooleanValue.get(effectiveBooleanValue(context)); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new BooleanExpression(operand0.copy(), operator, operand1.copy()); }
/** * Perform optimisation of an expression and its subexpressions. * <p>This method is called after all references to functions and variables have been resolved * to the declaration of the function or variable, and after all type checking has been done.</p> * * @param visitor an expression visitor * @param contextItemType the static type of "." at the point where this expression is invoked. * The parameter is set to null if it is known statically that the context item will be undefined. * If the type of the context item is not known statically, the argument is set to * {@link net.sf.saxon.type.Type#ITEM_TYPE} * @return the original expression, rewritten if appropriate to optimize execution * @throws XPathException if an error is discovered during this phase * (typically a type error) */ /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { optimizeChildren(visitor, contextItemType); boolean forStreaming = visitor.isOptimizeForStreaming(); setLhsExpression(ExpressionTool.unsortedIfHomogeneous(getLhsExpression(), forStreaming)); setRhsExpression(ExpressionTool.unsortedIfHomogeneous(getRhsExpression(), forStreaming)); Expression op0 = BooleanFn.rewriteEffectiveBooleanValue(getLhsExpression(), visitor, contextItemType); if (op0 != null) { setLhsExpression(op0); } Expression op1 = BooleanFn.rewriteEffectiveBooleanValue(getRhsExpression(), visitor, contextItemType); if (op1 != null) { setRhsExpression(op1); } return preEvaluate(); }
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { getLhs().typeCheck(visitor, contextInfo); getRhs().typeCheck(visitor, contextInfo); TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); XPathException err0 = TypeChecker.ebvError(getLhsExpression(), th); if (err0 != null) { err0.setLocator(getLocation()); throw err0; } XPathException err1 = TypeChecker.ebvError(getRhsExpression(), th); if (err1 != null) { err1.setLocator(getLocation()); throw err1; } // Precompute the EBV of any constant operand if (getLhsExpression() instanceof Literal && !(((Literal) getLhsExpression()).getValue() instanceof BooleanValue)) { setLhsExpression(Literal.makeLiteral( BooleanValue.get(getLhsExpression().effectiveBooleanValue(visitor.makeDynamicContext())), this)); } if (getRhsExpression() instanceof Literal && !(((Literal) getRhsExpression()).getValue() instanceof BooleanValue)) { setRhsExpression(Literal.makeLiteral( BooleanValue.get(getRhsExpression().effectiveBooleanValue(visitor.makeDynamicContext())), this)); } return preEvaluate(); }
BooleanExpression.listAndComponents(condition, list); for (int i = list.size() - 1; i >= 0; i--) { Expression term = (Expression) list.get(i); promotedCondition = term; } else { promotedCondition = new BooleanExpression(term, Token.AND, promotedCondition); retainedCondition = new BooleanExpression(retainedCondition, Token.AND, (Expression) list.get(i));
FunctionCall e1 = SystemFunction.makeSystemFunction( getFunctionName().getLocalName(), new Expression[]{v.getOperands()[1]}); return new BooleanExpression(e0, newop, e1).optimize(visitor, contextItemType);
/** * Get a name identifying the kind of expression, in terms meaningful to a user. * * @return a name identifying the kind of expression, in terms meaningful to a user. * The name will always be in the form of a lexical XML QName, and should match the name used * in explain() output displaying the expression. */ @Override public String getExpressionName() { return Token.tokens[getOperator()] + "-expression"; }
/** * Perform optimisation of an expression and its subexpressions. * <p>This method is called after all references to functions and variables have been resolved * to the declaration of the function or variable, and after all type checking has been done.</p> * * @param visitor an expression visitor * @param contextItemType the static type of "." at the point where this expression is invoked. * The parameter is set to null if it is known statically that the context item will be undefined. * If the type of the context item is not known statically, the argument is set to * {@link net.sf.saxon.type.Type#ITEM_TYPE} * @return the original expression, rewritten if appropriate to optimize execution * @throws XPathException if an error is discovered during this phase * (typically a type error) */ /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { final Expression e = super.optimize(visitor, contextItemType); if (e != this) { return e; } // If this is a top-level or-expression then try to replace multiple branches with a general comparison if (!(getParentExpression() instanceof OrExpression)) { final Expression e2 = visitor.obtainOptimizer().tryGeneralComparison(visitor, contextItemType, this); if (e2 != null && e2 != this) { return e2; } } return this; }
Expression condition = whereClause.getPredicate(); List<Expression> list = new ArrayList<>(5); BooleanExpression.listAndComponents(condition, list); for (int i = list.size() - 1; i >= 0; i--) { Expression term = list.get(i);
((BooleanExpression) getFilter()).operator == Token.AND) { BooleanExpression bf = (BooleanExpression) getFilter(); if (isExplicitlyPositional(bf.getLhsExpression()) && !isExplicitlyPositional(bf.getRhsExpression())) { Expression p0 = forceToBoolean(bf.getLhsExpression()); Expression p1 = forceToBoolean(bf.getRhsExpression()); FilterExpression f1 = new FilterExpression(getBase(), p0); ExpressionTool.copyLocationInfo(this, f1); if (isExplicitlyPositional(bf.getRhsExpression()) && !isExplicitlyPositional(bf.getLhsExpression())) { Expression p0 = forceToBoolean(bf.getLhsExpression()); Expression p1 = forceToBoolean(bf.getRhsExpression()); FilterExpression f1 = new FilterExpression(getBase(), p1); ExpressionTool.copyLocationInfo(this, f1);
protected Expression forceToBoolean(Expression in) { if (in.getItemType() == BuiltInAtomicType.BOOLEAN && in.getCardinality() == StaticProperty.ALLOWS_ONE) { return in; } else { return SystemFunction.makeCall("boolean", getRetainedStaticContext(), in); } }
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { getLhs().typeCheck(visitor, contextInfo); getRhs().typeCheck(visitor, contextInfo); TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); XPathException err0 = TypeChecker.ebvError(getLhsExpression(), th); if (err0 != null) { err0.setLocator(getLocation()); throw err0; } XPathException err1 = TypeChecker.ebvError(getRhsExpression(), th); if (err1 != null) { err1.setLocator(getLocation()); throw err1; } // Precompute the EBV of any constant operand if (getLhsExpression() instanceof Literal && !(((Literal) getLhsExpression()).getValue() instanceof BooleanValue)) { setLhsExpression(Literal.makeLiteral( BooleanValue.get(getLhsExpression().effectiveBooleanValue(visitor.makeDynamicContext())), this)); } if (getRhsExpression() instanceof Literal && !(((Literal) getRhsExpression()).getValue() instanceof BooleanValue)) { setRhsExpression(Literal.makeLiteral( BooleanValue.get(getRhsExpression().effectiveBooleanValue(visitor.makeDynamicContext())), this)); } return preEvaluate(); }
BooleanExpression.listAndComponents(condition, list); for (int i = list.size() - 1; i >= 0; i--) { Expression term = (Expression) list.get(i); promotedCondition = term; } else { promotedCondition = new BooleanExpression(term, Token.AND, promotedCondition); retainedCondition = new BooleanExpression(retainedCondition, Token.AND, (Expression) list.get(i));
/** * Perform optimisation of an expression and its subexpressions. * <p>This method is called after all references to functions and variables have been resolved * to the declaration of the function or variable, and after all type checking has been done.</p> * * @param visitor an expression visitor * @param contextItemType the static type of "." at the point where this expression is invoked. * The parameter is set to null if it is known statically that the context item will be undefined. * If the type of the context item is not known statically, the argument is set to * {@link net.sf.saxon.type.Type#ITEM_TYPE} * @return the original expression, rewritten if appropriate to optimize execution * @throws XPathException if an error is discovered during this phase * (typically a type error) */ /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { optimizeChildren(visitor, contextItemType); boolean forStreaming = visitor.isOptimizeForStreaming(); setLhsExpression(ExpressionTool.unsortedIfHomogeneous(getLhsExpression(), forStreaming)); setRhsExpression(ExpressionTool.unsortedIfHomogeneous(getRhsExpression(), forStreaming)); Expression op0 = BooleanFn.rewriteEffectiveBooleanValue(getLhsExpression(), visitor, contextItemType); if (op0 != null) { setLhsExpression(op0); } Expression op1 = BooleanFn.rewriteEffectiveBooleanValue(getRhsExpression(), visitor, contextItemType); if (op1 != null) { setRhsExpression(op1); } return preEvaluate(); }
FunctionCall e1 = SystemFunction.makeSystemFunction( getFunctionName().getLocalName(), new Expression[]{v.getOperands()[1]}); return new BooleanExpression(e0, newop, e1).optimize(visitor, contextItemType);
/** * Get a name identifying the kind of expression, in terms meaningful to a user. * * @return a name identifying the kind of expression, in terms meaningful to a user. * The name will always be in the form of a lexical XML QName, and should match the name used * in explain() output displaying the expression. */ @Override public String getExpressionName() { return Token.tokens[getOperator()] + "-expression"; }
/** * Perform optimisation of an expression and its subexpressions. * <p>This method is called after all references to functions and variables have been resolved * to the declaration of the function or variable, and after all type checking has been done.</p> * * @param visitor an expression visitor * @param contextItemType the static type of "." at the point where this expression is invoked. * The parameter is set to null if it is known statically that the context item will be undefined. * If the type of the context item is not known statically, the argument is set to * {@link net.sf.saxon.type.Type#ITEM_TYPE} * @return the original expression, rewritten if appropriate to optimize execution * @throws XPathException if an error is discovered during this phase * (typically a type error) */ /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { final Expression e = super.optimize(visitor, contextItemType); if (e != this) { return e; } // If this is a top-level or-expression then try to replace multiple branches with a general comparison if (!(getParentExpression() instanceof OrExpression)) { final Expression e2 = visitor.obtainOptimizer().tryGeneralComparison(visitor, contextItemType, this); if (e2 != null && e2 != this) { return e2; } } return this; }
Expression condition = whereClause.getPredicate(); List<Expression> list = new ArrayList<>(5); BooleanExpression.listAndComponents(condition, list); for (int i = list.size() - 1; i >= 0; i--) { Expression term = list.get(i);
((BooleanExpression) getFilter()).operator == Token.AND) { BooleanExpression bf = (BooleanExpression) getFilter(); if (isExplicitlyPositional(bf.getLhsExpression()) && !isExplicitlyPositional(bf.getRhsExpression())) { Expression p0 = forceToBoolean(bf.getLhsExpression()); Expression p1 = forceToBoolean(bf.getRhsExpression()); FilterExpression f1 = new FilterExpression(getBase(), p0); ExpressionTool.copyLocationInfo(this, f1); if (isExplicitlyPositional(bf.getRhsExpression()) && !isExplicitlyPositional(bf.getLhsExpression())) { Expression p0 = forceToBoolean(bf.getLhsExpression()); Expression p1 = forceToBoolean(bf.getRhsExpression()); FilterExpression f1 = new FilterExpression(getBase(), p1); ExpressionTool.copyLocationInfo(this, f1);