bison-patches
[Top][All Lists]
Advanced

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

[PATCH 4/8] c++: make position.hh completely useless


From: Akim Demaille
Subject: [PATCH 4/8] c++: make position.hh completely useless
Date: Sat, 6 Oct 2018 18:03:13 +0200

Let's put the definition of position into location.hh, there's no real
value in keeping them separate: they are small, and share the same
requirements.

To help users transition to this new model, still generate position.hh
by default, but as a simple include to location.hh.

* data/location.cc (api.position.file): Accept only 'none' as possible
value.
(position.hh): Make it a stub.
(location.hh): Adjust.
(b4_position_define): Merge into...
(b4_location_define): this.
* data/glr.cc, data/lalr1.cc, tests/input.at, tests/output.at: Adjust.
---
 data/glr.cc      |  6 +----
 data/lalr1.cc    |  6 +----
 data/location.cc | 66 ++++++++++++++++++++++++------------------------
 data/stack.hh    |  4 ++-
 tests/input.at   |  3 ++-
 tests/output.at  | 16 +++---------
 6 files changed, 44 insertions(+), 57 deletions(-)

diff --git a/data/glr.cc b/data/glr.cc
index a89ede60..6eba471e 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -246,8 +246,6 @@ b4_percent_code_get([[requires]])[
 #include <stdexcept>
 #include <string>
 
-]m4_ifdef([b4_position_file],
-          [[# include "]b4_position_file["]])[
 ]m4_ifdef([b4_location_file],
           [[# include "]b4_location_file["]])[
 
@@ -257,9 +255,7 @@ b4_percent_code_get([[requires]])[
 
 ]b4_namespace_open[
 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
-                                  [m4_ifndef([b4_position_file], 
[b4_position_define
-
-])[]b4_location_define])])[
+                                  [b4_location_define])])[
 
   /// A Bison parser.
   class ]b4_parser_class_name[
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 59b277ac..7709c2cd 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -163,8 +163,6 @@ m4_define([b4_shared_declarations],
 # include <vector>
 
 ]b4_cxx_portability[
-]m4_ifdef([b4_position_file],
-          [[# include "]b4_position_file["]])[
 ]m4_ifdef([b4_location_file],
           [[# include "]b4_location_file["]])[
 ]b4_variant_if([b4_variant_includes])[
@@ -178,9 +176,7 @@ m4_define([b4_shared_declarations],
 
 ]b4_stack_define[
 ]b4_bison_locations_if([m4_ifndef([b4_location_file],
-                                  [m4_ifndef([b4_position_file], 
[b4_position_define
-
-])[]b4_location_define])])[
+                                  [b4_location_define])])[
 
 ]b4_variant_if([b4_variant_define])[
 
diff --git a/data/location.cc b/data/location.cc
index 6b82a115..7ebf2f40 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -18,23 +18,32 @@
 m4_pushdef([b4_copyright_years],
            [2002-2015, 2018])
 
+
 # b4_position_file
+# ----------------
+# Name of the file containing the position class, if we want this file.
+b4_percent_define_ifdef([[api.position.file]],
+[b4_percent_define_check_values([[[[api.position.file]],
+                                  [[none]]]])],
+[b4_defines_if([b4_percent_define_ifdef([[api.location.file]],
+                                        [],
+                                        [m4_define([b4_position_file], 
[position.hh])])])])
+
+
 # b4_location_file
 # ----------------
 # Name of the file containing the position/location class,
 # if we want this file.
-b4_percent_define_check_file([b4_position_file],
-                             [[api.position.file]],
-                             b4_defines_if([[position.hh]]))
 b4_percent_define_check_file([b4_location_file],
                              [[api.location.file]],
                              b4_defines_if([[location.hh]]))
 
 
-# b4_position_define
+
+# b4_location_define
 # ------------------
-# Define class position.
-m4_define([b4_position_define],
+# Define the position and location classes.
+m4_define([b4_location_define],
 [[  /// Abstract a position.
   class position
   {
@@ -152,13 +161,8 @@ m4_define([b4_position_define],
       ostr << *pos.filename << ':';
     return ostr << pos.line << '.' << pos.column;
   }
-]])
 
-
-# b4_location_define
-# ------------------
-m4_define([b4_location_define],
-[[  /// Abstract a location.
+  /// Abstract a location.
   class location
   {
   public:
@@ -302,25 +306,18 @@ m4_define([b4_location_define],
 
 m4_ifdef([b4_position_file], [[
 ]b4_output_begin([b4_dir_prefix[]b4_position_file])[
-]b4_copyright([Positions for Bison parsers in C++])[
-
-/**
- ** \file ]b4_dir_prefix[]b4_position_file[
- ** Define the ]b4_namespace_ref[::position class.
- */
-
-]b4_cpp_guard_open([b4_dir_prefix[]b4_position_file])[
-
-# include <algorithm> // std::max
-# include <iostream>
-# include <string>
-
-]b4_null_define[
-
-]b4_namespace_open[
-]b4_position_define[
-]b4_namespace_close[
-]b4_cpp_guard_close([b4_dir_prefix[]b4_position_file])[
+// Starting with Bison 3.2, this file is useless: the structure it
+// used to define is now defined in "]b4_location_file[".
+//
+// To get rid of this file:
+// 1. add '%define api.position.file none'
+//     or '%define api.location.file none'
+//     or '%define api.location.file "my-loc.hh"' to your grammar file
+// 2. add 'require "3.2"' to your grammar file
+// 3. remove references to this file from your build system
+// 4. if you used to include it, include "]b4_location_file[" instead.
+
+#include "]b4_location_file["
 ]b4_output_end[
 ]])
 
@@ -336,10 +333,13 @@ m4_ifdef([b4_location_file], [[
 
 ]b4_cpp_guard_open([b4_dir_prefix[]b4_location_file])[
 
-]m4_ifdef([b4_position_file], [[#] include "b4_position_file"], 
[b4_null_define])[
+# include <algorithm> // std::max
+# include <iostream>
+# include <string>
+
+]b4_null_define[
 
 ]b4_namespace_open[
-]m4_ifndef([b4_position_file], [b4_position_define])[
 ]b4_location_define[
 ]b4_namespace_close[
 ]b4_cpp_guard_close([b4_dir_prefix[]b4_location_file])[
diff --git a/data/stack.hh b/data/stack.hh
index 76bfbc61..992e92ef 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -143,7 +143,9 @@ m4_ifdef([b4_stack_file],
 // used to define is now defined with the parser itself.
 //
 // To get rid of this file:
-// 1. add '%define api.stack.file none' to your grammar file
+// 1. add '%define api.stack.file none'
+//     or '%define api.location.file none'
+//     or '%define api.location.file "my-loc.hh"' to your grammar file
 // 2. add 'require "3.2"' to your grammar file
 // 3. remove references to this file from your build system.
 
diff --git a/tests/input.at b/tests/input.at
index 1acc9b51..bbe5e27a 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1667,9 +1667,10 @@ AT_DATA([[input.y]],
 start: %empty;
 ]])
 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
-[[input.y:5.9-25: error: %define variable 'api.position.file' requires 'none' 
or '"..."' values
+[[input.y:5.9-25: error: invalid value for %define variable 
'api.position.file': 'bogus'
  %define api.position.file bogus
          ^^^^^^^^^^^^^^^^^
+input.y:5.9-25:     accepted value: 'none'
 input.y:4.9-25: error: %define variable 'api.location.file' requires 'none' or 
'"..."' values
  %define api.location.file {bogus}
          ^^^^^^^^^^^^^^^^^
diff --git a/tests/output.at b/tests/output.at
index 78af8be5..1684fa04 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -195,26 +195,18 @@ AT_CHECK_OUTPUT([foo.yy],
                 [],
                 [foo.tab.cc foo.tab.hh location.hh])
 
+# api.location.file=none => api.position.file=none
 AT_CHECK_OUTPUT([foo.yy],
-                [%skeleton "lalr1.cc" %defines %define api.stack.file none 
%locations %define api.position.file none %define api.location.file none],
+                [%skeleton "lalr1.cc" %defines %define api.stack.file none 
%locations %define api.location.file none],
                 [],
                 [foo.tab.cc foo.tab.hh])
 
+# api.location.file="*" => api.position.file=none
 AT_CHECK_OUTPUT([foo.yy],
-                [%skeleton "lalr1.cc" %defines %define api.stack.file none 
%locations %define api.position.file none %define api.location.file 
"foo.loc.hh"],
+                [%skeleton "lalr1.cc" %defines %define api.stack.file none 
%locations %define api.location.file "foo.loc.hh"],
                 [],
                 [foo.loc.hh foo.tab.cc foo.tab.hh])
 
-AT_CHECK_OUTPUT([foo.yy],
-                [%skeleton "lalr1.cc" %defines %define api.stack.file none 
%locations %define api.position.file "foo.pos.hh" %define api.location.file 
"foo.loc.hh"],
-                [],
-                [foo.loc.hh foo.pos.hh foo.tab.cc foo.tab.hh])
-
-AT_CHECK_OUTPUT([gram_dir/foo.yy],
-                [%skeleton "lalr1.cc" %verbose %defines %file-prefix 
"output_dir/foo"],
-                [],
-                [output_dir/foo.output output_dir/foo.tab.cc 
output_dir/foo.tab.hh])
-
 
 # AT_CHECK_CONFLICTING_OUTPUT(INPUT-FILE, DIRECTIVES, FLAGS, STDERR,
 #                             [EXIT-STATUS])
-- 
2.19.0




reply via email to

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