|
1 |
| -// A Bison parser, made by GNU Bison 3.1. |
| 1 | +// A Bison parser, made by GNU Bison 3.2. |
2 | 2 |
|
3 | 3 | // Locations for Bison parsers in C++
|
4 | 4 |
|
|
38 | 38 | #ifndef YY_YY_LOCATION_HH_INCLUDED
|
39 | 39 | # define YY_YY_LOCATION_HH_INCLUDED
|
40 | 40 |
|
41 |
| -# include "position.hh" |
| 41 | +# include <algorithm> // std::max |
| 42 | +# include <iostream> |
| 43 | +# include <string> |
| 44 | + |
| 45 | +# ifndef YY_NULLPTR |
| 46 | +# if defined __cplusplus |
| 47 | +# if 201103L <= __cplusplus |
| 48 | +# define YY_NULLPTR nullptr |
| 49 | +# else |
| 50 | +# define YY_NULLPTR 0 |
| 51 | +# endif |
| 52 | +# else |
| 53 | +# define YY_NULLPTR ((void*)0) |
| 54 | +# endif |
| 55 | +# endif |
42 | 56 |
|
43 | 57 |
|
44 | 58 | namespace yy {
|
45 |
| -#line 46 "location.hh" // location.cc:290 |
| 59 | +#line 60 "location.hh" // location.cc:339 |
| 60 | + /// Abstract a position. |
| 61 | + class position |
| 62 | + { |
| 63 | + public: |
| 64 | + /// Construct a position. |
| 65 | + explicit position (std::string* f = YY_NULLPTR, |
| 66 | + unsigned l = 1u, |
| 67 | + unsigned c = 1u) |
| 68 | + : filename (f) |
| 69 | + , line (l) |
| 70 | + , column (c) |
| 71 | + {} |
| 72 | + |
| 73 | + |
| 74 | + /// Initialization. |
| 75 | + void initialize (std::string* fn = YY_NULLPTR, |
| 76 | + unsigned l = 1u, |
| 77 | + unsigned c = 1u) |
| 78 | + { |
| 79 | + filename = fn; |
| 80 | + line = l; |
| 81 | + column = c; |
| 82 | + } |
| 83 | + |
| 84 | + /** \name Line and Column related manipulators |
| 85 | + ** \{ */ |
| 86 | + /// (line related) Advance to the COUNT next lines. |
| 87 | + void lines (int count = 1) |
| 88 | + { |
| 89 | + if (count) |
| 90 | + { |
| 91 | + column = 1u; |
| 92 | + line = add_ (line, count, 1); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + /// (column related) Advance to the COUNT next columns. |
| 97 | + void columns (int count = 1) |
| 98 | + { |
| 99 | + column = add_ (column, count, 1); |
| 100 | + } |
| 101 | + /** \} */ |
| 102 | + |
| 103 | + /// File name to which this position refers. |
| 104 | + std::string* filename; |
| 105 | + /// Current line number. |
| 106 | + unsigned line; |
| 107 | + /// Current column number. |
| 108 | + unsigned column; |
| 109 | + |
| 110 | + private: |
| 111 | + /// Compute max (min, lhs+rhs). |
| 112 | + static unsigned add_ (unsigned lhs, int rhs, int min) |
| 113 | + { |
| 114 | + return static_cast<unsigned> (std::max (min, |
| 115 | + static_cast<int> (lhs) + rhs)); |
| 116 | + } |
| 117 | + }; |
| 118 | + |
| 119 | + /// Add \a width columns, in place. |
| 120 | + inline position& |
| 121 | + operator+= (position& res, int width) |
| 122 | + { |
| 123 | + res.columns (width); |
| 124 | + return res; |
| 125 | + } |
| 126 | + |
| 127 | + /// Add \a width columns. |
| 128 | + inline position |
| 129 | + operator+ (position res, int width) |
| 130 | + { |
| 131 | + return res += width; |
| 132 | + } |
| 133 | + |
| 134 | + /// Subtract \a width columns, in place. |
| 135 | + inline position& |
| 136 | + operator-= (position& res, int width) |
| 137 | + { |
| 138 | + return res += -width; |
| 139 | + } |
| 140 | + |
| 141 | + /// Subtract \a width columns. |
| 142 | + inline position |
| 143 | + operator- (position res, int width) |
| 144 | + { |
| 145 | + return res -= width; |
| 146 | + } |
| 147 | + |
| 148 | + /// Compare two position objects. |
| 149 | + inline bool |
| 150 | + operator== (const position& pos1, const position& pos2) |
| 151 | + { |
| 152 | + return (pos1.line == pos2.line |
| 153 | + && pos1.column == pos2.column |
| 154 | + && (pos1.filename == pos2.filename |
| 155 | + || (pos1.filename && pos2.filename |
| 156 | + && *pos1.filename == *pos2.filename))); |
| 157 | + } |
| 158 | + |
| 159 | + /// Compare two position objects. |
| 160 | + inline bool |
| 161 | + operator!= (const position& pos1, const position& pos2) |
| 162 | + { |
| 163 | + return !(pos1 == pos2); |
| 164 | + } |
| 165 | + |
| 166 | + /** \brief Intercept output stream redirection. |
| 167 | + ** \param ostr the destination output stream |
| 168 | + ** \param pos a reference to the position to redirect |
| 169 | + */ |
| 170 | + template <typename YYChar> |
| 171 | + std::basic_ostream<YYChar>& |
| 172 | + operator<< (std::basic_ostream<YYChar>& ostr, const position& pos) |
| 173 | + { |
| 174 | + if (pos.filename) |
| 175 | + ostr << *pos.filename << ':'; |
| 176 | + return ostr << pos.line << '.' << pos.column; |
| 177 | + } |
| 178 | + |
46 | 179 | /// Abstract a location.
|
47 | 180 | class location
|
48 | 181 | {
|
@@ -185,5 +318,5 @@ namespace yy {
|
185 | 318 |
|
186 | 319 |
|
187 | 320 | } // yy
|
188 |
| -#line 189 "location.hh" // location.cc:290 |
| 321 | +#line 322 "location.hh" // location.cc:339 |
189 | 322 | #endif // !YY_YY_LOCATION_HH_INCLUDED
|
0 commit comments