Package org.objectweb.asm

Examples of org.objectweb.asm.Type


 
  public void doMath(BytecodeContextMethodASM context, IBytecodeReferenceable value1, IBytecodeReferenceable value2, MathmaticalOperator operator) {
    value1.load(context);
    value2.load(context);
   
    Type type = getType(value1.getType());
   
    context.push(value1.getType());
    context.push(value2.getType());
   
    int opcode = 0;
    switch (operator) {
      case Multiply: opcode = type.getOpcode(IMUL); break;
      case Divide: opcode = type.getOpcode(IDIV); break;
      case Plus: opcode = type.getOpcode(IADD); break;
      case Minus: opcode = type.getOpcode(ISUB); break;
     
      default:
        throw new BytecodeException("Unsupported operator: " + operator);
    }
   
View Full Code Here


  @Override public void loadType(BytecodeContextMethodASM context, IBytecodeResolvable type) {
    context.getTarget().visitLdcInsn(Type.getType(type.getType().toDescriptorString()));
  }

  public void loadLiteral(BytecodeContextMethodASM context, LiteralValue literal) {
    Type type = getType(literal.getType());
    if (literal.getValue() instanceof Number || literal.getValue() instanceof Character) {
      Number value = literal.getValue() instanceof Character ? (int) ((Character)literal.getValue()).charValue() : (Number) literal.getValue();
      if (value instanceof Double || value instanceof Float || value.longValue() > Short.MAX_VALUE) {
        context.getTarget().visitLdcInsn(value);
      } else {
View Full Code Here

   
    context.push(literal.getType());
  }

  public void storeLocal (BytecodeContextMethodASM context, int idx) {
    Type type = getType(context.getLocalVariable(idx).getType());
    context.getTarget().visitVarInsn(type.getOpcode(ISTORE), idx);
    context.popStack();
  }
View Full Code Here

    context.popStack();
  }
 
  public void loadLocal (BytecodeContextMethodASM context, int idx) {
    TypeDescriptor ts = context.getLocalVariable(idx).getType();
    Type type = getType(ts);
    context.getTarget().visitVarInsn(type.getOpcode(ILOAD), idx);
    context.push(ts);
  }
View Full Code Here

  public void returnValue(BytecodeContextMethodASM context, TypeDescriptor td) {
    if (td == null) {
      this.loadNull(context);
      context.getTarget().visitInsn(ARETURN);
    } else {
      Type type = getType(td);
      context.getTarget().visitInsn(type.getOpcode(IRETURN));
    }
  }
View Full Code Here

    }

    private <T> Class<? extends T> doGenerate(Class<T> type) {
        ClassWriter visitor = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        String typeName = StringUtils.substringBeforeLast(type.getName(), ".") + ".LocationAware" + type.getSimpleName();
        Type generatedType = Type.getType("L" + typeName.replaceAll("\\.", "/") + ";");
        Type superclassType = Type.getType(type);

        visitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, generatedType.getInternalName(), null,
                superclassType.getInternalName(), new String[]{Type.getType(LocationAwareException.class).getInternalName()});

        Type helperType = Type.getType(ExceptionHelper.class);
        Type throwableType = Type.getType(Throwable.class);
        Type scriptSourceType = Type.getType(ScriptSource.class);
        Type integerType = Type.getType(Integer.class);

        // GENERATE private ExceptionHelper helper;
        visitor.visitField(Opcodes.ACC_PRIVATE, "helper", helperType.getDescriptor(), null, null);

        // GENERATE <init>(<type> target, ScriptSource source, Integer lineNumber)
View Full Code Here

    }

    private <T extends Script> Class<? extends T> generateEmptyScriptClass(Class<T> type) {
        ClassWriter visitor = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        String typeName = type.getName() + "_Decorated";
        Type generatedType = Type.getType("L" + typeName.replaceAll("\\.", "/") + ";");
        Type superclassType = Type.getType(type);
        visitor.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, generatedType.getInternalName(), null,
                superclassType.getInternalName(), new String[0]);

        // Constructor

        String constructorDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]);
        MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", constructorDescriptor, null,
                new String[0]);
        methodVisitor.visitCode();

        // super()
        methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
        methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>",
                constructorDescriptor);

        methodVisitor.visitInsn(Opcodes.RETURN);
        methodVisitor.visitMaxs(0, 0);
        methodVisitor.visitEnd();
View Full Code Here

                        buf1.append(getSimpleName(Type.getType(desc)));
                    }
                    break;
                case METHOD_DESCRIPTOR :
                    Type[] args = Type.getArgumentTypes(desc);
                    Type res = Type.getReturnType(desc);
                    buf1.append('(');
                    for (int i = 0; i < args.length; ++i) {
                        if (i > 0) {
                            buf1.append(',');
                        }
View Full Code Here

      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "getF", "()I", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("int getF()");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadThis();
      ga.getField(bean, "f", Type.INT_TYPE);
      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "setF", "(I)V", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("void setF(int)");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadThis();
      ga.loadArg(0);
      ga.putField(bean, "f", Type.INT_TYPE);
      ga.returnValue();
      ga.endMethod();
    }
    mv = cv.visitMethod(ACC_PUBLIC, "checkAndSetF", "(I)V", null, null);
    if (mv != null) {
      Type bean = Type.getType("Lpkg/Bean;");
      Method m = Method.getMethod("void checkAndSetF(int)");
      GeneratorAdapter ga = new GeneratorAdapter(ACC_PUBLIC, m, mv);
      ga.visitCode();
      ga.loadArg(0);
      Label label = new Label();
View Full Code Here

    cv.visitEnd();
  }

  private static Method getMethod(java.lang.reflect.Method m) {
    Type returnType = Type.getType(m.getReturnType());
    Type[] argTypes = new Type[m.getParameterTypes().length];
    for (int i = 0; i < argTypes.length; ++i) {
      argTypes[i] = Type.getType(m.getParameterTypes()[i]);
    }
    return new Method(m.getName(), returnType, argTypes);
View Full Code Here

TOP

Related Classes of org.objectweb.asm.Type

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.