1 /* |
1 /* |
2 * reserved comment block |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT REMOVE OR ALTER! |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
19 * limitations under the License. |
19 * limitations under the License. |
20 */ |
20 */ |
21 |
21 |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
22 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
23 |
23 |
24 import java.util.Vector; |
|
25 |
|
26 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
24 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
27 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
25 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
28 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; |
26 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; |
29 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
27 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
30 import com.sun.org.apache.bcel.internal.generic.ICONST; |
28 import com.sun.org.apache.bcel.internal.generic.ICONST; |
31 import com.sun.org.apache.bcel.internal.generic.ILOAD; |
29 import com.sun.org.apache.bcel.internal.generic.ILOAD; |
32 import com.sun.org.apache.bcel.internal.generic.ISTORE; |
|
33 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; |
30 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; |
34 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; |
31 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; |
|
32 import com.sun.org.apache.bcel.internal.generic.ISTORE; |
35 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
33 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
36 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
34 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
37 import com.sun.org.apache.bcel.internal.generic.NEW; |
35 import com.sun.org.apache.bcel.internal.generic.NEW; |
38 import com.sun.org.apache.bcel.internal.generic.PUSH; |
36 import com.sun.org.apache.bcel.internal.generic.PUSH; |
39 import com.sun.org.apache.xalan.internal.xsltc.DOM; |
37 import com.sun.org.apache.xalan.internal.xsltc.DOM; |
42 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
40 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
43 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
41 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
44 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; |
42 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; |
45 import com.sun.org.apache.xml.internal.dtm.Axis; |
43 import com.sun.org.apache.xml.internal.dtm.Axis; |
46 import com.sun.org.apache.xml.internal.dtm.DTM; |
44 import com.sun.org.apache.xml.internal.dtm.DTM; |
|
45 import java.util.List; |
47 |
46 |
48 /** |
47 /** |
49 * @author Jacek Ambroziak |
48 * @author Jacek Ambroziak |
50 * @author Santiago Pericas-Geertsen |
49 * @author Santiago Pericas-Geertsen |
51 * @author Morten Jorgensen |
50 * @author Morten Jorgensen |
58 private int _axis; |
57 private int _axis; |
59 |
58 |
60 /** |
59 /** |
61 * A vector of predicates (filters) defined on this step - may be null |
60 * A vector of predicates (filters) defined on this step - may be null |
62 */ |
61 */ |
63 private Vector _predicates; |
62 private List<Predicate> _predicates; |
64 |
63 |
65 /** |
64 /** |
66 * Some simple predicates can be handled by this class (and not by the |
65 * Some simple predicates can be handled by this class (and not by the |
67 * Predicate class) and will be removed from the above vector as they are |
66 * Predicate class) and will be removed from the above vector as they are |
68 * handled. We use this boolean to remember if we did have any predicates. |
67 * handled. We use this boolean to remember if we did have any predicates. |
72 /** |
71 /** |
73 * Type of the node test. |
72 * Type of the node test. |
74 */ |
73 */ |
75 private int _nodeType; |
74 private int _nodeType; |
76 |
75 |
77 public Step(int axis, int nodeType, Vector predicates) { |
76 public Step(int axis, int nodeType, List<Predicate> predicates) { |
78 _axis = axis; |
77 _axis = axis; |
79 _nodeType = nodeType; |
78 _nodeType = nodeType; |
80 _predicates = predicates; |
79 _predicates = predicates; |
81 } |
80 } |
82 |
81 |
86 public void setParser(Parser parser) { |
85 public void setParser(Parser parser) { |
87 super.setParser(parser); |
86 super.setParser(parser); |
88 if (_predicates != null) { |
87 if (_predicates != null) { |
89 final int n = _predicates.size(); |
88 final int n = _predicates.size(); |
90 for (int i = 0; i < n; i++) { |
89 for (int i = 0; i < n; i++) { |
91 final Predicate exp = (Predicate)_predicates.elementAt(i); |
90 final Predicate exp = _predicates.get(i); |
92 exp.setParser(parser); |
91 exp.setParser(parser); |
93 exp.setParent(this); |
92 exp.setParent(this); |
94 } |
93 } |
95 } |
94 } |
96 } |
95 } |
117 } |
116 } |
118 |
117 |
119 /** |
118 /** |
120 * Returns the vector containing all predicates for this step. |
119 * Returns the vector containing all predicates for this step. |
121 */ |
120 */ |
122 public Vector getPredicates() { |
121 public List<Predicate> getPredicates() { |
123 return _predicates; |
122 return _predicates; |
124 } |
123 } |
125 |
124 |
126 /** |
125 /** |
127 * Returns the vector containing all predicates for this step. |
126 * Returns the vector containing all predicates for this step. |
128 */ |
127 */ |
129 public void addPredicates(Vector predicates) { |
128 public void addPredicates(List<Predicate> predicates) { |
130 if (_predicates == null) { |
129 if (_predicates == null) { |
131 _predicates = predicates; |
130 _predicates = predicates; |
132 } |
131 } |
133 else { |
132 else { |
134 _predicates.addAll(predicates); |
133 _predicates.addAll(predicates); |
211 _type = Type.NodeSet; |
210 _type = Type.NodeSet; |
212 } |
211 } |
213 |
212 |
214 // Type check all predicates (expressions applied to the step) |
213 // Type check all predicates (expressions applied to the step) |
215 if (_predicates != null) { |
214 if (_predicates != null) { |
216 final int n = _predicates.size(); |
215 for (Expression pred : _predicates) { |
217 for (int i = 0; i < n; i++) { |
|
218 final Expression pred = (Expression)_predicates.elementAt(i); |
|
219 pred.typeCheck(stable); |
216 pred.typeCheck(stable); |
220 } |
217 } |
221 } |
218 } |
222 |
219 |
223 // Return either Type.Node or Type.NodeSet |
220 // Return either Type.Node or Type.NodeSet |
247 int star = 0; |
244 int star = 0; |
248 String name = null; |
245 String name = null; |
249 final XSLTC xsltc = getParser().getXSLTC(); |
246 final XSLTC xsltc = getParser().getXSLTC(); |
250 |
247 |
251 if (_nodeType >= DTM.NTYPES) { |
248 if (_nodeType >= DTM.NTYPES) { |
252 final Vector ni = xsltc.getNamesIndex(); |
249 final List<String> ni = xsltc.getNamesIndex(); |
253 |
250 |
254 name = (String)ni.elementAt(_nodeType-DTM.NTYPES); |
251 name = ni.get(_nodeType-DTM.NTYPES); |
255 star = name.lastIndexOf('*'); |
252 star = name.lastIndexOf('*'); |
256 } |
253 } |
257 |
254 |
258 // If it is an attribute, but not '@*', '@pre:*' or '@node()', |
255 // If it is an attribute, but not '@*', '@pre:*' or '@node()', |
259 // and has no parent |
256 // and has no parent |
373 |
370 |
374 if (predicateIndex < 0) { |
371 if (predicateIndex < 0) { |
375 translateStep(classGen, methodGen, predicateIndex); |
372 translateStep(classGen, methodGen, predicateIndex); |
376 } |
373 } |
377 else { |
374 else { |
378 final Predicate predicate = (Predicate) _predicates.get(predicateIndex--); |
375 final Predicate predicate = _predicates.get(predicateIndex--); |
379 |
376 |
380 // Special case for predicates that can use the NodeValueIterator |
377 // Special case for predicates that can use the NodeValueIterator |
381 // instead of an auxiliary class. Certain path/predicates pairs |
378 // instead of an auxiliary class. Certain path/predicates pairs |
382 // are translated into a base path, on top of which we place a |
379 // are translated into a base path, on top of which we place a |
383 // node value iterator that tests for the desired value: |
380 // node value iterator that tests for the desired value: |
523 */ |
520 */ |
524 public String toString() { |
521 public String toString() { |
525 final StringBuffer buffer = new StringBuffer("step(\""); |
522 final StringBuffer buffer = new StringBuffer("step(\""); |
526 buffer.append(Axis.getNames(_axis)).append("\", ").append(_nodeType); |
523 buffer.append(Axis.getNames(_axis)).append("\", ").append(_nodeType); |
527 if (_predicates != null) { |
524 if (_predicates != null) { |
528 final int n = _predicates.size(); |
525 for (Expression pred : _predicates) { |
529 for (int i = 0; i < n; i++) { |
|
530 final Predicate pred = (Predicate)_predicates.elementAt(i); |
|
531 buffer.append(", ").append(pred.toString()); |
526 buffer.append(", ").append(pred.toString()); |
532 } |
527 } |
533 } |
528 } |
534 return buffer.append(')').toString(); |
529 return buffer.append(')').toString(); |
535 } |
530 } |