Package soot.jimple

Examples of soot.jimple.SpecialInvokeExpr


        AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr);
        body.getUnits().insertBefore(assignStmt, insertionPoint);
       
        //exc.<init>(message)
        SootMethodRef cref = runtimeExceptionType.getSootClass().getMethod("<init>", Collections.singletonList(RefType.v("java.lang.String"))).makeRef();
        SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message));
        InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr);
        body.getUnits().insertAfter(initStmt, assignStmt);
       
        if(options.guards().equals("print")) {
          //exc.printStackTrace();
View Full Code Here


      AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr);
      body.getUnits().add(assignStmt);
     
      //exc.<init>(message)
      SootMethodRef cref = runtimeExceptionType.getSootClass().getMethod("<init>", Collections.singletonList(RefType.v("java.lang.String"))).makeRef();
      SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v("Unresolved compilation error: Method "+getSignature()+" does not exist!"));
      InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr);
      body.getUnits().insertAfter(initStmt, assignStmt);
     
      //throw exc
      body.getUnits().insertAfter(Jimple.v().newThrowStmt(exceptionLocal), initStmt);
View Full Code Here

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

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

                ValueBox box = stmt.getInvokeExprBox();
                Value value = box.getValue();

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

                    if (PtolemyUtilities.executableInterface.declaresMethod(r
                            .getMethod().getSubSignature())) {
                        boolean isNonVoidMethod = r.getMethod().getName()
                                .equals("prefire")
                                || r.getMethod().getName().equals("postfire");

                        if (isNonVoidMethod && stmt instanceof AssignStmt) {
                            box.setValue(IntConstant.v(1));
                        } else {
                            System.out.println("mt: executable: removing "
                                    + stmt);
                            body.getUnits().remove(stmt);
                        }
                    }
                    if (PtolemyUtilities.initializableInterface
                            .declaresMethod(r.getMethod().getSubSignature())) {
                        System.out.println("mt: initializable: removing "
                                + stmt);
                        body.getUnits().remove(stmt);
                    }
                }
