Don't impose std::string for filenames.
authorAkim Demaille <akim@epita.fr>
Tue, 21 Dec 2004 12:03:47 +0000 (12:03 +0000)
committerAkim Demaille <akim@epita.fr>
Tue, 21 Dec 2004 12:03:47 +0000 (12:03 +0000)
* 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.

ChangeLog
data/lalr1.cc

index f00c19233e3fd041761bd55859284950255322c2..eda08019f87118480a726b9046a4aae20aedebf1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2004-12-21  Akim Demaille  <akim@epita.fr>
+
+       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  <akim@epita.fr>
 
        Use more STL like names: my_class instead of MyClass.
index fbfc0b76e3cec25c6e88f122d638b9f0fcf36aa2..914bc966d10f779af9ced929cd99f3dac345088b 100644 (file)
@@ -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 <string>
 #include <iostream>
 
@@ -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;