Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

symbol.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_SYMBOL_H
00038 #define CBZ_SYMBOL_H
00039 
00040 
00041 // ------------------------------------------------------------
00042 //   Symbol Table
00043 // ------------------------------------------------------------
00044 
00045 template <class T>
00046 class SymbolTable {
00047 
00048 private:
00049 
00050   // -- Nested or flat symbol table
00051   bool _is_nested;
00052 
00053   // -- A symbol table is a list of scopes
00054 
00055   typedef map<string,
00056           T,
00057           less< string > > scope;
00058 
00059   typedef scope::iterator scope_p;
00060 
00061   typedef list< scope * > table;
00062   typedef table::iterator table_p;
00063 
00064   table _table;
00065 
00066   virtual void shadow(T create, T shadowed) =0;
00067   virtual void notify_exit_scope(T dead) =0;
00068 
00069 public:
00070 
00071   SymbolTable(bool is_nested)
00072     : _is_nested(is_nested), _table()
00073   { _table.push_front(new scope()); }
00074 
00075   ~SymbolTable();
00076 
00077   void mark_nodes (void);
00078   void reset();
00079   T insert(const string & name, T sym); // Returns any conflicting object
00080   T lookup(const string & name);
00081   void print(FILE * out);
00082   string insert_unique(const string & root, T sym); // Returns new name
00083   void enter_scope();
00084   void exit_scope();
00085 
00086 };
00087 
00088 // ------------------------------------------------------------
00089 //   Subclass the symbol-table for each type of table
00090 // ------------------------------------------------------------
00091 
00092 class Identifiers_table : public SymbolTable< declNode * > {
00093 
00094 public:
00095 
00096   Identifiers_table();
00097   bool is_a_type(const string & name);
00098 
00099 private:
00100 
00101   void shadow(declNode * create, declNode * shadowed);
00102   void notify_exit_scope(declNode * dead);
00103 };
00104 
00105 class Labels_table : public SymbolTable< labelNode * > {
00106 
00107 public:
00108 
00109   Labels_table();
00110 
00111 private:
00112 
00113   void shadow(labelNode * create, labelNode * shadowed);
00114   void notify_exit_scope(labelNode * dead);
00115 };
00116 
00117 class Tags_table : public SymbolTable< suespecNode * > {
00118 
00119 public:
00120 
00121   Tags_table();
00122 
00123 private:
00124 
00125   void shadow(suespecNode * create, suespecNode * shadowed);
00126   void notify_exit_scope(suespecNode * dead);
00127 };
00128 
00129 class Externals_table : public SymbolTable< declNode * > {
00130 
00131 public:
00132 
00133   Externals_table();
00134 
00135 private:
00136 
00137   void shadow(declNode * create, declNode * shadowed);
00138   void notify_exit_scope(declNode * dead);
00139 };
00140 
00141 // ------------------------------------------------------------
00142 //   Symbols class holds the global information and static
00143 //   symbol table functions.
00144 // ------------------------------------------------------------
00145 
00146 class Symbols {
00147 
00148 public:
00149 
00150   /* Moved to unitNode...
00151   // -- Static functions -------------------
00152 
00153   static void EnterScope();
00154   static void ExitScope();
00155 
00156   // -- Static members ---------------------
00157 
00158   // -- ANSI defines the following name spaces (K&R A11.1, pg 227): 
00159 
00160   static Identifiers_table  * Identifiers;
00161   static Labels_table       * Labels; 
00162   static Tags_table         * Tags;
00163 
00164   // -- This table is used to ensure consistency across the translation unit 
00165 
00166   static Externals_table    * Externals;
00167   */
00168 
00169   static bool TrackScopeExits;
00170   static bool TrackInsertSymbol;
00171   static bool TrackIds;
00172 
00173   static int Level;
00174 };
00175 
00176 
00177 #endif // CBZ_SYMBOL_H

Generated on Thu Jan 10 12:06:20 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001