Alexandre Duret-Lutz <adl@gnu.org>

* data/lalr1.cc (Parser::yycdebug_): New, a pointer, to allow
changes.
(YYCDEBUG): Adjust.
Use it instead of cdebug_.
(Parser::debug_stream, Parser::set_debug_stream): New.
(Parser::symprint_): Define cdebug_ for temporary backward
compatibility.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Use
debug_stream ().
This commit is contained in:
Akim Demaille
2004-11-17 16:17:50 +00:00
parent 85c19f8819
commit 9a1e998918
3 changed files with 59 additions and 26 deletions

View File

@@ -1,3 +1,16 @@
2004-11-17 Akim Demaille <akim@epita.fr>,
Alexandre Duret-Lutz <adl@gnu.org>
* data/lalr1.cc (Parser::yycdebug_): New, a pointer, to allow
changes.
(YYCDEBUG): Adjust.
Use it instead of cdebug_.
(Parser::debug_stream, Parser::set_debug_stream): New.
(Parser::symprint_): Define cdebug_ for temporary backward
compatibility.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Use
debug_stream ().
2004-11-17 Akim Demaille <akim@epita.fr> 2004-11-17 Akim Demaille <akim@epita.fr>
* data/lalr1.cc (Parser:print_): Remove, use %printer instead. * data/lalr1.cc (Parser:print_): Remove, use %printer instead.

View File

