1 // A Bison parser, made by GNU Bison 3.5.1. 2 3 // Locations for Bison parsers in C++ 4 5 // Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. 6 7 // This program is free software: you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by 9 // the Free Software Foundation, either version 3 of the License, or 10 // (at your option) any later version. 11 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 17 // You should have received a copy of the GNU General Public License 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. 19 20 // As a special exception, you may create a larger work that contains 21 // part or all of the Bison parser skeleton and distribute that work 22 // under terms of your choice, so long as that work isn't itself a 23 // parser generator using the skeleton or a modified version thereof 24 // as a parser skeleton. Alternatively, if you modify or redistribute 25 // the parser skeleton itself, you may (at your option) remove this 26 // special exception, which will cause the skeleton and the resulting 27 // Bison output files to be licensed under the GNU General Public 28 // License without this special exception. 29 30 // This special exception was added by the Free Software Foundation in 31 // version 2.2 of Bison. 32 33 /** 34 ** \file sqlite3_location.h 35 ** Define the sqlb::parser ::location class. 36 */ 37 38 #ifndef YY_YY_SQLITE3_LOCATION_H_INCLUDED 39 # define YY_YY_SQLITE3_LOCATION_H_INCLUDED 40 41 # include <iostream> 42 # include <string> 43 44 # ifndef YY_NULLPTR 45 # if defined __cplusplus 46 # if 201103L <= __cplusplus 47 # define YY_NULLPTR nullptr 48 # else 49 # define YY_NULLPTR 0 50 # endif 51 # else 52 # define YY_NULLPTR ((void*)0) 53 # endif 54 # endif 55 56 #line 10 "sqlite3_parser.yy" 57 namespace sqlb { namespace parser { 58 #line 59 "sqlite3_location.h" 59 60 /// A point in a source file. 61 class position 62 { 63 public: 64 /// Type for line and column numbers. 65 typedef int counter_type; 66 67 /// Construct a position. 68 explicit position (std::string* f = YY_NULLPTR, 69 counter_type l = 1, 70 counter_type c = 1) filename(f)71 : filename (f) 72 , line (l) 73 , column (c) 74 {} 75 76 77 /// Initialization. 78 void initialize (std::string* fn = YY_NULLPTR, 79 counter_type l = 1, 80 counter_type c = 1) 81 { 82 filename = fn; 83 line = l; 84 column = c; 85 } 86 87 /** \name Line and Column related manipulators 88 ** \{ */ 89 /// (line related) Advance to the COUNT next lines. 90 void lines (counter_type count = 1) 91 { 92 if (count) 93 { 94 column = 1; 95 line = add_ (line, count, 1); 96 } 97 } 98 99 /// (column related) Advance to the COUNT next columns. 100 void columns (counter_type count = 1) 101 { 102 column = add_ (column, count, 1); 103 } 104 /** \} */ 105 106 /// File name to which this position refers. 107 std::string* filename; 108 /// Current line number. 109 counter_type line; 110 /// Current column number. 111 counter_type column; 112 113 private: 114 /// Compute max (min, lhs+rhs). add_(counter_type lhs,counter_type rhs,counter_type min)115 static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min) 116 { 117 return lhs + rhs < min ? min : lhs + rhs; 118 } 119 }; 120 121 /// Add \a width columns, in place. 122 inline position& 123 operator+= (position& res, position::counter_type width) 124 { 125 res.columns (width); 126 return res; 127 } 128 129 /// Add \a width columns. 130 inline position 131 operator+ (position res, position::counter_type width) 132 { 133 return res += width; 134 } 135 136 /// Subtract \a width columns, in place. 137 inline position& 138 operator-= (position& res, position::counter_type width) 139 { 140 return res += -width; 141 } 142 143 /// Subtract \a width columns. 144 inline position 145 operator- (position res, position::counter_type width) 146 { 147 return res -= width; 148 } 149 150 /// Compare two position objects. 151 inline bool 152 operator== (const position& pos1, const position& pos2) 153 { 154 return (pos1.line == pos2.line 155 && pos1.column == pos2.column 156 && (pos1.filename == pos2.filename 157 || (pos1.filename && pos2.filename 158 && *pos1.filename == *pos2.filename))); 159 } 160 161 /// Compare two position objects. 162 inline bool 163 operator!= (const position& pos1, const position& pos2) 164 { 165 return !(pos1 == pos2); 166 } 167 168 /** \brief Intercept output stream redirection. 169 ** \param ostr the destination output stream 170 ** \param pos a reference to the position to redirect 171 */ 172 template <typename YYChar> 173 std::basic_ostream<YYChar>& 174 operator<< (std::basic_ostream<YYChar>& ostr, const position& pos) 175 { 176 if (pos.filename) 177 ostr << *pos.filename << ':'; 178 return ostr << pos.line << '.' << pos.column; 179 } 180 181 /// Two points in a source file. 182 class location 183 { 184 public: 185 /// Type for line and column numbers. 186 typedef position::counter_type counter_type; 187 188 /// Construct a location from \a b to \a e. location(const position & b,const position & e)189 location (const position& b, const position& e) 190 : begin (b) 191 , end (e) 192 {} 193 194 /// Construct a 0-width location in \a p. 195 explicit location (const position& p = position ()) begin(p)196 : begin (p) 197 , end (p) 198 {} 199 200 /// Construct a 0-width location in \a f, \a l, \a c. 201 explicit location (std::string* f, 202 counter_type l = 1, 203 counter_type c = 1) begin(f,l,c)204 : begin (f, l, c) 205 , end (f, l, c) 206 {} 207 208 209 /// Initialization. 210 void initialize (std::string* f = YY_NULLPTR, 211 counter_type l = 1, 212 counter_type c = 1) 213 { 214 begin.initialize (f, l, c); 215 end = begin; 216 } 217 218 /** \name Line and Column related manipulators 219 ** \{ */ 220 public: 221 /// Reset initial location to final location. step()222 void step () 223 { 224 begin = end; 225 } 226 227 /// Extend the current location to the COUNT next columns. 228 void columns (counter_type count = 1) 229 { 230 end += count; 231 } 232 233 /// Extend the current location to the COUNT next lines. 234 void lines (counter_type count = 1) 235 { 236 end.lines (count); 237 } 238 /** \} */ 239 240 241 public: 242 /// Beginning of the located region. 243 position begin; 244 /// End of the located region. 245 position end; 246 }; 247 248 /// Join two locations, in place. 249 inline location& 250 operator+= (location& res, const location& end) 251 { 252 res.end = end.end; 253 return res; 254 } 255 256 /// Join two locations. 257 inline location 258 operator+ (location res, const location& end) 259 { 260 return res += end; 261 } 262 263 /// Add \a width columns to the end position, in place. 264 inline location& 265 operator+= (location& res, location::counter_type width) 266 { 267 res.columns (width); 268 return res; 269 } 270 271 /// Add \a width columns to the end position. 272 inline location 273 operator+ (location res, location::counter_type width) 274 { 275 return res += width; 276 } 277 278 /// Subtract \a width columns to the end position, in place. 279 inline location& 280 operator-= (location& res, location::counter_type width) 281 { 282 return res += -width; 283 } 284 285 /// Subtract \a width columns to the end position. 286 inline location 287 operator- (location res, location::counter_type width) 288 { 289 return res -= width; 290 } 291 292 /// Compare two location objects. 293 inline bool 294 operator== (const location& loc1, const location& loc2) 295 { 296 return loc1.begin == loc2.begin && loc1.end == loc2.end; 297 } 298 299 /// Compare two location objects. 300 inline bool 301 operator!= (const location& loc1, const location& loc2) 302 { 303 return !(loc1 == loc2); 304 } 305 306 /** \brief Intercept output stream redirection. 307 ** \param ostr the destination output stream 308 ** \param loc a reference to the location to redirect 309 ** 310 ** Avoid duplicate information. 311 */ 312 template <typename YYChar> 313 std::basic_ostream<YYChar>& 314 operator<< (std::basic_ostream<YYChar>& ostr, const location& loc) 315 { 316 location::counter_type end_col 317 = 0 < loc.end.column ? loc.end.column - 1 : 0; 318 ostr << loc.begin; 319 if (loc.end.filename 320 && (!loc.begin.filename 321 || *loc.begin.filename != *loc.end.filename)) 322 ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; 323 else if (loc.begin.line < loc.end.line) 324 ostr << '-' << loc.end.line << '.' << end_col; 325 else if (loc.begin.column < end_col) 326 ostr << '-' << end_col; 327 return ostr; 328 } 329 330 #line 10 "sqlite3_parser.yy" 331 } } // sqlb::parser 332 #line 333 "sqlite3_location.h" 333 334 #endif // !YY_YY_SQLITE3_LOCATION_H_INCLUDED 335