6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: ParameterRef.java,v 1.2.4.1 2005/09/02 11:05:08 pvedula Exp $
|
|
22 |
*/
|
|
23 |
|
|
24 |
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
|
25 |
|
|
26 |
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
|
|
27 |
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
|
28 |
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
|
|
29 |
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
|
|
30 |
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
|
31 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
|
32 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
|
33 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
|
|
34 |
import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* @author Jacek Ambroziak
|
|
38 |
* @author Santiago Pericas-Geertsen
|
|
39 |
* @author Morten Jorgensen
|
|
40 |
* @author Erwin Bolwidt <ejb@klomp.org>
|
|
41 |
*/
|
|
42 |
final class ParameterRef extends VariableRefBase {
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Name of param being referenced.
|
|
46 |
*/
|
|
47 |
QName _name = null;
|
|
48 |
|
|
49 |
public ParameterRef(Param param) {
|
|
50 |
super(param);
|
|
51 |
_name = param._name;
|
|
52 |
|
|
53 |
}
|
|
54 |
|
|
55 |
public String toString() {
|
|
56 |
return "parameter-ref("+_variable.getName()+'/'+_variable.getType()+')';
|
|
57 |
}
|
|
58 |
|
|
59 |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
|
|
60 |
final ConstantPoolGen cpg = classGen.getConstantPool();
|
|
61 |
final InstructionList il = methodGen.getInstructionList();
|
|
62 |
|
|
63 |
/*
|
|
64 |
* To fix bug 24518 related to setting parameters of the form
|
|
65 |
* {namespaceuri}localName, which will get mapped to an instance
|
|
66 |
* variable in the class.
|
|
67 |
*/
|
|
68 |
final String name = BasisLibrary.mapQNameToJavaName (_name.toString());
|
|
69 |
final String signature = _type.toSignature();
|
|
70 |
|
|
71 |
if (_variable.isLocal()) {
|
|
72 |
if (classGen.isExternal()) {
|
|
73 |
Closure variableClosure = _closure;
|
|
74 |
while (variableClosure != null) {
|
|
75 |
if (variableClosure.inInnerClass()) break;
|
|
76 |
variableClosure = variableClosure.getParentClosure();
|
|
77 |
}
|
|
78 |
|
|
79 |
if (variableClosure != null) {
|
|
80 |
il.append(ALOAD_0);
|
|
81 |
il.append(new GETFIELD(
|
|
82 |
cpg.addFieldref(variableClosure.getInnerClassName(),
|
|
83 |
name, signature)));
|
|
84 |
}
|
|
85 |
else {
|
|
86 |
il.append(_variable.loadInstruction());
|
|
87 |
}
|
|
88 |
}
|
|
89 |
else {
|
|
90 |
il.append(_variable.loadInstruction());
|
|
91 |
}
|
|
92 |
}
|
|
93 |
else {
|
|
94 |
final String className = classGen.getClassName();
|
|
95 |
il.append(classGen.loadTranslet());
|
|
96 |
if (classGen.isExternal()) {
|
|
97 |
il.append(new CHECKCAST(cpg.addClass(className)));
|
|
98 |
}
|
|
99 |
il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
|
|
100 |
}
|
|
101 |
|
|
102 |
if (_variable.getType() instanceof NodeSetType) {
|
|
103 |
// The method cloneIterator() also does resetting
|
|
104 |
final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
|
|
105 |
"cloneIterator",
|
|
106 |
"()" +
|
|
107 |
NODE_ITERATOR_SIG);
|
|
108 |
il.append(new INVOKEINTERFACE(clone, 1));
|
|
109 |
}
|
|
110 |
}
|
|
111 |
}
|