Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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")));
  }