[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 3/4] regen
From: |
Akim Demaille |
Subject: |
[RFC PATCH 3/4] regen |
Date: |
Sun, 7 Jul 2019 20:20:35 +0200 |
---
src/parse-gram.c | 41 ++++++++++++++++++++++++++++++++++-------
src/parse-gram.h | 8 ++++++++
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/src/parse-gram.c b/src/parse-gram.c
index ca2ca699..cf1deee5 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -75,10 +75,15 @@
#define yylex gram_lex
#define yyerror gram_error
#define yydebug gram_debug
+#define yydebug_init gram_debug_init
+#define yydebug_none gram_debug_none
+#define yydebug_trace gram_debug_trace
+#define yydebug_stats gram_debug_stats
+#define yydebug_all gram_debug_all
+#define yydebug_type gram_debug_type
#define yynerrs gram_nerrs
-
# ifndef YY_NULLPTR
# if defined __cplusplus
# if 201103L <= __cplusplus
@@ -806,7 +811,7 @@ static const yytype_uint8 yyr2[] =
# define YYDPRINTF(Args) \
do { \
- if (yydebug) \
+ if (yydebug & yydebug_trace) \
YYFPRINTF Args; \
} while (0)
@@ -857,7 +862,7 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
- if (yydebug) \
+ if (yydebug & yydebug_trace) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
@@ -1106,7 +1111,7 @@ yy_stack_print (yytype_int16 *yybottom, yytype_int16
*yytop)
# define YY_STACK_PRINT(Bottom, Top) \
do { \
- if (yydebug) \
+ if (yydebug & yydebug_trace) \
yy_stack_print ((Bottom), (Top)); \
} while (0)
@@ -1137,7 +1142,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp,
YYLTYPE *yylsp, int yyrule
# define YY_REDUCE_PRINT(Rule) \
do { \
- if (yydebug) \
+ if (yydebug & yydebug_trace) \
yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
} while (0)
@@ -1288,7 +1293,7 @@ do {
\
do { \
if (yy_lac_established) \
{ \
- if (yydebug) \
+ if (yydebug & yydebug_trace) \
YYFPRINTF (stderr, "LAC: initial context discarded due to " \
Event "\n"); \
yy_lac_established = 0; \
@@ -1573,7 +1578,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
}
}
# if GRAM_DEBUG
- else if (yydebug)
+ else if (yydebug & yydebug_trace)
YYFPRINTF (stderr, "No expected tokens.\n");
# endif
}
@@ -1775,6 +1780,15 @@ YYLTYPE yylloc = yyloc_default;
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif
+#if GRAM_DEBUG
+ typedef struct {
+ int num_reductions;
+ int num_shifts;
+ } yy_stats_t;
+ static yy_stats_t yy_stats_init;
+ yy_stats_t yy_stats = yy_stats_init;
+#endif
+
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
/* The number of symbols on the RHS of the reduced rule.
@@ -1956,6 +1970,9 @@ yybackup:
/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+#if GRAM_DEBUG
+ yy_stats.num_shifts += 1;
+#endif
/* Discard the shifted token. */
yychar = YYEMPTY;
@@ -2000,6 +2017,9 @@ yyreduce:
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
yyerror_range[1] = yyloc;
YY_REDUCE_PRINT (yyn);
+#if GRAM_DEBUG
+ yy_stats.num_reductions += 1;
+#endif
{
int yychar_backup = yychar;
switch (yyn)
@@ -2761,6 +2781,13 @@ yyreturn:
#endif
if (yyes != yyesa)
YYSTACK_FREE (yyes);
+#if GRAM_DEBUG
+ if (yydebug & yydebug_stats)
+ {
+ YYFPRINTF (stderr, "num_reductions: %d\n", yy_stats.num_reductions);
+ YYFPRINTF (stderr, "num_shifts: %d\n", yy_stats.num_shifts);
+ }
+#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
diff --git a/src/parse-gram.h b/src/parse-gram.h
index 76f3ae91..f8897eb6 100644
--- a/src/parse-gram.h
+++ b/src/parse-gram.h
@@ -49,6 +49,14 @@
# endif /* ! defined YYDEBUG */
#endif /* ! defined GRAM_DEBUG */
#if GRAM_DEBUG
+/* Values of gram_debug. */
+enum gram_debug_type
+{
+ gram_debug_none = 0,
+ gram_debug_trace = 1 << 0,
+ gram_debug_stats = 1 << 1,
+ gram_debug_all = -1
+};
extern int gram_debug;
#endif
/* "%code requires" blocks. */
--
2.22.0
- [PATCH 2/4] parse.stats: add --trace=parse-stats, (continued)
- [PATCH 2/4] parse.stats: add --trace=parse-stats, Akim Demaille, 2019/07/03
- [PATCH 1/4] parse.stats: new feature of yacc.c, Akim Demaille, 2019/07/03
- [PATCH 4/4] parse.stats: documentation, Akim Demaille, 2019/07/03
- [PATCH 3/4] regen, Akim Demaille, 2019/07/03
- Re: [PATCH 0/4] RFC: add stats about parsing, Adrian Vogelsgesang, 2019/07/03
- Re: [PATCH 0/4] RFC: add stats about parsing, Akim Demaille, 2019/07/03
- Re: [PATCH 0/4] RFC: add stats about parsing, Adrian Vogelsgesang, 2019/07/04
- [RFC PATCH 0/4] RFC: add stats about parsing, Akim Demaille, 2019/07/07
- [RFC PATCH 1/4] parse stats: new feature of yacc.c, Akim Demaille, 2019/07/07
- [RFC PATCH 2/4] parse stats: add --trace=parse-stats, Akim Demaille, 2019/07/07
- [RFC PATCH 3/4] regen,
Akim Demaille <=
- [RFC PATCH 4/4] parse stats: documentation, Akim Demaille, 2019/07/07