bison-patches
[Top][All Lists]
Advanced

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

Re: encapsulating code properties


From: Joel E. Denny
Subject: Re: encapsulating code properties
Date: Tue, 2 Jan 2007 20:13:11 -0500 (EST)

On Tue, 2 Jan 2007, Joel E. Denny wrote:

> On Tue, 2 Jan 2007, Paul Eggert wrote:
> 
> > "Joel E. Denny" <address@hidden> writes:
> > 
> > > The first step appears below.  It implements the code_props interface but 
> > > does not update any other module to use it.  I believe all previous 
> > > qualms 
> > > about the larger patch appeared in this step, and I believe I've 
> > > addressed 
> > > them all.
> > 
> > Yes, that looks fine to me as well; please install when you have the time.
> > Thanks.
> 
> Thanks for the rapid response.  I committed it.

Here's the next step, uncommitted.  I don't recall any previous objections 
to this part, but I'll wait a day or so just in case.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1644
diff -p -u -r1.1644 ChangeLog
--- ChangeLog   2 Jan 2007 23:31:14 -0000       1.1644
+++ ChangeLog   3 Jan 2007 01:04:55 -0000
@@ -1,5 +1,25 @@
 2007-01-02  Joel E. Denny  <address@hidden>
 
+       Use the new code_props interface in parse-gram.y.
+       * src/parse-gram.y (prologue_declaration, braceless, epilogue.opt):
+       Update all uses of translate_* functions to use the new code_props
+       interface and to use gram_scanner_last_string_free and
+       code_scanner_last_string_free where possible.
+       (grammar_declaration): symbol_list_destructor_set and
+       symbol_list_printer_set now perform the translation, so don't do it
+       here.  Use gram_scanner_last_string_free where possible.
+       * src/scan-code.h, src/scan-code.l (translate_symbol_action,
+       translate_code): Remove, no longer used.
+       * src/symlist.h, src/symlist.c (symbol_list_destructor_set,
+       symbol_list_printer_set): Perform code translation here rather than
+       depending on the caller to do so.
+
+       * src/symlist.h (struct symbol_list): Correct some documentation typos.
+       * src/scan-gram.h (gram_last_string): Remove declaration.
+       * src/scan-gram.l (last_string): Declare it static.
+
+2007-01-02  Joel E. Denny  <address@hidden>
+
        Encapsulate code properties and related functionality for the various
        destructors, printers, and actions into a code_props structure and
        interface.  This patch merely implements code_props in scan-code.h and
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.104
diff -p -u -r1.104 parse-gram.y
--- src/parse-gram.y    31 Dec 2006 20:29:48 -0000      1.104
+++ src/parse-gram.y    3 Jan 2007 01:04:56 -0000
@@ -1,6 +1,7 @@
 %{/* Bison Grammar Parser                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
+   Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -185,7 +186,7 @@ static int current_prec = 0;
 %printer { fputs (char_name ($$), stderr); } CHAR
 
 /* braceless is not to be used for rule or symbol actions, as it
-   calls translate_code. */
+   calls code_props_plain_init.  */
 %type <chars> STRING "%{...%}" EPILOGUE braceless content content.opt
 %type <code> "{...}"
 %printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
@@ -225,7 +226,15 @@ prologue_declarations:
 
 prologue_declaration:
   grammar_declaration
-| "%{...%}"     { prologue_augment (translate_code ($1, @1), @1, union_seen); }
+| "%{...%}"
+    {
+      code_props plain_code;
+      code_props_plain_init (&plain_code, $1, @1);
+      code_props_translate_code (&plain_code);
+      gram_scanner_last_string_free ();
+      prologue_augment (plain_code.code, @1, union_seen);
+      code_scanner_last_string_free ();
+    }
 | "%debug"                         { debug_flag = true; }
 | "%define" STRING content.opt     { muscle_insert ($2, $3); }
 | "%defines"                       { defines_flag = true; }
@@ -246,7 +255,12 @@ prologue_declaration:
     }
 | "%initial-action" "{...}"
     {
-      muscle_code_grow ("initial_action", translate_symbol_action ($2, @2), 
@2);
+      code_props action;
+      code_props_symbol_action_init (&action, $2, @2);
+      code_props_translate_code (&action);
+      gram_scanner_last_string_free ();
+      muscle_code_grow ("initial_action", action.code, @2);
+      code_scanner_last_string_free ();
     }
 | "%language" STRING           { language_argmatch ($2, 1, &@1); }
 | "%lex-param" "{...}"         { add_param ("lex_param", $2, @2); }
@@ -279,17 +293,15 @@ grammar_declaration:
 | "%destructor" "{...}" generic_symlist
     {
       symbol_list *list;
-      const char *action = translate_symbol_action ($2, @2);
       for (list = $3; list; list = list->next)
-       symbol_list_destructor_set (list, action, @2);
+       symbol_list_destructor_set (list, $2, @2);
       symbol_list_free ($3);
     }
 | "%printer" "{...}" generic_symlist
     {
       symbol_list *list;
-      const char *action = translate_symbol_action ($2, @2);
       for (list = $3; list; list = list->next)
-       symbol_list_printer_set (list, action, @2);
+       symbol_list_printer_set (list, $2, @2);
       symbol_list_free ($3);
     }
 | "%default-prec"
