[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: c++: provide control over the stack.hh file name
From: |
Akim Demaille |
Subject: |
Re: RFC: c++: provide control over the stack.hh file name |
Date: |
Tue, 2 Oct 2018 14:37:04 +0200 |
> Le 2 oct. 2018 à 07:19, Akim Demaille <address@hidden> a écrit :
>
> Here’s a proposal to make stack.hh completely useless.
Here’s another one, to make position.hh useless.
commit 422f1abf1c213c732e03c9dfd54ff2e479ea91ef
Author: Akim Demaille <address@hidden>
Date: Tue Oct 2 08:28:46 2018 +0200
c++: make position.hh completely useless
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.
diff --git a/data/glr.cc b/data/glr.cc
index 5de23e69..512d11d4 100644
--- a/data/glr.cc
+++ b/data/glr.cc
@@ -245,8 +245,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["]])[
@@ -256,9 +254,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 eb4e8837..8c57799c 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -194,8 +194,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])[
@@ -209,9 +207,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 72855739..0b4bf14e 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -19,22 +19,27 @@ 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([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 +157,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 +302,17 @@ 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.
+/* 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' 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.
*/
-
-]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])[
+]m4_ifdef([b4_location_file],
+ [[# include "]b4_location_file["]])[
]b4_output_end[
]])
@@ -336,10 +328,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/tests/input.at b/tests/input.at
index e196bd7b..e48979ea 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1642,9 +1642,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 39e0c706..75b20ea3 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -205,16 +205,6 @@ AT_CHECK_OUTPUT([foo.yy],
[],
[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])