mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
yacc: comply with recent POSIX updates: declare yyerror and yylex
In POSIX Yacc mode, declare yyerror and yylex unless already #defined, or if YYERROR_IS_DECLARED/YYLEX_IS_DECLARED are defined (for consistency with Bison's YYSTYPE_IS_DECLARED/YYLTYPE_IS_DECLARED). See <https://austingroupbugs.net/view.php?id=1388#c5220>. * data/skeletons/c.m4 (b4_function_declare): Resurect. (b4_lex_formals): Since we will possibly expose this prototype in the header, take the prefix into account. * data/skeletons/yacc.c (b4_declare_yyerror_and_yylex): New. (b4_shared_declarations): Use it. * tests/local.at (AT_YACC_IF): New. When in Yacc mode, set the `yacc` Autotest keyword. (AT_YYERROR_DECLARE(c)): Don't declare in Yacc mode, to avoid clashes (since this signature is static). (AT_YYERROR_DEFINE(c)): Don't define as static in Yacc mode. * tests/regression.at (Early token definitions with --yacc): Specify that we are in Yacc mode.
This commit is contained in:
@@ -102,6 +102,16 @@ m4_define([b4_yyerror_arg_loc_if],
|
||||
[1], [m4_ifset([b4_parse_param], [$1])],
|
||||
[2], [$1])])])
|
||||
|
||||
# b4_yyerror_formals
|
||||
# ------------------
|
||||
m4_define([b4_yyerror_formals],
|
||||
[b4_pure_if([b4_locations_if([, [[const ]b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])[]dnl
|
||||
m4_ifdef([b4_parse_param], [, b4_parse_param])[]dnl
|
||||
,])dnl
|
||||
[[const char *msg], [msg]]])
|
||||
|
||||
|
||||
|
||||
# b4_yyerror_args
|
||||
# ---------------
|
||||
# Arguments passed to yyerror: user args plus yylloc.
|
||||
@@ -352,17 +362,32 @@ m4_define([b4_declare_yyparse],
|
||||
])
|
||||
|
||||
|
||||
# b4_declare_yyerror_and_yylex
|
||||
# ----------------------------
|
||||
# Comply with POSIX Yacc.
|
||||
# <https://austingroupbugs.net/view.php?id=1388#c5220>
|
||||
m4_define([b4_declare_yyerror_and_yylex],
|
||||
[b4_yacc_if([[#if !defined ]b4_prefix[error && !defined ]b4_api_PREFIX[ERROR_IS_DECLARED
|
||||
]b4_function_declare([b4_prefix[error]], void, b4_yyerror_formals)[
|
||||
#endif
|
||||
#if !defined ]b4_prefix[lex && !defined ]b4_api_PREFIX[LEX_IS_DECLARED
|
||||
]b4_function_declare([b4_prefix[lex]], int, b4_lex_formals)[
|
||||
#endif
|
||||
]])dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_shared_declarations
|
||||
# ----------------------
|
||||
# Declaration that might either go into the header (if --header)
|
||||
# or open coded in the parser body.
|
||||
# Declarations that might either go into the header (if --header)
|
||||
# or into the implementation file.
|
||||
m4_define([b4_shared_declarations],
|
||||
[b4_cpp_guard_open([b4_spec_mapped_header_file])[
|
||||
]b4_declare_yydebug[
|
||||
]b4_percent_code_get([[requires]])[
|
||||
]b4_token_enums_defines[
|
||||
]b4_declare_yylstype[
|
||||
]b4_declare_yyerror_and_yylex[
|
||||
]b4_declare_yyparse[
|
||||
]b4_percent_code_get([[provides]])[
|
||||
]b4_cpp_guard_close([b4_spec_mapped_header_file])[]dnl
|
||||
|
||||
Reference in New Issue
Block a user