]>
git.saurik.com Git - bison.git/blob - data/location.cc
3 # C++ skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
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 2 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # We do want M4 expansion after # for CPP macros.
25 @output b4_dir_prefix
[]position
.hh
26 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
30 ** Define the yy::position class.
33 #ifndef BISON_POSITION_HH
34 # define BISON_POSITION_HH
41 /// Abstract a position.
45 ]m4_ifdef([b4_location_constructors
], [
46 /// Construct a position.
48 : filename (0), line (1), column (0)
54 inline void initialize (]b4_filename_type
[* fn
)
61 /** \name Line and Column related manipulators
64 /// (line related) Advance to the COUNT next lines.
65 inline void lines (int count
= 1)
71 /// (column related) Advance to the COUNT next columns.
72 inline void columns (int count
= 1)
76 if (leftmost
<= current
+ count
)
84 /// File name to which this position refers.
85 ]b4_filename_type
[* filename
;
86 /// Current line number.
88 /// Current column number.
92 /// Add and assign a position.
93 inline const position
&
94 operator+= (position
& res
, const int width
)
100 /// Add two position objects.
101 inline const position
102 operator+ (const position
& begin
, const int width
)
104 position res
= begin
;
108 /// Add and assign a position.
109 inline const position
&
110 operator-= (position
& res
, const int width
)
112 return res
+= -width
;
115 /// Add two position objects.
116 inline const position
117 operator- (const position
& begin
, const int width
)
119 return begin
+ -width
;
122 /** \brief Intercept output stream redirection.
123 ** \param ostr the destination output stream
124 ** \param pos a reference to the position to redirect
127 operator<< (std::ostream
& ostr
, const position
& pos
)
130 ostr
<< *pos
.filename
<< ':';
131 return ostr
<< pos
.line
<< '.' << pos
.column
;
135 #endif // not BISON_POSITION_HH]
136 @output b4_dir_prefix
[]location
.hh
137 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
141 ** Define the yy::location class.
144 #ifndef BISON_LOCATION_HH
145 # define BISON_LOCATION_HH
149 # include "position.hh"
154 /// Abstract a location.
158 ]m4_ifdef([b4_location_constructors
], [
159 /// Construct a location.
167 inline void initialize (]b4_filename_type
[* fn
)
169 begin
.initialize (fn
);
173 /** \name Line and Column related manipulators
176 /// Reset initial location to final location.
182 /// Extend the current location to the COUNT next columns.
183 inline void columns (unsigned int count
= 1)
188 /// Extend the current location to the COUNT next lines.
189 inline void lines (unsigned int count
= 1)
197 /// Beginning of the located region.
199 /// End of the located region.
203 /// Join two location objects to create a location.
204 inline const location
operator+ (const location
& begin
, const location
& end
)
206 location res
= begin
;
211 /// Add two location objects.
212 inline const location
operator+ (const location
& begin
, unsigned int width
)
214 location res
= begin
;
219 /// Add and assign a location.
220 inline location
& operator+= (location
& res
, unsigned int width
)
226 /** \brief Intercept output stream redirection.
227 ** \param ostr the destination output stream
228 ** \param loc a reference to the location to redirect
230 ** Avoid duplicate information.
232 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
234 position last
= loc
.end
- 1;
237 && (!loc
.begin
.filename
238 || *loc
.begin
.filename
!= *last
.filename
))
240 else if (loc
.begin
.line
!= last
.line
)
241 ostr
<< '-' << last
.line
<< '.' << last
.column
;
242 else if (loc
.begin
.column
!= last
.column
)
243 ostr
<< '-' << last
.column
;
249 #endif // not BISON_LOCATION_HH]