Search in sources :

Example 26 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class TrampolineCompiler method checkMemberAccessible.

private boolean checkMemberAccessible(Function f, Trampoline t, ClassMember member) {
    Clazz caller = config.getClazzes().load(t.getCallingClass());
    Clazz target = config.getClazzes().load(member.getDeclaringClass().getName().replace('.', '/'));
    String runtimeClassName = null;
    runtimeClassName = t instanceof Invokevirtual ? ((Invokevirtual) t).getRuntimeClass() : runtimeClassName;
    runtimeClassName = t instanceof Invokespecial ? ((Invokespecial) t).getRuntimeClass() : runtimeClassName;
    runtimeClassName = t instanceof GetField ? ((GetField) t).getRuntimeClass() : runtimeClassName;
    runtimeClassName = t instanceof PutField ? ((PutField) t).getRuntimeClass() : runtimeClassName;
    SootClass runtimeClass = null;
    if (runtimeClassName != null && !isArray(runtimeClassName)) {
        Clazz c = config.getClazzes().load(runtimeClassName);
        if (c == null) {
            // just return true here.
            return true;
        }
        runtimeClass = c.getSootClass();
    }
    if (Access.checkMemberAccessible(member, caller, target, runtimeClass)) {
        return true;
    }
    if (member instanceof SootMethod) {
        SootMethod method = (SootMethod) member;
        throwIllegalAccessError(f, ILLEGAL_ACCESS_ERROR_METHOD, method.getDeclaringClass(), method.getName(), getDescriptor(method), caller.getSootClass());
    } else {
        SootField field = (SootField) member;
        throwIllegalAccessError(f, ILLEGAL_ACCESS_ERROR_FIELD, field.getDeclaringClass(), field.getName(), caller.getSootClass());
    }
    f.add(new Unreachable());
    return false;
}
Also used : GetField(org.robovm.compiler.trampoline.GetField) Unreachable(org.robovm.compiler.llvm.Unreachable) SootMethod(soot.SootMethod) Clazz(org.robovm.compiler.clazz.Clazz) SootField(soot.SootField) SootClass(soot.SootClass) Invokevirtual(org.robovm.compiler.trampoline.Invokevirtual) Invokespecial(org.robovm.compiler.trampoline.Invokespecial) PutField(org.robovm.compiler.trampoline.PutField)

Example 27 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class ObjCBlockPluginTest method testParseTargetMethodAnnotationsInvalid3.

@Test(expected = CompilerException.class)
public void testParseTargetMethodAnnotationsInvalid3() throws Exception {
    SootMethod m = toSootClass(Runners.class).getMethodByName("runner1");
    ObjCBlockPlugin.parseTargetMethodAnnotations(m, 0, "garbage");
}
Also used : SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 28 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class ObjCBlockPluginTest method testParseTargetMethodAnnotationsInvalid1.

@Test(expected = CompilerException.class)
public void testParseTargetMethodAnnotationsInvalid1() throws Exception {
    SootMethod m = toSootClass(Runners.class).getMethodByName("runner1");
    ObjCBlockPlugin.parseTargetMethodAnnotations(m, 0, "(");
}
Also used : SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 29 with SootMethod

use of soot.SootMethod 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 30 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class MarshalerLookupTest method testFindMarshalerStructMemberUnsupportedArrayDimension.

@Test
public void testFindMarshalerStructMemberUnsupportedArrayDimension() {
    MarshalerLookup lookup = new MarshalerLookup(config).searchBuiltins(false);
    SootMethod getter = toSootClass(TestStruct.class).getMethodByName("getV6");
    SootMethod setter = toSootClass(TestStruct.class).getMethodByName("setV6");
    try {
        lookup.findMarshalerMethod(new MarshalSite(getter)).getMethod();
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
    try {
        lookup.findMarshalerMethod(new MarshalSite(setter, 0)).getMethod();
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) SootMethod(soot.SootMethod) Test(org.junit.Test)

Aggregations

SootMethod (soot.SootMethod)82 Test (org.junit.Test)34 SootClass (soot.SootClass)30 MarshalSite (org.robovm.compiler.MarshalerLookup.MarshalSite)21 PrimType (soot.PrimType)15 RefType (soot.RefType)14 VoidType (soot.VoidType)13 SootMethodType (org.robovm.compiler.util.generic.SootMethodType)11 DoubleType (soot.DoubleType)11 FloatType (soot.FloatType)11 LongType (soot.LongType)11 ArrayList (java.util.ArrayList)9 BooleanType (soot.BooleanType)9 SootField (soot.SootField)8 Type (soot.Type)8 Body (soot.Body)7 RefLikeType (soot.RefLikeType)7 CompilerException (org.robovm.compiler.CompilerException)6 Unit (soot.Unit)6 MethodVisitor (org.objectweb.asm.MethodVisitor)5