View Full Code Here

        if (stmt instanceof InvokeStmt) {
            Value expr = ((InvokeStmt) stmt).getInvokeExpr();

            if (expr instanceof SpecialInvokeExpr) {
                SpecialInvokeExpr r = (SpecialInvokeExpr) expr;
                //String methodName = r.getMethod().getName();

                Type type = r.getBase().getType();

                //   System.out.println("baseType = " + type);
                //  System.out.println("methodName = " + methodName);
                if (type instanceof NullType) {
                    // Note: The control path that causes this to be
                    // null should never occur in practice.
                    return;
                }

                SootClass baseClass = ((RefType) type).getSootClass();

                // FIXME: match better.
                // If we are invoking a method on a token, then...
                if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.tokenClass)) {
                    if (r.getMethod().equals(
                            PtolemyUtilities.arrayTokenConstructor)) {
                        // The arrayToken constructor depends on the type
                        // of its constructor argument.
                        //     System.out.println("found array invoke: " + r);
                        //     System.out.println("Argument type is : " + in.get(r.getArg(0)));
                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if (argType == null) {
                            argType = BaseType.UNKNOWN;
                        }

                        out.put(r.getBase(), new ArrayType(argType));
                    } else if (r.getMethod().equals(
                            PtolemyUtilities.arrayTokenWithTypeConstructor)) {
                        // The arrayToken constructor depends on the type
                        // of its constructor argument.
                        //     System.out.println("found array invoke: " + r);
                        //     System.out.println("Argument type is : " + in.get(r.getArg(0)));

                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if (argType == null) {
                            argType = BaseType.UNKNOWN;
                        }

                        out.put(r.getBase(), new ArrayType(argType));
                    }
                }
            }
        } else if (stmt instanceof AssignStmt) {
            Value leftOp = ((AssignStmt) stmt).getLeftOp();

            if (!_isTokenType(leftOp.getType())) {
                //     System.out.println("type " + leftOp.getType()
                //             + " is not a token");
                return;
            }

            //  System.out.println("from " + in);
            Value rightOp = ((AssignStmt) stmt).getRightOp();

            if (rightOp instanceof StaticInvokeExpr) {
                StaticInvokeExpr r = (StaticInvokeExpr) rightOp;

                if (r.getMethod().equals(PtolemyUtilities.arraycopyMethod)) {
                    out.put(r.getArg(0), in.get(r.getArg(2)));
                }
            } else if (rightOp instanceof InstanceInvokeExpr
                    || rightOp instanceof InterfaceInvokeExpr) {
                InstanceInvokeExpr r = (InstanceInvokeExpr) rightOp;
                String methodName = r.getMethod().getName();

                Type type = r.getBase().getType();

                //   System.out.println("baseType = " + type);
                //  System.out.println("methodName = " + methodName);
                if (type instanceof NullType) {
                    // Note: The control path that causes this to be
                    // null should never occur in practice.
                    return;
                }

                SootClass baseClass = ((RefType) type).getSootClass();

                // FIXME: match better.
                // If we are invoking a method on a token, then...
                if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.tokenClass)) {
                    if (methodName.equals("one") || methodName.equals("zero")
                            || methodName.equals("not")
                            || methodName.equals("bitwiseNot")
                            || methodName.equals("leftShift")
                            || methodName.equals("rightShift")
                            || methodName.equals("logicalRightShift")
                            || methodName.equals("pow")) {
                        // The returned type must be equal to the type
                        // we are calling the method on.
                        _updateTypeInAssignment(leftOp, in.get(r.getBase()),
                                out);
                    } else if (methodName.equals("add")
                            || methodName.equals("addReverse")
                            || methodName.equals("subtract")
                            || methodName.equals("subtractReverse")
                            || methodName.equals("multiply")
                            || methodName.equals("multiplyReverse")
                            || methodName.equals("divide")
                            || methodName.equals("divideReverse")
                            || methodName.equals("modulo")
                            || methodName.equals("moduloReverse")
                            || methodName.equals("bitwiseAnd")
                            || methodName.equals("bitwiseOr")
                            || methodName.equals("bitwiseXor")) {
                        //                         System.out.println("methodName = " + methodName);
                        //                         System.out.println("r.getBase() = " + r.getBase());
                        //                         System.out.println("r.getArg(0) = " + r.getArg(0));
                        //                         System.out.println("type(r.getBase()) = " + in.get(r.getBase()));
                        //                         System.out.println("type(r.getArg(0)) = " + in.get(r.getArg(0)));
                        ptolemy.data.type.Type baseType = (ptolemy.data.type.Type) in
                                .get(r.getBase());
                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if ((baseType == null) || (argType == null)) {
                            out.put(leftOp, null);
                        } else {
                            _updateTypeInAssignment(leftOp, TypeLattice
                                    .lattice().leastUpperBound(baseType,
                                            argType), out);
                        }
                    } else if (methodName.equals("convert")) {
                        // The return rightOp type is equal to the base type.
                        // The first argument type is less than or equal to the base type.
                        _updateTypeInAssignment(leftOp, in.get(r.getBase()),
                                out);
                    } else if (methodName.equals("getElement")
                            || methodName.equals("arrayValue")) {
                        ptolemy.data.type.Type arrayType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if ((arrayType != null)
                                && arrayType instanceof ArrayType) {
                            _updateTypeInAssignment(leftOp,
                                    ((ArrayType) arrayType).getElementType(),
                                    out);
                        }
                    } else if (methodName.equals("getElementAsToken")) {
                        ptolemy.data.type.Type matrixType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if ((matrixType != null)
                                && matrixType instanceof MatrixType) {
                            _updateTypeInAssignment(leftOp,
                                    ((MatrixType) matrixType).getElementType(),
                                    out);
                        }
                    } else if (methodName.equals("absolute")) {
                        // Return the same as the input type, unless complex,
                        // in which case, return double.
                        ptolemy.data.type.Type inType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if (inType.equals(BaseType.COMPLEX)) {
                            _updateTypeInAssignment(leftOp, BaseType.DOUBLE,
                                    out);
                        } else {
                            _updateTypeInAssignment(leftOp, inType, out);
                        }
                    }
                } else if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.componentPortClass)) {
                    // If we are invoking a method on a port.
                    TypedIOPort port = (TypedIOPort) _namedObjAnalysis
                            .getObject((Local) r.getBase());

                    //System.out.println("port for " + r.getBase() + " = " + port);
                    if (methodName.equals("broadcast")) {
                        // The type of the argument must be less than the
                        // type of the port.
                    } else if (methodName.equals("get")) {
                        // The port here may be null if the model does not
                        // actually contain the port...  This happens, for
                        // instance, in MathFunction
                        if (port != null) {
                            _updateTypeInAssignment(leftOp, port.getType(), out);
                        }
                    } else if (methodName.equals("send")) {
                        if (r.getArgCount() == 3) {
                            // The type of the argument must be less than the
                            // type of the port.
                            //r.getArg(1));
                        } else if (r.getArgCount() == 2) {
                            // The type of the argument must be less than the
                            // type of the port.
                            //            r.getArg(1));
                        }
                    }
                } else if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.attributeClass)) {
                    // If we are invoking a method on a parameter.
                    Attribute attribute = (Attribute) _namedObjAnalysis
                            .getObject((Local) r.getBase());

                    if (attribute == null) {
                        // A method invocation with a null base is bogus,
                        // so don't create a type constraint.
                    }
View Full Code Here

                    if (pair.getUnit() instanceof InvokeStmt) {
                        InvokeStmt useStmt = (InvokeStmt) pair.getUnit();

                        if (useStmt.getInvokeExpr() instanceof SpecialInvokeExpr) {
                            SpecialInvokeExpr constructorExpr = (SpecialInvokeExpr) useStmt
                                    .getInvokeExpr();

                            if (constructorExpr
                                    .getMethod()
                                    .getSignature()
                                    .equals(
                                            "<ptolemy.data.type.ArrayType: void <init>(ptolemy.data.type.Type)>")) {
                                Local arg1Local = (Local) constructorExpr
                                        .getArg(0);
                                ptolemy.data.type.Type elementType = getTypeValue(
                                        method, arg1Local, useStmt, localDefs,
                                        localUses);
                                return new ptolemy.data.type.ArrayType(
View Full Code Here

            ValueBox box = stmt.getInvokeExprBox();
            Value value = box.getValue();

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

                //      System.out.println("compare " + r.getMethod().getDeclaringClass());
                //                 System.out.println("with " + theClass);
                if (classSet.contains(r.getMethod().getDeclaringClass())
                        && !liveLocals.getLiveLocalsAfter(stmt).contains(
                                r.getBase())) {
                    // Remove the initialization and the constructor.
                    // Note: This assumes a fairly tight coupling between
                    // the new and the object constructor.  This may
                    // not be true.
                    body.getUnits().remove(stmt);

                    for (Iterator defs = localDefs.getDefsOfAt(
                            (Local) r.getBase(), stmt).iterator(); defs
                            .hasNext();) {
                        Unit defUnit = (Unit) defs.next();

                        if (defUnit instanceof DefinitionStmt) {
                            // If we are keeping a definition, then
View Full Code Here

                        expr.setCastType(RefType
                                .v(PtolemyUtilities.runtimeExceptionClass));
                    }
                } else if (value instanceof SpecialInvokeExpr) {
                    // Fix the exception constructors.
                    SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                    SootClass exceptionClass = ((RefType) expr.getBase()
                            .getType()).getSootClass();

                    if (_isPtolemyException(exceptionClass)) {
                        Value foundArg = null;

                        for (Iterator args = expr.getArgs().iterator(); args
                                .hasNext();) {
                            Value arg = (Value) args.next();

                            if (arg.getType().equals(
                                    RefType.v(PtolemyUtilities.stringClass))) {
                                foundArg = arg;
                                break;
                            }
                        }

                        if ((foundArg == null) || _obfuscate) {
                            box
                                    .setValue(Jimple
                                            .v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    PtolemyUtilities.runtimeExceptionConstructor
                                                            .makeRef(),
                                                    Collections.EMPTY_LIST));
                        } else {
                            box
                                    .setValue(Jimple
                                            .v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    PtolemyUtilities.runtimeExceptionStringConstructor
                                                            .makeRef(),
                                                    foundArg));
                        }
                    }
                } else if (value instanceof VirtualInvokeExpr) {
                    VirtualInvokeExpr expr = (VirtualInvokeExpr) value;
                    Type exceptionType = expr.getBase().getType();

                    if (exceptionType instanceof RefType) {
                        SootClass exceptionClass = ((RefType) exceptionType)
                                .getSootClass();

                        if (_isPtolemyException(exceptionClass)) {
                            SootMethod method = expr.getMethod();

                            if (method.getName().equals("getMessage")) {
                                if (unit instanceof InvokeStmt) {
                                    body.getUnits().remove(unit);
                                } else {
View Full Code Here

                        if (value instanceof SpecialInvokeExpr) {
                            // System.out.println("invoke = " + unit);

                            // If we're constructing one of our actor classes,
                            // then switch to the modified constructor.
                            SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                            SootClass declaringClass = expr.getMethodRef()
                                    .declaringClass();
                            // System.out.println("declaringClass = "
                            //        + declaringClass);
                            if (expr.getMethod().getName().equals("<init>")
                                    && modifiedConstructorClassList
                                            .contains(declaringClass)) {
                                //  System.out.println(
                                //  "replacing constructor invocation = "
                                //               + unit + " in method " + method);
                                SootMethod newConstructor = (SootMethod) classToConstructorMap
                                        .get(declaringClass);

                                if (newConstructor.getParameterCount() == 2) {
                                    SpecialInvokeExpr r = (SpecialInvokeExpr) value;
                                    r.setMethodRef(newConstructor.makeRef());
                                }//  else if (newConstructor.getParameterCount() == 1) {
                                //                                     // Replace with just container arg constructor.
                                //                                     List args = new LinkedList();
                                //                                     args.add(expr.getArg(0));
                                //                                     box.setValue(
View Full Code Here

TOP

Related Classes of soot.jimple.SpecialInvokeExpr

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.