Package soot.jimple

Examples of soot.jimple.DefinitionStmt


        out.clear();

        out.putAll(in);

        if (s instanceof DefinitionStmt) {
            DefinitionStmt ds = (DefinitionStmt) s;
            Value lhs = ds.getLeftOp();
            Value rhs = ds.getRightOp();

            if (rhs instanceof CastExpr) {
              //un-box casted value
        CastExpr castExpr = (CastExpr) rhs;
              rhs = castExpr.getOp();
View Full Code Here


    public static Token getTokenValue(Local local, Unit location,
            LocalDefs localDefs, TokenConstructorAnalysis tokenAnalysis) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof Local) {
                return getTokenValue((Local) value, stmt, localDefs,
                        tokenAnalysis);
            } else if (value instanceof CastExpr) {
View Full Code Here

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

                if (unit instanceof DefinitionStmt) {
                    DefinitionStmt stmt = (DefinitionStmt) unit;
                    Value rightValue = stmt.getRightOp();

                    if (stmt.getLeftOp() instanceof Local) {
                        Local local = (Local) stmt.getLeftOp();

                        if (rightValue instanceof Local) {
                            _update(local, (Local) rightValue);
                        } else if (rightValue instanceof CastExpr) {
                            Value value = ((CastExpr) rightValue).getOp();

                            if (value instanceof Local) {
                                _update(local, (Local) value);
                            }
                        } else if (rightValue instanceof FieldRef) {
                            SootField field = ((FieldRef) rightValue)
                                    .getField();
                            _set(local, _getFieldObject(field));
                        }
                    } else if (stmt.getLeftOp() instanceof FieldRef) {
                        if (rightValue instanceof Local) {
                            SootField field = ((FieldRef) stmt.getLeftOp())
                                    .getField();
                            _set((Local) rightValue, _getFieldObject(field));
                        }
                    } else {
                        // Ignore..  probably not a named obj anyway.
View Full Code Here

            if (jumpStmt == null) {
                continue;
            }

            // assume that the last statement in the body is the loop counter.
            DefinitionStmt counterStmt = (DefinitionStmt) block.getTail();

            Local counterLocal = (Local) counterStmt.getLeftOp();

            // Determine the loop increment.
            int increment = 0;

            if (counterStmt.getRightOp() instanceof AddExpr) {
                AddExpr addExpr = (AddExpr) counterStmt.getRightOp();
                Value incrementValue;

                if (addExpr.getOp1().equals(counterLocal)) {
                    incrementValue = addExpr.getOp2();
                } else {
                    incrementValue = addExpr.getOp1();
                }

                if (!Evaluator.isValueConstantValued(incrementValue)) {
                    continue;
                }

                increment = ((IntConstant) Evaluator
                        .getConstantValueOf(incrementValue)).value;
                System.out.println("increment = " + increment);
            } else {
                continue;
            }

            BinopExpr conditionalExpr = (BinopExpr) jumpStmt.getCondition();

            // Now determine the loop limit from the conditional block.
            Value limitValue;

            if (conditionalExpr.getOp1().equals(counterLocal)) {
                limitValue = conditionalExpr.getOp2();
            } else {
                limitValue = conditionalExpr.getOp1();
            }

            int limit;

            if (Evaluator.isValueConstantValued(counterStmt.getRightOp())) {
                limit = ((IntConstant) Evaluator.getConstantValueOf(limitValue)).value;
                System.out.println("limit = " + limit + " " + increment);
            } else {
                continue;
            }

            // Lastly, find the initial value of the loop.
            //List defsList = localDefs.getDefsOfAt(counterLocal,
            //        whilePredecessor.getTail());
            //DefinitionStmt initializeStmt = (DefinitionStmt) defsList.get(0);
            int initial;

            if (Evaluator.isValueConstantValued(counterStmt.getRightOp())) {
                initial = ((IntConstant) Evaluator
                        .getConstantValueOf(counterStmt.getRightOp())).value;
                System.out.println("initial = " + initial);
            } else {
                continue;
            }
View Full Code Here

        //    //   System.out.println("
        //}
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof Local) {
                return getAttributeContainerRef(container, method,
                        (Local) value, stmt, localDefs, localUses, insertPoint);
            } else if (value instanceof CastExpr) {
                return getAttributeContainerRef(container, method,
                        (Local) ((CastExpr) value).getOp(), stmt, localDefs,
                        localUses, insertPoint);
            } else if (value instanceof InstanceFieldRef) {
                return (Local) ((InstanceFieldRef) value).getBase();
            } else if (value instanceof NewExpr) {
                // If we get to an object creation, then try
                // to figure out where the variable is stored into a field.
                Iterator pairs = localUses.getUsesOf(stmt).iterator();

                while (pairs.hasNext()) {
                    UnitValueBoxPair pair = (UnitValueBoxPair) pairs.next();

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

                        if (useStmt.getLeftOp() instanceof InstanceFieldRef) {
                            InstanceFieldRef leftOp = ((InstanceFieldRef) useStmt
                                    .getLeftOp());
                            return (Local) leftOp.getBase();
                        }
                    }
                }
View Full Code Here

    public static Attribute getAttributeValue(SootMethod method, Local local,
            Unit location, LocalDefs localDefs, LocalUses localUses) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof Local) {
                return getAttributeValue(method, (Local) value, stmt,
                        localDefs, localUses);
            } else if (value instanceof CastExpr) {
                return getAttributeValue(method, (Local) ((CastExpr) value)
                        .getOp(), stmt, localDefs, localUses);
            } else if (value instanceof FieldRef) {
                SootField field = ((FieldRef) value).getField();
                ValueTag tag = (ValueTag) field.getTag("_CGValue");

                if (tag == null) {
                    // return null;
                    throw new RuntimeException(
                            "Could not determine the static value of " + local
                                    + " in " + method);
                } else {
                    return (Attribute) tag.getObject();
                }
            } else if (value instanceof NewExpr) {
                // If we get to an object creation, then try
                // to figure out where the variable is stored into a field.
                Iterator pairs = localUses.getUsesOf(stmt).iterator();

                while (pairs.hasNext()) {
                    UnitValueBoxPair pair = (UnitValueBoxPair) pairs.next();
                    System.out.println("iat unit = " + pair.getUnit());

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

                        if (useStmt.getLeftOp() instanceof FieldRef) {
                            SootField field = ((FieldRef) useStmt.getLeftOp())
                                    .getField();
                            ValueTag tag = (ValueTag) field.getTag("_CGValue");

                            if (tag == null) {
                                System.out.println("Failed usage: " + useStmt);
View Full Code Here

            Value useValue;

            // Find a method invocation that doesn't have a return
            // value, or whose return value is dead.
            if (unit instanceof DefinitionStmt) {
                DefinitionStmt stmt = (DefinitionStmt) unit;
                Value left = stmt.getLeftOp();

                // If this statement defines a local that is later used,
                // then we cannot remove it.
                if (liveLocals.getLiveLocalsAfter(stmt).contains(left)) {
                    continue;
                }

                useValue = stmt.getRightOp();
            } else if (unit instanceof InvokeStmt) {
                useValue = ((InvokeStmt) unit).getInvokeExpr();
            } else {
                continue;
            }
View Full Code Here

                // to hasNext().
                if (!(whileCond.getHead() instanceof DefinitionStmt)) {
                    continue;
                }

                DefinitionStmt stmt = (DefinitionStmt) whileCond.getHead();

                if (!(stmt.getRightOp() instanceof InterfaceInvokeExpr)) {
                    continue;
                }

                InterfaceInvokeExpr expr = (InterfaceInvokeExpr) stmt
                        .getRightOp();

                if (expr.getMethod() != iteratorHasNextMethod) {
                    continue;
                }

                // At this point we know we have a while (hasNext()) loop.
                // Now go check for iterator is defined...  it should be just
                // above
                Local iteratorLocal = (Local) expr.getBase();
                Block whilePredecessor = (Block) whileCond.getPreds().get(0);

                if (whilePredecessor == block) {
                    whilePredecessor = (Block) whileCond.getPreds().get(1);
                }

                // System.out.println("whilePredecessor = " + whilePredecessor);
                Unit unit = whilePredecessor.getTail();
                boolean found = false;

                // walk backwards until we find a definition of the iterator.
                while ((unit != whilePredecessor.getHead()) && !found) {
                    if (unit instanceof DefinitionStmt
                            && ((DefinitionStmt) unit).getLeftOp().equals(
                                    iteratorLocal)) {
                        found = true;
                    } else {
                        unit = whilePredecessor.getPredOf(unit);
                    }
                }

                //  System.out.println("iterator def = " + unit);
                DefinitionStmt iteratorDefinition = ((DefinitionStmt) unit);

                if (!(iteratorDefinition.getRightOp() instanceof InterfaceInvokeExpr)
                        || !((InterfaceInvokeExpr) iteratorDefinition
                                .getRightOp()).getMethod().getName().equals(
                                "iterator")) {
                    continue;
                }

                Local collectionLocal = (Local) ((InterfaceInvokeExpr) iteratorDefinition
                        .getRightOp()).getBase();

                //  System.out.println("collection Local = " + collectionLocal);
                found = false;

                // Walk backward again until we reach the definition
                // of the collection.
                while ((unit != whilePredecessor.getHead()) && !found) {
                    if (unit instanceof DefinitionStmt
                            && ((DefinitionStmt) unit).getLeftOp().equals(
                                    collectionLocal)) {
                        found = true;
                    } else {
                        unit = whilePredecessor.getPredOf(unit);
                    }
                }

                //  System.out.println("collection def = " + unit);
                // System.out.println("field = " + field);
                DefinitionStmt collectionDefinition = ((DefinitionStmt) unit);

                if (!(collectionDefinition.getRightOp() instanceof FieldRef)
                        || (((FieldRef) collectionDefinition.getRightOp())
                                .getField() != field)) {
                    continue;
                }

                // FINALLY we know we've found something we can unroll... :)
View Full Code Here

    public static ptolemy.data.type.Type getTypeValue(SootMethod method,
            Local local, Unit location, LocalDefs localDefs, LocalUses localUses) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = (Value) stmt.getRightOp();

            if (value instanceof Local) {
                return getTypeValue(method, (Local) value, stmt, localDefs,
                        localUses);
            } else if (value instanceof CastExpr) {
View Full Code Here

    public static NamedObj getNamedObjValue(SootMethod method, Local local,
            Unit location, LocalDefs localDefs, LocalUses localUses) {
        List definitionList = localDefs.getDefsOfAt(local, location);

        if (definitionList.size() == 1) {
            DefinitionStmt stmt = (DefinitionStmt) definitionList.get(0);
            Value value = stmt.getRightOp();

            if (value instanceof Local) {
                return getNamedObjValue(method, (Local) value, stmt, localDefs,
                        localUses);
            } else if (value instanceof CastExpr) {
                return getNamedObjValue(method, (Local) ((CastExpr) value)
                        .getOp(), stmt, localDefs, localUses);
            } else if (value instanceof FieldRef) {
                SootField field = ((FieldRef) value).getField();
                ValueTag tag = (ValueTag) field.getTag("_CGValue");

                if (tag == null) {
                    // return null;
                    throw new RuntimeException(
                            "Could not determine the static value of " + local
                                    + " in " + method);
                } else {
                    return (NamedObj) tag.getObject();
                }
            } else if (value instanceof NewExpr) {
                // If we get to an object creation, then try
                // to figure out where the variable is stored into a field.
                Iterator pairs = localUses.getUsesOf(stmt).iterator();

                while (pairs.hasNext()) {
                    UnitValueBoxPair pair = (UnitValueBoxPair) pairs.next();

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

                        if (useStmt.getLeftOp() instanceof FieldRef) {
                            SootField field = ((FieldRef) useStmt.getLeftOp())
                                    .getField();
                            ValueTag tag = (ValueTag) field.getTag("_CGValue");

                            if (tag == null) {
                                System.out.println("Failed usage: " + useStmt);
View Full Code Here

TOP

Related Classes of soot.jimple.DefinitionStmt

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.