bison-patches
[Top][All Lists]
Advanced

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

[PATCH 3/4] Use consistent extensions for generated header files.


From: Paolo Bonzini
Subject: [PATCH 3/4] Use consistent extensions for generated header files.
Date: Sun, 2 Nov 2008 15:04:36 +0100

What we can do now is also rename the stack.hh/location.hh/position.hh
files according to the header file name chosen by the user for his
defines file.  As a fan of .cc/.h naming, I cannot but applaud this.
:-)

Note that this is done entirely in m4.

I defined the new m4 macros for C too, just in case.

Paolo


* NEWS: Document change.
* data/bison.m4 (_b4_compute_defines_file_name_and_ext): Rename to...
(_b4_compute_extra_file_name_and_ext): ... this.
(b4_compute_extra_file_name_and_ext): New.
(b4_compute_defines_file_name_and_ext): Use it.
* data/c.m4 (b4_compute_extra_defines_file_name,
b4_compute_extra_source_file_name): New.
* data/c++.m4 (b4_compute_extra_defines_file_name,
b4_compute_extra_source_file_name): New.
* data/lalr1.cc: Use b4_compute_extra_defines_file_name.
* data/location.cc: Likewise.
* doc/bison.texinfo (Output Files): Document it.
* tests/output.at: Fix quoting.
(cpp_aux): Accept second parameter.  Change users.
(AT_CHECK_CONFLICTING_OUTPUT): Use %language.
---
 NEWS              |    5 +++++
 data/bison.m4     |   30 ++++++++++++++++++++----------
 data/c++.m4       |   16 ++++++++++++++++
 data/c.m4         |   16 ++++++++++++++++
 data/lalr1.cc     |    6 +++---
 data/location.cc  |   10 +++++-----
 doc/bison.texinfo |   17 ++++++++++-------
 tests/output.at   |   20 ++++++++++----------
 8 files changed, 85 insertions(+), 35 deletions(-)

diff --git a/NEWS b/NEWS
index 985d34b..843472e 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,11 @@ Changes in version ?.? (????-??-??):
   because the file names it produces are often unintuitive.  The warning
   may be changed into an error in future releases of Bison.
 
+* Auxiliary header files for C++ parsers
+
+  The files `stack.hh', `location.hh', `position.hh' now have the same
+  extension as the --defines file produced by Bison.
+
 Changes in version 2.3b (2008-05-27):
 
 * The quotes around NAME that used to be required in the following directive
diff --git a/data/bison.m4 b/data/bison.m4
index c3ec51e..d288eca 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -264,12 +264,25 @@ m4_define([b4_compute_parser_file_name],
 [m4_ifval(b4_parser_file_name, [b4_parser_file_name],
           [b4_file_prefix[]$1])])
 
-# _b4_compute_defines_file_name_and_ext(FILE, EXT, DEFAULT-EXT,
-#                                       TRANSLIT-FROM, TRANSLIT-TO)
+# _b4_compute_extra_file_name_and_ext(FILE, EXT, DEFAULT-EXT,
+#                                     TRANSLIT-FROM, TRANSLIT-TO)
 # ---------------------------------------------------------------------------
-# Helper macro for b4_compute_defines_file_name.
-m4_define([_b4_compute_defines_file_name_and_ext],
-[$1[]m4_translit([$2], [$3], [$4])])
+# Helper macro for b4_compute_extra_file_name_and_ext.
+m4_define([_b4_compute_extra_file_name_and_ext],
+[m4_echo($1)[]m4_translit([$2], [$3], [$4])])
+
+# b4_compute_extra_file_name_and_ext(MODEL, ROOT, DEFAULT-DEFINES-EXT,
+#                                    TRANSLIT-FROM, TRANSLIT-TO)
+# ----------------------------------------------------------------------------
+# Compute the name of an extra file name from the parser file name, by applying
+# the transliteration given by the other two arguments.   For example:
+#
+#   b4_compute_defines_file_name([[.c]], [[.h]], [[cC]], [[hH]])
+m4_define([b4_compute_extra_file_name_and_ext],
+[m4_if(m4_index($1, .), -1,
+       [m4_bpatsubst($1, [^\(.*\)], [$2])$3],
+       [_$0(m4_bpatsubst($1, [^\(.*\)\(\..*\)], [[$2], [\2]]),
+           [$4], [$5])])])
 
 # b4_compute_defines_file_name_and_ext(DEFAULT-PARSER-EXT, DEFAULT-DEFINES-EXT,
 #                                      TRANSLIT-FROM, TRANSLIT-TO)
