Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

sym.h

Go to the documentation of this file.
00001 
00002 #ifndef SYM_H
00003 #define SYM_H
00004 
00005 /*
00006    include dependencies:
00007 
00008    stdlib.h     -- for NULL
00009    stdtypes.h
00010    string.h
00011    type.h
00012    str.h        -- definition for STRING
00013 
00014  */
00015 
00016 #include "typedefs.h"
00017 #include "list.h"
00018 #include "const.h"
00019 
00020 
00021 /*===============================<o>=====================================
00022 
00023 Copyright 1996, 1997, 2004 Ian Kaplan, Bear Products International,
00024 www.bearcave.com.
00025 
00026 All Rights Reserved
00027 
00028 You may use this software in software components for which you do
00029 not collect money (e.g., non-commercial software).  All commercial
00030 use is reserved.
00031 
00032 ===============================<o>=====================================*/
00033 
00034 
00044 class src_ref {
00045     ushort file_num;   // handle in the file name table
00046     ushort offset;     // char offset within the line
00047     uint line_num;     // line number within the file
00048 }; // src_ref
00049 
00050 
00051 enum { bad_symbol,
00052        sy_ident,
00053        sy_type,
00054        sy_const,          // an enumeration value, a defined constant
00055        sy_subprog,
00056        sy_component,      // an elaborated entity/architecture pair
00057        sy_package,        // both declaration parts and body
00058        sy_process,
00059        sy_block_label    // its not clear this is needed
00060     };
00061 
00062 class symtable;
00063 class typetable;
00064 
00073 class sym {
00074 private:
00075     STRING name;       // Symbol name, entered into the string table
00076     src_ref  m_sr;     // source location for the declaration
00077     uint m_referenced : 1,  // symbol was referenced
00078          m_unused     : 31;
00079 
00080 public:
00081     sym(STRING n )
00082     {
00083         name = n;
00084         m_referenced = FALSE;
00085     } // sym constructor
00086 
00087     sym( )
00088     {
00089         name.SetText( NULL );
00090         m_referenced = FALSE;
00091     } // sym constructor
00092 
00093 
00094     void *operator new( unsigned int num_bytes )
00095     {
00096         assert( FALSE );
00097         return NULL;
00098     }
00099 
00100     //
00101     // Overloaded new
00102     //
00103     void *operator new( unsigned int num_bytes, pool *mem_pool )
00104     {
00105         return mem_pool->GetMem( num_bytes );
00106     }
00107 
00108     // Memory is recovered by deleting the memory pool.  So delete
00109     // should do nothing.
00110     void operator delete( void *addr ) {/* do nothing */}
00111 
00112     STRING get_name(void) { return name; }
00113     void set_name( const STRING str ) { name = str; }
00114 
00115     void set_referenced(void) { m_referenced = TRUE; }
00116     void unset_referenced(void) { m_referenced = FALSE; }
00117     const Boolean is_referenced(void) { return m_referenced; }
00118     
00119     //
00120     // Virtual functions common to all classes
00121     //
00122     virtual const uint get_sy_kind(void) { return bad_symbol; }
00123 
00124     //
00125     // Virtual functions for derived classes
00126     //
00127     // -- sym_scoped subclass
00128     //
00129     virtual void set_scope( pSym scope )
00130     {
00131         assert( FALSE );
00132     }
00133     //
00134     // get_scope default class
00135     //
00136     // Return null if there is no scope, since this
00137     // is one way to test this characteristic of
00138     // a symbol.
00139     virtual const pSym get_parent_scope(void) 
00140     {
00141         return NULL;
00142     }
00143     //
00144     // -- sym_const subclass
00145     //
00146     virtual void set_const( pConst c )
00147     {
00148         assert( FALSE );
00149     }
00150     virtual const pConst get_const(void)
00151     {
00152         assert( NULL );
00153         return NULL;
00154     }
00155     //
00156     // -- sym_type subclass
00157     //
00158     virtual void set_ty_type( pType t ) 
00159     { 
00160         assert( NULL );
00161     } // set_type
00162     virtual const pType get_ty_type(void) 
00163     { 
00164         assert( FALSE );
00165         return NULL; 
00166     } // get_type
00167     //
00168     // -- sym_ident subclass
00169     //
00170     virtual void set_alloc( uint alloc )
00171     {
00172         assert( FALSE );
00173     } // set_offset
00174     virtual const uint get_alloc(void)
00175     {
00176         assert( FALSE );
00177         return 0;
00178     }
00179     virtual void set_id_kind( uint kind )
00180     {
00181         assert( FALSE );
00182     }
00183     virtual const uint get_id_kind(void)
00184     {
00185         assert( FALSE );
00186         return 0;
00187     }
00188     virtual void set_id_type( pType t ) 
00189     { 
00190         assert( FALSE );
00191     } // set_id_type
00192     virtual const pType get_id_type(void) 
00193     { 
00194         assert( FALSE );
00195         return NULL; 
00196     }
00197     //
00198     // -- sym_scope subclass
00199     //
00200     virtual sym *LookupFromScope(STRING s)
00201     {
00202         assert( FALSE );
00203         return NULL;
00204     }
00205     virtual sym *LookupFromScope(const char *pChar )
00206     {
00207         assert( FALSE );
00208         return NULL;
00209     }
00210     virtual symtable *get_symtab(void)
00211     {
00212         assert( FALSE );
00213         return NULL;
00214     }
00215 
00216     virtual typetable *get_typtab(void)
00217     {
00218         assert( FALSE );
00219         return NULL;
00220     }
00221     virtual Boolean has_scope()
00222     {
00223         // return false for any symbol that is not of
00224         // the sym_scope sub-class
00225         return FALSE;
00226     }
00227     //
00228     // -- sym_subprog subclass
00229     //
00230     virtual void set_statement( NODE *s )
00231     {
00232         assert( FALSE );
00233     }
00234     virtual const NODE *get_statement(void)
00235     {
00236         assert( FALSE );
00237         return NULL;
00238     }
00239 
00240     virtual void set_func_type( pType t )
00241     {
00242         assert( FALSE );
00243     }
00244     virtual const pType get_func_type(void)
00245     {
00246         assert( FALSE );
00247         return NULL;
00248     }
00249     //
00250     // -- sym_component subclass
00251     //
00252     virtual void init(void)
00253     {
00254         // its ok to do nothing if there's nothing to initialize
00255     }
00256     virtual void dealloc(void)
00257     {
00258         // its ok to do nothing if there's nothing to deallocate
00259     }
00260     // Allocate memory from the pool that is local to the 
00261     // component.
00262     virtual void *GetMem( uint num_bytes )
00263     {
00264         assert( FALSE );
00265         return NULL;
00266     }
00267 
00268     virtual LIST<sym *> *get_proc_list(void)
00269     {
00270         assert( FALSE );
00271         return NULL;
00272     }
00273     virtual LIST<NODE *> *get_sigass_list(void)
00274     {
00275         assert( FALSE );
00276         return NULL;
00277     }
00278 };  // class sym
00279 
00280 
00281 
00332 class sym_scoped : public sym {
00333 private:
00334     pSym parent_scope;
00335 
00336 public:
00337     sym_scoped(STRING n) : sym( n )
00338     { 
00339         parent_scope = NULL; 
00340     }
00341 
00342     sym_scoped()
00343     {
00344         parent_scope = NULL;
00345     }
00346 
00347     void set_scope( pSym scope )
00348     {
00349         parent_scope = scope;
00350     }
00351     const pSym get_parent_scope(void) 
00352     {
00353         return parent_scope;
00354     }
00355 }; // sym_scoped
00356 
00357 
00358 #endif

Generated on Wed Mar 31 21:15:55 2004 for Data Structures for a VHDL Compiler by doxygen 1.3.3