15 * distributed under the License is distributed on an "AS IS" BASIS, |
14 * distributed under the License is distributed on an "AS IS" BASIS, |
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 * See the License for the specific language governing permissions and |
16 * See the License for the specific language governing permissions and |
18 * limitations under the License. |
17 * limitations under the License. |
19 */ |
18 */ |
20 /* |
|
21 * $Id: CallTemplate.java,v 1.2.4.1 2005/09/12 10:02:41 pvedula Exp $ |
|
22 */ |
|
23 |
19 |
24 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
20 package com.sun.org.apache.xalan.internal.xsltc.compiler; |
25 |
21 |
26 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
|
27 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
|
28 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
29 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
23 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
30 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
24 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
31 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
|
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
25 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; |
36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
54 /** |
47 /** |
55 * The array of effective parameters in this CallTemplate. An object in |
48 * The array of effective parameters in this CallTemplate. An object in |
56 * this array can be either a WithParam or a Param if no WithParam |
49 * this array can be either a WithParam or a Param if no WithParam |
57 * exists for a particular parameter. |
50 * exists for a particular parameter. |
58 */ |
51 */ |
59 private Object[] _parameters = null; |
52 private SyntaxTreeNode[] _parameters = null; |
60 |
53 |
61 /** |
54 /** |
62 * The corresponding template which this CallTemplate calls. |
55 * The corresponding template which this CallTemplate calls. |
63 */ |
56 */ |
64 private Template _calleeTemplate = null; |
57 private Template _calleeTemplate = null; |
145 StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG |
138 StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG |
146 + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); |
139 + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); |
147 |
140 |
148 // If calling a simply named template, push actual arguments |
141 // If calling a simply named template, push actual arguments |
149 if (_calleeTemplate != null) { |
142 if (_calleeTemplate != null) { |
150 Vector calleeParams = _calleeTemplate.getParameters(); |
|
151 int numParams = _parameters.length; |
143 int numParams = _parameters.length; |
152 |
144 |
153 for (int i = 0; i < numParams; i++) { |
145 for (int i = 0; i < numParams; i++) { |
154 SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i]; |
146 SyntaxTreeNode node = _parameters[i]; |
155 methodSig.append(OBJECT_SIG); // append Object to signature |
147 methodSig.append(OBJECT_SIG); // append Object to signature |
156 |
148 |
157 // Push 'null' if Param to indicate no actual parameter specified |
149 // Push 'null' if Param to indicate no actual parameter specified |
158 if (node instanceof Param) { |
150 if (node instanceof Param) { |
159 il.append(ACONST_NULL); |
151 il.append(ACONST_NULL); |
167 // Complete signature and generate invokevirtual call |
159 // Complete signature and generate invokevirtual call |
168 methodSig.append(")V"); |
160 methodSig.append(")V"); |
169 il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, |
161 il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, |
170 methodName, |
162 methodName, |
171 methodSig.toString()))); |
163 methodSig.toString()))); |
|
164 |
|
165 // release temporary result trees |
|
166 if (_parameters != null) { |
|
167 for (int i = 0; i < _parameters.length; i++) { |
|
168 if (_parameters[i] instanceof WithParam) { |
|
169 ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); |
|
170 } |
|
171 } |
|
172 } |
172 |
173 |
173 // Do not need to call Translet.popParamFrame() if we are |
174 // Do not need to call Translet.popParamFrame() if we are |
174 // calling a simple named template. |
175 // calling a simple named template. |
175 if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { |
176 if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { |
176 // Pop parameter frame |
177 // Pop parameter frame |
201 * the Param with a corresponding WithParam having the same name. |
202 * the Param with a corresponding WithParam having the same name. |
202 */ |
203 */ |
203 private void buildParameterList() { |
204 private void buildParameterList() { |
204 // Put the parameters from the called template into the array first. |
205 // Put the parameters from the called template into the array first. |
205 // This is to ensure the order of the parameters. |
206 // This is to ensure the order of the parameters. |
206 Vector defaultParams = _calleeTemplate.getParameters(); |
207 Vector<Param> defaultParams = _calleeTemplate.getParameters(); |
207 int numParams = defaultParams.size(); |
208 int numParams = defaultParams.size(); |
208 _parameters = new Object[numParams]; |
209 _parameters = new SyntaxTreeNode[numParams]; |
209 for (int i = 0; i < numParams; i++) { |
210 for (int i = 0; i < numParams; i++) { |
210 _parameters[i] = defaultParams.elementAt(i); |
211 _parameters[i] = defaultParams.elementAt(i); |
211 } |
212 } |
212 |
213 |
213 // Replace a Param with a WithParam if they have the same name. |
214 // Replace a Param with a WithParam if they have the same name. |
220 WithParam withParam = (WithParam)node; |
221 WithParam withParam = (WithParam)node; |
221 QName name = withParam.getName(); |
222 QName name = withParam.getName(); |
222 |
223 |
223 // Search for a Param with the same name |
224 // Search for a Param with the same name |
224 for (int k = 0; k < numParams; k++) { |
225 for (int k = 0; k < numParams; k++) { |
225 Object object = _parameters[k]; |
226 SyntaxTreeNode parm = _parameters[k]; |
226 if (object instanceof Param |
227 if (parm instanceof Param |
227 && ((Param)object).getName().equals(name)) { |
228 && ((Param)parm).getName().equals(name)) { |
228 withParam.setDoParameterOptimization(true); |
229 withParam.setDoParameterOptimization(true); |
229 _parameters[k] = withParam; |
230 _parameters[k] = withParam; |
230 break; |
231 break; |
231 } |
232 } |
232 else if (object instanceof WithParam |
233 else if (parm instanceof WithParam |
233 && ((WithParam)object).getName().equals(name)) { |
234 && ((WithParam)parm).getName().equals(name)) { |
234 withParam.setDoParameterOptimization(true); |
235 withParam.setDoParameterOptimization(true); |
235 _parameters[k] = withParam; |
236 _parameters[k] = withParam; |
236 break; |
237 break; |
237 } |
238 } |
238 } |
239 } |