Search in sources :

Example 11 with FieldRef

use of soot.jimple.FieldRef in project soot by Sable.

the class StmtTranslator method handleAssign.

void handleAssign(DefinitionStmt stmt) {
    Value lval = stmt.getLeftOp();
    Value rval = stmt.getRightOp();
    Variable rvar;
    if (lval instanceof Local) {
        rvar = getLocalVariable((Local) lval);
    } else {
        rvar = jt.makeVariable(rval);
    }
    et.translateExpr(rvar, stmt.getRightOpBox());
    if (lval instanceof ArrayRef) {
        notSupported("We do not support arrays");
    } else if (lval instanceof FieldRef) {
        notSupported("We do not support field references");
    }
}
Also used : ArrayRef(soot.jimple.ArrayRef) Variable(dk.brics.soot.intermediate.representation.Variable) FieldRef(soot.jimple.FieldRef) Value(soot.Value) Local(soot.Local)

Example 12 with FieldRef

use of soot.jimple.FieldRef in project soot by Sable.

the class DexNumTransformer method internalTransform.

@Override
protected void internalTransform(final Body body, String phaseName, Map<String, String> options) {
    final DexDefUseAnalysis localDefs = new DexDefUseAnalysis(body);
    for (Local loc : getNumCandidates(body)) {
        usedAsFloatingPoint = false;
        Set<Unit> defs = localDefs.collectDefinitionsWithAliases(loc);
        // process normally
        doBreak = false;
        for (Unit u : defs) {
            // put correct local in l
            final Local l = u instanceof DefinitionStmt ? (Local) ((DefinitionStmt) u).getLeftOp() : null;
            // check defs
            u.apply(new AbstractStmtSwitch() {

                @Override
                public void caseAssignStmt(AssignStmt stmt) {
                    Value r = stmt.getRightOp();
                    if (r instanceof BinopExpr && !(r instanceof CmpExpr)) {
                        usedAsFloatingPoint = examineBinopExpr(stmt);
                        doBreak = true;
                    } else if (r instanceof FieldRef) {
                        usedAsFloatingPoint = isFloatingPointLike(((FieldRef) r).getFieldRef().type());
                        doBreak = true;
                    } else if (r instanceof NewArrayExpr) {
                        NewArrayExpr nae = (NewArrayExpr) r;
                        Type t = nae.getType();
                        usedAsFloatingPoint = isFloatingPointLike(t);
                        doBreak = true;
                    } else if (r instanceof ArrayRef) {
                        ArrayRef ar = (ArrayRef) r;
                        Type arType = ar.getType();
                        if (arType instanceof UnknownType) {
                            Type t = findArrayType(localDefs, stmt, 0, // TODO:
                            Collections.<Unit>emptySet());
                            // check
                            // where
                            // else
                            // to
                            // update
                            // if(ArrayRef...
                            usedAsFloatingPoint = isFloatingPointLike(t);
                        } else {
                            usedAsFloatingPoint = isFloatingPointLike(ar.getType());
                        }
                        doBreak = true;
                    } else if (r instanceof CastExpr) {
                        usedAsFloatingPoint = isFloatingPointLike(((CastExpr) r).getCastType());
                        doBreak = true;
                    } else if (r instanceof InvokeExpr) {
                        usedAsFloatingPoint = isFloatingPointLike(((InvokeExpr) r).getType());
                        doBreak = true;
                    } else if (r instanceof LengthExpr) {
                        usedAsFloatingPoint = false;
                        doBreak = true;
                    }
                }

                @Override
                public void caseIdentityStmt(IdentityStmt stmt) {
                    if (stmt.getLeftOp() == l) {
                        usedAsFloatingPoint = isFloatingPointLike(stmt.getRightOp().getType());
                        doBreak = true;
                    }
                }
            });
            if (doBreak) {
                break;
            }
            // check uses
            for (Unit use : localDefs.getUsesOf(l)) {
                use.apply(new AbstractStmtSwitch() {

                    private boolean examineInvokeExpr(InvokeExpr e) {
                        List<Value> args = e.getArgs();
                        List<Type> argTypes = e.getMethodRef().parameterTypes();
                        assert args.size() == argTypes.size();
                        for (int i = 0; i < args.size(); i++) {
                            if (args.get(i) == l && isFloatingPointLike(argTypes.get(i))) {
                                return true;
                            }
                        }
                        return false;
                    }

                    @Override
                    public void caseInvokeStmt(InvokeStmt stmt) {
                        InvokeExpr e = stmt.getInvokeExpr();
                        usedAsFloatingPoint = examineInvokeExpr(e);
                    }

                    @Override
                    public void caseAssignStmt(AssignStmt stmt) {
                        // only case where 'l' could be on the left side is
                        // arrayRef with 'l' as the index
                        Value left = stmt.getLeftOp();
                        if (left instanceof ArrayRef) {
                            ArrayRef ar = (ArrayRef) left;
                            if (ar.getIndex() == l) {
                                doBreak = true;
                                return;
                            }
                        }
                        // from this point, we only check the right hand
                        // side of the assignment
                        Value r = stmt.getRightOp();
                        if (r instanceof ArrayRef) {
                            if (((ArrayRef) r).getIndex() == l) {
                                doBreak = true;
                                return;
                            }
                        } else if (r instanceof InvokeExpr) {
                            usedAsFloatingPoint = examineInvokeExpr((InvokeExpr) r);
                            doBreak = true;
                            return;
                        } else if (r instanceof BinopExpr) {
                            usedAsFloatingPoint = examineBinopExpr(stmt);
                            doBreak = true;
                            return;
                        } else if (r instanceof CastExpr) {
                            usedAsFloatingPoint = stmt.hasTag("FloatOpTag") || stmt.hasTag("DoubleOpTag");
                            doBreak = true;
                            return;
                        } else if (r instanceof Local && r == l) {
                            if (left instanceof FieldRef) {
                                FieldRef fr = (FieldRef) left;
                                if (isFloatingPointLike(fr.getType())) {
                                    usedAsFloatingPoint = true;
                                }
                                doBreak = true;
                                return;
                            } else if (left instanceof ArrayRef) {
                                ArrayRef ar = (ArrayRef) left;
                                Type arType = ar.getType();
                                if (arType instanceof UnknownType) {
                                    arType = findArrayType(localDefs, stmt, 0, Collections.<Unit>emptySet());
                                }
                                usedAsFloatingPoint = isFloatingPointLike(arType);
                                doBreak = true;
                                return;
                            }
                        }
                    }

                    @Override
                    public void caseReturnStmt(ReturnStmt stmt) {
                        usedAsFloatingPoint = stmt.getOp() == l && isFloatingPointLike(body.getMethod().getReturnType());
                        doBreak = true;
                        return;
                    }
                });
                if (doBreak)
                    break;
            }
            // for uses
            if (doBreak)
                break;
        }
        // change values
        if (usedAsFloatingPoint) {
            for (Unit u : defs) {
                replaceWithFloatingPoint(u);
            }
        }
    // end if
    }
}
Also used : FieldRef(soot.jimple.FieldRef) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) LengthExpr(soot.jimple.LengthExpr) Local(soot.Local) Unit(soot.Unit) ArrayRef(soot.jimple.ArrayRef) UnknownType(soot.UnknownType) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) Type(soot.Type) InvokeExpr(soot.jimple.InvokeExpr) NewArrayExpr(soot.jimple.NewArrayExpr) CmpExpr(soot.jimple.CmpExpr) AbstractStmtSwitch(soot.jimple.AbstractStmtSwitch) Value(soot.Value) CastExpr(soot.jimple.CastExpr) List(java.util.List) DefinitionStmt(soot.jimple.DefinitionStmt) ReturnStmt(soot.jimple.ReturnStmt) IdentityStmt(soot.jimple.IdentityStmt) BinopExpr(soot.jimple.BinopExpr)

