1 30 31 package oracle.toplink.libraries.asm.util; 32 33 import oracle.toplink.libraries.asm.CodeVisitor; 34 import oracle.toplink.libraries.asm.Label; 35 import oracle.toplink.libraries.asm.Attribute; 36 37 import java.util.ArrayList ; 38 import java.util.List ; 39 40 51 52 public abstract class PrintCodeVisitor implements CodeVisitor { 53 54 57 58 protected final List text; 59 60 63 64 protected final StringBuffer buf; 65 66 69 70 public final static String [] OPCODES = { 71 "NOP", 72 "ACONST_NULL", 73 "ICONST_M1", 74 "ICONST_0", 75 "ICONST_1", 76 "ICONST_2", 77 "ICONST_3", 78 "ICONST_4", 79 "ICONST_5", 80 "LCONST_0", 81 "LCONST_1", 82 "FCONST_0", 83 "FCONST_1", 84 "FCONST_2", 85 "DCONST_0", 86 "DCONST_1", 87 "BIPUSH", 88 "SIPUSH", 89 "LDC", 90 null, 91 null, 92 "ILOAD", 93 "LLOAD", 94 "FLOAD", 95 "DLOAD", 96 "ALOAD", 97 null, 98 null, 99 null, 100 null, 101 null, 102 null, 103 null, 104 null, 105 null, 106 null, 107 null, 108 null, 109 null, 110 null, 111 null, 112 null, 113 null, 114 null, 115 null, 116 null, 117 "IALOAD", 118 "LALOAD", 119 "FALOAD", 120 "DALOAD", 121 "AALOAD", 122 "BALOAD", 123 "CALOAD", 124 "SALOAD", 125 "ISTORE", 126 "LSTORE", 127 "FSTORE", 128 "DSTORE", 129 "ASTORE", 130 null, 131 null, 132 null, 133 null, 134 null, 135 null, 136 null, 137 null, 138 null, 139 null, 140 null, 141 null, 142 null, 143 null, 144 null, 145 null, 146 null, 147 null, 148 null, 149 null, 150 "IASTORE", 151 "LASTORE", 152 "FASTORE", 153 "DASTORE", 154 "AASTORE", 155 "BASTORE", 156 "CASTORE", 157 "SASTORE", 158 "POP", 159 "POP2", 160 "DUP", 161 "DUP_X1", 162 "DUP_X2", 163 "DUP2", 164 "DUP2_X1", 165 "DUP2_X2", 166 "SWAP", 167 "IADD", 168 "LADD", 169 "FADD", 170 "DADD", 171 "ISUB", 172 "LSUB", 173 "FSUB", 174 "DSUB", 175 "IMUL", 176 "LMUL", 177 "FMUL", 178 "DMUL", 179 "IDIV", 180 "LDIV", 181 "FDIV", 182 "DDIV", 183 "IREM", 184 "LREM", 185 "FREM", 186 "DREM", 187 "INEG", 188 "LNEG", 189 "FNEG", 190 "DNEG", 191 "ISHL", 192 "LSHL", 193 "ISHR", 194 "LSHR", 195 "IUSHR", 196 "LUSHR", 197 "IAND", 198 "LAND", 199 "IOR", 200 "LOR", 201 "IXOR", 202 "LXOR", 203 "IINC", 204 "I2L", 205 "I2F", 206 "I2D", 207 "L2I", 208 "L2F", 209 "L2D", 210 "F2I", 211 "F2L", 212 "F2D", 213 "D2I", 214 "D2L", 215 "D2F", 216 "I2B", 217 "I2C", 218 "I2S", 219 "LCMP", 220 "FCMPL", 221 "FCMPG", 222 "DCMPL", 223 "DCMPG", 224 "IFEQ", 225 "IFNE", 226 "IFLT", 227 "IFGE", 228 "IFGT", 229 "IFLE", 230 "IF_ICMPEQ", 231 "IF_ICMPNE", 232 "IF_ICMPLT", 233 "IF_ICMPGE", 234 "IF_ICMPGT", 235 "IF_ICMPLE", 236 "IF_ACMPEQ", 237 "IF_ACMPNE", 238 "GOTO", 239 "JSR", 240 "RET", 241 "TABLESWITCH", 242 "LOOKUPSWITCH", 243 "IRETURN", 244 "LRETURN", 245 "FRETURN", 246 "DRETURN", 247 "ARETURN", 248 "RETURN", 249 "GETSTATIC", 250 "PUTSTATIC", 251 "GETFIELD", 252 "PUTFIELD", 253 "INVOKEVIRTUAL", 254 "INVOKESPECIAL", 255 "INVOKESTATIC", 256 "INVOKEINTERFACE", 257 null, 258 "NEW", 259 "NEWARRAY", 260 "ANEWARRAY", 261 "ARRAYLENGTH", 262 "ATHROW", 263 "CHECKCAST", 264 "INSTANCEOF", 265 "MONITORENTER", 266 "MONITOREXIT", 267 null, 268 "MULTIANEWARRAY", 269 "IFNULL", 270 "IFNONNULL", 271 null, 272 null 273 }; 274 275 278 279 protected PrintCodeVisitor () { 280 this.buf = new StringBuffer (); 281 this.text = new ArrayList (); 282 } 283 284 public void visitInsn (final int opcode) { 285 buf.setLength(0); 286 printInsn(opcode); 287 text.add(buf.toString()); 288 } 289 290 public void visitIntInsn (final int opcode, final int operand) { 291 buf.setLength(0); 292 printIntInsn(opcode, operand); 293 text.add(buf.toString()); 294 } 295 296 public void visitVarInsn (final int opcode, final int var) { 297 buf.setLength(0); 298 printVarInsn(opcode, var); 299 text.add(buf.toString()); 300 } 301 302 public void visitTypeInsn (final int opcode, final String desc) { 303 buf.setLength(0); 304 printTypeInsn(opcode, desc); 305 text.add(buf.toString()); 306 } 307 308 public void visitFieldInsn ( 309 final int opcode, 310 final String owner, 311 final String name, 312 final String desc) 313 { 314 buf.setLength(0); 315 printFieldInsn(opcode, owner, name, desc); 316 text.add(buf.toString()); 317 } 318 319 public void visitMethodInsn ( 320 final int opcode, 321 final String owner, 322 final String name, 323 final String desc) 324 { 325 buf.setLength(0); 326 printMethodInsn(opcode, owner, name, desc); 327 text.add(buf.toString()); 328 } 329 330 public void visitJumpInsn (final int opcode, final Label label) { 331 buf.setLength(0); 332 printJumpInsn(opcode, label); 333 text.add(buf.toString()); 334 } 335 336 public void visitLabel (final Label label) { 337 buf.setLength(0); 338 printLabel(label); 339 text.add(buf.toString()); 340 } 341 342 public void visitLdcInsn (final Object cst) { 343 buf.setLength(0); 344 printLdcInsn(cst); 345 text.add(buf.toString()); 346 } 347 348 public void visitIincInsn (final int var, final int increment) { 349 buf.setLength(0); 350 printIincInsn(var, increment); 351 text.add(buf.toString()); 352 } 353 354 public void visitTableSwitchInsn ( 355 final int min, 356 final int max, 357 final Label dflt, 358 final Label labels[]) 359 { 360 buf.setLength(0); 361 printTableSwitchInsn(min, max, dflt, labels); 362 text.add(buf.toString()); 363 } 364 365 public void visitLookupSwitchInsn ( 366 final Label dflt, 367 final int keys[], 368 final Label labels[]) 369 { 370 buf.setLength(0); 371 printLookupSwitchInsn(dflt, keys, labels); 372 text.add(buf.toString()); 373 } 374 375 public void visitMultiANewArrayInsn (final String desc, final int dims) { 376 buf.setLength(0); 377 printMultiANewArrayInsn(desc, dims); 378 text.add(buf.toString()); 379 } 380 381 public void visitTryCatchBlock ( 382 final Label start, 383 final Label end, 384 final Label handler, 385 final String type) 386 { 387 buf.setLength(0); 388 printTryCatchBlock(start, end, handler, type); 389 text.add(buf.toString()); 390 } 391 392 public void visitMaxs (final int maxStack, final int maxLocals) { 393 buf.setLength(0); 394 printMaxs(maxStack, maxLocals); 395 text.add(buf.toString()); 396 } 397 398 public void visitLocalVariable ( 399 final String name, 400 final String desc, 401 final Label start, 402 final Label end, 403 final int index) 404 { 405 buf.setLength(0); 406 printLocalVariable(name, desc, start, end, index); 407 text.add(buf.toString()); 408 } 409 410 public void visitLineNumber (final int line, final Label start) { 411 buf.setLength(0); 412 printLineNumber(line, start); 413 text.add(buf.toString()); 414 } 415 416 public void visitAttribute (final Attribute attr) { 417 buf.setLength(0); 418 printAttribute(attr); 419 text.add(buf.toString()); 420 } 421 422 428 429 public List getText () { 430 return text; 431 } 432 433 465 466 public abstract void printInsn (final int opcode); 467 468 475 476 public abstract void printIntInsn (final int opcode, final int operand); 477 478 488 489 public abstract void printVarInsn (final int opcode, final int var); 490 491 501 502 public abstract void printTypeInsn (final int opcode, final String desc); 503 504 516 517 public abstract void printFieldInsn ( 518 final int opcode, 519 final String owner, 520 final String name, 521 final String desc); 522 523 536 537 public abstract void printMethodInsn ( 538 final int opcode, 539 final String owner, 540 final String name, 541 final String desc); 542 543 555 556 public abstract void printJumpInsn (final int opcode, final Label label); 557 558 564 565 public abstract void printLabel (final Label label); 566 567 575 576 public abstract void printLdcInsn (final Object cst); 577 578 584 585 public abstract void printIincInsn (final int var, final int increment); 586 587 596 597 public abstract void printTableSwitchInsn ( 598 final int min, 599 final int max, 600 final Label dflt, 601 final Label labels[]); 602 603 611 612 public abstract void printLookupSwitchInsn ( 613 final Label dflt, 614 final int keys[], 615 final Label labels[]); 616 617 624 625 public abstract void printMultiANewArrayInsn ( 626 final String desc, 627 final int dims); 628 629 638 639 public abstract void printTryCatchBlock ( 640 final Label start, 641 final Label end, 642 final Label handler, 643 final String type); 644 645 652 653 public abstract void printMaxs (final int maxStack, final int maxLocals); 654 655 666 667 public abstract void printLocalVariable ( 668 final String name, 669 final String desc, 670 final Label start, 671 final Label end, 672 final int index); 673 674 681 682 public abstract void printLineNumber (final int line, final Label start); 683 684 689 690 public abstract void printAttribute (final Attribute attr); 691 } | Popular Tags |