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

ArrayVariantManager.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  * ArrayVariantManager.java
00042  * $Id: ArrayVariantManager.java,v 1.1.1.1 2002/01/24 03:42:07 pserver Exp $
00043  */
00044 
00045 /**
00046  * This class maps various Array classes and value variants(array creation site
00047  * expression) to <code>ArrayVariant</code>s.  
00048  * 
00049  * We maintain a map from each <code>ClassTokenArray</code>(array class) to
00050  * IndexMap.  The IndexMap maps the <code>Index</code>(array indices) to
00051  * <code>ArrayVariant</code>s.
00052  *
00053  * @author <a href="http://www.cis.ksu.edu/~hatcliff">John Hatcliff</a>
00054  * @author 
00055  * <a href="http://www.cis.ksu.edu/~rvprasadVenkatesh Prasad Ranganath</a>
00056  * @version $Name:  $($Revision: 1.1.1.1 $)
00057  */
00058 public class ArrayVariantManager
00059 {
00060     /** 
00061      * <code>ArrayIndexManager</code> used to obtain indices for
00062      * <code>ValueVariant</code>s.
00063      */
00064     private static ArrayIndexManager arrayIndexManager;
00065 
00066     /** 
00067      * Maps the <code>ClassTokenArray</code>s to a map of 
00068      * <code>ArrayIndex</code> to <code>ArrayVariant</code>s. 
00069      */ 
00070     private static Map arrayClassMap;
00071 
00072     /** 
00073      * Provide the <code>ClassTokenArray</code> objects registered
00074      * with the Manager.
00075      *
00076      * @return the set of registered <code>ClassTokenArray</code> objects. 
00077      */
00078     public static Set getClassTokens()
00079     {
00080         return arrayClassMap.keySet();
00081     }
00082     /** 
00083      * Provide a collection of maps corresponding to each distinct
00084      * <code>ClassTokenArray</code> registered.
00085      *
00086      * @return the collection of maps.
00087      */
00088     public static Collection getValues()
00089     {
00090         // returns a collection of maps //
00091         return arrayClassMap.values();
00092     }
00093     /** 
00094      * Initializes the class with an <code>ArrayIndexManager</code>. 
00095      *
00096      * @param arrayIndexManager the <code>ArrayIndexManager</code> to use to get
00097      * <code>Index</code>. 
00098      */
00099     public static void init(ArrayIndexManager arrayIndexManager)
00100     {
00101         ArrayVariantManager.arrayIndexManager = arrayIndexManager;
00102         arrayClassMap     = new HashMap();
00103     }
00104     /**
00105      * Resets the data structures in the Manager.
00106      *
00107      */
00108     public static void reset() {
00109         if (arrayClassMap != null) {
00110             arrayClassMap.clear();
00111         } // end of if (arrayClassMap != null)
00112         if (arrayIndexManager != null) {
00113             arrayIndexManager.reset();
00114         } // end of if (arrayIndexManager != null)
00115     }
00116     /** 
00117      * Returns an <code>ArrayVariant</code> corresponding to the given
00118      * <code>ClassTokenArray</code> and <code>ValueVaraint</code>.  If none is
00119      * available, a new array variant is created and returned.
00120      *
00121      * @param classToken the class of the array. 
00122      * @param valueVariant the array creation expression.
00123      * @return the <code>ArrayVariant</code> registered for the array objects of
00124      * type <code>classToken</code> corresponding to the
00125      * <code>valueVaraint</code>. 
00126      */  
00127     public static ArrayVariant select(ClassToken classToken,
00128                                       ValueVariant  valueVariant)
00129     {
00130         Map             arrayIndexMap;
00131         Index           arrayIndex;
00132         ArrayVariant    arrayVariant;
00133         FGNodeArray     node;
00134         ClassTokenArray classTokenArray;
00135 
00136         // type-check classToken to make sure it describes an array
00137         // Should throw an appropriate exception if test fails, but
00138         // let type system do it for now.
00139 
00140         classTokenArray = (ClassTokenArray)classToken;
00141       
00142         // compute index based on value variant
00143 
00144         arrayIndex = arrayIndexManager.select(valueVariant);
00145 
00146         if (arrayClassMap.containsKey(classTokenArray)) {
00147             // if class is already registered, compute variant index, and
00148             // see if it is registered.
00149             arrayIndexMap = (Map) arrayClassMap.get(classTokenArray);
00150 
00151             if (arrayIndexMap.containsKey(arrayIndex)) {
00152                 // if array index is registered, then return array variant.
00153                 arrayVariant = (ArrayVariant) arrayIndexMap.get(arrayIndex);
00154             } else {
00155                 // index was not registered, so make new array variant and
00156                 // register.  There is a circular reference here: FGNodeArray
00157                 // references the arrayVariant, and the arrayVariant references
00158                 // the FGNode.  So create the node first with a null reference
00159                 // for arrayVariant.  Then, fill in the arrayVariant field after
00160                 // the arrayVariant has been created.
00161                 node = new FGNodeArray(null); 
00162                 arrayVariant = new ArrayVariant(classTokenArray, arrayIndex,
00163                                                 node);
00164                 node.putArrayVariant(arrayVariant);
00165                 arrayIndexMap.put(arrayIndex,arrayVariant);
00166             }
00167         } else {
00168             // if class token is not registered, then register it with an
00169             // index map with the current variant
00170             arrayIndexMap = new HashMap();
00171             // There is a circular reference here: 
00172             //    FGNodeArray references the arrayVariant, and the 
00173             //    arrayVariant references the FGNode.
00174             // So create the node first with a null reference for arrayVariant.
00175             // Then, fill in the arrayVariant field after the arrayVariant
00176             // has been created.
00177             node = new FGNodeArray(null); 
00178             arrayVariant = new ArrayVariant(classTokenArray, arrayIndex, node);
00179             node.putArrayVariant(arrayVariant);
00180 
00181             arrayIndexMap.put(arrayIndex,arrayVariant);
00182             arrayClassMap.put(classTokenArray,arrayIndexMap);
00183         }
00184         return arrayVariant;
00185     }
00186 }

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