Package soot.jimple

Examples of soot.jimple.InstanceInvokeExpr


                    return ptolemy.data.type.BaseType.STRING;
                } else {
                    throw new RuntimeException("Unknown type field: " + field);
                }
            } else if (value instanceof InstanceInvokeExpr) {
                InstanceInvokeExpr r = (InstanceInvokeExpr) value;

                if (r.getMethod().getName().equals("getElementType")) {
                    ptolemy.data.type.ArrayType arrayType = (ptolemy.data.type.ArrayType) getTypeValue(
                            method, (Local) r.getBase(), stmt, localDefs,
                            localUses);
                    return arrayType.getElementType();
                } else {
                    throw new RuntimeException("Unknown instance invoke: " + r);
                }
View Full Code Here


                    // token constructors, there is no
                    // longer a token to pass to the
                    // constructor.  It is easier to
                    // just deal with it now...
                    // Create a new two-argument constructor.
                    InstanceInvokeExpr expr = (InstanceInvokeExpr) r;
                    stmt.getInvokeExprBox().setValue(
                            Jimple.v().newSpecialInvokeExpr(
                                    (Local) expr.getBase(),
                                    constructorWithoutToken.makeRef(),
                                    r.getArg(0), r.getArg(1)));
                }
            }
        }
View Full Code Here

                _addInequality(debug, solver, firstArgTerm, thirdArgTerm);
                _addInequality(debug, solver, thirdArgTerm, firstArgTerm);
                return null;
            }
        } else if (value instanceof InstanceInvokeExpr) {
            InstanceInvokeExpr r = (InstanceInvokeExpr) value;
            String methodName = r.getMethod().getName();

            // If we are invoking on something that is not a reference type,
            // then ignore it.
            if (!(r.getBase().getType() instanceof RefType)) {
                return null;
            }

            //    System.out.println("invokeExpr = " + r);
            SootClass baseClass = ((RefType) r.getBase().getType())
                    .getSootClass();
            InequalityTerm baseTerm = (InequalityTerm) objectToInequalityTerm
                    .get(r.getBase());

            // FIXME: match better.
            // If we are invoking a method on a token, then...
            if (SootUtilities
                    .derivesFrom(baseClass, PtolemyUtilities.typeClass)) {
                if (methodName.equals("convert")) {
                    return baseTerm;
                    //                     try {
                    //                         ptolemy.data.type.Type baseType = PtolemyUtilities
                    //                                 .getTypeValue(method, (Local) r.getBase(),
                    //                                         unit, localDefs, localUses);
                    //                         InequalityTerm baseTypeTerm = new ConstantTerm(
                    //                                 baseType, r);
                    //                         return baseTypeTerm;
                    //                     } catch (RuntimeException ex) {
                    //                         // Ignore..
                    //                     }
                } else if (r
                        .getMethod()
                        .getSignature()
                        .equals(
                                "<ptolemy.data.type.ArrayType: void <init>(ptolemy.data.type.Type)>")) {
                    InequalityTerm elementTerm = (InequalityTerm) objectToInequalityTerm
                            .get(r.getArg(0));
                    ptolemy.data.type.ArrayType arrayType = new ptolemy.data.type.ArrayType(
                            ptolemy.data.type.BaseType.UNKNOWN);
                    InequalityTerm variableTerm = new VariableTerm(arrayType, r);
                    _addInequality(debug, solver, elementTerm, arrayType
                            .getElementTypeTerm());
                    _addInequality(debug, solver, arrayType
                            .getElementTypeTerm(), elementTerm);
                    _addInequality(debug, solver, variableTerm, baseTerm);
                    return variableTerm;
                }
            }

            if (SootUtilities.derivesFrom(baseClass,
                    PtolemyUtilities.tokenClass)) {
                if (r.getMethod()
                        .equals(PtolemyUtilities.arrayTokenConstructor)) {
                    InequalityTerm firstArgTerm = (InequalityTerm) objectToInequalityTerm
                            .get(r.getArg(0));
                    ptolemy.data.type.ArrayType arrayType = new ptolemy.data.type.ArrayType(
                            ptolemy.data.type.BaseType.UNKNOWN);
                    VariableTerm newTerm = new VariableTerm(arrayType, r);
                    _addInequality(debug, solver, baseTerm, newTerm);
                    _addInequality(debug, solver, newTerm, baseTerm);

                    InequalityTerm elementTerm = arrayType.getElementTypeTerm();
                    _addInequality(debug, solver, firstArgTerm, elementTerm);
                    _addInequality(debug, solver, elementTerm, firstArgTerm);
                    return baseTerm;
                } else if (r.getMethod().equals(
                        PtolemyUtilities.arrayTokenWithTypeConstructor)) {
                    InequalityTerm elementTypeTerm = (InequalityTerm) objectToInequalityTerm
                            .get(r.getArg(0));
                    ptolemy.data.type.ArrayType arrayType = new ptolemy.data.type.ArrayType(
                            ptolemy.data.type.BaseType.UNKNOWN);
                    VariableTerm newTerm = new VariableTerm(arrayType, r);
                    _addInequality(debug, solver, baseTerm, newTerm);
                    _addInequality(debug, solver, newTerm, baseTerm);

                    InequalityTerm elementTerm = arrayType.getElementTypeTerm();
                    _addInequality(debug, solver, elementTypeTerm, elementTerm);
                    _addInequality(debug, solver, elementTerm, elementTypeTerm);
                    return baseTerm;
                } else if (methodName.equals("one")
                        || methodName.equals("zero")
                        || methodName.equals("bitwiseNot")
                        || methodName.equals("pow")
                        || methodName.equals("logicalRightShift")
                        || methodName.equals("leftShift")
                        || methodName.equals("rightShit")) {
                    // The returned type must be equal to the type
                    // we are calling the method on.
                    return baseTerm;
                } 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")) {
                    // The return value is greater than the base and
                    // the argument.
                    //  InequalityTerm returnValueTerm = new VariableTerm(
                    //                             PtolemyUtilities.getTokenTypeForSootType(
                    //                                     (RefType)r.getMethod().getReturnType()),
                    //                             r.getMethod());
                    final InequalityTerm firstArgTerm = (InequalityTerm) objectToInequalityTerm
                            .get(r.getArg(0));
                    final InequalityTerm finalBaseTerm = baseTerm;
                    final InstanceInvokeExpr finalExpression = r;

                    //                     _addInequality(debug, solver, firstArgTerm,
                    //                             returnValueTerm);
                    //                     _addInequality(debug, solver, baseTerm,
                    //                             returnValueTerm);
                    InequalityTerm returnValueTerm = new MonotonicFunction() {
                        public Object getValue() throws IllegalActionException {
                            if (firstArgTerm.getValue().equals(
                                    TypeLattice.lattice().bottom())
                                    || finalBaseTerm.getValue().equals(
                                            TypeLattice.lattice().bottom())) {
                                return TypeLattice.lattice().bottom();
                            }

                            return TypeLattice.lattice().leastUpperBound(
                                    firstArgTerm.getValue(),
                                    finalBaseTerm.getValue());
                        }

                        public InequalityTerm[] getVariables() {
                            ArrayList list = new ArrayList();

                            if (firstArgTerm.isSettable()) {
                                list.add(firstArgTerm);
                            }

                            if (finalBaseTerm.isSettable()) {
                                list.add(finalBaseTerm);
                            }

                            InequalityTerm[] terms = (InequalityTerm[]) list
                                    .toArray(new InequalityTerm[list.size()]);
                            return terms;
                        }

                        public Object getAssociatedObject() {
                            return finalExpression;
                        }
                    };

                    return returnValueTerm;
                } else if (methodName.equals("convert")) {
                    System.out.println("convert method!");

                    // The return value type is equal to the base
                    // type.  The first argument type is less than or
                    // equal to the base type.
                    InequalityTerm firstArgTerm = (InequalityTerm) objectToInequalityTerm
                            .get(r.getArg(0));
                    _addInequality(debug, solver, firstArgTerm, baseTerm);
                    return baseTerm;
                } else if (methodName.equals("getElement")
                        || methodName.equals("arrayValue")
                        || methodName.equals("getElementType")) {
                    // If we call getElement or arrayValue on an array
                    // token, then the returned type is the element
                    // type of the array.
                    ptolemy.data.type.ArrayType arrayType = new ptolemy.data.type.ArrayType(
                            ptolemy.data.type.BaseType.UNKNOWN);
                    _addInequality(debug, solver, baseTerm, new VariableTerm(
                            arrayType, r));

                    InequalityTerm returnTypeTerm = arrayType
                            .getElementTypeTerm();
                    return returnTypeTerm;
                } else if (methodName.equals("getElementAsToken")) {
                    final InequalityTerm matrixTerm = baseTerm;
                    InequalityTerm returnTypeTerm = new MonotonicFunction() {
                        public Object getValue() throws IllegalActionException {
                            if (matrixTerm.getValue() instanceof MatrixType) {
                                MatrixType type = (MatrixType) matrixTerm
                                        .getValue();
                                return type.getElementType();
                            } else {
                                return BaseType.UNKNOWN;
                            }
                        }

                        public InequalityTerm[] getVariables() {
                            if (matrixTerm.isSettable()) {
                                InequalityTerm[] terms = new InequalityTerm[1];
                                terms[0] = matrixTerm;
                                return terms;
                            } else {
                                return new InequalityTerm[0];
                            }
                        }
                    };

                    return returnTypeTerm;
                } else if (methodName.equals("absolute")) {
                    // Return the same as the input type, unless
                    // complex, in which case, return double.
                    final InequalityTerm finalBaseTerm = baseTerm;
                    final InstanceInvokeExpr finalExpression = r;
                    InequalityTerm returnValueTerm = new MonotonicFunction() {
                        public Object getValue() throws IllegalActionException {
                            if (finalBaseTerm.getValue().equals(
                                    BaseType.COMPLEX)) {
                                return BaseType.DOUBLE;
View Full Code Here

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

            if (unit.containsInvokeExpr()
                    && unit.getInvokeExpr() instanceof InstanceInvokeExpr) {
                InstanceInvokeExpr invokeExpr = (InstanceInvokeExpr) unit
                        .getInvokeExpr();
                SootMethod invokedMethod = invokeExpr.getMethod();

                // If we invoke a Token class initializer
                if (invokedMethod.getName().equals("<init>")
                        && SootUtilities.isSubtypeOf(invokeExpr.getBase()
                                .getType(), RefType
                                .v(PtolemyUtilities.tokenClass))) {
                    // System.out.println("found token initializer: " + unit);
                    Unit constructor = _findConstructor((Local) invokeExpr
                            .getBase(), unit, localDefs);

                    //  System.out.println("found token constructor: " + constructor);
                    if (constructor == null) {
                        continue;
View Full Code Here

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

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

                if (r.getBase().getType() instanceof RefType) {
                    RefType type = (RefType) r.getBase().getType();

                    // Inline calls to connections changed.
                    if (r.getMethod().equals(
                            PtolemyUtilities.connectionsChangedMethod)) {
                        // If we are calling connections changed on one of the classes
                        // we are generating code for, then inline it.
                        if (type.getSootClass().isApplicationClass()) {
                            SootMethod inlinee = null;

                            if (r instanceof VirtualInvokeExpr) {
                                // Now inline the resulting call.
                                List methodList = Scene
                                        .v()
                                        .getActiveHierarchy()
                                        .resolveAbstractDispatch(
                                                type.getSootClass(),
                                                PtolemyUtilities.connectionsChangedMethod);

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

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

                                    System.out.println(string);
                                }
                            } else if (r instanceof SpecialInvokeExpr) {
                                inlinee = Scene.v().getActiveHierarchy()
                                        .resolveSpecialDispatch(
                                                (SpecialInvokeExpr) r, method);
                            }

                            if (inlinee != null
                                    && !inlinee.getDeclaringClass()
                                            .isApplicationClass()) {
                                inlinee.getDeclaringClass().setLibraryClass();
                            }

                            inlinee.retrieveActiveBody();

                            if (debug) {
                                System.out
                                        .println("Inlining method call: " + r);
                            }

                            SiteInliner.inlineSite(inlinee, stmt, method);

                            doneSomething = true;
                        } else {
                            // FIXME: this is a bit of a hack, but
                            // for right now it seems to work.
                            // How many things that aren't
                            // the actors we are generating
                            // code for do we really care about here?
                            // Can we do this without having to create
                            // a class for the port too????
                            body.getUnits().remove(stmt);
                            doneSomething = true;
                        }
                    }

                    // Statically evaluate constant arguments.
                    Value[] argValues = new Value[r.getArgCount()];
                    int constantArgCount = 0;

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

                        //System.out.println("arg = " + arg);
                        if (Evaluator.isValueConstantValued(arg)) {
                            argValues[constantArgCount++] = Evaluator
                                    .getConstantValueOf(arg);

                            // System.out.println("argument = " + argValues[argCount-1]);
                        } else {
                            break;
                        }
                    }

                    //boolean allArgsAreConstant = (r.getArgCount() == constantArgCount);

                    if (SootUtilities.derivesFrom(type.getSootClass(),
                            PtolemyUtilities.componentPortClass)) {
                        // If we are invoking a method on a port
                        // class, then attempt to get the constant
                        // value of the port.
                        TypedIOPort port = (TypedIOPort) analysis
                                .getObject((Local) r.getBase());

                        //     System.out.println("reference to port = " + port);
                        if (port == null) {
                            continue;
                        }

                        // If we do this, then we have to get rid of
                        // the ports.
                        if (port instanceof Typeable) {
                            PtolemyUtilities.inlineTypeableMethods(body, stmt,
                                    box, r, port);
                        }

                        // Inline namedObj methods on the attribute.
                        if (r.getMethod().getSubSignature().equals(
                                PtolemyUtilities.getFullNameMethod
                                        .getSubSignature())) {
                            box.setValue(StringConstant.v(port.getFullName()));
                        }

                        if (r.getMethod().getSubSignature().equals(
                                PtolemyUtilities.getNameMethod
                                        .getSubSignature())) {
                            box.setValue(StringConstant.v(port.getName()));
                        }

                        String methodName = r.getMethod().getName();

                        if ((port.getWidth() == 0)
                                && (methodName.equals("hasToken")
                                        || methodName.equals("hasRoom")
                                        || methodName.equals("get") || methodName
                                        .equals("put"))) {
                            // NOTE: broadcast is legal on a zero
                            // width port.
                            // If we try to get on a port with
                            // zero width, then throw a runtime
                            // exception.
                            Local local = SootUtilities
                                    .createRuntimeException(
                                            body,
                                            stmt,
                                            methodName
                                                    + "() called on a port with zero width: "
                                                    + port.getFullName() + "!");
                            body.getUnits().insertBefore(
                                    Jimple.v().newThrowStmt(local), stmt);

                            if (stmt instanceof DefinitionStmt) {
                                // be sure we replace with the
                                // right return type.
                                if (methodName.equals("hasToken")
                                        || methodName.equals("hasRoom")) {
                                    box.setValue(IntConstant.v(0));
                                } else {
                                    box.setValue(NullConstant.v());
                                }
                            } else {
                                body.getUnits().remove(stmt);
                            }

                            continue;
                        }

                        if (r.getMethod().getName().equals("isInput")) {
                            if (debug) {
                                System.out.println("replacing isInput at "
                                        + stmt);
                            }

                            if (port.isInput()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName().equals("isOutput")) {
                            if (debug) {
                                System.out.println("replacing isOutput at "
                                        + stmt);
                            }

                            if (port.isOutput()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName()
                                .equals("isMultiport")) {
                            if (debug) {
                                System.out.println("replacing isMultiport at "
                                        + stmt);
                            }

                            if (port.isMultiport()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName().equals("getWidth")
                                || r.getMethod().getName().equals(
                                        "numberOfSources")
                                || r.getMethod().getName().equals(
                                        "numberOfSinks")) {
                            if (debug) {
                                System.out.println("replacing getWidth at "
                                        + stmt);
                            }

                            // Reflect and invoke the same method on our port
                            Object object = SootUtilities
                                    .reflectAndInvokeMethod(port,
                                            r.getMethod(), argValues);

                            // System.out.println("method result  = " + constant);
                            Constant constant = SootUtilities
                                    .convertArgumentToConstantValue(object);

                            // replace the method invocation.
                            box.setValue(constant);
                        } else if (r.getMethod().getName().equals("hasToken")) {
                            // return true.
                            if (debug) {
                                System.out.println("replacing hasToken at "
                                        + stmt);
                            }

                            box.setValue(IntConstant.v(1));
                        } else if (r.getMethod().getName().equals("hasRoom")) {
                            // return true.
                            if (debug) {
                                System.out.println("replacing hasRoom at "
                                        + stmt);
                            }

                            box.setValue(IntConstant.v(1));
                        } else if (r.getMethod().getName().equals("get")) {
                            // Could be get that takes a channel and
                            // returns a token, or get that takes a
                            // channel and a count and returns an
                            // array of tokens.  In either case,
                            // replace the get with circular array
                            // ref.
                            if (debug) {
                                System.out.println("replacing get at " + stmt);
                            }

                            inliner.inlineGet(body, stmt, box, r, port);
                        } else if (r.getMethod().getName().equals("send")) {
                            // Could be send that takes a channel and
                            // returns a token, or send that takes a
                            // channel and an array of tokens.  In
                            // either case, replace the send with
                            // circular array ref.
                            if (debug) {
                                System.out.println("replacing send at " + stmt);
                            }

                            inliner.inlineSend(body, stmt, r, port);
                        } else if (r.getMethod().getName().equals("broadcast")) {
                            // Broadcasting on a port of zero width does
                            // nothing.
                            if (port.getWidth() == 0) {
                                if (debug) {
                                    System.out
View Full Code Here

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

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

                if (r.getBase().getType() instanceof RefType) {
                    RefType type = (RefType) r.getBase().getType();

                    // Inline calls to connections changed.
                    if (r.getMethod().equals(
                            PtolemyUtilities.connectionsChangedMethod)) {
                        // If we are calling connections changed on one of the classes
                        // we are generating code for, then inline it.
                        if (type.getSootClass().isApplicationClass()) {
                            SootMethod inlinee = null;

                            if (r instanceof VirtualInvokeExpr) {
                                // Now inline the resulting call.
                                List methodList = Scene
                                        .v()
                                        .getActiveHierarchy()
                                        .resolveAbstractDispatch(
                                                type.getSootClass(),
                                                PtolemyUtilities.connectionsChangedMethod);

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

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

                                    System.out.println(string);
                                }
                            } else if (r instanceof SpecialInvokeExpr) {
                                inlinee = Scene.v().getActiveHierarchy()
                                        .resolveSpecialDispatch(
                                                (SpecialInvokeExpr) r, method);
                            }

                            if (inlinee != null
                                    && !inlinee.getDeclaringClass()
                                            .isApplicationClass()) {
                                inlinee.getDeclaringClass().setLibraryClass();
                            }

                            inlinee.retrieveActiveBody();

                            if (debug) {
                                System.out
                                        .println("Inlining method call: " + r);
                            }

                            SiteInliner.inlineSite(inlinee, stmt, method);

                            doneSomething = true;
                        } else {
                            // FIXME: this is a bit of a hack, but
                            // for right now it seems to work.
                            // How many things that aren't
                            // the actors we are generating
                            // code for do we really care about here?
                            // Can we do this without having to create
                            // a class for the port too????
                            body.getUnits().remove(stmt);
                            doneSomething = true;
                        }
                    }

                    // Statically evaluate constant arguments.
                    Value[] argValues = new Value[r.getArgCount()];
                    int constantArgCount = 0;

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

                        //System.out.println("arg = " + arg);
                        if (Evaluator.isValueConstantValued(arg)) {
                            argValues[constantArgCount++] = Evaluator
                                    .getConstantValueOf(arg);

                            // System.out.println("argument = " + argValues[argCount-1]);
                        } else {
                            break;
                        }
                    }

                    //boolean allArgsAreConstant = (r.getArgCount() == constantArgCount);

                    if (SootUtilities.derivesFrom(type.getSootClass(),
                            PtolemyUtilities.componentPortClass)) {
                        // If we are invoking a method on a port
                        // class, then attempt to get the constant
                        // value of the port.
                        TypedIOPort port = (TypedIOPort) analysis
                                .getObject((Local) r.getBase());

                        //     System.out.println("reference to port = " + port);
                        if (port == null) {
                            continue;
                        }

                        /** Don't do this for inside connections, to
                         * allow for properly defined ports of
                         * toplevel composites.
                         */

                        //    if (port instanceof Typeable) {
                        //                             PtolemyUtilities.inlineTypeableMethods(body,
                        //                                     stmt, box, r, (Typeable)port);
                        //                         }
                        // Inline namedObj methods on the attribute.
                        if (r.getMethod().getSubSignature().equals(
                                PtolemyUtilities.getFullNameMethod
                                        .getSubSignature())) {
                            box.setValue(StringConstant.v(port.getFullName()));
                        }

                        if (r.getMethod().getSubSignature().equals(
                                PtolemyUtilities.getNameMethod
                                        .getSubSignature())) {
                            box.setValue(StringConstant.v(port.getName()));
                        }

                        //String methodName = r.getMethod().getName();

                        //   if (port.getWidth() == 0 &&
                        //                                     (methodName.equals("hasToken") ||
                        //                                             methodName.equals("hasRoom") ||
                        //                                             methodName.equals("get") ||
                        //                                             methodName.equals("put"))) {
                        //                                 // NOTE: broadcast is legal on a zero
                        //                                 // width port.
                        //                                 // If we try to get on a port with
                        //                                 // zero width, then throw a runtime
                        //                                 // exception.
                        //                                 Local local = SootUtilities.createRuntimeException(body, stmt,
                        //                                         methodName + "() called on a port with zero width: " +
                        //                                         port.getFullName() + "!");
                        //                                 body.getUnits().insertBefore(Jimple.v().newThrowStmt(local),
                        //                                         stmt);
                        //                                 if (stmt instanceof DefinitionStmt) {
                        //                                     // be sure we replace with the
                        //                                     // right return type.
                        //                                     if (methodName.equals("hasToken") ||
                        //                                             methodName.equals("hasRoom")) {
                        //                                         box.setValue(IntConstant.v(0));
                        //                                     } else {
                        //                                         box.setValue(NullConstant.v());
                        //                                     }
                        //                                 } else {
                        //                                     body.getUnits().remove(stmt);
                        //                                 }
                        //                                 continue;
                        //                             }
                        if (r.getMethod().getName().equals("isInput")) {
                            // return true.
                            if (port.isInput()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName().equals("isOutput")) {
                            // return true.
                            if (port.isOutput()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName()
                                .equals("isMultiport")) {
                            // return true.
                            if (port.isMultiport()) {
                                box.setValue(IntConstant.v(1));
                            } else {
                                box.setValue(IntConstant.v(0));
                            }
                        } else if (r.getMethod().getName().equals("getWidth")) {
                            // Reflect and invoke the same method on our port
                            Object object = SootUtilities
                                    .reflectAndInvokeMethod(port,
                                            r.getMethod(), argValues);

                            // System.out.println("method result  = " + constant);
                            Constant constant = SootUtilities
                                    .convertArgumentToConstantValue(object);

                            // replace the method invocation.
                            box.setValue(constant);
                        } else if (r.getMethod().getName().equals("hasToken")) {
                            // return true.
                            if (debug) {
                                System.out.println("inlining hasToken at "
                                        + stmt);
                            }

                            box.setValue(IntConstant.v(1));
                        } else if (r.getMethod().getName().equals("hasRoom")) {
                            // return true.
                            if (debug) {
                                System.out.println("inlining hasRoom at "
                                        + stmt);
                            }

                            box.setValue(IntConstant.v(1));
                        } else if (r.getMethod().getName().equals("getInside")) {
                            // Could be get that takes a channel and
                            // returns a token, or get that takes a
                            // channel and a count and returns an
                            // array of tokens.  In either case,
                            // replace the get with circular array
                            // ref.
                            if (debug) {
                                System.out.println("inlining getInside at "
                                        + stmt);
                            }

                            inliner.inlineGetInside(body, stmt, box, r, port);
                        } else if (r.getMethod().getName().equals("sendInside")) {
                            // Could be send that takes a channel and
                            // returns a token, or send that takes a
                            // channel and an array of tokens.  In
                            // either case, replace the send with
                            // circular array ref.
View Full Code Here

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

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

                    if (r.getMethod().getSubSignature().equals(_getDirectorSig)) {
                        // Replace calls to getDirector with
                        // null.  FIXME: we should be able to
                        // do better than this?
                        if (unit instanceof InvokeStmt) {
                            body.getUnits().remove(unit);
                        } else {
                            box.setValue(NullConstant.v());
                        }
                    } else if (r.getMethod().getSubSignature().equals(
                            _getAttributeSig)) {
                        if (unit instanceof InvokeStmt) {
                            body.getUnits().remove(unit);
                        } else {
                            // Replace calls to getAttribute(arg)
                            // when arg is a string that can be
                            // statically evaluated.
                            Value nameValue = r.getArg(0);

                            if (Evaluator.isValueConstantValued(nameValue)) {
                                StringConstant nameConstant = (StringConstant) Evaluator
                                        .getConstantValueOf(nameValue);
                                String name = nameConstant.value;

                                // perform type analysis to determine what the
                                // type of the base is.
                                Local baseLocal = (Local) r.getBase();
                                _replaceGetAttributeMethod(actorClass, body,
                                        box, baseLocal, name, unit, localDefs);
                            } else {
                                String string = "Attribute cannot be "
                                        + "statically determined";
View Full Code Here

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

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

                    if (r.getMethod().getSubSignature().equals(
                            PtolemyUtilities.getPortMethod.getSubSignature())) {
                        if (_debug) {
                            System.out.println("replacing getPort in " + unit);
                        }

                        // Inline calls to getPort(arg) when
                        // arg is a string that can be
                        // statically evaluated.
                        Value nameValue = r.getArg(0);

                        if (Evaluator.isValueConstantValued(nameValue)) {
                            StringConstant nameConstant = (StringConstant) Evaluator
                                    .getConstantValueOf(nameValue);
                            String name = nameConstant.value;

                            // perform type analysis to determine what the
                            // type of the base is.
                            Local baseLocal = (Local) r.getBase();
                            Value newFieldRef = _createPortField(baseLocal,
                                    name, unit, localDefs);

                            if (unit instanceof AssignStmt) {
                                box.setValue(newFieldRef);
View Full Code Here

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

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

                    if (r.getMethod().getSubSignature().equals(
                            PtolemyUtilities.getContainerMethod
                                    .getSubSignature())) {
                        Value newFieldRef = _getContainerMethodReplacementFieldRef(
                                theClass, (Local) r.getBase(), body, unit,
                                localDefs);
                        box.setValue(newFieldRef);

                        if (_debug) {
                            System.out.println("replacing " + unit);
                        }
                    } else if (r.getMethod().equals(
                            PtolemyUtilities.toplevelMethod)) {
                        // Replace with reference to the toplevel
                        Value newFieldRef = getLocalReferenceForEntity(_model,
                                theClass, body.getThisLocal(), body, unit,
                                _options);
                        box.setValue(newFieldRef);

                        if (_debug) {
                            System.out.println("replacing " + unit);
                        }
                    } else if (r.getMethod().getSubSignature().equals(
                            PtolemyUtilities.getEntityMethod.getSubSignature())) {
                        Value nameValue = r.getArg(0);

                        if (Evaluator.isValueConstantValued(nameValue)) {
                            StringConstant nameConstant = (StringConstant) Evaluator
                                    .getConstantValueOf(nameValue);
                            String name = nameConstant.value;

                            if (_debug) {
                                System.out.println("replacing " + unit);
                            }

                            Value newFieldRef = _getEntityMethodReplacementValue(
                                    theClass, (Local) r.getBase(), name, body,
                                    unit, localDefs);
                            box.setValue(newFieldRef);

                            if (_debug) {
                                System.out.println("replacing " + unit);
View Full Code Here

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

                if (value instanceof InstanceInvokeExpr) {
                    InstanceInvokeExpr expr = (InstanceInvokeExpr) value;

                    if (expr.getMethod().equals(mainStartRunMethod)) {
                        // Replace the start run method call
                        // with code to iterate the model.
                        // First create a local that refers to the model.
                        // FIXME This is redundant, since the local
                        // already exists somewhere...
View Full Code Here

TOP

Related Classes of soot.jimple.InstanceInvokeExpr

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.