/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new CompareToIntegerConstant(operand.copy(), operator, comparand); }
public Operand getLhs() { return getOperand(); }
/** * Create the expression * @param operand the operand to be compared with an integer constant * @param operator the comparison operator, * one of {@link Token#FEQ}, {@link Token#FNE}, {@link Token#FGE}, * {@link Token#FGT}, {@link Token#FLE}, {@link Token#FLT} * @param comparand the integer constant */ public CompareToIntegerConstant(Expression operand, int operator, long comparand) { this.operand = operand; this.operator = operator; this.comparand = comparand; adoptChildExpression(operand); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { CompareToIntegerConstant c2 = new CompareToIntegerConstant(getLhsExpression().copy(rebindings), operator, comparand); ExpressionTool.copyLocationInfo(this, c2); return c2; }
/** * Perform optimisation of an expression and its subexpressions. This is the third and final * phase of static optimization. * <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 the expression visitor * @param contextInfo 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 contextInfo) throws XPathException { getOperand().optimize(visitor, contextInfo); if (getLhsExpression() instanceof Literal) { return Literal.makeLiteral(BooleanValue.get(effectiveBooleanValue(null)), this); } return this; }
/** * Evaluate an expression as a single item. This always returns either a single Item or * null (denoting the empty sequence). No conversion is done. This method should not be * used unless the static type of the expression is a subtype of "item" or "item?": that is, * it should not be called if the expression may return a sequence. There is no guarantee that * this condition will be detected. * * @param context The context in which the expression is to be evaluated * @return the node or atomic value that results from evaluating the * expression; or null to indicate that the result is an empty * sequence * @throws net.sf.saxon.trans.XPathException * if any dynamic error occurs evaluating the * expression */ public BooleanValue evaluateItem(XPathContext context) throws XPathException { return BooleanValue.get(effectiveBooleanValue(context)); }
public AbstractExpression exprFor (CompareToIntegerConstant comp) { Operator op = operatorFor (comp.getComparisonOperator()); long num = comp.getComparand(); return new BinaryOperation (exprFor (comp.getOperand()), op, new LiteralExpression (num)); }
/** * Is this expression the same as another expression? * * @param other the expression to be compared with this one * @return true if the two expressions are statically equivalent */ @Override public boolean equals(Object other) { return other instanceof CompareToIntegerConstant && ((CompareToIntegerConstant)other).getLhsExpression().isEqual(getLhsExpression()) && ((CompareToIntegerConstant)other).comparand == comparand && ((CompareToIntegerConstant)other).operator == operator; }
public Expression getLhsExpression() { return getBaseExpression(); }
public Operand getRhs() { return new Operand(this, getRhsExpression(), OperandRole.SINGLE_ATOMIC); }
/** * Offer promotion for this subexpression. The offer will be accepted if the subexpression * is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. * By default the offer is not accepted - this is appropriate in the case of simple expressions * such as constant values and variable references where promotion would give no performance * advantage. This method is always called at compile time. * * @param offer details of the offer, for example the offer to move * expressions that don't depend on the context to an outer level in * the containing expression * @return if the offer is not accepted, return this expression unchanged. * Otherwise return the result of rewriting the expression to promote * this subexpression * @throws net.sf.saxon.trans.XPathException * if any error is detected */ public Expression promote(PromotionOffer offer) throws XPathException { Expression exp = offer.accept(this); if (exp != null) { return exp; } else { operand = doPromotion(operand, offer); return this; } }
/** * Perform optimisation of an expression and its subexpressions. This is the third and final * phase of static optimization. * <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 the expression visitor * @param contextInfo 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 contextInfo) throws XPathException { getOperand().optimize(visitor, contextInfo); if (getLhsExpression() instanceof Literal) { return Literal.makeLiteral(BooleanValue.get(effectiveBooleanValue(null)), this); } return this; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { CompareToIntegerConstant c2 = new CompareToIntegerConstant(getLhsExpression().copy(rebindings), operator, comparand); ExpressionTool.copyLocationInfo(this, c2); return c2; }
/** * Evaluate an expression as a single item. This always returns either a single Item or * null (denoting the empty sequence). No conversion is done. This method should not be * used unless the static type of the expression is a subtype of "item" or "item?": that is, * it should not be called if the expression may return a sequence. There is no guarantee that * this condition will be detected. * * @param context The context in which the expression is to be evaluated * @return the node or atomic value that results from evaluating the * expression; or null to indicate that the result is an empty * sequence * @throws net.sf.saxon.trans.XPathException * if any dynamic error occurs evaluating the * expression */ public BooleanValue evaluateItem(XPathContext context) throws XPathException { return BooleanValue.get(effectiveBooleanValue(context)); }
/** * Is this expression the same as another expression? * * @param other the expression to be compared with this one * @return true if the two expressions are statically equivalent */ @Override public boolean equals(Object other) { return other instanceof CompareToIntegerConstant && ((CompareToIntegerConstant)other).getLhsExpression().isEqual(getLhsExpression()) && ((CompareToIntegerConstant)other).comparand == comparand && ((CompareToIntegerConstant)other).operator == operator; }
public Expression getLhsExpression() { return getBaseExpression(); }
public Operand getRhs() { return new Operand(this, getRhsExpression(), OperandRole.SINGLE_ATOMIC); }
/** * Offer promotion for this subexpression. The offer will be accepted if the subexpression * is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. * By default the offer is not accepted - this is appropriate in the case of simple expressions * such as constant values and variable references where promotion would give no performance * advantage. This method is always called at compile time. * * @param offer details of the offer, for example the offer to move * expressions that don't depend on the context to an outer level in * the containing expression * @return if the offer is not accepted, return this expression unchanged. * Otherwise return the result of rewriting the expression to promote * this subexpression * @throws net.sf.saxon.trans.XPathException * if any error is detected */ public Expression promote(PromotionOffer offer) throws XPathException { Expression exp = offer.accept(this); if (exp != null) { return exp; } else { operand = doPromotion(operand, offer); return this; } }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new CompareToIntegerConstant(operand.copy(), operator, comparand); }
/** * Evaluate an expression as a single item. This always returns either a single Item or * null (denoting the empty sequence). No conversion is done. This method should not be * used unless the static type of the expression is a subtype of "item" or "item?": that is, * it should not be called if the expression may return a sequence. There is no guarantee that * this condition will be detected. * * @param context The context in which the expression is to be evaluated * @return the node or atomic value that results from evaluating the * expression; or null to indicate that the result is an empty * sequence * @throws net.sf.saxon.trans.XPathException * if any dynamic error occurs evaluating the * expression */ public Item evaluateItem(XPathContext context) throws XPathException { return BooleanValue.get(effectiveBooleanValue(context)); }