Search in sources :

Example 1 with Method

use of dk.brics.soot.intermediate.representation.Method in project soot by Sable.

the class JavaTranslator method makeMethods.

void makeMethods() {
    Collection<SootClass> app = Scene.v().getApplicationClasses();
    for (SootClass ac : app) {
        List<SootMethod> sootMethods = ac.getMethods();
        for (SootMethod sm : sootMethods) {
            List<Variable> vars = new LinkedList<Variable>();
            List<Type> params = sm.getParameterTypes();
            for (Type pt : params) {
                Variable v = makeVariable(pt);
                vars.add(v);
            }
            Variable[] var_array = (Variable[]) vars.toArray(new Variable[0]);
            Method m = new Method(sm.getName(), var_array);
            methods.add(m);
            methodsignaturToMethod.put(sm.getSignature(), m);
        }
    }
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType) Type(soot.Type) Variable(dk.brics.soot.intermediate.representation.Variable) SootMethod(soot.SootMethod) Method(dk.brics.soot.intermediate.representation.Method) SootMethod(soot.SootMethod) SootClass(soot.SootClass) LinkedList(java.util.LinkedList)

Example 2 with Method

use of dk.brics.soot.intermediate.representation.Method in project soot by Sable.

the class ExprTranslator method handleSpecialCall.

// any type
boolean handleSpecialCall(InstanceInvokeExpr expr, SootMethod target) {
    String mn = target.getName();
    int np = target.getParameterCount();
    SootClass dc = target.getDeclaringClass();
    // Is it a method in a Foo object?
    if (isFoo(dc)) {
        if (mn.equals("foo") && np == 1) {
            Variable lvar = new Variable(Variable.Type.FOO);
            Method foo = new Method("foo", new Variable[0]);
            FooMethodCall fmc = new FooMethodCall(foo);
            fmc.setAssignmentTarget(lvar);
            st.addStatement(fmc);
            return true;
        }
        // Unknown Foo method
        return false;
    }
    // Not a special call
    return false;
}
Also used : Variable(dk.brics.soot.intermediate.representation.Variable) FooMethodCall(dk.brics.soot.intermediate.representation.FooMethodCall) SootMethod(soot.SootMethod) Method(dk.brics.soot.intermediate.representation.Method) SootClass(soot.SootClass)

Example 3 with Method

use of dk.brics.soot.intermediate.representation.Method in project soot by Sable.

the class ExprTranslator method handleCall.

// For a single target, foo-type or not, non-special
void handleCall(InvokeExpr expr, SootMethod target) {
    SootClass dc = target.getDeclaringClass();
    if (jt.isApplicationClass(dc)) {
        if (!dc.isInterface()) {
            // Target in an application class.
            // Setup call to translated method.
            Method method = jt.methodsignaturToMethod.get(target.getSignature());
            SomeMethodCall smc = new SomeMethodCall(method, getArgs(target));
            st.addStatement(smc);
        } else {
            // Call to interface method or abstract method as target.
            // Only occurs if no implementions are found.
            // Arguments are evaluated and nothing is returned.
            jt.notSupported("We don't support interface calls");
        }
    } else {
        // Target in non-application class.
        // We should Escape all arguments and corrupt result.
        // So this might not be what we want.
        Method method = new Method(target.getName(), getArgs(target));
        SomeMethodCall smc = new SomeMethodCall(method, getArgs(target));
        st.addStatement(smc);
        return;
    }
}
Also used : SootMethod(soot.SootMethod) Method(dk.brics.soot.intermediate.representation.Method) SomeMethodCall(dk.brics.soot.intermediate.representation.SomeMethodCall) SootClass(soot.SootClass)

Example 4 with Method

use of dk.brics.soot.intermediate.representation.Method in project soot by Sable.

the class JavaTranslator method translate.

private void translate() {
    st = new StmtTranslator(this);
    Collection<SootClass> app = Scene.v().getApplicationClasses();
    for (SootClass ac : app) {
        st.setCurrentClass(ac);
        List<SootMethod> sootMethods = ac.getMethods();
        for (SootMethod sm : sootMethods) {
            if (sm.isConcrete()) {
                Method method = methodsignaturToMethod.get(sm.getSignature());
                st.setCurrentMethod(sm);
                CompleteUnitGraph cug = new CompleteUnitGraph(sm.retrieveActiveBody());
                Iterator si = cug.iterator();
                while (si.hasNext()) {
                    Stmt stmt = (Stmt) si.next();
                    st.translateStmt(stmt);
                }
                // System.err.println("Setting up link between entry and first stmt of the method...");
                si = cug.getHeads().iterator();
                while (si.hasNext()) {
                    Stmt stmt = (Stmt) si.next();
                    method.getEntry().addSucc(st.getFirst(stmt));
                }
                si = cug.iterator();
                // System.err.println("Setting up link between the last statement and the first statement...");
                while (si.hasNext()) {
                    Stmt stmt = (Stmt) si.next();
                    Iterator si2 = cug.getSuccsOf(stmt).iterator();
                    while (si2.hasNext()) {
                        Stmt stmt2 = (Stmt) si2.next();
                        st.getLast(stmt).addSucc(st.getFirst(stmt2));
                    }
                }
            // System.err.println("!!!!!!!!!!!!!!!!!!"+sm.getName()+"!!!!!!!!!!!!!!!!!!!!");
            // si = cug.iterator();
            // while (si.hasNext()) {
            // Stmt stmt = (Stmt)si.next();
            // System.err.println("The stmt: "+stmt+" translates to "+st.getFirst(stmt));
            // //System.err.println(st.getFirst(stmt).getSuccs());
            // }
            // System.err.println("######################################");
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) SootMethod(soot.SootMethod) CompleteUnitGraph(soot.toolkits.graph.CompleteUnitGraph) Method(dk.brics.soot.intermediate.representation.Method) SootMethod(soot.SootMethod) SootClass(soot.SootClass) Stmt(soot.jimple.Stmt)

Aggregations

Method (dk.brics.soot.intermediate.representation.Method)4 SootClass (soot.SootClass)4 SootMethod (soot.SootMethod)4 Variable (dk.brics.soot.intermediate.representation.Variable)2 FooMethodCall (dk.brics.soot.intermediate.representation.FooMethodCall)1 SomeMethodCall (dk.brics.soot.intermediate.representation.SomeMethodCall)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 ArrayType (soot.ArrayType)1 RefType (soot.RefType)1 Type (soot.Type)1 Stmt (soot.jimple.Stmt)1 CompleteUnitGraph (soot.toolkits.graph.CompleteUnitGraph)1