Search in sources :

Example 41 with Type

use of org.objectweb.asm.Type in project cglib by cglib.

the class ParallelSorterEmitter method generateConstructor.

private void generateConstructor(Object[] arrays) {
    CodeEmitter e = begin_method(Constants.ACC_PUBLIC, CSTRUCT_OBJECT_ARRAY, null);
    e.load_this();
    e.super_invoke_constructor();
    e.load_this();
    e.load_arg(0);
    e.super_putfield("a", Constants.TYPE_OBJECT_ARRAY);
    for (int i = 0; i < arrays.length; i++) {
        Type type = Type.getType(arrays[i].getClass());
        declare_field(Constants.ACC_PRIVATE, getFieldName(i), type, null);
        e.load_this();
        e.load_arg(0);
        e.push(i);
        e.aaload();
        e.checkcast(type);
        e.putfield(getFieldName(i));
    }
    e.return_value();
    e.end_method();
}
Also used : Type(org.objectweb.asm.Type)

Example 42 with Type

use of org.objectweb.asm.Type in project cglib by cglib.

the class ParallelSorterEmitter method generateSwap.

private void generateSwap(final Object[] arrays) {
    CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SWAP, null);
    for (int i = 0; i < arrays.length; i++) {
        Type type = Type.getType(arrays[i].getClass());
        Type component = TypeUtils.getComponentType(type);
        Local T = e.make_local(type);
        e.load_this();
        e.getfield(getFieldName(i));
        e.store_local(T);
        e.load_local(T);
        e.load_arg(0);
        e.load_local(T);
        e.load_arg(1);
        e.array_load(component);
        e.load_local(T);
        e.load_arg(1);
        e.load_local(T);
        e.load_arg(0);
        e.array_load(component);
        e.array_store(component);
        e.array_store(component);
    }
    e.return_value();
    e.end_method();
}
Also used : Type(org.objectweb.asm.Type)

Example 43 with Type

use of org.objectweb.asm.Type in project buck by facebook.

the class FirstOrderHelper method addFirstOrderTypes.

private void addFirstOrderTypes(Type type) {
    addTypeAndSupers(type);
    FirstOrderTypeInfo info = knownTypes.get(type);
    if (info != null) {
        for (Type dependency : info.observedDependencies) {
            addTypeAndSupers(dependency);
        }
    }
}
Also used : Type(org.objectweb.asm.Type)

Example 44 with Type

use of org.objectweb.asm.Type in project buck by facebook.

the class FirstOrderHelper method addDependencies.

private ImmutableSet<String> addDependencies(Iterable<ClassNode> allClasses) {
    for (ClassNode classNode : allClasses) {
        FirstOrderVisitorContext context = new FirstOrderVisitorContext();
        classNode.accept(context.classVisitor);
        FirstOrderTypeInfo info = context.builder.build();
        knownTypes.put(info.type, info);
    }
    for (Type type : scenarioTypes) {
        addFirstOrderTypes(type);
    }
    return resultBuilder.build();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) Type(org.objectweb.asm.Type)

Example 45 with Type

use of org.objectweb.asm.Type in project enumerable by hraberg.

the class ExpressionInterpreter method newOperation.

public Value newOperation(final AbstractInsnNode insn) throws AnalyzerException {
    switch(insn.getOpcode()) {
        case ACONST_NULL:
            return new ExpressionValue(createClassOrInterfaceType(Object.class.getName()), new NullLiteralExpr());
        case ICONST_M1:
            return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("1"), UnaryExpr.Operator.negative));
        case ICONST_0:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("0"));
        case ICONST_1:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("1"));
        case ICONST_2:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("2"));
        case ICONST_3:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("3"));
        case ICONST_4:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("4"));
        case ICONST_5:
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("5"));
        case LCONST_0:
            return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("0L"));
        case LCONST_1:
            return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("1L"));
        case FCONST_0:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("0.0f"));
        case FCONST_1:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("1.0f"));
        case FCONST_2:
            return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("2.0f"));
        case DCONST_0:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("0.0"));
        case DCONST_1:
            return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("1.0"));
        case BIPUSH:
        case SIPUSH:
            int operand = ((IntInsnNode) insn).operand;
            if (operand < 0)
                return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("" + Math.abs(operand)), UnaryExpr.Operator.negative));
            return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("" + operand));
        case LDC:
            Object cst = ((LdcInsnNode) insn).cst;
            if (cst instanceof Number) {
                ExpressionValue value = null;
                if (cst instanceof Integer) {
                    value = new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr(cst.toString()));
                } else if (cst instanceof Float) {
                    value = new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr(cst.toString() + "f"));
                } else if (cst instanceof Long) {
                    value = new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr(cst.toString() + "L"));
                } else if (cst instanceof Double) {
                    value = new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr(cst.toString()));
                }
                if (((Number) cst).intValue() < 0) {
                    StringLiteralExpr expr = (StringLiteralExpr) value.expression;
                    expr.setValue(expr.getValue().substring("-".length()));
                    value.expression = new UnaryExpr(expr, UnaryExpr.Operator.negative);
                }
                return value;
            } else if (cst instanceof Type) {
                ClassExpr classExpr = new ClassExpr(new ReferenceType(createClassOrInterfaceType(((Type) cst).getClassName())));
                return new ExpressionValue(createClassOrInterfaceType(Class.class.getName()), classExpr);
            } else {
                return new ExpressionValue(createClassOrInterfaceType(String.class.getName()), new StringLiteralExpr(cst.toString()));
            }
        case JSR:
            throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
        case GETSTATIC:
            FieldInsnNode fieldNode = (FieldInsnNode) insn;
            ExpressionValue getField = (ExpressionValue) newValue(getType(fieldNode.desc));
            getField.expression = new FieldAccessExpr(new NameExpr(removeJavaLang(getObjectType(fieldNode.owner).getClassName())), fieldNode.name);
            return getField;
        case NEW:
            return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
        default:
            throw new Error("Internal error.");
    }
}
Also used : IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) ReferenceType(japa.parser.ast.type.ReferenceType) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) Type(org.objectweb.asm.Type) ClassOrInterfaceType(japa.parser.ast.type.ClassOrInterfaceType) ReferenceType(japa.parser.ast.type.ReferenceType) PrimitiveType(japa.parser.ast.type.PrimitiveType)

Aggregations

Type (org.objectweb.asm.Type)185 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)39 MethodVisitor (org.objectweb.asm.MethodVisitor)34 Method (org.objectweb.asm.commons.Method)28 Label (org.objectweb.asm.Label)27 ClassWriter (org.objectweb.asm.ClassWriter)16 Method (java.lang.reflect.Method)13 ArrayList (java.util.ArrayList)12 ClassReader (org.objectweb.asm.ClassReader)10 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)9 ClassVisitor (org.objectweb.asm.ClassVisitor)9 ExprString (lucee.transformer.expression.ExprString)8 ModelType (org.gradle.model.internal.type.ModelType)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 IOException (java.io.IOException)6 MethodType (java.lang.invoke.MethodType)6 HashMap (java.util.HashMap)6 List (java.util.List)6 LitString (lucee.transformer.expression.literal.LitString)6 PropertyAccessorType (org.gradle.internal.reflect.PropertyAccessorType)6