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.
This commit is contained in:
Akim Demaille
2013-02-27 15:43:26 +01:00
committed by Akim Demaille
parent ebe9b20841
commit d92ed9d9f7
6 changed files with 62 additions and 34 deletions

View File

@@ -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 void
deprecated_directive (location const *loc, char const *old, char const *upd) deprecated_directive (location const *loc, char const *old, char const *upd)
{ {

View File

@@ -119,6 +119,9 @@ void complain_indent (location const *loc, warnings flags, unsigned *indent,
__attribute__ ((__format__ (__printf__, 4, 5))); __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. */ /** Report an obsolete syntax, suggest the updated one. */
void deprecated_directive (location const *loc, void deprecated_directive (location const *loc,
char const *obsolete, char const *updated); char const *obsolete, char const *updated);

View File

@@ -53,6 +53,10 @@ static boundary scanner_cursor;
static size_t no_cr_read (FILE *, char *, size_t); static size_t no_cr_read (FILE *, char *, size_t);
#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size)) #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) \ #define RETURN_PERCENT_PARAM(Value) \
RETURN_VALUE(PERCENT_PARAM, param_ ## Value) RETURN_VALUE(PERCENT_PARAM, param_ ## Value)
@@ -214,49 +218,49 @@ eqopt ([[:space:]]*=)?
<INITIAL> <INITIAL>
{ {
"%binary" return PERCENT_NONASSOC; "%binary" return BISON_DIRECTIVE(NONASSOC);
"%code" return PERCENT_CODE; "%code" return BISON_DIRECTIVE(CODE);
"%debug" RETURN_PERCENT_FLAG("parse.trace"); "%debug" RETURN_PERCENT_FLAG("parse.trace");
"%default-prec" return PERCENT_DEFAULT_PREC; "%default-prec" return BISON_DIRECTIVE(DEFAULT_PREC);
"%define" return PERCENT_DEFINE; "%define" return BISON_DIRECTIVE(DEFINE);
"%defines" return PERCENT_DEFINES; "%defines" return BISON_DIRECTIVE(DEFINES);
"%destructor" return PERCENT_DESTRUCTOR; "%destructor" return BISON_DIRECTIVE(DESTRUCTOR);
"%dprec" return PERCENT_DPREC; "%dprec" return BISON_DIRECTIVE(DPREC);
"%empty" return PERCENT_EMPTY; "%empty" return BISON_DIRECTIVE(EMPTY);
"%expect" return PERCENT_EXPECT; "%expect" return BISON_DIRECTIVE(EXPECT);
"%expect-rr" return PERCENT_EXPECT_RR; "%expect-rr" return BISON_DIRECTIVE(EXPECT_RR);
"%file-prefix" return PERCENT_FILE_PREFIX; "%file-prefix" return BISON_DIRECTIVE(FILE_PREFIX);
"%fixed-output-files" return PERCENT_YACC; "%fixed-output-files" return BISON_DIRECTIVE(YACC);
"%initial-action" return PERCENT_INITIAL_ACTION; "%initial-action" return BISON_DIRECTIVE(INITIAL_ACTION);
"%glr-parser" return PERCENT_GLR_PARSER; "%glr-parser" return BISON_DIRECTIVE(GLR_PARSER);
"%language" return PERCENT_LANGUAGE; "%language" return BISON_DIRECTIVE(LANGUAGE);
"%left" return PERCENT_LEFT; "%left" return PERCENT_LEFT;
"%lex-param" RETURN_PERCENT_PARAM(lex); "%lex-param" RETURN_PERCENT_PARAM(lex);
"%locations" RETURN_PERCENT_FLAG("locations"); "%locations" RETURN_PERCENT_FLAG("locations");
"%merge" return PERCENT_MERGE; "%merge" return BISON_DIRECTIVE(MERGE);
"%name-prefix" return PERCENT_NAME_PREFIX; "%name-prefix" return BISON_DIRECTIVE(NAME_PREFIX);
"%no-default-prec" return PERCENT_NO_DEFAULT_PREC; "%no-default-prec" return BISON_DIRECTIVE(NO_DEFAULT_PREC);
"%no-lines" return PERCENT_NO_LINES; "%no-lines" return BISON_DIRECTIVE(NO_LINES);
"%nonassoc" return PERCENT_NONASSOC; "%nonassoc" return PERCENT_NONASSOC;
"%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER; "%nondeterministic-parser" return BISON_DIRECTIVE(NONDETERMINISTIC_PARSER);
"%output" return PERCENT_OUTPUT; "%output" return BISON_DIRECTIVE(OUTPUT);
"%param" RETURN_PERCENT_PARAM(both); "%param" RETURN_PERCENT_PARAM(both);
"%parse-param" RETURN_PERCENT_PARAM(parse); "%parse-param" RETURN_PERCENT_PARAM(parse);
"%prec" return PERCENT_PREC; "%prec" return PERCENT_PREC;
"%precedence" return PERCENT_PRECEDENCE; "%precedence" return BISON_DIRECTIVE(PRECEDENCE);
"%printer" return PERCENT_PRINTER; "%printer" return BISON_DIRECTIVE(PRINTER);
"%pure-parser" RETURN_PERCENT_FLAG("api.pure"); "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
"%require" return PERCENT_REQUIRE; "%require" return BISON_DIRECTIVE(REQUIRE);
"%right" return PERCENT_RIGHT; "%right" return PERCENT_RIGHT;
"%skeleton" return PERCENT_SKELETON; "%skeleton" return BISON_DIRECTIVE(SKELETON);
"%start" return PERCENT_START; "%start" return PERCENT_START;
"%term" return PERCENT_TOKEN; "%term" return BISON_DIRECTIVE(TOKEN);
"%token" return PERCENT_TOKEN; "%token" return PERCENT_TOKEN;
"%token-table" return PERCENT_TOKEN_TABLE; "%token-table" return BISON_DIRECTIVE(TOKEN_TABLE);
"%type" return PERCENT_TYPE; "%type" return PERCENT_TYPE;
"%union" return PERCENT_UNION; "%union" return PERCENT_UNION;
"%verbose" return PERCENT_VERBOSE; "%verbose" return BISON_DIRECTIVE(VERBOSE);
"%yacc" return PERCENT_YACC; "%yacc" return BISON_DIRECTIVE(YACC);
/* Deprecated since Bison 3.0 (2013-07-25), but the warning is /* Deprecated since Bison 3.0 (2013-07-25), but the warning is
issued only since Bison 3.3. */ issued only since Bison 3.3. */

View File

@@ -433,7 +433,13 @@ input.y:26.40-42: warning: unset value: $][$ [-Wother]
AT_BISON_CHECK([-Wnone,yacc -fcaret input.y], AT_BISON_CHECK([-Wnone,yacc -fcaret input.y],
[0], [], [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 ($$); } <integer>;
^^^^^^^^^^^
]])[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 <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; }; m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; };
^^^^^^^^^^^^ ^^^^^^^^^^^^
input.y:24.49-65: warning: POSIX Yacc does not support typed midrule actions [-Wyacc] 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] input.y:26.40-42: warning: POSIX Yacc does not support typed midrule actions [-Wyacc]
o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; }; o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
^^^ ^^^
]]) ]m4_ifval([$1], [[input.y:30.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
%destructor { destroy ($$); } <integer>;
^^^^^^^^^^^
]])])
]) ])
## --------------- ## ## --------------- ##
@@ -1169,7 +1178,9 @@ AT_BISON_OPTION_POPDEFS
# POSIX Yacc accept periods, but not dashes. # POSIX Yacc accept periods, but not dashes.
AT_BISON_CHECK([--yacc input.y], [1], [], 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] input.y:20.8-16: error: POSIX Yacc forbids dashes in symbol names: with-dash [-Werror=yacc]
]]) ]])

View File

@@ -44,7 +44,7 @@ done
]AT_DATA([$1], ]AT_DATA([$1],
[$2[ [$2[
%% %%
foo: %empty {}; foo: '0' {};
]]) ]])
# There is not AT_DATA_UNQUOTED. # There is not AT_DATA_UNQUOTED.

View File

@@ -88,7 +88,9 @@ AT_SETUP([Early token definitions with --yacc])
# prologue, so that they can use the token definitions in it. # prologue, so that they can use the token definitions in it.
AT_BISON_OPTION_PUSHDEFS 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_YYERROR_DECLARE_EXTERN[
]AT_YYLEX_DECLARE_EXTERN[ ]AT_YYLEX_DECLARE_EXTERN[