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.jimple.toolkits.base;
 
 import soot.*;
 import soot.jimple.*;
 import soot.util.*;
 import java.util.*;
 
 public class Zonation
 {
     private int zoneCount;
     private Map<UnitZoneunitToZone;
     
     public Zonation(StmtBody body)
     {
         Chain units = body.getUnits();
         Map<UnitArrayListunitToTrapBoundaries = new HashMap<UnitArrayList>();
         
         // Initialize each unit to an empty set
         {
             Iterator unitIt = units.iterator();
             
             while(unitIt.hasNext())
             {
                 Unit u = (UnitunitIt.next();
                 
                 unitToTrapBoundaries.put(unew ArrayList());
             }
         }
             
         // Build trap boundaries
         {
             Iterator trapIt = body.getTraps().iterator();
             
             while(trapIt.hasNext())
             {
                 Trap t = (TraptrapIt.next();
                 
                 List<Trapboundary = unitToTrapBoundaries.get(t.getBeginUnit());
                 boundary.add(t);
                 
                 boundary = unitToTrapBoundaries.get(t.getEndUnit());
                 boundary.add(t);
             }
         }
         
         // Traverse units, assigning each to a zone
         {
             Map<ListZonetrapListToZone = new HashMap<ListZone>(10, 0.7f);
             List<TrapcurrentTraps = new ArrayList<Trap>();
             Zone currentZone;
             
              = 0;
              = new HashMap<UnitZone>(units.size() * 2 + 1, 0.7f);
                         
             // Initialize first empty zone
                 currentZone = new Zone("0");
                 trapListToZone.put(new ArrayList(), currentZone);
                 
             Iterator unitIt = units.iterator();
             
             while(unitIt.hasNext())
             {
                 Unit u = (UnitunitIt.next();
                 
                 // Process trap boundaries
                 {
                     List trapBoundaries = unitToTrapBoundaries.get(u);
 
                     if(trapBoundaries.size() != 0)
                     {                        
                        Iterator trapIt = trapBoundaries.iterator();
                        
                        while(trapIt.hasNext())
                        {
                            Trap trap = (TraptrapIt.next();
                            
                            if(currentTraps.contains(trap))
                                currentTraps.remove(trap);
                            else
                                currentTraps.add(trap);
                        }
                                          
                        if(trapListToZone.containsKey(currentTraps))
                            currentZone = trapListToZone.get(currentTraps);
                        else
                        {   
                            // Create a new zone
                            
                            ++;
                            currentZone = new Zone(new Integer().toString());
                            
                            trapListToZone.put(currentTrapscurrentZone);
                        }
                                                    
                    }
                }
                    
                .put(ucurrentZone);
            }
        }
        
    }
    
    public Zone getZoneOf(Unit u)
    {
        Zone z = .get(u);
        
        if(z == null)
            throw new RuntimeException("null zone!");
        return z
    }
    
    public int getZoneCount()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X