home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / tools / javap / JavaPBinaryCode.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  7.6 KB  |  367 lines

  1. package sun.tools.javap;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.CharArrayWriter;
  5. import java.io.DataInputStream;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import sun.tools.java.BinaryAttribute;
  9. import sun.tools.java.BinaryCode;
  10. import sun.tools.java.BinaryConstantPool;
  11. import sun.tools.java.BinaryExceptionHandler;
  12. import sun.tools.java.ClassDeclaration;
  13. import sun.tools.java.Constants;
  14. import sun.tools.java.FieldDefinition;
  15. import sun.tools.java.Identifier;
  16. import sun.tools.java.MethodType;
  17. import sun.tools.java.RuntimeConstants;
  18. import sun.tools.util.ConstantPrinter;
  19.  
  20. class JavaPBinaryCode extends BinaryCode implements Constants {
  21.    private JavaPEnvironment env;
  22.    private PrintWriter output;
  23.    private byte[] codeBytes;
  24.    private BinaryConstantPool cpool;
  25.    private ConstantPrinter constPrint;
  26.    private FieldDefinition fieldDef;
  27.    private String methodName;
  28.    private int offset;
  29.  
  30.    JavaPBinaryCode(byte[] var1, BinaryConstantPool var2, JavaPEnvironment var3, FieldDefinition var4) {
  31.       super(var1, var2, var3);
  32.       this.output = var3.output;
  33.       this.codeBytes = ((BinaryCode)this).getCode();
  34.       this.cpool = var2;
  35.       this.constPrint = new ConstantPrinter(var2, var3, !var3.showBackwardCompatible);
  36.       this.fieldDef = var4;
  37.       this.methodName = var4.toString();
  38.    }
  39.  
  40.    FieldDefinition fieldDefinition() {
  41.       return this.fieldDef;
  42.    }
  43.  
  44.    // $FF: renamed from: at (int) int
  45.    private final int method_0(int var1) {
  46.       return this.codeBytes[this.offset + var1] & 255;
  47.    }
  48.  
  49.    private final int shortAt(int var1) {
  50.       int var2 = this.offset + var1;
  51.       return (this.codeBytes[var2] & 255) << 8 | this.codeBytes[var2 + 1] & 255;
  52.    }
  53.  
  54.    private final int intAt(int var1, int var2) {
  55.       int var3 = var1 + (var2 << 2);
  56.       return this.codeBytes[var3] << 24 | (this.codeBytes[var3 + 1] & 255) << 16 | (this.codeBytes[var3 + 2] & 255) << 8 | this.codeBytes[var3 + 3] & 255;
  57.    }
  58.  
  59.    private void printFixedWidthInt(int var1, int var2) {
  60.       CharArrayWriter var3 = new CharArrayWriter();
  61.       PrintWriter var4 = new PrintWriter(var3);
  62.       var4.print(var1);
  63.       String var5 = var3.toString();
  64.  
  65.       for(int var6 = var2 - var5.length(); var6 > 0; --var6) {
  66.          this.output.print(' ');
  67.       }
  68.  
  69.       this.output.print(var5);
  70.    }
  71.  
  72.    void printCodeSequence() throws IOException {
  73.       this.output.println("");
  74.       this.output.println("Method " + this.methodName);
  75.       this.offset = 0;
  76.  
  77.       while(this.offset < this.codeBytes.length) {
  78.          int var1 = this.method_0(0);
  79.          this.printFixedWidthInt(this.offset, 4);
  80.          this.output.print(" ");
  81.          if (var1 == 196) {
  82.             var1 = this.method_0(1);
  83.             this.output.print(RuntimeConstants.opcNames[var1] + "_w ");
  84.             int var18 = this.shortAt(2);
  85.             switch (var1) {
  86.                case 21:
  87.                case 22:
  88.                case 23:
  89.                case 24:
  90.                case 25:
  91.                case 54:
  92.                case 55:
  93.                case 56:
  94.                case 57:
  95.                case 58:
  96.                case 169:
  97.                   this.output.print(var18);
  98.                   this.offset += 4;
  99.                   break;
  100.                case 132:
  101.                   this.output.print(var18 + " " + (short)this.shortAt(4));
  102.                   this.offset += 6;
  103.                   break;
  104.                default:
  105.                   this.output.print("Invalid opcode");
  106.                   ++this.offset;
  107.             }
  108.          } else {
  109.             this.output.print(RuntimeConstants.opcNames[var1]);
  110.             switch (var1) {
  111.                case 16:
  112.                   this.output.print(" " + (byte)this.method_0(1));
  113.                   this.offset += 2;
  114.                   break;
  115.                case 17:
  116.                   this.output.print(" " + (short)this.shortAt(1));
  117.                   this.offset += 3;
  118.                   break;
  119.                case 18:
  120.                   int var17 = this.method_0(1);
  121.                   this.output.print(" #" + var17 + " ");
  122.                   this.constPrint.printConstant(var17);
  123.                   this.offset += 2;
  124.                   break;
  125.                case 19:
  126.                case 20:
  127.                case 178:
  128.                case 179:
  129.                case 180:
  130.                case 181:
  131.                case 182:
  132.                case 183:
  133.                case 184:
  134.                case 187:
  135.                case 192:
  136.                case 193:
  137.                   int var16 = this.shortAt(1);
  138.                   this.output.print(" #" + var16 + " ");
  139.                   this.constPrint.printConstant(var16);
  140.                   this.offset += 3;
  141.                   break;
  142.                case 21:
  143.                case 22:
  144.                case 23:
  145.                case 24:
  146.                case 25:
  147.                case 54:
  148.                case 55:
  149.                case 56:
  150.                case 57:
  151.                case 58:
  152.                case 169:
  153.                   this.output.print(" " + this.method_0(1));
  154.                   this.offset += 2;
  155.                   break;
  156.                case 132:
  157.                   this.output.print(" " + this.method_0(1) + " " + (byte)this.method_0(2));
  158.                   this.offset += 3;
  159.                   break;
  160.                case 153:
  161.                case 154:
  162.                case 155:
  163.                case 156:
  164.                case 157:
  165.                case 158:
  166.                case 159:
  167.                case 160:
  168.                case 161:
  169.                case 162:
  170.                case 163:
  171.                case 164:
  172.                case 165:
  173.                case 166:
  174.                case 167:
  175.                case 168:
  176.                case 198:
  177.                case 199:
  178.                   int var15 = this.offset + (short)this.shortAt(1);
  179.                   this.output.print(" " + var15);
  180.                   this.offset += 3;
  181.                   break;
  182.                case 170:
  183.                   int var13 = this.offset + 1 + 3 & -4;
  184.                   int var19 = this.intAt(var13, 0);
  185.                   int var20 = this.intAt(var13, 1);
  186.                   int var21 = this.intAt(var13, 2);
  187.                   this.output.print(" " + var20 + " to " + var21 + ": default=");
  188.                   this.output.print(this.offset + var19);
  189.                   var13 += 12;
  190.  
  191.                   for(int var22 = var20; var22 <= var21; ++var22) {
  192.                      this.output.println("");
  193.                      this.output.print('\t');
  194.                      this.printFixedWidthInt(var22, 5);
  195.                      this.output.print(": " + (this.offset + this.intAt(var13, var22 - var20)));
  196.                   }
  197.  
  198.                   this.offset = var13 + (var21 - var20 + 1 << 2);
  199.                   break;
  200.                case 171:
  201.                   int var11 = this.offset + 1 + 3 & -4;
  202.                   int var3 = this.intAt(var11, 0);
  203.                   int var4 = this.intAt(var11, 1);
  204.                   int var5 = var4 * 2;
  205.                   this.output.print(" " + var4);
  206.                   this.output.print(": default=" + (this.offset + var3));
  207.                   var11 += 8;
  208.  
  209.                   for(int var6 = 0; var6 < var5; var6 += 2) {
  210.                      this.output.println("");
  211.                      this.output.print('\t');
  212.                      this.printFixedWidthInt(this.intAt(var11, var6), 5);
  213.                      this.output.print(": " + (this.offset + this.intAt(var11, var6 + 1)));
  214.                   }
  215.  
  216.                   this.offset = var11 + (var5 << 2);
  217.                   break;
  218.                case 185:
  219.                   int var10 = this.shortAt(1);
  220.                   this.output.print(" (args " + this.method_0(3) + ") #" + var10 + " ");
  221.                   this.constPrint.printConstant(var10);
  222.                   this.offset += 5;
  223.                   break;
  224.                case 188:
  225.                   switch (this.method_0(1)) {
  226.                      case 4:
  227.                         this.output.print(" boolean");
  228.                         break;
  229.                      case 5:
  230.                         this.output.print(" char");
  231.                         break;
  232.                      case 6:
  233.                         this.output.print(" float");
  234.                         break;
  235.                      case 7:
  236.                         this.output.print(" double");
  237.                         break;
  238.                      case 8:
  239.                         this.output.print(" byte");
  240.                         break;
  241.                      case 9:
  242.                         this.output.print(" short");
  243.                         break;
  244.                      case 10:
  245.                         this.output.print(" int");
  246.                         break;
  247.                      case 11:
  248.                         this.output.print(" long");
  249.                         break;
  250.                      default:
  251.                         this.output.print(" BOGUS TYPE");
  252.                   }
  253.  
  254.                   this.offset += 2;
  255.                   break;
  256.                case 189:
  257.                   int var9 = this.shortAt(1);
  258.                   this.output.print(" class #" + var9 + " ");
  259.                   this.constPrint.printConstant(var9);
  260.                   this.offset += 3;
  261.                   break;
  262.                case 197:
  263.                   int var8 = this.shortAt(1);
  264.                   this.output.print(" #" + var8 + " dim #" + this.method_0(3) + " ");
  265.                   this.constPrint.printConstant(var8);
  266.                   this.offset += 4;
  267.                   break;
  268.                case 200:
  269.                case 201:
  270.                   int var2 = this.offset + this.intAt(this.offset + 1, 0);
  271.                   this.output.print(" " + var2);
  272.                   this.offset += 5;
  273.                   break;
  274.                default:
  275.                   ++this.offset;
  276.             }
  277.  
  278.             this.output.println("");
  279.          }
  280.       }
  281.  
  282.    }
  283.  
  284.    void printExceptionTable() throws IOException {
  285.       BinaryExceptionHandler[] var1 = ((BinaryCode)this).getExceptionHandlers();
  286.       if (var1.length > 0) {
  287.          this.output.print("Exception table:\n   from   to  target type\n");
  288.  
  289.          for(int var2 = 0; var2 < var1.length; ++var2) {
  290.             BinaryExceptionHandler var3 = var1[var2];
  291.             this.printFixedWidthInt(var3.startPC, 6);
  292.             this.printFixedWidthInt(var3.endPC, 6);
  293.             this.printFixedWidthInt(var3.handlerPC, 6);
  294.             this.output.print("   ");
  295.             ClassDeclaration var4 = var3.exceptionClass;
  296.             if (var4 == null) {
  297.                this.output.println("any");
  298.             } else {
  299.                this.constPrint.printClassDeclaration(var4);
  300.                this.output.println("");
  301.             }
  302.          }
  303.       }
  304.  
  305.    }
  306.  
  307.    private DataInputStream findAttribute(Identifier var1) {
  308.       for(BinaryAttribute var2 = ((BinaryCode)this).getAttributes(); var2 != null; var2 = var2.getNextAttribute()) {
  309.          if (var2.getName().equals(var1)) {
  310.             ByteArrayInputStream var3 = new ByteArrayInputStream(var2.getData());
  311.             return new DataInputStream(var3);
  312.          }
  313.       }
  314.  
  315.       return null;
  316.    }
  317.  
  318.    void printLineNumberTable() throws IOException {
  319.       DataInputStream var1 = this.findAttribute(Constants.idLineNumberTable);
  320.       short var2;
  321.       if (var1 != null && (var2 = var1.readShort()) > 0) {
  322.          this.output.println("");
  323.          this.output.println("Line numbers for method " + this.methodName);
  324.  
  325.          for(int var3 = var2; var3 > 0; --var3) {
  326.             short var4 = var1.readShort();
  327.             short var5 = var1.readShort();
  328.             this.output.println("   line " + var5 + ": " + var4);
  329.          }
  330.       }
  331.  
  332.    }
  333.  
  334.    void printLocalVariableTable() throws IOException {
  335.       DataInputStream var1 = this.findAttribute(Constants.idLocalVariableTable);
  336.       short var2;
  337.       if (var1 != null && (var2 = var1.readShort()) > 0) {
  338.          this.output.println("");
  339.          this.output.println("Local variables for method " + this.methodName);
  340.  
  341.          for(int var3 = var2; var3 > 0; --var3) {
  342.             short var4 = var1.readShort();
  343.             short var5 = var1.readShort();
  344.             short var6 = var1.readShort();
  345.             short var7 = var1.readShort();
  346.             short var8 = var1.readShort();
  347.             this.output.print("   ");
  348.             this.output.print(this.cpool.getType(var7));
  349.             this.output.print(" ");
  350.             this.output.print(this.cpool.getString(var6));
  351.             this.output.println("  pc=" + var4 + ", length=" + var5 + ", slot=" + var8);
  352.          }
  353.       }
  354.  
  355.    }
  356.  
  357.    void printVerboseHeader() {
  358.       MethodType var1 = (MethodType)this.fieldDef.getType();
  359.       int var2 = var1.getArgumentTypes().length;
  360.       if (!this.fieldDef.isStatic()) {
  361.          ++var2;
  362.       }
  363.  
  364.       this.output.println("\t/* Stack=" + ((BinaryCode)this).getMaxStack() + ", Locals=" + ((BinaryCode)this).getMaxLocals() + ", Args_size=" + var2 + " */");
  365.    }
  366. }
  367.