Project

Profile

Help

Revision 7a95ed26

Added by Michael Kay over 11 years ago

Fix 3012591 Incorrect optimization of name()='x' under Saxon-EE

View differences:

latest9.2/hej/net/sf/saxon/expr/ExpressionParser.java
881 881
            case Token.GE:
882 882
                op = t.currentToken;
883 883
                nextToken();
884
                exp = env.getConfiguration().getOptimizer().makeGeneralComparison(
885
                        exp, op, parseRangeExpression(), env.isInBackwardsCompatibleMode());
884
                exp = new GeneralComparison(
885
                        exp, op, parseRangeExpression());
886 886
                setLocation(exp);
887 887
                return exp;
888 888

  
latest9.2/hej/net/sf/saxon/expr/GeneralComparison.java
38 38
        singletonOperator = getSingletonOperator(op);
39 39
    }
40 40

  
41
   @Override
42
    public Expression simplify(ExpressionVisitor visitor) throws XPathException {
43
        Expression e = super.simplify(visitor);
44
        if (e == this) {
45
            e = visitor.getConfiguration().getOptimizer().simplifyGeneralComparison(
46
                    this, visitor.getStaticContext().isInBackwardsCompatibleMode());
47
        }
48
        ExpressionTool.copyLocationInfo(this, e);
49
        return e;
50
    }    
51

  
41 52
    /**
42 53
     * Get the AtomicComparer used to compare atomic values. This encapsulates any collation that is used
43 54
     */
latest9.2/hej/net/sf/saxon/expr/GeneralComparison10.java
139 139
            // or the complications of converting values to numbers
140 140
            if (operator == Token.EQUALS || operator == Token.NE) {
141 141
                if ((!maybeNumeric0 && !maybeNumeric1) || (numeric0 && numeric1)) {
142
                    BinaryExpression gc = opt.makeGeneralComparison(operand0, operator, operand1, false);
143
                    ExpressionTool.copyLocationInfo(this, gc);
144
                    return visitor.optimize(visitor.typeCheck(gc, contextItemType), contextItemType);
142
                    GeneralComparison gc = new GeneralComparison(operand0, operator, operand1);
143
                    BinaryExpression binExp = visitor.getConfiguration().getOptimizer().simplifyGeneralComparison(gc, false);
144
                    ExpressionTool.copyLocationInfo(this, binExp);
145
                    return visitor.optimize(visitor.typeCheck(binExp, contextItemType), contextItemType);
145 146
                }
146 147
            } else if (numeric0 && numeric1) {
147
                BinaryExpression gc = opt.makeGeneralComparison(operand0, operator, operand1, false);
148
                ExpressionTool.copyLocationInfo(this, gc);
149
                return visitor.optimize(visitor.typeCheck(gc, contextItemType), contextItemType);
148
                GeneralComparison gc = new GeneralComparison(operand0, operator, operand1);
149
                BinaryExpression binExp = visitor.getConfiguration().getOptimizer().simplifyGeneralComparison(gc, false);
150
                ExpressionTool.copyLocationInfo(this, binExp);
151
                return visitor.optimize(visitor.typeCheck(binExp, contextItemType), contextItemType);
150 152
            }
151 153
        }
152 154

  
latest9.2/hej/net/sf/saxon/expr/Optimizer.java
76 76
    }
77 77

  
78 78
    /**
79
     * Create a GeneralComparison expression
80
     * @param p0 the first operand
81
     * @param op the operator
82
     * @param p1 the second operand
83
     * @param backwardsCompatible true if XPath 1.0 backwards compatibility is in force
84
     * @return the constructed expression
79
     * Simplify a GeneralComparison expression
80
     * @param gc the GeneralComparison to be simplified
81
     * @param backwardsCompatible true if in 1.0 compatibility mode
82
     * @return the simplified expression
85 83
     */
86 84

  
87
    public BinaryExpression makeGeneralComparison(Expression p0, int op, Expression p1, boolean backwardsCompatible) {
85
    public BinaryExpression simplifyGeneralComparison(GeneralComparison gc, boolean backwardsCompatible) {
88 86
        if (backwardsCompatible) {
89
            return new GeneralComparison10(p0, op, p1);
87
            Expression[] operands = gc.getOperands();
88
            return new GeneralComparison10(operands[0], gc.getOperator(), operands[1]);
90 89
        } else {
91
            return new GeneralComparison(p0, op, p1);
90
            return gc;
92 91
        }
93 92
    }
94 93

  
94

  
95 95
    /**
96 96
     * Attempt to optimize a copy operation. Return null if no optimization is possible.
97 97
     * @param select the expression that selects the items to be copied

Also available in: Unified diff