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 java.util.*;
 
Analysis that provides an implementation of the LiveLocals interface.
 
 public class SimpleLiveLocals implements LiveLocals
 {
     Map<UnitListunitToLocalsBefore;



    
Computes the analysis given a UnitGraph computed from a method body. It is recommended that a ExceptionalUnitGraph (or similar) be provided for correct results in the case of exceptional control flow.

Parameters:
g a graph on which to compute the analysis.
See also:
soot.toolkits.graph.ExceptionalUnitGraph
 
     public SimpleLiveLocals(UnitGraph graph)
     {
         if(Options.v().time())
             Timers.v()..start();
         
         if(Options.v().verbose())
             G.v()..println("[" + graph.getBody().getMethod().getName() +
                 "]     Constructing SimpleLiveLocals...");
 
                         
         SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph);
 
         if(Options.v().time())
                 Timers.v()..start();
 
         // Build unitToLocals map
         {
              = new HashMap<UnitList>(graph.size() * 2 + 1, 0.7f);
              = 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()));
                 
                 set = (FlowSetanalysis.getFlowAfter(s);
                 .put(s, Collections.unmodifiableList(set.toList()));
             }            
         }
         
         if(Options.v().time())
             Timers.v()..end();
         
         if(Options.v().time())
             Timers.v()..end();
     }
    public List getLiveLocalsAfter(Unit s)
    {
        return .get(s);
    }
    
    public List getLiveLocalsBefore(Unit s)
    {
        return .get(s);
    }
    {
        super(g);
        if(Options.v().time())
            Timers.v()..start();
         = new ArraySparseSet();
        // Create kill sets.
        {
             = new HashMap<UnitFlowSet>(g.size() * 2 + 1, 0.7f);
            Iterator unitIt = g.iterator();
            while(unitIt.hasNext())
            {
                Unit s = (UnitunitIt.next();
                FlowSet killSet = .clone();
                Iterator boxIt = s.getDefBoxes().iterator();
                while(boxIt.hasNext())
                {
                    ValueBox box = (ValueBoxboxIt.next();
                    if(box.getValue() instanceof Local)
                        killSet.add(box.getValue(), killSet);
                }
                    .put(skillSet);
            }
        }
        // Create generate sets
        {
             = new HashMap<UnitFlowSet>(g.size() * 2 + 1, 0.7f);
            Iterator unitIt = g.iterator();
            while(unitIt.hasNext())
            {
                Unit s = (UnitunitIt.next();
                FlowSet genSet = .clone();
                Iterator boxIt = s.getUseBoxes().iterator();
                while(boxIt.hasNext())
                {
                    ValueBox box = (ValueBoxboxIt.next();
                    if(box.getValue() instanceof Local)
                        genSet.add(box.getValue(), genSet);
                }
                .put(sgenSet);
            }
        }
        if(Options.v().time())
            Timers.v()..end();
        if(Options.v().time())
            Timers.v()..start();
        doAnalysis();
        
        if(Options.v().time())
            Timers.v()..end();
    }
    protected Object newInitialFlow()
    {
        return .clone();
    }
    protected Object entryInitialFlow()
    {
        return .clone();
    }
        
    protected void flowThrough(Object inValueObject unitObject outValue)
    {
        FlowSet in = (FlowSetinValueout = (FlowSetoutValue;
        // Perform kill
            in.difference(.get(unit), out);
        // Perform generation
            out.union(.get(unit), out);
    }
    protected void merge(Object in1Object in2Object out)
    {
        FlowSet inSet1 = (FlowSetin1,
            inSet2 = (FlowSetin2;
        FlowSet outSet = (FlowSetout;
        inSet1.union(inSet2outSet);
    }
    
    protected void copy(Object sourceObject dest)
    {
        FlowSet sourceSet = (FlowSetsource,
            destSet = (FlowSetdest;
            
        sourceSet.copy(destSet);
    }
New to GrepCode? Check out our FAQ X