@Override public Expression makeFunctionCall(Expression[] arguments) { if (Literal.isAtomic(arguments[1])) { Sequence<?> index = ((Literal) arguments[1]).getValue(); if (index instanceof IntegerValue) { try { long value = ((IntegerValue) index).longValue(); if (value <= 0) { return arguments[0]; } else if (value == 1) { return new TailExpression(arguments[0], 2); } } catch (XPathException err) { // } } } return super.makeFunctionCall(arguments); }
/** * Simplify. Recognize remove(seq, 1) as a TailExpression. This * is worth doing because tail expressions used in a recursive call * are handled specially. */ private Expression simplifyAsTailExpression() { if (Literal.isAtomic(argument[1])) { try { long value = ((IntegerValue)((Literal)argument[1]).getValue()).longValue(); if (value <= 0) { return argument[0]; } else if (value == 1) { TailExpression t = new TailExpression(argument[0], 2); ExpressionTool.copyLocationInfo(this, t); return t; } } catch (XPathException err) { return this; } } return this; }
@Override public Expression makeFunctionCall(Expression[] arguments) { if (Literal.isAtomic(arguments[1])) { Sequence<?> index = ((Literal) arguments[1]).getValue(); if (index instanceof IntegerValue) { try { long value = ((IntegerValue) index).longValue(); if (value <= 0) { return arguments[0]; } else if (value == 1) { return new TailExpression(arguments[0], 2); } } catch (XPathException err) { // } } } return super.makeFunctionCall(arguments); }
/** * Simplify. Recognize remove(seq, 1) as a TailExpression. This * is worth doing because tail expressions used in a recursive call * are handled specially. */ private Expression simplifyAsTailExpression() { if (Literal.isAtomic(argument[1])) { try { long value = ((IntegerValue)((Literal)argument[1]).getValue()).longValue(); if (value <= 0) { return argument[0]; } else if (value == 1) { TailExpression t = new TailExpression(argument[0], 2); ExpressionTool.copyLocationInfo(this, t); return t; } } catch (XPathException err) { return this; } } return this; }
/** * Simplify. Recognize remove(seq, 1) as a TailExpression. This * is worth doing because tail expressions used in a recursive call * are handled specially. */ private Expression simplifyAsTailExpression() { if (Literal.isAtomic(argument[1])) { try { long value = ((IntegerValue)((Literal)argument[1]).getValue()).longValue(); if (value <= 0) { return argument[0]; } else if (value == 1) { TailExpression t = new TailExpression(argument[0], 2); ExpressionTool.copyLocationInfo(this, t); return t; } } catch (XPathException err) { return this; } } return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { boolean allAtomic = true; if (children != null) { for (int c=0; c<children.length; c++) { children[c] = visitor.optimize(children[c], contextItemType); adoptChildExpression(children[c]); if (!Literal.isAtomic(children[c])) { allAtomic = false; } } if (allAtomic) { Item[] items = new Item[children.length]; for (int c=0; c<children.length; c++) { items[c] = (AtomicValue)((Literal)children[c]).getValue(); } return new Literal(new SequenceExtent(items)); } } return this; }
private Expression preEvaluate(ExpressionVisitor visitor) throws XPathException { if (Literal.isAtomic(operand)) { return Literal.makeLiteral( BooleanValue.get(effectiveBooleanValue(visitor.getStaticContext().makeEarlyEvaluationContext()))); } if (Literal.isEmptySequence(operand)) { return new Literal(BooleanValue.get(allowEmpty)); } return this; }
private Expression preEvaluate(ExpressionVisitor visitor) throws XPathException { if (Literal.isAtomic(operand)) { return Literal.makeLiteral( BooleanValue.get(effectiveBooleanValue(visitor.getStaticContext().makeEarlyEvaluationContext()))); } if (Literal.isEmptySequence(operand)) { return new Literal(BooleanValue.get(allowEmpty)); } return this; }
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { boolean allAtomic = true; if (children != null) { for (int c=0; c<children.length; c++) { children[c] = visitor.optimize(children[c], contextItemType); adoptChildExpression(children[c]); if (!Literal.isAtomic(children[c])) { allAtomic = false; } } if (allAtomic) { Item[] items = new Item[children.length]; for (int c=0; c<children.length; c++) { items[c] = (AtomicValue)((Literal)children[c]).getValue(); } return new Literal(new SequenceExtent(items)); } } return this; }
/** * Make an expression that either calls this function, or that is equivalent to a call * on this function * * @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 */ @Override public Expression makeFunctionCall(Expression[] arguments) { // Handle the case where the second argument is known statically try { if (Literal.isAtomic(arguments[1]) && !(arguments[0] instanceof ErrorExpression)) { NumericValue start = (NumericValue) ((Literal) arguments[1]).getValue(); start = start.round(0); long intStart = start.longValue(); if (intStart > Integer.MAX_VALUE) { // Handle this case dynamically. Test case cbcl-subsequence-012 return super.makeFunctionCall(arguments); } if (intStart <= 0) { return arguments[0]; } return new TailExpression(arguments[0], (int) intStart); } } catch (Exception e) { // fall through (for example, in 1.0 mode start can be a StringValue ...) } return super.makeFunctionCall(arguments); }
/** * Make an expression that either calls this function, or that is equivalent to a call * on this function * * @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 */ @Override public Expression makeFunctionCall(Expression[] arguments) { // Handle the case where the second argument is known statically try { if (Literal.isAtomic(arguments[1]) && !(arguments[0] instanceof ErrorExpression)) { NumericValue start = (NumericValue) ((Literal) arguments[1]).getValue(); start = start.round(0); long intStart = start.longValue(); if (intStart > Integer.MAX_VALUE) { // Handle this case dynamically. Test case cbcl-subsequence-012 return super.makeFunctionCall(arguments); } if (intStart <= 0) { return arguments[0]; } return new TailExpression(arguments[0], (int) intStart); } } catch (Exception e) { // fall through (for example, in 1.0 mode start can be a StringValue ...) } return super.makeFunctionCall(arguments); }
public Expression simplify(ExpressionVisitor visitor) throws XPathException { if (simplified) { // Don't simplify more than once; because in XSLT the static context on subsequent calls // might not know whether backwards compatibility is in force or not return this; } simplified = true; Expression e = super.simplify(visitor); if (e == this && visitor.getStaticContext().isInBackwardsCompatibleMode()) { return new ArithmeticExpression10(operand0, operator, operand1); } else { if (operator == Token.NEGATE && Literal.isAtomic(operand1)) { // very early evaluation of expressions like "-1", so they are treated as numeric literals AtomicValue val = (AtomicValue)((Literal)operand1).getValue(); if (val instanceof NumericValue) { return new Literal(((NumericValue)val).negate()); } } return e; } }
public Expression simplify(ExpressionVisitor visitor) throws XPathException { if (simplified) { // Don't simplify more than once; because in XSLT the static context on subsequent calls // might not know whether backwards compatibility is in force or not return this; } simplified = true; Expression e = super.simplify(visitor); if (e == this && visitor.getStaticContext().isInBackwardsCompatibleMode()) { return new ArithmeticExpression10(operand0, operator, operand1); } else { if (operator == Token.NEGATE && Literal.isAtomic(operand1)) { // very early evaluation of expressions like "-1", so they are treated as numeric literals AtomicValue val = (AtomicValue)((Literal)operand1).getValue(); if (val instanceof NumericValue) { return new Literal(((NumericValue)val).negate()); } } return e; } }
/** * Simplify the expression * @return the simplified expression * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { StaticContext env = visitor.getStaticContext(); if ((targetType instanceof BuiltInAtomicType) && !env.isAllowedBuiltInType((BuiltInAtomicType)targetType)) { // this is checked here because the ConstructorFunctionLibrary doesn't have access to the static // context at bind time XPathException err = new XPathException("The type " + targetType.getDisplayName() + " is not recognized by a Basic XSLT Processor", this); err.setErrorCode("XPST0080"); err.setIsStaticError(true); throw err; } operand = visitor.simplify(operand); if (Literal.isAtomic(operand)) { return typeCheck(visitor, Type.ITEM_TYPE); } return this; }
/** * Simplify the expression * @return the simplified expression * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { StaticContext env = visitor.getStaticContext(); if ((targetType instanceof BuiltInAtomicType) && !env.isAllowedBuiltInType((BuiltInAtomicType)targetType)) { // this is checked here because the ConstructorFunctionLibrary doesn't have access to the static // context at bind time XPathException err = new XPathException("The type " + targetType.getDisplayName() + " is not recognized by a Basic XSLT Processor", this); err.setErrorCode("XPST0080"); err.setIsStaticError(true); throw err; } operand = visitor.simplify(operand); if (Literal.isAtomic(operand)) { return typeCheck(visitor, Type.ITEM_TYPE); } return this; }
private Expression makeUnaryExpression(int operator, Expression operand) { if (Literal.isAtomic(operand)) { // very early evaluation of expressions like "-1", so they are treated as numeric literals AtomicValue val = (AtomicValue) ((Literal) operand).getValue(); if (val instanceof NumericValue) { if (env.isInBackwardsCompatibleMode()) { val = new DoubleValue(((NumericValue) val).getDoubleValue()); } AtomicValue value = operator == Token.NEGATE ? ((NumericValue) val).negate() : (NumericValue) val; return Literal.makeLiteral(value); } } return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeArithmeticExpression( Literal.makeLiteral(Int64Value.ZERO), operator, operand); }
return e; if (getNumberOfArguments() == 2 && Literal.isAtomic(argument[1])) { NumericValue start = (NumericValue)((Literal)argument[1]).getValue(); start = start.round();
private Expression makeUnaryExpression(int operator, Expression operand) { if (Literal.isAtomic(operand)) { // very early evaluation of expressions like "-1", so they are treated as numeric literals AtomicValue val = (AtomicValue) ((Literal) operand).getValue(); if (val instanceof NumericValue) { if (env.isInBackwardsCompatibleMode()) { val = new DoubleValue(((NumericValue) val).getDoubleValue()); } AtomicValue value = operator == Token.NEGATE ? ((NumericValue) val).negate() : (NumericValue) val; return Literal.makeLiteral(value); } } return env.getConfiguration().getTypeChecker(env.isInBackwardsCompatibleMode()).makeArithmeticExpression( Literal.makeLiteral(Int64Value.ZERO), operator, operand); }
return e; if (getNumberOfArguments() == 2 && Literal.isAtomic(argument[1])) { NumericValue start = (NumericValue)((Literal)argument[1]).getValue(); start = start.round();
return e; if (getNumberOfArguments() == 2 && Literal.isAtomic(argument[1])) { NumericValue start = (NumericValue)((Literal)argument[1]).getValue(); start = start.round();