c++: by default, use const std::string for file names

Reported by Martin Blais and Yuriy Solodkyy.
https://lists.gnu.org/r/help-bison/2020-05/msg00011.html
https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html

While at it, modernize filename_type as api.filename.type and document
it properly.

* data/skeletons/c++.m4 (filename_type): Rename as...
(api.filename.type): this.
Default to const std::string.
* data/skeletons/location.cc (position, location): Expose the
filename_type type.
Use api.filename.type.
* doc/bison.texi (%define Summary): Document api.filename.type.
(C++ Location Values): Document position::filename_type.
* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.
* tests/c++.at: Check that using const file names is ok.
tests/input.at: Check backward compat.
This commit is contained in:
Akim Demaille
2020-06-27 09:43:14 +02:00
parent cf6d8d0631
commit eeafc706e8
8 changed files with 105 additions and 50 deletions

View File

@@ -46,38 +46,45 @@ template <typename T>
bool
check (const T& in, const std::string& s)
{
const static bool verbose = getenv ("VERBOSE");
std::stringstream os;
os << in;
if (os.str () != s)
if (os.str () == s)
{
if (verbose)
std::cerr << os.str () << '\n';
return true;
}
else
{
std::cerr << "fail: " << os.str () << ", expected: " << s << '\n';
return false;
}
return true;
}
int
main (void)
{
const std::string fn = "foo.txt";
int fail = 0;
]AT_YYLTYPE[ loc; fail += check (loc, "1.1");
fail += check (loc + 10, "1.1-10");
loc += 10; fail += check (loc, "1.1-10");
loc += -5; fail += check (loc, "1.1-5");
fail += check (loc - 5, "1.1");
loc -= 5; fail += check (loc, "1.1");
]AT_YYLTYPE[ loc (&fn); fail += check (loc, "foo.txt:1.1");
fail += check (loc + 10, "foo.txt:1.1-10");
loc += 10; fail += check (loc, "foo.txt:1.1-10");
loc += -5; fail += check (loc, "foo.txt:1.1-5");
fail += check (loc - 5, "foo.txt:1.1");
loc -= 5; fail += check (loc, "foo.txt:1.1");
// Check that we don't go below.
// http://lists.gnu.org/archive/html/bug-bison/2013-02/msg00000.html
loc -= 10; fail += check (loc, "1.1");
loc -= 10; fail += check (loc, "foo.txt:1.1");
loc.columns (10); loc.lines (10); fail += check (loc, "1.1-11.0");
loc.lines (-2); fail += check (loc, "1.1-9.0");
loc.lines (-10); fail += check (loc, "1.1");
loc.columns (10); loc.lines (10); fail += check (loc, "foo.txt:1.1-11.0");
loc.lines (-2); fail += check (loc, "foo.txt:1.1-9.0");
loc.lines (-10); fail += check (loc, "foo.txt:1.1");
]AT_YYLTYPE[ loc2 (YY_NULLPTR, 5, 10);
fail += check (loc2, "5.10");
fail += check (loc + loc2, "1.1-5.9");
loc += loc2; fail += check (loc, "1.1-5.9");
fail += check (loc + loc2, "foo.txt:1.1-5.9");
loc += loc2; fail += check (loc, "foo.txt:1.1-5.9");
return !fail;
}
]])

View File

@@ -2220,6 +2220,7 @@ AT_DATA([[input.y]],
%define namespace "foo"
%define variant
%define parser_class_name {parser}
%define filename_type {filename}
%%
start: %empty;
]])
@@ -2244,6 +2245,10 @@ input.y:5.1-34: warning: deprecated directive: '%define parser_class_name {parse
5 | %define parser_class_name {parser}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| %define api.parser.class {parser}
input.y:6.1-32: warning: deprecated directive: '%define filename_type {filename}', use '%define api.filename.type {filename}' [-Wdeprecated]
6 | %define filename_type {filename}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| %define api.filename.type {filename}
input.y:2.1-40: error: invalid value for %define Boolean variable 'lr.keep-unreachable-state'
2 | %define lr.keep_unreachable_states maybe
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~