Skip to content

Commit

Permalink
Add user argument to some macros used by bison
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed May 14, 2023
1 parent 3150516 commit bdaa491
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 124 deletions.
4 changes: 2 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -919,15 +919,15 @@ $(ENC_MK): $(srcdir)/enc/make_encmake.rb $(srcdir)/enc/Makefile.in $(srcdir)/enc

PHONY:

{$(VPATH)}parse.c: {$(VPATH)}parse.y $(tooldir)/ytab.sed {$(VPATH)}id.h
{$(VPATH)}parse.c: {$(VPATH)}parse.y {$(VPATH)}id.h
{$(VPATH)}parse.h: {$(VPATH)}parse.c

{$(srcdir)}.y.c:
$(ECHO) generating $@
$(Q)$(BASERUBY) $(tooldir)/id2token.rb $(SRC_FILE) > parse.tmp.y
$(Q)$(YACC) -d $(YFLAGS) -o y.tab.c parse.tmp.y
$(Q)$(RM) parse.tmp.y
$(Q)sed -f $(tooldir)/ytab.sed -e "/^#/s|parse\.tmp\.[iy]|$(SRC_FILE)|" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
$(Q)sed -e "/^#/s|parse\.tmp\.[iy]|$(SRC_FILE)|" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new
$(Q)$(MV) $@.new $@
$(Q)sed -e "/^#line.*y\.tab\.h/d;/^#line.*parse.*\.y/d" y.tab.h > $(@:.c=.h)
$(Q)$(RM) y.tab.c y.tab.h
Expand Down
5 changes: 1 addition & 4 deletions ext/ripper/depend
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ ripper.o: ripper.c

.y.c:
$(ECHO) compiling compiler $<
$(ECHO) $(BISON)
$(Q) $(BISON) -t -v -oy.tab.c $<
$(Q) sed -e "/^#/s!y\.tab\.c!$@!" -f $(top_srcdir)/tool/ytab.sed y.tab.c > $@
@$(RM) y.tab.c
$(Q) $(BISON) -t -v -o$@ -h$*.h $<

all: check
static: check
Expand Down
4 changes: 2 additions & 2 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ RBIMPL_WARNING_POP()
#define YYREALLOC(ptr, size) rb_parser_realloc(p, (ptr), (size))
#define YYCALLOC(nelem, size) rb_parser_calloc(p, (nelem), (size))
#define YYFREE(ptr) rb_parser_free(p, (ptr))
#define YYFPRINTF rb_parser_printf
#define YY_LOCATION_PRINT(File, loc) \
#define YYFPRINTF(out, ...) rb_parser_printf(p, __VA_ARGS__)
#define YY_LOCATION_PRINT(File, loc, p) \
rb_parser_printf(p, "%d.%d-%d.%d", \
(loc).beg_pos.lineno, (loc).beg_pos.column,\
(loc).end_pos.lineno, (loc).end_pos.column)
Expand Down
68 changes: 35 additions & 33 deletions tool/lrama/template/bison/yacc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%# b4_generated_by -%>
/* A Bison parser, made by GNU Bison 3.8.2. */
/* A Bison parser, made by Lrama <%= Lrama::VERSION %>. */

<%# b4_copyright -%>
/* Bison implementation for Yacc-like parsers in C
Expand Down Expand Up @@ -114,7 +114,7 @@
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
#if YYDEBUG && !defined(yydebug)
extern int yydebug;
#endif
<%-# b4_percent_code_get([[requires]]). %code is not supported -%>
Expand Down Expand Up @@ -731,7 +731,7 @@ do { \

/* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc))
# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) YY_LOCATION_PRINT(File, *(Loc)<%= output.user_args %>)

# elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL

Expand Down Expand Up @@ -767,11 +767,11 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)

/* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc))
# define YY_LOCATION_PRINT(File, Loc<%= output.user_args %>) YYLOCATION_PRINT(File, &(Loc)<%= output.user_args %>)

# else

# define YYLOCATION_PRINT(File, Loc) ((void) 0)
# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) ((void) 0)
/* Temporary convenience wrapper in case some people defined the
undocumented and private YY_LOCATION_PRINT macros. */
# define YY_LOCATION_PRINT YYLOCATION_PRINT
Expand All @@ -780,13 +780,13 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
# endif /* !defined YYLOCATION_PRINT */


# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Kind, Value, Location, p); \
Kind, Value, Location<%= output.user_args %>); \
YYFPRINTF (stderr, "\n"); \
} \
} while (0)
Expand Down Expand Up @@ -828,9 +828,9 @@ yy_symbol_print (FILE *yyo,
YYFPRINTF (yyo, "%s %s (",
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));

YYLOCATION_PRINT (yyo, yylocationp);
YYLOCATION_PRINT (yyo, yylocationp<%= output.user_args %>);
YYFPRINTF (yyo, ": ");
yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, p);
yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp<%= output.user_args %>);
YYFPRINTF (yyo, ")");
}

