| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.expr.parser.RebindingMap; |
| 12 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.type.ErrorType; |
| 15 |
import net.sf.saxon.type.ItemType; |
| 16 |
|
| 17 |
import java.util.Arrays; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class LocalParamBlock extends Instruction { |
| 25 |
|
| 26 |
Operand[] operanda; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public LocalParamBlock(LocalParam[] params) { |
| 35 |
operanda = new Operand[params.length]; |
| 36 |
for (int i=0; i<params.length; i++) { |
| 37 |
operanda[i] = new Operand(this, params[i], OperandRole.NAVIGATE); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public String getExpressionName() { |
| 42 |
return "params"; |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public Iterable<Operand> operands() { |
| 47 |
return Arrays.asList(operanda); |
| 48 |
} |
| 49 |
|
| 50 |
public int getNumberOfParams() { |
| 51 |
return operanda.length; |
| 52 |
} |
| 53 |
|
| 54 |
public int computeSpecialProperties() { |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public Expression copy(RebindingMap rebindings) { |
| 68 |
LocalParam[] lps2 = new LocalParam[getNumberOfParams()]; |
| 69 |
int i=0; |
| 70 |
for (Operand o : operands()) { |
| 71 |
LocalParam oldLps = (LocalParam) o.getChildExpression(); |
| 72 |
LocalParam newLps = oldLps.copy(rebindings); |
| 73 |
rebindings.put(oldLps, newLps); |
| 74 |
lps2[i++] = newLps; |
| 75 |
} |
| 76 |
return new LocalParamBlock(lps2); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public final ItemType getItemType() { |
| 87 |
return ErrorType.getInstance(); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public final int getCardinality() { |
| 95 |
return StaticProperty.EMPTY; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void export(ExpressionPresenter out) throws XPathException { |
| 104 |
out.startElement("params", this); |
| 105 |
for (Operand o : operands()) { |
| 106 |
o.getChildExpression().export(out); |
| 107 |
} |
| 108 |
out.endElement(); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public TailCall processLeavingTail(XPathContext context) throws XPathException { |
| 114 |
for (Operand o : operands()) { |
| 115 |
LocalParam param = (LocalParam)o.getChildExpression(); |
| 116 |
try { |
| 117 |
context.setLocalVariable(param.getSlotNumber(), param.getSelectValue(context)); |
| 118 |
} catch (XPathException e) { |
| 119 |
e.maybeSetLocation(param.getLocation()); |
| 120 |
e.maybeSetContext(context); |
| 121 |
throw e; |
| 122 |
} |
| 123 |
} |
| 124 |
return null; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public int getImplementationMethod() { |
| 134 |
return PROCESS_METHOD; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
} |
| 139 |
|