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
00035
00036
00037
00038
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 44 "parser.yy"
00049 namespace torc { namespace generic {
00050
00051
00052 #line 53 "location.hh"
00053
00054
00055 class location
00056 {
00057 public:
00058
00059
00060 location ()
00061 : begin (), end ()
00062 {
00063 }
00064
00065
00066
00067 inline void initialize (std::string* fn)
00068 {
00069 begin.initialize (fn);
00070 end = begin;
00071 }
00072
00073
00074
00075 public:
00076
00077 inline void step ()
00078 {
00079 begin = end;
00080 }
00081
00082
00083 inline void columns (unsigned int count = 1)
00084 {
00085 end += count;
00086 }
00087
00088
00089 inline void lines (unsigned int count = 1)
00090 {
00091 end.lines (count);
00092 }
00093
00094
00095
00096 public:
00097
00098 position begin;
00099
00100 position end;
00101 };
00102
00103
00104 inline const location operator+ (const location& begin, const location& end)
00105 {
00106 location res = begin;
00107 res.end = end.end;
00108 return res;
00109 }
00110
00111
00112 inline const location operator+ (const location& begin, unsigned int width)
00113 {
00114 location res = begin;
00115 res.columns (width);
00116 return res;
00117 }
00118
00119
00120 inline location& operator+= (location& res, unsigned int width)
00121 {
00122 res.columns (width);
00123 return res;
00124 }
00125
00126
00127 inline bool
00128 operator== (const location& loc1, const location& loc2)
00129 {
00130 return loc1.begin == loc2.begin && loc1.end == loc2.end;
00131 }
00132
00133
00134 inline bool
00135 operator!= (const location& loc1, const location& loc2)
00136 {
00137 return !(loc1 == loc2);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
00147 {
00148 position last = loc.end - 1;
00149 ostr << loc.begin;
00150 if (last.filename
00151 && (!loc.begin.filename
00152 || *loc.begin.filename != *last.filename))
00153 ostr << '-' << last;
00154 else if (loc.begin.line != last.line)
00155 ostr << '-' << last.line << '.' << last.column;
00156 else if (loc.begin.column != last.column)
00157 ostr << '-' << last.column;
00158 return ostr;
00159 }
00160
00161
00162
00163 #line 44 "parser.yy"
00164 } }
00165
00166
00167 #line 168 "location.hh"
00168
00169 #endif // not BISON_LOCATION_HH