Пример #1
0
 //
 // called by the .class directive
 //
 void setClass(String name, short acc) {
   class_name = name;
   class_env.setClass(new ClassCP(name));
   class_env.setClassAccess(acc);
   class_header = true;
   isInterface = 0 != (acc & RuntimeConstants.ACC_INTERFACE);
 }
Пример #2
0
 //
 // called by the .enclosing directive
 //
 void setEnclosingMethod(String str) {
   try {
     if (str.indexOf("(") != -1) { // full method description
       String[] split = ScannerUtils.splitClassMethodSignature(str);
       class_env.setEnclosingMethod(split[0], split[1], split[2]);
     } else // just a class name
     class_env.setEnclosingMethod(str, null, null);
   } catch (IllegalArgumentException e) {
     report_error(e.toString());
   }
 }
Пример #3
0
  //
  // called by the .end field directive to end 'prompted' field
  //
  void endField() throws jasError {
    if (cur_field == null) throw new jasError(".end field without .field");

    if (cur_annotation != null) opened_annotation("field");

    class_env.addField(cur_field);
    cur_field = null;
  }
Пример #4
0
 void addAnnotation(boolean visible, String clname) throws jasError {
   if (cur_method != null) {
     cur_annotation = cur_method.addAnnotation(visible, clname);
   } else if (cur_field != null) {
     cur_annotation = cur_field.addAnnotation(visible, clname);
   } else if (class_header) {
     cur_annotation = class_env.addAnnotation(visible, clname);
   } else {
     outside(".annotation");
   }
 }
Пример #5
0
 //
 // called by the .deprecated directive
 //
 //
 void setDeprecated() throws jasError {
   DeprecatedAttr depr = new DeprecatedAttr();
   if (cur_method != null) {
     cur_method.setDeprecated(depr);
   } else if (cur_field != null) {
     cur_field.setDeprecated(depr);
   } else if (class_header) {
     class_env.setDeprecated(depr);
   } else {
     outside(".deprecated");
   }
 }
Пример #6
0
 //
 // called by the .signature directive
 //
 void setSignature(String str) throws jasError {
   SignatureAttr sig = new SignatureAttr(str);
   if (cur_method != null) {
     cur_method.setSignature(sig);
   } else if (cur_field != null) {
     cur_field.setSignature(sig);
   } else if (class_header) {
     class_env.setSignature(str);
   } else {
     outside(".signature");
   }
 }
Пример #7
0
 //
 // called by the .bytecode directive
 //
 void setVersion(Number version) {
   // int V1_1 = 3 << 16 | 45;
   // int V1_2 = 0 << 16 | 46;
   // int V1_3 = 0 << 16 | 47;
   // int V1_4 = 0 << 16 | 48;
   // int V1_5 = 0 << 16 | 49;
   // int V1_6 = 0 << 16 | 50;
   // int V1_7 = 0 << 16 | 51;
   String str = version.toString();
   String key = "[" + str + "]";
   if ("[5][1.5][5.0][49.0]".contains(key)) {
     this.class_env.setVersion((short) 49, (short) 0);
   } else if ("[6][1.6][6.0][50.0]".contains(key)) {
     this.class_env.setVersion((short) 50, (short) 0);
   } else if ("[7][1.7][7.0][51.0]".contains(key)) {
     this.class_env.setVersion((short) 51, (short) 0);
   } else if ("[4][1.4][4.0][48.0]".contains(key)) {
     this.class_env.setVersion((short) 48, (short) 0);
   } else if ("[3][1.3][3.0][47.0]".contains(key)) {
     this.class_env.setVersion((short) 47, (short) 0);
   } else if ("[2][1.2][2.0][46.0]".contains(key)) {
     this.class_env.setVersion((short) 46, (short) 0);
   } else if ("[1][1.1][1.0][45.3]".contains(key)) {
     this.class_env.setVersion((short) 45, (short) 3);
   } else {
     int idx = str.indexOf(".");
     try {
       if (idx > 0) {
         class_env.setVersion(
             Short.parseShort(str.substring(0, idx)),
             Short.parseShort(str.substring(idx + 1, str.length())));
       } else {
         class_env.setVersion(version.shortValue(), (short) 0);
       }
     } catch (Exception ex) {
       report_error("invalid bytecode version number : " + str);
     }
   }
 }
