g2o
Loading...
Searching...
No Matches
location.hh
Go to the documentation of this file.
1// A Bison parser, made by GNU Bison 3.8.2.
2
3// Locations for Bison parsers in C++
4
5// Copyright (C) 2002-2015, 2018-2021 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 <https://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
38#ifndef YY_SLAMPARSER_LOCATION_HH_INCLUDED
39#define YY_SLAMPARSER_LOCATION_HH_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
56namespace SlamParser {
57#line 58 "location.hh"
58
60class position {
61 public:
63 typedef const std::string filename_type;
65 typedef int counter_type;
66
69 counter_type c = 1)
70 : filename(f), line(l), column(c) {}
71
74 counter_type c = 1) {
75 filename = fn;
76 line = l;
77 column = c;
78 }
79
83 void lines(counter_type count = 1) {
84 if (count) {
85 column = 1;
86 line = add_(line, count, 1);
87 }
88 }
89
91 void columns(counter_type count = 1) { column = add_(column, count, 1); }
100
101 private:
104 counter_type min) {
105 return lhs + rhs < min ? min : lhs + rhs;
106 }
107};
108
111 res.columns(width);
112 return res;
113}
114
117 return res += width;
118}
119
122 return res += -width;
123}
124
127 return res -= width;
128}
129
134template <typename YYChar>
135std::basic_ostream<YYChar>& operator<<(std::basic_ostream<YYChar>& ostr,
136 const position& pos) {
137 if (pos.filename) ostr << *pos.filename << ':';
138 return ostr << pos.line << '.' << pos.column;
139}
140
142class location {
143 public:
148
150 location(const position& b, const position& e) : begin(b), end(e) {}
151
153 explicit location(const position& p = position()) : begin(p), end(p) {}
154
157 : begin(f, l, c), end(f, l, c) {}
158
161 counter_type c = 1) {
162 begin.initialize(f, l, c);
163 end = begin;
164 }
165
168 public:
170 void step() { begin = end; }
171
173 void columns(counter_type count = 1) { end += count; }
174
176 void lines(counter_type count = 1) { end.lines(count); }
179 public:
184};
185
187inline location& operator+=(location& res, const location& end) {
188 res.end = end.end;
189 return res;
190}
191
193inline location operator+(location res, const location& end) {
194 return res += end;
195}
196
199 res.columns(width);
200 return res;
201}
202
205 return res += width;
206}
207
210 return res += -width;
211}
212
215 return res -= width;
216}
217
224template <typename YYChar>
225std::basic_ostream<YYChar>& operator<<(std::basic_ostream<YYChar>& ostr,
226 const location& loc) {
227 location::counter_type end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
228 ostr << loc.begin;
229 if (loc.end.filename &&
230 (!loc.begin.filename || *loc.begin.filename != *loc.end.filename))
231 ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
232 else if (loc.begin.line < loc.end.line)
233 ostr << '-' << loc.end.line << '.' << end_col;
234 else if (loc.begin.column < end_col)
235 ostr << '-' << end_col;
236 return ostr;
237}
238
239} // namespace SlamParser
240#line 303 "location.hh"
241
242#endif // !YY_SLAMPARSER_LOCATION_HH_INCLUDED
Two points in a source file.
Definition location.hh:142
void step()
Reset initial location to final location.
Definition location.hh:170
void columns(counter_type count=1)
Extend the current location to the COUNT next columns.
Definition location.hh:173
position::filename_type filename_type
Type for file name.
Definition location.hh:145
location(const position &p=position())
Construct a 0-width location in p.
Definition location.hh:153
position::counter_type counter_type
Type for line and column numbers.
Definition location.hh:147
void lines(counter_type count=1)
Extend the current location to the COUNT next lines.
Definition location.hh:176
position end
End of the located region.
Definition location.hh:183
location(filename_type *f, counter_type l=1, counter_type c=1)
Construct a 0-width location in f, l, c.
Definition location.hh:156
position begin
Beginning of the located region.
Definition location.hh:181
void initialize(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition location.hh:160
location(const position &b, const position &e)
Construct a location from b to e.
Definition location.hh:150
A point in a source file.
Definition location.hh:60
const std::string filename_type
Type for file name.
Definition location.hh:63
void columns(counter_type count=1)
(column related) Advance to the COUNT next columns.
Definition location.hh:91
void lines(counter_type count=1)
(line related) Advance to the COUNT next lines.
Definition location.hh:83
filename_type * filename
File name to which this position refers.
Definition location.hh:95
counter_type column
Current column number.
Definition location.hh:99
static counter_type add_(counter_type lhs, counter_type rhs, counter_type min)
Compute max (min, lhs+rhs).
Definition location.hh:103
int counter_type
Type for line and column numbers.
Definition location.hh:65
void initialize(filename_type *fn=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition location.hh:73
counter_type line
Current line number.
Definition location.hh:97
position(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Construct a position.
Definition location.hh:68
#define YY_NULLPTR
Definition location.hh:52
position operator-(position res, position::counter_type width)
Subtract width columns.
Definition location.hh:126
position & operator+=(position &res, position::counter_type width)
Add width columns, in place.
Definition location.hh:110
std::basic_ostream< YYChar > & operator<<(std::basic_ostream< YYChar > &ostr, const position &pos)
Intercept output stream redirection.
Definition location.hh:135
position & operator-=(position &res, position::counter_type width)
Subtract width columns, in place.
Definition location.hh:121
position operator+(position res, position::counter_type width)
Add width columns.
Definition location.hh:116