Example 13 with FieldRef

use of soot.jimple.FieldRef in project soot by Sable.

the class DexTransformer method findArrayType.

protected Type findArrayType(LocalDefs localDefs, Stmt arrayStmt, int depth, Set<Unit> alreadyVisitedDefs) {
    ArrayRef aRef = null;
    if (arrayStmt.containsArrayRef()) {
        aRef = arrayStmt.getArrayRef();
    }
    Local aBase = null;
    if (null == aRef) {
        if (arrayStmt instanceof AssignStmt) {
            AssignStmt stmt = (AssignStmt) arrayStmt;
            aBase = (Local) stmt.getRightOp();
        } else {
            throw new RuntimeException("ERROR: not an assign statement: " + arrayStmt);
        }
    } else {
        aBase = (Local) aRef.getBase();
    }
    List<Unit> defsOfaBaseList = localDefs.getDefsOfAt(aBase, arrayStmt);
    if (defsOfaBaseList == null || defsOfaBaseList.isEmpty()) {
        throw new RuntimeException("ERROR: no def statement found for array base local " + arrayStmt);
    }
    // We should find an answer only by processing the first item of the
    // list
    Type aType = null;
    int nullDefCount = 0;
    for (Unit baseDef : defsOfaBaseList) {
        if (alreadyVisitedDefs.contains(baseDef))
            continue;
        Set<Unit> newVisitedDefs = new HashSet<Unit>(alreadyVisitedDefs);
        newVisitedDefs.add(baseDef);
        // statement
        if (baseDef instanceof AssignStmt) {
            AssignStmt stmt = (AssignStmt) baseDef;
            Value r = stmt.getRightOp();
            if (r instanceof FieldRef) {
                Type t = ((FieldRef) r).getFieldRef().type();
                if (t instanceof ArrayType) {
                    ArrayType at = (ArrayType) t;
                    t = at.getArrayElementType();
                }
                if (depth == 0) {
                    aType = t;
                    break;
                } else {
                    return t;
                }
            } else if (r instanceof ArrayRef) {
                ArrayRef ar = (ArrayRef) r;
                if (ar.getType().toString().equals(".unknown") || ar.getType().toString().equals("unknown")) {
                    // ||
                    // ar.getType())
                    // {
                    Type t = findArrayType(localDefs, stmt, ++depth, // TODO: which type should be
                    newVisitedDefs);
                    // returned?
                    if (t instanceof ArrayType) {
                        ArrayType at = (ArrayType) t;
                        t = at.getArrayElementType();
                    }
                    if (depth == 0) {
                        aType = t;
                        break;
                    } else {
                        return t;
                    }
                } else {
                    ArrayType at = (ArrayType) stmt.getRightOp().getType();
                    Type t = at.getArrayElementType();
                    if (depth == 0) {
                        aType = t;
                        break;
                    } else {
                        return t;
                    }
                }
            } else if (r instanceof NewArrayExpr) {
                NewArrayExpr expr = (NewArrayExpr) r;
                Type t = expr.getBaseType();
                if (depth == 0) {
                    aType = t;
                    break;
                } else {
                    return t;
                }
            } else if (r instanceof CastExpr) {
                Type t = (((CastExpr) r).getCastType());
                if (t instanceof ArrayType) {
                    ArrayType at = (ArrayType) t;
                    t = at.getArrayElementType();
                }
                if (depth == 0) {
                    aType = t;
                    break;
                } else {
                    return t;
                }
            } else if (r instanceof InvokeExpr) {
                Type t = ((InvokeExpr) r).getMethodRef().returnType();
                if (t instanceof ArrayType) {
                    ArrayType at = (ArrayType) t;
                    t = at.getArrayElementType();
                }
                if (depth == 0) {
                    aType = t;
                    break;
                } else {
                    return t;
                }
            // introduces alias. We look whether there is any type
            // information associated with the alias.
            } else if (r instanceof Local) {
                Type t = findArrayType(localDefs, stmt, ++depth, newVisitedDefs);
                if (depth == 0) {
                    aType = t;
                // break;
                } else {
                    // return t;
                    aType = t;
                }
            } else if (r instanceof Constant) {
                // If the right side is a null constant, we might have a
                // case of broken code, e.g.,
                // a = null;
                // a[12] = 42;
                nullDefCount++;
            } else {
                throw new RuntimeException("ERROR: def statement not possible! " + stmt);
            }
        } else if (baseDef instanceof IdentityStmt) {
            IdentityStmt stmt = (IdentityStmt) baseDef;
            ArrayType at = (ArrayType) stmt.getRightOp().getType();
            Type t = at.getArrayElementType();
            if (depth == 0) {
                aType = t;
                break;
            } else {
                return t;
            }
        } else {
            throw new RuntimeException("ERROR: base local def must be AssignStmt or IdentityStmt! " + baseDef);
        }
        if (aType != null)
            break;
    }
    if (depth == 0 && aType == null) {
        if (nullDefCount == defsOfaBaseList.size()) {
            return NullType.v();
        } else {
            throw new RuntimeException("ERROR: could not find type of array from statement '" + arrayStmt + "'");
        }
    } else
        return aType;
}
Also used : FieldRef(soot.jimple.FieldRef) AssignStmt(soot.jimple.AssignStmt) Constant(soot.jimple.Constant) Local(soot.Local) Unit(soot.Unit) ArrayRef(soot.jimple.ArrayRef) ArrayType(soot.ArrayType) ArrayType(soot.ArrayType) Type(soot.Type) NullType(soot.NullType) InvokeExpr(soot.jimple.InvokeExpr) NewArrayExpr(soot.jimple.NewArrayExpr) Value(soot.Value) CastExpr(soot.jimple.CastExpr) IdentityStmt(soot.jimple.IdentityStmt) HashSet(java.util.HashSet)

