1 // A Bison parser, made by GNU Bison 3.7.1.
3 // Locations for Bison parsers in C++
5 // Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
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.
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.
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/>.
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.
30 // This special exception was added by the Free Software Foundation in
31 // version 2.2 of Bison.
34 ** \file StepFile/location.hh
35 ** Define the step::location class.
38 #ifndef YY_STEP_STEPFILE_LOCATION_HH_INCLUDED
39 # define YY_STEP_STEPFILE_LOCATION_HH_INCLUDED
45 # if defined __cplusplus
46 # if 201103L <= __cplusplus
47 # define YY_NULLPTR nullptr
52 # define YY_NULLPTR ((void*)0)
58 /// A point in a source file.
62 /// Type for file name.
63 typedef const std::string filename_type;
64 /// Type for line and column numbers.
65 typedef int counter_type;
67 /// Construct a position.
68 explicit position (filename_type* f = YY_NULLPTR,
78 void initialize (filename_type* fn = YY_NULLPTR,
87 /** \name Line and Column related manipulators
89 /// (line related) Advance to the COUNT next lines.
90 void lines (counter_type count = 1)
95 line = add_ (line, count, 1);
99 /// (column related) Advance to the COUNT next columns.
100 void columns (counter_type count = 1)
102 column = add_ (column, count, 1);
106 /// File name to which this position refers.
107 filename_type* filename;
108 /// Current line number.
110 /// Current column number.
114 /// Compute max (min, lhs+rhs).
115 static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min)
117 return lhs + rhs < min ? min : lhs + rhs;
121 /// Add \a width columns, in place.
123 operator+= (position& res, position::counter_type width)
129 /// Add \a width columns.
131 operator+ (position res, position::counter_type width)
136 /// Subtract \a width columns, in place.
138 operator-= (position& res, position::counter_type width)
140 return res += -width;
143 /// Subtract \a width columns.
145 operator- (position res, position::counter_type width)
150 /** \brief Intercept output stream redirection.
151 ** \param ostr the destination output stream
152 ** \param pos a reference to the position to redirect
154 template <typename YYChar>
155 std::basic_ostream<YYChar>&
156 operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
159 ostr << *pos.filename << ':';
160 return ostr << pos.line << '.' << pos.column;
163 /// Two points in a source file.
167 /// Type for file name.
168 typedef position::filename_type filename_type;
169 /// Type for line and column numbers.
170 typedef position::counter_type counter_type;
172 /// Construct a location from \a b to \a e.
173 location (const position& b, const position& e)
178 /// Construct a 0-width location in \a p.
179 explicit location (const position& p = position ())
184 /// Construct a 0-width location in \a f, \a l, \a c.
185 explicit location (filename_type* f,
194 void initialize (filename_type* f = YY_NULLPTR,
198 begin.initialize (f, l, c);
202 /** \name Line and Column related manipulators
205 /// Reset initial location to final location.
211 /// Extend the current location to the COUNT next columns.
212 void columns (counter_type count = 1)
217 /// Extend the current location to the COUNT next lines.
218 void lines (counter_type count = 1)
226 /// Beginning of the located region.
228 /// End of the located region.
232 /// Join two locations, in place.
234 operator+= (location& res, const location& end)
240 /// Join two locations.
242 operator+ (location res, const location& end)
247 /// Add \a width columns to the end position, in place.
249 operator+= (location& res, location::counter_type width)
255 /// Add \a width columns to the end position.
257 operator+ (location res, location::counter_type width)
262 /// Subtract \a width columns to the end position, in place.
264 operator-= (location& res, location::counter_type width)
266 return res += -width;
269 /// Subtract \a width columns to the end position.
271 operator- (location res, location::counter_type width)
276 /** \brief Intercept output stream redirection.
277 ** \param ostr the destination output stream
278 ** \param loc a reference to the location to redirect
280 ** Avoid duplicate information.
282 template <typename YYChar>
283 std::basic_ostream<YYChar>&
284 operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
286 location::counter_type end_col
287 = 0 < loc.end.column ? loc.end.column - 1 : 0;
290 && (!loc.begin.filename
291 || *loc.begin.filename != *loc.end.filename))
292 ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
293 else if (loc.begin.line < loc.end.line)
294 ostr << '-' << loc.end.line << '.' << end_col;
295 else if (loc.begin.column < end_col)
296 ostr << '-' << end_col;
302 #endif // !YY_STEP_STEPFILE_LOCATION_HH_INCLUDED