Working Scanner
[obcplusplus.git] / parser / position.hh
blob3013e41838ba532014d1fc7e5a028c1c7b6171b3
1 /* A Bison parser, made by GNU Bison 2.4.3. */
3 /* Positions for Bison parsers in C++
5 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software
6 Foundation, Inc.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
34 /**
35 ** \file position.hh
36 ** Define the objectbuilder::position class.
39 #ifndef BISON_POSITION_HH
40 # define BISON_POSITION_HH
42 # include <iostream>
43 # include <string>
44 # include <algorithm>
47 namespace objectbuilder {
49 /* Line 38 of location.cc */
50 #line 51 "position.hh"
51 /// Abstract a position.
52 class position
54 public:
56 /// Construct a position.
57 position ()
58 : filename (0), line (1), column (1)
63 /// Initialization.
64 inline void initialize (std::string* fn)
66 filename = fn;
67 line = 1;
68 column = 1;
71 /** \name Line and Column related manipulators
72 ** \{ */
73 public:
74 /// (line related) Advance to the COUNT next lines.
75 inline void lines (int count = 1)
77 column = 1;
78 line += count;
81 /// (column related) Advance to the COUNT next columns.
82 inline void columns (int count = 1)
84 column = std::max (1u, column + count);
86 /** \} */
88 public:
89 /// File name to which this position refers.
90 std::string* filename;
91 /// Current line number.
92 unsigned int line;
93 /// Current column number.
94 unsigned int column;
97 /// Add and assign a position.
98 inline const position&
99 operator+= (position& res, const int width)
101 res.columns (width);
102 return res;
105 /// Add two position objects.
106 inline const position
107 operator+ (const position& begin, const int width)
109 position res = begin;
110 return res += width;
113 /// Add and assign a position.
114 inline const position&
115 operator-= (position& res, const int width)
117 return res += -width;
120 /// Add two position objects.
121 inline const position
122 operator- (const position& begin, const int width)
124 return begin + -width;
127 /// Compare two position objects.
128 inline bool
129 operator== (const position& pos1, const position& pos2)
131 return (pos1.line == pos2.line
132 && pos1.column == pos2.column
133 && (pos1.filename == pos2.filename
134 || (pos1.filename && pos2.filename
135 && *pos1.filename == *pos2.filename)));
138 /// Compare two position objects.
139 inline bool
140 operator!= (const position& pos1, const position& pos2)
142 return !(pos1 == pos2);
145 /** \brief Intercept output stream redirection.
146 ** \param ostr the destination output stream
147 ** \param pos a reference to the position to redirect
149 inline std::ostream&
150 operator<< (std::ostream& ostr, const position& pos)
152 if (pos.filename)
153 ostr << *pos.filename << ':';
154 return ostr << pos.line << '.' << pos.column;
158 } // objectbuilder
160 /* Line 145 of location.cc */
161 #line 162 "position.hh"
162 #endif // not BISON_POSITION_HH