1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.INVOKEINTERFACE; 24 import org.apache.bcel.generic.INVOKEVIRTUAL; 25 import org.apache.bcel.generic.InstructionList; 26 import org.apache.bcel.generic.PUSH; 27 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 28 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 29 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 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 34 39 final class ValueOf extends Instruction { 40 private Expression _select; 41 private boolean _escaping = true; 42 private boolean _isString = false; 43 44 public void display(int indent) { 45 indent(indent); 46 Util.println("ValueOf"); 47 indent(indent + IndentIncrement); 48 Util.println("select " + _select.toString()); 49 } 50 51 public void parseContents(Parser parser) { 52 _select = parser.parseExpression(this, "select", null); 53 54 if (_select.isDummy()) { 56 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select"); 57 return; 58 } 59 final String str = getAttribute("disable-output-escaping"); 60 if ((str != null) && (str.equals("yes"))) _escaping = false; 61 } 62 63 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 64 Type type = _select.typeCheck(stable); 65 66 if (type != null && !type.identicalTo(Type.Node)) { 68 77 if (type.identicalTo(Type.NodeSet)) { 78 _select = new CastExpr(_select, Type.Node); 79 } else { 80 _isString = true; 81 if (!type.identicalTo(Type.String)) { 82 _select = new CastExpr(_select, Type.String); 83 } 84 _isString = true; 85 } 86 } 87 return Type.Void; 88 } 89 90 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 91 final ConstantPoolGen cpg = classGen.getConstantPool(); 92 final InstructionList il = methodGen.getInstructionList(); 93 final int setEscaping = cpg.addInterfaceMethodref(OUTPUT_HANDLER, 94 "setEscaping","(Z)Z"); 95 96 if (!_escaping) { 98 il.append(methodGen.loadHandler()); 99 il.append(new PUSH(cpg,false)); 100 il.append(new INVOKEINTERFACE(setEscaping,2)); 101 } 102 103 if (_isString) { 109 final int characters = cpg.addMethodref(TRANSLET_CLASS, 110 CHARACTERSW, 111 CHARACTERSW_SIG); 112 113 il.append(classGen.loadTranslet()); 114 _select.translate(classGen, methodGen); 115 il.append(methodGen.loadHandler()); 116 il.append(new INVOKEVIRTUAL(characters)); 117 } else { 118 final int characters = cpg.addInterfaceMethodref(DOM_INTF, 119 CHARACTERS, 120 CHARACTERS_SIG); 121 122 il.append(methodGen.loadDOM()); 123 _select.translate(classGen, methodGen); 124 il.append(methodGen.loadHandler()); 125 il.append(new INVOKEINTERFACE(characters, 3)); 126 } 127 128 if (!_escaping) { 130 il.append(methodGen.loadHandler()); 131 il.append(SWAP); 132 il.append(new INVOKEINTERFACE(setEscaping,2)); 133 il.append(POP); 134 } 135 } 136 } 137 | Popular Tags |