Search in sources :

Example 36 with SootClass

use of soot.SootClass in project robovm by robovm.

the class MarshalerLookup method findMarshalersOnOuterClasses.

private void findMarshalersOnOuterClasses(SootClass sc, List<Marshaler> result, Set<String> visited, Set<String> seen) {
    SootClass outer = getOuterClass(sc);
    if (outer != null) {
        findMarshalersOnClasses(outer, result, visited, seen);
        findMarshalersOnInterfaces(outer, result, visited, seen);
        findMarshalersOnOuterClasses(outer, result, visited, seen);
    }
}
Also used : SootClass(soot.SootClass)

Example 37 with SootClass

use of soot.SootClass in project robovm by robovm.

the class ObjCMemberPlugin method findOverriddenMethods.

private List<SootMethod> findOverriddenMethods(SootClass sootClass, SootMethod method) {
    SootClass supercls = sootClass.getSuperclass();
    while (!supercls.getType().equals(org_robovm_objc_ObjCObject.getType())) {
        try {
            SootMethod m = supercls.getMethod(method.getName(), method.getParameterTypes(), method.getReturnType());
            if (overrides(method, m) && !hasAnnotation(m, NOT_IMPLEMENTED)) {
                return Collections.singletonList(m);
            }
        } catch (RuntimeException e) {
        // Soot throws RuntimeException if method not found
        }
        supercls = supercls.getSuperclass();
    }
    /*
         * Method doesn't override any method in superclasses. Check interfaces
         * as well. There may be several methods in interfaces which this method
         * overrides. We have to return all of them as we cannot assume that
         * first one found has the @Method or @Property annotation.
         */
    List<SootMethod> candidates = new ArrayList<>();
    findOverriddenMethodsOnInterfaces(sootClass, method, candidates);
    return candidates;
}
Also used : ArrayList(java.util.ArrayList) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 38 with SootClass

use of soot.SootClass in project robovm by robovm.

the class TypeEncoder method getStructMembers.

private List<Member> getStructMembers(SootClass clazz, boolean is64bit) {
    List<Member> members = new ArrayList<>();
    if (clazz.hasSuperclass()) {
        SootClass superclass = clazz.getSuperclass();
        if (!superclass.getName().equals("org.robovm.rt.bro.Struct")) {
            members.addAll(getStructMembers(clazz, is64bit));
        }
    }
    for (SootMethod method : clazz.getMethods()) {
        int offset = getStructMemberOffset(method);
        if (offset != -1) {
            if (!method.isNative() && !method.isStatic()) {
                // thrown by the ClassCompiler later on.
                continue;
            }
            Type type;
            int idx;
            if (method.getParameterCount() == 0) {
                type = method.getReturnType();
                idx = -1;
            } else if (method.getParameterCount() == 1) {
                type = method.getParameterType(0);
                idx = 0;
            } else {
                // throw by the ClassCompiler later on.
                continue;
            }
            Member member = new Member();
            member.offset = offset;
            member.type = encodeOne(method, type, idx, is64bit);
            members.add(member);
        }
    }
    return members;
}
Also used : RefType(soot.RefType) Type(soot.Type) PrimType(soot.PrimType) VoidType(soot.VoidType) ArrayList(java.util.ArrayList) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 39 with SootClass

use of soot.SootClass in project robovm by robovm.

the class VTableTest method testB.

