C++: let %require "3.2" disable the generation of obsolete files

The files stack.hh and position.hh are deprecated.  Rather than
devoting specify %define variables to discard them (api.position.file
and api.stack.file), and rather than having to use special rules when
api.location.file is used, let's simply decide that from %require
"3.2" onwards, these files will not be generated.

The only noticeable thing here is that, in order to be able to check
the behavior of %require "3.2", to have this version (which is still
3.1-*) to accept %require "3.2".

* src/gram.h, src/gram.c (required_version): New.
* src/parse-gram.y (version_check): Set it.
* src/output.c (prepare): Pass it m4.
* data/bison.m4 (b4_required_version_if): Receive it and use it.
* data/location.cc, data/stack.hh: Replace the api.*.file with only
required version comparison.
* tests/input.at: No longer check api.stack.file and api.position.file.
* NEWS, doc/bison.texi: Don't mention them.
Document the %require 3.2 behavior.
* tests/output.at: Use %require 3.2 instead.
This commit is contained in:
Akim Demaille
2018-10-15 14:04:00 +02:00
parent 2b0a9c69df
commit ea31f21fd8
11 changed files with 76 additions and 122 deletions

View File

@@ -46,6 +46,8 @@ symbol_number *token_translations = NULL;
int max_user_token_number = 256;
int required_version = 0;
bool
rule_useful_in_grammar_p (rule const *r)
{

View File

@@ -271,4 +271,8 @@ void grammar_rules_useless_report (const char *message);
/* Free the packed grammar. */
void grammar_free (void);
/* The version %required by the grammar file, as an int (100 * major +
minor). 0 if unspecified. */
extern int required_version;
#endif /* !GRAM_H_ */

View File

@@ -625,6 +625,8 @@ prepare (void)
char const *cp = getenv ("BISON_USE_PUSH_FOR_PULL");
bool use_push_for_pull_flag = cp && *cp && strtol (cp, 0, 10);
MUSCLE_INSERT_INT ("required_version", required_version);
/* Flags. */
MUSCLE_INSERT_BOOL ("defines_flag", defines_flag);
MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);

View File

@@ -32,6 +32,7 @@
%code
{
#include "system.h"
#include <errno.h>
#include "c-ctype.h"
#include "complain.h"
@@ -822,10 +823,37 @@ add_param (param_type type, char *decl, location loc)
static void
version_check (location const *loc, char const *version)
{
if (strverscmp (version, PACKAGE_VERSION) > 0)
/* Changes of behavior are only on minor version changes, so "3.0.5"
is the same as "3.0". */
errno = 0;
char* cp = NULL;
unsigned long major = strtoul (version, &cp, 10);
if (errno || *cp != '.')
{
complain (loc, complaint, "require bison %s, but have %s",
version, PACKAGE_VERSION);
complain (loc, complaint, _("invalid version requirement: %s"),
version);
return;
}
++cp;
unsigned long minor = strtoul (cp, NULL, 10);
if (errno)
{
complain (loc, complaint, _("invalid version requirement: %s"),
version);
return;
}
required_version = major * 100 + minor;
/* Pretend to be at least 3.2, even if we are only 3.1-211, as it
allows us to check features published in 3.2 while developping
3.2. */
const char* api_version = "3.2";
const char* package_version =
strverscmp (api_version, PACKAGE_VERSION) > 0
? api_version : PACKAGE_VERSION;
if (strverscmp (version, package_version) > 0)
{
complain (loc, complaint, _("require bison %s, but have %s"),
version, package_version);
exit (EX_MISMATCH);
}
}