| 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.ContextItemStaticInfo; |
| 12 |
import net.sf.saxon.expr.parser.ExpressionTool; |
| 13 |
import net.sf.saxon.expr.parser.ExpressionVisitor; |
| 14 |
import net.sf.saxon.expr.parser.RebindingMap; |
| 15 |
import net.sf.saxon.om.Sequence; |
| 16 |
import net.sf.saxon.om.StandardNames; |
| 17 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 18 |
import net.sf.saxon.trans.XPathException; |
| 19 |
|
| 20 |
import java.util.ArrayList; |
| 21 |
import java.util.Arrays; |
| 22 |
import java.util.List; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class NextIteration extends Instruction implements TailCallLoop.TailCallInfo { |
| 28 |
|
| 29 |
private WithParam[] actualParams = null; |
| 30 |
|
| 31 |
public NextIteration() { |
| 32 |
} |
| 33 |
|
| 34 |
public void setParameters(WithParam[] actualParams) { |
| 35 |
this.actualParams = actualParams; |
| 36 |
} |
| 37 |
|
| 38 |
public WithParam[] getParameters() { |
| 39 |
return actualParams; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public boolean isLiftable(boolean forStreaming) { |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
@Override |
| 59 |
public int getInstructionNameCode() { |
| 60 |
return StandardNames.XSL_NEXT_ITERATION; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
public Expression simplify() throws XPathException { |
| 65 |
WithParam.simplify(actualParams); |
| 66 |
return this; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { |
| 71 |
WithParam.typeCheck(actualParams, visitor, contextInfo); |
| 72 |
return this; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
public Expression copy(RebindingMap rebindings) { |
| 77 |
NextIteration c2 = new NextIteration(); |
| 78 |
ExpressionTool.copyLocationInfo(this, c2); |
| 79 |
c2.actualParams = WithParam.copy(c2, actualParams, rebindings); |
| 80 |
return c2; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
@Override |
| 91 |
public Iterable<Operand> operands() { |
| 92 |
List<Operand> list = new ArrayList<Operand>(); |
| 93 |
WithParam.gatherOperands(this, actualParams, list); |
| 94 |
return list; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
@Override |
| 104 |
public String getStreamerName() { |
| 105 |
return "NextIteration"; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
public TailCall processLeavingTail(XPathContext context) throws XPathException { |
| 110 |
XPathContext c = context; |
| 111 |
while (!(c instanceof XPathContextMajor)) { |
| 112 |
c = c.getCaller(); |
| 113 |
} |
| 114 |
XPathContextMajor cm = (XPathContextMajor)c; |
| 115 |
if (actualParams.length == 1) { |
| 116 |
cm.setLocalVariable(actualParams[0].getSlotNumber(), actualParams[0].getSelectValue(context)); |
| 117 |
} else { |
| 118 |
|
| 119 |
Sequence[] oldVars = cm.getAllVariableValues(); |
| 120 |
Sequence[] newVars = Arrays.copyOf(oldVars, oldVars.length); |
| 121 |
for (WithParam wp : actualParams) { |
| 122 |
newVars[wp.getSlotNumber()] = wp.getSelectValue(context); |
| 123 |
} |
| 124 |
cm.resetAllVariableValues(newVars); |
| 125 |
} |
| 126 |
cm.requestTailCall(this, null); |
| 127 |
return null; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
public void export(ExpressionPresenter out) throws XPathException { |
| 132 |
out.startElement("nextIteration", this); |
| 133 |
if (actualParams != null && actualParams.length > 0) { |
| 134 |
WithParam.exportParameters(actualParams, out, false); |
| 135 |
} |
| 136 |
out.endElement(); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
} |
| 141 |
|