Line data Source code
1 : // A Bison parser, made by GNU Bison 3.0.4.
2 :
3 : // Positions for Bison parsers in C++
4 :
5 : // Copyright (C) 2002-2015 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 :
33 : /**
34 : ** \file position.hh
35 : ** Define the gspn::position class.
36 : */
37 :
38 : #ifndef YY_GSPN_POSITION_HH_INCLUDED
39 : # define YY_GSPN_POSITION_HH_INCLUDED
40 :
41 : # include <algorithm> // std::max
42 : # include <iostream>
43 : # include <string>
44 :
45 : # ifndef YY_NULLPTR
46 : # if defined __cplusplus && 201103L <= __cplusplus
47 : # define YY_NULLPTR nullptr
48 : # else
49 : # define YY_NULLPTR 0
50 : # endif
51 : # endif
52 :
53 :
54 : namespace gspn {
55 : #line 56 "position.hh" // location.cc:296
56 : /// Abstract a position.
57 : class position
58 : {
59 : public:
60 : /// Construct a position.
61 7040 : explicit position (std::string* f = YY_NULLPTR,
62 : unsigned int l = 1u,
63 : unsigned int c = 1u)
64 7040 : : filename (f)
65 : , line (l)
66 7040 : , column (c)
67 : {
68 7040 : }
69 :
70 :
71 : /// Initialization.
72 : void initialize (std::string* fn = YY_NULLPTR,
73 : unsigned int l = 1u,
74 : unsigned int c = 1u)
75 : {
76 : filename = fn;
77 : line = l;
78 : column = c;
79 : }
80 :
81 : /** \name Line and Column related manipulators
82 : ** \{ */
83 : /// (line related) Advance to the COUNT next lines.
84 443 : void lines (int count = 1)
85 : {
86 443 : if (count)
87 : {
88 443 : column = 1u;
89 443 : line = add_ (line, count, 1);
90 : }
91 443 : }
92 :
93 : /// (column related) Advance to the COUNT next columns.
94 : void columns (int count = 1)
95 : {
96 : column = add_ (column, count, 1);
97 : }
98 : /** \} */
99 :
100 : /// File name to which this position refers.
101 : std::string* filename;
102 : /// Current line number.
103 : unsigned int line;
104 : /// Current column number.
105 : unsigned int column;
106 :
107 : private:
108 : /// Compute max(min, lhs+rhs) (provided min <= lhs).
109 443 : static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
110 : {
111 0 : return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
112 886 : ? rhs + lhs
113 443 : : min);
114 : }
115 : };
116 :
117 : /// Add \a width columns, in place.
118 : inline position&
119 : operator+= (position& res, int width)
120 : {
121 : res.columns (width);
122 : return res;
123 : }
124 :
125 : /// Add \a width columns.
126 : inline position
127 : operator+ (position res, int width)
128 : {
129 : return res += width;
130 : }
131 :
132 : /// Subtract \a width columns, in place.
133 : inline position&
134 : operator-= (position& res, int width)
135 : {
136 : return res += -width;
137 : }
138 :
139 : /// Subtract \a width columns.
140 : inline position
141 : operator- (position res, int width)
142 : {
143 : return res -= width;
144 : }
145 :
146 : /// Compare two position objects.
147 : inline bool
148 : operator== (const position& pos1, const position& pos2)
149 : {
150 : return (pos1.line == pos2.line
151 : && pos1.column == pos2.column
152 : && (pos1.filename == pos2.filename
153 : || (pos1.filename && pos2.filename
154 : && *pos1.filename == *pos2.filename)));
155 : }
156 :
157 : /// Compare two position objects.
158 : inline bool
159 : operator!= (const position& pos1, const position& pos2)
160 : {
161 : return !(pos1 == pos2);
162 : }
163 :
164 : /** \brief Intercept output stream redirection.
165 : ** \param ostr the destination output stream
166 : ** \param pos a reference to the position to redirect
167 : */
168 : template <typename YYChar>
169 : inline std::basic_ostream<YYChar>&
170 0 : operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
171 : {
172 0 : if (pos.filename)
173 0 : ostr << *pos.filename << ':';
174 0 : return ostr << pos.line << '.' << pos.column;
175 : }
176 :
177 :
178 : } // gspn
179 : #line 180 "position.hh" // location.cc:296
180 : #endif // !YY_GSPN_POSITION_HH_INCLUDED
|