bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFA] Fix glr.c's YYDEBUG and YY_ERROR_VERBOSE vs. glr.cc


From: Paolo Bonzini
Subject: Re: [RFA] Fix glr.c's YYDEBUG and YY_ERROR_VERBOSE vs. glr.cc
Date: Tue, 12 Sep 2006 11:25:54 +0200
User-agent: Thunderbird 1.5.0.5 (Macintosh/20060719)

Paolo Bonzini wrote:
Currently, glr.cc testing is limited in calc.at because of a couple of bugs in glr.cc itself. These bugs are due to glr.cc's nature of thin wrapper around glr.c.

First, glr.cc sets YY_ERROR_VERBOSE to 0 and glr.c interprets it as a request to *have* verbose errors, thanks to these directives:

#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# ...
#endif

This can be considered a bug in glr.c actually, and the same bug is also there in yacc.c (if you want, the same glr.c hunk applies to yacc.c as well). This patch fixes it using some preprocessor magic.

Second, yy::parser::set_debug_level is never defined unless %debug is specified. This because it just sets "::yydebug" to its argument, and the variable is not defined in glr.c unless YYDEBUG is defined. This patch also fixes it by making the function do nothing unless %debug is specified.

Unluckily, the testsuite changes enabled by this patch are tangled in my %language work, and I'd rather wait for the copyright assignment. In the meanwhile, these are bug fixes that could be applied as uncopyrightable.

Tested with no regressions.

And as usual I forgot the patch. I must stop writing messages before preparing the patch...

Paolo
2006-09-12  Paolo Bonzini  <address@hidden>

        * glr.c (YYERROR_VERBOSE): Do not redefine if defined to 0.
        * glr.cc (debug_stream, set_debug_stream, debug_level, set_debug_level):
        Always provide them.
        (debug_level, set_debug_level) [!YYDEBUG]: Do nothing.

Index: glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.188
diff -u -p -r1.188 glr.c
--- glr.c       11 Aug 2006 19:50:14 -0000      1.188
+++ glr.c       12 Sep 2006 09:15:35 -0000
@@ -215,8 +215,12 @@ b4_defines_if([#include @output_header_n
 # define YYDEBUG ]b4_debug_flag[
 #endif
 
-/* Enabling verbose error messages.  */
-#ifdef YYERROR_VERBOSE
+/* Enabling verbose error messages.
+   if YYERROR_VERBOSE is:
+   - 1 -> first succeeds (1 + 0 != 0), second succeeds (1 - 1 + 1 != 0)
+   - 0 -> first fails (0 + 0 == 0), second succeeds (1 - 0 + 1 != 0)
+   - empty -> first fails (+0 == 0), second fails (1 - +1 == 0) */
+#if defined YYERROR_VERBOSE && ((YYERROR_VERBOSE + 0 != 0) == (1 - 
YYERROR_VERBOSE + 1 != 0))
 # undef YYERROR_VERBOSE
 # define YYERROR_VERBOSE 1
 #else
Index: glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.24
diff -u -p -r1.24 glr.cc
--- glr.cc      9 Jul 2006 20:36:33 -0000       1.24
+++ glr.cc      12 Sep 2006 09:15:35 -0000
@@ -168,6 +168,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4
     yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
     *yycdebug_ << ')';
   }
+#endif /* ! YYDEBUG */
 
   std::ostream&
   ]b4_parser_class_name[::debug_stream () const
@@ -185,16 +186,19 @@ m4_pushdef([b4_parse_param], m4_defn([b4
   ]b4_parser_class_name[::debug_level_type
   ]b4_parser_class_name[::debug_level () const
   {
+#if YYDEBUG
     return ::yydebug;
+#endif
   }
 
   void
   ]b4_parser_class_name[::set_debug_level (debug_level_type l)
   {
+#if YYDEBUG
     ::yydebug = l;
+#endif
   }
 
-#endif /* ! YYDEBUG */
 ]m4_popdef([b4_parse_param])dnl
 [} // namespace ]b4_namespace[
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]