Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 1997-1999 Raja Vallee-Rai
   *
   * 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.
  */
 
 /*
  * Modified by the Sable Research Group and others 1997-1999.  
  * See the 'credits' file distributed with Soot for the complete list of
  * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
  */
 
 
 
 
 
 
 package soot.toolkits.scalar;
 import soot.options.*;
 
 import soot.*;
 import soot.util.*;
 import java.util.*;


Analysis that implements the LocalUses interface. Uses for a Local defined at a given Unit are returned as a list of UnitValueBoxPairs each containing a Unit that use the local and the Local itself wrapped in a ValueBox.
 
 public class SimpleLocalUses implements LocalUses
 {
     Map<UnitListunitToUses;

    
Construct the analysis from a UnitGraph representation of a method body and a LocalDefs interface. This supposes that a LocalDefs analysis must have been computed prior.

Note: If you do not already have a UnitGraph, it may be cheaper to use the constructor which only requires a Body.

 
     public SimpleLocalUses(UnitGraph graphLocalDefs localDefs)
     {
         this(graph.getBody(), localDefs);
     }

    
Construct the analysis from a method body and a LocalDefs interface. This supposes that a LocalDefs analysis must have been computed prior.
 
     public SimpleLocalUses(Body bodyLocalDefs localDefs)
     {
         if(Options.v().time())
            Timers.v()..start();
     
         if(Options.v().time())
            Timers.v()..start();
         
         if(Options.v().verbose())
             G.v()..println("[" + body.getMethod().getName() +
                 "]     Constructing SimpleLocalUses...");
     
 	Chain units = body.getUnits();
 	
          = new HashMap<UnitList>(units.size() * 2 + 1, 0.7f);
     
         // Initialize this map to empty sets
         {
             Iterator it = units.iterator();
 
             while(it.hasNext())
             {
                 Unit s = (Unitit.next();
                 .put(snew ArrayList());
             }
         }
 
         if(Options.v().time())
            Timers.v()..end();
     
         if(Options.v().time())
            Timers.v()..start();
    
        // Traverse units and associate uses with definitions
        {
            Iterator it = units.iterator();
            while(it.hasNext())
            {
                Unit s = (Unitit.next();
                Iterator boxIt = s.getUseBoxes().iterator();
                while(boxIt.hasNext())
                {
                    ValueBox useBox = (ValueBoxboxIt.next();
                    if(useBox.getValue() instanceof Local)
                    {
                        // Add this statement to the uses of the definition of the local
                        Local l = (LocaluseBox.getValue();
                        List<UnitpossibleDefs = localDefs.getDefsOfAt(ls);
                        Iterator<UnitdefIt = possibleDefs.iterator();
                        while(defIt.hasNext())
                        {
                            List<UnitValueBoxPairuseList = .get(defIt.next());
                            useList.add(new UnitValueBoxPair(suseBox));
                        }
                    }
                }
            }
        }
        if(Options.v().time())
           Timers.v()..end();
    
        if(Options.v().time())
           Timers.v()..start();
    
        // Store the map as a bunch of unmodifiable lists.
        {
            Iterator it = units.iterator();
            
            while(it.hasNext())
            {
                Unit s = (Unitit.next();
                .put(s, Collections.unmodifiableList(.get(s)));
            }
            
        }
        
        if(Options.v().time())
           Timers.v()..end();
    
        if(Options.v().time())
            Timers.v()..end();
        if(Options.v().verbose())
            G.v()..println("[" + body.getMethod().getName() +
                "]     finished SimpleLocalUses...");
    }

    
Uses for a Local defined at a given Unit are returned as a list of UnitValueBoxPairs each containing a Unit that use the local and the Local itself wrapped in a ValueBox.

Parameters:
s a unit that we want to query for the uses of the Local it (may) define.
Returns:
a UnitValueBoxPair of the Units that use the Local.
    public List getUsesOf(Unit s)
    {
        List l = .get(s);
        return l;
    }
New to GrepCode? Check out our FAQ X