]> git.saurik.com Git - bison.git/commitdiff
code_props: factor more.
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 22 Jun 2012 12:47:31 +0000 (14:47 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Fri, 22 Jun 2012 12:49:40 +0000 (14:49 +0200)
* src/symtab.h, src/symtab.c (code_props_type_string): No longer static.
* src/output.c (CODE_PROPS): Remove, we can now iterate on both the
destructor and the printer.
(SET_KEY2): New.

src/output.c
src/symtab.c
src/symtab.h

index c967fa7a477b9985eac70ae4ed158e2334c60c0d..e8cff20e25812d573e23ea8b9db02364b57c815e 100644 (file)
@@ -402,9 +402,16 @@ prepare_symbol_definitions (void)
       const char *key;
       const char *value;
 
-#define SET_KEY(Entry)                                                  \
-      obstack_fgrow2 (&format_obstack, "symbol(%d, %s)", i, Entry);     \
-      obstack_1grow (&format_obstack, 0);                               \
+#define SET_KEY(Entry)                                          \
+      obstack_fgrow2 (&format_obstack, "symbol(%d, %s)",        \
+                      i, Entry);                                \
+      obstack_1grow (&format_obstack, 0);                       \
+      key = obstack_finish (&format_obstack);
+
+#define SET_KEY2(Entry, Suffix)                                 \
+      obstack_fgrow3 (&format_obstack, "symbol(%d, %s_%s)",     \
+                      i, Entry, Suffix);                        \
+      obstack_1grow (&format_obstack, 0);                       \
       key = obstack_finish (&format_obstack);
 
       // Whether the symbol has an identifier.
@@ -436,28 +443,29 @@ prepare_symbol_definitions (void)
       SET_KEY("type");
       MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
 
-#define CODE_PROP(PropName)                                             \
-      do {                                                              \
-        code_props const *p = symbol_code_props_get (sym, PropName);    \
-        SET_KEY("has_" #PropName);                                      \
-        MUSCLE_INSERT_INT (key, !!p->code);                             \
-                                                                        \
-        if (p->code)                                                    \
-          {                                                             \
-            SET_KEY(#PropName "_file");                                 \
-            MUSCLE_INSERT_STRING (key, p->location.start.file);         \
-                                                                        \
-            SET_KEY(#PropName "_line");                                 \
-            MUSCLE_INSERT_INT (key, p->location.start.line);            \
-                                                                        \
-            SET_KEY(#PropName);                                         \
-            MUSCLE_INSERT_STRING_RAW (key, p->code);                    \
-          }                                                             \
-      } while (0)
-
-      CODE_PROP(destructor);
-      CODE_PROP(printer);
-#undef CODE_PROP
+      {
+        int j;
+        for (j = 0; j < CODE_PROPS_SIZE; ++j)
+          {
+            char const *pname = code_props_type_string (j);
+            code_props const *p = symbol_code_props_get (sym, j);
+            SET_KEY2("has", pname);
+            MUSCLE_INSERT_INT (key, !!p->code);
+
+            if (p->code)
+              {
+                SET_KEY2(pname, "file");
+                MUSCLE_INSERT_STRING (key, p->location.start.file);
+
+                SET_KEY2(pname, "line");
+                MUSCLE_INSERT_INT (key, p->location.start.line);
+
+                SET_KEY(pname);
+                MUSCLE_INSERT_STRING_RAW (key, p->code);
+              }
+          }
+      }
+#undef SET_KEY2
 #undef SET_KEY
     }
 }
index b30ccaf1eb577df2f149f4b00c9c14a2d1f26401..14d107c9ef1dc142275c01a22c2845e512ff7685 100644 (file)
@@ -100,11 +100,7 @@ symbol_new (uniqstr tag, location loc)
   return res;
 }
 
-/*-------------------------------------------------------.
-| Name of the code_props type: %destructor or %printer.  |
-`-------------------------------------------------------*/
-
-static char const *
+char const *
 code_props_type_string (code_props_type kind)
 {
   switch (kind)
index 0ef4db29d17e87400af3c274b118b123c2993af3..70b4a8174a48eae92b93826f01b548ee6ed514fc 100644 (file)
@@ -154,7 +154,10 @@ void symbol_print (symbol *s, FILE *f);
 /** Is this a dummy nonterminal?  */
 bool symbol_is_dummy (const symbol *sym);
 
-/** Return the name of the symbol that can be used as an identifier.
+/** The name of the code_props type: "\%destructor" or "\%printer".  */
+char const *code_props_type_string (code_props_type kind);
+
+/** The name of the symbol that can be used as an identifier.
  ** Consider the alias if needed.
  ** Return 0 if there is none (e.g., the symbol is only defined as
  ** a string). */