Package org.objectweb.asm

Examples of org.objectweb.asm.MethodVisitor


        make_invoke_method(cw, self_type, arity);

        CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0);

        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "arity", "()I", null, null);
        mv.visitCode();
        mv.visitLdcInsn(new Integer(arity));
        mv.visitInsn(Opcodes.IRETURN);
        mv.visitMaxs(2, 2);
        mv.visitEnd();

        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "("
                + EPROC_TYPE.getDescriptor() + EOBJECT_ARR_TYPE.getDescriptor()
                + ")" + EOBJECT_TYPE.getDescriptor(), null, PAUSABLE_EX);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0); // load this
        mv.visitVarInsn(Opcodes.ALOAD, 1); // load proc
        for (int i = 0; i < arity; i++) {
            mv.visitVarInsn(Opcodes.ALOAD, 2);
            push_int(mv, i);
            mv.visitInsn(Opcodes.AALOAD);
        }

        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, self_type, "invoke", EUtil
                .getSignature(arity, true));

        mv.visitInsn(Opcodes.ARETURN);
        mv.visitMaxs(arity + 2, arity + 2);
        mv.visitEnd();

        mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "()V", null, null);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, EFUN_TYPE.getInternalName(),
                "<init>", "()V");
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        make_cast_method(cw, arity);

        cw.visitEnd();
View Full Code Here


            cw.visitField(ACC_PRIVATE | ACC_FINAL, "function_name", EATOM_DESC, null, null)
                    .visitEnd();


            // make constructor
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "("
                    + EFUNHANDLER_TYPE.getDescriptor()
                    + EATOM_DESC
                    + EATOM_DESC
                    + ")V", null, null);
            mv.visitCode();

            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, super_class_name, "<init>",
                    "()V");

            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 1);
            mv.visitFieldInsn(PUTFIELD, self_type, "handler", EFUNHANDLER_TYPE
                    .getDescriptor());
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 2);
            mv.visitFieldInsn(PUTFIELD, self_type, "module_name", EATOM_DESC);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 3);
            mv.visitFieldInsn(PUTFIELD, self_type, "function_name", EATOM_DESC);

            mv.visitInsn(RETURN);
            mv.visitMaxs(4, 4);
            mv.visitEnd();

            /** forward toString to handler */
            mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
            mv.visitCode();
            mv.visitVarInsn(ALOAD, 0); // load self
            mv.visitFieldInsn(GETFIELD, self_type, "handler", EFUNHANDLER_TYPE.getDescriptor());
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;");
            mv.visitInsn(ARETURN);
            mv.visitMaxs(3, 3);
            mv.visitEnd();

            // make invoke_tail method
            //CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0);
            make_invoke_method(cw, self_type, arity);
            make_go_method(cw, self_type, arity);
View Full Code Here

            throw new Error(e);
        }
    }

    private static void make_cast_method(ClassWriter cw, int n) {
        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC|Opcodes.ACC_STATIC, "cast",
                "(" + EOBJECT_DESC + ")L" + EFUN_NAME + n + ";",
                null, null);
        mv.visitCode();

        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitTypeInsn(INSTANCEOF, EFUN_NAME+n);

        Label fail = new Label();

        mv.visitJumpInsn(Opcodes.IFEQ, fail);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitTypeInsn(Opcodes.CHECKCAST, EFUN_NAME+n);
        mv.visitInsn(Opcodes.ARETURN);

        mv.visitLabel(fail);
        mv.visitInsn(Opcodes.ACONST_NULL);
        mv.visitInsn(Opcodes.ARETURN);

        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