@Test
public void testB() {
    SootClass scJLO = getSootClass("java.lang.Object");
    SootClass scA = getSootClass("org.robovm.compiler.a.A");
    SootClass scB = getSootClass("org.robovm.compiler.b.B");
    VTable.Cache cache = new VTable.Cache();
    VTable vtableJLO = cache.get(scJLO);
    VTable vtableA = cache.get(scA);
    VTable vtableB = cache.get(scB);
    assertEquals(16, vtableB.size());
    Entry toStringEntry = vtableB.findEntry("toString", "()Ljava/lang/String;");
    assertEquals(scA.getName(), toStringEntry.getDeclaringClass());
    Entry superToStringEntry = vtableA.findEntry("toString", "()Ljava/lang/String;");
    assertSame(toStringEntry, superToStringEntry);
    Entry equalsEntry = vtableB.findEntry("equals", "(Ljava/lang/Object;)Z");
    assertEquals(scA.getName(), equalsEntry.getDeclaringClass());
    Entry superEqualsEntry = vtableA.findEntry("equals", "(Ljava/lang/Object;)Z");
    assertSame(superEqualsEntry, equalsEntry);
    Entry cloneEntry = vtableB.findEntry("clone", "()Ljava/lang/Object;");
    assertEquals(scJLO.getName(), cloneEntry.getDeclaringClass());
    Entry superCloneEntry = vtableJLO.findEntry("clone", "()Ljava/lang/Object;");
    assertSame(superCloneEntry, cloneEntry);
    Entry fooInAEntry = vtableB.findEntry("org.robovm.compiler.a", "foo", "()V");
    assertEquals(scA.getName(), fooInAEntry.getDeclaringClass());
    assertEquals(11, fooInAEntry.getIndex());
    Entry fooInBEntry = vtableB.findEntry("org.robovm.compiler.b", "foo", "()V");
    assertEquals(scB.getName(), fooInBEntry.getDeclaringClass());
    assertEquals(14, fooInBEntry.getIndex());
    assertNotSame(fooInAEntry, fooInBEntry);
    Entry fooIVEntry = vtableB.findEntry("foo", "(I)V");
    assertEquals(scB.getName(), fooIVEntry.getDeclaringClass());
    Entry superFooIVEntry = vtableA.findEntry("foo", "(I)V");
    assertEquals(superFooIVEntry.getIndex(), fooIVEntry.getIndex());
    assertNotSame(superFooIVEntry, fooIVEntry);
    Entry barInAEntry = vtableB.findEntry("org.robovm.compiler.a", "bar", "()V");
    assertEquals(scA.getName(), barInAEntry.getDeclaringClass());
    assertEquals(12, barInAEntry.getIndex());
    Entry barInBEntry = vtableB.findEntry("org.robovm.compiler.b", "bar", "()V");
    assertEquals(scB.getName(), barInBEntry.getDeclaringClass());
    assertEquals(15, barInBEntry.getIndex());
    assertNotSame(barInAEntry, barInBEntry);
}
Also used : Entry(org.robovm.compiler.VTable.Entry) SootClass(soot.SootClass) Test(org.junit.Test)

Example 40 with SootClass

use of soot.SootClass in project robovm by robovm.

the class VTableTest method testD.

@Test
public void testD() {
    SootClass scA = getSootClass("org.robovm.compiler.a.A");
    SootClass scB = getSootClass("org.robovm.compiler.b.B");
    SootClass scD = getSootClass("org.robovm.compiler.b.D");
    VTable.Cache cache = new VTable.Cache();
    VTable vtableB = cache.get(scB);
    VTable vtableD = cache.get(scD);
    assertEquals(vtableB.size(), vtableD.size());
    Entry barInAEntry = vtableD.findEntry("org.robovm.compiler.a", "bar", "()V");
    assertEquals(scA.getName(), barInAEntry.getDeclaringClass());
    assertEquals(12, barInAEntry.getIndex());
    Entry barInDEntry = vtableD.findEntry("org.robovm.compiler.b", "bar", "()V");
    assertEquals(scD.getName(), barInDEntry.getDeclaringClass());
    assertEquals(15, barInDEntry.getIndex());
    assertNotSame(barInAEntry, barInDEntry);
    Entry barInBEntry = vtableD.findEntry("org.robovm.compiler.b", "bar", "()V");
    assertSame(barInBEntry, barInDEntry);
}
Also used : Entry(org.robovm.compiler.VTable.Entry) SootClass(soot.SootClass) Test(org.junit.Test)

Aggregations

SootClass (soot.SootClass)48 SootMethod (soot.SootMethod)30 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 PrimType (soot.PrimType)9 RefType (soot.RefType)8 SootField (soot.SootField)7 HashSet (java.util.HashSet)6 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)4 Global (org.robovm.compiler.llvm.Global)4 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)4 Type (org.robovm.compiler.llvm.Type)4 File (java.io.File)3 CompilerException (org.robovm.compiler.CompilerException)3 Entry (org.robovm.compiler.VTable.Entry)3 ArrayType (org.robovm.compiler.llvm.ArrayType)3 NullConstant (org.robovm.compiler.llvm.NullConstant)3 PointerType (org.robovm.compiler.llvm.PointerType)3 StructureConstant (org.robovm.compiler.llvm.StructureConstant)3 StructureConstantBuilder (org.robovm.compiler.llvm.StructureConstantBuilder)3