mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 13:53:03 +00:00
* src/struniq.h, src/struniq.c (struniq_t): Is const.
(STRUNIQ_EQ, struniq_assert, struniq_assert_p): New. Use struniq for symbols. * src/symtab.h (symbol_t): The tag member is a struniq. (symbol_type_set): Adjust. * src/symtab.c (symbol_new): Takes a struniq. (symbol_free): Don't free the tag member. (hash_compare_symbol_t, hash_symbol_t): Rename as... (hash_compare_symbol, hash_symbol): these. Use the fact that tags as struniqs. (symbol_get): Use struniq_new. * src/symlist.h, src/symlist.c (symbol_list_n_type_name_get): Returns a strniq. * src/reader.h (merger_list, grammar_currentmerge_set): The name and type members are struniqs. * src/reader.c (get_merge_function) (grammar_current_rule_merge_set): Adjust. (TYPE, current_type): Are struniq. Use struniq for file names. * src/files.h, src/files.c (infile): Split into... (grammar_file, current_file): these. * src/scan-gram.c (YY_USER_INIT, handle_syncline): Adjust. * src/reduce.c (reduce_print): Likewise. * src/getargs.c (getargs): Likewise. * src/complain.h, src/complain.c: Likewise. * src/main.c (main): Call struniqs_new early enough to use it for file names. Don't free the input file name.
This commit is contained in:
25
src/symtab.c
25
src/symtab.c
@@ -42,11 +42,12 @@ location_t startsymbol_location;
|
||||
`---------------------------------*/
|
||||
|
||||
static symbol_t *
|
||||
symbol_new (const char *tag, location_t location)
|
||||
symbol_new (struniq_t tag, location_t location)
|
||||
{
|
||||
symbol_t *res = XMALLOC (symbol_t, 1);
|
||||
|
||||
res->tag = xstrdup (tag);
|
||||
struniq_assert (tag);
|
||||
res->tag = tag;
|
||||
res->location = location;
|
||||
|
||||
res->type_name = NULL;
|
||||
@@ -72,13 +73,14 @@ symbol_new (const char *tag, location_t location)
|
||||
`------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
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)
|
||||
{
|
||||
if (type_name)
|
||||
{
|
||||
if (symbol->type_name)
|
||||
complain_at (location,
|
||||
_("type redeclaration for %s"), symbol->tag);
|
||||
struniq_assert (type_name);
|
||||
symbol->type_name = type_name;
|
||||
}
|
||||
}
|
||||
@@ -200,7 +202,6 @@ symbol_user_token_number_set (symbol_t *symbol,
|
||||
static void
|
||||
symbol_free (symbol_t *this)
|
||||
{
|
||||
free (this->tag);
|
||||
free (this);
|
||||
}
|
||||
|
||||
@@ -376,15 +377,17 @@ symbol_translation (symbol_t *this)
|
||||
static struct hash_table *symbol_table = NULL;
|
||||
|
||||
static bool
|
||||
hash_compare_symbol_t (const symbol_t *m1, const symbol_t *m2)
|
||||
hash_compare_symbol (const symbol_t *m1, const symbol_t *m2)
|
||||
{
|
||||
return strcmp (m1->tag, m2->tag) == 0;
|
||||
/* Since tags are unique, we can compare the pointers themselves. */
|
||||
return STRUNIQ_EQ (m1->tag, m2->tag);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
hash_symbol_t (const symbol_t *m, unsigned int tablesize)
|
||||
hash_symbol (const symbol_t *m, unsigned int tablesize)
|
||||
{
|
||||
return hash_string (m->tag, tablesize);
|
||||
/* Since tags are unique, we can hash the pointer itself. */
|
||||
return ((size_t) m->tag) % tablesize;
|
||||
}
|
||||
|
||||
|
||||
@@ -397,8 +400,8 @@ symbols_new (void)
|
||||
{
|
||||
symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
|
||||
NULL,
|
||||
(Hash_hasher) hash_symbol_t,
|
||||
(Hash_comparator) hash_compare_symbol_t,
|
||||
(Hash_hasher) hash_symbol,
|
||||
(Hash_comparator) hash_compare_symbol,
|
||||
(Hash_data_freer) symbol_free);
|
||||
}
|
||||
|
||||
@@ -415,7 +418,7 @@ symbol_get (const char *key, location_t location)
|
||||
symbol_t *entry;
|
||||
|
||||
/* Keep the symbol in a printable form. */
|
||||
key = quotearg_style (escape_quoting_style, key);
|
||||
key = struniq_new (quotearg_style (escape_quoting_style, key));
|
||||
*(char const **) &probe.tag = key;
|
||||
entry = hash_lookup (symbol_table, &probe);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user