Debian Codegraph @

net/sf/saxon/expr/instruct/SequenceInstr.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.ExpressionVisitor;
13 import net.sf.saxon.expr.parser.RebindingMap;
14 import net.sf.saxon.om.Item;
15 import net.sf.saxon.om.SequenceIterator;
16 import net.sf.saxon.trace.ExpressionPresenter;
17 import net.sf.saxon.trans.XPathException;
18
19 /**
20 * A compiled xsl:sequence instruction. Used only when strict streamability analysis is
21 * required; the instruction differs from its operand only by being marked as an instruction,
22 * which is sometimes relevant for streamability analysis. Used for xsl:sequence and also
23 * for xsl:map and xsl:map-entry; and also to wrap expressions in text value templates.
24 */
25 public class SequenceInstr extends UnaryExpression {
26
27
28 /**
29 * Create the instruction
30 */
31 public SequenceInstr(Expression base) {
32 super(base);
33 }
34
35 /**
36 * Ask whether this expression is an instruction. In XSLT streamability analysis this
37 * is used to distinguish constructs corresponding to XSLT instructions from other constructs.
38 *
39 * @return true if this construct originates as an XSLT instruction
40 */
41 @Override
42 public boolean isInstruction() {
43 return true;
44 }
45
46 /**
47 * Get the usage (in terms of streamability analysis) of the single operand
48 *
49 * @return the operand usage
50 */
51 @Override
52 protected OperandRole getOperandRole() {
53 return new OperandRole(0, OperandUsage.TRANSMISSION);
54 }
55
56 /**
57 * Simplify an expression. This performs any static optimization (by rewriting the expression
58 * as a different expression). The default implementation simplifies its operands.
59 *
60 * @return the simplified expression (or the original if unchanged, or if modified in-situ)
61 * @throws XPathException if an error is discovered during expression
62 * rewriting
63 */
64 // @Override
65 // public Expression simplify() throws XPathException {
66 // return getBaseExpression();
67 // }
68
69 /**
70 * Type-check the expression. Default implementation for unary operators that accept
71 * any kind of operand
72 */
73
74 /*@NotNull*/
75 public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
76 getOperand().typeCheck(visitor, contextInfo);
77 return this;
78 }
79
80 /**
81 * Perform optimisation of an expression and its subexpressions.
82 * <p>This method is called after all references to functions and variables have been resolved
83 * to the declaration of the function or variable, and after all type checking has been done.</p>
84 *
85 * @param visitor an expression visitor
86 * @param contextInfo the static type of "." at the point where this expression is invoked.
87 * The parameter is set to null if it is known statically that the context item will be undefined.
88 * If the type of the context item is not known statically, the argument is set to
89 * {@link net.sf.saxon.type.Type#ITEM_TYPE}
90 * @return the original expression, rewritten if appropriate to optimize execution
91 * @throws XPathException if an error is discovered during this phase
92 * (typically a type error)
93 */
94
95 /*@NotNull*/
96 public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
97 getOperand().optimize(visitor, contextInfo);
98 return this;
99 }
100
101
102 /*@NotNull*/
103 public Expression copy(RebindingMap rebindings) {
104 return new SequenceInstr(getBaseExpression().copy(rebindings));
105 }
106
107 /**
108 * An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
109 * This method indicates which of these methods is provided directly. The other methods will always be available
110 * indirectly, using an implementation that relies on one of the other methods.
111 *
112 * @return the implementation method, for example {@link #ITERATE_METHOD} or {@link #EVALUATE_METHOD} or
113 * {@link #PROCESS_METHOD}
114 */
115 @Override
116 public int getImplementationMethod() {
117 return getBaseExpression().getImplementationMethod();
118 }
119
120 /**
121 * Get a name identifying the kind of expression, in terms meaningful to a user.
122 *
123 * @return a name identifying the kind of expression, in terms meaningful to a user.
124 * The name will always be in the form of a lexical XML QName, and should match the name used
125 * in export() output displaying the expression.
126 */
127 @Override
128 public String getExpressionName() {
129 return "sequence";
130 }
131
132 /**
133 * Process the instruction, without returning any tail calls
134 *
135 * @param context The dynamic context, giving access to the current node,
136 * the current variables, etc.
137 * @throws XPathException if a dynamic error occurs
138 */
139 @Override
140 public void process(XPathContext context) throws XPathException {
141 getBaseExpression().process(context);
142 }
143
144 /**
145 * Return an Iterator to iterate over the values of a sequence. The value of every
146 * expression can be regarded as a sequence, so this method is supported for all
147 * expressions. This default implementation handles iteration for expressions that
148 * return singleton values: for non-singleton expressions, the subclass must
149 * provide its own implementation.
150 *
151 * @param context supplies the context for evaluation
152 * @return a SequenceIterator that can be used to iterate over the result
153 * of the expression
154 * @throws XPathException if any dynamic error occurs evaluating the
155 * expression
156 */
157 @Override
158 public SequenceIterator<?> iterate(XPathContext context) throws XPathException {
159 return getBaseExpression().iterate(context);
160 }
161
162
163
164 public void export(ExpressionPresenter out) throws XPathException {
165 getBaseExpression().export(out);
166 }
167
168 /**
169 * Get the (partial) name of a class that supports streaming of this kind of expression
170 *
171 * @return the partial name of a class that can be instantiated to provide streaming support in Saxon-EE,
172 * or null if there is no such class
173 */
174 @Override
175 public String getStreamerName() {
176
177 return "SequenceInstr";
178 }
179 }
180