Examples of SootClass


Examples of soot.SootClass

                        }

                        Type type = r.getType();

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

                            if (refClass == oldClass) {
                                r.setCastType(RefType.v(newClass));
View Full Code Here

Examples of soot.SootClass

        // First remove most method invocations that are not
        // 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.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);
                    // If any box is removable, then remove the statement.
                    for (Iterator boxes = unit.getUseAndDefBoxes().iterator(); boxes
                            .hasNext();) {
                        ValueBox box = (ValueBox) boxes.next();

                        Value value = box.getValue();
                        Type type = value.getType();

                        if (_isRemovableType(type)) {
                            //  System.out.println("Unit with removable type "
                            //        + type + ": " + unit);
                            body.getUnits().remove(unit);
                            break;
                        }
                    }

                    // If any locals are removable, then remove them.
                    for (Iterator locals = body.getLocals().snapshotIterator(); locals
                            .hasNext();) {
                        Local local = (Local) locals.next();
                        Type type = local.getType();

                        if (_isRemovableType(type)) {
                            body.getLocals().remove(local);
                        }
                    }
                }

                // If any fields are removable, then remove them.
                for (Iterator fields = theClass.getFields().snapshotIterator(); fields
                        .hasNext();) {
                    SootField field = (SootField) fields.next();
                    Type type = field.getType();

                    if (_isRemovableType(type)) {
                        theClass.getFields().remove(field);
                    }
                }

                // If any arguments are removable, then remove the method.
                //   for (Iterator params = method.getParameterTypes().iterator();
                //                      params.hasNext();) {
                //                     Type type = (Type)params.next();
                //                     if (_isRemovableType(type)) {
                //                         System.out.println("removing method with removable parameters = " + method);
                //                         theClass.removeMethod(method);
                //                         break;
                //                     }
                //                 }
            }
        } /*
                              */
        // Remove all the interfaces that it implements??
        for (Iterator i = Scene.v().getApplicationClasses().iterator(); i
                .hasNext();) {
            SootClass theClass = (SootClass) i.next();

            for (Iterator interfaces = theClass.getInterfaces()
                    .snapshotIterator(); interfaces.hasNext();) {
                SootClass theInterface = (SootClass) interfaces.next();

                if (theInterface.equals(PtolemyUtilities.inequalityTermClass)) {
                    theClass.getInterfaces().remove(theInterface);
                }

                if (theInterface
                        .equals(PtolemyUtilities.explicitChangeContextClass)) {
                    theClass.getInterfaces().remove(theInterface);
                }
            }
        }
View Full Code Here