@@ -238,19 +238,19 @@ namespace yy
]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) : ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
]b4_constructor[][debug_ (debug), ]b4_constructor[][debug_ (debug),
cdebug_ (std::cerr)]b4_parse_param_cons[ yycdebug_ (&std::cerr)]b4_parse_param_cons[
{ {
} }
]b4_parser_class_name[ (bool debug, ]b4_parser_class_name[ (bool debug,
LocationType][]b4_param[]b4_parse_param_decl[) : LocationType][]b4_param[]b4_parse_param_decl[) :
]b4_constructor[][debug_ (debug), ]b4_constructor[][debug_ (debug),
cdebug_ (std::cerr)]b4_parse_param_cons[ yycdebug_ (&std::cerr)]b4_parse_param_cons[
{ {
cdebug_ << __FILE__ << ':' << __LINE__ *yycdebug_ << __FILE__ << ':' << __LINE__
<< ": this constructor is provided by backward compatibility" << ": this constructor is provided by backward compatibility"
<< ", but will be removed in the near future." << ", but will be removed in the near future."
<< std::endl; << std::endl;
} }
virtual ~]b4_parser_class_name[ () virtual ~]b4_parser_class_name[ ()
@@ -259,6 +259,11 @@ namespace yy
virtual int parse (); virtual int parse ();
/// Return the current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
void set_debug_stream (std::ostream &);
private: private:
virtual void lex_ (); virtual void lex_ ();
@@ -336,7 +341,7 @@ namespace yy
/* Debugging. */ /* Debugging. */
int debug_; int debug_;
std::ostream& cdebug_; std::ostream* yycdebug_;
/* Look-ahead and look-ahead in internal form. */ /* Look-ahead and look-ahead in internal form. */
int looka_; int looka_;
@@ -368,20 +373,21 @@ b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
/* A pseudo ostream that takes debug_ into account. */
# define YYCDEBUG \
for (bool yydebugcond_ = debug_; yydebugcond_; yydebugcond_ = false) \
(*yycdebug_)
/* Enable debugging if requested. */ /* Enable debugging if requested. */
#if YYDEBUG #if YYDEBUG
# define YYCDEBUG \
if (debug_) \
cdebug_
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \ do { \
if (debug_) \ if (debug_) \
{ \ { \
cdebug_ << (Title) << ' '; \ *yycdebug_ << (Title) << ' '; \
symprint_ ((Type), (Value), (Location)); \ symprint_ ((Type), (Value), (Location)); \
cdebug_ << std::endl; \ *yycdebug_ << std::endl; \
} \ } \
} while (0) } while (0)
@@ -399,7 +405,6 @@ do { \
#else /* !YYDEBUG */ #else /* !YYDEBUG */
# define YYCDEBUG if (0) cdebug_
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_REDUCE_PRINT(Rule) # define YY_REDUCE_PRINT(Rule)
# define YY_STACK_PRINT() # define YY_STACK_PRINT()
@@ -422,17 +427,19 @@ yy::]b4_parser_class_name[::symprint_ (int yytype,
/* Pacify ``unused variable'' warnings. */ /* Pacify ``unused variable'' warnings. */
(void) yyvaluep; (void) yyvaluep;
(void) yylocationp; (void) yylocationp;
/* Backward compatibility, but should be removed eventually. */
std::ostream& cdebug_ = *yycdebug_;
cdebug_ << (yytype < ntokens_ ? "token" : "nterm") *yycdebug_ << (yytype < ntokens_ ? "token" : "nterm")
<< ' ' << name_[yytype] << " (" << ' ' << name_[yytype] << " ("
<< *yylocationp << ": "; << *yylocationp << ": ";
switch (yytype) switch (yytype)
{ {
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
[ default: [ default:
break; break;
} }
cdebug_ << ')'; *yycdebug_ << ')';
} }
#endif /* ! YYDEBUG */ #endif /* ! YYDEBUG */
@@ -462,6 +469,19 @@ yy::]b4_parser_class_name[::pop (unsigned int n)
location_stack_.pop (n); location_stack_.pop (n);
} }
std::ostream&
yy::]b4_parser_class_name[::debug_stream () const
{
return *yycdebug_;
}
void
yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
{
yycdebug_ = &o;
}
int int
yy::]b4_parser_class_name[::parse () yy::]b4_parser_class_name[::parse ()
{ {
@@ -914,11 +934,11 @@ yy::]b4_parser_class_name[::rline_[] =
void void
yy::]b4_parser_class_name[::stack_print_ () yy::]b4_parser_class_name[::stack_print_ ()
{ {
cdebug_ << "Stack now"; *yycdebug_ << "Stack now";
for (StateStack::const_iterator i = state_stack_.begin (); for (StateStack::const_iterator i = state_stack_.begin ();
i != state_stack_.end (); ++i) i != state_stack_.end (); ++i)
cdebug_ << ' ' << *i; *yycdebug_ << ' ' << *i;
cdebug_ << std::endl; *yycdebug_ << std::endl;
} }
/** Report that the YYRULE is going to be reduced. */ /** Report that the YYRULE is going to be reduced. */
@@ -928,12 +948,12 @@ yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
{ {
unsigned int yylno = rline_[yyrule]; unsigned int yylno = rline_[yyrule];
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
cdebug_ << "Reducing stack by rule " << n_ - 1 *yycdebug_ << "Reducing stack by rule " << n_ - 1
<< " (line " << yylno << "), "; << " (line " << yylno << "), ";
for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
0 <= rhs_[i]; ++i) 0 <= rhs_[i]; ++i)
cdebug_ << name_[rhs_[i]] << ' '; *yycdebug_ << name_[rhs_[i]] << ' ';
cdebug_ << "-> " << name_[r1_[n_]] << std::endl; *yycdebug_ << "-> " << name_[r1_[n_]] << std::endl;
} }
#endif // YYDEBUG #endif // YYDEBUG

View File

@@ -196,7 +196,7 @@ m4_ifval([$6], [%union
%printer %printer
{ {
]AT_LALR1_CC_IF([cdebug_ << $$;], ]AT_LALR1_CC_IF([debug_stream () << $$;],
[fprintf (yyoutput, "%d", $$)])[; [fprintf (yyoutput, "%d", $$)])[;
} }
input line thing 'x' 'y' input line thing 'x' 'y'