00001 00002 #ifndef DSYM_H 00003 #define DSYM_H 00004 00014 /*===============================<o>===================================== 00015 00016 Copyright 1996, 1997, 2004 Ian Kaplan, Bear Products International, 00017 www.bearcave.com. 00018 00019 All Rights Reserved 00020 00021 You may use this software in software components for which you do 00022 not collect money (e.g., non-commercial software). All commercial 00023 use is reserved. 00024 00025 ===============================<o>=====================================*/ 00026 00027 #include "stdtypes.h" 00028 #include "sym.h" 00029 #include "type.h" 00030 #include "const.h" 00031 #include "symtable.h" 00032 #include "typetable.h" 00033 00034 #ifndef NULL 00035 #define NULL 0 00036 #endif 00037 00038 00046 class sym_const : public sym { 00047 private: 00048 pConst konst; 00049 00050 public: 00051 sym_const(STRING n) : sym( n ) 00052 { 00053 konst = NULL; 00054 } 00055 00056 sym_const() 00057 { 00058 konst = NULL; 00059 } 00060 00061 const uint get_sy_kind(void) { return sy_const; } 00062 00063 void set_const( pConst c ) 00064 { 00065 konst = c; 00066 } 00067 const pConst get_const(void) 00068 { 00069 return konst; 00070 } 00071 }; // sym_const 00072 00073 00074 00084 class sym_type : public sym { 00085 private: 00086 pType ty; 00087 00088 public: 00089 sym_type(STRING n ) : sym( n ) 00090 { 00091 ty = NULL; 00092 } // sym_type constructor 00093 00094 sym_type() 00095 { 00096 ty = NULL; 00097 } 00098 00099 const uint get_sy_kind(void) { return sy_type; } 00100 00101 const pType get_ty_type(void) 00102 { 00103 return ty; 00104 } // get_type 00105 void set_ty_type( pType t ) 00106 { 00107 assert( t != NULL ); 00108 ty = t; 00109 } // set_type 00110 00111 }; // sym_type 00112 00113 00114 00115 enum { sy_bad_alloc, 00116 sy_static_id, 00117 sy_frame_id 00118 }; 00119 00120 enum { sy_bad_ident_type, 00121 sy_signal, 00122 sy_variable }; 00123 00161 class sym_ident : public sym_scoped { 00162 private: 00163 pType ty; 00164 uint id_alloc : 3, // sy_static_id, sy_frame_id, ... 00165 id_kind : 3, // sy_signal, sy_variable 00166 unused : 26; 00167 public: 00168 sym_ident(STRING n) : sym_scoped( n ) 00169 { 00170 ty = NULL; 00171 id_alloc = sy_bad_alloc; 00172 id_kind = sy_bad_ident_type; 00173 } 00174 00175 sym_ident() 00176 { 00177 ty = NULL; 00178 id_alloc = sy_bad_alloc; 00179 id_kind = sy_bad_ident_type; 00180 } 00181 00182 const uint get_sy_kind(void) { return sy_ident; } 00183 00184 void set_alloc( uint alloc ) 00185 { 00186 id_alloc = alloc; 00187 } // set_offset 00188 const uint get_alloc(void) 00189 { 00190 return id_alloc; 00191 } 00192 00193 void set_id_kind( uint kind ) 00194 { 00195 id_kind = kind; 00196 } 00197 const uint get_id_kind(void) 00198 { 00199 return id_kind; 00200 } 00201 00202 void set_id_type( pType t ) 00203 { 00204 assert( t != NULL ); 00205 ty = t; 00206 } // set_type 00207 const pType get_id_type(void) 00208 { 00209 return ty; 00210 } // get_type 00211 }; // sym_ident 00212 00213 00214 00223 class sym_scope : public sym_scoped { 00224 private: 00225 sym *find_in_scope( sym *pSym, STRING sym_name ); 00226 00227 private: 00229 sym_scope( const sym_scope &s ) 00230 { 00231 assert( FALSE ); 00232 } 00233 00234 protected: 00235 symtable symtab; 00236 typetable typtab; 00237 00238 public: 00239 // 00240 // constructors 00241 // 00242 sym_scope(STRING n ) : sym_scoped( n ) 00243 { 00244 } 00245 00246 sym_scope() 00247 { 00248 } 00249 00250 void dealloc(void) 00251 { 00252 symtab.dealloc(); 00253 typtab.~typetable(); 00254 } 00255 //upwards lookup starting from 'this' scope 00256 sym *LookupFromScope(STRING s); 00257 00258 sym *LookupFromScope(const char *pChar ) 00259 { 00260 STRING local_str; 00261 00262 local_str.SetText( pChar ); 00263 return LookupFromScope( local_str ); 00264 } 00265 00266 symtable *get_symtab(void) 00267 { 00268 return &symtab; 00269 } 00270 00271 typetable *get_typtab(void) 00272 { 00273 return &typtab; 00274 } 00275 00279 Boolean has_scope() 00280 { 00281 return TRUE; 00282 } 00283 }; // sym_scope 00284 00285 00297 class sym_subprog : public sym_scope { 00298 private: 00299 pType ty; 00300 NODE *tree; 00301 00302 public: 00303 FIFO_LIST<sym_ident *> arg_list; 00304 00305 public: 00306 sym_subprog(STRING n ) : sym_scope( n ) 00307 { 00308 tree = NULL; 00309 ty = NULL; 00310 } 00311 00312 sym_subprog() 00313 { 00314 tree = NULL; 00315 ty = NULL; 00316 } 00317 00318 const uint get_sy_kind(void) { return sy_subprog; } 00319 00320 void set_statement( NODE *s ) 00321 { 00322 tree = s; 00323 } 00324 const NODE *get_statement(void) 00325 { 00326 return tree; 00327 } 00328 00329 void set_func_type( pType t ) 00330 { 00331 ty = t; 00332 } 00333 00334 const pType get_func_type(void) 00335 { 00336 return ty; 00337 } 00338 00339 }; // sym_subprog 00340 00341 00360 class sym_process : public sym_scope { 00361 public: 00362 LIST<sym_ident *> active_list; // process activation list 00363 00364 public: 00365 sym_process(STRING n ) : sym_scope( n ) 00366 { 00367 } 00368 sym_process() 00369 { 00370 } 00371 00372 const uint get_sy_kind(void) { return sy_process; } 00373 }; 00374 00375 00393 class sym_component : public sym_scope { 00394 private: 00395 pool mem; // memory pool for this component 00396 00397 private: 00398 // No copy constructor allowed 00399 sym_component( const sym_component &c ) 00400 { 00401 assert( FALSE ); 00402 } 00403 00404 void proc_list_dealloc(void); 00405 00406 private: 00407 LIST<sym *> proc_list; // list of processes 00408 LIST<NODE *> sigass_list; // list of signal assignments 00409 00410 public: 00411 sym_component( STRING n ) : sym_scope( n ) 00412 { 00413 init(); 00414 } 00415 sym_component() 00416 { 00417 init(); 00418 } 00419 00420 ~sym_component() 00421 { 00422 dealloc(); 00423 } 00424 00425 const uint get_sy_kind(void) { return sy_component; } 00426 00427 void init(void) 00428 { 00430 mem.new_pool(); 00433 symtab.set_pool( &mem ); 00434 typtab.set_pool( &mem ); 00435 00436 } 00437 void dealloc(void) 00438 { 00440 sym_scope::dealloc(); 00441 proc_list_dealloc(); 00442 sigass_list.dealloc(); 00444 mem.delete_pool(); 00445 } 00446 00447 00451 void *GetMem( uint num_bytes ) 00452 { 00453 void *pMem; 00454 00455 pMem = mem.GetMem( num_bytes ); 00456 return pMem; 00457 } 00458 00459 LIST<sym *> *get_proc_list(void) 00460 { 00461 return &proc_list; 00462 } 00463 LIST<NODE *> *get_sigass_list(void) 00464 { 00465 return &sigass_list; 00466 } 00467 }; // sym_component 00468 00469 00470 #endif