From 5d9ccd5a87f7991c6f52d45e2b57ad0b03e76cf7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 10 Sep 2021 06:48:02 +0200 Subject: yacc: declare yyerror/yylex only when POSIXLY_CORRECT The recent changes to comply with POSIX are breaking Automake's test suite. Reported by Kiyoshi Kanazawa. To limit the impact of POSIX changes, bind them to $POSIXLY_CORRECT. Suggested by Karl Berry. The existing `maintainer-check-posix` Make target checks these changes. * src/getargs.h, src/getargs.c (set_yacc): New. Use it. * data/skeletons/bison.m4 (b4_posix_if): New. * data/skeletons/yacc.c (b4_declare_yyerror_and_yylex): Use it. * doc/bison.texi, tests/local.at: Adjust. --- src/getargs.c | 17 ++++++++++++++--- src/getargs.h | 1 + src/parse-gram.c | 8 ++++---- src/parse-gram.h | 3 ++- src/parse-gram.y | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/getargs.c b/src/getargs.c index 697ad7eb..ef559296 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -71,6 +71,18 @@ struct bison_language const *language = &valid_languages[0]; typedef int* (xargmatch_fn) (const char *context, const char *arg); +void +set_yacc (location loc) +{ + yacc_loc = loc; + if (getenv ("POSIXLY_CORRECT")) + muscle_percent_define_insert ("posix", + loc, + muscle_keyword, "", + MUSCLE_PERCENT_DEFINE_D); +} + + /** Decode an option's key. * * \param opt option being decoded. @@ -631,8 +643,7 @@ static struct option const long_options[] = }; /* Build a location for the current command line argument. */ -static -location +static location command_line_location (void) { location res; @@ -835,7 +846,7 @@ getargs (int argc, char *argv[]) case 'y': warning_argmatch ("yacc", 0, 0); - yacc_loc = loc; + set_yacc (loc); break; case COLOR_OPTION: diff --git a/src/getargs.h b/src/getargs.h index a26aec2f..836c1290 100644 --- a/src/getargs.h +++ b/src/getargs.h @@ -140,6 +140,7 @@ void getargs (int argc, char *argv[]); /* Used by parse-gram.y. */ void language_argmatch (char const *arg, int prio, location loc); void skeleton_arg (const char *arg, int prio, location loc); +void set_yacc (location loc); /** In the string \c s, replace all characters \c from by \c to. */ void tr (char *s, char from, char to); diff --git a/src/parse-gram.c b/src/parse-gram.c index 95fe43e0..3bc44dbd 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.7.5.297-b46a. */ +/* A Bison parser, made by GNU Bison 3.8. */ /* Bison implementation for Yacc-like parsers in C @@ -46,10 +46,10 @@ USER NAME SPACE" below. */ /* Identify Bison output, and Bison version. */ -#define YYBISON 30705 +#define YYBISON 30800 /* Bison version string. */ -#define YYBISON_VERSION "3.7.5.297-b46a" +#define YYBISON_VERSION "3.8" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -3129,7 +3129,7 @@ handle_yacc (location const *loc) const char *directive = "%yacc"; bison_directive (loc, directive); if (location_empty (yacc_loc)) - yacc_loc = *loc; + set_yacc (*loc); else duplicate_directive (directive, yacc_loc, *loc); } diff --git a/src/parse-gram.h b/src/parse-gram.h index 10a63528..77849263 100644 --- a/src/parse-gram.h +++ b/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.7.5.297-b46a. */ +/* A Bison parser, made by GNU Bison 3.8. */ /* Bison interface for Yacc-like parsers in C @@ -215,6 +215,7 @@ struct GRAM_LTYPE + int gram_parse (void); /* "%code provides" blocks. */ diff --git a/src/parse-gram.y b/src/parse-gram.y index 1de83d02..15180cb5 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -1112,7 +1112,7 @@ handle_yacc (location const *loc) const char *directive = "%yacc"; bison_directive (loc, directive); if (location_empty (yacc_loc)) - yacc_loc = *loc; + set_yacc (*loc); else duplicate_directive (directive, yacc_loc, *loc); } -- cgit v1.2.1