Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

InstanceVariantManager.java

00001 package edu.ksu.cis.bandera.bofa;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999                                          *
00006  * John Hatcliff (hatcliff@cis.ksu.edu)
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 
00037 import ca.mcgill.sable.soot.*;
00038 import ca.mcgill.sable.util.*;
00039 
00040 /* 
00041  * InstanceVariantManager.java 
00042  * $Id: InstanceVariantManager.java,v 1.1.1.1 2002/01/24 03:42:08 pserver Exp $
00043  */
00044 
00045 /**
00046  * This class that manages the instance variable variants.
00047  * 
00048  * @author <A HREF="http://www.cis.ksu.edu/~hatcliff">John Hatcliff</A>
00049  * @author
00050  * <a href="http://www.cis.ksu.edu/~rvprasad">Venkatesh Prasad Ranganath</a>
00051  * @version $Name:  $($Revision: 1.1.1.1 $)
00052  */
00053 public class InstanceVariantManager
00054 {
00055     /** 
00056      * Manager of the indices associated with instance variants. 
00057      *
00058      */
00059     private static InstanceIndexManager instanceIndexManager;
00060 
00061     /** 
00062      * Mapping from field to instance indices map. 
00063      *
00064      */
00065     private static Map                  instanceMap;
00066 
00067     /**
00068      * Provides the set of instance variables managed.
00069      *
00070      * @return set of instance variants managed. 
00071      */
00072     public static Set getFields()
00073     {
00074         return instanceMap.keySet();
00075     }
00076     /**
00077      * Provides the collection of instance variants managed.
00078      *
00079      * @param sootField a <code>SootField</code> value
00080      * @return collection of instance variants managed.
00081      */
00082     public static Collection getVariants(SootField sootField)
00083     {
00084         return ((Map) instanceMap.get(sootField)).values();
00085     }
00086     /**
00087      * Initialize the Manager.
00088      * @param instanceIndexManager the manager who will provide the indices to
00089      * get to the instance variants.  
00090      */
00091     public static void init(InstanceIndexManager instanceIndexManager) {
00092         InstanceVariantManager.instanceIndexManager = instanceIndexManager;
00093         InstanceVariantManager.instanceMap          = new HashMap();
00094     }
00095     /**
00096      * Reset the data structures of the manager.
00097      *
00098      */
00099     public static void reset() {
00100         if (instanceMap != null) {
00101             instanceMap.clear();
00102         } // end of if (instanceMap != null)
00103         if (instanceIndexManager != null) {
00104             instanceIndexManager.reset();
00105         } // end of if (instanceIndexManager != null)
00106     }
00107     /**
00108      * Select the variant corresponding to the instance variable.  If none
00109      * exists, then a new one is created.  In this implementation only one
00110      * instance variant is associated with one field variable of a class.
00111      *
00112      * @param sootField the field for which variant is requested.
00113      * @return the corresponding variant. 
00114      */
00115     public static InstanceVariant select(SootField  sootField)
00116     {
00117         Map             indexMap;
00118         Index           instanceIndex;
00119         InstanceVariant instanceVariant;
00120         FGNodeField     node;
00121       
00122         // compute index based on context info 
00123         instanceIndex = instanceIndexManager.select();
00124 
00125         if (instanceMap.containsKey(sootField)) {
00126             // if field is already registered, compute variant index, and
00127             // see if it is registered.
00128             indexMap = (Map) instanceMap.get(sootField);
00129 
00130             if (indexMap.containsKey(instanceIndex)) {
00131                 // if variant index is registered, then return variant
00132                 instanceVariant = (InstanceVariant) indexMap.get(instanceIndex);
00133             } else {
00134                 // index was not registered, so make new instance and register.
00135                 node = new FGNodeField(sootField);
00136                 instanceVariant = new InstanceVariant(sootField,
00137                                                       instanceIndex,
00138                                                       node);
00139                 indexMap.put(instanceIndex,instanceVariant);
00140             }
00141         } else {
00142             // if instance field is not registered, then register it with an
00143             // index map with the current variant
00144             indexMap = new HashMap();
00145             node = new FGNodeField(sootField);
00146             instanceVariant = new InstanceVariant(sootField,
00147                                                   instanceIndex,
00148                                                   node);
00149             indexMap.put(instanceIndex,instanceVariant);
00150             instanceMap.put(sootField,indexMap);
00151         }
00152         return instanceVariant;
00153     }
00154 }

Generated at Thu Feb 7 06:46:52 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001