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: WithParam.java,v 1.2.4.1 2005/09/12 11:38:01 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 |
|
22 import com.sun.org.apache.bcel.internal.generic.ALOAD; |
|
23 import com.sun.org.apache.bcel.internal.generic.ASTORE; |
|
24 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; |
26 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; |
|
26 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; |
27 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
27 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; |
28 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
28 import com.sun.org.apache.bcel.internal.generic.InstructionList; |
|
29 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; |
29 import com.sun.org.apache.bcel.internal.generic.PUSH; |
30 import com.sun.org.apache.bcel.internal.generic.PUSH; |
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; |
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; |
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType; |
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType; |
58 * Parameter's default value. |
59 * Parameter's default value. |
59 */ |
60 */ |
60 private Expression _select; |
61 private Expression _select; |
61 |
62 |
62 /** |
63 /** |
|
64 * Reference to JVM variable holding temporary result tree. |
|
65 */ |
|
66 private LocalVariableGen _domAdapter; |
|
67 |
|
68 /** |
63 * %OPT% This is set to true when the WithParam is used in a CallTemplate |
69 * %OPT% This is set to true when the WithParam is used in a CallTemplate |
64 * for a simple named template. If this is true, the parameters are |
70 * for a simple named template. If this is true, the parameters are |
65 * passed to the named template through method arguments rather than |
71 * passed to the named template through method arguments rather than |
66 * using the expensive Translet.addParameter() call. |
72 * using the expensive Translet.addParameter() call. |
67 */ |
73 */ |
162 if (_select != null) { |
168 if (_select != null) { |
163 _select.translate(classGen, methodGen); |
169 _select.translate(classGen, methodGen); |
164 _select.startIterator(classGen, methodGen); |
170 _select.startIterator(classGen, methodGen); |
165 } |
171 } |
166 // If not, compile result tree from parameter body if present. |
172 // If not, compile result tree from parameter body if present. |
|
173 // Store result tree into local variable for releasing it later |
167 else if (hasContents()) { |
174 else if (hasContents()) { |
|
175 final InstructionList il = methodGen.getInstructionList(); |
168 compileResultTree(classGen, methodGen); |
176 compileResultTree(classGen, methodGen); |
|
177 _domAdapter = methodGen.addLocalVariable2("@" + _escapedName, Type.ResultTree.toJCType(), il.getEnd()); |
|
178 il.append(DUP); |
|
179 il.append(new ASTORE(_domAdapter.getIndex())); |
169 } |
180 } |
170 // If neither are present then store empty string in parameter slot |
181 // If neither are present then store empty string in parameter slot |
171 else { |
182 else { |
172 final ConstantPoolGen cpg = classGen.getConstantPool(); |
183 final ConstantPoolGen cpg = classGen.getConstantPool(); |
173 final InstructionList il = methodGen.getInstructionList(); |
184 final InstructionList il = methodGen.getInstructionList(); |
206 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, |
217 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, |
207 ADD_PARAMETER, |
218 ADD_PARAMETER, |
208 ADD_PARAMETER_SIG))); |
219 ADD_PARAMETER_SIG))); |
209 il.append(POP); // cleanup stack |
220 il.append(POP); // cleanup stack |
210 } |
221 } |
|
222 |
|
223 /** |
|
224 * Release the compiled result tree. |
|
225 */ |
|
226 public void releaseResultTree(ClassGenerator classGen, MethodGenerator methodGen) { |
|
227 if (_domAdapter != null) { |
|
228 final ConstantPoolGen cpg = classGen.getConstantPool(); |
|
229 final InstructionList il = methodGen.getInstructionList(); |
|
230 if (classGen.getStylesheet().callsNodeset() && classGen.getDOMClass().equals(MULTI_DOM_CLASS)) { |
|
231 final int removeDA = cpg.addMethodref(MULTI_DOM_CLASS, "removeDOMAdapter", "(" + DOM_ADAPTER_SIG + ")V"); |
|
232 il.append(methodGen.loadDOM()); |
|
233 il.append(new CHECKCAST(cpg.addClass(MULTI_DOM_CLASS))); |
|
234 il.append(new ALOAD(_domAdapter.getIndex())); |
|
235 il.append(new CHECKCAST(cpg.addClass(DOM_ADAPTER_CLASS))); |
|
236 il.append(new INVOKEVIRTUAL(removeDA)); |
|
237 } |
|
238 final int release = cpg.addInterfaceMethodref(DOM_IMPL_CLASS, "release", "()V"); |
|
239 il.append(new ALOAD(_domAdapter.getIndex())); |
|
240 il.append(new INVOKEINTERFACE(release, 1)); |
|
241 _domAdapter = null; |
|
242 } |
|
243 } |
211 } |
244 } |