Debian Codegraph @

net/sf/saxon/expr/instruct/OnNonEmptyExpr.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:on-non-empty instruction.
21 */
22 public class OnNonEmptyExpr extends UnaryExpression {
23
24 /**
25 * Create the instruction
26 */
27 public OnNonEmptyExpr(Expression base) {
28 super(base);
29 }
30
31 /**
32 * Ask whether this expression is an instruction. In XSLT streamability analysis this
33 * is used to distinguish constructs corresponding to XSLT instructions from other constructs.
34 *
35 * @return true if this construct originates as an XSLT instruction
36 */
37 @Override
38 public boolean isInstruction() {
39 return true;
40 }
41
42 /**
43 * Get the usage (in terms of streamability analysis) of the single operand
44 *
45 * @return the operand usage
46 */
47 @Override
48 protected OperandRole getOperandRole() {
49 return new OperandRole(0, OperandUsage.TRANSMISSION);
50 }
51
52 /*@NotNull*/
53 public Expression copy(RebindingMap rebindings) {
54 return new OnNonEmptyExpr(getBaseExpression().copy(rebindings));
55 }
56
57 /**
58 * Determine the intrinsic dependencies of an expression, that is, those which are not derived
59 * from the dependencies of its subexpressions. For example, position() has an intrinsic dependency
60 * on the context position, while (position()+1) does not. The default implementation
61 * of the method returns 0, indicating "no dependencies".
62 *
63 * @return a set of bit-significant flags identifying the "intrinsic"
64 * dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
65 */
66 @Override
67 public int getIntrinsicDependencies() {
68 return StaticProperty.HAS_SIDE_EFFECTS; // suppress optimizations such as loop-lifting
69 }
70
71 /**
72 * Ask whether common subexpressions found in the operands of this expression can
73 * be extracted and evaluated outside the expression itself. The result is irrelevant
74 * in the case of operands evaluated with a different focus, which will never be
75 * extracted in this way, even if they have no focus dependency.
76 *
77 * @return false for this kind of expression
78 */
79 @Override
80 public boolean allowExtractingCommonSubexpressions() {
81 return false;
82 }
83
84 /**
85 * Type-check the expression. Default implementation for unary operators that accept
86 * any kind of operand
87 */
88
89 /*@NotNull*/
90 public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
91 getOperand().typeCheck(visitor, contextInfo);
92 return this;
93 }
94
95 /**
96 * Perform optimisation of an expression and its subexpressions.
97 * <p>This method is called after all references to functions and variables have been resolved
98 * to the declaration of the function or variable, and after all type checking has been done.</p>
99 *
100 * @param visitor an expression visitor
101 * @param contextInfo the static type of "." at the point where this expression is invoked.
102 * The parameter is set to null if it is known statically that the context item will be undefined.
103 * If the type of the context item is not known statically, the argument is set to
104 * {@link net.sf.saxon.type.Type#ITEM_TYPE}
105 * @return the original expression, rewritten if appropriate to optimize execution
106 * @throws XPathException if an error is discovered during this phase
107 * (typically a type error)
108 */
109
110 /*@NotNull*/
111 public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
112 getOperand().optimize(visitor, contextInfo);
113 if (visitor.isOptimizeForStreaming()) {
114 visitor.obtainOptimizer().makeCopyOperationsExplicit(this, getOperand());
115 }
116 return this;
117 }
118
119 /**
120 * An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
121 * This method indicates which of these methods is provided directly. The other methods will always be available
122 * indirectly, using an implementation that relies on one of the other methods.
123 *
124 * @return the implementation method, for example {@link #ITERATE_METHOD} or {@link #EVALUATE_METHOD} or
125 * {@link #PROCESS_METHOD}
126 */
127 @Override
128 public int getImplementationMethod() {
129 return getBaseExpression().getImplementationMethod();
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 net.sf.saxon.trans.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 net.sf.saxon.trans.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 * Get a name identifying the kind of expression, in terms meaningful to a user.
164 *
165 * @return a name identifying the kind of expression, in terms meaningful to a user.
166 * The name will always be in the form of a lexical XML QName, and should match the name used
167 * in export() output displaying the expression.
168 */
169 @Override
170 public String getExpressionName() {
171 return "onNonEmpty";
172 }
173
174
175
176 public void export(ExpressionPresenter out) throws XPathException {
177 out.startElement("onNonEmpty", this);
178 getBaseExpression().export(out);
179 out.endElement();
180 }
181
182 /**
183 * Get the (partial) name of a class that supports streaming of this kind of expression
184 *
185 * @return the partial name of a class that can be instantiated to provide streaming support in Saxon-EE,
186 * or null if there is no such class
187 */
188 @Override
189 public String getStreamerName() {
190 return "OnNonEmpty";
191 }
192 }