]> git.saurik.com Git - bison.git/blobdiff - src/output.c
Formatting changes.
[bison.git] / src / output.c
index 5950b4f71156af9eaee61aa11af329c79bd9de82..73e634855e6c2a4a184e2e2b2d9e38a4a6d4a493 100644 (file)
@@ -287,7 +287,7 @@ prepare_states (void)
 | Compare two symbols by type-name, and then by number.  |
 `-------------------------------------------------------*/
 
-int
+static int
 symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
 {
   int res = UNIQSTR_CMP((*lhs)->type_name, (*rhs)->type_name);
@@ -302,7 +302,7 @@ symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
 `----------------------------------------------------------------*/
 
 static symbol **
-symbols_by_type_name ()
+symbols_by_type_name (void)
 {
   typedef int (*qcmp_type) (const void *, const void *);
   symbol **res = xmemdup (symbols, nsyms * sizeof *res);
@@ -320,28 +320,17 @@ static void
 type_names_output (FILE *out)
 {
   int i;
-  const char *isep = "";
   symbol **syms = symbols_by_type_name ();
   fputs ("m4_define([b4_type_names],\n[", out);
-  for (i = 0; i < nsyms; )
-    if (syms[i]->type_name)
-      {
-        int j;
-        const char *jsep = "";
-        fprintf (out, "%s[", isep);
-        isep = ",\n";
-        for (j = i; j < nsyms; ++j)
-          {
-            if (syms[i]->type_name != syms[j]->type_name)
-              break;
-            fprintf (out, "%s%d", jsep, syms[j]->number);
-            jsep = ", ";
-          }
-        fputs ("]", out);
-        i = j;
-      }
-    else
-      ++i;
+  for (i = 0; i < nsyms; /* nothing */)
+    {
+      // The index of the first symbol of the current type-name.
+      int i0 = i;
+      fputs (i ? ",\n[" : "[", out);
+      for (; i < nsyms && syms[i]->type_name == syms[i0]->type_name; ++i)
+        fprintf (out, "%s%d", i != i0 ? ", " : "", syms[i]->number);
+      fputs ("]", out);
+    }
   fputs ("])\n\n", out);
   free (syms);
 }
@@ -407,34 +396,52 @@ merger_output (FILE *out)
 }
 
 
-/*---------------------------------------.
-| Output the symbol definitions to OUT.  |
-`---------------------------------------*/
+/*---------------------------------------------.
+| Prepare the muscles for symbol definitions.  |
+`---------------------------------------------*/
 
 static void
-symbol_definitions_output (FILE *out)
+prepare_symbol_definitions (void)
 {
   int i;
   for (i = 0; i < nsyms; ++i)
     {
       symbol *sym = symbols[i];
       const char *key;
+      const char *value;
 
 #define SET_KEY(Entry)                                                  \
       obstack_fgrow2 (&format_obstack, "symbol(%d, %s)", i, Entry);     \
       obstack_1grow (&format_obstack, 0);                               \
       key = obstack_finish (&format_obstack);
 
+      // Whether the symbol has an identifier.
+      value = symbol_id_get (sym);
+      SET_KEY("has_id");
+      MUSCLE_INSERT_INT (key, !!value);
+
+      // Its identifier.
+      SET_KEY("id");
+      MUSCLE_INSERT_STRING (key, value ? value : "");
+
+      // Its tag.  Typically for documentation purpose.
       SET_KEY("tag");
       MUSCLE_INSERT_STRING (key, sym->tag);
 
       SET_KEY("user_number");
       MUSCLE_INSERT_INT (key, sym->user_token_number);
 
+      SET_KEY("is_token");
+      MUSCLE_INSERT_INT (key,
+                         i < ntokens && sym != errtoken && sym != undeftoken);
+
       SET_KEY("number");
       MUSCLE_INSERT_INT (key, sym->number);
 
-      SET_KEY("type_name");
+      SET_KEY("has_type");
+      MUSCLE_INSERT_INT (key, !!sym->type_name);
+
+      SET_KEY("type");
       MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
 
 #undef SET_KEY
@@ -589,7 +596,6 @@ muscles_output (FILE *out)
   merger_output (out);
   symbol_code_props_output (out, "destructors", &symbol_destructor_get);
   symbol_code_props_output (out, "printers", &symbol_printer_get);
-  symbol_definitions_output (out);
   symbol_numbers_output (out);
   token_definitions_output (out);
   type_names_output (out);
@@ -787,6 +793,7 @@ output (void)
   prepare_rules ();
   prepare_states ();
   prepare_actions ();
+  prepare_symbol_definitions ();
 
   prepare ();