| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.Operand; |
| 12 |
import net.sf.saxon.expr.OperandRole; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.expr.parser.ExpressionTool; |
| 15 |
import net.sf.saxon.expr.parser.RebindingMap; |
| 16 |
import net.sf.saxon.om.StandardNames; |
| 17 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 18 |
import net.sf.saxon.trans.XPathException; |
| 19 |
import net.sf.saxon.type.AnyItemType; |
| 20 |
import net.sf.saxon.type.ErrorType; |
| 21 |
import net.sf.saxon.type.ItemType; |
| 22 |
import net.sf.saxon.type.Type; |
| 23 |
|
| 24 |
import java.util.Arrays; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class Fork extends Instruction { |
| 32 |
|
| 33 |
Operand[] operanda; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public Fork(Operand[] prongs) { |
| 41 |
operanda = new Operand[prongs.length]; |
| 42 |
for (int i=0; i<prongs.length; i++) { |
| 43 |
operanda[i] = new Operand(this, prongs[i].getChildExpression(), OperandRole.SAME_FOCUS_ACTION); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public Fork(Expression[] prongs) { |
| 48 |
operanda = new Operand[prongs.length]; |
| 49 |
for (int i = 0; i < prongs.length; i++) { |
| 50 |
operanda[i] = new Operand(this, prongs[i], OperandRole.SAME_FOCUS_ACTION); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public Iterable<Operand> operands() { |
| 56 |
return Arrays.asList(operanda); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public int getInstructionNameCode() { |
| 67 |
return StandardNames.XSL_FORK; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public int getSize() { |
| 76 |
return operanda.length; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public Expression getProng(int i) { |
| 87 |
return operanda[i].getChildExpression(); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public ItemType getItemType() { |
| 96 |
if (getSize() == 0) { |
| 97 |
return ErrorType.getInstance(); |
| 98 |
} |
| 99 |
ItemType t1 = null; |
| 100 |
for (Operand o : operands()) { |
| 101 |
ItemType t2 = o.getChildExpression().getItemType(); |
| 102 |
t1 = t1 == null ? t2 : Type.getCommonSuperType(t1, t2); |
| 103 |
if (t1 instanceof AnyItemType) { |
| 104 |
return t1; |
| 105 |
} |
| 106 |
} |
| 107 |
return t1; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
@Override |
| 117 |
public String getStreamerName() { |
| 118 |
return "Fork"; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public Expression copy(RebindingMap rebindings) { |
| 130 |
Expression[] e2 = new Expression[getSize()]; |
| 131 |
int i=0; |
| 132 |
for (Operand o : operands()) { |
| 133 |
e2[i++] = o.getChildExpression().copy(rebindings); |
| 134 |
} |
| 135 |
Fork f2 = new Fork(e2); |
| 136 |
ExpressionTool.copyLocationInfo(this, f2); |
| 137 |
return f2; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
@Override |
| 149 |
public TailCall processLeavingTail(XPathContext context) throws XPathException { |
| 150 |
for (Operand o : operands()) { |
| 151 |
o.getChildExpression().process(context); |
| 152 |
} |
| 153 |
return null; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public void export(ExpressionPresenter out) throws XPathException { |
| 164 |
out.startElement("fork", this); |
| 165 |
for (Operand o : operands()) { |
| 166 |
o.getChildExpression().export(out); |
| 167 |
} |
| 168 |
out.endElement(); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
} |