Vcsn  2.3
Be Rational
position.hh
Go to the documentation of this file.
1 // A Bison parser, made by GNU Bison 3.0.4.19-fbaf-dirty.
2 
3 // Positions for Bison parsers in C++
4 
5 // Copyright (C) 2002-2015 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_YY_USERS_AKIM_SRC_LRDE_2_LIB_VCSN_RAT_POSITION_HH_INCLUDED
39 # define YY_YY_USERS_AKIM_SRC_LRDE_2_LIB_VCSN_RAT_POSITION_HH_INCLUDED
40 
41 # include <algorithm> // std::max
42 # include <iostream>
43 # include <string>
44 
45 # ifndef YY_NULLPTR
46 # if defined __cplusplus && 201103L <= __cplusplus
47 # define YY_NULLPTR nullptr
48 # else
49 # define YY_NULLPTR 0
50 # endif
51 # endif
52 
53 #line 11 "/Users/akim/src/lrde/2/lib/vcsn/rat/parse.yy" // location.cc:296
54 namespace vcsn { namespace rat {
55 #line 56 "/Users/akim/src/lrde/2/lib/vcsn/rat/position.hh" // location.cc:296
56  class position
58  {
59  public:
61  explicit position (std::string* f = YY_NULLPTR,
62  unsigned int l = 1u,
63  unsigned int c = 1u)
64  : filename (f)
65  , line (l)
66  , column (c)
67  {
68  }
69 
70 
72  void initialize (std::string* fn = YY_NULLPTR,
73  unsigned int l = 1u,
74  unsigned int c = 1u)
75  {
76  filename = fn;
77  line = l;
78  column = c;
79  }
80 
83  void lines (int count = 1)
85  {
86  if (count)
87  {
88  column = 1u;
89  line = add_ (line, count, 1);
90  }
91  }
92 
94  void columns (int count = 1)
95  {
96  column = add_ (column, count, 1);
97  }
100  std::string* filename;
103  unsigned int line;
105  unsigned int column;
106 
107  private:
109  static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
110  {
111  return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
112  ? rhs + lhs
113  : min);
114  }
115  };
116 
118  inline position&
119  operator+= (position& res, int width)
120  {
121  res.columns (width);
122  return res;
123  }
124 
126  inline position
127  operator+ (position res, int width)
128  {
129  return res += width;
130  }
131 
133  inline position&
134  operator-= (position& res, int width)
135  {
136  return res += -width;
137  }
138 
140  inline position
141  operator- (position res, int width)
142  {
143  return res -= width;
144  }
145 
147  inline bool
148  operator== (const position& pos1, const position& pos2)
149  {
150  return (pos1.line == pos2.line
151  && pos1.column == pos2.column
152  && (pos1.filename == pos2.filename
153  || (pos1.filename && pos2.filename
154  && *pos1.filename == *pos2.filename)));
155  }
156 
158  inline bool
159  operator!= (const position& pos1, const position& pos2)
160  {
161  return !(pos1 == pos2);
162  }
163 
168  template <typename YYChar>
169  inline std::basic_ostream<YYChar>&
170  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
171  {
172  if (pos.filename)
173  ostr << *pos.filename << ':';
174  return ostr << pos.line << '.' << pos.column;
175  }
176 
177 #line 11 "/Users/akim/src/lrde/2/lib/vcsn/rat/parse.yy" // location.cc:296
178 } } // vcsn::rat
179 #line 180 "/Users/akim/src/lrde/2/lib/vcsn/rat/position.hh" // location.cc:296
180 #endif // !YY_YY_USERS_AKIM_SRC_LRDE_2_LIB_VCSN_RAT_POSITION_HH_INCLUDED
bool operator!=(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:161
location & operator-=(location &res, int width)
Subtract width columns to the end position, in place.
Definition: location.hh:141
std::string * filename
File name to which this position refers.
Definition: position.hh:101
position(std::string *f=0, unsigned int l=1u, unsigned int c=1u)
Construct a position.
Definition: position.hh:61
location operator-(location res, int width)
Subtract width columns to the end position.
Definition: location.hh:147
unsigned int line
Current line number.
Definition: position.hh:103
mutable_automaton< Context > u(const Context &ctx, unsigned n)
The Brzozowski universal witness.
Definition: u.hh:15
void columns(int count=1)
(column related) Advance to the COUNT next columns.
Definition: position.hh:94
bool operator==(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:154
location operator+(location res, const location &end)
Join two locations.
Definition: location.hh:122
return res
Definition: multiply.hh:398
#define YY_NULLPTR
Definition: position.hh:49
Definition: a-star.hh:8
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:84
location & operator+=(location &res, const location &end)
Join two locations, in place.
Definition: location.hh:115
static unsigned int add_(unsigned int lhs, int rhs, unsigned int min)
Compute max(min, lhs+rhs) (provided min <= lhs).
Definition: position.hh:109
return exp min
Definition: multiply.hh:361
unsigned int column
Current column number.
Definition: position.hh:105
void initialize(std::string *fn=0, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: position.hh:72
Abstract a position.
Definition: position.hh:57