- muscle_insert ("version", VERSION);
- muscle_insert ("filename", infile);
-
- /* Types. */
- muscle_insert ("stype", "int");
- muscle_insert ("ltype", "yyltype");
-
- /* Tokens. */
- muscle_insert ("tokendef", "");
-
- /* Tables. */
- muscle_insert ("rhs", "0");
- muscle_insert ("pact", "0");
- muscle_insert ("prhs", "0");
- muscle_insert ("stos", "0");
- muscle_insert ("check", "0");
- muscle_insert ("pgoto", "0");
- muscle_insert ("table", "0");
- muscle_insert ("tname", "0");
- muscle_insert ("defact", "0");
- muscle_insert ("toknum", "0");
- muscle_insert ("defgoto", "0");
- muscle_insert ("translate", "0");
-
- /* Various macros. */
- muscle_insert ("flag", "0");
- muscle_insert ("last", "0");
- muscle_insert ("pure", "0");
- muscle_insert ("nsym", "0");
- muscle_insert ("debug", "0");
- muscle_insert ("final", "0");
- muscle_insert ("maxtok", "0");
- muscle_insert ("ntbase", "0");
- muscle_insert ("verbose", "0");
- muscle_insert ("error_verbose", "0");
- muscle_insert ("prefix", "yy");
- /* Default #line formatting. */
- muscle_insert ("linef", "#line %d %s\n");
-
- /* No parser macros. */
- muscle_insert ("nnts", "0");
- muscle_insert ("nrules", "0");
- muscle_insert ("nstates", "0");
- muscle_insert ("ntokens", "0");
-
- /* Stack parameters. */
- muscle_insert ("maxdepth", "10000");
- muscle_insert ("initdepth", "200");
-
- /* C++ macros. */
- muscle_insert ("name", "Parser");
+ MUSCLE_INSERT_STRING ("version", VERSION);
+ MUSCLE_INSERT_C_STRING ("filename", grammar_file);
+}
+
+
+/*------------------------------------------------------------.
+| Free all the memory consumed by the muscle machinery only. |
+`------------------------------------------------------------*/
+
+void
+muscle_free (void)
+{
+ hash_free (muscle_table);
+ obstack_free (&muscle_obstack, NULL);
+}
+
+
+
+/*------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. |
+`------------------------------------------------------------*/
+
+void
+muscle_insert (const char *key, char *value)
+{
+ muscle_entry probe;
+ muscle_entry *entry;
+
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = xmalloc (sizeof *entry);
+ entry->key = key;
+ hash_insert (muscle_table, entry);
+ }
+ entry->value = value;
+}
+
+
+/*-------------------------------------------------------------------.
+| Insert (KEY, VALUE). If KEY already existed, overwrite the |
+| previous value. Uses MUSCLE_OBSTACK. De-allocates the previously |
+| associated value. VALUE and SEPARATOR are copied. |
+`-------------------------------------------------------------------*/
+
+void
+muscle_grow (const char *key, const char *val, const char *separator)
+{
+ muscle_entry probe;
+ muscle_entry *entry = NULL;
+
+ probe.key = key;
+ entry = hash_lookup (muscle_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = xmalloc (sizeof *entry);
+ entry->key = key;
+ hash_insert (muscle_table, entry);
+ entry->value = xstrdup (val);
+ }
+ else
+ {
+ /* Grow the current value. */
+ char *new_val;
+ obstack_sgrow (&muscle_obstack, entry->value);
+ free (entry->value);
+ obstack_sgrow (&muscle_obstack, separator);
+ obstack_sgrow (&muscle_obstack, val);
+ obstack_1grow (&muscle_obstack, 0);
+ new_val = obstack_finish (&muscle_obstack);
+ entry->value = xstrdup (new_val);
+ obstack_free (&muscle_obstack, new_val);
+ }
+}
+
+
+/*------------------------------------------------------------------.
+| Append VALUE to the current value of KEY, using muscle_grow. But |
+| in addition, issue a synchronization line for the location LOC. |
+`------------------------------------------------------------------*/
+
+void
+muscle_code_grow (const char *key, const char *val, location loc)
+{
+ char *extension = NULL;
+ obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", loc.start.line);
+ MUSCLE_OBSTACK_SGROW (&muscle_obstack,
+ quotearg_style (c_quoting_style, loc.start.file));
+ obstack_sgrow (&muscle_obstack, "]])[\n");
+ obstack_sgrow (&muscle_obstack, val);
+ obstack_1grow (&muscle_obstack, 0);
+ extension = obstack_finish (&muscle_obstack);
+ muscle_grow (key, extension, "");