]> git.saurik.com Git - bison.git/commitdiff
Generalize the display of semantic values and locations in traces.
authorAkim Demaille <akim@epita.fr>
Wed, 16 Nov 2005 14:20:48 +0000 (14:20 +0000)
committerAkim Demaille <akim@epita.fr>
Wed, 16 Nov 2005 14:20:48 +0000 (14:20 +0000)
* data/glr.c (yy_reduce_print): Fix indices (again).
* data/c++.m4 (b4_rhs_value, b4_rhs_location): Don't expect
literal integers.
* data/lalr1.cc (yyreduce_print): Rename as...
(yy_reduce_print): this.
Display values and locations.
* data/yacc.c (yy_reduce_print): Likewise.
(YY_REDUCE_PRINT): Adjust to pass the required arguments.
(yysymprint): Move higher to be visible from yy_reduce_print).
(yyparse): Adjust.
* tests/calc.at: Adjust the expected length of the traces.

ChangeLog
data/c++.m4
data/glr.c
data/lalr1.cc
data/yacc.c
tests/calc.at

index 9827aaac7676b24f690e0462006c58de7e89826d..b0fd56f8a189d859875bf64118c7fbb99cb990ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2005-11-16  Akim Demaille  <akim@epita.fr>
+
+       Generalize the display of semantic values and locations in traces.
+       * data/glr.c (yy_reduce_print): Fix indices (again).
+       * data/c++.m4 (b4_rhs_value, b4_rhs_location): Don't expect
+       literal integers.
+       * data/lalr1.cc (yyreduce_print): Rename as...
+       (yy_reduce_print): this.
+       Display values and locations.
+       * data/yacc.c (yy_reduce_print): Likewise.
+       (YY_REDUCE_PRINT): Adjust to pass the required arguments.
+       (yysymprint): Move higher to be visible from yy_reduce_print).
+       (yyparse): Adjust.
+       * tests/calc.at: Adjust the expected length of the traces.
+
 2005-11-14  Akim Demaille  <akim@epita.fr>
 
        * data/glr.c (yy_reduce_print): The loop was quite wrong: type are
index f3926f7baa9262c94bec7795d000a02f7e7965ea..cf5e83d6b319bfac5c1e3b975e4c6493975627fc 100644 (file)
@@ -61,7 +61,7 @@ m4_define([b4_lhs_value],
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))])
+[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
 
 # b4_lhs_location()
 # -----------------
@@ -75,7 +75,7 @@ m4_define([b4_lhs_location],
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(yylocation_stack_@{m4_eval([$1 - $2])@})])
+[(yylocation_stack_@{($1) - ($2)@})])
 
 
 # b4_parse_param_decl
index d770b4399f8925818805b0ab8e0de02f15d69568..4a286ad30f280b070ba887e553535ec8140f4058 100644 (file)
@@ -1387,8 +1387,8 @@ yy_reduce_print (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
     {
       fprintf (stderr, "   $%d = ", yyi + 1);
       yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
-                  &]b4_rhs_value(yynrhs, yyi - 1)[
-                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi - 1))[]dnl
+                  &]b4_rhs_value(yynrhs, yyi + 1)[
+                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
                  b4_user_args[);
       fprintf (stderr, "\n");
     }
index 1073e8d2f2d3ab38f886ed91a5f2cec18995394b..bcc6080f4acb54864bcd70ca76745dace4b2dd9c 100644 (file)
@@ -232,7 +232,7 @@ b4_error_verbose_if([, int tok])[);
     /// For each scanner token number, its symbol number.
     static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
     /// Report on the debug stream that the rule \a r is going to be reduced.
-    virtual void yyreduce_print_ (int r);
+    virtual void yy_reduce_print_ (int r);
     /// Print the state stack on the debug stream.
     virtual void yystack_print_ ();
 #endif
