From: Akim Demaille Date: Tue, 21 Dec 2004 12:03:47 +0000 (+0000) Subject: Don't impose std::string for filenames. X-Git-Tag: BISON-2_0~15 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/9a0d8becd844eba80ff657a7391b2e85b7ff2077 Don't impose std::string for filenames. * data/lalr1.cc (b4_filename_type): New. (position::filename): Use it. (parser.hh): Move the inclusion of stack.hh and location.hh below the user code, so that needed headers for the filename type can be included first. --- diff --git a/ChangeLog b/ChangeLog index f00c1923..eda08019 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-12-21 Akim Demaille + + Don't impose std::string for filenames. + + * data/lalr1.cc (b4_filename_type): New. + (position::filename): Use it. + (parser.hh): Move the inclusion of stack.hh and location.hh below + the user code, so that needed headers for the filename type can be + included first. + 2004-12-20 Akim Demaille Use more STL like names: my_class instead of MyClass. diff --git a/data/lalr1.cc b/data/lalr1.cc index fbfc0b76..914bc966 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -46,6 +46,7 @@ m4_define([b4_rhs_value], [(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))]) m4_define_default([b4_location_type], [location]) +m4_define_default([b4_filename_type], [std::string]) # b4_lhs_location() # ----------------- @@ -118,9 +119,6 @@ b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], #ifndef PARSER_HEADER_H # define PARSER_HEADER_H -#include "stack.hh" -#include "location.hh" - #include #include @@ -135,6 +133,9 @@ b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], ]/* Line __line__ of lalr1.cc. */ b4_syncline([@oline@], [@ofile@])[ +#include "stack.hh" +#include "location.hh" + /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG ]b4_debug[ @@ -1168,7 +1169,7 @@ namespace yy public: /// Construct a position. position () : - filename (), + filename (0), line (initial_line), column (initial_column) { @@ -1200,7 +1201,7 @@ namespace yy public: /// File name to which this position refers. - std::string filename; + ]b4_filename_type[* filename; /// Current line number. unsigned int line; /// Current column number. @@ -1244,8 +1245,8 @@ namespace yy inline std::ostream& operator<< (std::ostream& ostr, const position& pos) { - if (!pos.filename.empty ()) - ostr << pos.filename << ':'; + if (pos.filename) + ostr << *pos.filename << ':'; return ostr << pos.line << '.' << pos.column; } @@ -1347,7 +1348,9 @@ namespace yy { position last = loc.end - 1; ostr << loc.begin; - if (loc.begin.filename != last.filename) + if (last.filename + && (!loc.begin.filename + || *loc.begin.filename != *last.filename)) ostr << '-' << last; else if (loc.begin.line != last.line) ostr << '-' << last.line << '.' << last.column;