View Full Code Here

    }


    private static void make_go_method(ClassWriter cw, String self_type,
                                       int arity) {
        MethodVisitor mv;
        mv = cw.visitMethod(ACC_PUBLIC, "go", GO_DESC, null, PAUSABLE_EX);
        mv.visitCode();

        for (int i = 0; i < arity; i++) {
            mv.visitVarInsn(ALOAD, 1);
            mv.visitFieldInsn(GETFIELD, EPROC_NAME, "arg" + i, EOBJECT_DESC);
            mv.visitVarInsn(ASTORE, i + 2);
        }
        for (int i = 0; i < arity; i++) {
            mv.visitVarInsn(ALOAD, 1);
            mv.visitInsn(ACONST_NULL);
            mv.visitFieldInsn(PUTFIELD, EPROC_NAME, "arg" + i, EOBJECT_DESC);
        }

        // load handler
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, self_type, "handler", EFUNHANDLER_TYPE
                .getDescriptor());

        // load proc
        mv.visitVarInsn(ALOAD, 1);

        // create array
        mv.visitLdcInsn(new Integer(arity));
        mv.visitTypeInsn(ANEWARRAY, EOBJECT_TYPE.getInternalName());

        for (int i = 0; i < arity; i++) {
            mv.visitInsn(DUP);
            mv.visitLdcInsn(new Integer(i));
            mv.visitVarInsn(ALOAD, i + 2);
            mv.visitInsn(AASTORE);
        }

        mv.visitMethodInsn(INVOKEINTERFACE, EFUNHANDLER_TYPE.getInternalName(), "invoke",
                "(" + EPROC_TYPE.getDescriptor() + "[" + EOBJECT_DESC + ")" + EOBJECT_DESC);
        mv.visitInsn(ARETURN);
        mv.visitMaxs(arity + 2, arity + 2);
        mv.visitEnd();

        cw.visitEnd();
    }
View Full Code Here

  }

  @Override
  public MethodVisitor visitMethod(int access, String name, String desc,
                                   String signature, String[] exceptions) {
    MethodVisitor mv =
        cv.visitMethod(access, name, desc, signature, exceptions);
    return new HelperMethodAdapter(mv, access, name, desc);
  }
View Full Code Here

   * Visits the specified method, adding line numbering.
   */
  @Override
  public MethodVisitor visitMethod(int access, final String name, String desc,
                                   String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access | Opcodes.ACC_SYNTHETIC,
                                      name, desc, signature, exceptions);
    return new LineNumberingMethodAdapter(mv, access | Opcodes.ACC_SYNTHETIC,
                                          name, desc) {
      @Override
      protected void onMethodEnter() {
View Full Code Here

  }

  @Override
  public MethodVisitor visitMethod(int access, String name, String desc,
                                   String signature, String[] exceptions) {
    MethodVisitor mv =
        cv.visitMethod(access, name, desc, signature, exceptions);
    if ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) != 0) {
      return mv;
    }
View Full Code Here

          "Duplicate method after name translation in class "
              + className + ": " + name + ' ' + newDesc);
    }
    visitedMethods.add(fullDesc);

    MethodVisitor mv = super.visitMethod(access, name, newDesc,
        translator.getClassMirrorTranslation(signature), exceptions);
    return (mv == null)?null:new MethodTranslator(mv);
  }
View Full Code Here

            */
            newAccess = access & ~ACC_SYNTHETIC & ~ACC_BRIDGE;
        } else
            newAccess = access;

        MethodVisitor mv = new MethodWeaver(super.visitMethod(newAccess,
                    name,
                    desc,
                    signature,
                    exceptions));
     
View Full Code Here

        }

        if (!isInterface) {
          // "class$" method
          String exceptionTable[] = { JAVA_LANG_NOCLASSDEFFOUNDERROR };
          MethodVisitor mv = cv.visitMethod(ACC_STATIC+ACC_SYNTHETIC,
                            CLASS_METHOD,
                            CLASS_SIGNATURE,
                            null, exceptionTable);
 
          mv.visitCode();

              mv.visitVarInsn(ALOAD, 0);
              generateClassCall(mv);
              mv.visitInsn(ARETURN);
     
              mv.visitMaxs(0, 0);
              mv.visitEnd();
        }
      }
        cv.visitEnd();
    }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.MethodVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.