Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2015 The Pennsylvania State University and the University of Wisconsin
   * Systems and Internet Infrastructure Security Laboratory
   *
   * Author: Damien Octeau
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package edu.psu.cse.siis.coal.arguments;
 
 import java.util.List;
 import java.util.Set;
 
 
 import soot.Local;
 import soot.Unit;
An abstract backward argument value analysis, which provides utility functions.
 
 public abstract class BackwardValueAnalysis implements ArgumentValueAnalysis {
   private final Logger logger = LoggerFactory.getLogger(getClass());

  
Returns all assignments for a local variable. This walks the interprocedural control flow graph back from a statement looking for all assignments to a given local variable.

Parameters:
start The statement where the analysis should start.
local The local variable whose assignments should be found.
init A boolean that indicates whether the analysis should be initialized. This should always be true for non-recursive calls.
visitedUnits The set of statements visited by the analysis.
Returns:
The set of assignment statements for the local variable.
 
   protected List<DefinitionStmtfindAssignmentsForLocal(Unit startLocal localboolean init,
       Set<Pair<UnitLocal>> visitedUnits) {
     if (.isDebugEnabled()) {
       .debug("Finding assignments for local " + local);
     }
     SootMethod method = AnalysisParameters.v().getIcfg().getMethodOf(start);
     ExceptionalUnitGraph graph = new ExceptionalUnitGraph(method.getActiveBody());
     List<DefinitionStmtresult = new ArrayList<DefinitionStmt>();
 
     Stack<Unitstack = new Stack<Unit>();
     stack.push(start);
     if (init) {
       visitedUnits.clear();
     }
 
     while (!stack.empty()) {
       Unit current = stack.pop();
       if (.isDebugEnabled()) {
         .debug(current + " " + current.getClass());
       }
       Pair<UnitLocalpair = new Pair<UnitLocal>(currentlocal);
       if (visitedUnits.contains(pair)) {
         continue;
       }
       visitedUnits.add(pair);
       if (current instanceof IdentityStmt) {
         IdentityStmt identityStmt = (IdentityStmtcurrent;
         // method.
         if (identityStmt.getLeftOp().equivTo(local)) {
           result.add(identityStmt);
         }
       } else if (current instanceof AssignStmt) {
         AssignStmt assignStmt = (AssignStmtcurrent;
         if (assignStmt.getLeftOp().equivTo(local)) {
           if (assignStmt.getRightOp() instanceof Local) {
             result.addAll(findAssignmentsForLocal(current, (LocalassignStmt.getRightOp(), false,
                 visitedUnits));
           } else {
             result.add(assignStmt);
           }
           // The assignment generates the local on that path.
           // Anything before is irrelevant.
           continue;
         }
      }
      for (Unit pred : graph.getPredsOf(current)) {
        stack.push(pred);
      }
    }
    return result;
  }
New to GrepCode? Check out our FAQ X