Пример #1
0
 /** Prepares return value. */
 public static void prepareReturnValue(
     MethodVisitor mv, MethodSignatureVisitor msign, int varOffset) {
   varOffset += msign.getAllArgumentsSize();
   switch (msign.getReturnOpcodeType()) {
     case 'V':
       mv.visitInsn(ACONST_NULL);
       break;
     case 'B':
       AsmUtil.valueOfByte(mv);
       break;
     case 'C':
       AsmUtil.valueOfCharacter(mv);
       break;
     case 'S':
       AsmUtil.valueOfShort(mv);
       break;
     case 'I':
       AsmUtil.valueOfInteger(mv);
       break;
     case 'Z':
       AsmUtil.valueOfBoolean(mv);
       break;
     case 'J':
       AsmUtil.valueOfLong(mv);
       break;
     case 'F':
       AsmUtil.valueOfFloat(mv);
       break;
     case 'D':
       AsmUtil.valueOfDouble(mv);
       break;
   }
 }
Пример #2
0
 public static void loadMethodArgumentAsObject(
     MethodVisitor mv, MethodSignatureVisitor msign, int index) {
   int offset = msign.getArgumentOffset(index);
   int type = msign.getArgumentOpcodeType(index);
   switch (type) {
     case 'V':
       break;
     case 'B':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfByte(mv);
       break;
     case 'C':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfCharacter(mv);
       break;
     case 'S':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfShort(mv);
       break;
     case 'I':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfInteger(mv);
       break;
     case 'Z':
       mv.visitVarInsn(ILOAD, offset);
       AsmUtil.valueOfBoolean(mv);
       break;
     case 'J':
       mv.visitVarInsn(LLOAD, offset);
       AsmUtil.valueOfLong(mv);
       break;
     case 'F':
       mv.visitVarInsn(FLOAD, offset);
       AsmUtil.valueOfFloat(mv);
       break;
     case 'D':
       mv.visitVarInsn(DLOAD, offset);
       AsmUtil.valueOfDouble(mv);
       break;
     default:
       mv.visitVarInsn(ALOAD, offset);
   }
 }
Пример #3
0
 public static void storeValue(MethodVisitor mv, int offset, int type) {
   switch (type) {
     case 'V':
       break;
     case 'B':
       AsmUtil.byteValue(mv);
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'C':
       AsmUtil.charValue(mv);
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'S':
       AsmUtil.shortValue(mv);
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'I':
       AsmUtil.intValue(mv);
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'Z':
       AsmUtil.booleanValue(mv);
       mv.visitVarInsn(ISTORE, offset);
       break;
     case 'J':
       AsmUtil.longValue(mv);
       mv.visitVarInsn(LSTORE, offset);
       break;
     case 'F':
       AsmUtil.floatValue(mv);
       mv.visitVarInsn(FSTORE, offset);
       break;
     case 'D':
       AsmUtil.doubleValue(mv);
       mv.visitVarInsn(DSTORE, offset);
       break;
     default:
       mv.visitVarInsn(ASTORE, offset);
   }
 }
Пример #4
0
  /** Visits return opcodes. */
  public static void visitReturn(MethodVisitor mv, MethodSignatureVisitor msign, boolean isLast) {
    switch (msign.getReturnOpcodeType()) {
      case 'V':
        if (isLast == true) {
          mv.visitInsn(POP);
        }
        mv.visitInsn(RETURN);
        break;

      case 'B':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.byteValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'C':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.charValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'S':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.shortValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'I':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.intValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'Z':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(ICONST_0);
          mv.visitInsn(IRETURN);
          mv.visitLabel(label);

          AsmUtil.booleanValue(mv);
        }
        mv.visitInsn(IRETURN);
        break;

      case 'J':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(LCONST_0);
          mv.visitInsn(LRETURN);
          mv.visitLabel(label);

          AsmUtil.longValue(mv);
        }
        mv.visitInsn(LRETURN);
        break;

      case 'F':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(FCONST_0);
          mv.visitInsn(FRETURN);
          mv.visitLabel(label);

          AsmUtil.floatValue(mv);
        }
        mv.visitInsn(FRETURN);
        break;

      case 'D':
        if (isLast == true) {
          mv.visitInsn(DUP);
          Label label = new Label();
          mv.visitJumpInsn(IFNONNULL, label);
          mv.visitInsn(POP);
          mv.visitInsn(DCONST_0);
          mv.visitInsn(DRETURN);
          mv.visitLabel(label);

          AsmUtil.doubleValue(mv);
        }
        mv.visitInsn(DRETURN);
        break;

      default:
        mv.visitInsn(ARETURN);
        break;
    }
  }