]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/debug/formatter.h
loop-doloop.c (doloop_modify): Pass doloop_end pattern to gen_doloop_begin.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / formatter.h
CommitLineData
285b36d6
BK
1// Debug-mode error formatting implementation -*- C++ -*-
2
739fd6a6 3// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
0f136367 4// Free Software Foundation, Inc.
285b36d6
BK
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
285b36d6
BK
10// any later version.
11
12// This library 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
748086b7
JJ
17// Under Section 7 of GPL version 3, you are granted additional
18// permissions described in the GCC Runtime Library Exception, version
19// 3.1, as published by the Free Software Foundation.
285b36d6 20
748086b7
JJ
21// You should have received a copy of the GNU General Public License and
22// a copy of the GCC Runtime Library Exception along with this program;
23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24// <http://www.gnu.org/licenses/>.
285b36d6 25
78a53887
BK
26/** @file debug/formatter.h
27 * This file is a GNU debug extension to the Standard C++ Library.
28 */
29
285b36d6
BK
30#ifndef _GLIBCXX_DEBUG_FORMATTER_H
31#define _GLIBCXX_DEBUG_FORMATTER_H 1
32
b8add594 33#include <bits/c++config.h>
67c495be 34#include <bits/cpp_type_traits.h>
285b36d6 35#include <typeinfo>
285b36d6
BK
36
37namespace __gnu_debug
38{
45f388bb
BK
39 using std::type_info;
40
1f5ca1a1
PC
41 template<typename _Iterator>
42 bool __check_singular(_Iterator&);
43
285b36d6
BK
44 class _Safe_sequence_base;
45
526da49c 46 template<typename _Iterator, typename _Sequence>
285b36d6
BK
47 class _Safe_iterator;
48
77e0bf4e
FD
49 template<typename _Iterator, typename _Sequence>
50 class _Safe_local_iterator;
51
526da49c 52 template<typename _Sequence>
285b36d6
BK
53 class _Safe_sequence;
54
55 enum _Debug_msg_id
56 {
57 // General checks
58 __msg_valid_range,
59 __msg_insert_singular,
60 __msg_insert_different,
61 __msg_erase_bad,
62 __msg_erase_different,
63 __msg_subscript_oob,
64 __msg_empty,
65 __msg_unpartitioned,
66 __msg_unpartitioned_pred,
67 __msg_unsorted,
68 __msg_unsorted_pred,
69 __msg_not_heap,
70 __msg_not_heap_pred,
71 // std::bitset checks
72 __msg_bad_bitset_write,
73 __msg_bad_bitset_read,
74 __msg_bad_bitset_flip,
75 // std::list checks
76 __msg_self_splice,
77 __msg_splice_alloc,
78 __msg_splice_bad,
79 __msg_splice_other,
80 __msg_splice_overlap,
81 // iterator checks
82 __msg_init_singular,
83 __msg_init_copy_singular,
84 __msg_init_const_singular,
85 __msg_copy_singular,
86 __msg_bad_deref,
87 __msg_bad_inc,
88 __msg_bad_dec,
89 __msg_iter_subscript_oob,
90 __msg_advance_oob,
91 __msg_retreat_oob,
92 __msg_iter_compare_bad,
93 __msg_compare_different,
94 __msg_iter_order_bad,
95 __msg_order_different,
96 __msg_distance_bad,
97 __msg_distance_different,
98 // istream_iterator
99 __msg_deref_istream,
100 __msg_inc_istream,
101 // ostream_iterator
102 __msg_output_ostream,
103 // istreambuf_iterator
104 __msg_deref_istreambuf,
b8b4301e
PC
105 __msg_inc_istreambuf,
106 // forward_list
107 __msg_insert_after_end,
108 __msg_erase_after_bad,
77e0bf4e
FD
109 __msg_valid_range2,
110 // unordered sequence local iterators
a8028a3e 111 __msg_local_iter_compare_bad,
739fd6a6
PC
112 __msg_non_empty_range,
113 // self move assign
114 __msg_self_move_assign
285b36d6
BK
115 };
116
117 class _Error_formatter
118 {
119 /// Whether an iterator is constant, mutable, or unknown
120 enum _Constness
121 {
122 __unknown_constness,
123 __const_iterator,
124 __mutable_iterator,
125 __last_constness
526da49c 126 };
285b36d6
BK
127
128 // The state of the iterator (fine-grained), if we know it.
129 enum _Iterator_state
130 {
131 __unknown_state,
132 __singular, // singular, may still be attached to a sequence
133 __begin, // dereferenceable, and at the beginning
134 __middle, // dereferenceable, not at the beginning
135 __end, // past-the-end, may be at beginning if sequence empty
b8b4301e 136 __before_begin, // before begin
285b36d6
BK
137 __last_state
138 };
139
140 // Tags denoting the type of parameter for construction
141 struct _Is_iterator { };
142 struct _Is_sequence { };
143
144 // A parameter that may be referenced by an error message
145 struct _Parameter
146 {
526da49c
BI
147 enum
148 {
149 __unused_param,
150 __iterator,
151 __sequence,
285b36d6
BK
152 __integer,
153 __string
154 } _M_kind;
526da49c 155
285b36d6
BK
156 union
157 {
158 // When _M_kind == __iterator
526da49c 159 struct
285b36d6 160 {
526da49c
BI
161 const char* _M_name;
162 const void* _M_address;
163 const type_info* _M_type;
285b36d6
BK
164 _Constness _M_constness;
165 _Iterator_state _M_state;
526da49c 166 const void* _M_sequence;
285b36d6
BK
167 const type_info* _M_seq_type;
168 } _M_iterator;
526da49c 169
285b36d6
BK
170 // When _M_kind == __sequence
171 struct
172 {
173 const char* _M_name;
174 const void* _M_address;
175 const type_info* _M_type;
176 } _M_sequence;
177
178 // When _M_kind == __integer
179 struct
180 {
181 const char* _M_name;
182 long _M_value;
183 } _M_integer;
184
185 // When _M_kind == __string
186 struct
187 {
188 const char* _M_name;
189 const char* _M_value;
190 } _M_string;
191 } _M_variant;
192
26c691a8 193 _Parameter() : _M_kind(__unused_param), _M_variant() { }
526da49c 194
26c691a8
BK
195 _Parameter(long __value, const char* __name)
196 : _M_kind(__integer), _M_variant()
526da49c 197 {
285b36d6 198 _M_variant._M_integer._M_name = __name;
526da49c 199 _M_variant._M_integer._M_value = __value;
285b36d6
BK
200 }
201
26c691a8
BK
202 _Parameter(const char* __value, const char* __name)
203 : _M_kind(__string), _M_variant()
285b36d6
BK
204 {
205 _M_variant._M_string._M_name = __name;
526da49c 206 _M_variant._M_string._M_value = __value;
285b36d6
BK
207 }
208
209 template<typename _Iterator, typename _Sequence>
210 _Parameter(const _Safe_iterator<_Iterator, _Sequence>& __it,
211 const char* __name, _Is_iterator)
26c691a8 212 : _M_kind(__iterator), _M_variant()
285b36d6
BK
213 {
214 _M_variant._M_iterator._M_name = __name;
215 _M_variant._M_iterator._M_address = &__it;
0f136367 216#ifdef __GXX_RTTI
285b36d6 217 _M_variant._M_iterator._M_type = &typeid(__it);
0f136367
PC
218#else
219 _M_variant._M_iterator._M_type = 0;
220#endif
526da49c 221 _M_variant._M_iterator._M_constness =
67c495be
PC
222 std::__are_same<_Safe_iterator<_Iterator, _Sequence>,
223 typename _Sequence::iterator>::
224 __value ? __mutable_iterator : __const_iterator;
285b36d6 225 _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
0f136367 226#ifdef __GXX_RTTI
285b36d6 227 _M_variant._M_iterator._M_seq_type = &typeid(_Sequence);
0f136367
PC
228#else
229 _M_variant._M_iterator._M_seq_type = 0;
230#endif
285b36d6
BK
231
232 if (__it._M_singular())
233 _M_variant._M_iterator._M_state = __singular;
234 else
235 {
b8b4301e
PC
236 if (__it._M_is_before_begin())
237 _M_variant._M_iterator._M_state = __before_begin;
238 else if (__it._M_is_end())
285b36d6 239 _M_variant._M_iterator._M_state = __end;
b8b4301e 240 else if (__it._M_is_begin())
285b36d6
BK
241 _M_variant._M_iterator._M_state = __begin;
242 else
243 _M_variant._M_iterator._M_state = __middle;
244 }
245 }
246
77e0bf4e
FD
247 template<typename _Iterator, typename _Sequence>
248 _Parameter(const _Safe_local_iterator<_Iterator, _Sequence>& __it,
249 const char* __name, _Is_iterator)
250 : _M_kind(__iterator), _M_variant()
251 {
252 _M_variant._M_iterator._M_name = __name;
253 _M_variant._M_iterator._M_address = &__it;
254#ifdef __GXX_RTTI
255 _M_variant._M_iterator._M_type = &typeid(__it);
256#else
257 _M_variant._M_iterator._M_type = 0;
258#endif
259 _M_variant._M_iterator._M_constness =
260 std::__are_same<_Safe_local_iterator<_Iterator, _Sequence>,
261 typename _Sequence::local_iterator>::
262 __value ? __mutable_iterator : __const_iterator;
263 _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
264#ifdef __GXX_RTTI
265 _M_variant._M_iterator._M_seq_type = &typeid(_Sequence);
266#else
267 _M_variant._M_iterator._M_seq_type = 0;
268#endif
269
270 if (__it._M_singular())
271 _M_variant._M_iterator._M_state = __singular;
272 else
273 {
274 if (__it._M_is_end())
275 _M_variant._M_iterator._M_state = __end;
276 else if (__it._M_is_begin())
277 _M_variant._M_iterator._M_state = __begin;
278 else
279 _M_variant._M_iterator._M_state = __middle;
280 }
281 }
282
285b36d6
BK
283 template<typename _Type>
284 _Parameter(const _Type*& __it, const char* __name, _Is_iterator)
26c691a8 285 : _M_kind(__iterator), _M_variant()
285b36d6
BK
286 {
287 _M_variant._M_iterator._M_name = __name;
288 _M_variant._M_iterator._M_address = &__it;
0f136367 289#ifdef __GXX_RTTI
285b36d6 290 _M_variant._M_iterator._M_type = &typeid(__it);
0f136367
PC
291#else
292 _M_variant._M_iterator._M_type = 0;
293#endif
285b36d6
BK
294 _M_variant._M_iterator._M_constness = __mutable_iterator;
295 _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
296 _M_variant._M_iterator._M_sequence = 0;
297 _M_variant._M_iterator._M_seq_type = 0;
298 }
299
300 template<typename _Type>
301 _Parameter(_Type*& __it, const char* __name, _Is_iterator)
26c691a8 302 : _M_kind(__iterator), _M_variant()
285b36d6
BK
303 {
304 _M_variant._M_iterator._M_name = __name;
305 _M_variant._M_iterator._M_address = &__it;
0f136367 306#ifdef __GXX_RTTI
285b36d6 307 _M_variant._M_iterator._M_type = &typeid(__it);
0f136367
PC
308#else
309 _M_variant._M_iterator._M_type = 0;
310#endif
285b36d6
BK
311 _M_variant._M_iterator._M_constness = __const_iterator;
312 _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
313 _M_variant._M_iterator._M_sequence = 0;
314 _M_variant._M_iterator._M_seq_type = 0;
315 }
526da49c 316
285b36d6
BK
317 template<typename _Iterator>
318 _Parameter(const _Iterator& __it, const char* __name, _Is_iterator)
26c691a8 319 : _M_kind(__iterator), _M_variant()
285b36d6
BK
320 {
321 _M_variant._M_iterator._M_name = __name;
322 _M_variant._M_iterator._M_address = &__it;
0f136367 323#ifdef __GXX_RTTI
285b36d6 324 _M_variant._M_iterator._M_type = &typeid(__it);
0f136367
PC
325#else
326 _M_variant._M_iterator._M_type = 0;
327#endif
285b36d6 328 _M_variant._M_iterator._M_constness = __unknown_constness;
526da49c 329 _M_variant._M_iterator._M_state =
285b36d6
BK
330 __gnu_debug::__check_singular(__it)? __singular : __unknown_state;
331 _M_variant._M_iterator._M_sequence = 0;
332 _M_variant._M_iterator._M_seq_type = 0;
333 }
334
335 template<typename _Sequence>
526da49c 336 _Parameter(const _Safe_sequence<_Sequence>& __seq,
285b36d6 337 const char* __name, _Is_sequence)
26c691a8 338 : _M_kind(__sequence), _M_variant()
285b36d6
BK
339 {
340 _M_variant._M_sequence._M_name = __name;
526da49c 341 _M_variant._M_sequence._M_address =
285b36d6 342 static_cast<const _Sequence*>(&__seq);
0f136367 343#ifdef __GXX_RTTI
285b36d6 344 _M_variant._M_sequence._M_type = &typeid(_Sequence);
0f136367
PC
345#else
346 _M_variant._M_sequence._M_type = 0;
347#endif
285b36d6
BK
348 }
349
350 template<typename _Sequence>
351 _Parameter(const _Sequence& __seq, const char* __name, _Is_sequence)
26c691a8 352 : _M_kind(__sequence), _M_variant()
285b36d6
BK
353 {
354 _M_variant._M_sequence._M_name = __name;
355 _M_variant._M_sequence._M_address = &__seq;
0f136367 356#ifdef __GXX_RTTI
285b36d6 357 _M_variant._M_sequence._M_type = &typeid(_Sequence);
0f136367
PC
358#else
359 _M_variant._M_sequence._M_type = 0;
360#endif
285b36d6 361 }
526da49c 362
285b36d6 363 void
526da49c 364 _M_print_field(const _Error_formatter* __formatter,
285b36d6 365 const char* __name) const;
526da49c 366
285b36d6
BK
367 void
368 _M_print_description(const _Error_formatter* __formatter) const;
369 };
370
371 friend struct _Parameter;
372
526da49c 373 public:
285b36d6
BK
374 template<typename _Iterator>
375 const _Error_formatter&
376 _M_iterator(const _Iterator& __it, const char* __name = 0) const
377 {
8fc81078 378 if (_M_num_parameters < std::size_t(__max_parameters))
285b36d6
BK
379 _M_parameters[_M_num_parameters++] = _Parameter(__it, __name,
380 _Is_iterator());
381 return *this;
382 }
383
384 const _Error_formatter&
385 _M_integer(long __value, const char* __name = 0) const
386 {
8fc81078 387 if (_M_num_parameters < std::size_t(__max_parameters))
285b36d6
BK
388 _M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
389 return *this;
390 }
391
392 const _Error_formatter&
393 _M_string(const char* __value, const char* __name = 0) const
394 {
8fc81078 395 if (_M_num_parameters < std::size_t(__max_parameters))
285b36d6
BK
396 _M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
397 return *this;
398 }
399
400 template<typename _Sequence>
401 const _Error_formatter&
402 _M_sequence(const _Sequence& __seq, const char* __name = 0) const
403 {
8fc81078 404 if (_M_num_parameters < std::size_t(__max_parameters))
526da49c 405 _M_parameters[_M_num_parameters++] = _Parameter(__seq, __name,
285b36d6
BK
406 _Is_sequence());
407 return *this;
408 }
409
410 const _Error_formatter&
411 _M_message(const char* __text) const
412 { _M_text = __text; return *this; }
413
414 const _Error_formatter&
5d51b87a 415 _M_message(_Debug_msg_id __id) const throw ();
285b36d6 416
b8add594 417 _GLIBCXX_NORETURN void
285b36d6
BK
418 _M_error() const;
419
420 private:
8fc81078 421 _Error_formatter(const char* __file, std::size_t __line)
285b36d6
BK
422 : _M_file(__file), _M_line(__line), _M_num_parameters(0), _M_text(0),
423 _M_max_length(78), _M_column(1), _M_first_line(true), _M_wordwrap(false)
5dddb7e5 424 { _M_get_max_length(); }
285b36d6 425
9dc420e6 426 template<typename _Tp>
4be58168 427 void
5d51b87a 428 _M_format_word(char*, int, const char*, _Tp) const throw ();
4be58168 429
526da49c 430 void
285b36d6
BK
431 _M_print_word(const char* __word) const;
432
526da49c 433 void
285b36d6
BK
434 _M_print_string(const char* __string) const;
435
5dddb7e5 436 void
5d51b87a 437 _M_get_max_length() const throw ();
5dddb7e5 438
285b36d6
BK
439 enum { __max_parameters = 9 };
440
441 const char* _M_file;
8fc81078 442 std::size_t _M_line;
285b36d6 443 mutable _Parameter _M_parameters[__max_parameters];
8fc81078 444 mutable std::size_t _M_num_parameters;
285b36d6 445 mutable const char* _M_text;
8fc81078 446 mutable std::size_t _M_max_length;
285b36d6 447 enum { _M_indent = 4 } ;
8fc81078 448 mutable std::size_t _M_column;
285b36d6
BK
449 mutable bool _M_first_line;
450 mutable bool _M_wordwrap;
451
452 public:
453 static _Error_formatter
8fc81078 454 _M_at(const char* __file, std::size_t __line)
285b36d6
BK
455 { return _Error_formatter(__file, __line); }
456 };
457} // namespace __gnu_debug
458
526da49c 459#endif