]>
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.
47 /// Initial column number.
48 static const unsigned int initial_column
= 0;
49 /// Initial line number.
50 static const unsigned int initial_line
= 1;
52 /** \name Ctor & dtor.
55 /// Construct a position.
59 column (initial_column
)
65 /** \name Line and Column related manipulators
68 /// (line related) Advance to the COUNT next lines.
69 inline void lines (int count
= 1)
71 column
= initial_column
;
75 /// (column related) Advance to the COUNT next columns.
76 inline void columns (int count
= 1)
78 int leftmost
= initial_column
;
80 if (leftmost
<= current
+ count
)
83 column
= initial_column
;
88 /// File name to which this position refers.
89 ]b4_filename_type
[* filename
;
90 /// Current line number.
92 /// Current column number.
96 /// Add and assign a position.
97 inline const position
&
98 operator+= (position
& res
, const int width
)
104 /// Add two position objects.
105 inline const position
106 operator+ (const position
& begin
, const int width
)
108 position res
= begin
;
112 /// Add and assign a position.
113 inline const position
&
114 operator-= (position
& res
, const int width
)
116 return res
+= -width
;
119 /// Add two position objects.
120 inline const position
121 operator- (const position
& begin
, const int width
)
123 return begin
+ -width
;
126 /** \brief Intercept output stream redirection.
127 ** \param ostr the destination output stream
128 ** \param pos a reference to the position to redirect
131 operator<< (std::ostream
& ostr
, const position
& pos
)
134 ostr
<< *pos
.filename
<< ':';
135 return ostr
<< pos
.line
<< '.' << pos
.column
;
139 #endif // not BISON_POSITION_HH]
140 @output b4_dir_prefix
[]location
.hh
141 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003, 2004, 2005])[
145 ** Define the location class.
148 #ifndef BISON_LOCATION_HH
149 # define BISON_LOCATION_HH
153 # include "position.hh"
158 /// Abstract a location.
161 /** \name Ctor & dtor.
164 /// Construct a location.
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]