@@ -328,7 +328,7 @@ b4_syncline([@oline@], [@ofile@])[
 do {                                                   \
   if (yydebug_)                                                \
     {                                                  \
-      *yycdebug_ << (Title) << ' ';                    \
+      *yycdebug_ << Title << ' ';                      \
       yysymprint_ ((Type), (Value), (Location));       \
       *yycdebug_ << std::endl;                         \
     }                                                  \
@@ -337,7 +337,7 @@ do {                                                        \
 # define YY_REDUCE_PRINT(Rule)         \
 do {                                   \
   if (yydebug_)                                \
-    yyreduce_print_ (Rule);            \
+    yy_reduce_print_ (Rule);           \
 } while (false)
 
 # define YY_STACK_PRINT()              \
@@ -655,9 +655,9 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
         ]b4_actions[
         default: break;
       }
-
-  ]/* Line __line__ of lalr1.cc.  */
-  b4_syncline([@oline@], [@ofile@])[
+    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
+    /* Line __line__ of lalr1.cc.  */
+]b4_syncline([@oline@], [@ofile@])[
 
     yypop_ (yylen);
 
@@ -981,16 +981,19 @@ b4_error_verbose_if([, int tok])[)
 
   // Report on the debug stream that the rule \a yyrule is going to be reduced.
   void
-  ]b4_parser_class_name[::yyreduce_print_ (int yyrule)
+  ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
   {
     unsigned int yylno = yyrline_[yyrule];
+    int yynrhs = yyr2_[yyrule];
     /* Print the symbols being reduced, and their result.  */
     *yycdebug_ << "Reducing stack by rule " << yyrule - 1
                << " (line " << yylno << "), ";
-    for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule];
-         0 <= yyrhs_[i]; ++i)
-      *yycdebug_ << yytname_[yyrhs_[i]] << ' ';
-    *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl;
+    /* The symbols being reduced.  */
+    for (int yyi = 0; yyi < yynrhs; yyi++)
+      YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
+                       yyrhs_[yyprhs_[yyrule] + yyi],
+                       &]b4_rhs_value(yynrhs, yyi + 1)[,
+                       &]b4_rhs_location(yynrhs, yyi + 1)[);
   }
 #endif // YYDEBUG
 
index 7af81941efc0536908f8befd237c26931eff785d..9bc021fa292c20c15328163faf94f8334754f89e 100644 (file)
@@ -102,7 +102,7 @@ m4_define([b4_lhs_value],
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[(yyvsp@{m4_eval([$2 - $1])@}m4_ifval([$3], [.$3]))])
+[(yyvsp@{($2) - ($1)@}m4_ifval([$3], [.$3]))])
 
 
 
@@ -122,7 +122,7 @@ m4_define([b4_lhs_location],
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(yylsp@{m4_eval([$2 - $1])@})])
+[(yylsp@{($2) - ($1)@})])
 
 
 
@@ -639,6 +639,8 @@ do {                                                                          \
     }                                                                    \
 } while (/*CONSTCOND*/ 0)
 
+]b4_yysymprint_generate([b4_c_function_def])[
+
 /*------------------------------------------------------------------.
 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
 | TOP (included).                                                   |
@@ -666,22 +668,32 @@ do {                                                              \
 `------------------------------------------------*/
 
 ]b4_c_function_def([yy_reduce_print], [static void],
-                   [[int yyrule], [yyrule]])[
+                   [[YYSTYPE *yyvsp], [yyvsvp]],
+   b4_location_if([[[YYLTYPE *yylsp], [yyvlvp]],])
+                   [[int yyrule],     [yyrule]]
+                   b4_parse_param)[
 {
+  int yynrhs = yyr2[yyrule];
   int yyi;
   unsigned long int yylno = yyrline[yyrule];
-  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu)",
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
              yyrule - 1, yylno);
-  /* Print the symbols being reduced, and their result.  */
-  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
-    YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
-  YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
+  /* The symbols being reduced.  */
+  for (yyi = 0; yyi < yynrhs; yyi++)
+    {
+      fprintf (stderr, "   $%d = ", yyi + 1);
+      yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi],
+                  &]b4_rhs_value(yynrhs, yyi + 1)[
+                  ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
+                 b4_user_args[);
+      fprintf (stderr, "\n");
+    }
 }
 
