1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import com.sun.org.apache.bcel.internal.classfile.Field; 23 import com.sun.org.apache.bcel.internal.generic.BranchHandle; 24 import com.sun.org.apache.bcel.internal.generic.CHECKCAST; 25 import com.sun.org.apache.bcel.internal.generic.IFNONNULL; 26 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 27 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 28 import com.sun.org.apache.bcel.internal.generic.Instruction; 29 import com.sun.org.apache.bcel.internal.generic.InstructionList; 30 import com.sun.org.apache.bcel.internal.generic.PUSH; 31 import com.sun.org.apache.bcel.internal.generic.PUTFIELD; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType; 36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 37 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ObjectType; 38 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 39 import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary; 40 41 48 final class Param extends VariableBase { 49 50 55 private boolean _isInSimpleNamedTemplate = false; 56 57 60 public String toString() { 61 return "param(" + _name + ")"; 62 } 63 64 68 public Instruction setLoadInstruction(Instruction instruction) { 69 Instruction tmp = _loadInstruction; 70 _loadInstruction = instruction; 71 return tmp; 72 } 73 74 78 public Instruction setStoreInstruction(Instruction instruction) { 79 Instruction tmp = _storeInstruction; 80 _storeInstruction = instruction; 81 return tmp; 82 } 83 84 87 public void display(int indent) { 88 indent(indent); 89 System.out.println("param " + _name); 90 if (_select != null) { 91 indent(indent + IndentIncrement); 92 System.out.println("select " + _select.toString()); 93 } 94 displayContents(indent + IndentIncrement); 95 } 96 97 101 public void parseContents(Parser parser) { 102 103 super.parseContents(parser); 105 106 final SyntaxTreeNode parent = getParent(); 108 if (parent instanceof Stylesheet) { 109 _isLocal = false; 111 Param param = parser.getSymbolTable().lookupParam(_name); 113 if (param != null) { 115 final int us = this.getImportPrecedence(); 116 final int them = param.getImportPrecedence(); 117 if (us == them) { 119 final String name = _name.toString(); 120 reportError(this, parser, ErrorMsg.VARIABLE_REDEF_ERR,name); 121 } 122 else if (them > us) { 124 _ignore = true; 125 return; 126 } 127 else { 128 param.disable(); 129 } 130 } 131 ((Stylesheet)parent).addParam(this); 133 parser.getSymbolTable().addParam(this); 134 } 135 else if (parent instanceof Template) { 136 Template template = (Template) parent; 137 _isLocal = true; 138 template.addParameter(this); 139 if (template.isSimpleNamedTemplate()) { 140 _isInSimpleNamedTemplate = true; 141 } 142 } 143 } 144 145 150 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 151 if (_select != null) { 152 _type = _select.typeCheck(stable); 153 if (_type instanceof ReferenceType == false && !(_type instanceof ObjectType)) { 154 _select = new CastExpr(_select, Type.Reference); 155 } 156 } 157 else if (hasContents()) { 158 typeCheckContents(stable); 159 } 160 _type = Type.Reference; 161 162 return Type.Void; 165 } 166 167 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 168 final ConstantPoolGen cpg = classGen.getConstantPool(); 169 final InstructionList il = methodGen.getInstructionList(); 170 171 if (_ignore) return; 172 _ignore = true; 173 174 179 final String name = BasisLibrary.mapQNameToJavaName(_name.toString()); 180 final String signature = _type.toSignature(); 181 final String className = _type.getClassName(); 182 183 if (isLocal()) { 184 189 if (_isInSimpleNamedTemplate) { 190 il.append(loadInstruction()); 191 BranchHandle ifBlock = il.append(new IFNONNULL(null)); 192 translateValue(classGen, methodGen); 193 il.append(storeInstruction()); 194 ifBlock.setTarget(il.append(NOP)); 195 return; 196 } 197 198 il.append(classGen.loadTranslet()); 199 il.append(new PUSH(cpg, name)); 200 translateValue(classGen, methodGen); 201 il.append(new PUSH(cpg, true)); 202 203 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, 205 ADD_PARAMETER, 206 ADD_PARAMETER_SIG))); 207 if (className != EMPTYSTRING) { 208 il.append(new CHECKCAST(cpg.addClass(className))); 209 } 210 211 _type.translateUnBox(classGen, methodGen); 212 213 if (_refs.isEmpty()) { il.append(_type.POP()); 215 _local = null; 216 } 217 else { _local = methodGen.addLocalVariable2(name, 219 _type.toJCType(), 220 il.getEnd()); 221 il.append(_type.STORE(_local.getIndex())); 223 } 224 } 225 else { 226 if (classGen.containsField(name) == null) { 227 classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name), 228 cpg.addUtf8(signature), 229 null, cpg.getConstantPool())); 230 il.append(classGen.loadTranslet()); 231 il.append(DUP); 232 il.append(new PUSH(cpg, name)); 233 translateValue(classGen, methodGen); 234 il.append(new PUSH(cpg, true)); 235 236 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, 238 ADD_PARAMETER, 239 ADD_PARAMETER_SIG))); 240 241 _type.translateUnBox(classGen, methodGen); 242 243 if (className != EMPTYSTRING) { 245 il.append(new CHECKCAST(cpg.addClass(className))); 246 } 247 il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(), 248 name, signature))); 249 } 250 } 251 } 252 } 253 | Popular Tags |