mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-23 19:23:02 +00:00
m4: decommission function generating macro
These macros have been extremely useful when we had to support K&R C, which we dropped long ago. Now, they merely make the code uselessly hard to read. * data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc, * data/skeletons/yacc.c: Stop using b4_function_define.
This commit is contained in:
4
TODO
4
TODO
@@ -91,6 +91,10 @@ Maybe we should exhibit the YYUNDEFTOK token. It could also be assigned a
|
|||||||
semantic value so that yyerror could be used to report invalid lexemes.
|
semantic value so that yyerror could be used to report invalid lexemes.
|
||||||
See also the item "$undefined" below.
|
See also the item "$undefined" below.
|
||||||
|
|
||||||
|
** push parsers
|
||||||
|
Consider deprecating impure push parsers. They add a lot of complexity, for
|
||||||
|
a bad feature.
|
||||||
|
|
||||||
* Bison 3.7
|
* Bison 3.7
|
||||||
** Unit rules / Injection rules (Akim Demaille)
|
** Unit rules / Injection rules (Akim Demaille)
|
||||||
Maybe we could expand unit rules (or "injections", see
|
Maybe we could expand unit rules (or "injections", see
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ m4_define([b4_user_args],
|
|||||||
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
|
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_user_formals
|
||||||
|
# ---------------
|
||||||
|
# The possible parse-params formal arguments preceded by a comma.
|
||||||
|
m4_define([b4_user_formals],
|
||||||
|
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
|
||||||
|
|
||||||
|
|
||||||
# b4_parse_param
|
# b4_parse_param
|
||||||
# --------------
|
# --------------
|
||||||
# If defined, b4_parse_param arrives double quoted, but below we prefer
|
# If defined, b4_parse_param arrives double quoted, but below we prefer
|
||||||
@@ -600,13 +607,10 @@ m4_define_default([b4_yydestruct_define],
|
|||||||
| Release the memory associated to this symbol. |
|
| Release the memory associated to this symbol. |
|
||||||
`-----------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yydestruct],
|
static void
|
||||||
[static void],
|
yydestruct (const char *yymsg,
|
||||||
[[const char *yymsg], [yymsg]],
|
int yytype, YYSTYPE *yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE *yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
|
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
|
||||||
[ if (!yymsg)
|
[ if (!yymsg)
|
||||||
@@ -629,13 +633,10 @@ m4_define_default([b4_yy_symbol_print_define],
|
|||||||
| Print this symbol's value on YYO. |
|
| Print this symbol's value on YYO. |
|
||||||
`-----------------------------------*/
|
`-----------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_value_print],
|
static void
|
||||||
[static void],
|
yy_symbol_value_print (FILE *yyo,
|
||||||
[[FILE *yyo], [yyo]],
|
int yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
FILE *yyoutput = yyo;
|
FILE *yyoutput = yyo;
|
||||||
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
||||||
@@ -660,13 +661,10 @@ b4_percent_code_get([[post-printer]])dnl
|
|||||||
| Print this symbol on YYO. |
|
| Print this symbol on YYO. |
|
||||||
`---------------------------*/
|
`---------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_print],
|
static void
|
||||||
[static void],
|
yy_symbol_print (FILE *yyo,
|
||||||
[[FILE *yyo], [yyo]],
|
int yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
YYFPRINTF (yyo, "%s %s (",
|
YYFPRINTF (yyo, "%s %s (",
|
||||||
yytype < YYNTOKENS ? "token" : "nterm", yysymbol_name (yytype));
|
yytype < YYNTOKENS ? "token" : "nterm", yysymbol_name (yytype));
|
||||||
@@ -943,10 +941,8 @@ m4_define([b4_yy_location_print_define],
|
|||||||
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
|
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
|
||||||
|
|
||||||
YY_ATTRIBUTE_UNUSED
|
YY_ATTRIBUTE_UNUSED
|
||||||
]b4_function_define([yy_location_print_],
|
static int
|
||||||
[static int],
|
yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
|
||||||
[[FILE *yyo], [yyo]],
|
|
||||||
[[YYLTYPE const * const yylocp], [yylocp]])[
|
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
||||||
|
|||||||
@@ -46,16 +46,6 @@ m4_ifndef([b4_pure_flag],
|
|||||||
m4_define([b4_pure_flag],
|
m4_define([b4_pure_flag],
|
||||||
[b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
|
[b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
|
||||||
|
|
||||||
# b4_user_formals
|
|
||||||
# ---------------
|
|
||||||
# The possible parse-params formal arguments preceded by a comma.
|
|
||||||
#
|
|
||||||
# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
|
|
||||||
# formal argument declarations.
|
|
||||||
m4_define([b4_user_formals],
|
|
||||||
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
|
|
||||||
|
|
||||||
|
|
||||||
# b4_yyerror_args
|
# b4_yyerror_args
|
||||||
# ---------------
|
# ---------------
|
||||||
# Optional effective arguments passed to yyerror: user args plus yylloc, and
|
# Optional effective arguments passed to yyerror: user args plus yylloc, and
|
||||||
|
|||||||
@@ -77,16 +77,10 @@ m4_define([b4_yy_symbol_print_define],
|
|||||||
| Print this symbol. |
|
| Print this symbol. |
|
||||||
`--------------------*/
|
`--------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_print],
|
static void
|
||||||
[static void],
|
yy_symbol_print (FILE *, int yytype,
|
||||||
[[FILE *], []],
|
const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[,
|
||||||
[[int yytype], [yytype]],
|
const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[)
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep],
|
|
||||||
[yyvaluep]][]dnl
|
|
||||||
b4_locations_if([,
|
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
|
|
||||||
[yylocationp]]]),
|
|
||||||
b4_parse_param)[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use[]dnl
|
]b4_parse_param_use[]dnl
|
||||||
[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
|
[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
|
||||||
@@ -134,12 +128,10 @@ m4_append([b4_epilogue],
|
|||||||
| Report an error. |
|
| Report an error. |
|
||||||
`------------------*/
|
`------------------*/
|
||||||
|
|
||||||
]b4_function_define([yyerror],
|
static void
|
||||||
[static void],b4_locations_if([
|
yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
|
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
|
||||||
[yylocationp]],])
|
])[const char* msg)
|
||||||
b4_parse_param,
|
|
||||||
[[const char* msg], [msg]])[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use[]dnl
|
]b4_parse_param_use[]dnl
|
||||||
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
|
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
|
||||||
|
|||||||
@@ -735,9 +735,8 @@ do { \
|
|||||||
| TOP (included). |
|
| TOP (included). |
|
||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_stack_print], [static void],
|
static void
|
||||||
[[yy_state_t *yybottom], [yybottom]],
|
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
|
||||||
[[yy_state_t *yytop], [yytop]])[
|
|
||||||
{
|
{
|
||||||
YYFPRINTF (stderr, "Stack now");
|
YYFPRINTF (stderr, "Stack now");
|
||||||
for (; yybottom <= yytop; yybottom++)
|
for (; yybottom <= yytop; yybottom++)
|
||||||
@@ -759,12 +758,9 @@ do { \
|
|||||||
| Report that the YYRULE is going to be reduced. |
|
| Report that the YYRULE is going to be reduced. |
|
||||||
`------------------------------------------------*/
|
`------------------------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_reduce_print], [static void],
|
static void
|
||||||
[[yy_state_t *yyssp], [yyssp]],
|
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *yylsp,]])[
|
||||||
[[YYSTYPE *yyvsp], [yyvsp]],
|
int yyrule]b4_user_formals[)
|
||||||
b4_locations_if([[[YYLTYPE *yylsp], [yylsp]],
|
|
||||||
])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [,
|
|
||||||
b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
int yylno = yyrline[yyrule];
|
int yylno = yyrline[yyrule];
|
||||||
int yynrhs = yyr2[yyrule];
|
int yynrhs = yyr2[yyrule];
|
||||||
@@ -1207,8 +1203,8 @@ yyparse_context_location (const yyparse_context_t *yyctx)
|
|||||||
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
|
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
|
||||||
# else
|
# else
|
||||||
/* Return the length of YYSTR. */
|
/* Return the length of YYSTR. */
|
||||||
]b4_function_define([yystrlen], [static YYPTRDIFF_T],
|
static YYPTRDIFF_T
|
||||||
[[const char *yystr], [yystr]])[
|
yystrlen (const char *yystr)
|
||||||
{
|
{
|
||||||
YYPTRDIFF_T yylen;
|
YYPTRDIFF_T yylen;
|
||||||
for (yylen = 0; yystr[yylen]; yylen++)
|
for (yylen = 0; yystr[yylen]; yylen++)
|
||||||
@@ -1224,8 +1220,8 @@ yyparse_context_location (const yyparse_context_t *yyctx)
|
|||||||
# else
|
# else
|
||||||
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
|
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
|
||||||
YYDEST. */
|
YYDEST. */
|
||||||
]b4_function_define([yystpcpy], [static char *],
|
static char *
|
||||||
[[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[
|
yystpcpy (char *yydest, const char *yysrc)
|
||||||
{
|
{
|
||||||
char *yyd = yydest;
|
char *yyd = yydest;
|
||||||
const char *yys = yysrc;
|
const char *yys = yysrc;
|
||||||
@@ -1388,10 +1384,9 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
|
|||||||
|
|
||||||
]b4_yydestruct_define[
|
]b4_yydestruct_define[
|
||||||
|
|
||||||
]b4_pure_if([], [[
|
]b4_pure_if([], [b4_declare_scanner_communication_variables])[
|
||||||
|
|
||||||
]b4_declare_scanner_communication_variables])[]b4_push_if([[
|
|
||||||
|
|
||||||
|
]b4_push_if([[
|
||||||
struct yypstate
|
struct yypstate
|
||||||
{]b4_declare_parser_state_variables[
|
{]b4_declare_parser_state_variables[
|
||||||
/* Used to determine if this is the first time this instance has
|
/* Used to determine if this is the first time this instance has
|
||||||
@@ -1399,17 +1394,16 @@ struct yypstate
|
|||||||
int yynew;
|
int yynew;
|
||||||
};]b4_pure_if([], [[
|
};]b4_pure_if([], [[
|
||||||
|
|
||||||
static char yypstate_allocated = 0;]])b4_pull_if([
|
static char yypstate_allocated = 0;]])b4_pull_if([[
|
||||||
|
|
||||||
b4_function_define([[yyparse]], [[int]], b4_parse_param)[
|
int
|
||||||
|
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)
|
||||||
{
|
{
|
||||||
return yypull_parse (YY_NULLPTR]m4_ifset([b4_parse_param],
|
return yypull_parse (YY_NULLPTR]b4_user_args[);
|
||||||
[[, ]b4_args(b4_parse_param)])[);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_function_define([[yypull_parse]], [[int]],
|
int
|
||||||
[[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
|
yypull_parse (yypstate *yyps]b4_user_formals[)
|
||||||
b4_parse_param]))[
|
|
||||||
{]b4_pure_if([b4_locations_if([[
|
{]b4_pure_if([b4_locations_if([[
|
||||||
static YYLTYPE yyloc_default][]b4_yyloc_default[;
|
static YYLTYPE yyloc_default][]b4_yyloc_default[;
|
||||||
YYLTYPE yylloc = yyloc_default;]])])[
|
YYLTYPE yylloc = yyloc_default;]])])[
|
||||||
@@ -1440,7 +1434,8 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
|
|||||||
}]])[
|
}]])[
|
||||||
|
|
||||||
/* Initialize the parser data structure. */
|
/* Initialize the parser data structure. */
|
||||||
]b4_function_define([[yypstate_new]], [[yypstate *]])[
|
yypstate *
|
||||||
|
yypstate_new (void)
|
||||||
{
|
{
|
||||||
yypstate *yyps;]b4_pure_if([], [[
|
yypstate *yyps;]b4_pure_if([], [[
|
||||||
if (yypstate_allocated)
|
if (yypstate_allocated)
|
||||||
@@ -1453,8 +1448,8 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
|
|||||||
return yyps;
|
return yyps;
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_function_define([[yypstate_delete]], [[void]],
|
void
|
||||||
[[[yypstate *yyps]], [[yyps]]])[
|
yypstate_delete (yypstate *yyps)
|
||||||
{
|
{
|
||||||
if (yyps)
|
if (yyps)
|
||||||
{
|
{
|
||||||
@@ -1488,25 +1483,23 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
|
|||||||
#define yyesa yyps->yyesa
|
#define yyesa yyps->yyesa
|
||||||
#define yyes yyps->yyes
|
#define yyes yyps->yyes
|
||||||
#define yyes_capacity yyps->yyes_capacity]])[
|
#define yyes_capacity yyps->yyes_capacity]])[
|
||||||
|
]])[
|
||||||
|
|
||||||
|
]b4_push_if([[
|
||||||
/*---------------.
|
/*---------------.
|
||||||
| yypush_parse. |
|
| yypush_parse. |
|
||||||
`---------------*/
|
`---------------*/
|
||||||
|
|
||||||
]b4_function_define([[yypush_parse]], [[int]],
|
int
|
||||||
[[[yypstate *yyps]], [[yyps]]]b4_pure_if([,
|
yypush_parse (yypstate *yyps]b4_pure_if([[,
|
||||||
[[[int yypushed_char]], [[yypushed_char]]],
|
int yypushed_char, YYSTYPE const *yypushed_val]b4_locations_if([[, YYLTYPE *yypushed_loc]])])b4_user_formals[)]],
|
||||||
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
|
[[
|
||||||
[[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
|
|
||||||
b4_parse_param]))], [[
|
|
||||||
|
|
||||||
|
|
||||||
/*----------.
|
/*----------.
|
||||||
| yyparse. |
|
| yyparse. |
|
||||||
`----------*/
|
`----------*/
|
||||||
|
|
||||||
]b4_function_define([yyparse], [int], b4_parse_param)])[
|
int
|
||||||
|
yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
|
||||||
{]b4_pure_if([b4_declare_scanner_communication_variables
|
{]b4_pure_if([b4_declare_scanner_communication_variables
|
||||||
])b4_push_if([b4_pure_if([], [[
|
])b4_push_if([b4_pure_if([], [[
|
||||||
int yypushed_char = yychar;
|
int yypushed_char = yychar;
|
||||||
|
|||||||
Reference in New Issue
Block a user