bison-patches
[Top][All Lists]
Advanced

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

computing filenames in skeletons


From: Joel E. Denny
Subject: computing filenames in skeletons
Date: Sat, 9 Dec 2006 21:29:34 -0500 (EST)

Hi Paul.  Could you review the following patch?  It's fairly short, so I 
hope it won't take up too much of your time.  I'm a little worried I might 
be messing up something with respect to file name quoting or 
backward-compatibility.  I haven't installed it yet.  Thanks.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1617
diff -p -u -r1.1617 ChangeLog
--- ChangeLog   10 Dec 2006 00:16:15 -0000      1.1617
+++ ChangeLog   10 Dec 2006 02:25:03 -0000
@@ -1,5 +1,22 @@
 2006-12-09  Joel E. Denny  <address@hidden>
 
+       Make it easier for skeletons to compute output file names with the same
+       file name prefix as Bison-computed output file names.
+       * data/glr.c, data/glr.cc, data/lalr1.cc, data/push.c, data/yacc.c: Use
+       b4_parser_file_name, b4_spec_defines_file, and @base_qputs instead of
+       @output_parser_name@ and @address@hidden
+       * src/files.c (all_but_ext): Remove static qualifier.
+       (compute_output_file_names): Move `free (all_but_ext)' to...
+       (output_file_names_free): ... here since all_but_ext is needed later.
+       * src/files.h (all_but_ext): Declare.
+       * src/output.c (prepare): Define muscle name file_name_all_but_ext as
+       all_but_ext.
+       * src/scan-skel.l: Don't parse @output_header_name@ and
+       @output_parser_name@ anymore since they're now redundant.
+       Parse a new @base_qputs command that invokes BASE_QPUTS.
+
+2006-12-09  Joel E. Denny  <address@hidden>
+
        Warn about output files that are generated by the skeletons and that
        conflict with other output files.
        * data/glr.c: Don't generate the header file here when glr.cc does.
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.192
diff -p -u -r1.192 glr.c
--- data/glr.c  10 Dec 2006 00:16:15 -0000      1.192
+++ data/glr.c  10 Dec 2006 02:25:04 -0000
@@ -142,7 +142,7 @@ m4_define([b4_rhs_location],
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
address@hidden @output_parser_name@
address@hidden b4_parser_file_name
 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
   [2002, 2003, 2004, 2005, 2006])
 [
@@ -207,7 +207,7 @@ typedef struct YYLTYPE
 ]b4_user_provides])[]dnl
 ])
 
-b4_defines_if([#include @address@hidden,
+b4_defines_if([[#include @base_qputs ]b4_spec_defines_file],
              [b4_shared_declarations])[
 
 /* Enabling traces.  */
@@ -2629,7 +2629,7 @@ dnl glr.cc produces its own header.
 dnl
 m4_if(b4_skeleton, ["glr.c"],
 [b4_defines_if(
address@hidden @output_header_name@
address@hidden b4_spec_defines_file
 b4_copyright([Skeleton interface for Bison GLR parsers in C],
   [2002, 2003, 2004, 2005, 2006])
 
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.28
diff -p -u -r1.28 glr.cc
--- data/glr.cc 15 Oct 2006 12:37:06 -0000      1.28
+++ data/glr.cc 10 Dec 2006 02:25:04 -0000
@@ -216,7 +216,7 @@ m4_defn([b4_parse_param])))],
 m4_include(b4_pkgdatadir/[glr.c])
 m4_popdef([b4_parse_param])
 
address@hidden @output_header_name@
address@hidden b4_spec_defines_file
 b4_copyright([Skeleton interface for Bison GLR parsers in C++],
   [2002, 2003, 2004, 2005, 2006])[
 
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.145
diff -p -u -r1.145 lalr1.cc
--- data/lalr1.cc       15 Oct 2006 12:37:06 -0000      1.145
+++ data/lalr1.cc       10 Dec 2006 02:25:04 -0000
@@ -33,7 +33,7 @@ m4_include(b4_pkgdatadir/[location.cc])
 m4_changecom()
 m4_divert(0)dnl
 b4_defines_if(
address@hidden @output_header_name@
address@hidden b4_spec_defines_file
 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
 dnl FIXME: This is wrong, we want computed header guards.
@@ -301,7 +301,7 @@ m4_ifdef([b4_provides],
 
 [#endif /* ! defined PARSER_HEADER_H */]
 ])dnl
address@hidden @output_parser_name@
address@hidden b4_parser_file_name
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
   [2002, 2003, 2004, 2005, 2006])
 m4_if(b4_prefix, [yy], [],
@@ -312,8 +312,8 @@ m4_if(b4_prefix, [yy], [],
 /* First part of user declarations.  */
 ]b4_user_pre_prologue
 
-b4_defines_if([
-#include @address@hidden)[
+b4_defines_if([[
+#include @base_qputs ]b4_spec_defines_file])[
 
 /* User implementation prologue.  */
 ]b4_user_post_prologue[
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.11
diff -p -u -r1.11 push.c
--- data/push.c 8 Dec 2006 22:36:33 -0000       1.11
+++ data/push.c 10 Dec 2006 02:25:05 -0000
@@ -134,7 +134,7 @@ m4_define([b4_rhs_location],
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
address@hidden @output_parser_name@
address@hidden b4_parser_file_name
 b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])[
 
@@ -1638,7 +1638,7 @@ yyreturn:
 
 b4_epilogue
 b4_defines_if(
address@hidden @output_header_name@
address@hidden b4_spec_defines_file
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
 
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.155
diff -p -u -r1.155 yacc.c
--- data/yacc.c 22 Oct 2006 00:28:16 -0000      1.155
+++ data/yacc.c 10 Dec 2006 02:25:05 -0000
@@ -134,7 +134,7 @@ m4_define([b4_rhs_location],
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert(0)dnl
address@hidden @output_parser_name@
address@hidden b4_parser_file_name
 b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])[
 
@@ -1485,7 +1485,7 @@ yyreturn:
 
 b4_epilogue
 b4_defines_if(
address@hidden @output_header_name@
address@hidden b4_spec_defines_file
 b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
   [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
 
Index: src/files.c
===================================================================
RCS file: /sources/bison/bison/src/files.c,v
retrieving revision 1.100
diff -p -u -r1.100 files.c
--- src/files.c 10 Dec 2006 00:16:15 -0000      1.100
+++ src/files.c 10 Dec 2006 02:25:05 -0000
@@ -76,7 +76,7 @@ uniqstr current_file = NULL;
    empty string (meaning the current directory); otherwise it is
    `dir/'.  */
 
