Search in sources :

Example 1 with AnnotationClassElem

use of soot.tagkit.AnnotationClassElem in project robovm by robovm.

the class MarshalerLookup method getBaseType.

private soot.Type getBaseType(SootMethod m, AnnotationTag anno) {
    AnnotationClassElem el = (AnnotationClassElem) getElemByName(anno, "baseType");
    if (el != null) {
        switch(el.getDesc().charAt(0)) {
            case 'Z':
                return BooleanType.v();
            case 'B':
                return ByteType.v();
            case 'S':
                return ShortType.v();
            case 'C':
                return CharType.v();
            case 'I':
                return IntType.v();
            case 'J':
                return LongType.v();
            case 'F':
                return FloatType.v();
            case 'D':
                return DoubleType.v();
        }
        return null;
    }
    soot.Type t = m.getReturnType();
    if (t == VoidType.v()) {
        t = m.getParameterType(0);
    }
    if (t instanceof RefType) {
        SootClass c = ((RefType) t).getSootClass();
        if (isInstanceOfClass(c, "java.nio.ByteBuffer")) {
            return ByteType.v();
        } else if (isInstanceOfClass(c, "java.nio.ShortBuffer")) {
            return ShortType.v();
        } else if (isInstanceOfClass(c, "java.nio.CharBuffer")) {
            return CharType.v();
        } else if (isInstanceOfClass(c, "java.nio.IntBuffer")) {
            return IntType.v();
        } else if (isInstanceOfClass(c, "java.nio.LongBuffer")) {
            return LongType.v();
        } else if (isInstanceOfClass(c, "java.nio.FloatBuffer")) {
            return FloatType.v();
        } else if (isInstanceOfClass(c, "java.nio.DoubleBuffer")) {
            return DoubleType.v();
        } else if (isInstanceOfClass(c, "org.robovm.rt.bro.Struct")) {
            return config.getClazzes().load("org/robovm/rt/bro/Struct").getSootClass().getType();
        }
    } else if (t instanceof ArrayType) {
        ArrayType arrayType = (ArrayType) t;
        if (arrayType.baseType instanceof PrimType || isInstanceOfClass(arrayType.baseType, "org.robovm.rt.bro.Struct")) {
            return arrayType.baseType;
        }
    }
    return null;
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType) AnnotationClassElem(soot.tagkit.AnnotationClassElem) PrimType(soot.PrimType) SootClass(soot.SootClass)

Example 2 with AnnotationClassElem

use of soot.tagkit.AnnotationClassElem in project robovm by robovm.

the class MarshalerLookup method findMarshalerMethod.

public MarshalerMethod findMarshalerMethod(MarshalSite marshalSite) {
    int pidx = marshalSite.paramIdx;
    if (pidx != MarshalSite.RECEIVER) {
        // Use @Marshaler annotation on method or parameter at paramIndex if there is one 
        AnnotationTag anno = pidx == MarshalSite.RETURN_TYPE ? getMarshalerAnnotation(marshalSite.method) : getMarshalerAnnotation(marshalSite.method, pidx);
        if (anno != null) {
            AnnotationClassElem elem = (AnnotationClassElem) getElemByName(anno, "value");
            String name = getInternalNameFromDescriptor(elem.getDesc());
            Clazz marshalerClazz = config.getClazzes().load(name);
            if (marshalerClazz != null) {
                Marshaler marshaler = new Marshaler(marshalerClazz);
                if (marshaler.canMarshal(marshalSite)) {
                    return marshaler.getMarshalerMethod(marshalSite);
                }
            }
            throw new IllegalArgumentException(String.format("@Marshaler %s specified for %s of %s method %s can " + "not be used to marshal %s", name.replace('/', '.'), (pidx == MarshalSite.RETURN_TYPE ? "return type" : "parameter " + (pidx + 1)), marshalSite.callTypeName, marshalSite.method, marshalSite.type));
        }
    }
    Marshaler marshaler = findMarshalers(marshalSite);
    if (marshaler != null) {
        return marshaler.getMarshalerMethod(marshalSite);
    }
    throw new IllegalArgumentException(String.format("No @Marshaler found for %s of %s method %s", (pidx == MarshalSite.RECEIVER ? "receiver" : (pidx == MarshalSite.RETURN_TYPE ? "return type" : "parameter " + (pidx + 1))), marshalSite.callTypeName, marshalSite.method));
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem) Clazz(org.robovm.compiler.clazz.Clazz)

