00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00040 #ifndef BISON_LOCATION_HH
00041 # define BISON_LOCATION_HH
00042
00043 # include <iostream>
00044 # include <string>
00045 # include "position.hh"
00046
00047 namespace yy
00048 {
00049
00051 class location
00052 {
00053 public:
00054
00056 location ()
00057 : begin (), end ()
00058 {
00059 }
00060
00061
00063 inline void initialize (std::string* fn)
00064 {
00065 begin.initialize (fn);
00066 end = begin;
00067 }
00068
00071 public:
00073 inline void step ()
00074 {
00075 begin = end;
00076 }
00077
00079 inline void columns (unsigned int count = 1)
00080 {
00081 end += count;
00082 }
00083
00085 inline void lines (unsigned int count = 1)
00086 {
00087 end.lines (count);
00088 }
00092 public:
00094 position begin;
00096 position end;
00097 };
00098
00100 inline const location operator+ (const location& begin, const location& end)
00101 {
00102 location res = begin;
00103 res.end = end.end;
00104 return res;
00105 }
00106
00108 inline const location operator+ (const location& begin, unsigned int width)
00109 {
00110 location res = begin;
00111 res.columns (width);
00112 return res;
00113 }
00114
00116 inline location& operator+= (location& res, unsigned int width)
00117 {
00118 res.columns (width);
00119 return res;
00120 }
00121
00128 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
00129 {
00130 position last = loc.end - 1;
00131 ostr << loc.begin;
00132 if (last.filename
00133 && (!loc.begin.filename
00134 || *loc.begin.filename != *last.filename))
00135 ostr << '-' << last;
00136 else if (loc.begin.line != last.line)
00137 ostr << '-' << last.line << '.' << last.column;
00138 else if (loc.begin.column != last.column)
00139 ostr << '-' << last.column;
00140 return ostr;
00141 }
00142
00143 }
00144
00145 #endif // not BISON_LOCATION_HH