Example 14 with FieldRef

use of soot.jimple.FieldRef in project soot by Sable.

the class DexNullTransformer method internalTransform.

@Override
protected void internalTransform(final Body body, String phaseName, Map<String, String> options) {
    final DexDefUseAnalysis localDefs = new DexDefUseAnalysis(body);
    AbstractStmtSwitch checkDef = new // Alex: should also end as
    AbstractStmtSwitch() {

        // soon as detected as not
        // used as an object
        @Override
        public void caseAssignStmt(AssignStmt stmt) {
            Value r = stmt.getRightOp();
            if (r instanceof FieldRef) {
                usedAsObject = isObject(((FieldRef) r).getFieldRef().type());
                doBreak = true;
                return;
            } else if (r instanceof ArrayRef) {
                ArrayRef ar = (ArrayRef) r;
                if (ar.getType() instanceof UnknownType) {
                    // isObject
                    usedAsObject = stmt.hasTag("ObjectOpTag");
                // (findArrayType
                // (g,
                // localDefs,
                // localUses,
                // stmt));
                } else {
                    usedAsObject = isObject(ar.getType());
                }
                doBreak = true;
                return;
            } else if (r instanceof StringConstant || r instanceof NewExpr || r instanceof NewArrayExpr) {
                usedAsObject = true;
                doBreak = true;
                return;
            } else if (r instanceof CastExpr) {
                usedAsObject = isObject(((CastExpr) r).getCastType());
                doBreak = true;
                return;
            } else if (r instanceof InvokeExpr) {
                usedAsObject = isObject(((InvokeExpr) r).getType());
                doBreak = true;
                return;
            } else if (r instanceof LengthExpr) {
                usedAsObject = false;
                doBreak = true;
                return;
            // introduces alias
            }
        }

        @Override
        public void caseIdentityStmt(IdentityStmt stmt) {
            if (stmt.getLeftOp() == l) {
                usedAsObject = isObject(stmt.getRightOp().getType());
                doBreak = true;
                return;
            }
        }
    };
    AbstractStmtSwitch checkUse = new AbstractStmtSwitch() {

        private boolean examineInvokeExpr(InvokeExpr e) {
            List<Value> args = e.getArgs();
            List<Type> argTypes = e.getMethodRef().parameterTypes();
            assert args.size() == argTypes.size();
            for (int i = 0; i < args.size(); i++) {
                if (args.get(i) == l && isObject(argTypes.get(i))) {
                    return true;
                }
            }
            // check for base
            SootMethodRef sm = e.getMethodRef();
            if (!sm.isStatic()) {
                if (e instanceof AbstractInvokeExpr) {
                    AbstractInstanceInvokeExpr aiiexpr = (AbstractInstanceInvokeExpr) e;
                    Value b = aiiexpr.getBase();
                    if (b == l) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public void caseInvokeStmt(InvokeStmt stmt) {
            InvokeExpr e = stmt.getInvokeExpr();
            usedAsObject = examineInvokeExpr(e);
            doBreak = true;
            return;
        }

        @Override
        public void caseAssignStmt(AssignStmt stmt) {
            Value left = stmt.getLeftOp();
            Value r = stmt.getRightOp();
            if (left instanceof ArrayRef) {
                ArrayRef ar = (ArrayRef) left;
                if (ar.getIndex() == l) {
                    doBreak = true;
                    return;
                } else if (ar.getBase() == l) {
                    usedAsObject = true;
                    doBreak = true;
                    return;
                }
            }
            if (left instanceof InstanceFieldRef) {
                InstanceFieldRef ifr = (InstanceFieldRef) left;
                if (ifr.getBase() == l) {
                    usedAsObject = true;
                    doBreak = true;
                    return;
                }
            }
            // used to assign
            if (stmt.getRightOp() == l) {
                Value l = stmt.getLeftOp();
                if (l instanceof StaticFieldRef && isObject(((StaticFieldRef) l).getFieldRef().type())) {
                    usedAsObject = true;
                    doBreak = true;
                    return;
                } else if (l instanceof InstanceFieldRef && isObject(((InstanceFieldRef) l).getFieldRef().type())) {
                    usedAsObject = true;
                    doBreak = true;
                    return;
                } else if (l instanceof ArrayRef) {
                    Type aType = ((ArrayRef) l).getType();
                    if (aType instanceof UnknownType) {
                        usedAsObject = stmt.hasTag(// isObject(
                        "ObjectOpTag");
                    // findArrayType(g,
                    // localDefs,
                    // localUses,
                    // stmt));
                    } else {
                        usedAsObject = isObject(aType);
                    }
                    doBreak = true;
                    return;
                }
            }
            // is used as value (does not exclude assignment)
            if (r instanceof FieldRef) {
                // isObject(((FieldRef)
                usedAsObject = true;
                // r).getFieldRef().type());
                doBreak = true;
                return;
            } else if (r instanceof ArrayRef) {
                ArrayRef ar = (ArrayRef) r;
                if (ar.getBase() == l) {
                    usedAsObject = true;
                } else {
                    // used as index
                    usedAsObject = false;
                }
                doBreak = true;
                return;
            } else if (r instanceof StringConstant || r instanceof NewExpr) {
                throw new RuntimeException("NOT POSSIBLE StringConstant or NewExpr at " + stmt);
            } else if (r instanceof NewArrayExpr) {
                usedAsObject = false;
                doBreak = true;
                return;
            } else if (r instanceof CastExpr) {
                usedAsObject = isObject(((CastExpr) r).getCastType());
                doBreak = true;
                return;
            } else if (r instanceof InvokeExpr) {
                usedAsObject = examineInvokeExpr((InvokeExpr) stmt.getRightOp());
                doBreak = true;
                return;
            } else if (r instanceof LengthExpr) {
                usedAsObject = true;
                doBreak = true;
                return;
            } else if (r instanceof BinopExpr) {
                usedAsObject = false;
                doBreak = true;
                return;
            }
        }

        @Override
        public void caseIdentityStmt(IdentityStmt stmt) {
            if (stmt.getLeftOp() == l)
                throw new RuntimeException("IMPOSSIBLE 0");
        }

        @Override
        public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
            usedAsObject = stmt.getOp() == l;
            doBreak = true;
            return;
        }

        @Override
        public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
            usedAsObject = stmt.getOp() == l;
            doBreak = true;
            return;
        }

        @Override
        public void caseReturnStmt(ReturnStmt stmt) {
            usedAsObject = stmt.getOp() == l && isObject(body.getMethod().getReturnType());
            doBreak = true;
            return;
        }

        @Override
        public void caseThrowStmt(ThrowStmt stmt) {
            usedAsObject = stmt.getOp() == l;
            doBreak = true;
            return;
        }
    };
    for (Local loc : getNullCandidates(body)) {
        usedAsObject = false;
        Set<Unit> defs = localDefs.collectDefinitionsWithAliases(loc);
        // process normally
        doBreak = false;
        for (Unit u : defs) {
            // put correct local in l
            if (u instanceof DefinitionStmt) {
                l = (Local) ((DefinitionStmt) u).getLeftOp();
            } else if (u instanceof IfStmt) {
                throw new RuntimeException("ERROR: def can not be something else than Assign or Identity statement! (def: " + u + " class: " + u.getClass() + "");
            }
            // check defs
            u.apply(checkDef);
            if (doBreak)
                break;
            // check uses
            for (Unit use : localDefs.getUsesOf(l)) {
                use.apply(checkUse);
                if (doBreak)
                    break;
            }
            // for uses
            if (doBreak)
                break;
        }
        // change values
        if (usedAsObject) {
            for (Unit u : defs) {
                replaceWithNull(u);
                Set<Value> defLocals = new HashSet<Value>();
                for (ValueBox vb : u.getDefBoxes()) defLocals.add(vb.getValue());
                Local l = (Local) ((DefinitionStmt) u).getLeftOp();
                for (Unit uuse : localDefs.getUsesOf(l)) {
                    Stmt use = (Stmt) uuse;
                    // If we have a[x] = 0 and a is an object, we may not conclude 0 -> null
                    if (!use.containsArrayRef() || !defLocals.contains(use.getArrayRef().getBase()))
                        replaceWithNull(use);
                }
            }
        }
    // end if
    }
    // Check for inlined zero values
    AbstractStmtSwitch inlinedZeroValues = new AbstractStmtSwitch() {

        final NullConstant nullConstant = NullConstant.v();

        @Override
        public void caseAssignStmt(AssignStmt stmt) {
            // Case a = 0 with a being an object
            if (isObject(stmt.getLeftOp().getType()) && isConstZero(stmt.getRightOp())) {
                stmt.setRightOp(nullConstant);
                return;
            }
            // Case a = (Object) 0
            if (stmt.getRightOp() instanceof CastExpr) {
                CastExpr ce = (CastExpr) stmt.getRightOp();
                if (isObject(ce.getCastType()) && isConstZero(ce.getOp())) {
                    stmt.setRightOp(nullConstant);
                }
            }
            // Case a[0] = 0
            if (stmt.getLeftOp() instanceof ArrayRef && isConstZero(stmt.getRightOp())) {
                ArrayRef ar = (ArrayRef) stmt.getLeftOp();
                if (isObjectArray(ar.getBase(), body) || stmt.hasTag("ObjectOpTag")) {
                    stmt.setRightOp(nullConstant);
                }
            }
        }

        private boolean isConstZero(Value rightOp) {
            if (rightOp instanceof IntConstant && ((IntConstant) rightOp).value == 0)
                return true;
            if (rightOp instanceof LongConstant && ((LongConstant) rightOp).value == 0)
                return true;
            return false;
        }

        @Override
        public void caseReturnStmt(ReturnStmt stmt) {
            if (stmt.getOp() instanceof IntConstant && isObject(body.getMethod().getReturnType())) {
                IntConstant iconst = (IntConstant) stmt.getOp();
                assert iconst.value == 0;
                stmt.setOp(nullConstant);
            }
        }

        @Override
        public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
            if (stmt.getOp() instanceof IntConstant && ((IntConstant) stmt.getOp()).value == 0)
                stmt.setOp(nullConstant);
        }

        @Override
        public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
            if (stmt.getOp() instanceof IntConstant && ((IntConstant) stmt.getOp()).value == 0)
                stmt.setOp(nullConstant);
        }
    };
    final NullConstant nullConstant = NullConstant.v();
    for (Unit u : body.getUnits()) {
        u.apply(inlinedZeroValues);
        if (u instanceof Stmt) {
            Stmt stmt = (Stmt) u;
            if (stmt.containsInvokeExpr()) {
                InvokeExpr invExpr = stmt.getInvokeExpr();
                for (int i = 0; i < invExpr.getArgCount(); i++) if (isObject(invExpr.getMethodRef().parameterType(i)))
                    if (invExpr.getArg(i) instanceof IntConstant) {
                        IntConstant iconst = (IntConstant) invExpr.getArg(i);
                        assert iconst.value == 0;
                        invExpr.setArg(i, nullConstant);
                    }
            }
        }
    }
}
Also used : ExitMonitorStmt(soot.jimple.ExitMonitorStmt) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) ThrowStmt(soot.jimple.ThrowStmt) IfStmt(soot.jimple.IfStmt) IdentityStmt(soot.jimple.IdentityStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) ReturnStmt(soot.jimple.ReturnStmt) ExitMonitorStmt(soot.jimple.ExitMonitorStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) DefinitionStmt(soot.jimple.DefinitionStmt) ArrayRef(soot.jimple.ArrayRef) AbstractInvokeExpr(soot.jimple.internal.AbstractInvokeExpr) AbstractInstanceInvokeExpr(soot.jimple.internal.AbstractInstanceInvokeExpr) AbstractInvokeExpr(soot.jimple.internal.AbstractInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) AbstractInstanceInvokeExpr(soot.jimple.internal.AbstractInstanceInvokeExpr) AbstractStmtSwitch(soot.jimple.AbstractStmtSwitch) CastExpr(soot.jimple.CastExpr) InstanceFieldRef(soot.jimple.InstanceFieldRef) IntConstant(soot.jimple.IntConstant) IdentityStmt(soot.jimple.IdentityStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) HashSet(java.util.HashSet) LongConstant(soot.jimple.LongConstant) FieldRef(soot.jimple.FieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) StaticFieldRef(soot.jimple.StaticFieldRef) SootMethodRef(soot.SootMethodRef) LengthExpr(soot.jimple.LengthExpr) Local(soot.Local) NullConstant(soot.jimple.NullConstant) StaticFieldRef(soot.jimple.StaticFieldRef) UnknownType(soot.UnknownType) UnknownType(soot.UnknownType) ArrayType(soot.ArrayType) Type(soot.Type) IfStmt(soot.jimple.IfStmt) NewArrayExpr(soot.jimple.NewArrayExpr) ValueBox(soot.ValueBox) Value(soot.Value) NewExpr(soot.jimple.NewExpr) StringConstant(soot.jimple.StringConstant) ReturnStmt(soot.jimple.ReturnStmt) ThrowStmt(soot.jimple.ThrowStmt) DefinitionStmt(soot.jimple.DefinitionStmt) BinopExpr(soot.jimple.BinopExpr)

