symbol_check_alias_consistency, symbol_pack, symbol_translation,
hash_compare_symbol, hash_symbol):
Now inline. Return bool, not int.
(symbol_check_defined_processor,
symbol_check_alias_consistency_processor, symbol_pack_processor,
symbol_translation_processor, hash_symbol_comparator,
hash_symbol_hasher): New functions, to avoid casts.
(symbols_new, symbols_do, symbols_check_defined,
symbols_token_translations_init):
Use new functions instead of casting old functions unportably.
(symbol_free): Remove; unused.
(symbol_get): Remove cast in lhs of assignment.
(symbols_do): Now static. Accept generic arguments, not hashing-related ones.
-/* Symbol table manager for Bison,
+/* Symbol table manager for Bison.
+
Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
static symbol *
symbol_new (uniqstr tag, location loc)
{
static symbol *
symbol_new (uniqstr tag, location loc)
{
- symbol *res = XMALLOC (symbol, 1);
+ symbol *res = MALLOC (res, 1);
uniqstr_assert (tag);
res->tag = tag;
uniqstr_assert (tag);
res->tag = tag;
-/*-----------.
-| Free SYM. |
-`-----------*/
-
-static void
-symbol_free (symbol *sym)
-{
- free (sym);
-}
-
-
/*----------------------------------------------------------.
| If SYM is not defined, report an error, and consider it a |
| nonterminal. |
`----------------------------------------------------------*/
/*----------------------------------------------------------.
| If SYM is not defined, report an error, and consider it a |
| nonterminal. |
`----------------------------------------------------------*/
symbol_check_defined (symbol *sym)
{
if (sym->class == unknown_sym)
symbol_check_defined (symbol *sym)
{
if (sym->class == unknown_sym)
+static bool
+symbol_check_defined_processor (void *sym, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_check_defined (sym);
+}
+
/*------------------------------------------------------------------.
| Declare the new symbol SYM. Make it an alias of SYMVAL, and type |
/*------------------------------------------------------------------.
| Declare the new symbol SYM. Make it an alias of SYMVAL, and type |
| associativity. |
`---------------------------------------------------------*/
| associativity. |
`---------------------------------------------------------*/
-static bool
-symbol_check_alias_consistence (symbol *this)
+static inline bool
+symbol_check_alias_consistency (symbol *this)
{
/* Check only those who _are_ the aliases. */
if (this->alias && this->user_token_number == USER_NUMBER_ALIAS)
{
/* Check only those who _are_ the aliases. */
if (this->alias && this->user_token_number == USER_NUMBER_ALIAS)
+static bool
+symbol_check_alias_consistency_processor (void *this,
+ void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_check_alias_consistency (this);
+}
+
/*-------------------------------------------------------------------.
| Assign a symbol number, and write the definition of the token name |
| into FDEFINES. Put in SYMBOLS. |
`-------------------------------------------------------------------*/
/*-------------------------------------------------------------------.
| Assign a symbol number, and write the definition of the token name |
| into FDEFINES. Put in SYMBOLS. |
`-------------------------------------------------------------------*/
symbol_pack (symbol *this)
{
if (this->class == nterm_sym)
symbol_pack (symbol *this)
{
if (this->class == nterm_sym)
+static bool
+symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_pack (this);
+}
+
| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
`--------------------------------------------------*/
| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
`--------------------------------------------------*/
symbol_translation (symbol *this)
{
/* Non-terminal? */
symbol_translation (symbol *this)
{
/* Non-terminal? */
+static bool
+symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_translation (this);
+}
+
/*----------------------.
| A symbol hash table. |
/*----------------------.
| A symbol hash table. |
static struct hash_table *symbol_table = NULL;
static struct hash_table *symbol_table = NULL;
hash_compare_symbol (const symbol *m1, const symbol *m2)
{
/* Since tags are unique, we can compare the pointers themselves. */
return UNIQSTR_EQ (m1->tag, m2->tag);
}
hash_compare_symbol (const symbol *m1, const symbol *m2)
{
/* Since tags are unique, we can compare the pointers themselves. */
return UNIQSTR_EQ (m1->tag, m2->tag);
}
+static bool
+hash_symbol_comparator (void const *m1, void const *m2)
+{
+ return hash_compare_symbol (m1, m2);
+}
+
+static inline unsigned int
hash_symbol (const symbol *m, unsigned int tablesize)
{
/* Since tags are unique, we can hash the pointer itself. */
hash_symbol (const symbol *m, unsigned int tablesize)
{
/* Since tags are unique, we can hash the pointer itself. */
- return ((size_t) m->tag) % tablesize;
+ return ((uintptr_t) m->tag) % tablesize;
+}
+
+static unsigned int
+hash_symbol_hasher (void const *m, unsigned int tablesize)
+{
+ return hash_symbol (m, tablesize);
{
symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
NULL,
{
symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
NULL,
- (Hash_hasher) hash_symbol,
- (Hash_comparator) hash_compare_symbol,
- (Hash_data_freer) symbol_free);
+ hash_symbol_hasher,
+ hash_symbol_comparator,
+ free);
/* Keep the symbol in a printable form. */
key = uniqstr_new (quotearg_style (escape_quoting_style, key));
/* Keep the symbol in a printable form. */
key = uniqstr_new (quotearg_style (escape_quoting_style, key));
- *(char const **) &probe.tag = key;
entry = hash_lookup (symbol_table, &probe);
if (!entry)
entry = hash_lookup (symbol_table, &probe);
if (!entry)
| terminals. |
`---------------------------------------------------------------*/
| terminals. |
`---------------------------------------------------------------*/
-void
-symbols_do (symbol_processor processor, void *processor_data)
+static void
+symbols_do (Hash_processor processor, void *processor_data)
- hash_do_for_each (symbol_table,
- (Hash_processor) processor,
- processor_data);
+ hash_do_for_each (symbol_table, processor, processor_data);
void
symbols_check_defined (void)
{
void
symbols_check_defined (void)
{
- symbols_do (symbol_check_defined, NULL);
+ symbols_do (symbol_check_defined_processor, NULL);
}
/*------------------------------------------------------------------.
}
/*------------------------------------------------------------------.
max_user_token_number = this->user_token_number;
}
max_user_token_number = this->user_token_number;
}
- token_translations = XCALLOC (symbol_number, max_user_token_number + 1);
+ CALLOC (token_translations, max_user_token_number + 1);
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined, which represents all invalid inputs.
*/
for (i = 0; i < max_user_token_number + 1; i++)
token_translations[i] = undeftoken->number;
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined, which represents all invalid inputs.
*/
for (i = 0; i < max_user_token_number + 1; i++)
token_translations[i] = undeftoken->number;
- symbols_do (symbol_translation, NULL);
+ symbols_do (symbol_translation_processor, NULL);
void
symbols_pack (void)
{
void
symbols_pack (void)
{
- symbols = XCALLOC (symbol *, nsyms);
+ CALLOC (symbols, nsyms);
- symbols_do (symbol_check_alias_consistence, NULL);
- symbols_do (symbol_pack, NULL);
+ symbols_do (symbol_check_alias_consistency_processor, NULL);
+ symbols_do (symbol_pack_processor, NULL);
symbols_token_translations_init ();
symbols_token_translations_init ();