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.ACONST_NULL; 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.DCONST; 26 import com.sun.org.apache.bcel.internal.generic.ICONST; 27 import com.sun.org.apache.bcel.internal.generic.InstructionList; 28 import com.sun.org.apache.bcel.internal.generic.PUTFIELD; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType; 30 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.IntType; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeType; 35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.RealType; 36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 37 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 38 39 46 final class Variable extends VariableBase { 47 48 public int getIndex() { 49 return (_local != null) ? _local.getIndex() : -1; 50 } 51 52 55 public void parseContents(Parser parser) { 56 super.parseContents(parser); 58 59 SyntaxTreeNode parent = getParent(); 61 if (parent instanceof Stylesheet) { 62 _isLocal = false; 64 Variable var = parser.getSymbolTable().lookupVariable(_name); 66 if (var != null) { 68 final int us = this.getImportPrecedence(); 69 final int them = var.getImportPrecedence(); 70 if (us == them) { 72 final String name = _name.toString(); 73 reportError(this, parser, ErrorMsg.VARIABLE_REDEF_ERR,name); 74 } 75 else if (them > us) { 77 _ignore = true; 78 return; 79 } 80 else { 81 var.disable(); 82 } 83 } 85 ((Stylesheet)parent).addVariable(this); 86 parser.getSymbolTable().addVariable(this); 87 } 88 else { 89 _isLocal = true; 90 } 91 } 92 93 97 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 98 99 if (_select != null) { 101 _type = _select.typeCheck(stable); 102 } 103 else if (hasContents()) { 105 typeCheckContents(stable); 106 _type = Type.ResultTree; 107 } 108 else { 109 _type = Type.Reference; 110 } 111 return Type.Void; 115 } 116 117 122 public void initialize(ClassGenerator classGen, MethodGenerator methodGen) { 123 final ConstantPoolGen cpg = classGen.getConstantPool(); 124 final InstructionList il = methodGen.getInstructionList(); 125 126 if (isLocal() && !_refs.isEmpty()) { 128 if (_local == null) { 130 _local = methodGen.addLocalVariable2(getEscapedName(), 131 _type.toJCType(), 132 il.getEnd()); 133 } 134 if ((_type instanceof IntType) || 136 (_type instanceof NodeType) || 137 (_type instanceof BooleanType)) 138 il.append(new ICONST(0)); else if (_type instanceof RealType) 140 il.append(new DCONST(0)); else 142 il.append(new ACONST_NULL()); il.append(_type.STORE(_local.getIndex())); 144 } 145 } 146 147 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 148 final ConstantPoolGen cpg = classGen.getConstantPool(); 149 final InstructionList il = methodGen.getInstructionList(); 150 151 final String name = getEscapedName(); 152 153 if (_ignore) return; 155 _ignore = true; 156 157 if (isLocal()) { 158 translateValue(classGen, methodGen); 160 161 if (_refs.isEmpty()) { il.append(_type.POP()); 164 _local = null; 165 } 166 else { if (_local == null) mapRegister(methodGen); 168 il.append(_type.STORE(_local.getIndex())); 169 } 170 } 171 else { 172 String signature = _type.toSignature(); 173 174 if (classGen.containsField(name) == null) { 176 classGen.addField(new Field(ACC_PUBLIC, 177 cpg.addUtf8(name), 178 cpg.addUtf8(signature), 179 null, cpg.getConstantPool())); 180 181 il.append(classGen.loadTranslet()); 183 translateValue(classGen, methodGen); 185 il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(), 187 name, signature))); 188 } 189 } 190 } 191 } 192 | Popular Tags |