@@ -280,11 +293,8 @@ m4_define([_b4_compute_defines_file_name_and_ext],
 #   b4_compute_defines_file_name([[.c]], [[.h]], [[cC]], [[hH]])
 m4_define([b4_compute_defines_file_name_and_ext],
 [m4_ifval(b4_defines_file_name, [b4_defines_file_name],
-         [m4_if(m4_index(b4_compute_parser_file_name([$1]), .), -1,
-                [b4_compute_parser_file_name([$1])$2],
-                [_$0(m4_bpatsubst(m4_quote(b4_compute_parser_file_name([$1])),
-                     [^\(.*\)\(\..*\)], [[\1], [\2]]), [$3], [$4])])])])
-
+         
[b4_compute_extra_file_name_and_ext([b4_compute_parser_file_name([$1])],
+                                             [[\1]], [$2], [$3], [$4])])])
 
 
 ## ----------- ##
diff --git a/data/c++.m4 b/data/c++.m4
index fb852d8..f60eea3 100644
--- a/data/c++.m4
+++ b/data/c++.m4
@@ -42,6 +42,22 @@ b4_percent_define_default([[define_location_comparison]],
 m4_define([b4_compute_defines_file_name],
 [b4_compute_defines_file_name_and_ext([[.cc]], [$1], [[cC]], [[hH]])])
 
+
+# b4_compute_extra_defines_file_name(NAME, DEFAULT-EXT, [PREFIX=b4_dir_prefix])
+# -----------------------------------------------------------------------------
+m4_define([b4_compute_extra_defines_file_name],
+[b4_compute_extra_file_name_and_ext([b4_compute_defines_file_name([[.cc]])],
+                                   [m4_if($#, 3, [$3], [b4_dir_prefix])[]$1],
+                                   [$2], [[cC]], [[hH]])])
+
+
+# b4_compute_extra_source_file_name(NAME, DEFAULT-EXT, [PREFIX=b4_dir_prefix])
+# ----------------------------------------------------------------------------
+m4_define([b4_compute_extra_source_file_name],
+[b4_compute_extra_file_name_and_ext([b4_compute_parser_file_name([[.cc]])],
+                                   [m4_if($#, 3, [$3], [b4_dir_prefix])[]$1],
+                                   [$2])])
+
 ## ----------- ##
 ## Namespace.  ##
 ## ----------- ##
diff --git a/data/c.m4 b/data/c.m4
index 2508ce5..584414f 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -73,6 +73,22 @@ m4_define_default([b4_prefix], [yy])
 m4_define([b4_compute_defines_file_name],
 [b4_compute_defines_file_name_and_ext([[.c]], [$1], [[cC]], [[hH]])])
 
+
+# b4_compute_extra_defines_file_name(NAME, DEFAULT-EXT, [PREFIX=b4_dir_prefix])
+# -----------------------------------------------------------------------------
+m4_define([b4_compute_extra_defines_file_name],
+[b4_compute_extra_file_name_and_ext([b4_compute_defines_file_name([[.c]])],
+                                   [m4_if($#, 3, [$3], [b4_dir_prefix])[]$1],
+                                   [$2], [[cC]], [[hH]])])
+
+
+# b4_compute_extra_source_file_name(NAME, DEFAULT-EXT, [PREFIX=b4_dir_prefix])
+# ----------------------------------------------------------------------------
+m4_define([b4_compute_extra_source_file_name],
+[b4_compute_extra_file_name_and_ext([b4_compute_parser_file_name([[.c]])],
+                                   [m4_if($#, 3, [$3], [b4_dir_prefix])[]$1],
+                                   [$2])])
+
 ## ------------------------ ##
 ## Pure/impure interfaces.  ##
 ## ------------------------ ##
diff --git a/data/lalr1.cc b/data/lalr1.cc
index bb11e82..bbf23eb 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -47,14 +47,14 @@ dnl FIXME: This is wrong, we want computed header guards.
 
 #include <string>
 #include <iostream>
-#include "stack.hh"
+#include "]b4_compute_extra_defines_file_name([[stack]], [[.hh]], [])["
 
 ]b4_namespace_open[
   class position;
   class location;
 ]b4_namespace_close[
 
-#include "location.hh"
+#include "]b4_compute_extra_defines_file_name([[location]], [[.hh]], [])["
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
@@ -1055,7 +1055,7 @@ b4_error_verbose_if([, int tok])[)
 
 ]b4_epilogue
 dnl
address@hidden(b4_dir_prefix[]stack.hh@)
address@hidden(b4_compute_extra_defines_file_name([[stack]], [[.hh]])@)
 b4_copyright([Stack handling for Bison parsers in C++],
              [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
 
diff --git a/data/location.cc b/data/location.cc
index 11fab9c..92e12bb 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -19,12 +19,12 @@
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 m4_divert_push(0)dnl
address@hidden(b4_dir_prefix[]position.hh@)
address@hidden(b4_compute_extra_defines_file_name([[position]], [[.hh]])@)
 b4_copyright([Positions for Bison parsers in C++],
   [2002, 2003, 2004, 2005, 2006, 2007])[
 
 /**
- ** \file position.hh
+ ** \file ]b4_compute_extra_defines_file_name([[position]], [[.hh]])[
  ** Define the ]b4_namespace_ref[::position class.
  */
 
@@ -143,12 +143,12 @@ b4_copyright([Positions for Bison parsers in C++],
 
 ]b4_namespace_close[
 #endif // not BISON_POSITION_HH]
address@hidden(b4_dir_prefix[]location.hh@)
address@hidden(b4_compute_extra_defines_file_name([[location]], [[.hh]])@)
 b4_copyright([Locations for Bison parsers in C++],
   [2002, 2003, 2004, 2005, 2006, 2007])[
 
 /**
- ** \file location.hh
+ ** \file ]b4_compute_extra_defines_file_name([[location]], [[.hh]])[
  ** Define the ]b4_namespace_ref[::location class.
  */
 
@@ -157,7 +157,7 @@ b4_copyright([Locations for Bison parsers in C++],
 
 # include <iostream>
 # include <string>
-# include "position.hh"
+# include "]b4_compute_extra_defines_file_name([[position]], [[.hh]])["
 
 ]b4_namespace_open[
 
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index 52e487e..91eba6e 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -7861,13 +7861,16 @@ not allowed by the file system.
 
 @item Auxiliary Code Files
 
-For some output languages, Bison generates auxiliary code files whose base
-names are static but that will be placed in any directory you specify as part
-of the file prefix.
-For example, one of the auxiliary header files Bison always generates for C++
-is @code{location.hh}.
-If the file prefix is @code{foo/bar}, then the file name is
address@hidden/location.hh}.
+For some output languages, Bison generates auxiliary code files that will
+be placed in any directory you specify as part of the file prefix.
+The extension will usually be based on that of the parser source code
+file, or of the parser header file.
+For example, one of the auxiliary header files Bison always generates
+for C++ is @address@hidden  If the file prefix
+is @code{foo/bar}, and the extension of the parser header file is
address@hidden@footnote{Note that the extensions are computed
+  @emph{even if the header file itself is not generated}.} then the file
+  name is @code{foo/location.hh}.
 @xref{Other Languages}, for a description of the various auxiliary files.
 
 @item Automaton Files
diff --git a/tests/output.at b/tests/output.at
index 0b3728e..e50676c 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -24,7 +24,7 @@ AT_BANNER([[Output file names.]])
 m4_define([AT_CHECK_OUTPUT],
 [AT_SETUP([[Output files: ]$2 $3 $5])
 for file in $1 $4; do
-  case "$file" in
+  case "$file" in @%:@(
     */*) mkdir -p `echo "$file" | sed 's,/.*,,'`;;
   esac
 done
@@ -128,13 +128,13 @@ AT_CHECK_OUTPUT([gram_dir/foo.yy],
 ## %language.  ##
 ## ----------- ##
 
-m4_define([cpp_aux], [$1[location.hh ]$1[position.hh ]$1[stack.hh]])
+m4_define([cpp_aux], [[$1][location.$2 $1][position.$2 $1][stack.$2]])
 
 # Default.
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x]],
                 [[foo.c foo.h foo.output foo.dot foo.xml]])
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x]],
-                [[foo.cc foo.hh foo.output foo.dot foo.xml ]cpp_aux])
+                [[foo.cc foo.hh foo.output foo.dot foo.xml ]]cpp_aux([], 
[[hh]]))
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x]],
                 [[foo.java foo.output foo.dot foo.xml]])
 
@@ -142,7 +142,7 @@ AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x]],
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -y]],
                 [[y.tab.c y.tab.h y.output y.dot y.xml]])
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -y]],
-                [[y.tab.cc y.tab.hh y.output y.dot y.xml ]cpp_aux])
+                [[y.tab.cc y.tab.hh y.output y.dot y.xml ]]cpp_aux([], [[hh]]))
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x -y]],
                 [[y.tab.java y.output y.dot y.xml]])
 
@@ -152,7 +152,7 @@ AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -bdir/b]],
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -bdir/b -y]],
                 [[dir/b.tab.c dir/b.tab.h dir/b.output dir/b.dot dir/b.xml]])
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -bdir/b]],
-                [[dir/b.cc dir/b.hh dir/b.output dir/b.dot dir/b.xml 
]cpp_aux([[dir/]])])
+                [[dir/b.cc dir/b.hh dir/b.output dir/b.dot dir/b.xml 
]]cpp_aux([[dir/]], [[hh]]))
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x -bdir/b]],
                 [[dir/b.java dir/b.output dir/b.dot dir/b.xml]])
 
@@ -163,9 +163,9 @@ dnl                 [[bar-c dir/b.h dir/b.output dir/b.dot 
dir/b.xml]])
 dnl AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -bdir/b -obar-c -y]],
 dnl                 [[bar-c dir/b.tab.h dir/b.output dir/b.dot dir/b.xml]])
 dnl AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -bdir/b -obar.C]],
-dnl                 [[bar.C dir/b.H dir/b.output dir/b.dot dir/b.xml 
]cpp_aux([[dir/]])])
+dnl                 [[bar.C dir/b.H dir/b.output dir/b.dot dir/b.xml 
]]cpp_aux([[dir/]], [[H]]))
 dnl AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -bdir/b -obar.cpp]],
-dnl                 [[bar.cpp dir/b.hpp dir/b.output dir/b.dot dir/b.xml 
]cpp_aux([[dir/]])])
+dnl                 [[bar.cpp dir/b.hpp dir/b.output dir/b.dot dir/b.xml 
]]cpp_aux([[dir/]], [[hpp]]))
 dnl AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x -bdir/b -obar.Java]],
 dnl                 [[bar.Java dir/b.output dir/b.dot dir/b.xml]])
 
@@ -175,9 +175,9 @@ AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -obar-c]],
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC -dv -g -x -obar-c -y]],
                 [[bar-c bar-c.h bar-c.output bar-c.dot bar-c.xml]])
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -obar.C]],
-                [[bar.C bar.H bar.output bar.dot bar.xml ]cpp_aux])
+                [[bar.C bar.H bar.output bar.dot bar.xml ]]cpp_aux([], [[H]]))
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LC++ -dv -g -x -obar.cpp]],
-                [[bar.cpp bar.hpp bar.output bar.dot bar.xml ]cpp_aux])
+                [[bar.cpp bar.hpp bar.output bar.dot bar.xml ]]cpp_aux([], 
[[hpp]]))
 AT_CHECK_OUTPUT([[foo.bison]],, [[-LJava -v -g -x -odir/bar.Java]],
                 [[dir/bar.Java dir/bar.output dir/bar.dot dir/bar.xml]])
 
@@ -218,7 +218,7 @@ AT_CHECK_CONFLICTING_OUTPUT([foo.y],
 ])
 
 AT_CHECK_CONFLICTING_OUTPUT([foo.y],
-[%skeleton "lalr1.cc" %defines], [--graph="location.hh"],
+[%language "C++" %defines], [--graph="location.hh"],
 [foo.y: warning: conflicting outputs to file `location.hh'
 ])
 
-- 
1.5.5





reply via email to

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