Search in sources :

Example 76 with Type

use of org.objectweb.asm.Type in project bytecode-viewer by Konloch.

the class SimpleVerifier method isSubTypeOf.

@Override
protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected) {
    Type expectedType = expected.getType();
    Type type = value.getType();
    switch(expectedType.getSort()) {
        case Type.INT:
        case Type.FLOAT:
        case Type.LONG:
        case Type.DOUBLE:
            return type.equals(expectedType);
        case Type.ARRAY:
        case Type.OBJECT:
            if ("Lnull;".equals(type.getDescriptor())) {
                return true;
            } else if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
                return isAssignableFrom(expectedType, type);
            } else {
                return false;
            }
        default:
            throw new Error("Internal error");
    }
}
Also used : Type(org.objectweb.asm.Type)

Example 77 with Type

use of org.objectweb.asm.Type in project bytecode-viewer by Konloch.

the class SimpleVerifier method merge.

@Override
public BasicValue merge(final BasicValue v, final BasicValue w) {
    if (!v.equals(w)) {
        Type t = v.getType();
        Type u = w.getType();
        if (t != null && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
            if (u != null && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
                if ("Lnull;".equals(t.getDescriptor())) {
                    return w;
                }
                if ("Lnull;".equals(u.getDescriptor())) {
                    return v;
                }
                if (isAssignableFrom(t, u)) {
                    return v;
                }
                if (isAssignableFrom(u, t)) {
                    return w;
                }
                // interfaces
                do {
                    if (t == null || isInterface(t)) {
                        return BasicValue.REFERENCE_VALUE;
                    }
                    t = getSuperClass(t);
                    if (isAssignableFrom(t, u)) {
                        return newValue(t);
                    }
                } while (true);
            }
        }
        return BasicValue.UNINITIALIZED_VALUE;
    }
    return v;
}
Also used : Type(org.objectweb.asm.Type)

Example 78 with Type

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

the class ClassDependenciesVisitor method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    Type methodType = Type.getMethodType(desc);
    maybeAddDependentType(methodType.getReturnType().getClassName());
    for (Type argType : methodType.getArgumentTypes()) {
        maybeAddDependentType(argType.getClassName());
    }
    return localVariableVisitor;
}
Also used : Type(org.objectweb.asm.Type)

Example 79 with Type

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

the class ManagedCollectionProxyClassGenerator method generate.

/**
 * Generates an implementation of the given managed type.
 *
 * <p>The generated type will:</p>
 *
 * <ul>
 *     <li>extend the given implementation class</li>
 *     <li>implement the given public interface</li>
 *     <li>override each public constructor of the given implementation class</li>
 * </ul>
 */
public Class<?> generate(Class<?> implClass, Class<?> publicContractType) {
    AsmClassGenerator classGenerator = new AsmClassGenerator(publicContractType, "_Impl");
    ClassWriter visitor = classGenerator.getVisitor();
    Type generatedType = classGenerator.getGeneratedType();
    Type superclassType = Type.getType(implClass);
    Type publicType = Type.getType(publicContractType);
    generateClass(visitor, generatedType, superclassType, publicType);
    generateConstructors(visitor, implClass, superclassType);
    visitor.visitEnd();
    return classGenerator.define();
}
Also used : Type(org.objectweb.asm.Type) AsmClassGenerator(org.gradle.model.internal.asm.AsmClassGenerator) ClassWriter(org.objectweb.asm.ClassWriter)

Example 80 with Type

use of org.objectweb.asm.Type in project Lucee by lucee.

the class ExpressionAsStatement method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    int rtn = bc.getReturn();
    // set rtn
    if (rtn > -1) {
        Type type = expr.writeOut(bc, Expression.MODE_REF);
        bc.getAdapter().storeLocal(rtn);
    } else {
        if (!(expr instanceof Literal)) {
            Type type = expr.writeOut(bc, Expression.MODE_VALUE);
            if (!type.equals(Types.VOID)) {
                ASMUtil.pop(adapter, type);
            }
        }
    }
}
Also used : Type(org.objectweb.asm.Type) Literal(lucee.transformer.expression.literal.Literal) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

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