QJson home page
location.hh
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.7. */
2 
3 /* Locations for Bison parsers in C++
4 
5  Copyright (C) 2002-2007, 2009-2012 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_LOCATION_HH_INCLUDED
39 # define YY_YY_LOCATION_HH_INCLUDED
40 
41 # include "position.hh"
42 
43 
44 namespace yy {
45 /* Line 166 of location.cc */
46 #line 47 "location.hh"
47 
49  class location
50  {
51  public:
52 
54  location (const position& b, const position& e)
55  : begin (b)
56  , end (e)
57  {
58  }
59 
61  explicit location (const position& p = position ())
62  : begin (p)
63  , end (p)
64  {
65  }
66 
68  explicit location (std::string* f,
69  unsigned int l = 1u,
70  unsigned int c = 1u)
71  : begin (f, l, c)
72  , end (f, l, c)
73  {
74  }
75 
76 
78  void initialize (std::string* f = YY_NULL,
79  unsigned int l = 1u,
80  unsigned int c = 1u)
81  {
82  begin.initialize (f, l, c);
83  end = begin;
84  }
85 
88  public:
90  void step ()
91  {
92  begin = end;
93  }
94 
96  void columns (unsigned int count = 1)
97  {
98  end += count;
99  }
100 
102  void lines (unsigned int count = 1)
103  {
104  end.lines (count);
105  }
109  public:
114  };
115 
117  inline const location operator+ (const location& begin, const location& end)
118  {
119  location res = begin;
120  res.end = end.end;
121  return res;
122  }
123 
125  inline const location operator+ (const location& begin, unsigned int width)
126  {
127  location res = begin;
128  res.columns (width);
129  return res;
130  }
131 
133  inline location& operator+= (location& res, unsigned int width)
134  {
135  res.columns (width);
136  return res;
137  }
138 
140  inline bool
141  operator== (const location& loc1, const location& loc2)
142  {
143  return loc1.begin == loc2.begin && loc1.end == loc2.end;
144  }
145 
147  inline bool
148  operator!= (const location& loc1, const location& loc2)
149  {
150  return !(loc1 == loc2);
151  }
152 
159  template <typename YYChar>
160  inline std::basic_ostream<YYChar>&
161  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
162  {
163  position last = loc.end - 1;
164  ostr << loc.begin;
165  if (last.filename
166  && (!loc.begin.filename
167  || *loc.begin.filename != *last.filename))
168  ostr << '-' << last;
169  else if (loc.begin.line != last.line)
170  ostr << '-' << last.line << '.' << last.column;
171  else if (loc.begin.column != last.column)
172  ostr << '-' << last.column;
173  return ostr;
174  }
175 
176 
177 } // yy
178 /* Line 296 of location.cc */
179 #line 180 "location.hh"
180 
181 #endif /* !YY_YY_LOCATION_HH_INCLUDED */
Abstract a position.
Definition: position.hh:58
void initialize(std::string *fn=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: position.hh:74
void columns(unsigned int count=1)
Extend the current location to the COUNT next columns.
Definition: location.hh:96
unsigned int column
Current column number.
Definition: position.hh:104
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:86
location(std::string *f, unsigned int l=1u, unsigned int c=1u)
Construct a 0-width location in f, l, c.
Definition: location.hh:68
position begin
Beginning of the located region.
Definition: location.hh:111
position end
End of the located region.
Definition: location.hh:113
void lines(unsigned int count=1)
Extend the current location to the COUNT next lines.
Definition: location.hh:102
void step()
Reset initial location to final location.
Definition: location.hh:90
Abstract a location.
Definition: location.hh:49
location(const position &p=position())
Construct a 0-width location in p.
Definition: location.hh:61
location(const position &b, const position &e)
Construct a location from b to e.
Definition: location.hh:54
void initialize(std::string *f=YY_NULL, unsigned int l=1u, unsigned int c=1u)
Initialization.
Definition: location.hh:78
unsigned int line
Current line number.
Definition: position.hh:102
std::string * filename
File name to which this position refers.
Definition: position.hh:100

SourceForge Logo hosts this site. Send comments to:
QJson Developers