1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util; 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.GOTO; 27 import com.sun.org.apache.bcel.internal.generic.IFLT; 28 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; 29 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; 30 import com.sun.org.apache.bcel.internal.generic.Instruction; 31 import com.sun.org.apache.bcel.internal.generic.InstructionList; 32 import com.sun.org.apache.bcel.internal.generic.PUSH; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList; 35 36 40 public final class NodeSetType extends Type { 41 protected NodeSetType() {} 42 43 public String toString() { 44 return "node-set"; 45 } 46 47 public boolean identicalTo(Type other) { 48 return this == other; 49 } 50 51 public String toSignature() { 52 return NODE_ITERATOR_SIG; 53 } 54 55 public com.sun.org.apache.bcel.internal.generic.Type toJCType() { 56 return new com.sun.org.apache.bcel.internal.generic.ObjectType(NODE_ITERATOR); 57 } 58 59 67 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 68 Type type) { 69 if (type == Type.String) { 70 translateTo(classGen, methodGen, (StringType) type); 71 } 72 else if (type == Type.Boolean) { 73 translateTo(classGen, methodGen, (BooleanType) type); 74 } 75 else if (type == Type.Real) { 76 translateTo(classGen, methodGen, (RealType) type); 77 } 78 else if (type == Type.Node) { 79 translateTo(classGen, methodGen, (NodeType) type); 80 } 81 else if (type == Type.Reference) { 82 translateTo(classGen, methodGen, (ReferenceType) type); 83 } 84 else if (type == Type.Object) { 85 translateTo(classGen, methodGen, (ObjectType) type); 86 } 87 else { 88 ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 89 toString(), type.toString()); 90 classGen.getParser().reportError(Constants.FATAL, err); 91 } 92 } 93 94 98 public void translateFrom(ClassGenerator classGen, 99 MethodGenerator methodGen, Class clazz) 100 { 101 102 InstructionList il = methodGen.getInstructionList(); 103 ConstantPoolGen cpg = classGen.getConstantPool(); 104 if (clazz.getName().equals("org.w3c.dom.NodeList")) { 105 il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS, 111 "nodeList2Iterator", 112 "(" 113 + "Lorg/w3c/dom/NodeList;" 114 + TRANSLET_INTF_SIG 115 + DOM_INTF_SIG 116 + ")" + NODE_ITERATOR_SIG ); 117 il.append(new INVOKESTATIC(convert)); 118 } 119 else if (clazz.getName().equals("org.w3c.dom.Node")) { 120 il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS, 126 "node2Iterator", 127 "(" 128 + "Lorg/w3c/dom/Node;" 129 + TRANSLET_INTF_SIG 130 + DOM_INTF_SIG 131 + ")" + NODE_ITERATOR_SIG ); 132 il.append(new INVOKESTATIC(convert)); 133 } 134 else { 135 ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 136 toString(), clazz.getName()); 137 classGen.getParser().reportError(Constants.FATAL, err); 138 } 139 } 140 141 142 150 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 151 BooleanType type) { 152 final InstructionList il = methodGen.getInstructionList(); 153 FlowList falsel = translateToDesynthesized(classGen, methodGen, type); 154 il.append(ICONST_1); 155 final BranchHandle truec = il.append(new GOTO(null)); 156 falsel.backPatch(il.append(ICONST_0)); 157 truec.setTarget(il.append(NOP)); 158 } 159 160 166 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 167 StringType type) { 168 final InstructionList il = methodGen.getInstructionList(); 169 getFirstNode(classGen, methodGen); 170 il.append(DUP); 171 final BranchHandle falsec = il.append(new IFLT(null)); 172 Type.Node.translateTo(classGen, methodGen, type); 173 final BranchHandle truec = il.append(new GOTO(null)); 174 falsec.setTarget(il.append(POP)); 175 il.append(new PUSH(classGen.getConstantPool(), "")); 176 truec.setTarget(il.append(NOP)); 177 } 178 179 185 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 186 RealType type) { 187 translateTo(classGen, methodGen, Type.String); 188 Type.String.translateTo(classGen, methodGen, Type.Real); 189 } 190 191 196 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 197 NodeType type) { 198 getFirstNode(classGen, methodGen); 199 } 200 201 206 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 207 ObjectType type) { 208 methodGen.getInstructionList().append(NOP); 209 } 210 211 218 public FlowList translateToDesynthesized(ClassGenerator classGen, 219 MethodGenerator methodGen, 220 BooleanType type) { 221 final InstructionList il = methodGen.getInstructionList(); 222 getFirstNode(classGen, methodGen); 223 return new FlowList(il.append(new IFLT(null))); 224 } 225 226 232 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 233 ReferenceType type) { 234 methodGen.getInstructionList().append(NOP); 235 } 236 237 242 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 243 Class clazz) { 244 final ConstantPoolGen cpg = classGen.getConstantPool(); 245 final InstructionList il = methodGen.getInstructionList(); 246 final String className = clazz.getName(); 247 248 il.append(methodGen.loadDOM()); 249 il.append(SWAP); 250 251 if (className.equals("org.w3c.dom.Node")) { 252 int index = cpg.addInterfaceMethodref(DOM_INTF, 253 MAKE_NODE, 254 MAKE_NODE_SIG2); 255 il.append(new INVOKEINTERFACE(index, 2)); 256 } 257 else if (className.equals("org.w3c.dom.NodeList") || 258 className.equals("java.lang.Object")) { 259 int index = cpg.addInterfaceMethodref(DOM_INTF, 260 MAKE_NODE_LIST, 261 MAKE_NODE_LIST_SIG2); 262 il.append(new INVOKEINTERFACE(index, 2)); 263 } 264 else if (className.equals("java.lang.String")) { 265 int next = cpg.addInterfaceMethodref(NODE_ITERATOR, 266 "next", "()I"); 267 int index = cpg.addInterfaceMethodref(DOM_INTF, 268 GET_NODE_VALUE, 269 "(I)"+STRING_SIG); 270 271 il.append(new INVOKEINTERFACE(next, 1)); 273 il.append(new INVOKEINTERFACE(index, 2)); 275 276 } 277 else { 278 ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 279 toString(), className); 280 classGen.getParser().reportError(Constants.FATAL, err); 281 } 282 } 283 284 288 private void getFirstNode(ClassGenerator classGen, MethodGenerator methodGen) { 289 final ConstantPoolGen cpg = classGen.getConstantPool(); 290 final InstructionList il = methodGen.getInstructionList(); 291 il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(NODE_ITERATOR, 292 NEXT, 293 NEXT_SIG), 1)); 294 } 295 296 299 public void translateBox(ClassGenerator classGen, 300 MethodGenerator methodGen) { 301 translateTo(classGen, methodGen, Type.Reference); 302 } 303 304 307 public void translateUnBox(ClassGenerator classGen, 308 MethodGenerator methodGen) { 309 methodGen.getInstructionList().append(NOP); 310 } 311 312 315 public String getClassName() { 316 return(NODE_ITERATOR); 317 } 318 319 320 public Instruction LOAD(int slot) { 321 return new ALOAD(slot); 322 } 323 324 public Instruction STORE(int slot) { 325 return new ASTORE(slot); 326 } 327 } 328 | Popular Tags |