-# define YY_REDUCE_PRINT(Rule)         \
-do {                                   \
-  if (yydebug)                         \
-    yy_reduce_print (Rule);            \
+# define YY_REDUCE_PRINT(Args)                                 \
+do {                                                           \
+  if (yydebug)                                                 \
+    yy_reduce_print (yyvsp, ]b4_location_if([yylsp, ])[Args);  \
 } while (/*CONSTCOND*/ 0)
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
@@ -691,7 +703,7 @@ int yydebug;
 # define YYDPRINTF(Args)
 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
 # define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
+# define YY_REDUCE_PRINT(Args)
 #endif /* !YYDEBUG */
 
 
@@ -922,10 +934,7 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
 #endif /* YYERROR_VERBOSE */
 \f
 
-#if YYDEBUG
-]b4_yysymprint_generate([b4_c_function_def])[
-#endif /* ! YYDEBUG */
-]b4_yydestruct_generate([b4_c_function_def])
+]b4_yydestruct_generate([b4_c_function_def])[
 \f
 
 /* Prevent warnings from -Wmissing-prototypes.  */
@@ -937,11 +946,11 @@ int yyparse (void *YYPARSE_PARAM);
 int yyparse ();
 # endif
 #else /* ! YYPARSE_PARAM */
-b4_c_function_decl([yyparse], [int], b4_parse_param)
+]b4_c_function_decl([yyparse], [int], b4_parse_param)[
 #endif /* ! YYPARSE_PARAM */
 
 
-m4_divert_push([KILL])# ======================== M4 code.
+]m4_divert_push([KILL])# ======================== M4 code.
 # b4_declare_parser_variables
 # ---------------------------
 # Declare the variables that are global, or local to YYPARSE if
@@ -1252,17 +1261,18 @@ yyreduce:
 ]b4_location_if(
 [[  /* Default location. */
   YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
-  YY_REDUCE_PRINT (yyn);
+  YY_REDUCE_PRINT ((yyn]b4_user_args[));
   switch (yyn)
-    ]{
-      b4_actions
+    {
+      ]b4_actions[
       default: break;
     }
+  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
 
 /* Line __line__ of yacc.c.  */
-b4_syncline([@oline@], [@ofile@])
+]b4_syncline([@oline@], [@ofile@])[
 \f
-[  yyvsp -= yylen;
+  yyvsp -= yylen;
   yyssp -= yylen;
 ]b4_location_if([  yylsp -= yylen;])[
 
index ca7cc95d1962d40e32fefe4b40523a625a9a30fe..217b8828a2ad1dad5539b3c6d7220fba431710c8 100644 (file)
@@ -465,21 +465,21 @@ _AT_CHECK_CALC([$1],
 
 2^2^3 = 256
 (2^2)^3 = 64],
-               [571])
+               [842])
 
 # Some syntax errors.
-_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [13],
+_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15],
                      [1.2: syntax error, unexpected number])
-_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [18],
+_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
                      [1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
 _AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
                      [1.0: syntax error, unexpected $undefined])
-_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [26],
+_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
                      [1.6: syntax error, unexpected '='])
 _AT_CHECK_CALC_ERROR([$1], [1],
                      [
 +1],
-                     [16],
+                     [20],
                      [2.0: syntax error, unexpected '+'])
 # Exercise error messages with EOF: work on an empty file.
 _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
@@ -503,7 +503,7 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
 #
 _AT_CHECK_CALC_ERROR([$1], [0],
                      [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
-                     [189],
+                     [250],
 [1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
@@ -512,10 +512,10 @@ calc: error: 4444 != 1])
 
 # The same, but this time exercising explicitly triggered syntax errors.
 # POSIX says the look-ahead causing the error should not be discarded.
-_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [76],
+_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
 [1.9: syntax error, unexpected number
 calc: error: 2222 != 1])
-_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [86],
+_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113],
 [1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
 1.11: syntax error, unexpected number
 calc: error: 2222 != 1])