-static char *all_but_ext;
+char *all_but_ext;
 static char *all_but_tab_ext;
 char *dir_prefix;
 
@@ -328,7 +328,6 @@ compute_output_file_names (void)
       output_file_name_check (spec_verbose_file);
     }
 
-  free (all_but_ext);
   free (all_but_tab_ext);
   free (src_extension);
   free (header_extension);
@@ -350,6 +349,7 @@ output_file_name_check (char const *file
 void
 output_file_names_free (void)
 {
+  free (all_but_ext);
   free (spec_verbose_file);
   free (spec_graph_file);
   free (spec_defines_file);
Index: src/files.h
===================================================================
RCS file: /sources/bison/bison/src/files.h,v
retrieving revision 1.43
diff -p -u -r1.43 files.h
--- src/files.h 10 Dec 2006 00:16:15 -0000      1.43
+++ src/files.h 10 Dec 2006 02:25:05 -0000
@@ -62,6 +62,9 @@ extern uniqstr grammar_file;
 /* The current file name.  Might change with %include, or with #line.  */
 extern uniqstr current_file;
 
+/* The computed base for output file names.  */
+extern char *all_but_ext;
+
 void compute_output_file_names (void);
 void output_file_names_free (void);
 void output_file_name_check (char const *file_name);
Index: src/output.c
===================================================================
RCS file: /sources/bison/bison/src/output.c,v
retrieving revision 1.259
diff -p -u -r1.259 output.c
--- src/output.c        12 Nov 2006 07:39:37 -0000      1.259
+++ src/output.c        10 Dec 2006 02:25:06 -0000
@@ -603,6 +603,8 @@ prepare (void)
   if (spec_name_prefix)
     MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
 
+  MUSCLE_INSERT_STRING ("file_name_all_but_ext", all_but_ext);
+
 #define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "")
   DEFINE (dir_prefix);
   DEFINE (parser_file_name);
Index: src/scan-skel.l
===================================================================
RCS file: /sources/bison/bison/src/scan-skel.l,v
retrieving revision 1.43
diff -p -u -r1.43 scan-skel.l
--- src/scan-skel.l     10 Dec 2006 00:16:15 -0000      1.43
+++ src/scan-skel.l     10 Dec 2006 02:25:06 -0000
@@ -62,19 +62,6 @@ int skel_lex (void);
   char const *file_name = yytext + sizeof "@output " - 1;
   yytext[yyleng - 1] = '\0';
 
-  /* Decode special file names.  They include the directory part,
-     contrary to their "free" occurrences, used for issuing #includes,
-     which must not include the directory part.  */
-
-  if (*file_name == '@')
-    {
-      if (strcmp (file_name, "@output_header_name@") == 0)
-       file_name = spec_defines_file;
-      else if (strcmp (file_name, "@output_parser_name@") == 0)
-       file_name = parser_file_name;
-      else
-       fatal ("invalid token in skeleton: %s", yytext);
-    }
   if (outname)
     {
       free (outname);
@@ -93,8 +80,12 @@ int skel_lex (void);
 "@oline@"  fprintf (yyout, "%d", lineno + 1);
 "@ofile@"  QPUTS (outname);
 "@dir_prefix@" QPUTS (dir_prefix);
-"@output_parser_name@" BASE_QPUTS (parser_file_name);
-"@output_header_name@" BASE_QPUTS (spec_defines_file);
+
+"@base_qputs ".*\n {
+  char const *file_name = yytext + sizeof "@base_qputs " - 1;
+  yytext[yyleng - 1] = '\0';
+  BASE_QPUTS (file_name);
+}
 
   /* This pattern must not match more than the previous @ patterns. */
 @address@hidden fatal ("invalid @ in skeleton: %s", yytext);




reply via email to

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