Пример #8
0
  public static void main(String argv[]) throws jasError, IOException {

    // CodeAttr's contain the body of
    // a method.

    CodeAttr init = new CodeAttr();
    init.addInsn(new Insn(opc_aload_0));
    init.addInsn(new Insn(opc_invokenonvirtual, new MethodCP("java/lang/Object", "<init>", "()V")));
    init.addInsn(new Insn(opc_return));

    // ClassEnv's are used as a container
    // to hold all information about a class.

    ClassEnv nclass = new ClassEnv();
    nclass.setClass(new ClassCP("out"));
    nclass.setSuperClass(new ClassCP("java/lang/Object"));

    // Add the init code to the class.
    nclass.addMethod((short) ACC_PUBLIC, "<init>", "()V", init, null);

    // write it all out
    nclass.write(new DataOutputStream(new FileOutputStream("out.class")));
  }
Пример #9
0
 //
 // called by the .attribute directive
 //
 void addGenericAttr(String name, String file) throws IOException, jasError {
   GenericAttr gattr = new GenericAttr(name, file);
   if (cur_method != null) {
     flushInsnBuffer();
     if (code != null) code.addGenericAttr(gattr);
     else cur_method.addGenericAttr(gattr);
   } else if (cur_field != null) {
     cur_field.addGenericAttr(gattr);
   } else if (class_header) {
     class_env.addGenericAttr(gattr);
   } else {
     outside(".attribute");
   }
 }
Пример #10
0
  //
  // called by the .end method directive to end the definition for a method
  //
  void endMethod() throws jasError {
    if (cur_method == null) throw new jasError(".end method without .method");

    if (cur_annotation != null) opened_annotation("method");

    if (code != null) {

      plantLabel(END_METHOD);
      flushInsnBuffer();

      if (catch_table != null) {
        code.setCatchtable(catch_table);
      }

      if (var_table != null) {
        code.setLocalVarTable(var_table);
      }
      if (vtype_table != null) {
        code.setLocalVarTypeTable(vtype_table);
      }
      if (line_table != null) {
        code.setLineTable(line_table);
      }
      if (stackmap != null) {
        code.setStackMap(stackmap);
      }
    }
    cur_method.setCode(code, except_attr);
    class_env.addMethod(cur_method);

    // clear method state variables
    cur_method = null;
    code = null;
    labels = null;
    catch_table = null;
    line_table = null;
    var_table = null;
    vtype_table = null;
    stackmap = null;
    verifyframe = null;
  }
Пример #11
0
 //
 // called by the .inner directive
 //
 //
 public void addInner(short iacc, String name, String inner, String outer) {
   class_env.addInnerClass(iacc, name, inner, outer);
 }
Пример #12
0
  //
  // called at end of jasmin-header (resolve class variables)
  //
  public void endHeader() throws jasError {
    if (cur_annotation != null) opened_annotation("class header");

    class_env.endHeader(); // resolve annotations
    class_header = false;
  }
Пример #13
0
 //
 // called by the .debug directive
 //
 void setSourceDebugExtension(String str) {
   class_env.setSourceDebugExtension(str);
 }
Пример #14
0
 //
 // called by the .implements directive
 //
 void addInterface(String name) {
   class_env.addInterface(new ClassCP(name));
 }
Пример #15
0
 //
 // called by the .super directive
 //
 void setSuperClass(String name) {
   class_env.setSuperClass(new ClassCP(name));
 }
Пример #16
0
 /**
  * Writes the binary data for the class represented by this ClassFile object to the specified
  * output stream, using the Java Class File format. Throws either an IOException or a jasError if
  * something goes wrong.
  */
 public void write(OutputStream outp) throws IOException, jasError {
   class_env.setSource(source_name);
   class_env.write(new DataOutputStream(outp));
 }