"Fossies" - the Fresh Open Source Software Archive

Member "erltools/pub/library/symb.h" (4 Oct 2000, 2990 Bytes) of package /linux/misc/old/erltools-4.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "symb.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef SYMBOL_TABLE
    2 #define SYMBOL_TABLE 1
    3 #include "smtoken.h"
    4 #include "tablist.h"
    5 
    6 class SymbolTable {
    7     
    8     public :
    9     
   10         //constructor
   11         SymbolTable ()
   12             : pvSize(0),  pvSizeMax(0),  pvTable(0)
   13         {}
   14         
   15         // copy constructor
   16         // parameters :
   17         //              symbTab : copied symboltable
   18         SymbolTable (SymbolTable &symbTab) ;
   19         
   20         // destructor
   21         ~SymbolTable ()
   22         {
   23             TabList **ptLevel = pvTable + pvSize - 1 ; // pointer on a level
   24             
   25             // free each level
   26             for (; pvSize > 0 ; ptLevel--, pvSize-- ) {
   27                 delete *ptLevel ;
   28             }
   29             
   30             // free the table
   31             if ( pvTable ) {
   32                 free(pvTable);
   33                 pvTable = 0 ;
   34             }
   35         }
   36         
   37         // add a level to table with initalization
   38         // parameters :
   39         //              initList : list of variable decl
   40         // return : number of levels
   41         int     AddLevel (PPTREE initList = 0) ;
   42         
   43         // remove a level to the table
   44         int     RemoveLevel () ;
   45         
   46         // insert a var at the current level
   47         void    AddVar (const PTREE &) ;
   48         
   49         // remove a var at the current level
   50         void    RemoveVar (const PTREE &) ;
   51         
   52         // get a var definition
   53         PTREE GetVar ( const PTREE &tree, int startLevel = - 1 )
   54         {
   55             return GetVar(Value(tree), startLevel);
   56         }
   57         
   58         PTREE operator[] ( PTREE tree )
   59         {
   60             return GetVar(tree);
   61         }
   62         
   63         // get a var definition by its name
   64         PTREE   GetVar (const char *name, int startLevel = - 1) ;
   65         
   66         PTREE operator[] ( const char *name )
   67         {
   68             return GetVar(name, pvSize - 1);
   69         }
   70         
   71         // GetList : get a list at a given level
   72         TabList *GetTabList ( int level )
   73         {
   74             if ( level < pvSize && level >= 0 ) 
   75                 return pvTable [level];
   76             else 
   77                 return (TabList *)0 ;
   78         }
   79         
   80         // Size : get size of current table
   81         // return : the size
   82         int Size () const
   83         {
   84             return pvSize ;
   85         }
   86         
   87         // LastLevel : return level at which last search succeeded
   88         // return : the level
   89         int LastLevel () const
   90         {
   91             return pvLastLevel ;
   92         }
   93         
   94         // operator = 
   95         // parameters :
   96         //              symbTable : the copied table
   97         const SymbolTable   &operator= (SymbolTable &symbTable) ;
   98     
   99     private :
  100     
  101         TabList **pvTable ;       // the table
  102         TabList *pvCurrentLevel ; // current level of table
  103         int     pvSize ;          // current size of table
  104         int     pvSizeMax ;       // current allocated space for table
  105         int     pvLastLevel ;     // level of success of last search
  106 };
  107 #endif