1 |
/* Keep a unique copy of strings. |
/* Keep a unique copy of strings. |
2 |
|
|
3 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2002, 2003 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. |
6 |
|
|
41 |
`-------------------------------------*/ |
`-------------------------------------*/ |
42 |
|
|
43 |
uniqstr |
uniqstr |
44 |
uniqstr_new (char const *s) |
uniqstr_new (char const *str) |
45 |
{ |
{ |
46 |
uniqstr res = hash_lookup (uniqstrs_table, s); |
uniqstr res = hash_lookup (uniqstrs_table, str); |
47 |
if (!res) |
if (!res) |
48 |
{ |
{ |
49 |
/* First insertion in the hash. */ |
/* First insertion in the hash. */ |
50 |
res = xstrdup (s); |
res = xstrdup (str); |
51 |
hash_insert (uniqstrs_table, res); |
hash_insert (uniqstrs_table, res); |
52 |
} |
} |
53 |
return res; |
return res; |
59 |
`------------------------------*/ |
`------------------------------*/ |
60 |
|
|
61 |
void |
void |
62 |
uniqstr_assert (char const *s) |
uniqstr_assert (char const *str) |
63 |
{ |
{ |
64 |
if (!hash_lookup (uniqstrs_table, s)) |
if (!hash_lookup (uniqstrs_table, str)) |
65 |
{ |
{ |
66 |
error (0, 0, "not a uniqstr: %s", quotearg (s)); |
error (0, 0, "not a uniqstr: %s", quotearg (str)); |
67 |
abort (); |
abort (); |
68 |
} |
} |
69 |
} |
} |
74 |
`--------------------*/ |
`--------------------*/ |
75 |
|
|
76 |
static inline bool |
static inline bool |
77 |
uniqstr_print (uniqstr s) |
uniqstr_print (uniqstr ustr) |
78 |
{ |
{ |
79 |
fprintf (stderr, "%s\n", s); |
fprintf (stderr, "%s\n", ustr); |
80 |
return true; |
return true; |
81 |
} |
} |
82 |
|
|
83 |
static bool |
static bool |
84 |
uniqstr_print_processor (void *s, void *null ATTRIBUTE_UNUSED) |
uniqstr_print_processor (void *ustr, void *null ATTRIBUTE_UNUSED) |
85 |
{ |
{ |
86 |
return uniqstr_print (s); |
return uniqstr_print (ustr); |
87 |
} |
} |
88 |
|
|
89 |
|
|