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.INVOKESTATIC; 25 import org.apache.bcel.generic.INVOKEVIRTUAL; 26 import org.apache.bcel.generic.InstructionList; 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.NodeSetType; 31 import org.apache.xalan.xsltc.compiler.util.NodeType; 32 import org.apache.xalan.xsltc.compiler.util.ReferenceType; 33 import org.apache.xalan.xsltc.compiler.util.ResultTreeType; 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 38 42 final class CopyOf extends Instruction { 43 private Expression _select; 44 45 public void display(int indent) { 46 indent(indent); 47 Util.println("CopyOf"); 48 indent(indent + IndentIncrement); 49 Util.println("select " + _select.toString()); 50 } 51 52 public void parseContents(Parser parser) { 53 _select = parser.parseExpression(this, "select", null); 54 if (_select.isDummy()) { 56 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "select"); 57 return; 58 } 59 } 60 61 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 62 final Type tselect = _select.typeCheck(stable); 63 if (tselect instanceof NodeType || 64 tselect instanceof NodeSetType || 65 tselect instanceof ReferenceType || 66 tselect instanceof ResultTreeType) { 67 } 69 else { 70 _select = new CastExpr(_select, Type.String); 71 } 72 return Type.Void; 73 } 74 75 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 76 final ConstantPoolGen cpg = classGen.getConstantPool(); 77 final InstructionList il = methodGen.getInstructionList(); 78 final Type tselect = _select.getType(); 79 80 final String CPY1_SIG = "("+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V"; 81 final int cpy1 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY1_SIG); 82 83 final String CPY2_SIG = "("+NODE_SIG+TRANSLET_OUTPUT_SIG+")V"; 84 final int cpy2 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY2_SIG); 85 86 final String getDoc_SIG = "()"+NODE_SIG; 87 final int getDoc = cpg.addInterfaceMethodref(DOM_INTF, "getDocument", getDoc_SIG); 88 89 90 if (tselect instanceof NodeSetType) { 91 il.append(methodGen.loadDOM()); 92 93 _select.translate(classGen, methodGen); 95 _select.startIterator(classGen, methodGen); 96 97 il.append(methodGen.loadHandler()); 99 il.append(new INVOKEINTERFACE(cpy1, 3)); 100 } 101 else if (tselect instanceof NodeType) { 102 il.append(methodGen.loadDOM()); 103 _select.translate(classGen, methodGen); 104 il.append(methodGen.loadHandler()); 105 il.append(new INVOKEINTERFACE(cpy2, 3)); 106 } 107 else if (tselect instanceof ResultTreeType) { 108 _select.translate(classGen, methodGen); 109 il.append(DUP); il.append(new INVOKEINTERFACE(getDoc,1)); il.append(methodGen.loadHandler()); 113 il.append(new INVOKEINTERFACE(cpy2, 3)); 114 } 115 else if (tselect instanceof ReferenceType) { 116 _select.translate(classGen, methodGen); 117 il.append(methodGen.loadHandler()); 118 il.append(methodGen.loadCurrentNode()); 119 il.append(methodGen.loadDOM()); 120 final int copy = cpg.addMethodref(BASIS_LIBRARY_CLASS, "copy", 121 "(" 122 + OBJECT_SIG 123 + TRANSLET_OUTPUT_SIG 124 + NODE_SIG 125 + DOM_INTF_SIG 126 + ")V"); 127 il.append(new INVOKESTATIC(copy)); 128 } 129 else { 130 il.append(classGen.loadTranslet()); 131 _select.translate(classGen, methodGen); 132 il.append(methodGen.loadHandler()); 133 il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, 134 CHARACTERSW, 135 CHARACTERSW_SIG))); 136 } 137 138 } 139 } 140 | Popular Tags |