Examples of soot.SootClass

    // code.  This includes Attribute, Settable, Relation, Port, and their
    // subclasses.
    private static boolean _isRemovableType(Type type) {
        if (type instanceof RefType) {
            RefType refType = (RefType) type;
            SootClass refClass = refType.getSootClass();

            if (SootUtilities.derivesFrom(refClass,
                    PtolemyUtilities.attributeClass)
                    || SootUtilities.derivesFrom(refClass,
                            PtolemyUtilities.managerClass)
View Full Code Here

Examples of soot.SootClass

            updateTokenTypes(classList, depth, unsafeLocalSet, debug);

            // Inline all methods on tokens that have the given depth.
            for (Iterator classes = Scene.v().getApplicationClasses()
                    .iterator(); classes.hasNext();) {
                SootClass entityClass = (SootClass) classes.next();

                inlineTokenAndTypeMethods(entityClass, depth, unsafeLocalSet,
                        debug);
            }

            updateTokenTypes(classList, depth, unsafeLocalSet, debug);

            // Create replacement fields for all token fields in the
            // given class with the given depth.
            for (Iterator classes = Scene.v().getApplicationClasses()
                    .iterator(); classes.hasNext();) {
                SootClass entityClass = (SootClass) classes.next();

                createReplacementTokenFields(entityClass, depth,
                        unsafeLocalSet, debug);
            }

            updateTokenTypes(classList, depth, unsafeLocalSet, debug);
            updateTokenTypes(classList, depth, unsafeLocalSet, debug);

            // Replace the locals and fields of the given depth.
            for (Iterator classes = Scene.v().getApplicationClasses()
                    .iterator(); classes.hasNext();) {
                SootClass entityClass = (SootClass) classes.next();

                replaceTokenFields(entityClass, depth, unsafeLocalSet, debug);
            }

            //                         if (depth == 1) {
            //                             break;
            //                         }

            for (Iterator classes = classList.iterator(); classes.hasNext();) {
                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);
View Full Code Here

Examples of soot.SootClass

    public void updateTokenTypes(List classList, int depth, Set unsafeLocalSet,
            boolean debug) {
        System.out.println("updating token types for all classes");

        for (Iterator classes = classList.iterator(); classes.hasNext();) {
            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");

                // We may have locals with the same name.  Rename them.
                LocalNameStandardizer.v().transform(body, _phaseName + ".lns");

                // Assign types to local variables... This types
                // everything that isn't a token type.
                TypeAssigner.v().transform(body, _phaseName + ".ta");

                // Run some cleanup...  this will speedup the rest
                // of the analysis.  And prevent typing errors.
                //     TokenInstanceofEliminator.eliminateCastsAndInstanceOf(
                //                         body, _phaseName + ".tie", unsafeLocalSet,
                //                         true);
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");

                // Run some cleanup...  this will speedup the rest
                // of the analysis.  And prevent typing errors.
                TypeAssigner.v().transform(body, _phaseName + ".ta");

                TokenInstanceofEliminator.eliminateCastsAndInstanceOf(body,
                        _phaseName + ".tie", unsafeLocalSet, debug);

                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");
                UnreachableCodeEliminator.v().transform(body,
                        _phaseName + ".uce");
                CopyPropagator.v().transform(body, _phaseName + ".cp");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                ConditionalBranchFolder.v()
                        .transform(body, _phaseName + ".cbf");
                ConstantPropagatorAndFolder.v().transform(body,
                        _phaseName + ".cpf");
                DeadAssignmentEliminator.v().transform(body,
                        _phaseName + ".dae");
                UnusedLocalEliminator.v().transform(body, _phaseName + ".ule");
                LocalSplitter.v().transform(body, _phaseName + ".ls");
                TypeAssigner.v().transform(body, _phaseName + ".ta");
                TokenInstanceofEliminator.eliminateCastsAndInstanceOf(body,
                        _phaseName + ".cie", Collections.EMPTY_SET, debug);
            }
        }

        System.out.println("Performing TypeSpecializerAnalysis");
        TypeSpecializerAnalysis typeAnalysis = new TypeSpecializerAnalysis(
                classList, unsafeLocalSet);

        //         TokenTypeAnalysis typeAnalysis =
        //             new TokenTypeAnalysis(classList, unsafeLocalSet);
        for (Iterator classes = Scene.v().getApplicationClasses().iterator(); classes
                .hasNext();) {
            SootClass entityClass = (SootClass) classes.next();

            // Specialize the code, according to the analyzed types.
            TypeSpecializer.specializeTypesInMethods(debug, entityClass,
                    unsafeLocalSet, typeAnalysis);
        }
        for (Iterator classes = Scene.v().getApplicationClasses().iterator(); classes
                .hasNext();) {
            SootClass entityClass = (SootClass) classes.next();

            // Specialize the code, according to the analyzed types.
            TypeSpecializer.specializeTypesOfFields(debug, entityClass,
                    unsafeLocalSet, typeAnalysis);
        }
View Full Code Here

Examples of soot.SootClass

            if (methodList.size() == 1) {
                // Then inline its code
                SootMethod inlinee = (SootMethod) methodList.get(0);

                if (inlinee.getName().equals("getClass")) {
                    SootClass typeClass = type.getSootClass();
                    int subclasses = hierarchy.getSubclassesOf(typeClass)
                            .size();

                    if (subclasses == 0) {
                        // FIXME: do something better here.
                        SootMethod newGetClassMethod = Scene.v().getMethod(
                                "<java.lang.Class: java.lang.Class "
                                        + "forName(java.lang.String)>");
                        box.setValue(Jimple.v().newStaticInvokeExpr(
                                newGetClassMethod.makeRef(),
                                StringConstant.v(typeClass.getName())));
                        doneSomething = true;
                    }
                } else if (inlinee.getName().equals("isNil")) {
                    box.setValue(IntConstant.v(0));
                    //                 } else if (inlinee.getSignature().equals(PtolemyUtilities.arrayTokenConstructor.getSignature())) {
                    //                     System.out.println("method = " + method);
                    //                     System.out.println("inlinee = " + inlinee.getSignature());
                    //                     throw new RuntimeException("Cannot inline arrayTokens that do not have a type explicitly specified.");
                } else {
                    SootClass declaringClass = inlinee.getDeclaringClass();

                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        // FIXME: only inline things where we are
                        // also inlining the constructor???
                        if (debug) {
                            System.out.println("inlining " + inlinee);
                        }

                        inlinee.retrieveActiveBody();

                        // Then we know exactly what method will
                        // be called, so inline it.
                        SiteInliner.inlineSite(inlinee, (Stmt) unit, method);
                        doneSomething = true;
                    } else {
                        throw new RuntimeException("inlinee is not concrete!: "
                                + inlinee);
                    }
                }
            } else {
                if (debug) {
                    System.out.println("uninlinable method invocation = " + r);

                    for (Iterator j = methodList.iterator(); j.hasNext();) {
                        System.out.println("method = " + j.next());
                    }
                }
            }
        } else if (value instanceof SpecialInvokeExpr) {
            SpecialInvokeExpr r = (SpecialInvokeExpr) value;

            if (debug) {
                System.out.println("special invoking = " + r.getMethod());
            }

            Type baseType = typeAnalysis.getSpecializedSootType((Local) r
                    .getBase());

            if (baseType instanceof RefType) {
                RefType type = (RefType) baseType;

                boolean isInlineableTokenMethod = SootUtilities.derivesFrom(
                        type.getSootClass(), PtolemyUtilities.tokenClass);

                // If it is a token, then check to
                // make sure that it has the
                // appropriate type
                if (isInlineableTokenMethod) {
                    type = (RefType) typeAnalysis
                            .getSpecializedSootType((Local) r.getBase());

                    if (PtolemyUtilities.getTypeDepth(typeAnalysis
                            .getSpecializedType((Local) r.getBase())) != depth) {
                        if (debug) {
                            System.out
                                    .println("skipping, type depth = "
                                            + PtolemyUtilities
                                                    .getTypeDepth(typeAnalysis
                                                            .getSpecializedType((Local) r
                                                                    .getBase()))
                                            + ", but only inlining depth "
                                            + depth);
                        }

                        return false;

                        //continue;
                    }
                }

                if (isInlineableTokenMethod) {
                    SootMethod inlinee = hierarchy.resolveSpecialDispatch(r,
                            method);
                    SootClass declaringClass = inlinee.getDeclaringClass();

                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        if (debug) {
                            System.out.println("inlining");
                        }

                        inlinee.retrieveActiveBody();

                        // Then we know exactly what method will
                        // be called, so inline it.
                        SiteInliner.inlineSite(inlinee, (Stmt) unit, method);
                        doneSomething = true;
                    } else {
                        if (debug) {
                            System.out.println("removing");
                        }

                        // If we don't have a method,
                        // then remove the invocation.
                        body.getUnits().remove(unit);
                    }
                }
            }
        } else if (value instanceof StaticInvokeExpr) {
            StaticInvokeExpr r = (StaticInvokeExpr) value;

            // Inline typelattice methods.
            if (r.getMethod().getDeclaringClass().equals(
                    PtolemyUtilities.typeLatticeClass)) {
                try {
                    if (debug) {
                        System.out.println("inlining typelattice method = "
                                + unit);
                    }

                    typeAnalysis.inlineTypeLatticeMethods(method, unit, box, r,
                            localDefs, localUses);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    System.out.println("Exception occurred " + ex.getMessage());
                }
            } else {
                if (debug) {
                    System.out.println("static invoking = " + r.getMethod());
                }

                SootMethod inlinee = r.getMethod();
                SootClass declaringClass = inlinee.getDeclaringClass();
                Type returnType = inlinee.getReturnType();

                // These methods contain a large amount of
                // code, which greatly slows down further
                // inlining.  The code should also contain
                // little information, and is hard to get
                // rid of any other way.
                if (_mangleExceptionMessages
                        && (inlinee.getName().equals("notSupportedMessage")
                                || inlinee.getName().equals(
                                        "notSupportedConversionMessage")
                                || inlinee.getName().equals(
                                        "notSupportedIncomparableMessage") || inlinee
                                .getName()
                                .equals(
                                        "notSupportedIncomparableConversionMessage"))) {
                    box.setValue(StringConstant.v("Token Exception"));
                } else if (SootUtilities.derivesFrom(declaringClass,
                        PtolemyUtilities.tokenClass)
                        || ((returnType instanceof RefType) && SootUtilities
                                .derivesFrom(((RefType) returnType)
                                        .getSootClass(),
                                        PtolemyUtilities.tokenClass))) {
                    // Note that we make sure to inline method like
                    // UtilityFunctions.gaussian, which returns a
                    // DoubleMatrixToken.
                    if (!declaringClass.isApplicationClass()) {
                        declaringClass.setLibraryClass();
                    }

                    if (!inlinee.isAbstract() && !inlinee.isNative()) {
                        if (debug) {
                            System.out.println("inlining");
View Full Code Here

Examples of soot.SootClass

                }

                if (isInlineableTypeMethod) {
                    ptolemy.data.type.Type baseTokenType = typeAnalysis
                            .getSpecializedType((Local) r.getBase());
                    SootClass typeClass = Scene.v().loadClassAndSupport(
                            baseTokenType.getClass().getName());

                    // Only instantiable types can be inlined..
                    if (!baseTokenType.isInstantiable()) {
                        return doneSomething;
                    }

                    // Then determine the method that was
                    // actually invoked.
                    List methodList = hierarchy.resolveAbstractDispatch(
                            typeClass, r.getMethod());

                    // If there was only one possible method...
                    if (methodList.size() == 1) {
                        // Then inline its code
                        SootMethod inlinee = (SootMethod) methodList.get(0);

                        if (inlinee.getName().equals("getClass")) {
                            // FIXME: do something better here.
                            SootMethod newGetClassMethod = Scene.v().getMethod(
                                    "<java.lang.Class: java.lang.Class "
                                            + "forName(java.lang.String)>");
                            box.setValue(Jimple.v().newStaticInvokeExpr(
                                    newGetClassMethod.makeRef(),
                                    StringConstant.v("java.lang.Object")));
                        } else if (inlinee.getName().equals("getElementType")) {
                            if (debug) {
                                System.out.println("handling getElementType: "
                                        + unit);
                            }

                            // Handle ArrayType.getElementType specially.
                            if (baseTokenType instanceof ptolemy.data.type.ArrayType) {
                                Local local = PtolemyUtilities
                                        .buildConstantTypeLocal(
                                                body,
                                                unit,
                                                ((ptolemy.data.type.ArrayType) baseTokenType)
                                                        .getElementType());
                                box.setValue(local);
                                doneSomething = true;
                            }
                        } else if (inlinee.getName().equals("equals")) {
                            try {
                                if (debug) {
                                    System.out.println("handling equals: "
                                            + unit);
                                }

                                // Handle Type.equals
                                ptolemy.data.type.Type argumentTokenType =
                                //                                     PtolemyUtilities
                                //                                         .getTypeValue(method, (Local) r
                                //                                                 .getArg(0), unit, localDefs,
                                //                                                 localUses);

                                typeAnalysis.getSpecializedType((Local) r
                                        .getArg(0));
                                System.out.println("baseTokenType = "
                                        + baseTokenType);
                                System.out.println("argumentTokenType = "
                                        + baseTokenType);
                                //    if (baseTokenType.isInstantiable()) {
                                //                                                     continue;
                                //                                                 }
                                if (baseTokenType.equals(argumentTokenType)) {
                                    if (debug) {
                                        System.out
                                                .println("replacing with true: type = "
                                                        + baseTokenType);
                                    }

                                    box.setValue(IntConstant.v(1));
                                    doneSomething = true;
                                } else {
                                    if (debug) {
                                        System.out
                                                .println("replacing with false: type1 = "
                                                        + baseTokenType
                                                        + ", type2 = "
                                                        + argumentTokenType);
                                    }

                                    box.setValue(IntConstant.v(0));
                                    doneSomething = true;
                                }
                            } catch (Exception ex) {
                            }
                        } else {
                            SootClass declaringClass = inlinee
                                    .getDeclaringClass();

                            if (!declaringClass.isApplicationClass()) {
                                declaringClass.setLibraryClass();
                            }

                            if (!inlinee.isAbstract() && !inlinee.isNative()) {
                                // FIXME: only inline things where we are
                                // also inlining the constructor???
View Full Code Here

Examples of soot.SootClass

                continue;
            }

            RefType type = (RefType) PtolemyUtilities
                    .getBaseTokenType(fieldType);
            SootClass fieldClass = type.getSootClass();

            if (!SootUtilities.derivesFrom(fieldClass,
                    PtolemyUtilities.tokenClass)) {
                if (debug) {
                    System.out.println("Skipping field " + field
View Full Code Here

Examples of soot.SootClass

                if (localToFieldToLocal.get(local) != null) {
                    continue;
                }

                RefType type = PtolemyUtilities.getBaseTokenType(localType);
                SootClass localClass = type.getSootClass();

                if (!SootUtilities.derivesFrom(localClass,
                        PtolemyUtilities.tokenClass)) {
                    if (debug) {
                        System.out.println("skipping: not a token.");
View Full Code Here

Examples of soot.SootClass

        if (generateSingleClass) {
            cGenerator.setSingleClassMode();
            hGenerator.setSingleClassMode();
        }

        SootClass sootClass = Scene.v().getSootClass(className);
        CNames.setup();

        // Generate the "interface header" file.
        String code = sGenerator.generate(sootClass);
        FileHandler.write(CNames.sanitize(className)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.