1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import com.sun.org.apache.bcel.internal.generic.ALOAD; 23 import com.sun.org.apache.bcel.internal.generic.ASTORE; 24 import com.sun.org.apache.bcel.internal.generic.BranchHandle; 25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 26 import com.sun.org.apache.bcel.internal.generic.IFEQ; 27 import com.sun.org.apache.bcel.internal.generic.IFNULL; 28 import com.sun.org.apache.bcel.internal.generic.ILOAD; 29 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; 30 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 31 import com.sun.org.apache.bcel.internal.generic.ISTORE; 32 import com.sun.org.apache.bcel.internal.generic.InstructionHandle; 33 import com.sun.org.apache.bcel.internal.generic.InstructionList; 34 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; 35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 37 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 38 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 39 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 40 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; 41 42 46 final class Copy extends Instruction { 47 private UseAttributeSets _useSets; 48 49 public void parseContents(Parser parser) { 50 final String useSets = getAttribute("use-attribute-sets"); 51 if (useSets.length() > 0) { 52 if (!Util.isValidQNames(useSets)) { 53 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this); 54 parser.reportError(Constants.ERROR, err); 55 } 56 _useSets = new UseAttributeSets(useSets, parser); 57 } 58 parseChildren(parser); 59 } 60 61 public void display(int indent) { 62 indent(indent); 63 Util.println("Copy"); 64 indent(indent + IndentIncrement); 65 displayContents(indent + IndentIncrement); 66 } 67 68 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 69 if (_useSets != null) { 70 _useSets.typeCheck(stable); 71 } 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 final LocalVariableGen name = 81 methodGen.addLocalVariable2("name", 82 Util.getJCRefType(STRING_SIG), 83 il.getEnd()); 84 final LocalVariableGen length = 85 methodGen.addLocalVariable2("length", 86 Util.getJCRefType("I"), 87 il.getEnd()); 88 89 il.append(methodGen.loadDOM()); 91 il.append(methodGen.loadCurrentNode()); 92 il.append(methodGen.loadHandler()); 93 final int cpy = cpg.addInterfaceMethodref(DOM_INTF, 94 "shallowCopy", 95 "(" 96 + NODE_SIG 97 + TRANSLET_OUTPUT_SIG 98 + ")" + STRING_SIG); 99 il.append(new INVOKEINTERFACE(cpy, 3)); 100 il.append(DUP); 101 il.append(new ASTORE(name.getIndex())); 102 final BranchHandle ifBlock1 = il.append(new IFNULL(null)); 103 104 il.append(new ALOAD(name.getIndex())); 106 final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I"); 107 il.append(new INVOKEVIRTUAL(lengthMethod)); 108 il.append(new ISTORE(length.getIndex())); 109 110 if (_useSets != null) { 112 final SyntaxTreeNode parent = getParent(); 115 if ((parent instanceof LiteralElement) || 116 (parent instanceof LiteralElement)) { 117 _useSets.translate(classGen, methodGen); 118 } 119 else { 122 il.append(new ILOAD(length.getIndex())); 124 final BranchHandle ifBlock2 = il.append(new IFEQ(null)); 125 _useSets.translate(classGen, methodGen); 127 ifBlock2.setTarget(il.append(NOP)); 129 } 130 } 131 132 translateContents(classGen, methodGen); 134 135 il.append(new ILOAD(length.getIndex())); 138 final BranchHandle ifBlock3 = il.append(new IFEQ(null)); 139 il.append(methodGen.loadHandler()); 140 il.append(new ALOAD(name.getIndex())); 141 il.append(methodGen.endElement()); 142 143 final InstructionHandle end = il.append(NOP); 144 ifBlock1.setTarget(end); 145 ifBlock3.setTarget(end); 146 methodGen.removeLocalVariable(name); 147 methodGen.removeLocalVariable(length); 148 } 149 } 150 | Popular Tags |