Example 3 with AnnotationClassElem

use of soot.tagkit.AnnotationClassElem in project robovm by robovm.

the class AttributesEncoder method encodeAnnotationElementValue.

private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
    PackedStructureType type = getAnnotationElementType(ae);
    Value kind = new IntegerConstant((byte) ae.getKind());
    if (ae instanceof AnnotationIntElem) {
        AnnotationIntElem aie = (AnnotationIntElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
    } else if (ae instanceof AnnotationLongElem) {
        AnnotationLongElem ale = (AnnotationLongElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
    } else if (ae instanceof AnnotationFloatElem) {
        AnnotationFloatElem afe = (AnnotationFloatElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
    } else if (ae instanceof AnnotationDoubleElem) {
        AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
    } else if (ae instanceof AnnotationStringElem) {
        AnnotationStringElem ase = (AnnotationStringElem) ae;
        return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
    } else if (ae instanceof AnnotationClassElem) {
        AnnotationClassElem ace = (AnnotationClassElem) ae;
        addDependencyIfNeeded(ace.getDesc());
        return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
    } else if (ae instanceof AnnotationEnumElem) {
        AnnotationEnumElem aee = (AnnotationEnumElem) ae;
        addDependencyIfNeeded(aee.getTypeName());
        return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
    } else if (ae instanceof AnnotationArrayElem) {
        AnnotationArrayElem aae = (AnnotationArrayElem) ae;
        Value[] values = new Value[aae.getNumValues() + 2];
        values[0] = kind;
        values[1] = new IntegerConstant((char) aae.getNumValues());
        for (int i = 0; i < aae.getNumValues(); i++) {
            values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
        }
        return new PackedStructureConstant(type, values);
    } else if (ae instanceof AnnotationAnnotationElem) {
        AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
        return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
    }
    throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem) Value(org.robovm.compiler.llvm.Value)

Example 4 with AnnotationClassElem

use of soot.tagkit.AnnotationClassElem in project robovm by robovm.

the class ObjCBlockPlugin method addMarshalerAnnotation.

static void addMarshalerAnnotation(SootMethod method, String marshalerName) {
    AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
    annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
    addRuntimeVisibleAnnotation(method, annotationTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Example 5 with AnnotationClassElem

use of soot.tagkit.AnnotationClassElem in project robovm by robovm.

the class ObjCBlockPlugin method addMarshalerAnnotation.

static void addMarshalerAnnotation(SootMethod method, int paramIndex, String marshalerName) {
    AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
    annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
    addRuntimeVisibleParameterAnnotation(method, paramIndex, annotationTag);
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem)

Aggregations

AnnotationClassElem (soot.tagkit.AnnotationClassElem)6 AnnotationTag (soot.tagkit.AnnotationTag)4 Clazz (org.robovm.compiler.clazz.Clazz)2 ArrayList (java.util.ArrayList)1 FloatingPointConstant (org.robovm.compiler.llvm.FloatingPointConstant)1 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)1 PackedStructureConstant (org.robovm.compiler.llvm.PackedStructureConstant)1 PackedStructureType (org.robovm.compiler.llvm.PackedStructureType)1 Value (org.robovm.compiler.llvm.Value)1 ArrayType (soot.ArrayType)1 PrimType (soot.PrimType)1 RefType (soot.RefType)1 SootClass (soot.SootClass)1 AnnotationAnnotationElem (soot.tagkit.AnnotationAnnotationElem)1 AnnotationArrayElem (soot.tagkit.AnnotationArrayElem)1 AnnotationDoubleElem (soot.tagkit.AnnotationDoubleElem)1 AnnotationEnumElem (soot.tagkit.AnnotationEnumElem)1 AnnotationFloatElem (soot.tagkit.AnnotationFloatElem)1 AnnotationIntElem (soot.tagkit.AnnotationIntElem)1 AnnotationLongElem (soot.tagkit.AnnotationLongElem)1