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

ValueVariantManager.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 java.util.*;
00039 import ca.mcgill.sable.soot.jimple.Value;
00040 import ca.mcgill.sable.soot.jimple.Stmt;
00041 
00042 /* 
00043  * ValueVariantManager.java 
00044  * $Id: ValueVariantManager.java,v 1.1.1.1 2002/01/24 03:42:08 pserver Exp $
00045  */
00046 
00047 /**
00048  * This class manages the value variants depending on the enclosing class,
00049  * method and position in code where the variants were created. 
00050  *
00051  * @author <A HREF="http://www.cis.ksu.edu/~hatcliff">John Hatcliff</A>
00052  * @author
00053  * <a href="http://www.cis.ksu.edu/~rvprasad">Venkatesh Prasad Ranganath</a>
00054  * @version $Name:  $($Revision: 1.1.1.1 $)
00055  */
00056 public class ValueVariantManager
00057 {
00058     /** 
00059      * Manages the indices for value variants. 
00060      */
00061     private static ValueIndexManager valueIndexManager;
00062 
00063     /** 
00064      * Manages the indices for position in code. 
00065      */
00066     private static CodeIndexManager  codeIndexManager;
00067 
00068     /** 
00069      * Maps class tokens to map of value indices. 
00070      */
00071     private static Map classMap;
00072 
00073     /** 
00074      * Maps class tokens to values.  This is used for objects like null and so
00075      * on. 
00076      */ 
00077     private static Map constClassMap;
00078 
00079     /**
00080      * Provide the set of classes in which value variants are managed. 
00081      * 
00082      * @return the set of classes in which value variants are managed. 
00083      */
00084     public static Set getClasses()
00085     {
00086         return classMap.keySet();
00087     }
00088     /**
00089      * Provide the set of maps of the managed value variants. 
00090      *
00091      * @return the set of maps of the managed value variants. 
00092      */
00093     public static Collection getValues()
00094     {
00095         // returns a collection of maps //
00096         return classMap.values();
00097     }
00098     /**
00099      * Initilizes the class.
00100      *
00101      * @param valueIndexManager the manager to be used to manage value indices.
00102      * @param codeIndexManager the manager to be used to manage code indices. 
00103      */
00104     public static void init(ValueIndexManager valueIndexManager,
00105                             CodeIndexManager  codeIndexManager) {
00106 
00107         ValueVariantManager.valueIndexManager = valueIndexManager;
00108         ValueVariantManager.codeIndexManager  = codeIndexManager;
00109         classMap = new HashMap();
00110         constClassMap = new HashMap();
00111     }
00112     /**
00113      * Describe <code>reset</code> method here.
00114      *
00115      */
00116     public static void reset() {
00117         if (classMap != null) {
00118             classMap.clear();
00119         } // end of if (classMap != null)
00120         if (codeIndexManager != null) {
00121             codeIndexManager.reset();
00122         } // end of if (codeIndexManager != null)
00123         if (constClassMap != null) {
00124             constClassMap.clear();
00125         } // end of if (constClassMap != null)
00126         if (valueIndexManager != null) {
00127             valueIndexManager.reset();
00128         } // end of if (valueIndexManager != null)
00129     }
00130     /**
00131      * Provides the value variants associated with constant objects.  Null
00132      * objects and BOFA_UnknowValue objects are obtained from here.
00133      *
00134      * @param classToken the class token representing the type of the value
00135      * variant. 
00136      * @return the corresponding value variant. 
00137      */
00138       //  public static ValueVariant select(ClassToken classToken, 
00139       //                                    MethodVariant methodVariant)
00140       //  {
00141       //    if (constClassMap.containsKey(classToken)) {
00142       //        return (ValueVariant)constClassMap.get(classToken);
00143       //    } // end of if ()
00144       //    else {
00145       //        ValueVariant valueVariant = new ValueVariant(classToken, 
00146       //                                                     methodVariant, 
00147       //                                                     (Value)null, 
00148       //                                                     (Stmt)null);
00149       //        constClassMap.put(classToken, valueVariant);
00150       //        return valueVariant;
00151       //    } // end of else
00152       //  }
00153     
00154 
00155     /**
00156      * Provides the Value variant associated with given combination.
00157      *
00158      * @param classToken the class in which the value variant occurs.
00159      * @param methodVariant the method in which the value variant occurs.
00160      * @param expr a <code>Value</code> value
00161      * @param stmt the statement in which the value variant occurs.
00162      * @return a <code>ValueVariant</code> value
00163      */
00164     public static ValueVariant select(ClassToken    classToken,
00165                                       MethodVariant methodVariant,
00166                                       Value         expr, Stmt stmt)
00167     {
00168         Map indexMap;
00169         Index valueIndex;
00170         Index  codeIndex;
00171         ValueVariant valueVariant;
00172         
00173         // compute index based on context info 
00174         // (code index gives position in the code) 
00175 
00176         codeIndex  = codeIndexManager.select(expr);
00177         valueIndex = valueIndexManager.select(methodVariant, codeIndex);
00178 
00179         if (classMap.containsKey(classToken)) {
00180             // if class is already registered, compute variant index, and
00181             // see if it is registered.
00182             indexMap = (Map) classMap.get(classToken);
00183 
00184             if (indexMap.containsKey(valueIndex)) {
00185                 // if variant index is registered, then return value.
00186                 valueVariant = (ValueVariant) indexMap.get(valueIndex);
00187             } else {
00188                 // index was not registered, so make new value and register.
00189                 valueVariant = new ValueVariant(classToken,valueIndex, expr,
00190                                                 stmt); 
00191                 indexMap.put(valueIndex,valueVariant);
00192             }
00193         } else {
00194             // if class is not registered, then register it with an
00195             // index map with the current variant
00196             indexMap     = new HashMap();
00197             valueVariant = new ValueVariant(classToken,valueIndex, expr, stmt);
00198             indexMap.put(valueIndex,valueVariant);
00199             classMap.put(classToken,indexMap);
00200         }
00201         return valueVariant;
00202     }
00203 }

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