]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/symbol.cxx
   1 /******************************************************************************* 
   2  * Simplified Wrapper and Interface Generator  (SWIG) 
   4  * Author : David Beazley 
   6  * Department of Computer Science         
   7  * University of Chicago 
  10  * beazley@cs.uchicago.edu 
  12  * Please read the file LICENSE for the copyright and terms by which SWIG 
  13  * can be used and distributed. 
  14  *******************************************************************************/ 
  18 /******************************************************************************* 
  23  * Symbol table management. 
  25  *******************************************************************************/ 
  27 // ----------------------------------------------------------------------------- 
  29 // ----------------------------------------------------------------------------- 
  33     if (name
) delete name
; 
  34     if (type
) delete type
; 
  35     if (value
) delete value
; 
  38   DataType  
*type
;        // Optional datatype 
  39   char      *value
;       // Optional value (for constant expressions) 
  42 static Hash    SymHash
;   // SWIG Symbol table 
  44 // ----------------------------------------------------------------------------- 
  45 // int add_symbol(char *name, DataType *type, char *value) 
  47 // Adds a symbol to the symbol table. Returns -1 if symbol is already in the 
  52 //          type     =  Datatype (for constants).  Optional. 
  53 //          value    =  Value string. Optional. 
  55 // Output : 0 on success, -1 if symbol already exists. 
  57 // Side Effects : None 
  58 // ----------------------------------------------------------------------------- 
  60 int add_symbol(char *name
, DataType 
*type
, char *value
) { 
  66   s
->name 
= copy_string(name
); 
  68     s
->type 
= new DataType(type
); 
  69   else s
->type 
= (DataType 
*) 0; 
  71     s
->value 
= copy_string(value
); 
  72   else s
->value 
= (char *) 0; 
  74   // Add this to the symbol table 
  76   ret 
= SymHash
.add(s
->name
, s
); 
  83 // ----------------------------------------------------------------------------- 
  84 // int lookup_symbol(char *name) 
  86 // Checks to see if a symbol is in the symbol table. 
  88 // Inputs : name   = Symbol name 
  90 // Output : 0 if not found, 1 if found. 
  92 // Side Effects : None 
  93 // ----------------------------------------------------------------------------- 
  95 int lookup_symbol(char *name
) { 
  98   s 
= (Symbol 
*) SymHash
.lookup(name
); 
 103 // ----------------------------------------------------------------------------- 
 104 // DataType *lookup_symtype(char *name) 
 106 // Returns the datatype of a symbol or NULL if not found. 
 108 // Inputs : name   = Symbol name 
 110 // Output : Datatype of symbol, NULL if not found. 
 112 // Side Effects : None 
 113 // ----------------------------------------------------------------------------- 
 115 DataType 
*lookup_symtype(char *name
) { 
 119   s 
= (Symbol 
*) SymHash
.lookup(name
); 
 120   if (s
) return s
->type
; 
 121   else return (DataType 
*) 0; 
 124 // ----------------------------------------------------------------------------- 
 125 // char *lookup_symvalue(char *name) 
 127 // Returns the value associate with a symbol. 
 129 // Inputs : name = Symbol name 
 131 // Output : Symbol value (or NULL if not present). 
 133 // Side Effects : None 
 134 // ----------------------------------------------------------------------------- 
 136 char *lookup_symvalue(char *name
) { 
 140   s 
= (Symbol 
*) SymHash
.lookup(name
); 
 141   if (s
) return s
->value
; 
 142   else return (char *) 0; 
 145 // ----------------------------------------------------------------------------- 
 146 // int update_symbol(char *name, DataType *type, char *value) 
 148 // Updates a symbol (or create it) in the hash table. 
 151 //          name   = Name of symbol 
 152 //          type   = Datatype of symbol (optional) 
 153 //          value  = Symbol value (optional) 
 157 // Side Effects : None 
 158 // ----------------------------------------------------------------------------- 
 160 int update_symbol(char *name
, DataType 
*type
, char *value
) { 
 164   s 
= (Symbol 
*) SymHash
.lookup(name
); 
 166     if (s
->type
) delete s
->type
; 
 167     if (s
->value
) delete s
->value
; 
 169       s
->type 
= new DataType(type
); 
 171       s
->type 
= (DataType 
*) 0; 
 173       s
->value 
= copy_string(value
); 
 175       s
->value 
= (char *) 0; 
 178     return add_symbol(name
, type
, value
); 
 182 // ----------------------------------------------------------------------------- 
 183 // void remove_symbol(char *name) 
 185 // Removes a symbol from the symbol table. 
 187 // Inputs : name = Symbol name. 
 191 // Side Effects : None 
 192 // ----------------------------------------------------------------------------- 
 194 void remove_symbol(char *name
) { 
 195   SymHash
.remove(name
);