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.CHECKCAST; 25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 26 import com.sun.org.apache.bcel.internal.generic.GETFIELD; 27 import com.sun.org.apache.bcel.internal.generic.IFEQ; 28 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE; 29 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; 30 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 31 import com.sun.org.apache.bcel.internal.generic.Instruction; 32 import com.sun.org.apache.bcel.internal.generic.InstructionList; 33 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; 34 import com.sun.org.apache.bcel.internal.generic.NEW; 35 import com.sun.org.apache.bcel.internal.generic.PUSH; 36 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; 37 import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList; 38 39 44 public final class ResultTreeType extends Type { 45 private final String _methodName; 46 47 protected ResultTreeType() { 48 _methodName = null; 49 } 50 51 public ResultTreeType(String methodName) { 52 _methodName = methodName; 53 } 54 55 public String toString() { 56 return "result-tree"; 57 } 58 59 public boolean identicalTo(Type other) { 60 return (other instanceof ResultTreeType); 61 } 62 63 public String toSignature() { 64 return DOM_INTF_SIG; 65 } 66 67 public com.sun.org.apache.bcel.internal.generic.Type toJCType() { 68 return Util.getJCRefType(toSignature()); 69 } 70 71 public String getMethodName() { 72 return _methodName; 73 } 74 75 public boolean implementedAsMethod() { 76 return _methodName != null; 77 } 78 79 89 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 90 Type type) { 91 if (type == Type.String) { 92 translateTo(classGen, methodGen, (StringType)type); 93 } 94 else if (type == Type.Boolean) { 95 translateTo(classGen, methodGen, (BooleanType)type); 96 } 97 else if (type == Type.Real) { 98 translateTo(classGen, methodGen, (RealType)type); 99 } 100 else if (type == Type.NodeSet) { 101 translateTo(classGen, methodGen, (NodeSetType)type); 102 } 103 else if (type == Type.Reference) { 104 translateTo(classGen, methodGen, (ReferenceType)type); 105 } 106 else if (type == Type.Object) { 107 translateTo(classGen, methodGen, (ObjectType) type); 108 } 109 else { 110 ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 111 toString(), type.toString()); 112 classGen.getParser().reportError(Constants.FATAL, err); 113 } 114 } 115 116 125 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 126 BooleanType type) { 127 final ConstantPoolGen cpg = classGen.getConstantPool(); 130 final InstructionList il = methodGen.getInstructionList(); 131 il.append(POP); il.append(ICONST_1); } 134 135 143 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 144 StringType type) { 145 final ConstantPoolGen cpg = classGen.getConstantPool(); 146 final InstructionList il = methodGen.getInstructionList(); 147 148 if (_methodName == null) { 149 int index = cpg.addInterfaceMethodref(DOM_INTF, 150 "getStringValue", 151 "()"+STRING_SIG); 152 il.append(new INVOKEINTERFACE(index, 1)); 153 } 154 else { 155 final String className = classGen.getClassName(); 156 final int current = methodGen.getLocalIndex("current"); 157 158 il.append(classGen.loadTranslet()); 160 if (classGen.isExternal()) { 161 il.append(new CHECKCAST(cpg.addClass(className))); 162 } 163 il.append(DUP); 164 il.append(new GETFIELD(cpg.addFieldref(className, "_dom", 165 DOM_INTF_SIG))); 166 167 int index = cpg.addMethodref(STRING_VALUE_HANDLER, "<init>", "()V"); 169 il.append(new NEW(cpg.addClass(STRING_VALUE_HANDLER))); 170 il.append(DUP); 171 il.append(DUP); 172 il.append(new INVOKESPECIAL(index)); 173 174 final LocalVariableGen handler = 176 methodGen.addLocalVariable("rt_to_string_handler", 177 Util.getJCRefType(STRING_VALUE_HANDLER_SIG), 178 null, null); 179 il.append(new ASTORE(handler.getIndex())); 180 181 index = cpg.addMethodref(className, _methodName, 183 "("+DOM_INTF_SIG+TRANSLET_OUTPUT_SIG+")V"); 184 il.append(new INVOKEVIRTUAL(index)); 185 186 il.append(new ALOAD(handler.getIndex())); 188 index = cpg.addMethodref(STRING_VALUE_HANDLER, 189 "getValue", 190 "()" + STRING_SIG); 191 il.append(new INVOKEVIRTUAL(index)); 192 } 193 } 194 195 204 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 205 RealType type) { 206 translateTo(classGen, methodGen, Type.String); 207 Type.String.translateTo(classGen, methodGen, Type.Real); 208 } 209 210 219 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 220 ReferenceType type) { 221 final ConstantPoolGen cpg = classGen.getConstantPool(); 222 final InstructionList il = methodGen.getInstructionList(); 223 224 if (_methodName == null) { 225 il.append(NOP); 226 } 227 else { 228 LocalVariableGen domBuilder, newDom; 229 final String className = classGen.getClassName(); 230 final int current = methodGen.getLocalIndex("current"); 231 232 il.append(classGen.loadTranslet()); 234 if (classGen.isExternal()) { 235 il.append(new CHECKCAST(cpg.addClass(className))); 236 } 237 il.append(methodGen.loadDOM()); 238 239 il.append(methodGen.loadDOM()); 241 int index = cpg.addInterfaceMethodref(DOM_INTF, 242 "getResultTreeFrag", 243 "(IZ)" + DOM_INTF_SIG); 244 il.append(new PUSH(cpg, RTF_INITIAL_SIZE)); 245 il.append(new PUSH(cpg, false)); 246 il.append(new INVOKEINTERFACE(index,3)); 247 il.append(DUP); 248 249 newDom = methodGen.addLocalVariable("rt_to_reference_dom", 251 Util.getJCRefType(DOM_INTF_SIG), 252 null, null); 253 il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG))); 254 il.append(new ASTORE(newDom.getIndex())); 255 256 index = cpg.addInterfaceMethodref(DOM_INTF, 258 "getOutputDomBuilder", 259 "()" + TRANSLET_OUTPUT_SIG); 260 261 il.append(new INVOKEINTERFACE(index,1)); 262 il.append(DUP); 267 il.append(DUP); 268 269 domBuilder = 271 methodGen.addLocalVariable("rt_to_reference_handler", 272 Util.getJCRefType(TRANSLET_OUTPUT_SIG), 273 null, null); 274 il.append(new ASTORE(domBuilder.getIndex())); 275 276 index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 278 "startDocument", "()V"); 279 il.append(new INVOKEINTERFACE(index, 1)); 280 281 index = cpg.addMethodref(className, 283 _methodName, 284 "(" 285 + DOM_INTF_SIG 286 + TRANSLET_OUTPUT_SIG 287 +")V"); 288 il.append(new INVOKEVIRTUAL(index)); 289 290 il.append(new ALOAD(domBuilder.getIndex())); 292 index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, 293 "endDocument", "()V"); 294 il.append(new INVOKEINTERFACE(index, 1)); 295 296 il.append(new ALOAD(newDom.getIndex())); 298 } 299 } 300 301 314 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 315 NodeSetType type) { 316 final ConstantPoolGen cpg = classGen.getConstantPool(); 317 final InstructionList il = methodGen.getInstructionList(); 318 319 il.append(DUP); 321 322 il.append(classGen.loadTranslet()); il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 327 NAMES_INDEX, 328 NAMES_INDEX_SIG))); 329 il.append(classGen.loadTranslet()); il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 331 URIS_INDEX, 332 URIS_INDEX_SIG))); 333 il.append(classGen.loadTranslet()); il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 335 TYPES_INDEX, 336 TYPES_INDEX_SIG))); 337 il.append(classGen.loadTranslet()); il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, 339 NAMESPACE_INDEX, 340 NAMESPACE_INDEX_SIG))); 341 final int mapping = cpg.addInterfaceMethodref(DOM_INTF, 343 "setupMapping", 344 "(["+STRING_SIG+ 345 "["+STRING_SIG+ 346 "[I" + 347 "["+STRING_SIG+")V"); 348 il.append(new INVOKEINTERFACE(mapping, 5)); 349 il.append(DUP); 350 351 final int iter = cpg.addInterfaceMethodref(DOM_INTF, 353 "getIterator", 354 "()"+NODE_ITERATOR_SIG); 355 il.append(new INVOKEINTERFACE(iter, 1)); 356 } 357 358 363 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 364 ObjectType type) { 365 methodGen.getInstructionList().append(NOP); 366 } 367 368 378 public FlowList translateToDesynthesized(ClassGenerator classGen, 379 MethodGenerator methodGen, 380 BooleanType type) { 381 final InstructionList il = methodGen.getInstructionList(); 382 translateTo(classGen, methodGen, Type.Boolean); 383 return new FlowList(il.append(new IFEQ(null))); 384 } 385 386 398 public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, 399 Class clazz) { 400 final String className = clazz.getName(); 401 final ConstantPoolGen cpg = classGen.getConstantPool(); 402 final InstructionList il = methodGen.getInstructionList(); 403 404 if (className.equals("org.w3c.dom.Node")) { 405 translateTo(classGen, methodGen, Type.NodeSet); 406 int index = cpg.addInterfaceMethodref(DOM_INTF, 407 MAKE_NODE, 408 MAKE_NODE_SIG2); 409 il.append(new INVOKEINTERFACE(index, 2)); 410 } 411 else if (className.equals("org.w3c.dom.NodeList")) { 412 translateTo(classGen, methodGen, Type.NodeSet); 413 int index = cpg.addInterfaceMethodref(DOM_INTF, 414 MAKE_NODE_LIST, 415 MAKE_NODE_LIST_SIG2); 416 il.append(new INVOKEINTERFACE(index, 2)); 417 } 418 else if (className.equals("java.lang.Object")) { 419 il.append(NOP); 420 } 421 else if (className.equals("java.lang.String")) { 422 translateTo(classGen, methodGen, Type.String); 423 } 424 else { 425 ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, 426 toString(), className); 427 classGen.getParser().reportError(Constants.FATAL, err); 428 } 429 } 430 431 434 public void translateBox(ClassGenerator classGen, 435 MethodGenerator methodGen) { 436 translateTo(classGen, methodGen, Type.Reference); 437 } 438 439 442 public void translateUnBox(ClassGenerator classGen, 443 MethodGenerator methodGen) { 444 methodGen.getInstructionList().append(NOP); 445 } 446 447 450 public String getClassName() { 451 return(DOM_INTF); 452 } 453 454 public Instruction LOAD(int slot) { 455 return new ALOAD(slot); 456 } 457 458 public Instruction STORE(int slot) { 459 return new ASTORE(slot); 460 } 461 } 462 | Popular Tags |