Package soot

Examples of soot.SootMethod


    /** Generate code for an instance invoke expression.
     *  @param expression The instance invoke expression.
     */
    protected void _generateInstanceInvokeExpression(
            InstanceInvokeExpr expression) {
        SootMethod method = expression.getMethod();
        SootClass declaringClass = method.getDeclaringClass();

        // If the declaring class is an interface extending a method in
        // Object, then the first argument to non-static methods will be
        // the interface, not Object.
        if ((expression instanceof VirtualInvokeExpr)
                && (Scene.v().getSootClass("java.lang.Object")
                        .declaresMethod(method.getSubSignature()))) {
            Type baseType = expression.getBase().getType();

            if (baseType instanceof RefType) {
                declaringClass = ((RefType) baseType).getSootClass();
            }
        }

        StringBuffer code = new StringBuffer();

        expression.getBase().apply(this);

        StringBuffer instanceName = _pop();

        // We're using the class pointer only for abstract methods.
        // We don't do this if the instance is an array.
        code = new StringBuffer(instanceName + "->class->methods."
                + CNames.methodNameOf(method));

        // Default cast is used only if the declaring class does not seem
        // to inherit this method.
        String cast = "(" + CNames.instanceNameOf(declaringClass)
                + "/* default cast */)";

        Iterator inheritedMethods = MethodListGenerator.getInheritedMethods(
                declaringClass).iterator();

        while (inheritedMethods.hasNext()) {
            SootMethod inheritedMethod = (SootMethod) inheritedMethods.next();

            if (inheritedMethod.getSubSignature().equals(
                    method.getSubSignature())) {
                cast = "("
                        + CNames.instanceNameOf(inheritedMethod
                                .getDeclaringClass()) + "/* inherited cast */)";
                break;
            }
        }

View Full Code Here


     *  perform the inlining.
     */
    public void inlineTypeLatticeMethods(SootMethod method, Unit unit,
            ValueBox box, StaticInvokeExpr expr, LocalDefs localDefs,
            LocalUses localUses) {
        SootMethod tokenTokenCompareMethod = PtolemyUtilities.typeLatticeClass
                .getMethod("int compare(ptolemy.data.Token,ptolemy.data.Token)");
        SootMethod tokenTypeCompareMethod = PtolemyUtilities.typeLatticeClass
                .getMethod("int compare(ptolemy.data.Token,ptolemy.data.type.Type)");
        SootMethod typeTokenCompareMethod = PtolemyUtilities.typeLatticeClass
                .getMethod("int compare(ptolemy.data.type.Type,ptolemy.data.Token)");
        SootMethod typeTypeCompareMethod = PtolemyUtilities.typeLatticeClass
                .getMethod("int compare(ptolemy.data.type.Type,ptolemy.data.type.Type)");

        ptolemy.data.type.Type type1;
        ptolemy.data.type.Type type2;

View Full Code Here

     *  accept the given argument list.
     */
    public static SootMethod getMatchingMethod(SootClass theClass, String name,
            List args) {
        boolean found = false;
        SootMethod foundMethod = null;

        Iterator methods = theClass.getMethods().iterator();

        while (methods.hasNext()) {
            SootMethod method = (SootMethod) methods.next();

            //  System.out.println("checking method " + method);
            if (method.getName().equals(name)
                    && (args.size() == method.getParameterCount())) {
                Iterator parameterTypes = method.getParameterTypes().iterator();
                Iterator arguments = args.iterator();
                boolean isEqual = true;

                while (parameterTypes.hasNext()) {
                    Type parameterType = (Type) parameterTypes.next();
View Full Code Here

        return Scene.v().getMethod(buffer.toString());
    }

    public static SootMethod resolveSpecialInvokationForInlining(
            SpecialInvokeExpr expr, SootMethod callingMethod) {
        SootMethod inlinee = Scene.v().getActiveHierarchy()
                .resolveSpecialDispatch(expr, callingMethod);

        // Make sure we can access the body of the method that is
        // being inlined.
        if (!inlinee.getDeclaringClass().isApplicationClass()) {
            inlinee.getDeclaringClass().setLibraryClass();
        }

        inlinee.retrieveActiveBody();
        return inlinee;
    }
View Full Code Here

        return inlinee;
    }

    public static SootMethod resolveVirtualInvokationForInlining(
            SootClass baseClass, SootMethod targetMethod) {
        SootMethod inlinee = null;

        // Now inline the resulting call.
        List methodList = Scene.v().getActiveHierarchy()
                .resolveAbstractDispatch(baseClass, targetMethod);

        if (methodList.size() == 1) {
            // inline the method.
            inlinee = (SootMethod) methodList.get(0);
        } else {
            String string = "Can't resolve " + targetMethod + " on baseClass "
                    + baseClass + "\n";

            for (int i = 0; i < methodList.size(); i++) {
                string += ("target = " + methodList.get(i) + "\n");
            }

            throw new RuntimeException(string);
        }

        // Make sure we can access the body of the method that is
        // being inlined.
        if (!inlinee.getDeclaringClass().isApplicationClass()) {
            inlinee.getDeclaringClass().setLibraryClass();
        }

        inlinee.retrieveActiveBody();
        return inlinee;
    }
View Full Code Here

        // This is required by the inliner.
        inlineMethod.retrieveActiveBody();

        for (Iterator methods = theClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            // System.out.println("method = " + method.getSignature());
            Body body = method.retrieveActiveBody();

            // use a snapshotIterator since we are going to be manipulating
            // the statements.
            Iterator j = body.getUnits().snapshotIterator();
View Full Code Here

            if (stmt.containsInvokeExpr()) {
                InvokeExpr invoke = stmt.getInvokeExpr();

                if (method instanceof StaticInvokeExpr) {
                    // simply inline static methods.
                    SootMethod inlineMethod = invoke.getMethod();

                    // Don't inline a recursive method call.
                    if (inlineMethod.equals(method)) {
                        continue;
                    }

                    SiteInliner.inlineSite(inlineMethod, stmt, method);
                    inlinedAnything = true;
                } else if (!method.isStatic()
                        && invoke instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr instanceInvoke = (InstanceInvokeExpr) invoke;

                    if (instanceInvoke.getBase().equals(body.getThisLocal())) {
                        SootMethod inlineMethod;

                        if (instanceInvoke instanceof VirtualInvokeExpr) {
                            inlineMethod = searchForMethodByName(theClass,
                                    method.getName());
                        } else {
                            // super. method call
                            // don't inline super constructors.
                            if (method.getName().equals("<init>")) {
                                continue;
                            }

                            inlineMethod = searchForMethodByName(theClass
                                    .getSuperclass(), method.getName());
                        }

                        // Don't inline a recursive method call.
                        if (inlineMethod.equals(method)) {
                            continue;
                        }

                        //System.out.println("inlining " + invoke.getMethod());
                        SiteInliner.inlineSite(inlineMethod, stmt, method);
View Full Code Here

        field.setModifiers(field.getModifiers() | Modifier.STATIC);

        ArrayList methodList = new ArrayList(theClass.getMethods());

        for (Iterator methods = methodList.iterator(); methods.hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            // ignore static methods?
            if (method.isStatic()) {
                continue;
            }

            JimpleBody body = (JimpleBody) method.retrieveActiveBody();

            for (Iterator useBoxes = body.getUseAndDefBoxes().iterator(); useBoxes
                    .hasNext();) {
                ValueBox box = (ValueBox) useBoxes.next();
View Full Code Here

                    // Print out what the possible methods are.
                    StringBuffer results = new StringBuffer("Methods are: ");
                    boolean commaNeeded = false;
                    Iterator methods = theClass.getMethods().iterator();
                    while (methods.hasNext()) {
                        SootMethod method = (SootMethod) methods.next();
                        if (commaNeeded) {
                            // Add a comma after the first method
                            results.append(", ");
                        } else {
                            commaNeeded = true;
                        }
                        results.append(method.toString());
                    }
                    throw new RuntimeException("Failed to search \"" + theClass
                            + "\" for \"" + name + "\" possible " + "methods: "
                            + results.toString(), ex);
                }
View Full Code Here

            SootField field, List fieldList) {
        // FIXME: This is currently written using a lot of manually searching
        // of the blocks.  Unfortunately, finding them all is hard.
        // This should really be done using Dava (when it is finished)
        SootClass iteratorClass = Scene.v().getSootClass("java.util.Iterator");
        SootMethod iteratorNextMethod = iteratorClass
                .getMethod("java.lang.Object next()");
        SootMethod iteratorHasNextMethod = iteratorClass
                .getMethod("boolean hasNext()");

        for (Iterator methods = theClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();
            JimpleBody body = (JimpleBody) method.retrieveActiveBody();

            BlockGraph graph = new CompleteBlockGraph(body);

            for (Iterator blocks = graph.iterator(); blocks.hasNext();) {
                Block block = (Block) blocks.next();
View Full Code Here

TOP

Related Classes of soot.SootMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.