/[bison]/bison/src/symtab.c
ViewVC logotype

Diff of /bison/src/symtab.c

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

revision 1.50 by akim, Tue Nov 12 07:55:55 2002 UTC revision 1.51 by akim, Tue Nov 12 08:05:59 2002 UTC
# Line 42  location_t startsymbol_location; Line 42  location_t startsymbol_location;
42  `---------------------------------*/  `---------------------------------*/
43    
44  static symbol_t *  static symbol_t *
45  symbol_new (const char *tag, location_t location)  symbol_new (struniq_t tag, location_t location)
46  {  {
47    symbol_t *res = XMALLOC (symbol_t, 1);    symbol_t *res = XMALLOC (symbol_t, 1);
48    
49    res->tag = xstrdup (tag);    struniq_assert (tag);
50      res->tag = tag;
51    res->location = location;    res->location = location;
52    
53    res->type_name = NULL;    res->type_name = NULL;
# Line 72  symbol_new (const char *tag, location_t Line 73  symbol_new (const char *tag, location_t
73  `------------------------------------------------------------------*/  `------------------------------------------------------------------*/
74    
75  void  void
76  symbol_type_set (symbol_t *symbol, char *type_name, location_t location)  symbol_type_set (symbol_t *symbol, struniq_t type_name, location_t location)
77  {  {
78    if (type_name)    if (type_name)
79      {      {
80        if (symbol->type_name)        if (symbol->type_name)
81          complain_at (location,          complain_at (location,
82                       _("type redeclaration for %s"), symbol->tag);                       _("type redeclaration for %s"), symbol->tag);
83          struniq_assert (type_name);
84        symbol->type_name = type_name;        symbol->type_name = type_name;
85      }      }
86  }  }
# Line 200  symbol_user_token_number_set (symbol_t * Line 202  symbol_user_token_number_set (symbol_t *
202  static void  static void
203  symbol_free (symbol_t *this)  symbol_free (symbol_t *this)
204  {  {
   free (this->tag);  
205    free (this);    free (this);
206  }  }
207    
# Line 376  symbol_translation (symbol_t *this) Line 377  symbol_translation (symbol_t *this)
377  static struct hash_table *symbol_table = NULL;  static struct hash_table *symbol_table = NULL;
378    
379  static bool  static bool
380  hash_compare_symbol_t (const symbol_t *m1, const symbol_t *m2)  hash_compare_symbol (const symbol_t *m1, const symbol_t *m2)
381  {  {
382    return strcmp (m1->tag, m2->tag) == 0;    /* Since tags are unique, we can compare the pointers themselves.  */
383      return STRUNIQ_EQ (m1->tag, m2->tag);
384  }  }
385    
386  static unsigned int  static unsigned int
387  hash_symbol_t (const symbol_t *m, unsigned int tablesize)  hash_symbol (const symbol_t *m, unsigned int tablesize)
388  {  {
389    return hash_string (m->tag, tablesize);    /* Since tags are unique, we can hash the pointer itself.  */
390      return ((size_t) m->tag) % tablesize;
391  }  }
392    
393    
# Line 397  symbols_new (void) Line 400  symbols_new (void)
400  {  {
401    symbol_table = hash_initialize (HT_INITIAL_CAPACITY,    symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
402                                    NULL,                                    NULL,
403                                    (Hash_hasher) hash_symbol_t,                                    (Hash_hasher) hash_symbol,
404                                    (Hash_comparator) hash_compare_symbol_t,                                    (Hash_comparator) hash_compare_symbol,
405                                    (Hash_data_freer) symbol_free);                                    (Hash_data_freer) symbol_free);
406  }  }
407    
# Line 415  symbol_get (const char *key, location_t Line 418  symbol_get (const char *key, location_t
418    symbol_t *entry;    symbol_t *entry;
419    
420    /* Keep the symbol in a printable form.  */    /* Keep the symbol in a printable form.  */
421    key = quotearg_style (escape_quoting_style, key);    key = struniq_new (quotearg_style (escape_quoting_style, key));
422    *(char const **) &probe.tag = key;    *(char const **) &probe.tag = key;
423    entry = hash_lookup (symbol_table, &probe);    entry = hash_lookup (symbol_table, &probe);
424    

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51

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