Debian Codegraph @

net/sf/saxon/expr/instruct/NextIteration.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * Implements a xsl:next-iteration instruction within the body of xsl:iterate
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 * Ask whether the expression can be lifted out of a loop, assuming it has no dependencies
44 * on the controlling variable/focus of the loop
45 * @param forStreaming
46 */
47
48 public boolean isLiftable(boolean forStreaming) {
49 return false;
50 }
51
52 /**
53 * Get the namecode of the instruction for use in diagnostics
54 *
55 * @return a code identifying the instruction: typically but not always
56 * the fingerprint of a name in the XSLT namespace
57 */
58 @Override
59 public int getInstructionNameCode() {
60 return StandardNames.XSL_NEXT_ITERATION;
61 }
62
63 /*@NotNull*/
64 public Expression simplify() throws XPathException {
65 WithParam.simplify(actualParams);
66 return this;
67 }
68
69 /*@NotNull*/
70 public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
71 WithParam.typeCheck(actualParams, visitor, contextInfo);
72 return this;
73 }
74
75 /*@NotNull*/
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 * Get the immediate sub-expressions of this expression, with information about the relationship
85 * of each expression to its parent expression. Default implementation
86 * works off the results of iterateSubExpressions()
87 *
88 * @return an iterator containing the sub-expressions of this expression
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 * Get the (partial) name of a class that supports streaming of this kind of expression
99 *
100 * @return the partial name of a class that can be instantiated to provide streaming support in Saxon-EE,
101 * or null if there is no such class
102 */
103 @Override
104 public String getStreamerName() {
105 return "NextIteration";
106 }
107
108 /*@Nullable*/
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 // we can't overwrite any of the parameters until we've evaluated all of them: test iterate012
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