1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.CHECKCAST; 23 import org.apache.bcel.generic.ConstantPoolGen; 24 import org.apache.bcel.generic.GETFIELD; 25 import org.apache.bcel.generic.INVOKEINTERFACE; 26 import org.apache.bcel.generic.InstructionList; 27 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 28 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 29 import org.apache.xalan.xsltc.compiler.util.NodeSetType; 30 31 37 final class VariableRef extends VariableRefBase { 38 39 public VariableRef(Variable variable) { 40 super(variable); 41 } 42 43 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 44 final ConstantPoolGen cpg = classGen.getConstantPool(); 45 final InstructionList il = methodGen.getInstructionList(); 46 47 if (_type.implementedAsMethod()) return; 49 50 final String name = _variable.getEscapedName(); 51 final String signature = _type.toSignature(); 52 53 if (_variable.isLocal()) { 54 if (classGen.isExternal()) { 55 Closure variableClosure = _closure; 56 while (variableClosure != null) { 57 if (variableClosure.inInnerClass()) break; 58 variableClosure = variableClosure.getParentClosure(); 59 } 60 61 if (variableClosure != null) { 62 il.append(ALOAD_0); 63 il.append(new GETFIELD( 64 cpg.addFieldref(variableClosure.getInnerClassName(), 65 name, signature))); 66 } 67 else { 68 il.append(_variable.loadInstruction()); 69 _variable.removeReference(this); 70 } 71 } 72 else { 73 il.append(_variable.loadInstruction()); 74 _variable.removeReference(this); 75 } 76 } 77 else { 78 final String className = classGen.getClassName(); 79 il.append(classGen.loadTranslet()); 80 if (classGen.isExternal()) { 81 il.append(new CHECKCAST(cpg.addClass(className))); 82 } 83 il.append(new GETFIELD(cpg.addFieldref(className,name,signature))); 84 } 85 86 if (_variable.getType() instanceof NodeSetType) { 87 final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR, 89 "cloneIterator", 90 "()" + 91 NODE_ITERATOR_SIG); 92 il.append(new INVOKEINTERFACE(clone, 1)); 93 } 94 } 95 } 96 | Popular Tags |