/[m4]/m4/m4/symtab.c
ViewVC logotype

Diff of /m4/m4/symtab.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by gary, Fri Sep 7 23:47:28 2001 UTC revision 1.20 by gary, Sat Sep 8 01:40:47 2001 UTC
# Line 19  Line 19 
19  */  */
20    
21  /* This file handles all the low level work around the symbol table.  The  /* This file handles all the low level work around the symbol table.  The
22     symbol table is a simple chained hash table.  Each symbol is described     symbol table is an abstract hash table type implemented in hash.c.  Each
23     by a struct symbol, which is placed in the hash table based upon the     symbol is represented by `struct m4_symbol', which is stored in the hash
24     symbol name.  Symbols that hash to the same entry in the table are     table keyed by the symbol name.  As a special case, to facilitate the
25     kept on a list, sorted by name.  As a special case, to facilitate the     "pushdef" and "popdef" builtins, the value stored against each key us a
26     "pushdef" and "popdef" builtins, a symbol can be several times in the     stack of `struct m4_symbol'. All the value entries for a symbol name are
27     symbol table, one for each definition.  Since the name is the same,     simply ordered on the stack by age.  The most recently pushed definition
    all the entries for the symbol will be on the same list, and will  
    also, because the list is sorted, be adjacent.  All the entries for a  
    name are simply ordered on the list by age.  The current definition  
28     will then always be the first found.  */     will then always be the first found.  */
29    
30  #include "m4private.h"  #include "m4private.h"
# Line 124  m4_symbol_del (m4_symbol *symbol) Line 121  m4_symbol_del (m4_symbol *symbol)
121  }  }
122    
123    
124  /* Dispatch on all the following 5 functions.  
   
    Search in, and manipulation of the symbol table, are all done by  
    m4_lookup_symbol ().  It basically hashes NAME to a list in the  
    symbol table, and searched this list for the first occurence of a  
    symbol with the name.  
   
    The MODE parameter determines what m4_lookup_symbol () will do.  It  
    can either just do a lookup, do a lookup and insert if not present,  
    do an insertion even if the name is already in the list, delete the  
    first occurrence of the name on the list or delete all occurences  
    of the name on the list.  */  
 m4_symbol *  
 m4_lookup_symbol (const char *name, m4_symbol_lookup_t mode)  
 {  
   switch (mode)  
     {  
     case M4_SYMBOL_INSERT:  
       return m4_symbol_insert (name);  
   
     case M4_SYMBOL_PUSHDEF:  
       return m4_symbol_pushdef (name);  
     }  
   
   assert (0);  
   /*NOTREACHED*/  
   return 0;  
 }  
   
   
125  /* Return the symbol associated to NAME, or else NULL.  */  /* Return the symbol associated to NAME, or else NULL.  */
126  m4_symbol *  m4_symbol *
127  m4_symbol_lookup (const char *name)  m4_symbol_lookup (const char *name)
# Line 237  m4_symbol_delete (const char *name) Line 205  m4_symbol_delete (const char *name)
205  }  }
206    
207    
208    void
209    m4_symbol_builtin (m4_symbol *symbol, lt_dlhandle handle,
210                       const m4_builtin *bp)
211    {
212      assert (symbol);
213      assert (handle);
214      assert (bp);
215    
216      if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
217        xfree (M4_SYMBOL_TEXT (symbol));
218    
219      M4_SYMBOL_HANDLE (symbol)             = handle;
220      M4_SYMBOL_TYPE (symbol)               = M4_TOKEN_FUNC;
221      M4_SYMBOL_MACRO_ARGS (symbol)         = bp->groks_macro_args;
222      M4_SYMBOL_BLIND_NO_ARGS (symbol)      = bp->blind_if_no_args;
223      M4_SYMBOL_FUNC (symbol)               = bp->func;
224      /* Do not reset M4_SYMBOL_TRACED as it means that --trace would be
225         usable only for existing macros.  m4_symbol_lookup takes care
226         of its proper initialisation.  */
227    }
228    
229    void
230    m4_symbol_macro (m4_symbol *symbol, lt_dlhandle handle, const char *text)
231    {
232      assert (symbol);
233    
234      if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
235        xfree (M4_SYMBOL_TEXT (symbol));
236    
237      M4_SYMBOL_HANDLE (symbol)             = handle;
238      M4_SYMBOL_TYPE (symbol)               = M4_TOKEN_TEXT;
239      M4_SYMBOL_MACRO_ARGS (symbol)         = FALSE;
240      M4_SYMBOL_BLIND_NO_ARGS (symbol)      = FALSE;
241      M4_SYMBOL_TEXT (symbol)               = xstrdup (text);
242      /* Do not reset M4_SYMBOL_TRACED as it means that --trace would be
243         usable only for existing macros.  m4_symbol_lookup takes care
244         of its proper initialisation.  */
245    }
246    
247  /* Remove every symbol that references the given module handle from  /* Remove every symbol that references the given module handle from
248     the symbol table.  */     the symbol table.  */
249  void  void

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26