Go to the documentation of this file.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
00038 #ifndef BISON_LOCATION_HH
00039 # define BISON_LOCATION_HH
00040
00041 # include <iostream>
00042 # include <string>
00043 # include "position.hh"
00044
00045
00046 namespace ltlyy {
00047
00048
00049 #line 50 "location.hh"
00050
00052 class location
00053 {
00054 public:
00055
00057 location ()
00058 : begin (), end ()
00059 {
00060 }
00061
00062
00064 inline void initialize (std::string* fn)
00065 {
00066 begin.initialize (fn);
00067 end = begin;
00068 }
00069
00072 public:
00074 inline void step ()
00075 {
00076 begin = end;
00077 }
00078
00080 inline void columns (unsigned int count = 1)
00081 {
00082 end += count;
00083 }
00084
00086 inline void lines (unsigned int count = 1)
00087 {
00088 end.lines (count);
00089 }
00093 public:
00095 position begin;
00097 position end;
00098 };
00099
00101 inline const location operator+ (const location& begin, const location& end)
00102 {
00103 location res = begin;
00104 res.end = end.end;
00105 return res;
00106 }
00107
00109 inline const location operator+ (const location& begin, unsigned int width)
00110 {
00111 location res = begin;
00112 res.columns (width);
00113 return res;
00114 }
00115
00117 inline location& operator+= (location& res, unsigned int width)
00118 {
00119 res.columns (width);
00120 return res;
00121 }
00122
00124 inline bool
00125 operator== (const location& loc1, const location& loc2)
00126 {
00127 return loc1.begin == loc2.begin && loc1.end == loc2.end;
00128 }
00129
00131 inline bool
00132 operator!= (const location& loc1, const location& loc2)
00133 {
00134 return !(loc1 == loc2);
00135 }
00136
00143 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
00144 {
00145 position last = loc.end - 1;
00146 ostr << loc.begin;
00147 if (last.filename
00148 && (!loc.begin.filename
00149 || *loc.begin.filename != *last.filename))
00150 ostr << '-' << last;
00151 else if (loc.begin.line != last.line)
00152 ostr << '-' << last.line << '.' << last.column;
00153 else if (loc.begin.column != last.column)
00154 ostr << '-' << last.column;
00155 return ostr;
00156 }
00157
00158
00159 }
00160
00161
00162 #line 163 "location.hh"
00163
00164 #endif // not BISON_LOCATION_HH