1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ALOAD; 23 import org.apache.bcel.generic.ASTORE; 24 import org.apache.bcel.generic.ConstantPoolGen; 25 import org.apache.bcel.generic.GETFIELD; 26 import org.apache.bcel.generic.INVOKEINTERFACE; 27 import org.apache.bcel.generic.INVOKESTATIC; 28 import org.apache.bcel.generic.INVOKEVIRTUAL; 29 import org.apache.bcel.generic.InstructionList; 30 import org.apache.bcel.generic.LocalVariableGen; 31 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 32 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 33 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 34 import org.apache.xalan.xsltc.compiler.util.Type; 35 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 36 import org.apache.xalan.xsltc.compiler.util.Util; 37 import org.apache.xml.utils.XMLChar; 38 39 43 final class ProcessingInstruction extends Instruction { 44 45 private AttributeValue _name; private boolean _isLiteral = false; 48 public void parseContents(Parser parser) { 49 final String name = getAttribute("name"); 50 51 if (name.length() > 0) { 52 _isLiteral = Util.isLiteral(name); 53 if (_isLiteral) { 54 if (!XMLChar.isValidNCName(name)) { 55 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_NCNAME_ERR, name, this); 56 parser.reportError(Constants.ERROR, err); 57 } 58 } 59 _name = AttributeValue.create(this, name, parser); 60 } 61 else 62 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "name"); 63 64 if (name.equals("xml")) { 65 reportError(this, parser, ErrorMsg.ILLEGAL_PI_ERR, "xml"); 66 } 67 parseChildren(parser); 68 } 69 70 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 71 _name.typeCheck(stable); 72 typeCheckContents(stable); 73 return Type.Void; 74 } 75 76 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 77 final ConstantPoolGen cpg = classGen.getConstantPool(); 78 final InstructionList il = methodGen.getInstructionList(); 79 80 if (!_isLiteral) { 81 LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue", 83 Util.getJCRefType(STRING_SIG), 84 il.getEnd()); 85 86 _name.translate(classGen, methodGen); 88 il.append(new ASTORE(nameValue.getIndex())); 89 il.append(new ALOAD(nameValue.getIndex())); 90 91 final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkNCName", 93 "(" 94 +STRING_SIG 95 +")V"); 96 il.append(new INVOKESTATIC(check)); 97 98 il.append(methodGen.loadHandler()); 100 il.append(DUP); 102 il.append(new ALOAD(nameValue.getIndex())); 104 } else { 105 il.append(methodGen.loadHandler()); 107 il.append(DUP); 109 _name.translate(classGen, methodGen); 112 } 113 114 il.append(classGen.loadTranslet()); 115 il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 116 "stringValueHandler", 117 STRING_VALUE_HANDLER_SIG))); 118 il.append(DUP); 119 il.append(methodGen.storeHandler()); 120 121 translateContents(classGen, methodGen); 123 124 il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER, 126 "getValueOfPI", 127 "()" + STRING_SIG))); 128 final int processingInstruction = 130 cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 131 "processingInstruction", 132 "(" + STRING_SIG + STRING_SIG + ")V"); 133 il.append(new INVOKEINTERFACE(processingInstruction, 3)); 134 il.append(methodGen.storeHandler()); 136 } 137 } 138 | Popular Tags |