/** * 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; }
/** * 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 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; }
/** * 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)); } }