From d92ed9d9f72bfe98dfee5d13800aef95b87c82c6 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 27 Feb 2013 15:43:26 +0100 Subject: [PATCH] diagnostics: complain about Bison directives when -Wyacc * src/complain.h, src/complain.c (bison_directive): New. * src/scan-gram.l (BISON_DIRECTIVE): New. Use it for Bison extensions. --- src/complain.c | 8 ++++++ src/complain.h | 3 +++ src/scan-gram.l | 62 ++++++++++++++++++++++++--------------------- tests/input.at | 17 ++++++++++--- tests/output.at | 2 +- tests/regression.at | 4 ++- 6 files changed, 62 insertions(+), 34 deletions(-) diff --git a/src/complain.c b/src/complain.c index 6c1acf39..7367a21d 100644 --- a/src/complain.c +++ b/src/complain.c @@ -374,6 +374,14 @@ complain_args (location const *loc, warnings w, unsigned *indent, } } + +void +bison_directive (location const *loc, char const *directive) +{ + complain (loc, Wyacc, + _("POSIX Yacc does not support %s"), directive); +} + void deprecated_directive (location const *loc, char const *old, char const *upd) { diff --git a/src/complain.h b/src/complain.h index 41d0c566..4191832d 100644 --- a/src/complain.h +++ b/src/complain.h @@ -119,6 +119,9 @@ void complain_indent (location const *loc, warnings flags, unsigned *indent, __attribute__ ((__format__ (__printf__, 4, 5))); +/** GNU Bison extension not valid with POSIX Yacc. */ +void bison_directive (location const *loc, char const *directive); + /** Report an obsolete syntax, suggest the updated one. */ void deprecated_directive (location const *loc, char const *obsolete, char const *updated); diff --git a/src/scan-gram.l b/src/scan-gram.l index 2b77226b..61256a0d 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -53,6 +53,10 @@ static boundary scanner_cursor; static size_t no_cr_read (FILE *, char *, size_t); #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size)) +/* Report that yytext is an extension, and evaluate to its token type. */ +#define BISON_DIRECTIVE(Directive) \ + (bison_directive (loc, yytext), PERCENT_ ## Directive) + #define RETURN_PERCENT_PARAM(Value) \ RETURN_VALUE(PERCENT_PARAM, param_ ## Value) @@ -214,49 +218,49 @@ eqopt ([[:space:]]*=)? { - "%binary" return PERCENT_NONASSOC; - "%code" return PERCENT_CODE; + "%binary" return BISON_DIRECTIVE(NONASSOC); + "%code" return BISON_DIRECTIVE(CODE); "%debug" RETURN_PERCENT_FLAG("parse.trace"); - "%default-prec" return PERCENT_DEFAULT_PREC; - "%define" return PERCENT_DEFINE; - "%defines" return PERCENT_DEFINES; - "%destructor" return PERCENT_DESTRUCTOR; - "%dprec" return PERCENT_DPREC; - "%empty" return PERCENT_EMPTY; - "%expect" return PERCENT_EXPECT; - "%expect-rr" return PERCENT_EXPECT_RR; - "%file-prefix" return PERCENT_FILE_PREFIX; - "%fixed-output-files" return PERCENT_YACC; - "%initial-action" return PERCENT_INITIAL_ACTION; - "%glr-parser" return PERCENT_GLR_PARSER; - "%language" return PERCENT_LANGUAGE; + "%default-prec" return BISON_DIRECTIVE(DEFAULT_PREC); + "%define" return BISON_DIRECTIVE(DEFINE); + "%defines" return BISON_DIRECTIVE(DEFINES); + "%destructor" return BISON_DIRECTIVE(DESTRUCTOR); + "%dprec" return BISON_DIRECTIVE(DPREC); + "%empty" return BISON_DIRECTIVE(EMPTY); + "%expect" return BISON_DIRECTIVE(EXPECT); + "%expect-rr" return BISON_DIRECTIVE(EXPECT_RR); + "%file-prefix" return BISON_DIRECTIVE(FILE_PREFIX); + "%fixed-output-files" return BISON_DIRECTIVE(YACC); + "%initial-action" return BISON_DIRECTIVE(INITIAL_ACTION); + "%glr-parser" return BISON_DIRECTIVE(GLR_PARSER); + "%language" return BISON_DIRECTIVE(LANGUAGE); "%left" return PERCENT_LEFT; "%lex-param" RETURN_PERCENT_PARAM(lex); "%locations" RETURN_PERCENT_FLAG("locations"); - "%merge" return PERCENT_MERGE; - "%name-prefix" return PERCENT_NAME_PREFIX; - "%no-default-prec" return PERCENT_NO_DEFAULT_PREC; - "%no-lines" return PERCENT_NO_LINES; + "%merge" return BISON_DIRECTIVE(MERGE); + "%name-prefix" return BISON_DIRECTIVE(NAME_PREFIX); + "%no-default-prec" return BISON_DIRECTIVE(NO_DEFAULT_PREC); + "%no-lines" return BISON_DIRECTIVE(NO_LINES); "%nonassoc" return PERCENT_NONASSOC; - "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER; - "%output" return PERCENT_OUTPUT; + "%nondeterministic-parser" return BISON_DIRECTIVE(NONDETERMINISTIC_PARSER); + "%output" return BISON_DIRECTIVE(OUTPUT); "%param" RETURN_PERCENT_PARAM(both); "%parse-param" RETURN_PERCENT_PARAM(parse); "%prec" return PERCENT_PREC; - "%precedence" return PERCENT_PRECEDENCE; - "%printer" return PERCENT_PRINTER; + "%precedence" return BISON_DIRECTIVE(PRECEDENCE); + "%printer" return BISON_DIRECTIVE(PRINTER); "%pure-parser" RETURN_PERCENT_FLAG("api.pure"); - "%require" return PERCENT_REQUIRE; + "%require" return BISON_DIRECTIVE(REQUIRE); "%right" return PERCENT_RIGHT; - "%skeleton" return PERCENT_SKELETON; + "%skeleton" return BISON_DIRECTIVE(SKELETON); "%start" return PERCENT_START; - "%term" return PERCENT_TOKEN; + "%term" return BISON_DIRECTIVE(TOKEN); "%token" return PERCENT_TOKEN; - "%token-table" return PERCENT_TOKEN_TABLE; + "%token-table" return BISON_DIRECTIVE(TOKEN_TABLE); "%type" return PERCENT_TYPE; "%union" return PERCENT_UNION; - "%verbose" return PERCENT_VERBOSE; - "%yacc" return PERCENT_YACC; + "%verbose" return BISON_DIRECTIVE(VERBOSE); + "%yacc" return BISON_DIRECTIVE(YACC); /* Deprecated since Bison 3.0 (2013-07-25), but the warning is issued only since Bison 3.3. */ diff --git a/tests/input.at b/tests/input.at index 19c1fafc..0ada606e 100644 --- a/tests/input.at +++ b/tests/input.at @@ -433,7 +433,13 @@ input.y:26.40-42: warning: unset value: $][$ [-Wother] AT_BISON_CHECK([-Wnone,yacc -fcaret input.y], [0], [], -[[input.y:24.23-34: warning: POSIX Yacc does not support typed midrule actions [-Wyacc] +[m4_ifval([$1], [], [[input.y:3.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc] + %destructor { destroy ($$); } ; + ^^^^^^^^^^^ +]])[input.y:13.10-15: warning: POSIX Yacc does not support %empty [-Wyacc] + b: INT | %empty; + ^^^^^^ +input.y:24.23-34: warning: POSIX Yacc does not support typed midrule actions [-Wyacc] m: INT | INT { $][$ = $][1; } INT { $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; }; ^^^^^^^^^^^^ input.y:24.49-65: warning: POSIX Yacc does not support typed midrule actions [-Wyacc] @@ -451,7 +457,10 @@ input.y:26.23-25: warning: POSIX Yacc does not support typed midrule actions [-W input.y:26.40-42: warning: POSIX Yacc does not support typed midrule actions [-Wyacc] o: INT | INT { } INT { } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; }; ^^^ -]]) +]m4_ifval([$1], [[input.y:30.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc] + %destructor { destroy ($$); } ; + ^^^^^^^^^^^ +]])]) ]) ## --------------- ## @@ -1169,7 +1178,9 @@ AT_BISON_OPTION_POPDEFS # POSIX Yacc accept periods, but not dashes. AT_BISON_CHECK([--yacc input.y], [1], [], -[[input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Werror=yacc] +[[input.y:1.1-5: error: POSIX Yacc does not support %code [-Werror=yacc] +input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Werror=yacc] +input.y:13.1-5: error: POSIX Yacc does not support %code [-Werror=yacc] input.y:20.8-16: error: POSIX Yacc forbids dashes in symbol names: with-dash [-Werror=yacc] ]]) diff --git a/tests/output.at b/tests/output.at index e1137002..b00746f8 100644 --- a/tests/output.at +++ b/tests/output.at @@ -44,7 +44,7 @@ done ]AT_DATA([$1], [$2[ %% -foo: %empty {}; +foo: '0' {}; ]]) # There is not AT_DATA_UNQUOTED. diff --git a/tests/regression.at b/tests/regression.at index 0e4e7693..d0cb5107 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -88,7 +88,9 @@ AT_SETUP([Early token definitions with --yacc]) # prologue, so that they can use the token definitions in it. AT_BISON_OPTION_PUSHDEFS -AT_DATA_GRAMMAR([input.y], + +# Not AT_DATA_GRAMMAR, which uses %code, which is not supported by Yacc. +AT_DATA([input.y], [[%{ ]AT_YYERROR_DECLARE_EXTERN[ ]AT_YYLEX_DECLARE_EXTERN[