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
00039 #ifndef BISON_LOCATION_HH
00040 # define BISON_LOCATION_HH
00041
00042 # include <iostream>
00043 # include <string>
00044 # include "position.hh"
00045
00046
00047
00048 #line 1 "[Bison:b4_percent_define_default]"
00049
00050 namespace example {
00051
00052
00053 #line 54 "location.hh"
00054
00056 class location
00057 {
00058 public:
00059
00061 location ()
00062 : begin (), end ()
00063 {
00064 }
00065
00066
00068 inline void initialize (std::string* fn)
00069 {
00070 begin.initialize (fn);
00071 end = begin;
00072 }
00073
00076 public:
00078 inline void step ()
00079 {
00080 begin = end;
00081 }
00082
00084 inline void columns (unsigned int count = 1)
00085 {
00086 end += count;
00087 }
00088
00090 inline void lines (unsigned int count = 1)
00091 {
00092 end.lines (count);
00093 }
00097 public:
00099 position begin;
00101 position end;
00102 };
00103
00105 inline const location operator+ (const location& begin, const location& end)
00106 {
00107 location res = begin;
00108 res.end = end.end;
00109 return res;
00110 }
00111
00113 inline const location operator+ (const location& begin, unsigned int width)
00114 {
00115 location res = begin;
00116 res.columns (width);
00117 return res;
00118 }
00119
00121 inline location& operator+= (location& res, unsigned int width)
00122 {
00123 res.columns (width);
00124 return res;
00125 }
00126
00128 inline bool
00129 operator== (const location& loc1, const location& loc2)
00130 {
00131 return loc1.begin == loc2.begin && loc1.end == loc2.end;
00132 }
00133
00135 inline bool
00136 operator!= (const location& loc1, const location& loc2)
00137 {
00138 return !(loc1 == loc2);
00139 }
00140
00147 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
00148 {
00149 position last = loc.end - 1;
00150 ostr << loc.begin;
00151 if (last.filename
00152 && (!loc.begin.filename
00153 || *loc.begin.filename != *last.filename))
00154 ostr << '-' << last;
00155 else if (loc.begin.line != last.line)
00156 ostr << '-' << last.line << '.' << last.column;
00157 else if (loc.begin.column != last.column)
00158 ostr << '-' << last.column;
00159 return ostr;
00160 }
00161
00162
00163
00164 #line 1 "[Bison:b4_percent_define_default]"
00165
00166 }
00167
00168
00169 #line 170 "location.hh"
00170
00171 #endif // not BISON_LOCATION_HH