Package soot.jimple

Examples of soot.jimple.InvokeExpr


        // insert a (static) call to the (non static)
        // constructor.
        // Later we will come back and inline this after we make all the
        // method static.
        InvokeExpr constructorExpr = constructorStmt.getInvokeExpr();
        Stmt insertStmt = Jimple.v().newInvokeStmt(
                Jimple.v().newStaticInvokeExpr(
                        staticConstructorMethod.makeRef(),
                        constructorExpr.getArgs()));
        clinitUnits.insertBefore(insertStmt, insertPoint);

        // Loop through the class and make all the non-static method static.
        // Make all reference to this into static references.
        ArrayList methodList = new ArrayList(staticClass.getMethods());
View Full Code Here


            Stmt invokeStmt = null;

            // Invoke the method...
            // handling static and void methods differently
            if (oldMethod.getReturnType() == VoidType.v()) {
                InvokeExpr invokeExpr;

                if (newMethod.isStatic()) {
                    invokeExpr = Jimple.v().newStaticInvokeExpr(
                            oldMethod.makeRef(), parameterList);
                } else {
                    Local thisLocal = newBody.getThisLocal();
                    parameterList.remove(thisLocal);
                    invokeExpr = Jimple.v().newVirtualInvokeExpr(thisLocal,
                            oldMethod.makeRef(), parameterList);
                }

                invokeStmt = Jimple.v().newInvokeStmt(invokeExpr);
                units.add(invokeStmt);

                // return void
                units.add(Jimple.v().newReturnVoidStmt());
            } else {
                InvokeExpr invokeExpr;

                // Create a new local for the return value.
                Local returnValueLocal = Jimple.v().newLocal("returnValue",
                        oldMethod.getReturnType());
                newBody.getLocals().add(returnValueLocal);

                if (newMethod.isStatic()) {
                    invokeExpr = Jimple.v().newStaticInvokeExpr(
                            oldMethod.makeRef(), parameterList);
                } else {
                    Local thisLocal = newBody.getThisLocal();
                    parameterList.remove(thisLocal);
                    invokeExpr = Jimple.v().newVirtualInvokeExpr(thisLocal,
                            oldMethod.makeRef(), parameterList);
                }

                invokeStmt = Jimple.v().newAssignStmt(returnValueLocal,
                        invokeExpr);
                units.add(invokeStmt);

                // return the value
                units.add(Jimple.v().newReturnStmt(returnValueLocal));
            }
        }

        // Loop through all the methods again, this time looking for
        // method invocations on the old superClass...  Inline these calls.
        // This code is similar to inlineCallsToMethod, but avoids iterating
        // over all the methods in the class twice, which could get
        // very expensive.
        for (Iterator methods = theClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod newMethod = (SootMethod) methods.next();
            Body newBody = newMethod.retrieveActiveBody();

            // use a snapshotIterator since we are going to be manipulating
            // the statements.
            Iterator j = newBody.getUnits().snapshotIterator();

            while (j.hasNext()) {
                Stmt stmt = (Stmt) j.next();

                System.out.println("stmt = " + stmt);
                Iterator boxes = stmt.getUseAndDefBoxes().iterator();

                while (boxes.hasNext()) {
                    ValueBox box = (ValueBox) boxes.next();
                    Value value = box.getValue();

                    if (value instanceof FieldRef) {
                        // Fix references to fields
                        FieldRef r = (FieldRef) value;
                        SootFieldRef fieldRef = r.getFieldRef();

                        if (r.getField().getDeclaringClass() != superClass
                                && fieldRef.declaringClass() == superClass) {
                            // We might also have a reference to a method
                            // which is not actually declared in the
                            // superclass, in which case, we just fix up
                            // the ref to point to the new super class
                            r.setFieldRef(Scene.v().makeFieldRef(
                                    superClass.getSuperclass(),
                                    fieldRef.name(), fieldRef.type(),
                                    fieldRef.isStatic()));
                        }
                    }
                }
                if (stmt.containsInvokeExpr()) {
                    InvokeExpr invoke = stmt.getInvokeExpr();
                    SootMethodRef invokeMethodRef = invoke.getMethodRef();
                    SootMethod invokeMethod = invoke.getMethod();

                    if (invokeMethod.getDeclaringClass() == superClass) {

                        // Force the body of the thing we are inlining to be
                        // loaded
                        try {
                            if (invokeMethod.isConcrete()) {
                                invokeMethod.retrieveActiveBody();
                            } else {
                                System.out.println("SootUtilities."
                                        + "foldClass() " + invokeMethod
                                        + " is not concrete!");

                                // javac -target 1.2 and greater
                                // ends up causing problems here when
                                // calling super on a method, but the
                                // direct parent does not have a
                                // method by that name.
                                //
                                // If I have 3 classes A, B and C,
                                // where C extends B which extends A
                                // and A and C define a method foo and
                                // C calls super.foo, then under javac
                                // -target 1.2 the constant pool ends
                                // up with a reference to
                                // [2] methodref=soot/coffi/B.foo
                                // and under javac -target 1.1, we end up with
                                // [2] methodref=soot/coffi/A.foo
                                // So, we look for the method in the superclass
                                SootClass scratchClass = invokeMethod
                                        .getDeclaringClass();

                                while (scratchClass.hasSuperclass()) {
                                    SootClass superC = scratchClass
                                            .getSuperclass();

                                    if (superC.declaresMethod(invokeMethod
                                            .getSubSignature())) {
                                        invokeMethod = superC
                                                .getMethod(invokeMethod
                                                        .getSubSignature());
                                        System.out.println("SootUtilties."
                                                + "foldClass() " + "found "
                                                + superC + " " + invokeMethod);
                                        invokeMethod.retrieveActiveBody();
                                        break;
                                    }

                                    scratchClass = superC;
                                }
                            }
                        } catch (Exception ex) {
                            throw new KernelRuntimeException(ex,
                                    "foldClass: Problem with "
                                            + "retrieveActiveBody()");
                        }

                        SiteInliner.inlineSite(invokeMethod, stmt, newMethod);
                    } else if (invokeMethodRef.declaringClass() == superClass) {
                        // We might also have a reference to a method
                        // which is not actually declared in the
                        // superclass, in which case, we just fix up
                        // the ref to point to the new super class
                        invoke.setMethodRef(Scene.v().makeMethodRef(
                                superClass.getSuperclass(),
                                invokeMethodRef.name(),
                                invokeMethodRef.parameterTypes(),
                                invokeMethodRef.returnType(),
                                invokeMethodRef.isStatic()));
View Full Code Here

            while (j.hasNext()) {
                Stmt stmt = (Stmt) j.next();

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

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

        while (j.hasNext()) {
            Stmt stmt = (Stmt) j.next();

            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;
                    }
View Full Code Here

                                .hasNext();) {
                            ValueBox box = (ValueBox) boxes.next();
                            Value value = box.getValue();

                            if (value instanceof InvokeExpr) {
                                InvokeExpr r = (InvokeExpr) value;

                                if (r.getMethod() == iteratorNextMethod) {
                                    box.setValue(Jimple.v()
                                            .newInstanceFieldRef(thisLocal,
                                                    insertField.makeRef()));
                                }
                            }
View Full Code Here

                if (!stmt.containsInvokeExpr()) {
                    continue;
                }

                InvokeExpr r = stmt.getInvokeExpr();

                // This is steve...
                // This is steve gacking at the ugliest code
                // he's written in a while.   See steve gack.
                // gack steve, gack.
                // This is Christopher.
                // This is Christopher gacking on Steve's code
                // gack Christopher, gack.
                // See Christopher come back to this code years later
                // and gack again
                // gack Christopher, gack.
                if (r.getMethod().getName().equals("attributeChanged")
                        || r.getMethod().getName().equals("setExpression")
                        || r.getMethod().getName().equals("setToken")
                        || r.getMethod().getName().equals(
                                "setTokenConsumptionRate")
                        || r.getMethod().getName().equals(
                                "setTokenProductionRate")
                        || r.getMethod().getName().equals(
                                "setTokenInitProduction")
                        || r.getMethod().getName().equals("setVisibility")) {
                    body.getUnits().remove(stmt);
                }

                if (r.getMethod().getSubSignature().equals(
                        PtolemyUtilities.variableConstructorWithToken
                                .getSubSignature())) {
                    SootClass variableClass = r.getMethod().getDeclaringClass();
                    SootMethod constructorWithoutToken = variableClass
                            .getMethod(PtolemyUtilities.variableConstructorWithoutToken
                                    .getSubSignature());

                    // Replace the three-argument
                    // constructor with a two-argument
                    // constructor.  We do this for
                    // several reasons:
                    // 1) The assignment is
                    // redundant...  all parameters
                    // are initialized with the
                    // appropriate value.
                    // 2) The type of the token is
                    // often wrong for polymorphic
                    // actors.
                    // 3) Later on, when we inline all
                    // token constructors, there is no
                    // longer a token to pass to the
                    // constructor.  It is easier to
                    // just deal with it now...
                    // Create a new two-argument constructor.
                    InstanceInvokeExpr expr = (InstanceInvokeExpr) r;
                    stmt.getInvokeExprBox().setValue(
                            Jimple.v().newSpecialInvokeExpr(
                                    (Local) expr.getBase(),
                                    constructorWithoutToken.makeRef(),
                                    r.getArg(0), r.getArg(1)));
                }
            }
        }
    }
View Full Code Here

                    if (!unit.containsInvokeExpr()) {
                        continue;
                    }

                    ValueBox box = unit.getInvokeExprBox();
                    InvokeExpr r = (InvokeExpr) box.getValue();

                    if (r.getMethod().getSubSignature().equals(
                            PtolemyUtilities.invalidateResolvedTypesMethod
                                    .getSubSignature())) {
                        // Remove calls to invalidateResolvedTypes()
                        body.getUnits().remove(unit);
                    }
View Full Code Here

      List<ValueBox> vboxes = unit.getUseAndDefBoxes();
      for(ValueBox vbox : vboxes){
        Value value = vbox.getValue();
        if(value instanceof InvokeExpr == false)
          continue;
        InvokeExpr expr = (InvokeExpr) value;
        SootMethod method = expr.getMethod();
        if(methods.contains(method) == false)
          methods.add(method);
      }
    }
    return methods;
View Full Code Here

      m_output.append("return;\n");
  }
 
  @Override
  public void caseInvokeStmt(InvokeStmt arg0) {
    InvokeExpr expr = arg0.getInvokeExpr();
    if(expr instanceof SpecialInvokeExpr == false){
      super.caseInvokeStmt(arg0);
      return;
    }
    SpecialInvokeExpr sexpr = (SpecialInvokeExpr) expr;
View Full Code Here

                if (sm.isConcrete()) {
                    for (Unit unit : sm.getActiveBody().getUnits()) {
                        Stmt stmt = (Stmt) unit;
                       
                        if (stmt.containsInvokeExpr()) {
                            InvokeExpr expr = stmt.getInvokeExpr();
                            if (expr instanceof SpecialInvokeExpr &&
                                    expr.getMethod().getSignature().equals("<java.net.URL: void <init>(java.lang.String)>") &&
                                    expr.getArg(0) instanceof StringConstant) {
                                Value value = ((SpecialInvokeExpr)expr).getBase();
                                String url = ((StringConstant)expr.getArg(0)).value;
                                url_map.put(value, url);
                            }
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: void bind(java.lang.String,java.lang.String)>")) {
                                String name = getName(expr);
                                RegExp re = getRegExp(expr);
                                regexp_bind.put(name, re);
                            }
                            if (expr.getMethod().getSignature().equals("<dk.brics.string.runtime.Strings: void bind(java.lang.String,java.net.URL)>")) {
                                String name = getName(expr);
                                URL url = getConstantURL(expr.getArg(1));
                                automaton_bind.put(name, getFromURL(url));
                            }
                        }
                    }
                }
View Full Code Here

TOP

Related Classes of soot.jimple.InvokeExpr

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.