1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.INVOKEVIRTUAL; 24 import org.apache.bcel.generic.InstructionList; 25 import org.apache.bcel.generic.PUSH; 26 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 27 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 28 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 29 import org.apache.xalan.xsltc.compiler.util.ReferenceType; 30 import org.apache.xalan.xsltc.compiler.util.Type; 31 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 32 import org.apache.xalan.xsltc.compiler.util.Util; 33 import org.apache.xml.utils.XMLChar; 34 35 41 final class WithParam extends Instruction { 42 43 46 private QName _name; 47 48 51 protected String _escapedName; 52 53 56 private Expression _select; 57 58 64 private boolean _doParameterOptimization = false; 65 66 69 public void display(int indent) { 70 indent(indent); 71 Util.println("with-param " + _name); 72 if (_select != null) { 73 indent(indent + IndentIncrement); 74 Util.println("select " + _select.toString()); 75 } 76 displayContents(indent + IndentIncrement); 77 } 78 79 82 public String getEscapedName() { 83 return _escapedName; 84 } 85 86 89 public QName getName() { 90 return _name; 91 } 92 93 96 public void setName(QName name) { 97 _name = name; 98 _escapedName = Util.escape(name.getStringRep()); 99 } 100 101 104 public void setDoParameterOptimization(boolean flag) { 105 _doParameterOptimization = flag; 106 } 107 108 112 public void parseContents(Parser parser) { 113 final String name = getAttribute("name"); 114 if (name.length() > 0) { 115 if (!XMLChar.isValidQName(name)) { 116 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, 117 this); 118 parser.reportError(Constants.ERROR, err); 119 } 120 setName(parser.getQNameIgnoreDefaultNs(name)); 121 } 122 else { 123 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name"); 124 } 125 126 final String select = getAttribute("select"); 127 if (select.length() > 0) { 128 _select = parser.parseExpression(this, "select", null); 129 } 130 131 parseChildren(parser); 132 } 133 134 138 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 139 if (_select != null) { 140 final Type tselect = _select.typeCheck(stable); 141 if (tselect instanceof ReferenceType == false) { 142 _select = new CastExpr(_select, Type.Reference); 143 } 144 } 145 else { 146 typeCheckContents(stable); 147 } 148 return Type.Void; 149 } 150 151 155 public void translateValue(ClassGenerator classGen, 156 MethodGenerator methodGen) { 157 if (_select != null) { 159 _select.translate(classGen, methodGen); 160 _select.startIterator(classGen, methodGen); 161 } 162 else if (hasContents()) { 164 compileResultTree(classGen, methodGen); 165 } 166 else { 168 final ConstantPoolGen cpg = classGen.getConstantPool(); 169 final InstructionList il = methodGen.getInstructionList(); 170 il.append(new PUSH(cpg, Constants.EMPTYSTRING)); 171 } 172 } 173 174 179 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 180 final ConstantPoolGen cpg = classGen.getConstantPool(); 181 final InstructionList il = methodGen.getInstructionList(); 182 183 if (_doParameterOptimization) { 185 translateValue(classGen, methodGen); 186 return; 187 } 188 189 String name = Util.escape(getEscapedName()); 191 192 il.append(classGen.loadTranslet()); 194 195 il.append(new PUSH(cpg, name)); translateValue(classGen, methodGen); 199 il.append(new PUSH(cpg, false)); 201 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, 203 ADD_PARAMETER, 204 ADD_PARAMETER_SIG))); 205 il.append(POP); } 207 } 208 | Popular Tags |