Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
location.hh
Go to the documentation of this file.
1 // A Bison parser, made by GNU Bison 3.0.2.13-aa0e.
2 
3 // Locations for Bison parsers in C++
4 
5 // Copyright (C) 2002-2013 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_VAUCANSON2_LIB_VCSN_RAT_LOCATION_HH_INCLUDED
39 # define YY_YY_USERS_AKIM_SRC_LRDE_VAUCANSON2_LIB_VCSN_RAT_LOCATION_HH_INCLUDED
40 
41 # include "position.hh"
42 
43 #line 11 "/Users/akim/src/lrde/vaucanson2/lib/vcsn/rat/parse.yy" // location.cc:291
44 namespace vcsn { namespace rat {
45 #line 46 "/Users/akim/src/lrde/vaucanson2/lib/vcsn/rat/location.hh" // location.cc:291
46  class location
48  {
49  public:
50 
52  location (const position& b, const position& e)
53  : begin (b)
54  , end (e)
55  {
56  }
57 
59  explicit location (const position& p = position ())
60  : begin (p)
61  , end (p)
62  {
63  }
64 
66  explicit location (std::string* f,
67  unsigned int l = 1u,
68  unsigned int c = 1u)
69  : begin (f, l, c)
70  , end (f, l, c)
71  {
72  }
73 
74 
76  void initialize (std::string* f = YY_NULLPTR,
77  unsigned int l = 1u,
78  unsigned int c = 1u)
79  {
80  begin.initialize (f, l, c);
81  end = begin;
82  }
83 
86  public:
88  void step ()
89  {
90  begin = end;
91  }
92 
94  void columns (int count = 1)
95  {
96  end += count;
97  }
98 
100  void lines (int count = 1)
101  {
102  end.lines (count);
103  }
107  public:
112  };
113 
115  inline location operator+ (location res, const location& end)
116  {
117  res.end = end.end;
118  return res;
119  }
120 
122  inline location& operator+= (location& res, int width)
123  {
124  res.columns (width);
125  return res;
126  }
127 
129  inline location operator+ (location res, int width)
130  {
131  return res += width;
132  }
133 
135  inline location& operator-= (location& res, int width)
136  {
137  return res += -width;
138  }
139 
141  inline location operator- (const location& begin, int width)
142  {
143  return begin + -width;
144  }
145 
147  inline bool
148  operator== (const location& loc1, const location& loc2)
149  {
150  return loc1.begin == loc2.begin && loc1.end == loc2.end;
151  }
152 
154  inline bool
155  operator!= (const location& loc1, const location& loc2)
156  {
157  return !(loc1 == loc2);
158  }
159 
166  template <typename YYChar>
167  inline std::basic_ostream<YYChar>&
168  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
169  {
170  unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
171  ostr << loc.begin// << "(" << loc.end << ") "
172 ;
173  if (loc.end.filename
174  && (!loc.begin.filename
175  || *loc.begin.filename != *loc.end.filename))
176  ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
177  else if (loc.begin.line < loc.end.line)
178  ostr << '-' << loc.end.line << '.' << end_col;
179  else if (loc.begin.column < end_col)
180  ostr << '-' << end_col;
181  return ostr;
182  }
183 
184 #line 11 "/Users/akim/src/lrde/vaucanson2/lib/vcsn/rat/parse.yy" // location.cc:291
185 } } // vcsn::rat
186 #line 187 "/Users/akim/src/lrde/vaucanson2/lib/vcsn/rat/location.hh" // location.cc:291
187 #endif // !YY_YY_USERS_AKIM_SRC_LRDE_VAUCANSON2_LIB_VCSN_RAT_LOCATION_HH_INCLUDED
location(std::string *f, unsigned int l=1u, unsigned int c=1u)
Construct a 0-width location in f, l, c.
Definition: location.hh:66
void lines(int count=1)
Extend the current location to the COUNT next lines.
Definition: location.hh:100
location(const position &p=position())
Construct a 0-width location in p.
Definition: location.hh:59
Define the vcsn::rat::position class.
position begin
Beginning of the located region.
Definition: location.hh:109
unsigned int column
Current column number.
Definition: position.hh:105
#define YY_NULLPTR
Definition: parse.cc:60
location & operator+=(location &res, int width)
Change end position in place.
Definition: location.hh:122
location(const position &b, const position &e)
Construct a location from b to e.
Definition: location.hh:52
void step()
Reset initial location to final location.
Definition: location.hh:88
vcsn::rat::location location
Definition: scan.hh:18
location operator-(const location &begin, int width)
Change end position.
Definition: location.hh:141
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:84
bool operator!=(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:155
Abstract a location.
Definition: location.hh:47
location & operator-=(location &res, int width)
Change end position in place.
Definition: location.hh:135
bool operator==(const location &loc1, const location &loc2)
Compare two location objects.
Definition: location.hh:148
Abstract a position.
Definition: position.hh:57
position end
End of the located region.
Definition: location.hh:111
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
void initialize(std::string *fn=0, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: position.hh:72
mutable_automaton< Context > u(const Context &ctx, unsigned n)
The Brzozowski universal witness.
Definition: u.hh:17
void columns(int count=1)
Extend the current location to the COUNT next columns.
Definition: location.hh:94
location operator+(location res, const location &end)
Join two location objects to create a location.
Definition: location.hh:115
void initialize(std::string *f=0, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: location.hh:76