Debian Codegraph @

net/sf/saxon/expr/instruct/LocalParamBlock.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.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 * Represents the set of xsl:param elements at the start of an xsl:iterate instruction
22 */
23
24 public class LocalParamBlock extends Instruction {
25
26 Operand[] operanda;
27
28 /**
29 * Create the block of parameters
30 *
31 * @param params the parameters
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 * Copy an expression. This makes a deep copy.
61 *
62 * @return the copy of the original expression
63 * @param rebindings
64 */
65
66 /*@NotNull*/
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 * Determine the data type of the items returned by this expression
81 *
82 * @return the data type
83 */
84
85 /*@NotNull*/
86 public final ItemType getItemType() {
87 return ErrorType.getInstance();
88 }
89
90 /**
91 * Determine the cardinality of the expression
92 */
93
94 public final int getCardinality() {
95 return StaticProperty.EMPTY;
96 }
97
98 /**
99 * Diagnostic print of expression structure. The abstract expression tree
100 * is written to the supplied output destination.
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 /*@Nullable*/
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 * An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
129 * This method indicates which of these methods is provided. This implementation provides both iterate() and
130 * process() methods natively.
131 */
132
133 public int getImplementationMethod() {
134 return PROCESS_METHOD;
135 }
136
137
138 }
139