/** * Static type checking for let expressions is delegated to the expression itself, * and is performed on the "action" expression, to allow further delegation to the branches * of a conditional * * * @param req the required type * @param backwardsCompatible true if backwards compatibility mode applies * @param role the role of the expression in relation to the required type * @param visitor an expression visitor * @return the expression after type checking (perhaps augmented with dynamic type checking code) * @throws XPathException if failures occur, for example if the static type of one branch of the conditional * is incompatible with the required type */ public Expression staticTypeCheck(SequenceType req, boolean backwardsCompatible, RoleDiagnostic role, ExpressionVisitor visitor) throws XPathException { TypeChecker tc = visitor.getConfiguration().getTypeChecker(backwardsCompatible); setAction(tc.staticTypeCheck(getAction(), req, role, visitor)); return this; }
/** * Static type checking for let expressions is delegated to the expression itself, * and is performed on the "action" expression, to allow further delegation to the branches * of a conditional * * * @param req the required type * @param backwardsCompatible true if backwards compatibility mode applies * @param role the role of the expression in relation to the required type * @param visitor an expression visitor * @return the expression after type checking (perhaps augmented with dynamic type checking code) * @throws XPathException if failures occur, for example if the static type of one branch of the conditional * is incompatible with the required type */ public Expression staticTypeCheck(SequenceType req, boolean backwardsCompatible, RoleDiagnostic role, ExpressionVisitor visitor) throws XPathException { TypeChecker tc = visitor.getConfiguration().getTypeChecker(backwardsCompatible); setAction(tc.staticTypeCheck(getAction(), req, role, visitor)); return this; }
/** * Copy an expression. This makes a deep copy. * @return the copy of the original expression */ public Expression copy() { LetExpression let = new LetExpression(); let.setVariableQName(variableName); let.setRequiredType(requiredType); let.setSequence(sequence.copy()); Expression newAction = action.copy(); let.setAction(newAction); ExpressionTool.rebindVariableReferences(newAction, this, let); return let; }
/** * Copy an expression. This makes a deep copy. * @return the copy of the original expression */ public Expression copy() { LetExpression let = new LetExpression(); let.setVariableQName(variableName); let.setRequiredType(requiredType); let.setSequence(sequence.copy()); Expression newAction = action.copy(); let.setAction(newAction); ExpressionTool.rebindVariableReferences(newAction, this, let); return let; }
/** * Copy an expression. This makes a deep copy. * @return the copy of the original expression */ public Expression copy() { LetExpression let = new LetExpression(); let.setVariableQName(variableName); let.setRequiredType(requiredType); let.setSequence(sequence.copy()); Expression newAction = action.copy(); let.setAction(newAction); ExpressionTool.rebindVariableReferences(newAction, this, let); return let; }
/** * Resolve calls to the XSLT current() function within an expression * @param exp the expression within which calls to current() should be resolved * @param config the Saxon configuration * @return the expression after resolving calls to current() */ public static Expression resolveCallsToCurrentFunction(Expression exp, Configuration config) throws XPathException { if (callsFunction(exp, Current.FN_CURRENT)) { LetExpression let = new LetExpression(); let.setVariableQName( new StructuredQName("saxon", NamespaceConstant.SAXON, "current" + exp.hashCode())); let.setRequiredType(SequenceType.SINGLE_ITEM); let.setSequence(new CurrentItemExpression()); PromotionOffer offer = new PromotionOffer(config.getOptimizer()); offer.action = PromotionOffer.REPLACE_CURRENT; offer.containingExpression = let; exp = exp.promote(offer); let.setAction(exp); return let; } else { return exp; } }
/** * Resolve calls to the XSLT current() function within an expression * @param exp the expression within which calls to current() should be resolved * @param config the Saxon configuration * @return the expression after resolving calls to current() */ public static Expression resolveCallsToCurrentFunction(Expression exp, Configuration config) throws XPathException { if (callsFunction(exp, Current.FN_CURRENT)) { LetExpression let = new LetExpression(); let.setVariableQName( new StructuredQName("saxon", NamespaceConstant.SAXON, "current" + exp.hashCode())); let.setRequiredType(SequenceType.SINGLE_ITEM); let.setSequence(new CurrentItemExpression()); PromotionOffer offer = new PromotionOffer(config.getOptimizer()); offer.action = PromotionOffer.REPLACE_CURRENT; offer.containingExpression = let; exp = exp.promote(offer); let.setAction(exp); return let; } else { return exp; } }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; // t.treatCurrentAsOperator(); // expect(Token.RETURN); // nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); return innerLet; // if (Literal.isEmptySequence(action)) { // // The purpose of simplifying this now is that () is allowed in a branch even in XQuery Update when // // other branches of the typeswitch are updating. // return action; // } else { // return innerLet; // } }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; // t.treatCurrentAsOperator(); // expect(Token.RETURN); // nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); return innerLet; // if (Literal.isEmptySequence(action)) { // // The purpose of simplifying this now is that () is allowed in a branch even in XQuery Update when // // other branches of the typeswitch are updating. // return action; // } else { // return innerLet; // } }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; t.treatCurrentAsOperator(); expect(Token.RETURN); nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); action = innerLet; return action; }
private Expression parseTypeswitchReturnClause(StructuredQName varQName, LetExpression outerLet) throws XPathException { Expression action; t.treatCurrentAsOperator(); expect(Token.RETURN); nextToken(); LetExpression innerLet = makeLetExpression(); innerLet.setRequiredType(SequenceType.ANY_SEQUENCE); innerLet.setVariableQName(varQName); innerLet.setSequence(new LocalVariableReference(outerLet)); declareRangeVariable(innerLet); action = parseExprSingle(); undeclareRangeVariable(); innerLet.setAction(action); return innerLet; // if (Literal.isEmptySequence(action)) { // // The purpose of simplifying this now is that () is allowed in a branch even in XQuery Update when // // other branches of the typeswitch are updating. // return action; // } else { // return innerLet; // } }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variables whose binding needs to change */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { LetExpression let = new LetExpression(); ExpressionTool.copyLocationInfo(this, let); let.isIndexedVariable = isIndexedVariable; let.hasLoopingReference = hasLoopingReference; let.setNeedsEagerEvaluation(needsEagerEvaluation); let.setNeedsLazyEvaluation(needsLazyEvaluation); let.setVariableQName(variableName); let.setRequiredType(requiredType); let.setSequence(getSequence().copy(rebindings)); let.setInstruction(isInstruction()); Expression newAction = getAction().copy(rebindings); let.setAction(newAction); ExpressionTool.rebindVariableReferences(newAction, this, let); return let; }
let.setNeedsLazyEvaluation(true); let.setEvaluationMode(Cardinality.allowsMany(child.getCardinality()) ? ExpressionTool.MAKE_MEMO_CLOSURE : ExpressionTool.MAKE_SINGLETON_CLOSURE); let.setAction(newAction); let.adoptChildExpression(newAction);
let.setSequence(new CurrentItemExpression()); replaceCallsToCurrent(exp, let); let.setAction(exp); return let; } else {
ExpressionTool.copyLocationInfo(containingExpression, let); let.setSequence(LazyExpression.makeLazyExpression(child)); let.setAction(containingExpression); let.adoptChildExpression(containingExpression); if (indexed) {
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variables whose binding needs to change */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { LetExpression let = new LetExpression(); ExpressionTool.copyLocationInfo(this, let); let.isIndexedVariable = isIndexedVariable; let.hasLoopingReference = hasLoopingReference; let.setNeedsEagerEvaluation(needsEagerEvaluation); let.setNeedsLazyEvaluation(needsLazyEvaluation); let.setVariableQName(variableName); let.setRequiredType(requiredType); let.setSequence(getSequence().copy(rebindings)); let.setInstruction(isInstruction()); Expression newAction = getAction().copy(rebindings); let.setAction(newAction); ExpressionTool.rebindVariableReferences(newAction, this, let); return let; }
ExpressionTool.copyLocationInfo(containingExpression, let); let.setSequence(LazyExpression.makeLazyExpression(child)); let.setAction(containingExpression); let.adoptChildExpression(containingExpression); if (indexed) {
ExpressionTool.copyLocationInfo(containingExpression, let); let.setSequence(LazyExpression.makeLazyExpression(child)); let.setAction(containingExpression); let.adoptChildExpression(containingExpression); if (indexed) {
let.setRequiredType(SequenceType.makeSequenceType(contextItemType, StaticProperty.EXACTLY_ONE)); let.setSequence(new ContextItemExpression()); let.setAction(exp); boolean changed = factorOutDot(exp, let); if (changed) {
let.setSequence(new CurrentItemExpression()); replaceCallsToCurrent(exp, let); let.setAction(exp); return let; } else {