]>
git.saurik.com Git - bison.git/blob - data/location.cc
3 # C++ skeleton for Bison
5 # Copyright (C) 2002, 2003, 2004, 2005 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 m4_include(b4_pkgdatadir
/[c
++.m4
])
24 # We do want M4 expansion after # for CPP macros.
27 @output b4_dir_prefix
[]position
.hh
28 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
32 ** Define the position class.
35 #ifndef BISON_POSITION_HH
36 # define BISON_POSITION_HH
43 /// Abstract a position.
46 /** \name Ctor & dtor.
49 /// Construct a position.
59 /** \name Line and Column related manipulators
62 /// (line related) Advance to the COUNT next lines.
63 inline void lines (int count
= 1)
69 /// (column related) Advance to the COUNT next columns.
70 inline void columns (int count
= 1)
74 if (leftmost
<= current
+ count
)
82 /// File name to which this position refers.
83 ]b4_filename_type
[* filename
;
84 /// Current line number.
86 /// Current column number.
90 /// Add and assign a position.
91 inline const position
&
92 operator+= (position
& res
, const int width
)
98 /// Add two position objects.
100 operator+ (const position
& begin
, const int width
)
102 position res
= begin
;
106 /// Add and assign a position.
107 inline const position
&
108 operator-= (position
& res
, const int width
)
110 return res
+= -width
;
113 /// Add two position objects.
114 inline const position
115 operator- (const position
& begin
, const int width
)
117 return begin
+ -width
;
120 /** \brief Intercept output stream redirection.
121 ** \param ostr the destination output stream
122 ** \param pos a reference to the position to redirect
125 operator<< (std::ostream
& ostr
, const position
& pos
)
128 ostr
<< *pos
.filename
<< ':';
129 return ostr
<< pos
.line
<< '.' << pos
.column
;
133 #endif // not BISON_POSITION_HH]
134 @output b4_dir_prefix
[]location
.hh
135 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
139 ** Define the location class.
142 #ifndef BISON_LOCATION_HH
143 # define BISON_LOCATION_HH
147 # include "position.hh"
152 /// Abstract a location.
155 /** \name Ctor & dtor.
158 /// Construct a location.
167 /** \name Line and Column related manipulators
170 /// Reset initial location to final location.
176 /// Extend the current location to the COUNT next columns.
177 inline void columns (unsigned int count
= 1)
182 /// Extend the current location to the COUNT next lines.
183 inline void lines (unsigned int count
= 1)
191 /// Beginning of the located region.
193 /// End of the located region.
197 /// Join two location objects to create a location.
198 inline const location
operator+ (const location
& begin
, const location
& end
)
200 location res
= begin
;
205 /// Add two location objects.
206 inline const location
operator+ (const location
& begin
, unsigned int width
)
208 location res
= begin
;
213 /// Add and assign a location.
214 inline location
& operator+= (location
& res
, unsigned int width
)
220 /** \brief Intercept output stream redirection.
221 ** \param ostr the destination output stream
222 ** \param loc a reference to the location to redirect
224 ** Avoid duplicate information.
226 inline std::ostream
& operator<< (std::ostream
& ostr
, const location
& loc
)
228 position last
= loc
.end
- 1;
231 && (!loc
.begin
.filename
232 || *loc
.begin
.filename
!= *last
.filename
))
234 else if (loc
.begin
.line
!= last
.line
)
235 ostr
<< '-' << last
.line
<< '.' << last
.column
;
236 else if (loc
.begin
.column
!= last
.column
)
237 ostr
<< '-' << last
.column
;
243 #endif // not BISON_LOCATION_HH]