summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-04-17 14:34:15 -0500
committerEric Blake <eblake@redhat.com>2021-04-21 08:53:01 -0500
commitdf96bf3332b023bc757e41b3e72bca0aeda1df38 (patch)
treee0902497a134881dac090c2b46961d7baf5b655e
parent16a0c347aa6ac4792c5965064b3ff15f247b9275 (diff)
downloadm4-df96bf3332b023bc757e41b3e72bca0aeda1df38.tar.gz
symtab: make symtab private
No need for a leaky abstraction of freezing to have to duplicate how our symbol hash table is organized; use the public function hack_all_symbols instead. This will make it easier to refactor the symbol table (such as automatic resizing, or switching to a trie). * src/m4.h (symtab, SYMBOL_NEXT): Make private. * src/freeze.c (produce_frozen_state): Split out... (freeze_symbol): ...new helper, for use by hack_all_symbols. * src/symtab.c (lookup_symbol, symtab_print_list): Update to treat next as internal-only code.
-rw-r--r--src/freeze.c116
-rw-r--r--src/m4.h3
-rw-r--r--src/symtab.c32
3 files changed, 74 insertions, 77 deletions
diff --git a/src/freeze.c b/src/freeze.c
index dca2e9cc..56adb969 100644
--- a/src/freeze.c
+++ b/src/freeze.c
@@ -44,6 +44,63 @@ reverse_symbol_list (symbol *sym)
return result;
}
+static void
+freeze_symbol (symbol *sym, void *arg)
+{
+ symbol *s = sym;
+ FILE *file = arg;
+ const builtin *bp;
+
+ /* Process all entries in one stack, from the last to the first.
+ This order ensures that, at reload time, pushdef's will be
+ executed with the oldest definitions first. */
+
+ s = reverse_symbol_list (s);
+ for (sym = s; sym; sym = SYMBOL_STACK (sym))
+ {
+ switch (SYMBOL_TYPE (sym))
+ {
+ case TOKEN_TEXT:
+ xfprintf (file, "T%d,%d\n",
+ (int) strlen (SYMBOL_NAME (sym)),
+ (int) strlen (SYMBOL_TEXT (sym)));
+ fputs (SYMBOL_NAME (sym), file);
+ fputs (SYMBOL_TEXT (sym), file);
+ fputc ('\n', file);
+ break;
+
+ case TOKEN_FUNC:
+ bp = find_builtin_by_addr (SYMBOL_FUNC (sym));
+ if (bp == NULL)
+ {
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: builtin not found in builtin table!"));
+ abort ();
+ }
+ xfprintf (file, "F%d,%d\n",
+ (int) strlen (SYMBOL_NAME (sym)),
+ (int) strlen (bp->name));
+ fputs (SYMBOL_NAME (sym), file);
+ fputs (bp->name, file);
+ fputc ('\n', file);
+ break;
+
+ case TOKEN_VOID:
+ /* Ignore placeholder tokens that exist due to traceon. */
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: bad token data type in freeze_symbol ()"));
+ abort ();
+ break;
+ }
+ }
+
+ /* Reverse the stack once more, putting it back as it was. */
+ reverse_symbol_list (s);
+}
+
/*------------------------------------------------.
| Produce a frozen state to the given file NAME. |
`------------------------------------------------*/
@@ -52,10 +109,6 @@ void
produce_frozen_state (const char *name)
{
FILE *file;
- size_t h;
- symbol *sym;
- symbol *bucket;
- const builtin *bp;
file = fopen (name, O_BINARY ? "wbe" : "we");
if (!file)
@@ -89,60 +142,7 @@ produce_frozen_state (const char *name)
/* Dump all symbols. */
- for (h = 0; h < hash_table_size; h++)
- {
- for (bucket = symtab[h]; bucket; bucket = SYMBOL_NEXT (bucket))
- {
- /* Process all entries in one stack, from the last to the first.
- This order ensures that, at reload time, pushdef's will be
- executed with the oldest definitions first. */
-
- bucket = reverse_symbol_list (bucket);
- for (sym = bucket; sym; sym = SYMBOL_STACK (sym))
- {
- switch (SYMBOL_TYPE (sym))
- {
- case TOKEN_TEXT:
- xfprintf (file, "T%d,%d\n",
- (int) strlen (SYMBOL_NAME (sym)),
- (int) strlen (SYMBOL_TEXT (sym)));
- fputs (SYMBOL_NAME (sym), file);
- fputs (SYMBOL_TEXT (sym), file);
- fputc ('\n', file);
- break;
-
- case TOKEN_FUNC:
- bp = find_builtin_by_addr (SYMBOL_FUNC (sym));
- if (bp == NULL)
- {
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: builtin not found in builtin table!"));
- abort ();
- }
- xfprintf (file, "F%d,%d\n",
- (int) strlen (SYMBOL_NAME (sym)),
- (int) strlen (bp->name));
- fputs (SYMBOL_NAME (sym), file);
- fputs (bp->name, file);
- fputc ('\n', file);
- break;
-
- case TOKEN_VOID:
- /* Ignore placeholder tokens that exist due to traceon. */
- break;
-
- default:
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: bad token data type in freeze_one_symbol ()"));
- abort ();
- break;
- }
- }
-
- /* Reverse the bucket once more, putting it back as it was. */
- bucket = reverse_symbol_list (bucket);
- }
- }
+ hack_all_symbols (freeze_symbol, file);
/* Let diversions be issued from output.c module, its cleaner to have this
piece of code there. */
diff --git a/src/m4.h b/src/m4.h
index efb21c04..89156acc 100644
--- a/src/m4.h
+++ b/src/m4.h
@@ -373,7 +373,6 @@ struct symbol
};
#define SYMBOL_STACK(S) ((S)->stack)
-#define SYMBOL_NEXT(S) ((S)->next)
#define SYMBOL_TRACED(S) ((S)->traced)
#define SYMBOL_MACRO_ARGS(S) ((S)->macro_args)
#define SYMBOL_BLIND_NO_ARGS(S) ((S)->blind_no_args)
@@ -390,8 +389,6 @@ typedef void hack_symbol (symbol *, void *);
#define HASHMAX 509 /* default, overridden by -Hsize */
-extern symbol **symtab;
-
extern void free_symbol (symbol *sym);
extern void symtab_init (void);
extern symbol *lookup_symbol (const char *, symbol_lookup);
diff --git a/src/symtab.c b/src/symtab.c
index 45f9da31..16ee3f97 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -93,7 +93,7 @@ profile_strcmp (const char *s1, const char *s2)
`------------------------------------------------------------------*/
/* Pointer to symbol table. */
-symbol **symtab;
+static symbol **symtab;
void
symtab_init (void)
@@ -227,9 +227,9 @@ lookup_symbol (const char *name, symbol_lookup mode)
SYMBOL_STACK (sym) = SYMBOL_STACK (old);
SYMBOL_STACK (old) = NULL;
- SYMBOL_NEXT (sym) = SYMBOL_NEXT (old);
- SYMBOL_NEXT (old) = NULL;
- (*spp) = sym;
+ sym->next = old->next;
+ old->next = NULL;
+ *spp = sym;
}
return sym;
}
@@ -251,14 +251,14 @@ lookup_symbol (const char *name, symbol_lookup mode)
SYMBOL_PENDING_EXPANSIONS (sym) = 0;
SYMBOL_STACK (sym) = NULL;
- SYMBOL_NEXT (sym) = *spp;
- (*spp) = sym;
+ sym->next = *spp;
+ *spp = sym;
if (mode == SYMBOL_PUSHDEF && cmp == 0)
{
- SYMBOL_STACK (sym) = SYMBOL_NEXT (sym);
- SYMBOL_NEXT (sym) = SYMBOL_NEXT (SYMBOL_STACK (sym));
- SYMBOL_NEXT (SYMBOL_STACK (sym)) = NULL;
+ SYMBOL_STACK (sym) = sym->next;
+ sym->next = SYMBOL_STACK (sym)->next;
+ SYMBOL_STACK (sym)->next = NULL;
SYMBOL_TRACED (sym) = SYMBOL_TRACED (SYMBOL_STACK (sym));
}
return sym;
@@ -277,18 +277,18 @@ lookup_symbol (const char *name, symbol_lookup mode)
return NULL;
{
bool traced = false;
- symbol *next = SYMBOL_NEXT (sym);
+ symbol *next;
if (SYMBOL_STACK (sym) != NULL
&& mode == SYMBOL_POPDEF)
{
SYMBOL_TRACED (SYMBOL_STACK (sym)) = SYMBOL_TRACED (sym);
- SYMBOL_NEXT (SYMBOL_STACK (sym)) = next;
+ SYMBOL_STACK (sym)->next = sym->next;
*spp = SYMBOL_STACK (sym);
}
else
{
traced = SYMBOL_TRACED (sym);
- *spp = next;
+ *spp = sym->next;
}
do
{
@@ -310,8 +310,8 @@ lookup_symbol (const char *name, symbol_lookup mode)
SYMBOL_PENDING_EXPANSIONS (sym) = 0;
SYMBOL_STACK (sym) = NULL;
- SYMBOL_NEXT (sym) = *spp;
- (*spp) = sym;
+ sym->next = *spp;
+ *spp = sym;
}
}
return NULL;
@@ -349,7 +349,7 @@ hack_all_symbols (hack_symbol *func, void *data)
calling func. */
for (sym = symtab[h]; sym != NULL; sym = next)
{
- next = SYMBOL_NEXT (sym);
+ next = sym->next;
func (sym, data);
}
}
@@ -404,7 +404,7 @@ symtab_print_list (int i)
"next %p, flags%s%s, pending %d\n",
SYMBOL_NAME (sym), (unsigned long int) sym->hash,
(unsigned long int) h, sym, SYMBOL_STACK (sym),
- SYMBOL_NEXT (sym),
+ sym->next,
SYMBOL_TRACED (sym) ? " traced" : "",
SYMBOL_DELETED (sym) ? " deleted" : "",
SYMBOL_PENDING_EXPANSIONS (sym));