Package soot

Examples of soot.SootMethod


    }
   
    private void insertGuard(Guard guard) {
      if(options.guards().equals("ignore")) return;
     
      SootMethod container = guard.container;
      Stmt insertionPoint = guard.stmt;
      if(!container.hasActiveBody()) {
        G.v().out.println("WARNING: Tried to insert guard into "+container+" but couldn't because method has no body.");
      } else {
        Body body = container.getActiveBody();
       
        //exc = new Error
        RefType runtimeExceptionType = RefType.v("java.lang.Error");
        NewExpr newExpr = Jimple.v().newNewExpr(runtimeExceptionType);
        LocalGenerator lg = new LocalGenerator(body);
View Full Code Here


                boolean finalize = true;
                Value fieldValue = null;

                for (Iterator methods = entityClass.getMethods().iterator(); (methods
                        .hasNext() && finalize);) {
                    SootMethod method = (SootMethod) methods.next();

                    if (method.getName().equals("<init>")) {
                        Chain units = method.retrieveActiveBody().getUnits();
                        Stmt stmt = (Stmt) units.getLast();

                        while (!stmt.equals(units.getFirst())) {
                            if (stmt instanceof DefinitionStmt
                                    && ((DefinitionStmt) stmt).getLeftOp() instanceof InstanceFieldRef) {
View Full Code Here

        // Inline calls to token methods that can be statically
        // evaluated.
        for (Iterator methods = actorClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

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

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

            // Add a this local...  note that we might not have one.
            //Local thisLocal;

            try {
View Full Code Here

                entityInstanceClass, constAnalysis);

        // Record everything that the class creates.
        HashMap tempCreatedMap = new HashMap();

        SootMethod initMethod = entityInstanceClass.getInitMethod();

        {
            // Populate the initialization method.
            JimpleBody body = Jimple.v().newBody(initMethod);
            initMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // Populate...
            // Initialize attributes that already exist in the class.
            ModelTransformer.createAttributes(body, entity, thisLocal, entity,
                    thisLocal, entityInstanceClass, tempCreatedMap);

            // Create and initialize ports
            ModelTransformer.createPorts(body, thisLocal, entity, thisLocal,
                    entity, entityInstanceClass, tempCreatedMap);

            // return void
            units.add(Jimple.v().newReturnVoidStmt());
        }

        // Add fields to contain the tokens for each port.
        Map nameToField = new HashMap();
        Map nameToType = new HashMap();

        {
            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());
                String name = port.getName(entity);
                Type type = PtolemyUtilities.tokenType;
                nameToType.put(name, port.getType());

                SootField field = new SootField(StringUtilities
                        .sanitizeName(name)
                        + "Token", type);
                entityInstanceClass.addField(field);
                nameToField.put(name, field);
            }
        }
        // Populate the fire method.
        {
            SootMethod fireMethod = new SootMethod("fire",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(fireMethod);

            JimpleBody body = Jimple.v().newBody(fireMethod);
            fireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Local hasTokenLocal = Jimple.v().newLocal("hasTokenLocal",
                    BooleanType.v());
            body.getLocals().add(hasTokenLocal);

            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());

                // FIXME: Handle multiports
                if (port.getWidth() > 0) {
                    String name = port.getName(entity);

                    // Create an if statement.
                    //
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityInstanceClass
                            .getFieldByName(StringUtilities.sanitizeName(name));
                    units.add(Jimple.v().newAssignStmt(
                            portLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    portField.makeRef())));
                    units.add(Jimple.v().newAssignStmt(
                            hasTokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.hasTokenMethod.makeRef(),
                                    IntConstant.v(0))));

                    Stmt target = Jimple.v().newNopStmt();
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(hasTokenLocal,
                                    IntConstant.v(0)), target));
                    units.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getMethod.makeRef(),
                                    IntConstant.v(0))));

                    SootField tokenField = entityInstanceClass
                            .getFieldByName(name + "Token");
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenField.makeRef()), tokenLocal));
                    units.add(target);
                }
            }

            StringAttribute expressionAttribute = (StringAttribute) entity
                    .getAttribute("expression");
            String expression = expressionAttribute.getExpression();

            Local local = DataUtilities.generateExpressionCode(entity,
                    entityInstanceClass, expression, nameToField, nameToType,
                    body);

            // send the computed token
            String name = "output";
            Local portLocal = Jimple.v().newLocal("port",
                    PtolemyUtilities.componentPortType);
            body.getLocals().add(portLocal);

            SootField portField = entityInstanceClass.getFieldByName(name);

            units.add(Jimple.v().newAssignStmt(
                    portLocal,
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            portField.makeRef())));
            units.add(Jimple.v().newInvokeStmt(
                    Jimple.v().newVirtualInvokeExpr(portLocal,
                            PtolemyUtilities.sendMethod.makeRef(),
                            IntConstant.v(0), local)));

            // return void
            units.add(Jimple.v().newReturnVoidStmt());

            LocalNameStandardizer.v().transform(body, "at.lns");
            LocalSplitter.v().transform(body, "at.ls");
        }

        {
            SootMethod preinitializeMethod = new SootMethod("preinitialize",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(preinitializeMethod);

            JimpleBody body = Jimple.v().newBody(preinitializeMethod);
            preinitializeMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Stmt insertPoint = Jimple.v().newReturnVoidStmt();
            body.getUnits().add(insertPoint);
            ModelTransformer.initializeAttributesBefore(body, insertPoint,
View Full Code Here

                    superClass = newClass.getSuperclass();
                }

                // Remove problematic methods for PortParameter
                if (newClass.declaresMethodByName("setContainer")) {
                    SootMethod method = newClass
                            .getMethodByName("setContainer");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresMethodByName("setName")) {
                    SootMethod method = newClass.getMethodByName("setName");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresMethodByName("attributeChanged")) {
                    SootMethod method = newClass
                            .getMethodByName("attributeChanged");
                    newClass.removeMethod(method);
                }

                if (newClass.declaresFieldByName("_port")) {
View Full Code Here

        }

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

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

            //   System.out.println("newMethod = " + newMethod.getSignature());
            //             Type returnType = newMethod.getReturnType();
            //             if (returnType instanceof RefType &&
            //                     ((RefType)returnType).getSootClass() == oldClass) {
            //                 newMethod.setReturnType(RefType.v(newClass));
            //             }
            //             List paramTypes = new LinkedList();
            //             for (Iterator oldParamTypes =
            //                      newMethod.getParameterTypes().iterator();
            //                  oldParamTypes.hasNext();) {
            //                 Type type = (Type)oldParamTypes.next();
            //                 if (type instanceof RefType &&
            //                         ((RefType)type).getSootClass() == oldClass) {
            //                     paramTypes.add(RefType.v(newClass));
            //                 } else {
            //                     paramTypes.add(type);
            //                 }
            //             }
            //             newMethod.setParameterTypes(paramTypes);
            //             // we have to do this seemingly useless
            //             // thing, since the scene caches a pointer
            //             // to the method based on it's parameter types.
            //             theClass.removeMethod(newMethod);
            //             theClass.addMethod(newMethod);
            Body newBody = newMethod.retrieveActiveBody();

            // Analyze what object each local points to.
            NamedObjAnalysis analysis = new NamedObjAnalysis(newMethod,
                    ModelTransformer.getObjectForClass(theClass));

            for (Iterator locals = newBody.getLocals().iterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();
                Type type = local.getType();

                try {
                    if (type instanceof RefType
                            && (((RefType) type).getSootClass() == oldClass)
                            && (object == analysis.getObject(local))) {
                        local.setType(RefType.v(newClass));
                    }
                } catch (Exception ex) {
                    if (_debug) {
                        System.out.println("Exception on local = " + ex);
                    }
                }
            }

            Iterator j = newBody.getUnits().iterator();

            while (j.hasNext()) {
                Unit unit = (Unit) j.next();

                // System.out.println("unit = " + unit);
                Iterator boxes = unit.getUseBoxes().iterator();

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

                    if (value instanceof InstanceFieldRef) {
                        // Fix references to fields
                        InstanceFieldRef r = (InstanceFieldRef) value;

                        if (object != analysis.getObject((Local) r.getBase())) {
                            //                             System.out.println("object = " + object);
                            //                             System.out.println("analysis object = " + analysis.getObject((Local)r.getBase()));
                            //                             System.out.println("not equal!");
                            continue;
                        }

                        if (SootUtilities.derivesFrom(oldClass, r.getField()
                                .getDeclaringClass())
                                && newClass.declaresFieldByName(r.getField()
                                        .getName())) {
                            r.setFieldRef(newClass.getFieldByName(
                                    r.getField().getName()).makeRef());

                            //   System.out.println("fieldRef = " +
                            //              box.getValue());
                            //       } else if (r.getField().getDeclaringClass().getName()
                            //                                 .startsWith(oldClass.getName())) {
                            //                             SootClass changeClass =
                            //                                 _getInnerClassCopy(oldClass,
                            //                                         r.getField().getDeclaringClass(),
                            //                                         newClass);
                            //                             r.setField(changeClass.getFieldByName(
                            //                                     r.getField().getName()));
                        }
                    } else if (value instanceof CastExpr) {
                        // Fix casts
                        CastExpr r = (CastExpr) value;

                        try {
                            if (object != analysis.getObject((Local) r.getOp())) {
                                continue;
                            }
                        } catch (Exception ex) {
                            if (_debug) {
                                System.out.println("Exception on cast = " + ex);
                            }

                            continue;
                        }

                        Type type = r.getType();

                        if (type instanceof RefType) {
                            SootClass refClass = ((RefType) type)
                                    .getSootClass();

                            if (refClass == oldClass) {
                                r.setCastType(RefType.v(newClass));

                                //    System.out.println("newValue = " +
                                //        box.getValue());
                                //                             } else if (refClass.getName().startsWith(
                                //                                     oldClass.getName())) {
                                //                                 SootClass changeClass =
                                //                                     _getInnerClassCopy(oldClass,
                                //                                             refClass, newClass);
                                //                                 r.setCastType(RefType.v(changeClass));
                            }
                        }

                        //     } else if (value instanceof ThisRef) {
                        //                         // Fix references to 'this'
                        //                         ThisRef r = (ThisRef)value;
                        //                         Type type = r.getType();
                        //                         if (type instanceof RefType &&
                        //                                 ((RefType)type).getSootClass() == oldClass) {
                        //                             box.setValue(Jimple.v().newThisRef(
                        //                                     RefType.v(newClass)));
                        //                         }
                        //                     } else if (value instanceof ParameterRef) {
                        //                         // Fix references to a parameter
                        //                         ParameterRef r = (ParameterRef)value;
                        //                         Type type = r.getType();
                        //                         if (type instanceof RefType &&
                        //                                 ((RefType)type).getSootClass() == oldClass) {
                        //                             box.setValue(Jimple.v().newParameterRef(
                        //                                     RefType.v(newClass), r.getIndex()));
                        //                         }
                    } else if (value instanceof InstanceInvokeExpr) {
                        // Fix up the method invokes.
                        InstanceInvokeExpr r = (InstanceInvokeExpr) value;

                        try {
                            if (object != analysis.getObject((Local) r
                                    .getBase())) {
                                //                                 System.out.println("object = " + object);
                                //                                 System.out.println("analysis object = " + analysis.getObject((Local)r.getBase()));
                                //                                 System.out.println("not equal!");
                                continue;
                            }
                        } catch (Exception ex) {
                            if (_debug) {
                                System.out.println("Exception on invoke = "
                                        + ex);
                            }

                            continue;
                        }

                        if (SootUtilities.derivesFrom(oldClass, r.getMethod()
                                .getDeclaringClass())) {
                            if (newClass.declaresMethod(r.getMethod()
                                    .getSubSignature())) {
                                SootMethod replacementMethod = newClass
                                        .getMethod(r.getMethod()
                                                .getSubSignature());
                                r.setMethodRef(replacementMethod.makeRef());
                            }

                            //                         } else if (r.getMethod().getDeclaringClass().getName().
                            //                                 startsWith(oldClass.getName())) {
                            //                             SootClass changeClass =
View Full Code Here

            NamedObj object, SootClass oldClass, SootClass newClass,
            HashMap oldSignatureToFieldMap) {
        ArrayList methodList = new ArrayList(theClass.getMethods());

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

            Body newBody = newMethod.retrieveActiveBody();
            Iterator j = newBody.getUnits().iterator();

            while (j.hasNext()) {
                Unit unit = (Unit) j.next();
                Iterator boxes = unit.getUseAndDefBoxes().iterator();
View Full Code Here

            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

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

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (unit.containsFieldRef()) {
                        ValueBox box = unit.getFieldRefBox();
                        Value value = box.getValue();

                        if (value instanceof InstanceFieldRef) {
                            InstanceFieldRef fieldRef = (InstanceFieldRef) value;
                            SootField field = fieldRef.getField();

                            // Turn off debugging..
                            if (field.getSubSignature().equals(
                                    PtolemyUtilities.debuggingField
                                            .getSubSignature())) {
                                if (unit instanceof AssignStmt) {
                                    body.getUnits().insertBefore(
                                            Jimple.v().newAssignStmt(
                                                    ((AssignStmt) unit)
                                                            .getLeftOp(),
                                                    IntConstant.v(0)), unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (field.getSubSignature().equals(
                                    PtolemyUtilities.stopRequestedField
                                            .getSubSignature())) {
                                // Assume stops are not requested..
                                if (unit instanceof AssignStmt
                                        && (box == ((AssignStmt) unit)
                                                .getLeftOpBox())) {
                                    body.getUnits().remove(unit);
                                } else {
                                    box.setValue(IntConstant.v(0));
                                }
                            }
                        }
                    } else if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if ((value instanceof InvokeExpr)
                                && !(value instanceof SpecialInvokeExpr)) {
                            // remove attachText
                            InvokeExpr expr = (InvokeExpr) value;

                            if (expr.getMethod().getSubSignature().equals(
                                    PtolemyUtilities.attachTextMethod
                                            .getSubSignature())) {
                                body.getUnits().remove(unit);
                            } else if (expr.getMethod().getSubSignature()
                                    .equals(
                                            PtolemyUtilities.setNameMethod
                                                    .getSubSignature())) {
                                body.getUnits().remove(unit);
                            } else if (expr.getMethod().getName().equals(
                                    "_debug")) {
                                body.getUnits().remove(unit);
                                //                             } else if (expr.getMethod().getName().equals(
                                //                                     "initialize")) {
                                //                                 // Assume no Initializables
                                //                                 body.getUnits().remove(unit);
                                //                             } else if (expr.getMethod().getName().equals(
                                //                                     "preinitialize")) {
                                //                                 // Assume no Initializables
                                //                                 body.getUnits().remove(unit);
                                //                             } else if (expr.getMethod().getName().equals(
                                //                                     "wrapup")) {
                                //                                 // Assume no Initializables
                                //                                 body.getUnits().remove(unit);
                            }

                            // Inline namedObj methods on the
                            // attribute.
                            // FIXME: This should do the
                            // whole traceback business to ensure that
                            // we are calling the methods on the
                            // toplevel object.  This assumes we've
                            // already removed other namedobj methods
                            // on the object objects already.  See
                            // InlineParameterTransformer and
                            // InlinePortTransformer
                            if (expr.getMethod().getSubSignature().equals(
                                    PtolemyUtilities.getFullNameMethod
                                            .getSubSignature())) {
                                if (unit instanceof AssignStmt) {
                                    body.getUnits().insertBefore(
                                            Jimple.v().newAssignStmt(
                                                    ((AssignStmt) unit)
                                                            .getLeftOp(),
                                                    StringConstant.v(_model
                                                            .getFullName())),
                                            unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (expr.getMethod().getSubSignature()
                                    .equals(
                                            PtolemyUtilities.getNameMethod
                                                    .getSubSignature())) {
                                if (unit instanceof AssignStmt) {
                                    body.getUnits().insertBefore(
                                            Jimple.v().newAssignStmt(
                                                    ((AssignStmt) unit)
                                                            .getLeftOp(),
                                                    StringConstant.v(_model
                                                            .getName())), unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (expr.getMethod().getSubSignature()
                                    .equals(
                                            PtolemyUtilities.findEffigyMethod
                                                    .getSubSignature())) {
                                if (unit instanceof AssignStmt) {
                                    body.getUnits().insertBefore(
                                            Jimple.v().newAssignStmt(
                                                    ((AssignStmt) unit)
                                                            .getLeftOp(),
                                                    NullConstant.v()), unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (expr.getMethod().getSubSignature()
                                    .equals(
                                            PtolemyUtilities.getModelURIMethod
                                                    .getSubSignature())) {
                                if (unit instanceof AssignStmt) {
                                    SootClass uriClass = Scene
                                            .v()
                                            .loadClassAndSupport("java.net.URI");
                                    RefType type = RefType.v(uriClass);
                                    SootMethod initMethod = uriClass
                                            .getMethod("void <init>(java.lang.String)");
                                    Local local = (Local) ((AssignStmt) unit)
                                            .getLeftOp();
                                    String uriString = URIAttribute
                                            .getModelURI(_model).toString();
                                    body
                                            .getUnits()
                                            .insertBefore(
                                                    Jimple
                                                            .v()
                                                            .newAssignStmt(
                                                                    local,
                                                                    Jimple
                                                                            .v()
                                                                            .newNewExpr(
                                                                                    type)),
                                                    unit);
                                    body
                                            .getUnits()
                                            .insertBefore(
                                                    Jimple
                                                            .v()
                                                            .newInvokeStmt(
                                                                    Jimple
                                                                            .v()
                                                                            .newSpecialInvokeExpr(
                                                                                    local,
                                                                                    initMethod
                                                                                            .makeRef(),
                                                                                    StringConstant
                                                                                            .v(uriString))),
                                                    unit);
                                }

                                body.getUnits().remove(unit);
                            } else if (expr
                                    .getMethod()
                                    .getSubSignature()
                                    .equals(
                                            PtolemyUtilities.handleModelErrorMethod
                                                    .getSubSignature())) {
                                // Replace handleModelError with a throw clause.
                                body.getUnits()
                                        .insertBefore(
                                                Jimple.v().newThrowStmt(
                                                        expr.getArg(1)), unit);
                                body.getUnits().remove(unit);
                            }
                        }
                    }
                }
            }
        }

        List modifiedConstructorClassList = new LinkedList();

        // Loop over all the classes
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            if (SootUtilities
                    .derivesFrom(theClass, PtolemyUtilities.actorClass)
                    || SootUtilities.derivesFrom(theClass,
                            PtolemyUtilities.compositeActorClass)
                    || SootUtilities.derivesFrom(theClass,
                            PtolemyUtilities.attributeClass)) {
                System.out.println("changing superclass for " + theClass);
                theClass.setSuperclass(PtolemyUtilities.objectClass);

                // Fix the constructor for the actor to take just a
                // container argument, if it was a 2 arg constructor,
                // or no arguments otherwise.  FIXME: Here we assume
                // that there is just one constructor.. This will
                // throw an exception if there is more than one, in
                // which case we need to improve this code.
                SootMethod method = null;

                try {
                    method = theClass.getMethodByName("<init>");
                } catch (RuntimeException ex) {
                    System.out.println("Could not get method <init> by name "
                            + "from class " + theClass);
                    System.out.println("Methods = " + theClass.getMethods());
                    throw ex;
                }

                if (method.getParameterCount() == 2) {
                    // Change the constructor so that it only takes the container.
                    SootField containerField = theClass
                            .getFieldByName(ModelTransformer
                                    .getContainerFieldName());
                    RefType containerType = (RefType) containerField.getType();
                    List typeList = new LinkedList();
                    typeList.add(containerType);
                    method.setParameterTypes(typeList);
                } else {
                    method.setParameterTypes(Collections.EMPTY_LIST);
                }

                // Keep track of the modification, so we know to
                // modify invocations of that constructor.
                modifiedConstructorClassList.add(theClass);

                // Dance so that indexes in the Scene are properly updated.
                theClass.removeMethod(method);
                theClass.addMethod(method);

                System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if (value instanceof SpecialInvokeExpr) {
                            // Fix super.<init> calls. constructor...
                            SpecialInvokeExpr expr = (SpecialInvokeExpr) value;

                            if (expr.getBase().equals(body.getThisLocal())
                                    && expr.getMethodRef().name().equals(
                                            "<init>")) {
                                //             System.out.println("replacing constructor = "
                                //       + unit + " in method " + method);
                                // Replace with zero arg object constructor.
                                box.setValue(Jimple.v().newSpecialInvokeExpr(
                                        (Local) expr.getBase(),
                                        PtolemyUtilities.objectConstructor
                                                .makeRef(),
                                        Collections.EMPTY_LIST));
                            }
                        }
                    } else if (unit instanceof IdentityStmt) {
                        IdentityStmt identityStmt = (IdentityStmt) unit;
                        Value value = identityStmt.getRightOp();

                        if (value instanceof ParameterRef) {
                            ParameterRef parameterRef = (ParameterRef) value;

                            if ((parameterRef.getIndex() == 0)
                                    && (method.getParameterCount() == 1)) {
                                //       System.out.println("found = " + identityStmt);
                                ValueBox box = identityStmt.getRightOpBox();
                                box.setValue(Jimple.v().newParameterRef(
                                        method.getParameterType(0), 0));

                                //    System.out.println("changed to: " + identityStmt);
                            } else {
                                // Parameter values are null.  Note that
                                // we need to make sure that the
                                // assignment to null happens after all
                                // the identity statements, otherwise the
                                // super constructor will be implicitly
                                // called.
                                body.getUnits().remove(identityStmt);
                                body.getUnits().insertBefore(
                                        Jimple.v().newAssignStmt(
                                                identityStmt.getLeftOp(),
                                                NullConstant.v()),
                                        body.getFirstNonIdentityStmt());
                            }
                        } //  else if (value instanceof ThisRef) {

                        //                             // Fix the type of thisRefs.
                        //                             ValueBox box = identityStmt.getRightOpBox();
                        //                             box.setValue(
                        //                                     Jimple.v().newThisRef(
                        //                                             RefType.v(PtolemyUtilities.objectClass)));
                        //                         }
                    }
                }
            }
        }

        // Reset the hierarchy, since we've changed superclasses and such.
        Scene.v().setActiveHierarchy(new Hierarchy());
        Scene.v().setFastHierarchy(new FastHierarchy());

        // Fix the specialInvokes.
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

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

                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    if (unit.containsInvokeExpr()) {
                        ValueBox box = unit.getInvokeExprBox();
                        Value value = box.getValue();

                        if (value instanceof SpecialInvokeExpr) {
                            // If we're constructing one of our actor classes,
                            // then switch to the modified constructor.
                            SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                            SootClass declaringClass = expr.getMethodRef()
                                    .declaringClass();

                            if (expr.getMethodRef().name().equals("<init>")
                                    && modifiedConstructorClassList
                                            .contains(declaringClass)) {
                                System.out
                                        .println("replacing constructor invocation = "
                                                + unit + " in method " + method);
                                SootMethod newConstructor = declaringClass
                                        .getMethodByName("<init>");

                                if (newConstructor.getParameterCount() == 1) {
                                    // Replace with just container arg constructor.
                                    List args = new LinkedList();
                                    args.add(expr.getArg(0));
                                    box.setValue(Jimple.v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    newConstructor.makeRef(),
                                                    args));
                                } else {
                                    // Replace with zero arg constructor.
                                    box.setValue(Jimple.v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    newConstructor.makeRef(),
                                                    Collections.EMPTY_LIST));
                                }
                            }
                        }
                    }
                }
            }
        }

        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

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

                // Infer types.
                LocalSplitter.v().transform(body, "nee.ls");
                TypeAssigner.v().transform(body, "nee.ta");
            }
        }

        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            // Loop through all the methods in the class.
            for (Iterator methods = theClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                // System.out.println("method = " + method);
                JimpleBody body = (JimpleBody) method.retrieveActiveBody();
                for (Iterator units = body.getUnits().snapshotIterator(); units
                        .hasNext();) {
                    Stmt unit = (Stmt) units.next();

                    //        System.out.println("unit = " + unit);
View Full Code Here

                SootClass entityClass = (SootClass) classes.next();

                // This will allow us to get a better type inference below.
                for (Iterator methods = entityClass.getMethods().iterator(); methods
                        .hasNext();) {
                    SootMethod method = (SootMethod) methods.next();

                    if (debug) {
                        System.out.println("method = " + method);
                    }

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

                    LocalSplitter.v().transform(body, _phaseName + ".ls");

                    // We may have locals with the same name.  Rename them.
                    LocalNameStandardizer.v().transform(body,
View Full Code Here

            SootClass entityClass = (SootClass) classes.next();

            // This will allow us to get a better type inference below.
            for (Iterator methods = entityClass.getMethods().iterator(); methods
                    .hasNext();) {
                SootMethod method = (SootMethod) methods.next();

                if (debug) {
                    System.out.println("method = " + method);
                }

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

                // First split local variables that are used in
                // multiple places.
                LocalSplitter.v().transform(body, _phaseName + ".ls");
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.