Line data Source code
1 : // A Bison parser, made by GNU Bison 3.0.4.
2 :
3 : // Locations 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 location.hh
35 : ** Define the eval::location class.
36 : */
37 :
38 : #ifndef YY_EVAL_LOCATION_HH_INCLUDED
39 : # define YY_EVAL_LOCATION_HH_INCLUDED
40 :
41 : # include "position.hh"
42 :
43 :
44 : namespace eval {
45 : #line 46 "location.hh" // location.cc:296
46 : /// Abstract a location.
47 : class location
48 : {
49 : public:
50 :
51 : /// Construct a location from \a b to \a e.
52 : location (const position& b, const position& e)
53 : : begin (b)
54 : , end (e)
55 : {
56 : }
57 :
58 : /// Construct a 0-width location in \a p.
59 5810 : explicit location (const position& p = position ())
60 5810 : : begin (p)
61 5810 : , end (p)
62 : {
63 5810 : }
64 :
65 : /// Construct a 0-width location in \a f, \a l, \a c.
66 : explicit location (std::string* f,
67 : unsigned int l = 1u,
68 : unsigned int c = 1u)
69 : : begin (f, l, c)
70 : , end (f, l, c)
71 : {
72 : }
73 :
74 :
75 : /// Initialization.
76 : void initialize (std::string* f = YY_NULLPTR,
77 : unsigned int l = 1u,
78 : unsigned int c = 1u)
79 : {
80 : begin.initialize (f, l, c);
81 : end = begin;
82 : }
83 :
84 : /** \name Line and Column related manipulators
85 : ** \{ */
86 : public:
87 : /// Reset initial location to final location.
88 1094 : void step ()
89 : {
90 1094 : begin = end;
91 1094 : }
92 :
93 : /// Extend the current location to the COUNT next columns.
94 : void columns (int count = 1)
95 : {
96 : end += count;
97 : }
98 :
99 : /// Extend the current location to the COUNT next lines.
100 0 : void lines (int count = 1)
101 : {
102 0 : end.lines (count);
103 0 : }
104 : /** \} */
105 :
106 :
107 : public:
108 : /// Beginning of the located region.
109 : position begin;
110 : /// End of the located region.
111 : position end;
112 : };
113 :
114 : /// Join two locations, in place.
115 : inline location& operator+= (location& res, const location& end)
116 : {
117 : res.end = end.end;
118 : return res;
119 : }
120 :
121 : /// Join two locations.
122 : inline location operator+ (location res, const location& end)
123 : {
124 : return res += end;
125 : }
126 :
127 : /// Add \a width columns to the end position, in place.
128 : inline location& operator+= (location& res, int width)
129 : {
130 : res.columns (width);
131 : return res;
132 : }
133 :
134 : /// Add \a width columns to the end position.
135 : inline location operator+ (location res, int width)
136 : {
137 : return res += width;
138 : }
139 :
140 : /// Subtract \a width columns to the end position, in place.
141 : inline location& operator-= (location& res, int width)
142 : {
143 : return res += -width;
144 : }
145 :
146 : /// Subtract \a width columns to the end position.
147 : inline location operator- (location res, int width)
148 : {
149 : return res -= width;
150 : }
151 :
152 : /// Compare two location objects.
153 : inline bool
154 : operator== (const location& loc1, const location& loc2)
155 : {
156 : return loc1.begin == loc2.begin && loc1.end == loc2.end;
157 : }
158 :
159 : /// Compare two location objects.
160 : inline bool
161 : operator!= (const location& loc1, const location& loc2)
162 : {
163 : return !(loc1 == loc2);
164 : }
165 :
166 : /** \brief Intercept output stream redirection.
167 : ** \param ostr the destination output stream
168 : ** \param loc a reference to the location to redirect
169 : **
170 : ** Avoid duplicate information.
171 : */
172 : template <typename YYChar>
173 : inline std::basic_ostream<YYChar>&
174 10 : operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
175 : {
176 10 : unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
177 10 : ostr << loc.begin;
178 20 : if (loc.end.filename
179 10 : && (!loc.begin.filename
180 0 : || *loc.begin.filename != *loc.end.filename))
181 0 : ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
182 10 : else if (loc.begin.line < loc.end.line)
183 0 : ostr << '-' << loc.end.line << '.' << end_col;
184 10 : else if (loc.begin.column < end_col)
185 0 : ostr << '-' << end_col;
186 10 : return ostr;
187 : }
188 :
189 :
190 : } // eval
191 : #line 192 "location.hh" // location.cc:296
192 : #endif // !YY_EVAL_LOCATION_HH_INCLUDED
|