Expand All @@ -840,7 +840,7 @@ yy_symbol_print (FILE *yyo,
`------------------------------------------------------------------*/

static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop<%= output.user_formals %>)
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
Expand All @@ -851,10 +851,10 @@ yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top) \
# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
yy_stack_print ((Bottom), (Top)<%= output.user_args %>); \
} while (0)


Expand All @@ -878,25 +878,27 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
yy_symbol_print (stderr,
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&yyvsp[(yyi + 1) - (yynrhs)],
&(yylsp[(yyi + 1) - (yynrhs)]), p);
&(yylsp[(yyi + 1) - (yynrhs)])<%= output.user_args %>);
YYFPRINTF (stderr, "\n");
}
}

# define YY_REDUCE_PRINT(Rule) \
# define YY_REDUCE_PRINT(Rule<%= output.user_args %>) \
do { \
if (yydebug) \
yy_reduce_print (yyssp, yyvsp, yylsp, Rule, p); \
yy_reduce_print (yyssp, yyvsp, yylsp, Rule<%= output.user_args %>); \
} while (0)

/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
#ifndef yydebug
int yydebug;
#endif
#else /* !YYDEBUG */
# define YYDPRINTF(Args) ((void) 0)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>)
# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>)
# define YY_REDUCE_PRINT(Rule<%= output.user_args %>)
#endif /* !YYDEBUG */


Expand Down Expand Up @@ -1110,7 +1112,7 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx,
required number of bytes is too large to store. */
static int
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
const yypcontext_t *yyctx)
const yypcontext_t *yyctx<%= output.user_formals %>)
{
enum { YYARGS_MAX = 5 };
/* Internationalized format string. */
Expand Down Expand Up @@ -1200,7 +1202,7 @@ yydestruct (const char *yymsg,
<%= output.parse_param_use("yyvaluep", "yylocationp") %>
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp<%= output.user_args %>);

YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YY_USE (yykind);
Expand All @@ -1227,11 +1229,11 @@ int yychar;
/* The semantic value of the lookahead symbol. */
/* Default value used for initialization, for pacifying older GCCs
or non-GCC compilers. */
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
YY_INITIAL_VALUE (static const YYSTYPE yyval_default;)
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);

/* Location data for the lookahead symbol. */
static YYLTYPE yyloc_default
static const YYLTYPE yyloc_default
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
= { 1, 1, 1, 1 }
# endif
Expand Down Expand Up @@ -1322,7 +1324,7 @@ YYLTYPE yylloc = yyloc_default;
YY_IGNORE_USELESS_CAST_BEGIN
*yyssp = YY_CAST (yy_state_t, yystate);
YY_IGNORE_USELESS_CAST_END
YY_STACK_PRINT (yyss, yyssp);
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);

if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
Expand Down Expand Up @@ -1440,7 +1442,7 @@ YYLTYPE yylloc = yyloc_default;
else
{
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
}

/* If the proper action on seeing token YYTOKEN is to reduce or to
Expand All @@ -1463,7 +1465,7 @@ YYLTYPE yylloc = yyloc_default;
yyerrstatus--;

/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc<%= output.user_args %>);
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
Expand Down Expand Up @@ -1505,7 +1507,7 @@ YYLTYPE yylloc = yyloc_default;
/* Default location. */
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
yyerror_range[1] = yyloc;
YY_REDUCE_PRINT (yyn);
YY_REDUCE_PRINT (yyn<%= output.user_args %>);
switch (yyn)
{
<%= output.user_actions -%>
Expand All @@ -1523,7 +1525,7 @@ YYLTYPE yylloc = yyloc_default;
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc<%= output.user_args %>);

YYPOPSTACK (yylen);
yylen = 0;
Expand Down Expand Up @@ -1561,7 +1563,7 @@ YYLTYPE yylloc = yyloc_default;
= {yyssp, yytoken, &yylloc};
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>);
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == -1)
Expand All @@ -1573,7 +1575,7 @@ YYLTYPE yylloc = yyloc_default;
if (yymsg)
{
yysyntax_error_status
= yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
= yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>);
yymsgp = yymsg;
}
else
Expand Down Expand Up @@ -1628,7 +1630,7 @@ YYLTYPE yylloc = yyloc_default;
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
yystate = *yyssp;
goto yyerrlab1;

Expand Down Expand Up @@ -1663,7 +1665,7 @@ YYLTYPE yylloc = yyloc_default;
YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp<%= output.user_args %>);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
}

YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Expand All @@ -1675,7 +1677,7 @@ YYLTYPE yylloc = yyloc_default;
YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);

/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>);

yystate = yyn;
goto yynewstate;
Expand Down Expand Up @@ -1721,7 +1723,7 @@ YYLTYPE yylloc = yyloc_default;
/* Do not reclaim the symbols of the rule whose action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
Expand Down
2 changes: 1 addition & 1 deletion tool/lrama/template/bison/yacc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%# b4_generated_by -%>
/* A Bison parser, made by GNU Bison 3.8.2. */
/* A Bison parser, made by Lrama <%= Lrama::VERSION %>. */

<%# b4_copyright -%>
/* Bison interface for Yacc-like parsers in C
Expand Down
82 changes: 0 additions & 82 deletions tool/ytab.sed

This file was deleted.

0 comments on commit bdaa491

Please sign in to comment.