Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 2003 Navindra Umanee <navindra@cs.mcgill.ca>
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 package soot.toolkits.scalar;
 
 import java.util.*;
 
 import soot.*;
 import soot.options.*;
Find all locals guaranteed to be defined at (just before) a given program point.

Author(s):
Navindra Umanee
 
 public class GuaranteedDefs
 {
     protected Map<UnitListunitToGuaranteedDefs;
 
     public GuaranteedDefs(UnitGraph graph)
     {
         if(Options.v().verbose())
             G.v()..println("[" + graph.getBody().getMethod().getName() +
                                "]     Constructing GuaranteedDefs...");
 
         GuaranteedDefsAnalysis analysis = new GuaranteedDefsAnalysis(graph);
 
         // build map
         {
              = new HashMap<UnitList>(graph.size() * 2 + 1, 0.7f);
             Iterator unitIt = graph.iterator();
 
             while(unitIt.hasNext()){
                 Unit s = (UnitunitIt.next();
                 FlowSet set = (FlowSetanalysis.getFlowBefore(s);
                 .put
                     (s, Collections.unmodifiableList(set.toList()));
             }
         }
     }

    
Returns a list of locals guaranteed to be defined at (just before) program point s.
 
     public List getGuaranteedDefs(Unit s)
     {
         return .get(s);
     }
 }

Flow analysis to determine all locals guaranteed to be defined at a given program point.
 
 {
     FlowSet emptySet = new ArraySparseSet();
 
     {
         super(graph);
         DominatorsFinder df = new MHGDominatorsFinder(graph);
          = new HashMap<UnitFlowSet>(graph.size() * 2 + 1, 0.7f);
 
         // pre-compute generate sets
         for(Iterator unitIt = graph.iterator(); unitIt.hasNext();){
             Unit s = (UnitunitIt.next();
             FlowSet genSet = .clone();
             
             for(Iterator domsIt = df.getDominators(s).iterator(); domsIt.hasNext();){
                 Unit dom = (UnitdomsIt.next();
                 for(Iterator boxIt = dom.getDefBoxes().iterator(); boxIt.hasNext();){
                     ValueBox box = (ValueBoxboxIt.next();
                     if(box.getValue() instanceof Local)
                         genSet.add(box.getValue(), genSet);
                 }
             }
             
             .put(sgenSet);
        }
        doAnalysis();
    }

    
All INs are initialized to the empty set.
    protected Object newInitialFlow()
    {
        return .clone();
    }

    
IN(Start) is the empty set
    protected Object entryInitialFlow()
    {
        return .clone();
    }

    
OUT is the same as IN plus the genSet.
    protected void flowThrough(Object inValueObject unitObject outValue)
    {
        FlowSet
            in = (FlowSetinValue,
            out = (FlowSetoutValue;
        // perform generation (kill set is empty)
        in.union(.get(unit), out);
    }

    
All paths == Intersection.
    protected void merge(Object in1Object in2Object out)
    {
        FlowSet
            inSet1 = (FlowSetin1,
            inSet2 = (FlowSetin2,
            outSet = (FlowSetout;
        inSet1.intersection(inSet2outSet);
    }
    protected void copy(Object sourceObject dest)
    {
        FlowSet
            sourceSet = (FlowSetsource,
            destSet = (FlowSetdest;
        sourceSet.copy(destSet);
    }
New to GrepCode? Check out our FAQ X