X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/beda758b1f805686378e7cba5b70216bb7278080..d1a1114f7f257f89887ea5825ba0d896dfaa747b:/src/muscle_tab.c?ds=sidebyside diff --git a/src/muscle_tab.c b/src/muscle_tab.c index 380a0471..895e2e3e 100644 --- a/src/muscle_tab.c +++ b/src/muscle_tab.c @@ -24,6 +24,10 @@ #include "muscle_tab.h" #include "getargs.h" + +/* An obstack used to create some entries. */ +struct obstack muscle_obstack; + /* Initial capacity of muscles hash table. */ #define HT_INITIAL_CAPACITY 257 @@ -44,18 +48,25 @@ hash_muscle (const void *x, unsigned int tablesize) return hash_string (m->key, tablesize); } +/*-----------------------------------------------------------------. +| Create the MUSCLE_TABLE, and initialize it with default values. | +| Also set up the MUSCLE_OBSTACK. | +`-----------------------------------------------------------------*/ + void muscle_init (void) { muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, - hash_compare_muscles, NULL); + hash_compare_muscles, free); /* Version and input file. */ muscle_insert ("version", VERSION); muscle_insert ("filename", infile); + /* FIXME: there should probably be no default here, only in the + skeletons. */ + /* Types. */ - muscle_insert ("stype", "int"); muscle_insert ("ltype", "yyltype"); /* Default #line formatting. */ @@ -67,13 +78,33 @@ muscle_init (void) /* C++ macros. */ muscle_insert ("name", "Parser"); + + /* Initialize the muscle obstack. */ + obstack_init (&muscle_obstack); } + +/*------------------------------------------------------------. +| Free all the memory consumed by the muscle machinery only. | +`------------------------------------------------------------*/ + +void +muscle_free (void) +{ + hash_free (muscle_table); + obstack_free (&muscle_obstack, NULL); +} + + + void muscle_insert (const char *key, const char *value) { - muscle_entry_t pair = { key, NULL }; - muscle_entry_t *entry = hash_lookup (muscle_table, &pair); + muscle_entry_t pair; + muscle_entry_t *entry = NULL; + + pair.key = key; + entry = hash_lookup (muscle_table, &pair); if (!entry) { @@ -88,7 +119,34 @@ muscle_insert (const char *key, const char *value) const char* muscle_find (const char *key) { - muscle_entry_t pair = { key, NULL }; - muscle_entry_t *result = hash_lookup (muscle_table, &pair); + muscle_entry_t pair; + muscle_entry_t *result = NULL; + + pair.key = key; + result = hash_lookup (muscle_table, &pair); return result ? result->value : NULL; } + + +/* Output the definition of all the current muscles into a list of + m4_defines. */ + +static int +muscle_m4_output (muscle_entry_t *entry, FILE *out) +{ + fprintf (out, "m4_define([b4_%s],\n", entry->key); + fprintf (out, " [[%s]])\n\n\n", entry->value); + return 1; +} + + +/* Output the definition of all the current muscles into a list of + m4_defines. */ + +void +muscles_m4_output (FILE *out) +{ + hash_do_for_each (muscle_table, + (Hash_processor) muscle_m4_output, + out); +}