public boolean canRemoveDef(DefinitionStmt ds) { List uses = useDefs.getDUChain(ds); if (uses.size() != 0) { return false; } // there is no use of this def, we can remove it if it is copy stmt or a constant assignment if (ds.getRightOp() instanceof Local || ds.getRightOp() instanceof Constant) { return true; } return false; }
private static boolean isSimpleCopy(Unit u) { if (!(u instanceof DefinitionStmt)) { return false; } DefinitionStmt defstmt = (DefinitionStmt) u; if (!(defstmt.getRightOp() instanceof Local)) { return false; } if (!(defstmt.getLeftOp() instanceof Local)) { return false; } return true; }
public boolean isCopyStmt(Stmt s) { if (!(s instanceof DefinitionStmt)) { // only definition stmts can be copy stmts return false; } // x = expr; // check if expr is a local in which case this is a copy Value leftOp = ((DefinitionStmt) s).getLeftOp(); Value rightOp = ((DefinitionStmt) s).getRightOp(); if (leftOp instanceof Local && rightOp instanceof Local) { // this is a copy statement return true; } return false; }
public void outDefinitionStmt(DefinitionStmt s) { // checking casting here because we want to see if the expr // on the right of def stmt is a cast expr not whether it contains a cast expr if (definedLocal != null && s.getRightOp() instanceof CastExpr) { Type castType = ((CastExpr) s.getRightOp()).getCastType(); info.addCastString(definedLocal, castType.toString()); } inDefinitionStmt = false; definedLocal = null; }
protected void flowThrough(HashMap<Local, Set<NewExpr>> in, Unit unit, HashMap<Local, Set<NewExpr>> out) { Stmt s = (Stmt) unit; out.clear(); out.putAll(in); if (s instanceof DefinitionStmt) { DefinitionStmt ds = (DefinitionStmt) s; Value lhs = ds.getLeftOp(); Value rhs = ds.getRightOp(); if (lhs instanceof Local) { HashSet<NewExpr> lv = new HashSet<NewExpr>(); out.put((Local) lhs, lv); if (rhs instanceof NewExpr) { lv.add((NewExpr) rhs); } else if (rhs instanceof Local) { lv.addAll(in.get(rhs)); } else { lv.add(UNKNOWN); } } } }
if (defStmt.getRightOp() instanceof Local && seenLocals.add((Local) defStmt.getRightOp())) { newLocals.add((Local) defStmt.getRightOp());
public ConstantArrayAnalysis(DirectedGraph<Unit> graph, Body b) { super(graph); for (Local l : b.getLocals()) { localToInt.put(l, size++); } for (Unit u : b.getUnits()) { Stmt s = (Stmt) u; if (s instanceof DefinitionStmt) { Type ty = ((DefinitionStmt) s).getRightOp().getType(); if (!typeToInt.containsKey(ty)) { int key = typeSize++; typeToInt.put(ty, key); rvTypeToInt.put(key, ty); } if (((DefinitionStmt) s).getRightOp() instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) ((DefinitionStmt) s).getRightOp(); if (nae.getSize() instanceof IntConstant) { int sz = ((IntConstant) nae.getSize()).value; if (!sizeToInt.containsKey(sz)) { int key = szSize++; sizeToInt.put(sz, key); rvSizeToInt.put(key, sz); } } } } } doAnalysis(); }
protected void handleStmt(Stmt stmt) { if (!(stmt instanceof DefinitionStmt)) { return; } DefinitionStmt dStmt = (DefinitionStmt) stmt; Value leftOp = dStmt.getLeftOp(); if (!(leftOp instanceof Local)) { return; } Value rightOp = dStmt.getRightOp(); Node node = fetchGraph(rightOp); localToNode.put(leftOp, node); // only update for non-trivial assignments and non-stubs if (!(rightOp instanceof Local) && !node.isStub()) { nodeToLocal.put(node, leftOp); } }
/** * Checks whether the given local is guaranteed to be always null at the given statement * * @param s * The statement at which to check the local * @param base * The local to check * @param defs * The definition analysis object to use for the check * @return True if the given local is guaranteed to always be null at the given statement, otherwise false */ private boolean isAlwaysNullBefore(Stmt s, Local base, LocalDefs defs) { List<Unit> baseDefs = defs.getDefsOfAt(base, s); if (baseDefs.isEmpty()) { return true; } for (Unit u : baseDefs) { if (!(u instanceof DefinitionStmt)) { return false; } DefinitionStmt defStmt = (DefinitionStmt) u; if (defStmt.getRightOp() != NullConstant.v()) { return false; } } return true; }
Value rightOp = ds.getRightOp();
DefinitionStmt ds = (DefinitionStmt) s; Value lhs = ds.getLeftOp(); Value rhs = ds.getRightOp();
/** * Returns (Unit, Constant) pair if an assumption has changed due to the fact that u is reachable. Else returns null. **/ protected Pair processDefinitionStmt(Unit u) { if (!(u instanceof DefinitionStmt)) { return null; } DefinitionStmt dStmt = (DefinitionStmt) u; Local local; { Value value = dStmt.getLeftOp(); if (!(value instanceof Local)) { return null; } local = (Local) value; } /* update assumptions */ Value rightOp = dStmt.getRightOp(); Constant constant = SEvaluator.getFuzzyConstantValueOf(rightOp, localToConstant); if (!merge(local, constant)) { return null; } return new Pair(u, localToConstant.get(local)); }
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo rhsInfo, AnalysisInfo out) { Value left = assignStmt.getLeftOp(); Value right = assignStmt.getRightOp(); // unbox casted value if (right instanceof JCastExpr) { JCastExpr castExpr = (JCastExpr) right; right = castExpr.getOp(); } // An assignment invalidates any assumptions of null/non-null for lhs // We COULD be more accurate by assigning those assumptions to the rhs prior to this statement rhsInfo.put(right, BOTTOM); // assign from rhs to lhs out.put(left, rhsInfo.get(right)); }
@Override public DavaFlowSet processStatement(Stmt s, DavaFlowSet input) { DavaFlowSet inSet = (DavaFlowSet) input; /* * If this path will not be taken return no path straightaway */ if (inSet == NOPATH) { return inSet; } if (s instanceof DefinitionStmt) { DavaFlowSet toReturn = (DavaFlowSet) cloneFlowSet(inSet); // x = expr; // check if expr is a local in which case this is a copy Value leftOp = ((DefinitionStmt) s).getLeftOp(); Value rightOp = ((DefinitionStmt) s).getRightOp(); if (leftOp instanceof Local) { // KILL any available copy with local since it has been // redefined kill(toReturn, (Local) leftOp); } // leftop is a local if (leftOp instanceof Local && rightOp instanceof Local) { // this is a copy statement // GEN gen(toReturn, (Local) leftOp, (Local) rightOp); } return toReturn; } else { return input; } }
if ((left.getType() instanceof IntegerType) || (left.getType() instanceof LongType)) { Value right = ((DefinitionStmt) s).getRightOp(); out.put(left, getParity(out, right));
@Override protected void flowThrough(FlowSet in, Unit d, FlowSet out) { in.copy(out); if (d instanceof DefinitionStmt) { DefinitionStmt ds = (DefinitionStmt) d; if (ds.getRightOp() instanceof NewExpr) { Value v = ds.getLeftOp(); if (v instanceof Local && in.contains(v)) { out.remove(v); } } } else { for (ValueBox useBox : d.getUseBoxes()) { Value v = useBox.getValue(); if (v instanceof Local) { out.add(v); } } } /* * else if (d instanceof InvokeStmt) { InvokeExpr ie = ((InvokeStmt)d).getInvokeExpr(); if (ie instanceof * SpecialInvokeExpr) { Value v = ((SpecialInvokeExpr)ie).getBase(); if (v instanceof Local && !inf.contains(v)) * outf.add(v); } } */ }
private void initAssignment(DefinitionStmt ds) { Value lhs = ds.getLeftOp(), rhs = ds.getRightOp(); if (lhs instanceof Local || lhs instanceof ArrayRef) { int assignmentIdx = this.assignments.size();
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) { Value left = assignStmt.getLeftOp(); Value right = assignStmt.getRightOp(); // unbox casted value if (right instanceof JCastExpr) { JCastExpr castExpr = (JCastExpr) right; right = castExpr.getOp(); } // if we have a definition (assignment) statement to a ref-like type, handle it, if (isAlwaysNonNull(right) || right instanceof NewExpr || right instanceof NewArrayExpr || right instanceof NewMultiArrayExpr || right instanceof ThisRef || right instanceof StringConstant || right instanceof ClassConstant || right instanceof CaughtExceptionRef) { // if we assign new... or @this, the result is non-null out.put(left, NON_NULL); } else if (right == NullConstant.v()) { // if we assign null, well, it's null out.put(left, NULL); } else if (left instanceof Local && right instanceof Local) { out.put(left, out.get(right)); } else if (left instanceof Local && right instanceof PhiExpr) { handlePhiExpr(out, left, (PhiExpr) right); } else { out.put(left, TOP); } }
if (!(astmt.getRightOp() instanceof CaughtExceptionRef)) { Type leftType = Type.toMachineType(astmt.getLeftOp().getType()); Type rightType = Type.toMachineType(astmt.getRightOp().getType());
public void walk_stmt(ASTAnalysis a, Stmt s) { if (a.getAnalysisDepth() < ASTAnalysis.ANALYSE_STMTS) { return; } if (s instanceof DefinitionStmt) { DefinitionStmt ds = (DefinitionStmt) s; walk_value(a, ds.getRightOp()); walk_value(a, ds.getLeftOp()); a.analyseDefinitionStmt(ds); } else if (s instanceof ReturnStmt) { ReturnStmt rs = (ReturnStmt) s; walk_value(a, rs.getOp()); a.analyseReturnStmt(rs); } else if (s instanceof InvokeStmt) { InvokeStmt is = (InvokeStmt) s; walk_value(a, is.getInvokeExpr()); a.analyseInvokeStmt(is); } else if (s instanceof ThrowStmt) { ThrowStmt ts = (ThrowStmt) s; walk_value(a, ts.getOp()); a.analyseThrowStmt(ts); } else { a.analyseStmt(s); } }