private boolean isConstant(Stmt s) { if (s instanceof DefinitionStmt) { DefinitionStmt ds = (DefinitionStmt) s; if (constants.contains(ds.getLeftOp())) { return true; } } return false; } }
@Override public FlowFunction<Local> getCallToReturnFlowFunction(Unit callSite, Unit returnSite) { if (callSite instanceof DefinitionStmt) { DefinitionStmt definition = (DefinitionStmt) callSite; if (definition.getLeftOp() instanceof Local) { final Local leftOpLocal = (Local) definition.getLeftOp(); return new Kill<Local>(leftOpLocal); } } return Identity.v(); } };
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; }
@Override public List<Unit> getDefsOf(Local l) { Set<Unit> defs = localToDefs.get(l); if (defs == null) { defs = new HashSet<>(); BitSet bs = localToDefsBits[localToNumber.get(l)]; if (bs != null) { for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { Unit u = unitList.get(i); if (u instanceof DefinitionStmt) { if (((DefinitionStmt) u).getLeftOp() == l) { defs.add(u); } } } } localToDefs.put(l, defs); } return new ArrayList<>(defs); }
public void inDefinitionStmt(DefinitionStmt s) { inDefinitionStmt = true; // System.out.println(s); Value v = s.getLeftOp(); if (v instanceof Local) { // System.out.println("This is a local:"+v); /* * We want definedLocal to be set only if we are interested in naming it Variables that are created by Dava itself e.g. * handler (refer to SuperFirstStmtHandler) Need not be renamed. So we check whether definedLocal is present in the * info set if it is we set this other wise we dont */ if (info.contains((Local) v)) { definedLocal = (Local) v; } else { definedLocal = null; } } else { // System.out.println("Not a local"+v); } }
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); } } } }
public void inDefinitionStmt(DefinitionStmt s) { if (definedLocal == null) { return; } Value defined = (s).getLeftOp(); if (!(defined instanceof Local)) { return; } if (defined.equals(definedLocal)) { // the local of interest is being defined // if this is the augmentedStmt of interest set possible to true if not already seen if (s.equals(ofInterest.get_Stmt())) { // it is the stmt of interest if (seenBefore == 0) { possible = true; } else { possible = false; } } else { // its a definition of the local of interest but not by the stmt of interest seenBefore++; } } }
public List<DefinitionStmt> getDefs(Local var) { List<DefinitionStmt> toReturn = new ArrayList<DefinitionStmt>(); HashMap<Object, List> dU = useDefs.getDUHashMap(); Iterator<Object> it = dU.keySet().iterator(); while (it.hasNext()) { DefinitionStmt s = (DefinitionStmt) it.next(); Value left = s.getLeftOp(); if (left instanceof Local) { if (((Local) left).getName().compareTo(var.getName()) == 0) { toReturn.add(s); } } } return toReturn; }
private List<String> getDefs() { if (stmtSeqNode == null) { return null; } List<String> toReturn = new ArrayList<String>(); int stmtNum = 0; for (AugmentedStmt as : stmtSeqNode.getStatements()) { Stmt s = as.get_Stmt(); // check if this is a def if (s instanceof DefinitionStmt) { Value left = ((DefinitionStmt) s).getLeftOp(); toReturn.add(left.toString()); varToStmtMap.put(left.toString(), new Integer(stmtNum)); } else { toReturn = new ArrayList<String>(); varToStmtMap = new HashMap<String, Integer>(); } stmtNum++; } // going through all statements return toReturn; }
public void inDefinitionStmt(DefinitionStmt s) { Value leftOp = s.getLeftOp(); if (leftOp instanceof FieldRef) { // System.out.println("leftOp is a fieldRef:"+s); SootField field = ((FieldRef) leftOp).getField(); // check if this is a final field if (field.isFinal()) { // System.out.println("the field is a final variable"); finalFieldDefined = true; } } }
public void kill(DavaFlowSet<Stmt> in, Local redefined) { String redefinedLocalName = redefined.getName(); // kill any previous localpairs which have the redefined Local in the // left i.e. previous definitions for (Iterator<Stmt> listIt = in.iterator(); listIt.hasNext();) { DefinitionStmt tempStmt = (DefinitionStmt) listIt.next(); Value leftOp = tempStmt.getLeftOp(); if (leftOp instanceof Local) { String storedLocalName = ((Local) leftOp).getName(); if (redefinedLocalName.compareTo(storedLocalName) == 0) { // need to kill this from the list // System.out.println("Killing "+tempStmt); listIt.remove(); } } } }
public void inASTMethodNode(ASTMethodNode node) { Stmt s = ofInterest.get_Stmt(); // check this is a definition if (!(s instanceof DefinitionStmt)) { possible = false; return; } Value defined = ((DefinitionStmt) s).getLeftOp(); if (!(defined instanceof Local)) { possible = false; return; } // check that this is a local defined in this method // its a sanity check List declaredLocals = node.getDeclaredLocals(); if (!declaredLocals.contains(defined)) { possible = false; return; } definedLocal = (Local) defined; }
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); } }
public FlowFunction<Pair<Value, Type>> getReturnFlowFunction(Unit callSite, SootMethod callee, Unit exitStmt, Unit retSite) { if (exitStmt instanceof ReturnStmt) { ReturnStmt returnStmt = (ReturnStmt) exitStmt; Value op = returnStmt.getOp(); if (op instanceof Local) { if (callSite instanceof DefinitionStmt) { DefinitionStmt defnStmt = (DefinitionStmt) callSite; Value leftOp = defnStmt.getLeftOp(); if (leftOp instanceof Local) { final Local tgtLocal = (Local) leftOp; final Local retLocal = (Local) op; return new FlowFunction<Pair<Value, Type>>() { public Set<Pair<Value, Type>> computeTargets(Pair<Value, Type> source) { if (source == retLocal) { return Collections.singleton(new Pair<Value, Type>(tgtLocal, source.getO2())); } return Collections.emptySet(); } }; } } } } return KillAll.v(); }
/** * 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)); }
@Override public DavaFlowSet<Stmt> processStatement(Stmt s, DavaFlowSet<Stmt> inSet) { /* * If this path will not be taken return no path straightaway */ if (inSet == NOPATH) { return inSet; } if (s instanceof DefinitionStmt) { DavaFlowSet<Stmt> toReturn = cloneFlowSet(inSet); // d:x = expr // gen is x // kill is all previous defs of x Value leftOp = ((DefinitionStmt) s).getLeftOp(); if (leftOp instanceof Local) { // KILL any reaching defs of leftOp kill(toReturn, (Local) leftOp); // GEN gen(toReturn, (DefinitionStmt) s); return toReturn; } // leftop is a local } return inSet; }
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 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); } } */ }
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); } }