* data/bison.simple (m4_location_if): New.

Use it instead of #ifdef YYLSP_NEEDED.
This commit is contained in:
Akim Demaille
2002-06-19 09:07:36 +00:00
parent 02097d3eab
commit 58612f1de0
2 changed files with 65 additions and 94 deletions

View File

@@ -1,3 +1,8 @@
2002-06-19 Akim Demaille <akim@epita.fr>
* data/bison.simple (m4_location_if): New.
Use it instead of #ifdef YYLSP_NEEDED.
2002-06-19 Akim Demaille <akim@epita.fr> 2002-06-19 Akim Demaille <akim@epita.fr>
Prepare @$ in %destructor, but currently don't bind it in the Prepare @$ in %destructor, but currently don't bind it in the

View File

@@ -33,6 +33,20 @@ m4_define([b4_rhs_value],
[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])]) [yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])])
## ----------- ##
## Locations. ##
## ----------- ##
# b4_location_if(IF-TRUE, IF-FALSE)
# ---------------------------------
# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
m4_define([b4_location_if],
[m4_if(b4_locations_flag, [1],
[$1],
[$2])])
# b4_lhs_location() # b4_lhs_location()
# ----------------- # -----------------
# Expansion of @$. # Expansion of @$.
@@ -48,6 +62,11 @@ m4_define([b4_rhs_location],
[yylsp@<:@m4_eval([$2 - $1])@:>@]) [yylsp@<:@m4_eval([$2 - $1])@:>@])
## ------------------- ##
## Output file names. ##
## ------------------- ##
m4_define_default([b4_input_suffix], [.y]) m4_define_default([b4_input_suffix], [.y])
m4_define_default([b4_output_parser_suffix], m4_define_default([b4_output_parser_suffix],
@@ -171,10 +190,7 @@ m4_if(b4_prefix[], [yy], [],
#define yychar b4_prefix[]char #define yychar b4_prefix[]char
#define yydebug b4_prefix[]debug #define yydebug b4_prefix[]debug
#define yynerrs b4_prefix[]nerrs #define yynerrs b4_prefix[]nerrs
#if YYLSP_NEEDED b4_location_if([#define yylloc b4_prefix[]lloc])])
# define yylloc b4_prefix[]lloc
#endif
])
/* Copy the first part of user declarations. */ /* Copy the first part of user declarations. */
b4_pre_prologue b4_pre_prologue
@@ -264,9 +280,8 @@ union yyalloc
{ {
short yyss; short yyss;
YYSTYPE yyvs; YYSTYPE yyvs;
# if YYLSP_NEEDED b4_location_if([ YYLTYPE yyls;
YYLTYPE yyls; ])dnl
# endif
}; };
/* The size of the maximum gap between one aligned stack and the next. */ /* The size of the maximum gap between one aligned stack and the next. */
@@ -274,15 +289,13 @@ union yyalloc
/* The size of an array large to enough to hold all stacks, each with /* The size of an array large to enough to hold all stacks, each with
N elements. */ N elements. */
# if YYLSP_NEEDED b4_location_if(
# define YYSTACK_BYTES(N) \ [# define YYSTACK_BYTES(N) \
((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+ 2 * YYSTACK_GAP_MAX) + 2 * YYSTACK_GAP_MAX)],
# else [# define YYSTACK_BYTES(N) \
# define YYSTACK_BYTES(N) \
((N) * (sizeof (short) + sizeof (YYSTYPE)) \ ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
+ YYSTACK_GAP_MAX) + YYSTACK_GAP_MAX)])
# endif
/* Copy COUNT objects from FROM to TO. The source and destination do /* Copy COUNT objects from FROM to TO. The source and destination do
not overlap. */ not overlap. */
@@ -510,21 +523,13 @@ while (0)
/* YYLEX -- calling `yylex' with the right arguments. */ /* YYLEX -- calling `yylex' with the right arguments. */
#if YYPURE #if YYPURE
# if YYLSP_NEEDED # ifdef YYLEX_PARAM
# ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, b4_location_if([&yylloc, ])YYLEX_PARAM)
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) # else
# else # define YYLEX yylex (&yylval, b4_location_if([&yylloc, ]))
# define YYLEX yylex (&yylval, &yylloc) # endif
# endif
# else /* !YYLSP_NEEDED */
# ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, YYLEX_PARAM)
# else
# define YYLEX yylex (&yylval)
# endif
# endif /* !YYLSP_NEEDED */
#else /* !YYPURE */ #else /* !YYPURE */
# define YYLEX yylex () # define YYLEX yylex ()
#endif /* !YYPURE */ #endif /* !YYPURE */
/* Enable debugging if requested. */ /* Enable debugging if requested. */
@@ -656,7 +661,7 @@ static void yydestructor (int symbol_type, YYSTYPE symbol_value);
/* YY_DECL_VARIABLES -- depending whether we use a pure parser, /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
variables are global, or local to YYPARSE. */ variables are global, or local to YYPARSE. */
#define YY_DECL_NON_LSP_VARIABLES \ #define YY_DECL_VARIABLES \
/* The lookahead symbol. */ \ /* The lookahead symbol. */ \
int yychar; \ int yychar; \
\ \
@@ -664,18 +669,10 @@ int yychar; \
YYSTYPE yylval; \ YYSTYPE yylval; \
\ \
/* Number of parse errors so far. */ \ /* Number of parse errors so far. */ \
int yynerrs; int yynerrs;b4_location_if([ \
/* Location data for the lookahead symbol. */ \
YYLTYPE yylloc;])
#if YYLSP_NEEDED
# define YY_DECL_VARIABLES \
YY_DECL_NON_LSP_VARIABLES \
\
/* Location data for the lookahead symbol. */ \
YYLTYPE yylloc;
#else
# define YY_DECL_VARIABLES \
YY_DECL_NON_LSP_VARIABLES
#endif
/* If nonreentrant, generate the variables here. */ /* If nonreentrant, generate the variables here. */
@@ -718,27 +715,20 @@ yyparse (YYPARSE_PARAM_ARG)
YYSTYPE *yyvs = yyvsa; YYSTYPE *yyvs = yyvsa;
register YYSTYPE *yyvsp; register YYSTYPE *yyvsp;
#if YYLSP_NEEDED ]b4_location_if(
/* The location stack. */ [[ /* The location stack. */
YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE yylsa[YYINITDEPTH];
YYLTYPE *yyls = yylsa; YYLTYPE *yyls = yylsa;
YYLTYPE *yylsp; YYLTYPE *yylsp;]])[
#endif
#if YYLSP_NEEDED #define YYPOPSTACK (yyvsp--, yyssp--]b4_location_if([, yylsp--])[)
# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
#else
# define YYPOPSTACK (yyvsp--, yyssp--)
#endif
YYSIZE_T yystacksize = YYINITDEPTH; YYSIZE_T yystacksize = YYINITDEPTH;
/* The variables used to return semantic value and location from the /* The variables used to return semantic value and location from the
action routines. */ action routines. */
YYSTYPE yyval; YYSTYPE yyval;
#if YYLSP_NEEDED ]b4_location_if([ YYLTYPE yyloc;])[
YYLTYPE yyloc;
#endif
/* When reducing, the number of symbols on the RHS of the reduced /* When reducing, the number of symbols on the RHS of the reduced
rule. */ rule. */
@@ -758,9 +748,7 @@ yyparse (YYPARSE_PARAM_ARG)
yyssp = yyss; yyssp = yyss;
yyvsp = yyvs; yyvsp = yyvs;
#if YYLSP_NEEDED ]b4_location_if([ yylsp = yyls;])[
yylsp = yyls;
#endif
goto yysetstate; goto yysetstate;
/*------------------------------------------------------------. /*------------------------------------------------------------.
@@ -787,25 +775,18 @@ yyparse (YYPARSE_PARAM_ARG)
memory. */ memory. */
YYSTYPE *yyvs1 = yyvs; YYSTYPE *yyvs1 = yyvs;
short *yyss1 = yyss; short *yyss1 = yyss;
]b4_location_if([ YYLTYPE *yyls1 = yyls;])[
/* Each stack pointer address is followed by the size of the /* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. */ data in use in that stack, in bytes. This used to be a
# if YYLSP_NEEDED conditional around just the two extra args, but that might
YYLTYPE *yyls1 = yyls; be undefined if yyoverflow is a macro. */
/* This used to be a conditional around just the two extra args,
but that might be undefined if yyoverflow is a macro. */
yyoverflow ("parser stack overflow", yyoverflow ("parser stack overflow",
&yyss1, yysize * sizeof (*yyssp), &yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp), &yyvs1, yysize * sizeof (*yyvsp),
&yyls1, yysize * sizeof (*yylsp), ]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[
&yystacksize); &yystacksize);
yyls = yyls1; ]b4_location_if([ yyls = yyls1;])[
# else
yyoverflow ("parser stack overflow",
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
&yystacksize);
# endif
yyss = yyss1; yyss = yyss1;
yyvs = yyvs1; yyvs = yyvs1;
} }
@@ -828,9 +809,7 @@ yyparse (YYPARSE_PARAM_ARG)
goto yyoverflowlab; goto yyoverflowlab;
YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyss);
YYSTACK_RELOCATE (yyvs); YYSTACK_RELOCATE (yyvs);
# if YYLSP_NEEDED ]b4_location_if([ YYSTACK_RELOCATE (yyls);])[
YYSTACK_RELOCATE (yyls);
# endif
# undef YYSTACK_RELOCATE # undef YYSTACK_RELOCATE
if (yyss1 != yyssa) if (yyss1 != yyssa)
YYSTACK_FREE (yyss1); YYSTACK_FREE (yyss1);
@@ -840,9 +819,7 @@ yyparse (YYPARSE_PARAM_ARG)
yyssp = yyss + yysize - 1; yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1; yyvsp = yyvs + yysize - 1;
#if YYLSP_NEEDED ]b4_location_if([ yylsp = yyls + yysize - 1;])[
yylsp = yyls + yysize - 1;
#endif
YYDPRINTF ((stderr, "Stack size increased to %lu\n", YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize)); (unsigned long int) yystacksize));
@@ -946,9 +923,7 @@ yybackup:
yychar = YYEMPTY; yychar = YYEMPTY;
*++yyvsp = yylval; *++yyvsp = yylval;
#if YYLSP_NEEDED ]b4_location_if([ *++yylsp = yylloc;])[
*++yylsp = yylloc;
#endif
/* Count tokens shifted since error; after three, turn off error /* Count tokens shifted since error; after three, turn off error
status. */ status. */
@@ -986,10 +961,9 @@ yyreduce:
GCC warning that YYVAL may be used uninitialized. */ GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen]; yyval = yyvsp[1-yylen];
#if YYLSP_NEEDED ]b4_location_if(
/* Default location. */ [ /* Default location. */
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[
#endif
#if YYDEBUG #if YYDEBUG
/* We have to keep this `#if YYDEBUG', since we use variables which /* We have to keep this `#if YYDEBUG', since we use variables which
@@ -1017,9 +991,7 @@ yyreduce:
[ yyvsp -= yylen; [ yyvsp -= yylen;
yyssp -= yylen; yyssp -= yylen;
#if YYLSP_NEEDED ]b4_location_if([ yylsp -= yylen;])[
yylsp -= yylen;
#endif
#if YYDEBUG #if YYDEBUG
if (yydebug) if (yydebug)
@@ -1033,9 +1005,7 @@ yyreduce:
#endif #endif
*++yyvsp = yyval; *++yyvsp = yyval;
#if YYLSP_NEEDED ]b4_location_if([ *++yylsp = yyloc;])[
*++yylsp = yyloc;
#endif
/* Now `shift' the result of the reduction. Determine what state /* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule that goes to, based on the state we popped back to and the rule
@@ -1207,9 +1177,7 @@ yyerrlab1:
yydestructor (yystos[yystate], *yyvsp); yydestructor (yystos[yystate], *yyvsp);
yyvsp--; yyvsp--;
yystate = *--yyssp; yystate = *--yyssp;
#if YYLSP_NEEDED ]b4_location_if([ yylsp--;])[
yylsp--;
#endif
#if YYDEBUG #if YYDEBUG
if (yydebug) if (yydebug)
@@ -1229,9 +1197,7 @@ yyerrlab1:
YYDPRINTF ((stderr, "Shifting error token, ")); YYDPRINTF ((stderr, "Shifting error token, "));
*++yyvsp = yylval; *++yyvsp = yylval;
#if YYLSP_NEEDED ]b4_location_if([ *++yylsp = yylloc;])[
*++yylsp = yylloc;
#endif
yystate = yyn; yystate = yyn;
goto yynewstate; goto yynewstate;
@@ -1321,7 +1287,7 @@ typedef union b4_stype yystype;
m4_if(b4_pure, [0], m4_if(b4_pure, [0],
[extern YYSTYPE b4_prefix[]lval;]) [extern YYSTYPE b4_prefix[]lval;])
m4_if(b4_locations_flag, [0], [], b4_location_if(
[#ifndef YYLTYPE [#ifndef YYLTYPE
typedef struct yyltype typedef struct yyltype
{ {