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