mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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:
@@ -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[
|
||||
|
||||
@@ -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])[
|
||||
|
||||
|
||||
@@ -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])[
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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}
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user