Debian Codegraph @

packages/seacas/libraries/aprepro_lib/location.hh

raw
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 SEAMS::location class.
36 */
37
38 #ifndef YY_SEAMS_LOCATION_HH_INCLUDED
39 # define YY_SEAMS_LOCATION_HH_INCLUDED
40
41 # include "position.hh"
42
43
44 namespace SEAMS {
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 explicit location (const position& p = position ())
60 : begin (p)
61 , end (p)
62 {
63 }
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 void step ()
89 {
90 begin = end;
91 }
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 void lines (int count = 1)
101 {
102 end.lines (count);
103 }
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 operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
175 {
176 unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
177 ostr << loc.begin;
178 if (loc.end.filename
179 && (!loc.begin.filename
180 || *loc.begin.filename != *loc.end.filename))
181 ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
182 else if (loc.begin.line < loc.end.line)
183 ostr << '-' << loc.end.line << '.' << end_col;
184 else if (loc.begin.column < end_col)
185 ostr << '-' << end_col;
186 return ostr;
187 }
188
189
190 } // SEAMS
191 #line 192 "location.hh" // location.cc:296
192 #endif // !YY_SEAMS_LOCATION_HH_INCLUDED