Debian Codegraph @

net/sf/saxon/expr/StaticProperty.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;
9
10 import net.sf.saxon.tree.util.FastStringBuffer;
11 import net.sf.saxon.value.Cardinality;
12
13 /**
14 * This class contains constants identifying dependencies that an XPath expression
15 * might have on its context.
16 */
17
18 public abstract class StaticProperty {
19
20 // TODO: use an EnumSet
21
22 /**
23 * Bit setting: Expression depends on current() item
24 */
25
26 public static final int DEPENDS_ON_CURRENT_ITEM = 1;
27
28 /**
29 * Bit setting: Expression depends on context item
30 */
31
32 public static final int DEPENDS_ON_CONTEXT_ITEM = 1 << 1;
33
34 /**
35 * Bit setting: Expression depends on position()
36 */
37
38 public static final int DEPENDS_ON_POSITION = 1 << 2;
39
40 /**
41 * Bit setting: Expression depends on last()
42 */
43
44 public static final int DEPENDS_ON_LAST = 1 << 3;
45
46 /**
47 * Bit setting: Expression depends on the document containing the context node
48 */
49
50 public static final int DEPENDS_ON_CONTEXT_DOCUMENT = 1 << 4;
51
52 /**
53 * Bit setting: Expression depends on current-group() and/or current-grouping-key()
54 */
55
56 public static final int DEPENDS_ON_CURRENT_GROUP = 1 << 5;
57
58 /**
59 * Bit setting: Expression depends on regex-group()
60 */
61
62 public static final int DEPENDS_ON_REGEX_GROUP = 1 << 6;
63
64
65 /**
66 * Bit setting: Expression depends on local variables
67 */
68
69 public static final int DEPENDS_ON_LOCAL_VARIABLES = 1 << 7;
70
71 /**
72 * Bit setting: Expression depends on user-defined functions
73 */
74
75 public static final int DEPENDS_ON_USER_FUNCTIONS = 1 << 8;
76
77 /**
78 * Bit setting: Expression depends on assignable global variables
79 */
80
81 public static final int DEPENDS_ON_ASSIGNABLE_GLOBALS = 1 << 9;
82
83 /**
84 * Bit setting: Expression can't be evaluated at compile time for reasons other than the above
85 */
86
87 public static final int DEPENDS_ON_RUNTIME_ENVIRONMENT = 1 << 10;
88
89 /**
90 * Bit setting: Expression depends on the static context, specifically, a part of the static
91 * context that can vary from one expression in a query/stylesheet to another; the main
92 * examples of this are the static base URI and the default collation
93 */
94
95 public static final int DEPENDS_ON_STATIC_CONTEXT = 1 << 11;
96
97 /**
98 * Combination of bits representing dependencies on the XSLT context
99 */
100
101 public static final int DEPENDS_ON_XSLT_CONTEXT =
102 DEPENDS_ON_CURRENT_ITEM |
103 DEPENDS_ON_CURRENT_GROUP |
104 DEPENDS_ON_REGEX_GROUP |
105 DEPENDS_ON_ASSIGNABLE_GLOBALS;
106
107 /**
108 * Combination of bits representing dependencies on the focus
109 */
110
111 public static final int DEPENDS_ON_FOCUS =
112 DEPENDS_ON_CONTEXT_ITEM |
113 DEPENDS_ON_POSITION |
114 DEPENDS_ON_LAST |
115 DEPENDS_ON_CONTEXT_DOCUMENT;
116
117 /**
118 * Combination of bits representing dependencies on the focus, but excluding dependencies
119 * on the current document
120 */
121
122 public static final int DEPENDS_ON_NON_DOCUMENT_FOCUS =
123 DEPENDS_ON_CONTEXT_ITEM |
124 DEPENDS_ON_POSITION |
125 DEPENDS_ON_LAST;
126
127 /*
128 * Bit set if an empty sequence is allowed
129 */
130
131 public static final int ALLOWS_ZERO = 1 << 13;
132
133 /**
134 * Bit set if a single value is allowed
135 */
136
137 public static final int ALLOWS_ONE = 1 << 14;
138
139 /**
140 * Bit set if multiple values are allowed
141 */
142
143 public static final int ALLOWS_MANY = 1 << 15;
144
145 /**
146 * Mask for all cardinality bits
147 */
148
149 public static final int CARDINALITY_MASK =
150 ALLOWS_ZERO | ALLOWS_ONE | ALLOWS_MANY;
151
152 /**
153 * Occurence indicator for "one or more" (+)
154 */
155
156 public static final int ALLOWS_ONE_OR_MORE =
157 ALLOWS_ONE | ALLOWS_MANY;
158
159 /**
160 * Occurence indicator for "zero or more" (*)
161 */
162
163 public static final int ALLOWS_ZERO_OR_MORE =
164 ALLOWS_ZERO | ALLOWS_ONE | ALLOWS_MANY;
165
166 /**
167 * Occurence indicator for "zero or one" (?)
168 */
169
170 public static final int ALLOWS_ZERO_OR_ONE =
171 ALLOWS_ZERO | ALLOWS_ONE;
172
173 /**
174 * Occurence indicator for "exactly one" (default occurrence indicator)
175 */
176
177 public static final int EXACTLY_ONE = ALLOWS_ONE;
178
179 /**
180 * Occurence indicator when an empty sequence is required
181 */
182
183 public static final int EMPTY = ALLOWS_ZERO;
184
185 /**
186 * Reduce the cardinality value to an integer in the range 0-7
187 *
188 * @param cardinality the result of calling getCardinality() on an expression
189 * @return the cardinality code
190 */
191
192 public static int getCardinalityCode(int cardinality) {
193 return (cardinality & CARDINALITY_MASK) >> 13;
194 }
195
196 /**
197 * Expression property: this bit is set by getProperties() in the case of
198 * an expression whose item type is node, when the nodes in the result are
199 * guaranteed all to be in the same document as the context node. For
200 * expressions that return values other than nodes, the setting is undefined.
201 */
202
203 public static final int CONTEXT_DOCUMENT_NODESET = 1 << 16;
204
205 /**
206 * Expression property: this bit is set by getProperties() in the case of
207 * an expression whose item type is node, when the nodes in the result are
208 * in document order.
209 */
210
211 public static final int ORDERED_NODESET = 1 << 17;
212
213 /**
214 * Expression property: this bit is set by getProperties() in the case of
215 * an expression that delivers items in the reverse of the correct order, when unordered
216 * retrieval is requested.
217 */
218
219 public static final int REVERSE_DOCUMENT_ORDER = 1 << 18;
220
221 /**
222 * Expression property: this bit is set by getProperties() in the case of
223 * an expression that delivers a set of nodes with the guarantee that no node in the
224 * set will be an ancestor of any other. This property is useful in deciding whether the
225 * results of a path expression are pre-sorted. The property is only used in the case where
226 * the ORDERED_NODESET property is true, so there is no point in setting it in other cases.
227 */
228
229 public static final int PEER_NODESET = 1 << 19;
230
231 /**
232 * Expression property: this bit is set by getProperties() in the case of
233 * an expression that delivers a set of nodes with the guarantee that every node in the
234 * result will be a descendant or self, or attribute or namespace, of the context node
235 */
236
237 public static final int SUBTREE_NODESET = 1 << 20;
238
239 /**
240 * Expression property: this bit is set by getProperties() in the case of
241 * an expression that delivers a set of nodes with the guarantee that every node in the
242 * result will be an attribute or namespace of the context node
243 */
244
245 public static final int ATTRIBUTE_NS_NODESET = 1 << 21;
246
247 /**
248 * Expression property: this bit indicates that the expression will always create new
249 * nodes: more specifically, any node in the result of the expression is guaranteed
250 * to be a newly created node.
251 */
252
253 public static final int ALL_NODES_NEWLY_CREATED = 1 << 22;
254
255 /**
256 * Expression property: this bit is set in the case of an expression that will
257 * never return newly created nodes, nor a value that depends on the identity
258 * of newly created nodes (for example generate-id(new-node())). Expressions
259 * that are capable of creating new nodes cannot be moved out of loops as this could cause
260 * too few nodes to be created: for example if f() creates a new node, then
261 * count(for $i in 1 to 5 return f()) must be 5.
262 */
263
264 public static final int NO_NODES_NEWLY_CREATED = 1 << 23;
265
266 /**
267 * Expression property: this bit is set in the case of an expression that delivers
268 * a set of nodes that are all in the same document (not necessarily the same
269 * document as the context node).
270 */
271
272 public static final int SINGLE_DOCUMENT_NODESET = 1 << 24;
273
274 /**
275 * Expression property: this bit indicates that an expression has (or might have)
276 * side-effects. This property is applied to calls on extension functions and to
277 * certain instructions such as xsl:result-document and xsl:message.
278 */
279
280 public static final int HAS_SIDE_EFFECTS = 1 << 25;
281
282 /**
283 * Expression property: this bit indicates that although the static type of the expression
284 * permits untyped atomic values, it is known that the value will not be untyped atomic.
285 */
286
287 public static final int NOT_UNTYPED_ATOMIC = 1 << 26;
288
289 /**
290 * Expression property: this bit indicates that in the result of an expression,
291 * any element and attribute nodes that are present will have type annotation xs:untyped or
292 * xs:untypedAtomic respectively, and that any document nodes that are present will have
293 * no element children whose type annotation is anything other than xs:untyped
294 */
295
296 public static final int ALL_NODES_UNTYPED = 1 << 27;
297
298
299 /**
300 * Mask to select all the dependency bits
301 */
302
303 public static final int DEPENDENCY_MASK =
304 DEPENDS_ON_CONTEXT_DOCUMENT |
305 DEPENDS_ON_CONTEXT_ITEM |
306 DEPENDS_ON_CURRENT_GROUP |
307 DEPENDS_ON_REGEX_GROUP |
308 DEPENDS_ON_CURRENT_ITEM |
309 DEPENDS_ON_FOCUS |
310 DEPENDS_ON_LOCAL_VARIABLES |
311 DEPENDS_ON_USER_FUNCTIONS |
312 DEPENDS_ON_ASSIGNABLE_GLOBALS |
313 DEPENDS_ON_RUNTIME_ENVIRONMENT |
314 DEPENDS_ON_STATIC_CONTEXT |
315 HAS_SIDE_EFFECTS;
316
317 /**
318 * Mask for "special properties": that is, all properties other than cardinality
319 * and dependencies
320 */
321
322 public static final int SPECIAL_PROPERTY_MASK =
323 CONTEXT_DOCUMENT_NODESET |
324 ORDERED_NODESET |
325 REVERSE_DOCUMENT_ORDER |
326 PEER_NODESET |
327 SUBTREE_NODESET |
328 ATTRIBUTE_NS_NODESET |
329 SINGLE_DOCUMENT_NODESET |
330 NO_NODES_NEWLY_CREATED |
331 HAS_SIDE_EFFECTS |
332 NOT_UNTYPED_ATOMIC |
333 ALL_NODES_UNTYPED |
334 ALL_NODES_NEWLY_CREATED;
335
336 /**
337 * Mask for nodeset-related properties
338 */
339
340 public static final int NODESET_PROPERTIES =
341 CONTEXT_DOCUMENT_NODESET |
342 ORDERED_NODESET |
343 REVERSE_DOCUMENT_ORDER |
344 PEER_NODESET |
345 SUBTREE_NODESET |
346 ATTRIBUTE_NS_NODESET |
347 SINGLE_DOCUMENT_NODESET |
348 ALL_NODES_UNTYPED;
349
350 // This class is not instantiated
351 private StaticProperty() {
352 }
353
354 // For diagnostic display of static properties
355 public static String display(int props) {
356 FastStringBuffer s = new FastStringBuffer(128);
357 s.append("D(");
358 if ((props & DEPENDS_ON_CURRENT_ITEM) != 0) {
359 s.append("U");
360 }
361 if ((props & DEPENDS_ON_CONTEXT_ITEM) != 0) {
362 s.append("C");
363 }
364 if ((props & DEPENDS_ON_POSITION) != 0) {
365 s.append("P");
366 }
367 if ((props & DEPENDS_ON_LAST) != 0) {
368 s.append("L");
369 }
370 if ((props & DEPENDS_ON_CONTEXT_DOCUMENT) != 0) {
371 s.append("D");
372 }
373 if ((props & DEPENDS_ON_LOCAL_VARIABLES) != 0) {
374 s.append("V");
375 }
376 if ((props & DEPENDS_ON_ASSIGNABLE_GLOBALS) != 0) {
377 s.append("A");
378 }
379 if ((props & DEPENDS_ON_REGEX_GROUP) != 0) {
380 s.append("R");
381 }
382 if ((props & DEPENDS_ON_RUNTIME_ENVIRONMENT) != 0) {
383 s.append("E");
384 }
385 if ((props & DEPENDS_ON_STATIC_CONTEXT) != 0) {
386 s.append("S");
387 }
388 s.append(") C(");
389 boolean m = Cardinality.allowsMany(props);
390 boolean z = Cardinality.allowsZero(props);
391 if (m && z) {
392 s.append("*");
393 } else if (m) {
394 s.append("+");
395 } else if (z) {
396 s.append("?");
397 } else {
398 s.append("1");
399 }
400 s.append(") S(");
401 if ((props & HAS_SIDE_EFFECTS) != 0) {
402 s.append("E");
403 }
404 if ((props & NO_NODES_NEWLY_CREATED) != 0) {
405 s.append("N");
406 }
407 if ((props & NOT_UNTYPED_ATOMIC) != 0) {
408 s.append("T");
409 }
410 if ((props & ORDERED_NODESET) != 0) {
411 s.append("O");
412 }
413 if ((props & PEER_NODESET) != 0) {
414 s.append("P");
415 }
416 if ((props & REVERSE_DOCUMENT_ORDER) != 0) {
417 s.append("R");
418 }
419 if ((props & SINGLE_DOCUMENT_NODESET) != 0) {
420 s.append("S");
421 }
422 if ((props & SUBTREE_NODESET) != 0) {
423 s.append("D");
424 }
425 s.append(")");
426 return s.toString();
427
428 }
429 }