ztsdb
location.hh
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 
38 #ifndef YY_CFGYY_HOME_LSILVEST_REPOS_ZTSDB_GITHUB_SRC_CONFIG_PARSER_LOCATION_HH_INCLUDED
39 # define YY_CFGYY_HOME_LSILVEST_REPOS_ZTSDB_GITHUB_SRC_CONFIG_PARSER_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 
56 namespace cfgyy {
57 #line 58 "/home/lsilvest/repos/ztsdb_github/src/config_parser/location.hh"
58 
60  class position
61  {
62  public:
64  typedef int counter_type;
65 
67  explicit position (std::string* f = YY_NULLPTR,
68  counter_type l = 1,
69  counter_type c = 1)
70  : filename (f)
71  , line (l)
72  , column (c)
73  {}
74 
75 
77  void initialize (std::string* fn = YY_NULLPTR,
78  counter_type l = 1,
79  counter_type c = 1)
80  {
81  filename = fn;
82  line = l;
83  column = c;
84  }
85 
88  void lines (counter_type count = 1)
90  {
91  if (count)
92  {
93  column = 1;
94  line = add_ (line, count, 1);
95  }
96  }
97 
99  void columns (counter_type count = 1)
100  {
101  column = add_ (column, count, 1);
102  }
105  std::string* filename;
111 
112  private:
114  static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min)
115  {
116  return lhs + rhs < min ? min : lhs + rhs;
117  }
118  };
119 
121  inline position&
122  operator+= (position& res, position::counter_type width)
123  {
124  res.columns (width);
125  return res;
126  }
127 
129  inline position
130  operator+ (position res, position::counter_type width)
131  {
132  return res += width;
133  }
134 
136  inline position&
137  operator-= (position& res, position::counter_type width)
138  {
139  return res += -width;
140  }
141 
143  inline position
144  operator- (position res, position::counter_type width)
145  {
146  return res -= width;
147  }
148 
150  inline bool
151  operator== (const position& pos1, const position& pos2)
152  {
153  return (pos1.line == pos2.line
154  && pos1.column == pos2.column
155  && (pos1.filename == pos2.filename
156  || (pos1.filename && pos2.filename
157  && *pos1.filename == *pos2.filename)));
158  }
159 
161  inline bool
162  operator!= (const position& pos1, const position& pos2)
163  {
164  return !(pos1 == pos2);
165  }
166 
171  template <typename YYChar>
172  std::basic_ostream<YYChar>&
173  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
174  {
175  if (pos.filename)
176  ostr << *pos.filename << ':';
177  return ostr << pos.line << '.' << pos.column;
178  }
179 
181  class location
182  {
183  public:
186 
188  location (const position& b, const position& e)
189  : begin (b)
190  , end (e)
191  {}
192 
194  explicit location (const position& p = position ())
195  : begin (p)
196  , end (p)
197  {}
198 
200  explicit location (std::string* f,
201  counter_type l = 1,
202  counter_type c = 1)
203  : begin (f, l, c)
204  , end (f, l, c)
205  {}
206 
207 
209  void initialize (std::string* f = YY_NULLPTR,
210  counter_type l = 1,
211  counter_type c = 1)
212  {
213  begin.initialize (f, l, c);
214  end = begin;
215  }
216 
219  public:
221  void step ()
222  {
223  begin = end;
224  }
225 
227  void columns (counter_type count = 1)
228  {
229  end += count;
230  }
231 
233  void lines (counter_type count = 1)
234  {
235  end.lines (count);
236  }
240  public:
245  };
246 
248  inline location&
249  operator+= (location& res, const location& end)
250  {
251  res.end = end.end;
252  return res;
253  }
254 
256  inline location
257  operator+ (location res, const location& end)
258  {
259  return res += end;
260  }
261 
263  inline location&
264  operator+= (location& res, location::counter_type width)
265  {
266  res.columns (width);
267  return res;
268  }
269 
271  inline location
272  operator+ (location res, location::counter_type width)
273  {
274  return res += width;
275  }
276 
278  inline location&
279  operator-= (location& res, location::counter_type width)
280  {
281  return res += -width;
282  }
283 
285  inline location
286  operator- (location res, location::counter_type width)
287  {
288  return res -= width;
289  }
290 
292  inline bool
293  operator== (const location& loc1, const location& loc2)
294  {
295  return loc1.begin == loc2.begin && loc1.end == loc2.end;
296  }
297 
299  inline bool
300  operator!= (const location& loc1, const location& loc2)
301  {
302  return !(loc1 == loc2);
303  }
304 
311  template <typename YYChar>
312  std::basic_ostream<YYChar>&
313  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
314  {
315  location::counter_type end_col
316  = 0 < loc.end.column ? loc.end.column - 1 : 0;
317  ostr << loc.begin;
318  if (loc.end.filename
319  && (!loc.begin.filename
320  || *loc.begin.filename != *loc.end.filename))
321  ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
322  else if (loc.begin.line < loc.end.line)
323  ostr << '-' << loc.end.line << '.' << end_col;
324  else if (loc.begin.column < end_col)
325  ostr << '-' << end_col;
326  return ostr;
327  }
328 
329 } // cfgyy
330 #line 331 "/home/lsilvest/repos/ztsdb_github/src/config_parser/location.hh"
331 
332 #endif // !YY_CFGYY_HOME_LSILVEST_REPOS_ZTSDB_GITHUB_SRC_CONFIG_PARSER_LOCATION_HH_INCLUDED
cfgyy::position::initialize
void initialize(std::string *fn=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition: location.hh:77
cfgyy::location::step
void step()
Reset initial location to final location.
Definition: location.hh:221
cfgyy::position::position
position(std::string *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Construct a position.
Definition: location.hh:67
cfgyy::location::initialize
void initialize(std::string *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition: location.hh:209
cfgyy::location::end
position end
End of the located region.
Definition: location.hh:244
cfgyy::position::counter_type
int counter_type
Type for line and column numbers.
Definition: location.hh:64
cfgyy::location::begin
position begin
Beginning of the located region.
Definition: location.hh:242
cfgyy::position::line
counter_type line
Current line number.
Definition: location.hh:108
cfgyy::position
A point in a source file.
Definition: location.hh:60
cfgyy::position::columns
void columns(counter_type count=1)
(column related) Advance to the COUNT next columns.
Definition: location.hh:99
cfgyy::location::location
location(const position &b, const position &e)
Construct a location from b to e.
Definition: location.hh:188
cfgyy::position::filename
std::string * filename
File name to which this position refers.
Definition: location.hh:106
cfgyy::location::location
location(std::string *f, counter_type l=1, counter_type c=1)
Construct a 0-width location in f, l, c.
Definition: location.hh:200
cfgyy::location::columns
void columns(counter_type count=1)
Extend the current location to the COUNT next columns.
Definition: location.hh:227
cfgyy::location::location
location(const position &p=position())
Construct a 0-width location in p.
Definition: location.hh:194
cfgyy::position::column
counter_type column
Current column number.
Definition: location.hh:110
cfgyy::location
Two points in a source file.
Definition: location.hh:181
cfgyy::location::counter_type
position::counter_type counter_type
Type for line and column numbers.
Definition: location.hh:185
cfgyy::position::lines
void lines(counter_type count=1)
(line related) Advance to the COUNT next lines.
Definition: location.hh:89
cfgyy::location::lines
void lines(counter_type count=1)
Extend the current location to the COUNT next lines.
Definition: location.hh:233