Project

Profile

Help

Revision b85f42b7

Added by Michael Kay over 1 year ago

Fix bug #4636

View differences:

latest9.9/hej/net/sf/saxon/expr/Operand.java
70 70

  
71 71
    public void setChildExpression(Expression childExpression) {
72 72
        if (childExpression != this.childExpression) {
73
            if (role.isConstrainedClass() && this.childExpression != null && childExpression.getClass() != this.childExpression.getClass()) {
74
                throw new AssertionError();
73
            if (role.isConstrainedClass()) {
74
                if (role.getConstraint() != null) {
75
                    if (!role.getConstraint().test(childExpression)) {
76
                        throw new AssertionError();
77
                    }
78
                } else if (this.childExpression != null && childExpression.getClass() != this.childExpression.getClass()) {
79
                    throw new AssertionError();
80
                }
75 81
            }
76 82
            this.childExpression = childExpression;
77 83
            parentExpression.adoptChildExpression(childExpression);
latest9.9/hej/net/sf/saxon/expr/OperandRole.java
8 8
package net.sf.saxon.expr;
9 9

  
10 10

  
11
import net.sf.saxon.expr.flwor.TupleExpression;
12
import net.sf.saxon.pattern.Pattern;
11 13
import net.sf.saxon.type.FunctionItemType;
12 14
import net.sf.saxon.type.ItemType;
13 15
import net.sf.saxon.type.PlainType;
14 16
import net.sf.saxon.value.SequenceType;
15 17

  
18
import java.util.function.Predicate;
19

  
16 20
/**
17 21
 * Defines the role of a child expression relative to its parent expression. The properties
18 22
 * of an operand role depend only on the kind of expression and not on the actual arguments
......
47 51
    public final static OperandRole REPEAT_NAVIGATE =
48 52
            new OperandRole(OperandRole.HIGHER_ORDER, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE);
49 53
    public final static OperandRole REPEAT_NAVIGATE_CONSTRAINED =
50
            new OperandRole(OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE);
54
            new OperandRole(OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS,
55
                            OperandUsage.NAVIGATION,
56
                            SequenceType.ANY_SEQUENCE,
57
                            expr -> expr instanceof TupleExpression);
51 58
    public final static OperandRole SINGLE_ATOMIC =
52 59
            new OperandRole(0, OperandUsage.ABSORPTION,  SequenceType.SINGLE_ATOMIC);
53 60
    public final static OperandRole ATOMIC_SEQUENCE =
......
55 62
    public final static OperandRole NEW_FOCUS_ATOMIC =
56 63
            new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER, OperandUsage.ABSORPTION, SequenceType.ATOMIC_SEQUENCE);
57 64
    public final static OperandRole PATTERN =
58
            new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS, OperandUsage.ABSORPTION, SequenceType.ATOMIC_SEQUENCE);
65
            new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS,
66
                            OperandUsage.ABSORPTION,
67
                            SequenceType.ATOMIC_SEQUENCE,
68
                            expr -> expr instanceof Pattern);
59 69

  
60 70
    int properties;
61 71
    private OperandUsage usage;
62 72
    private SequenceType requiredType = SequenceType.ANY_SEQUENCE;
73
    private Predicate<Expression> constraint;
63 74

  
64 75
    public OperandRole(int properties, OperandUsage usage) {
65 76
        this.properties = properties;
......
72 83
        this.requiredType = requiredType;
73 84
    }
74 85

  
86
    public OperandRole(int properties, OperandUsage usage, SequenceType requiredType, Predicate<Expression> constraint) {
87
        this.properties = properties;
88
        this.usage = usage;
89
        this.requiredType = requiredType;
90
        this.constraint = constraint;
91
    }
92

  
93

  
94

  
75 95
    /**
76 96
     * Ask whether the child expression sets the focus for evaluation of other child expressions
77 97
     * @return true if the child expression is evaluated with the same focus as its parent expression
......
116 136

  
117 137
     public boolean isConstrainedClass() { return (properties & CONSTRAINED_CLASS) != 0; }
118 138

  
139
     public Predicate<Expression> getConstraint() {
140
         return constraint;
141
     }
142

  
119 143
    /**
120 144
     * Get the usage of the operand
121 145
     * @return the usage
latest9.9/hej/net/sf/saxon/expr/instruct/IterateInstr.java
49 49
        selectOp = new Operand(this, select, OperandRole.FOCUS_CONTROLLING_SELECT);
50 50
        actionOp = new Operand(this, action, OperandRole.FOCUS_CONTROLLED_ACTION);
51 51
        initiallyOp = new Operand(this, initiallyExp,
52
                                  new OperandRole(OperandRole.CONSTRAINED_CLASS, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE));
52
                                  new OperandRole(OperandRole.CONSTRAINED_CLASS,
53
                                                  OperandUsage.NAVIGATION,
54
                                                  SequenceType.ANY_SEQUENCE,
55
                                                  expr -> expr instanceof LocalParamBlock));
53 56
        onCompletionOp = new Operand(this, onCompletion,
54 57
                                     new OperandRole(OperandRole.USES_NEW_FOCUS, OperandUsage.TRANSMISSION));
55 58
    }
latest9.9/hej/net/sf/saxon/expr/sort/ConditionalSorter.java
39 39
    }
40 40

  
41 41
    private final static OperandRole DOC_SORTER_ROLE =
42
            new OperandRole(OperandRole.CONSTRAINED_CLASS, OperandUsage.TRANSMISSION, SequenceType.ANY_SEQUENCE);
42
            new OperandRole(OperandRole.CONSTRAINED_CLASS,
43
                            OperandUsage.TRANSMISSION,
44
                            SequenceType.ANY_SEQUENCE,
45
                            expr -> expr instanceof DocumentSorter);
43 46

  
44 47
    /**
45 48
     * Create a conditional document sorter

Also available in: Unified diff