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

Diff of /bison/src/uniqstr.c

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

revision 1.1 by eggert, Wed Dec 11 05:20:31 2002 UTC revision 1.2 by eggert, Fri Dec 13 08:47:15 2002 UTC
# Line 1  Line 1 
1  /* Keeping a unique copy of strings.  /* Keep a unique copy of strings.
2    
3     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002 Free Software Foundation, Inc.
4    
5     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
# Line 40  static struct hash_table *uniqstrs_table Line 41  static struct hash_table *uniqstrs_table
41  `-------------------------------------*/  `-------------------------------------*/
42    
43  uniqstr  uniqstr
44  uniqstr_new (const char *s)  uniqstr_new (char const *s)
45  {  {
46    uniqstr res = hash_lookup (uniqstrs_table, s);    uniqstr res = hash_lookup (uniqstrs_table, s);
47    if (!res)    if (!res)
# Line 58  uniqstr_new (const char *s) Line 59  uniqstr_new (const char *s)
59  `------------------------------*/  `------------------------------*/
60    
61  void  void
62  uniqstr_assert (const char *s)  uniqstr_assert (char const *s)
63  {  {
64    if (!hash_lookup (uniqstrs_table, s))    if (!hash_lookup (uniqstrs_table, s))
65      {      {
# Line 72  uniqstr_assert (const char *s) Line 73  uniqstr_assert (const char *s)
73  | Print the uniqstr.  |  | Print the uniqstr.  |
74  `--------------------*/  `--------------------*/
75    
76  static bool  static inline bool
77  uniqstr_print (const uniqstr s)  uniqstr_print (uniqstr s)
78  {  {
79    fprintf (stderr, "%s\n", s);    fprintf (stderr, "%s\n", s);
80    return true;    return true;
81  }  }
82    
83    static bool
84    uniqstr_print_processor (void *s, void *null ATTRIBUTE_UNUSED)
85    {
86      return uniqstr_print (s);
87    }
88    
89    
90  /*-----------------------.  /*-----------------------.
91  | A uniqstr hash table.  |  | A uniqstr hash table.  |
92  `-----------------------*/  `-----------------------*/
93    
94  static bool  static bool
95  hash_compare_uniqstr (const uniqstr m1, const uniqstr m2)  hash_compare_uniqstr (void const *m1, void const *m2)
96  {  {
97    return strcmp (m1, m2) == 0;    return strcmp (m1, m2) == 0;
98  }  }
99    
100  static unsigned int  static unsigned int
101  hash_uniqstr (const uniqstr m, unsigned int tablesize)  hash_uniqstr (void const *m, unsigned int tablesize)
102  {  {
103    return hash_string (m, tablesize);    return hash_string (m, tablesize);
104  }  }
105    
 /* A function to apply to each symbol. */  
 typedef bool (*uniqstr_processor) (const uniqstr);  
   
106  /*----------------------------.  /*----------------------------.
107  | Create the uniqstrs table.  |  | Create the uniqstrs table.  |
108  `----------------------------*/  `----------------------------*/
# Line 108  uniqstrs_new (void) Line 112  uniqstrs_new (void)
112  {  {
113    uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY,    uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY,
114                                      NULL,                                      NULL,
115                                      (Hash_hasher) hash_uniqstr,                                      hash_uniqstr,
116                                      (Hash_comparator) hash_compare_uniqstr,                                      hash_compare_uniqstr,
117                                      (Hash_data_freer) free);                                      free);
118  }  }
119    
120    
# Line 119  uniqstrs_new (void) Line 123  uniqstrs_new (void)
123  `-------------------------------------*/  `-------------------------------------*/
124    
125  static void  static void
126  uniqstrs_do (uniqstr_processor processor, void *processor_data)  uniqstrs_do (Hash_processor processor, void *processor_data)
127  {  {
128    hash_do_for_each (uniqstrs_table,    hash_do_for_each (uniqstrs_table, processor, processor_data);
                     (Hash_processor) processor,  
                     processor_data);  
129  }  }
130    
131    
# Line 134  uniqstrs_do (uniqstr_processor processor Line 136  uniqstrs_do (uniqstr_processor processor
136  void  void
137  uniqstrs_print (void)  uniqstrs_print (void)
138  {  {
139    uniqstrs_do (uniqstr_print, NULL);    uniqstrs_do (uniqstr_print_processor, NULL);
140  }  }
141    
142    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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