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.
This commit is contained in:
Akim Demaille
2018-10-02 08:28:46 +02:00
parent 29b1da4e18
commit 3e6a075f7f
6 changed files with 43 additions and 56 deletions

View File

@@ -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[

View File

@@ -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])[

View File

@@ -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++])[
// 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.
/**
** \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])[
#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])[

View File

@@ -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.