/src/kea/src/bin/agent/location.hh
Line | Count | Source |
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 | | |
33 | | /** |
34 | | ** \file location.hh |
35 | | ** Define the isc::agent::location class. |
36 | | */ |
37 | | |
38 | | #ifndef YY_AGENT_LOCATION_HH_INCLUDED |
39 | | # define YY_AGENT_LOCATION_HH_INCLUDED |
40 | | |
41 | | # include <iostream> |
42 | | # include <string> |
43 | | |
44 | | # ifndef YY_NULLPTR |
45 | | # if defined __cplusplus |
46 | | # if 201103L <= __cplusplus |
47 | 2.27M | # 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 14 "agent_parser.yy" |
57 | | namespace isc { namespace agent { |
58 | | #line 59 "location.hh" |
59 | | |
60 | | /// A point in a source file. |
61 | | class position |
62 | | { |
63 | | public: |
64 | | /// Type for file name. |
65 | | typedef const std::string filename_type; |
66 | | /// Type for line and column numbers. |
67 | | typedef int counter_type; |
68 | | |
69 | | /// Construct a position. |
70 | | explicit position (filename_type* f = YY_NULLPTR, |
71 | | counter_type l = 1, |
72 | | counter_type c = 1) |
73 | 1.05M | : filename (f) |
74 | 1.05M | , line (l) |
75 | 1.05M | , column (c) |
76 | 1.05M | {} |
77 | | |
78 | | |
79 | | /// Initialization. |
80 | | void initialize (filename_type* fn = YY_NULLPTR, |
81 | | counter_type l = 1, |
82 | | counter_type c = 1) |
83 | 2.99k | { |
84 | 2.99k | filename = fn; |
85 | 2.99k | line = l; |
86 | 2.99k | column = c; |
87 | 2.99k | } |
88 | | |
89 | | /** \name Line and Column related manipulators |
90 | | ** \{ */ |
91 | | /// (line related) Advance to the COUNT next lines. |
92 | | void lines (counter_type count = 1) |
93 | 6.65k | { |
94 | 6.65k | if (count) |
95 | 6.65k | { |
96 | 6.65k | column = 1; |
97 | 6.65k | line = add_ (line, count, 1); |
98 | 6.65k | } |
99 | 6.65k | } |
100 | | |
101 | | /// (column related) Advance to the COUNT next columns. |
102 | | void columns (counter_type count = 1) |
103 | 183k | { |
104 | 183k | column = add_ (column, count, 1); |
105 | 183k | } |
106 | | /** \} */ |
107 | | |
108 | | /// File name to which this position refers. |
109 | | filename_type* filename; |
110 | | /// Current line number. |
111 | | counter_type line; |
112 | | /// Current column number. |
113 | | counter_type column; |
114 | | |
115 | | private: |
116 | | /// Compute max (min, lhs+rhs). |
117 | | static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min) |
118 | 190k | { |
119 | 190k | return lhs + rhs < min ? min : lhs + rhs; |
120 | 190k | } |
121 | | }; |
122 | | |
123 | | /// Add \a width columns, in place. |
124 | | inline position& |
125 | | operator+= (position& res, position::counter_type width) |
126 | 183k | { |
127 | 183k | res.columns (width); |
128 | 183k | return res; |
129 | 183k | } |
130 | | |
131 | | /// Add \a width columns. |
132 | | inline position |
133 | | operator+ (position res, position::counter_type width) |
134 | 0 | { |
135 | 0 | return res += width; |
136 | 0 | } |
137 | | |
138 | | /// Subtract \a width columns, in place. |
139 | | inline position& |
140 | | operator-= (position& res, position::counter_type width) |
141 | 0 | { |
142 | 0 | return res += -width; |
143 | 0 | } |
144 | | |
145 | | /// Subtract \a width columns. |
146 | | inline position |
147 | | operator- (position res, position::counter_type width) |
148 | 0 | { |
149 | 0 | return res -= width; |
150 | 0 | } |
151 | | |
152 | | /** \brief Intercept output stream redirection. |
153 | | ** \param ostr the destination output stream |
154 | | ** \param pos a reference to the position to redirect |
155 | | */ |
156 | | template <typename YYChar> |
157 | | std::basic_ostream<YYChar>& |
158 | | operator<< (std::basic_ostream<YYChar>& ostr, const position& pos) |
159 | 2.66k | { |
160 | 2.66k | if (pos.filename) |
161 | 2.66k | ostr << *pos.filename << ':'; |
162 | 2.66k | return ostr << pos.line << '.' << pos.column; |
163 | 2.66k | } |
164 | | |
165 | | /// Two points in a source file. |
166 | | class location |
167 | | { |
168 | | public: |
169 | | /// Type for file name. |
170 | | typedef position::filename_type filename_type; |
171 | | /// Type for line and column numbers. |
172 | | typedef position::counter_type counter_type; |
173 | | |
174 | | /// Construct a location from \a b to \a e. |
175 | | location (const position& b, const position& e) |
176 | | : begin (b) |
177 | | , end (e) |
178 | 0 | {} |
179 | | |
180 | | /// Construct a 0-width location in \a p. |
181 | | explicit location (const position& p = position ()) |
182 | 1.05M | : begin (p) |
183 | 1.05M | , end (p) |
184 | 1.05M | {} |
185 | | |
186 | | /// Construct a 0-width location in \a f, \a l, \a c. |
187 | | explicit location (filename_type* f, |
188 | | counter_type l = 1, |
189 | | counter_type c = 1) |
190 | | : begin (f, l, c) |
191 | | , end (f, l, c) |
192 | 0 | {} |
193 | | |
194 | | |
195 | | /// Initialization. |
196 | | void initialize (filename_type* f = YY_NULLPTR, |
197 | | counter_type l = 1, |
198 | | counter_type c = 1) |
199 | 2.99k | { |
200 | 2.99k | begin.initialize (f, l, c); |
201 | 2.99k | end = begin; |
202 | 2.99k | } |
203 | | |
204 | | /** \name Line and Column related manipulators |
205 | | ** \{ */ |
206 | | public: |
207 | | /// Reset initial location to final location. |
208 | | void step () |
209 | 176k | { |
210 | 176k | begin = end; |
211 | 176k | } |
212 | | |
213 | | /// Extend the current location to the COUNT next columns. |
214 | | void columns (counter_type count = 1) |
215 | 183k | { |
216 | 183k | end += count; |
217 | 183k | } |
218 | | |
219 | | /// Extend the current location to the COUNT next lines. |
220 | | void lines (counter_type count = 1) |
221 | 6.65k | { |
222 | 6.65k | end.lines (count); |
223 | 6.65k | } |
224 | | /** \} */ |
225 | | |
226 | | |
227 | | public: |
228 | | /// Beginning of the located region. |
229 | | position begin; |
230 | | /// End of the located region. |
231 | | position end; |
232 | | }; |
233 | | |
234 | | /// Join two locations, in place. |
235 | | inline location& |
236 | | operator+= (location& res, const location& end) |
237 | 0 | { |
238 | 0 | res.end = end.end; |
239 | 0 | return res; |
240 | 0 | } |
241 | | |
242 | | /// Join two locations. |
243 | | inline location |
244 | | operator+ (location res, const location& end) |
245 | 0 | { |
246 | 0 | return res += end; |
247 | 0 | } |
248 | | |
249 | | /// Add \a width columns to the end position, in place. |
250 | | inline location& |
251 | | operator+= (location& res, location::counter_type width) |
252 | 0 | { |
253 | 0 | res.columns (width); |
254 | 0 | return res; |
255 | 0 | } |
256 | | |
257 | | /// Add \a width columns to the end position. |
258 | | inline location |
259 | | operator+ (location res, location::counter_type width) |
260 | 0 | { |
261 | 0 | return res += width; |
262 | 0 | } |
263 | | |
264 | | /// Subtract \a width columns to the end position, in place. |
265 | | inline location& |
266 | | operator-= (location& res, location::counter_type width) |
267 | 0 | { |
268 | 0 | return res += -width; |
269 | 0 | } |
270 | | |
271 | | /// Subtract \a width columns to the end position. |
272 | | inline location |
273 | | operator- (location res, location::counter_type width) |
274 | 0 | { |
275 | 0 | return res -= width; |
276 | 0 | } |
277 | | |
278 | | /** \brief Intercept output stream redirection. |
279 | | ** \param ostr the destination output stream |
280 | | ** \param loc a reference to the location to redirect |
281 | | ** |
282 | | ** Avoid duplicate information. |
283 | | */ |
284 | | template <typename YYChar> |
285 | | std::basic_ostream<YYChar>& |
286 | | operator<< (std::basic_ostream<YYChar>& ostr, const location& loc) |
287 | 2.66k | { |
288 | 2.66k | location::counter_type end_col |
289 | 2.66k | = 0 < loc.end.column ? loc.end.column - 1 : 0; |
290 | 2.66k | ostr << loc.begin; |
291 | 2.66k | if (loc.end.filename |
292 | 2.66k | && (!loc.begin.filename |
293 | 2.66k | || *loc.begin.filename != *loc.end.filename)) |
294 | 0 | ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; |
295 | 2.66k | else if (loc.begin.line < loc.end.line) |
296 | 0 | ostr << '-' << loc.end.line << '.' << end_col; |
297 | 2.66k | else if (loc.begin.column < end_col) |
298 | 1.27k | ostr << '-' << end_col; |
299 | 2.66k | return ostr; |
300 | 2.66k | } |
301 | | |
302 | | #line 14 "agent_parser.yy" |
303 | | } } // isc::agent |
304 | | #line 305 "location.hh" |
305 | | |
306 | | #endif // !YY_AGENT_LOCATION_HH_INCLUDED |