/** * Type-check a calling expression. */ /*@NotNull*/ public Expression typeCheckCaller(FunctionCall caller, ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) { if (caller.getArg(0).isCallOn(Number_1.class)) { // happens through repeated rewriting caller.setArg(0, ((FunctionCall)caller.getArg(0)).getArg(0)); } return caller; }
/** * Simplify the arguments of the function. * Called from the simplify() method of each function. * * @param env the static context * @return the result of simplifying the arguments of the expression * @throws net.sf.saxon.trans.XPathException if an error occurs */ protected final Expression simplifyArguments(StaticContext env) throws XPathException { for (int i = 0; i < getArguments().length; i++) { Expression exp = getArg(i).simplify(); if (exp != getArg(i)) { adoptChildExpression(exp); setArg(i, exp); } } return this; }
/** * Simplify the arguments of the function. * Called from the simplify() method of each function. * * @param env the static context * @return the result of simplifying the arguments of the expression * @throws net.sf.saxon.trans.XPathException if an error occurs */ protected final Expression simplifyArguments(StaticContext env) throws XPathException { for (int i = 0; i < getArguments().length; i++) { Expression exp = getArg(i).simplify(); if (exp != getArg(i)) { adoptChildExpression(exp); setArg(i, exp); } } return this; }
/** * Type-check a calling expression. */ /*@NotNull*/ public Expression typeCheckCaller(FunctionCall caller, ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) { if (caller.getArg(0).isCallOn(Number_1.class)) { // happens through repeated rewriting caller.setArg(0, ((FunctionCall)caller.getArg(0)).getArg(0)); } return caller; }
public Sequence[] evaluateArguments(XPathContext context) throws XPathException { int numArgs = getArity(); Sequence[] actualArgs = new Sequence[numArgs]; for (int i = 0; i < numArgs; i++) { actualArgs[i] = ExpressionTool.lazyEvaluate(getArg(i), context, false); } return actualArgs; }
public Sequence[] evaluateArguments(XPathContext context) throws XPathException { int numArgs = getArity(); Sequence[] actualArgs = new Sequence[numArgs]; for (int i = 0; i < numArgs; i++) { actualArgs[i] = ExpressionTool.lazyEvaluate(getArg(i), context, false); } return actualArgs; }
/** * Type-check the expression. This also calls preEvaluate() to evaluate the function * if all the arguments are constant; functions that do not require this behavior * can override the preEvaluate method. */ /*@NotNull*/ public Expression typeCheckCaller(FunctionCall caller, ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e2 = super.typeCheckCaller(caller, visitor, contextInfo); if (e2 != caller) { return e2; } TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (caller.getArg(1).isCallOn(Number_1.class)) { Expression a1 = ((StaticFunctionCall)caller.getArg(1)).getArg(0); if (th.isSubType(a1.getItemType(), BuiltInAtomicType.INTEGER)) { caller.setArg(1, a1); } } if (getArity() > 2 && caller.getArg(2).isCallOn(Number_1.class)) { Expression a2 = ((StaticFunctionCall) caller.getArg(2)).getArg(0); if (th.isSubType(a2.getItemType(), BuiltInAtomicType.INTEGER)) { caller.setArg(2, a2); } } return caller; }
/** * Type-check the expression. This also calls preEvaluate() to evaluate the function * if all the arguments are constant; functions that do not require this behavior * can override the preEvaluate method. */ /*@NotNull*/ public Expression typeCheckCaller(FunctionCall caller, ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e2 = super.typeCheckCaller(caller, visitor, contextInfo); if (e2 != caller) { return e2; } TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (caller.getArg(1).isCallOn(Number_1.class)) { Expression a1 = ((StaticFunctionCall)caller.getArg(1)).getArg(0); if (th.isSubType(a1.getItemType(), BuiltInAtomicType.INTEGER)) { caller.setArg(1, a1); } } if (getArity() > 2 && caller.getArg(2).isCallOn(Number_1.class)) { Expression a2 = ((StaticFunctionCall) caller.getArg(2)).getArg(0); if (th.isSubType(a2.getItemType(), BuiltInAtomicType.INTEGER)) { caller.setArg(2, a2); } } return caller; }
/** * Determine whether two expressions are equivalent */ public boolean equals(Object o) { if (!(o instanceof FunctionCall)) { return false; } if (getFunctionName() == null) { return this == o; } FunctionCall f = (FunctionCall) o; if (!getFunctionName().equals(f.getFunctionName())) { return false; } if (getArity() != f.getArity()) { return false; } for (int i = 0; i < getArity(); i++) { if (!getArg(i).isEqual(f.getArg(i))) { return false; } } return true; }
/** * Determine whether two expressions are equivalent */ public boolean equals(Object o) { if (!(o instanceof FunctionCall)) { return false; } if (getFunctionName() == null) { return this == o; } FunctionCall f = (FunctionCall) o; if (!getFunctionName().equals(f.getFunctionName())) { return false; } if (getArity() != f.getArity()) { return false; } for (int i = 0; i < getArity(); i++) { if (!getArg(i).isEqual(f.getArg(i))) { return false; } } return true; }
/** * Get hashCode in support of equals() method */ public int computeHashCode() { if (getFunctionName() == null) { return super.computeHashCode(); } int h = getFunctionName().hashCode(); for (int i = 0; i < getArity(); i++) { h ^= getArg(i).hashCode(); } return h; }
/** * Get hashCode in support of equals() method */ public int computeHashCode() { if (getFunctionName() == null) { return super.computeHashCode(); } int h = getFunctionName().hashCode(); for (int i = 0; i < getArity(); i++) { h ^= getArg(i).hashCode(); } return h; }
/** * Check the function call against the declared function signature, applying the * function conversion rules to each argument as necessary * * @param target the function being called * @param visitor an expression visitor * @throws XPathException if there is a type error */ public void checkFunctionCall(Function target, ExpressionVisitor visitor) throws XPathException { TypeChecker tc = visitor.getConfiguration().getTypeChecker(visitor.getStaticContext().isInBackwardsCompatibleMode()); SequenceType[] argTypes = target.getFunctionItemType().getArgumentTypes(); int n = target.getArity(); for (int i = 0; i < n; i++) { String name = getFunctionName() == null ? "" : getFunctionName().getDisplayName(); RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.FUNCTION, name, i); setArg(i, tc.staticTypeCheck( getArg(i), argTypes[i], role, visitor)); } }
/** * Check the function call against the declared function signature, applying the * function conversion rules to each argument as necessary * * @param target the function being called * @param visitor an expression visitor * @throws XPathException if there is a type error */ public void checkFunctionCall(Function target, ExpressionVisitor visitor) throws XPathException { TypeChecker tc = visitor.getConfiguration().getTypeChecker(visitor.getStaticContext().isInBackwardsCompatibleMode()); SequenceType[] argTypes = target.getFunctionItemType().getArgumentTypes(); int n = target.getArity(); for (int i = 0; i < n; i++) { String name = getFunctionName() == null ? "" : getFunctionName().getDisplayName(); RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.FUNCTION, name, i); setArg(i, tc.staticTypeCheck( getArg(i), argTypes[i], role, visitor)); } }