Example 15 with FieldRef

use of soot.jimple.FieldRef in project soot by Sable.

the class NullnessAnalysis method flowThrough.

/**
 * {@inheritDoc}
 */
@Override
protected void flowThrough(AnalysisInfo in, Unit u, List<AnalysisInfo> fallOut, List<AnalysisInfo> branchOuts) {
    AnalysisInfo out = new AnalysisInfo(in);
    AnalysisInfo outBranch = new AnalysisInfo(in);
    Stmt s = (Stmt) u;
    // or for an instanceof expression
    if (s instanceof JIfStmt) {
        JIfStmt ifStmt = (JIfStmt) s;
        handleIfStmt(ifStmt, in, out, outBranch);
    } else // in case of a monitor statement, we know that if it succeeds, we have a non-null value
    if (s instanceof MonitorStmt) {
        MonitorStmt monitorStmt = (MonitorStmt) s;
        out.put(monitorStmt.getOp(), NON_NULL);
    }
    // if we have an array ref, set the base to non-null
    if (s.containsArrayRef()) {
        ArrayRef arrayRef = s.getArrayRef();
        handleArrayRef(arrayRef, out);
    }
    // for field refs, set the receiver object to non-null, if there is one
    if (s.containsFieldRef()) {
        FieldRef fieldRef = s.getFieldRef();
        handleFieldRef(fieldRef, out);
    }
    // for invoke expr, set the receiver object to non-null, if there is one
    if (s.containsInvokeExpr()) {
        InvokeExpr invokeExpr = s.getInvokeExpr();
        handleInvokeExpr(invokeExpr, out);
    }
    // x=y,                  copy the info for y (for locals x,y)
    if (s instanceof DefinitionStmt) {
        DefinitionStmt defStmt = (DefinitionStmt) s;
        if (defStmt.getLeftOp().getType() instanceof RefLikeType) {
            handleRefTypeAssignment(defStmt, out);
        }
    }
    // now copy the computed info to all successors
    for (Iterator<AnalysisInfo> it = fallOut.iterator(); it.hasNext(); ) {
        copy(out, it.next());
    }
    for (Iterator<AnalysisInfo> it = branchOuts.iterator(); it.hasNext(); ) {
        copy(outBranch, it.next());
    }
}
Also used : ArrayRef(soot.jimple.ArrayRef) RefLikeType(soot.RefLikeType) FieldRef(soot.jimple.FieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) JIfStmt(soot.jimple.internal.JIfStmt) MonitorStmt(soot.jimple.MonitorStmt) DefinitionStmt(soot.jimple.DefinitionStmt) MonitorStmt(soot.jimple.MonitorStmt) Stmt(soot.jimple.Stmt) JIfStmt(soot.jimple.internal.JIfStmt) DefinitionStmt(soot.jimple.DefinitionStmt)

Aggregations

FieldRef (soot.jimple.FieldRef)31 Value (soot.Value)25 Local (soot.Local)21 Unit (soot.Unit)20 Stmt (soot.jimple.Stmt)17 ArrayRef (soot.jimple.ArrayRef)14 InvokeExpr (soot.jimple.InvokeExpr)14 AssignStmt (soot.jimple.AssignStmt)13 SootField (soot.SootField)12 Type (soot.Type)12 DefinitionStmt (soot.jimple.DefinitionStmt)12 InstanceFieldRef (soot.jimple.InstanceFieldRef)12 SootMethod (soot.SootMethod)10 ValueBox (soot.ValueBox)10 ArrayList (java.util.ArrayList)9 NewArrayExpr (soot.jimple.NewArrayExpr)9 CastExpr (soot.jimple.CastExpr)8 StaticFieldRef (soot.jimple.StaticFieldRef)8 HashSet (java.util.HashSet)7 Iterator (java.util.Iterator)7