1 30 package org.objectweb.asm.util; 31 32 import java.io.PrintWriter ; 33 import java.util.ArrayList ; 34 import java.util.List ; 35 36 import org.objectweb.asm.Attribute; 37 import org.objectweb.asm.util.attrs.ASMStackMapAttribute; 38 import org.objectweb.asm.util.attrs.ASMStackMapTableAttribute; 39 import org.objectweb.asm.util.attrs.ASMifiable; 40 41 46 public abstract class AbstractVisitor { 47 48 51 public final static String [] OPCODES; 52 53 static { 54 String s = "DNOPLACONST_NULLJICONST_M1IICONST_0IICONST_1IICONST_2II" 55 + "CONST_3IICONST_4IICONST_5ILCONST_0ILCONST_1IFCONST_0IFCON" 56 + "ST_1IFCONST_2IDCONST_0IDCONST_1GBIPUSHGSIPUSHDLDCAAFILOAD" 57 + "FLLOADFFLOADFDLOADFALOADAAAAAAAAAAAAAAAAAAAAGIALOADGLALOA" 58 + "DGFALOADGDALOADGAALOADGBALOADGCALOADGSALOADGISTOREGLSTORE" 59 + "GFSTOREGDSTOREGASTOREAAAAAAAAAAAAAAAAAAAAHIASTOREHLASTORE" 60 + "HFASTOREHDASTOREHAASTOREHBASTOREHCASTOREHSASTOREDPOPEPOP2" 61 + "DDUPGDUP_X1GDUP_X2EDUP2HDUP2_X1HDUP2_X2ESWAPEIADDELADDEFA" 62 + "DDEDADDEISUBELSUBEFSUBEDSUBEIMULELMULEFMULEDMULEIDIVELDIV" 63 + "EFDIVEDDIVEIREMELREMEFREMEDREMEINEGELNEGEFNEGEDNEGEISHLEL" 64 + "SHLEISHRELSHRFIUSHRFLUSHREIANDELANDDIORDLOREIXORELXOREIIN" 65 + "CDI2LDI2FDI2DDL2IDL2FDL2DDF2IDF2LDF2DDD2IDD2LDD2FDI2BDI2C" 66 + "DI2SELCMPFFCMPLFFCMPGFDCMPLFDCMPGEIFEQEIFNEEIFLTEIFGEEIFG" 67 + "TEIFLEJIF_ICMPEQJIF_ICMPNEJIF_ICMPLTJIF_ICMPGEJIF_ICMPGTJ" 68 + "IF_ICMPLEJIF_ACMPEQJIF_ACMPNEEGOTODJSRDRETLTABLESWITCHMLO" 69 + "OKUPSWITCHHIRETURNHLRETURNHFRETURNHDRETURNHARETURNGRETURN" 70 + "JGETSTATICJPUTSTATICIGETFIELDIPUTFIELDNINVOKEVIRTUALNINVO" 71 + "KESPECIALMINVOKESTATICPINVOKEINTERFACEADNEWINEWARRAYJANEW" 72 + "ARRAYLARRAYLENGTHGATHROWJCHECKCASTKINSTANCEOFMMONITORENTE" 73 + "RLMONITOREXITAOMULTIANEWARRAYGIFNULLJIFNONNULL"; 74 OPCODES = new String [200]; 75 int i = 0; 76 int len = 0; 77 for (int j = 0; j < s.length(); j += len) { 78 len = s.charAt(j++) - 'A'; 79 OPCODES[i++] = len == 0 ? null : s.substring(j, j + len); 80 } 81 } 82 83 298 310 public final List text; 311 312 315 protected final StringBuffer buf; 316 317 320 protected AbstractVisitor() { 321 this.text = new ArrayList (); 322 this.buf = new StringBuffer (); 323 } 324 325 330 public List getText() { 331 return text; 332 } 333 334 340 public static void appendString(final StringBuffer buf, final String s) { 341 buf.append("\""); 342 for (int i = 0; i < s.length(); ++i) { 343 char c = s.charAt(i); 344 if (c == '\n') { 345 buf.append("\\n"); 346 } else if (c == '\r') { 347 buf.append("\\r"); 348 } else if (c == '\\') { 349 buf.append("\\\\"); 350 } else if (c == '"') { 351 buf.append("\\\""); 352 } else if (c < 0x20 || c > 0x7f) { 353 buf.append("\\u"); 354 if (c < 0x10) { 355 buf.append("000"); 356 } else if (c < 0x100) { 357 buf.append("00"); 358 } else if (c < 0x1000) { 359 buf.append("0"); 360 } 361 buf.append(Integer.toString(c, 16)); 362 } else { 363 buf.append(c); 364 } 365 } 366 buf.append("\""); 367 } 368 369 376 void printList(final PrintWriter pw, final List l) { 377 for (int i = 0; i < l.size(); ++i) { 378 Object o = l.get(i); 379 if (o instanceof List ) { 380 printList(pw, (List ) o); 381 } else { 382 pw.print(o.toString()); 383 } 384 } 385 } 386 387 392 public static Attribute[] getDefaultAttributes() { 393 try { 394 return new Attribute[] { 395 new ASMStackMapAttribute(), 396 new ASMStackMapTableAttribute() }; 397 } catch (Exception e) { 398 return new Attribute[0]; 399 } 400 } 401 } 402 | Popular Tags |