Search in sources :

Example 1 with SootMethodType

use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.

the class ObjCBlockPlugin method resolveTargetMethodSignature.

protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) {
    if (targetMethod.getTag("SignatureTag") == null) {
        // Not a generic method.
        Type[] result = new Type[targetMethod.getParameterCount() + 1];
        result[0] = new SootTypeType(targetMethod.getReturnType());
        for (int i = 1; i < result.length; i++) {
            result[i] = new SootTypeType(targetMethod.getParameterType(i - 1));
        }
        return result;
    }
    SootClassType base = new SootClassType(targetMethod.getDeclaringClass());
    TypeVariable<?>[] typeParameters = base.getTypeParameters();
    SootClassType offspring = null;
    Type[] actualArgs = null;
    if (blockParamType instanceof SootClassType) {
        offspring = (SootClassType) blockParamType;
        actualArgs = new Type[0];
    } else if (blockParamType instanceof ParameterizedType) {
        offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType();
        actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments();
    }
    Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs);
    Type[] result = new Type[targetMethod.getParameterCount() + 1];
    SootMethodType targetMethodType = new SootMethodType(targetMethod);
    result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters);
    Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes();
    for (int i = 1; i < result.length; i++) {
        result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters);
    }
    return result;
}
Also used : ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) SootClassType(org.robovm.compiler.util.generic.SootClassType) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) WildcardType(org.robovm.compiler.util.generic.WildcardType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootClassType(org.robovm.compiler.util.generic.SootClassType) ByteType(soot.ByteType) Type(org.robovm.compiler.util.generic.Type) DoubleType(soot.DoubleType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) FloatType(soot.FloatType) IntType(soot.IntType) ImplForType(org.robovm.compiler.util.generic.ImplForType) CharType(soot.CharType) LongType(soot.LongType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) PrimType(soot.PrimType) VoidType(soot.VoidType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) TypeVariable(org.robovm.compiler.util.generic.TypeVariable) SootMethodType(org.robovm.compiler.util.generic.SootMethodType)

Example 2 with SootMethodType

use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.

the class ObjCBlockPlugin method transformMethod.

private void transformMethod(Config config, Clazz clazz, SootMethod blockMethod, int[] blockParamIndexes, Map<String, Integer> blockTypeIds) throws IOException {
    SootMethodType blockMethodType = new SootMethodType(blockMethod);
    if (blockParamIndexes != null) {
        Type[] genericParameterTypes = blockMethodType.getGenericParameterTypes();
        for (int i = 0; i < blockParamIndexes.length; i++) {
            int idx = blockParamIndexes[i];
            if (idx == -1) {
                break;
            }
            SootMethod targetMethod = getBlockTargetMethod(blockMethod, idx);
            Type[] actualGenericTypes = resolveTargetMethodSignature(blockMethod, targetMethod, genericParameterTypes[idx]);
            soot.Type[] actualRawTypes = toRawTypes(actualGenericTypes);
            soot.Type[] unboxedTypes = unboxTypes(actualRawTypes);
            String[][] targetMethodAnnotations = parseTargetMethodAnnotations(targetMethod, readStringElem(getParameterAnnotation(blockMethod, idx, BLOCK), "value", ""));
            // Create the marshaler class associated with this block type
            String marshaler = createBlockMarshaler(config, clazz, targetMethod, actualGenericTypes, actualRawTypes, unboxedTypes, blockTypeIds, targetMethodAnnotations);
            addMarshalerAnnotation(blockMethod, idx, marshaler);
        }
    }
    if (hasAnnotation(blockMethod, BLOCK)) {
        SootMethod targetMethod = getBlockTargetMethod(blockMethod);
        Type[] actualGenericTypes = resolveTargetMethodSignature(blockMethod, targetMethod, blockMethodType.getGenericReturnType());
        soot.Type[] actualRawTypes = toRawTypes(actualGenericTypes);
        soot.Type[] unboxedTypes = unboxTypes(actualRawTypes);
        String[][] targetMethodAnnotations = parseTargetMethodAnnotations(targetMethod, readStringElem(getAnnotation(blockMethod, BLOCK), "value", ""));
        String marshaler = createBlockMarshaler(config, clazz, targetMethod, actualGenericTypes, actualRawTypes, unboxedTypes, blockTypeIds, targetMethodAnnotations);
        addMarshalerAnnotation(blockMethod, marshaler);
    }
}
Also used : RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) WildcardType(org.robovm.compiler.util.generic.WildcardType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootClassType(org.robovm.compiler.util.generic.SootClassType) ByteType(soot.ByteType) Type(org.robovm.compiler.util.generic.Type) DoubleType(soot.DoubleType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) FloatType(soot.FloatType) IntType(soot.IntType) ImplForType(org.robovm.compiler.util.generic.ImplForType) CharType(soot.CharType) LongType(soot.LongType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) PrimType(soot.PrimType) VoidType(soot.VoidType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootMethod(soot.SootMethod)

Example 3 with SootMethodType

use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.

the class ObjCBlockPluginTest method testResolveTargetMethodSignatureGenericWithUnresolvedDirectTypeVariable.

@Test(expected = CompilerException.class)
public void testResolveTargetMethodSignatureGenericWithUnresolvedDirectTypeVariable() throws Exception {
    SootMethod target = toSootClass(F.class).getMethodByName("run");
    SootMethod m = toSootClass(Runners.class).getMethodByName("runner8");
    SootMethodType mType = new SootMethodType(m);
    ObjCBlockPlugin.resolveTargetMethodSignature(m, target, mType.getGenericParameterTypes()[0]);
}
Also used : SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 4 with SootMethodType

use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.

the class ObjCMemberPlugin method createGenericSignatureForMsgSend.

private void createGenericSignatureForMsgSend(SootMethod annotatedMethod, SootMethod m, List<Type> paramTypes, boolean extensions) {
    SignatureTag tag = (SignatureTag) annotatedMethod.getTag(SignatureTag.class.getSimpleName());
    if (tag != null) {
        SootMethodType type = new SootMethodType(annotatedMethod);
        List<String> genericParameterTypes = new ArrayList<>();
        for (org.robovm.compiler.util.generic.Type t : type.getGenericParameterTypes()) {
            genericParameterTypes.add(t.toGenericSignature());
        }
        if (!extensions) {
            /*
                 * For non extensions the generic signature is missing the
                 * receiver as parameter 1.
                 */
            genericParameterTypes.add(0, Types.getDescriptor(paramTypes.get(0)));
        }
        /*
             * Always insert the selector as parameter 2 of the generic
             * signature.
             */
        genericParameterTypes.add(1, Types.getDescriptor(paramTypes.get(1)));
        StringBuilder sb = new StringBuilder("(");
        sb.append(StringUtils.join(genericParameterTypes, ""));
        sb.append(")");
        sb.append(type.getGenericReturnType().toGenericSignature());
        m.addTag(new SignatureTag(sb.toString()));
    }
}
Also used : SootMethodType(org.robovm.compiler.util.generic.SootMethodType) ArrayList(java.util.ArrayList) SignatureTag(soot.tagkit.SignatureTag)

Example 5 with SootMethodType

use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.

the class ObjCBlockPluginTest method signatureToType.

private Type signatureToType(String desc) {
    String rawDesc = desc.replaceAll("<.*>", "");
    String internalName = rawDesc.replaceAll("^\\[*", "");
    int dims = rawDesc.length() - internalName.length();
    internalName = Types.getInternalNameFromDescriptor(internalName);
    soot.Type sootType = SootResolver.v().makeClassRef(internalName.replace('/', '.')).getType();
    for (int i = 0; i < dims; i++) {
        sootType = sootType.makeArrayType();
    }
    SootMethod m = new SootMethod("foo", Arrays.asList(sootType), VoidType.v());
    m.addTag(new SignatureTag("(" + desc + ")V"));
    SootMethodType mType = new SootMethodType(m);
    return mType.getGenericParameterTypes()[0];
}
Also used : SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootMethod(soot.SootMethod) SignatureTag(soot.tagkit.SignatureTag)

Aggregations

SootMethodType (org.robovm.compiler.util.generic.SootMethodType)7 SootMethod (soot.SootMethod)5 SootClassType (org.robovm.compiler.util.generic.SootClassType)3 SootTypeType (org.robovm.compiler.util.generic.SootTypeType)3 Type (org.robovm.compiler.util.generic.Type)3 BooleanType (soot.BooleanType)3 VoidType (soot.VoidType)3 Test (org.junit.Test)2 GenericArrayType (org.robovm.compiler.util.generic.GenericArrayType)2 ImplForType (org.robovm.compiler.util.generic.ImplForType)2 ParameterizedType (org.robovm.compiler.util.generic.ParameterizedType)2 WildcardType (org.robovm.compiler.util.generic.WildcardType)2 ByteType (soot.ByteType)2 CharType (soot.CharType)2 DoubleType (soot.DoubleType)2 FloatType (soot.FloatType)2 IntType (soot.IntType)2 LongType (soot.LongType)2 PrimType (soot.PrimType)2 RefType (soot.RefType)2