@@ -340,6 +352,7 @@ grammar_declaration:
 
       union_seen = true;
       muscle_code_grow ("stype", body, @3);
+      gram_scanner_last_string_free ();
     }
 ;
 
@@ -522,8 +535,12 @@ content.opt:
 braceless:
   "{...}"
     {
+      code_props plain_code;
       $1[strlen ($1) - 1] = '\n';
-      $$ = translate_code ($1 + 1, @1);
+      code_props_plain_init (&plain_code, $1+1, @1);
+      code_props_translate_code (&plain_code);
+      gram_scanner_last_string_free ();
+      $$ = plain_code.code;
     }
 ;
 
@@ -569,8 +586,12 @@ epilogue.opt:
   /* Nothing.  */
 | "%%" EPILOGUE
     {
-      muscle_code_grow ("epilogue", translate_code ($2, @2), @2);
+      code_props plain_code;
+      code_props_plain_init (&plain_code, $2, @2);
+      code_props_translate_code (&plain_code);
       gram_scanner_last_string_free ();
+      muscle_code_grow ("epilogue", plain_code.code, @2);
+      code_scanner_last_string_free ();
     }
 ;
 
Index: src/scan-code.h
===================================================================
RCS file: /sources/bison/bison/src/scan-code.h,v
retrieving revision 1.7
diff -p -u -r1.7 scan-code.h
--- src/scan-code.h     2 Jan 2007 23:31:14 -0000       1.7
+++ src/scan-code.h     3 Jan 2007 01:04:56 -0000
@@ -162,22 +162,14 @@ void code_scanner_last_string_free (void
  * \pre
  *   - None.
  * \post
- *   - All dynamic memory allocated during any previous invocations of
- *     \c code_props_translate_code, \c translate_rule_action,
- *     \c translate_symbol_action, and \c translate_code has been freed.  All
- *     \c code_props instances may now be invalid.
+ *   - All dynamic memory allocated during invocations of
+ *     \c code_props_translate_code or \c translate_rule_action (if any) has
+ *     been freed.  All \c code_props instances may now be invalid.
  */
 void code_scanner_free (void);
 
 /* The action of the rule R contains $$, $1 etc. referring to the values
    of the rule R. */
-char const *translate_rule_action (symbol_list *r);
-
-/* The action A refers to $$ and @$ only, referring to a symbol. */
-char const *translate_symbol_action (char const *a, location l);
-
-/* The action contains no special escapes, just protect M4 special
-   symbols.  */
-char const *translate_code (char const *a, location l);
+char const *translate_rule_action (struct symbol_list *r);
 
 #endif /* !SCAN_CODE_H_ */
Index: src/scan-code.l
===================================================================
RCS file: /sources/bison/bison/src/scan-code.l,v
retrieving revision 1.18
diff -p -u -r1.18 scan-code.l
--- src/scan-code.l     2 Jan 2007 23:31:14 -0000       1.18
+++ src/scan-code.l     3 Jan 2007 01:04:56 -0000
@@ -488,21 +488,3 @@ translate_rule_action (symbol_list *rule
   code_props_translate_code (&cp);
   return cp.code;
 }
-
-char const *
-translate_symbol_action (char const *a, location l)
-{
-  code_props cp;
-  code_props_symbol_action_init (&cp, a, l);
-  code_props_translate_code (&cp);
-  return cp.code;
-}
-
-char const *
-translate_code (char const *a, location l)
-{
-  code_props cp;
-  code_props_plain_init (&cp, a, l);
-  code_props_translate_code (&cp);
-  return cp.code;
-}
Index: src/scan-gram.h
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.h,v
retrieving revision 1.5
diff -p -u -r1.5 scan-gram.h
--- src/scan-gram.h     12 Nov 2006 07:39:37 -0000      1.5
+++ src/scan-gram.h     3 Jan 2007 01:04:56 -0000
@@ -1,6 +1,6 @@
 /* Bison Grammar Scanner
 
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -26,7 +26,6 @@
 /* From the scanner.  */
 extern FILE *gram_in;
 extern int gram__flex_debug;
-extern char *gram_last_string;
 void gram_scanner_initialize (void);
 void gram_scanner_free (void);
 void gram_scanner_last_string_free (void);
Index: src/scan-gram.l
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.l,v
retrieving revision 1.113
diff -p -u -r1.113 scan-gram.l
--- src/scan-gram.l     31 Dec 2006 20:29:48 -0000      1.113
+++ src/scan-gram.l     3 Jan 2007 01:04:56 -0000
@@ -1,6 +1,7 @@
 /* Bison Grammar Scanner                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
+   Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -58,7 +59,7 @@ static size_t no_cr_read (FILE *, char *
 #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
 
 /* A string representing the most recently saved token.  */
-char *last_string;
+static char *last_string;
 
 void
 gram_scanner_last_string_free (void)
Index: src/symlist.c
===================================================================
RCS file: /sources/bison/bison/src/symlist.c,v
retrieving revision 1.27
diff -p -u -r1.27 symlist.c
--- src/symlist.c       2 Jan 2007 23:31:14 -0000       1.27
+++ src/symlist.c       3 Jan 2007 01:04:56 -0000
@@ -208,44 +208,52 @@ symbol_list_n_type_name_get (symbol_list
 
 
 void
-symbol_list_destructor_set (symbol_list *node, const char *destructor,
+symbol_list_destructor_set (symbol_list *node, char const *code,
                             location loc)
 {
+  code_props destructor;
+  code_props_symbol_action_init (&destructor, code, loc);
+  code_props_translate_code (&destructor);
+  code = destructor.code;
   switch (node->content_type)
     {
       case SYMLIST_SYMBOL:
-        symbol_destructor_set (node->content.sym, destructor, loc);
+        symbol_destructor_set (node->content.sym, code, loc);
         break;
       case SYMLIST_TYPE:
         semantic_type_destructor_set (
-          semantic_type_get (node->content.type_name), destructor, loc);
+          semantic_type_get (node->content.type_name), code, loc);
         break;
       case SYMLIST_DEFAULT_TAGGED:
-        default_tagged_destructor_set (destructor, loc);
+        default_tagged_destructor_set (code, loc);
         break;
       case SYMLIST_DEFAULT_TAGLESS:
-        default_tagless_destructor_set (destructor, loc);
+        default_tagless_destructor_set (code, loc);
         break;
     }
 }
 
 void
-symbol_list_printer_set (symbol_list *node, const char *printer, location loc)
+symbol_list_printer_set (symbol_list *node, char const *code, location loc)
 {
+  code_props printer;
+  code_props_symbol_action_init (&printer, code, loc);
+  code_props_translate_code (&printer);
+  code = printer.code;
   switch (node->content_type)
     {
       case SYMLIST_SYMBOL:
-        symbol_printer_set (node->content.sym, printer, loc);
+        symbol_printer_set (node->content.sym, code, loc);
         break;
       case SYMLIST_TYPE:
         semantic_type_printer_set (
-          semantic_type_get (node->content.type_name), printer, loc);
+          semantic_type_get (node->content.type_name), code, loc);
         break;
       case SYMLIST_DEFAULT_TAGGED:
-        default_tagged_printer_set (printer, loc);
+        default_tagged_printer_set (code, loc);
         break;
       case SYMLIST_DEFAULT_TAGLESS:
-        default_tagless_printer_set (printer, loc);
+        default_tagless_printer_set (code, loc);
         break;
     }
 }
Index: src/symlist.h
===================================================================
RCS file: /sources/bison/bison/src/symlist.h,v
retrieving revision 1.24
diff -p -u -r1.24 symlist.h
--- src/symlist.h       2 Jan 2007 23:31:14 -0000       1.24
+++ src/symlist.h       3 Jan 2007 01:04:56 -0000
@@ -23,6 +23,7 @@
 # define SYMLIST_H_
 
 # include "location.h"
+# include "scan-code.h"
 # include "symtab.h"
 
 /* A list of symbols, used during the parsing to store the rules.  */
@@ -37,9 +38,14 @@ typedef struct symbol_list
     SYMLIST_DEFAULT_TAGGED, SYMLIST_DEFAULT_TAGLESS
   } content_type;
   union {
-    /** The symbol or \c NULL iff <tt>node_type = SYMLIST_SYMBOL</tt>.  */
+    /**
+     * The symbol or \c NULL iff
+     * <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
+     */
     symbol *sym;
-    /** The semantic type iff <tt>node_type = SYMLIST_TYPE</tt>.  */
+    /**
+     * The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
+     */
     uniqstr type_name;
   } content;
   location location;
@@ -106,12 +112,12 @@ symbol_list *symbol_list_n_get (symbol_l
    symbol N in rule RULE.  */
 uniqstr symbol_list_n_type_name_get (symbol_list *l, location loc, int n);
 
-/** Set the \c \%destructor for \c node as \c destructor at \c loc.  */
-void symbol_list_destructor_set (symbol_list *node, const char *destructor,
+/** Set the \c \%destructor for \c node as \c code at \c loc.  */
+void symbol_list_destructor_set (symbol_list *node, char const *code,
                                  location loc);
 
-/** Set the \c \%printer for \c node as \c printer at \c loc.  */
-void symbol_list_printer_set (symbol_list *node, const char *printer,
+/** Set the \c \%printer for \c node as \c code at \c loc.  */
+void symbol_list_printer_set (symbol_list *node, char const *code,
                               location loc);
 
 #endif /* !SYMLIST_H_ */




reply via email to

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