/[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.23 by gary, Sun Sep 30 14:43:38 2001 UTC revision 1.24 by gary, Sun Sep 30 22:26:57 2001 UTC
# Line 18  Line 18 
18     02111-1307  USA     02111-1307  USA
19  */  */
20    
21    #include "m4private.h"
22    
23    #define DEBUG_SYM               /* Define this to see runtime debug info.  */
24    #undef DEBUG_SYM
25    
26  /* 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
27     symbol table is an abstract hash table type implemented in hash.c.  Each     symbol table is an abstract hash table type implemented in hash.c.  Each
28     symbol is represented by `struct m4_symbol', which is stored in the hash     symbol is represented by `struct m4_symbol', which is stored in the hash
# Line 27  Line 32 
32     simply ordered on the stack by age.  The most recently pushed definition     simply ordered on the stack by age.  The most recently pushed definition
33     will then always be the first found.  */     will then always be the first found.  */
34    
 #include "m4private.h"  
   
35  static size_t   m4_symtab_hash          (const void *key);  static size_t   m4_symtab_hash          (const void *key);
36  static int      m4_symtab_cmp           (const void *key, const void *try);  static int      m4_symtab_cmp           (const void *key, const void *try);
37  static void     m4_token_data_delete    (m4_token_data *data);  static void     m4_token_data_delete    (m4_token_data *data);
38  static void     m4_symbol_pop           (m4_symbol *symbol);  static void     m4_symbol_pop           (m4_symbol *symbol);
39  static void     m4_symbol_del           (m4_symbol *symbol);  static void     m4_symbol_del           (m4_symbol *symbol);
40    static int      m4_symbol_destroy       (const char *name, m4_symbol *symbol,
41                                             void *data);
42    
43    
44  /* Pointer to symbol table.  */  /* Pointer to symbol table.  */
# Line 47  m4_symtab_init (void) Line 52  m4_symtab_init (void)
52    m4_symtab = m4_hash_new (m4_symtab_hash, m4_symtab_cmp);    m4_symtab = m4_hash_new (m4_symtab_hash, m4_symtab_cmp);
53  }  }
54    
55    int
56    m4_symbol_destroy (const char *name, m4_symbol *symbol, void *data)
57    {
58      m4_symbol_delete (name);
59      return 0;
60    }
61    
62    void
63    m4_symtab_exit (void)
64    {
65      m4_symtab_apply (m4_symbol_destroy, NULL);
66      m4_hash_delete (m4_symtab);
67      m4_hash_exit ();
68    }
69    
70  /* Return a hashvalue for a string, from GNU-emacs.  */  /* Return a hashvalue for a string, from GNU-emacs.  */
71  size_t  static size_t
72  m4_symtab_hash (const void *key)  m4_symtab_hash (const void *key)
73  {  {
74    int val = 0;    int val = 0;
# Line 65  m4_symtab_hash (const void *key) Line 85  m4_symtab_hash (const void *key)
85    return val;    return val;
86  }  }
87    
88  int  static int
89  m4_symtab_cmp (const void *key, const void *try)  m4_symtab_cmp (const void *key, const void *try)
90  {  {
91    return (strcmp ((const char *) key, (const char *) try));    return (strcmp ((const char *) key, (const char *) try));
# Line 73  m4_symtab_cmp (const void *key, const vo Line 93  m4_symtab_cmp (const void *key, const vo
93    
94    
95    
96  void  static void
97  m4_token_data_delete (m4_token_data *data)  m4_token_data_delete (m4_token_data *data)
98  {  {
99    assert (data);    assert (data);
# Line 167  m4_symbol_pushdef (const char *name) Line 187  m4_symbol_pushdef (const char *name)
187  m4_symbol *  m4_symbol *
188  m4_symbol_define (const char *name)  m4_symbol_define (const char *name)
189  {  {
190    m4_symbol *res = m4_symbol_lookup (name);    m4_symbol **psymbol = (m4_symbol **) m4_hash_lookup (m4_symtab, name);
191    if (res)    if (psymbol)
192      return res;      return *psymbol;
193    else    else
194      m4_symbol_pushdef (name);      return m4_symbol_pushdef (name);
195  }  }
196    
197    
# Line 200  m4_symbol_delete (const char *name) Line 220  m4_symbol_delete (const char *name)
220    m4_symbol **psymbol = (m4_symbol **) m4_hash_lookup (m4_symtab, name);    m4_symbol **psymbol = (m4_symbol **) m4_hash_lookup (m4_symtab, name);
221    
222    assert (psymbol);    assert (psymbol);
223    
224    #ifdef DEBUG_SYM
225      M4_DEBUG_MESSAGE1("symbol %s recycled.", name);
226    #endif
227    
228    xfree (m4_hash_remove (m4_symtab, name));    xfree (m4_hash_remove (m4_symtab, name));
229    m4_symbol_del (*psymbol);    m4_symbol_del (*psymbol);
230  }  }
# Line 253  m4_symtab_remove_module_references (lt_d Line 278  m4_symtab_remove_module_references (lt_d
278    
279    assert (handle);    assert (handle);
280    
281       /* Traverse each symbol name in the hash table.  */
282    while ((place = m4_hash_iterator_next (m4_symtab, place)))    while ((place = m4_hash_iterator_next (m4_symtab, place)))
283      {      {
284        m4_symbol *symbol = (m4_symbol *) m4_hash_iterator_value (place);        m4_symbol *symbol = (m4_symbol *) m4_hash_iterator_value (place);
# Line 286  m4_symtab_remove_module_references (lt_d Line 312  m4_symtab_remove_module_references (lt_d
312      }      }
313  }  }
314    
315  /* The following function is used for the cases, where we want to do  /* The following function is used for the cases where we want to do
316     something to each and every symbol in the table.  The function     something to each and every symbol in the table.  The function
317     hack_all_symbols () traverses the symbol table, and calls a specified     m4_symtab_apply () traverses the symbol table, and calls a specified
318     function FUNC for each symbol in the table.  FUNC is called with a     function FUNC for each symbol in the table.  FUNC is called with a
319     pointer to the symbol, and the DATA argument.  */     pointer to the symbol, and the DATA argument.  */
320  int  int
# Line 327  symtab_debug (void) Line 353  symtab_debug (void)
353    m4_symbol *s;    m4_symbol *s;
354    int delete;    int delete;
355    
356    while ((t = m4_next_token (&td)) != NULL)    while ((t = m4_next_token (&td)) != M4_TOKEN_EOF)
357      {      {
358        if (t != M4_TOKEN_WORD)        if (t != M4_TOKEN_WORD)
359          continue;          continue;

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

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