Polaris: Symtab.h Source File

Symtab.h

Go to the documentation of this file.
00001 ///
00002 /// file Symtab.h
00003 ///
00004 #ifndef SYMTAB_H
00005 #define SYMTAB_H
00006 ///
00007 /// \class Symtab 
00008 /// \brief a Symbol Table class
00009 /// \defgroup Polaris
00010 /// \ingroup Polaris
00011 ///  C++ VDL
00012 /// \see Symtab.h
00013 /// \see Symtab.h
00014 /// \see Symtab.cc
00015 ///
00016 /// \endcode
00017 /// \section Description Description
00018 /// Symtab is a symbol table.
00019 ///
00020 /// Note that the Symtab::Symtab(const BinRep &binstr) method is NOT
00021 /// enough to completely read in the correct symbol table from the
00022 /// binstr.  Because it is necessary to have the symbol table before
00023 /// other objects, such as the expression table, are created, and
00024 /// vice versa, the constructor just mentioned only creates the
00025 /// various symbols and gives them their proper type and name.
00026 /// After the expression table, etc., are available, the method
00027 /// void fill_in(...) does the rest of the conversion.
00028 ///
00029 /// \endcode
00030 /// \section Usage Usage
00031 /// Examples:
00032 ///
00033 /// Symtab symtab;
00034 /// ...
00035 /// cout << symtab["J"].is_array() << "\n";
00036 ///
00037 /// To insert a new Symbol pointer, you can use notation like the following:
00038 ///
00039 /// Symbol &sym = symtab.ins(
00040 ///   new SymbolicConstantSymbol("PI",
00041 ///                              <expr-containing-PI-constant>));
00042 ///
00043 /// Using the return value of the ins() method is not necessary, but it
00044 /// has the advantage of allowing one to easily get a reference to the
00045 /// newly-inserted symbol with having to dereference, which may be
00046 /// confusing.  The following is just as valid, although perhaps more
00047 /// awkward:
00048 ///
00049 /// Symbol &sym =
00050 ///   * new SymbolicConstantSymbol("PI",
00051 ///                                <expr-containing-PI-constant>));
00052 /// symtab.ins(&sym);
00053 ///
00054 /// The following is also valid, although perhaps not as good style
00055 /// because afterwards you have a pointer to the symbol rather than
00056 /// a reference (which may be confusing because you have to think
00057 /// to decide whether or not you are in charge of deleteing it--
00058 /// which in this case you are not):
00059 ///
00060 /// Symbol *sym =
00061 ///   new SymbolicConstantSymbol("PI",
00062 ///                              <expr-containing-PI-constant>));
00063 /// symtab.ins(sym);
00064 ///
00065 ///
00066 /// The first example is this author's preferred style.
00067 ///
00068 /// Either way, the newly-inserted symbol will automatically be deleted
00069 /// when symtab is destroyed.
00070 ///
00071 #ifdef POLARIS_GNU_PRAGMAS
00072 #pragma interface
00073 #endif
00074 ///
00075 #include "ClassNames.h"
00076 #include "define.h"
00077 #include "Dictionary.h"
00078 #include "Collection/KeyIterator.h"
00079 #include "Symbol/Symbol.h"
00080 ///
00081 #define _T3D_NUM_PES "N$PES"   ///_ Must be the same as the definition in
00082                                ///_ t3d_convert.h 
00083 ///
00084 class ProgramUnit;
00085 class VDL;
00086 
00087 class Symtab {
00088     friend ostream & operator << (ostream & o, const Symtab & symtab);
00089 
00090  private:
00091     Dictionary<Symbol> _dict;
00092 
00093  public:
00094     Symtab();
00095     virtual ~Symtab();
00096 
00097     Symtab(const Symtab &s);
00098     ///< Copy constructor.
00099 
00100     Symtab &operator =(const Symtab &s);
00101     ///< Assignment operator.
00102 
00103     virtual Symtab *clone() const;
00104     ///< Create a clone of the Symtab.
00105 
00106     Symtab(const BinRep & binstr);
00107 
00108     void            fill_in(const BinRep & binstr,
00109                             ExprTable & exprs,
00110                             const Dictionary<VoidPtrDef>&stmts,
00111                             const Dictionary<VoidPtrDef>&commons,
00112                             const Dictionary<VoidPtrDef>&equivalences);
00113 
00114     Symbol &        ins(Symbol * new_symbol);
00115     ///< Insert a new symbol into symbol table.  This new symbol is
00116     ///< automatically deleted when the symbol table is destroyed
00117     ///< (which means that new_symbol must have been created dynamically
00118     ///< using the keyword "new").  If the name of new_symbol is already
00119     ///< in the symbol table, an error indication is given and the
00120     ///< program aborts.  If name conflicts might be a problem, use
00121     ///< rename_and_ins(...) instead.
00122 
00123     Symbol &        rename_and_ins(Symbol * sym);
00124     ///< Renames sym (only if needed) in such a way that there are
00125     ///< no naming conflicts, then inserts sym into the symbol table
00126 
00127     Symbol &        ins_intrinsic(const char *name);
00128     ///< Checks to see if the intrinsic exists, if it does not then
00129     ///< it finds it's type from the intrinsic table and creates it.
00130 
00131     Symbol  const  *find_ref(const char *symbol_name) const;
00132     Symbol         *find_ref(const char *symbol_name) ;
00133     ///< returns pointer to Symbol if found, 0 if not found
00134 
00135     const Symbol & operator[] (const char *symbol_name) const;
00136     Symbol &       operator[] (const char *symbol_name) ;
00137     ///< returns reference to a Symbol if found, causes error otherwise
00138 
00139     void            del(const char *sym_name);
00140     ///< deletes if found, ignores otherwise
00141 
00142     Symbol         *grab(const char *symbol_name);
00143     ///< Unlinks (removes from the symbol table but DOES NOT delete)
00144     ///< and returns a pointer to the symbol.  The user is then
00145     ///< responsible for deleting the symbol.  Returns 0 if not found.
00146 
00147     int            entries() const;
00148     ///< returns number of entries
00149 
00150     void            absorb(Symtab & other);
00151     ///< "Absorbs" the other symbol table into itself.  I.e., removes all
00152     ///< symbols from other, renames them as necessary to avoid naming
00153     ///< conflicts, and inserts them all into this symbol table.
00154 
00155     DictionaryIter<Symbol> iterator() const;
00156     ///< Return an iterator over all symbols of this symbol table
00157 
00158     void write(ostream & o, int space_for_label = 0,
00159                int max_line_len = FORTRAN_MAX_LINE_LEN) const;
00160     ///< Write to stream in Fortran declarations format (including type
00161     ///< statements such as INTEGER*4 as well as DIMENSION and SAVE
00162     ///< statements.
00163     ///< space_for_label should be 0 for FORTRAN output, or the length to
00164     ///< to allocate for statement labels (such as "S10") if debugging
00165     ///< output is desired.
00166 
00167     virtual int     structures_OK() const;
00168     ///< Check the structure of the data for errors or inconsistency
00169     ///< Return 0 and print error message if problems found, otherwise
00170     ///< return 1 without message.
00171 
00172     virtual void    exchange_convert( VDL &vdl );
00173     ///< Convert the Symbol table into the exchange format.
00174 
00175     void relink_ptrs( ProgramUnit &p);
00176     ///< Change the pointers within a Symtab element to
00177     ///< point within the given ProgramUnit.
00178     
00179     ///< silvius: Symbol Table bug fix:
00180     ///< when changing the name of the symbol, its key in the symtab does
00181     ///< not change.  You cannot do the following sequence:
00182     ///< rename(i,j); insert(i)
00183     ///< The symtab will complain that i still exists even after it
00184     ///< was renamed.
00185     void rename(const char* tag, const char* newtag) {
00186       _dict.rename(tag, newtag);
00187     }
00188 };
00189 
00190 
00191 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:15 2005