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