bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use b4_symbol for printers and destructors everywhere.


From: Akim Demaille
Subject: [PATCH] Use b4_symbol for printers and destructors everywhere.
Date: Fri, 28 Nov 2008 22:03:29 +0100

        * data/bison.m4 (b4_symbol_action_location): New.
        * data/c.m4 (b4_symbol_actions): Remove.
        Adjust all callers to use by b4_symbol_foreach and the corresponding
        b4_symbol_printer/destructor macro.
        * data/glr.cc: Adjust.
        * data/lalr1.java: Adjust the %destructor sanity check.
        * src/output.c (symbol_code_props_output): Remove, we no longer
        need the b4_symbol_printers/destructors tables.
---
 ChangeLog       |   12 ++++++++++++
 data/bison.m4   |    7 +++++++
 data/c.m4       |   23 +++--------------------
 data/glr.cc     |    2 +-
 data/lalr1.java |   15 ++++++++++-----
 src/output.c    |   41 -----------------------------------------
 6 files changed, 33 insertions(+), 67 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1a6ccea..4321286 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-12-01  Akim Demaille  <address@hidden>
 
+       Use b4_symbol for printers and destructors everywhere.
+       * data/bison.m4 (b4_symbol_action_location): New.
+       * data/c.m4 (b4_symbol_actions): Remove.
+       Adjust all callers to use by b4_symbol_foreach and the corresponding
+       b4_symbol_printer/destructor macro.
+       * data/glr.cc: Adjust.
+       * data/lalr1.java: Adjust the %destructor sanity check.
+       * src/output.c (symbol_code_props_output): Remove, we no longer
+       need the b4_symbol_printers/destructors tables.
+
+2008-12-01  Akim Demaille  <address@hidden>
+
        Use b4_symbol_case_.
        * data/lalr1.cc, data/bison.m4 (b4_symbol_action): Use
        b4_symbol_case_.
diff --git a/data/bison.m4 b/data/bison.m4
index d8b8539..5930ca7 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -373,6 +373,13 @@ m4_define([b4_symbol_if],
          [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], 
[$2]))])])
 
 
+# b4_symbol_action_location(SYMBOL-NUM, KIND)
+# -------------------------------------------
+# Report the location of the KIND action as FILE:LINE.
+m4_define([b4_symbol_action_location],
+[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])])
+
+
 # b4_symbol_action(SYMBOL-NUM, KIND)
 # ----------------------------------
 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
diff --git a/data/c.m4 b/data/c.m4
index abde5a1..030f6e4 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -404,23 +404,6 @@ $2
 b4_syncline(address@hidden@], address@hidden@])
     break;])
 
-# b4_symbol_actions(FILENAME, LINENO,
-#                   SYMBOL-TAG, SYMBOL-NUM,
-#                   SYMBOL-ACTION, SYMBOL-TYPENAME)
-# -------------------------------------------------
-m4_define([b4_symbol_actions],
-[m4_pushdef([b4_dollar_dollar],
-   [b4_symbol_value([(*yyvaluep)], [$6])])dnl
-m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
-      case $4: /* $3 */
-b4_syncline([$2], [$1])
-       $5;
-b4_syncline(address@hidden@], address@hidden@])
-       break;
-m4_popdef([b4_at_dollar])dnl
-m4_popdef([b4_dollar_dollar])dnl
-])
-
 
 # b4_yydestruct_generate(FUNCTION-DECLARATOR)
 # -------------------------------------------
@@ -452,8 +435,8 @@ b4_parse_param_use[]dnl
 
   switch (yytype)
     {
-]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
-      default:
+]b4_symbol_foreach([b4_symbol_destructor])dnl
+[      default:
        break;
     }
 }]dnl
@@ -493,7 +476,7 @@ b4_parse_param_use[]dnl
 # endif
   switch (yytype)
     {
-]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+]b4_symbol_foreach([b4_symbol_printer])dnl
 [      default:
        break;
     }
diff --git a/data/glr.cc b/data/glr.cc
index cbf0d07..51460fa 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -153,7 +153,7 @@ m4_pushdef([b4_parse_param], 
m4_defn([b4_parse_param_orig]))dnl
     YYUSE (yylocationp);
     switch (yytype)
       {
-  ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+]b4_symbol_foreach([b4_symbol_printer])dnl
 [        default:
          break;
       }
diff --git a/data/lalr1.java b/data/lalr1.java
index ea95654..af3cd12 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -17,15 +17,20 @@
 
 m4_include(b4_pkgdatadir/[java.m4])
 
-b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java], 
[b4_skeleton])])
-m4_ifval(m4_defn([b4_symbol_destructors]),
-        [b4_fatal([%s: %%destructor does not make sense in Java], 
[b4_skeleton])],
-        [])
+b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java],
+              [b4_skeleton])])
+
+m4_define([b4_symbol_no_destructor_assert],
+[b4_symbol_if([$1], [has_destructor],
+              [b4_fatal([%s: %s: %%destructor does not make sense in Java],
+                        [b4_skeleton],
+                        [b4_symbol_action_location([$1], [destructor])])])])
+b4_symbol_foreach([b4_symbol_no_destructor_assert])
 
 m4_divert_push(0)dnl
 @output(b4_parser_file_name@)@
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
-  [2007, 2008])
+             [2007, 2008])
 
 b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
 ])[/* First part of user declarations.  */
diff --git a/src/output.c b/src/output.c
index 6fcff5f..0c6cb76 100644
--- a/src/output.c
+++ b/src/output.c
@@ -504,45 +504,6 @@ token_definitions_output (FILE *out)
 }
 
 
-/*---------------------------------------------------.
-| Output the symbol destructors or printers to OUT.  |
-`---------------------------------------------------*/
-
-static void
-symbol_code_props_output (FILE *out, char const *what,
-                          code_props const *(*get)(symbol const *))
-{
-  int i;
-  char const *sep = "";
-
-  fputs ("m4_define([b4_symbol_", out);
-  fputs (what, out);
-  fputs ("], \n[", out);
-  for (i = 0; i < nsyms; ++i)
-    {
-      symbol *sym = symbols[i];
-      char const *code = (*get) (sym)->code;
-      if (code)
-        {
-          location loc = (*get) (sym)->location;
-          /* Filename, lineno,
-             Symbol-name, Symbol-number,
-             code, optional typename.  */
-          fprintf (out, "%s[", sep);
-          sep = ",\n";
-          escaped_output (out, loc.start.file);
-          fprintf (out, ", %d, ", loc.start.line);
-          escaped_output (out, sym->tag);
-          fprintf (out, ", %d, [[%s]]", sym->number, code);
-          if (sym->type_name)
-            fprintf (out, ", [[%s]]", sym->type_name);
-          fputc (']', out);
-        }
-    }
-  fputs ("])\n\n", out);
-}
-
-
 static void
 prepare_actions (void)
 {
@@ -600,8 +561,6 @@ muscles_output (FILE *out)
 {
   fputs ("m4_init()\n", out);
   merger_output (out);
-  symbol_code_props_output (out, "destructors", &symbol_destructor_get);
-  symbol_code_props_output (out, "printers", &symbol_printer_get);
   symbol_numbers_output (out);
   token_definitions_output (out);
   type_names_output (out);
-- 
1.6.0.4.790.gaa14a





reply via email to

[Prev in Thread] Current Thread [Next in Thread]