OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [debug/] [formatter.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Debug-mode error formatting implementation -*- C++ -*-
2
 
3
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4
// Free Software Foundation, Inc.
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
9
// Free Software Foundation; either version 3, or (at your option)
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
 
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.
20
 
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/>.
25
 
26
/** @file debug/formatter.h
27
 *  This file is a GNU debug extension to the Standard C++ Library.
28
 */
29
 
30
#ifndef _GLIBCXX_DEBUG_FORMATTER_H
31
#define _GLIBCXX_DEBUG_FORMATTER_H 1
32
 
33
#include <bits/c++config.h>
34
#include <bits/cpp_type_traits.h>
35
#include <typeinfo>
36
 
37
namespace __gnu_debug
38
{
39
  using std::type_info;
40
 
41
  template<typename _Iterator>
42
    bool __check_singular(_Iterator&);
43
 
44
  class _Safe_sequence_base;
45
 
46
  template<typename _Iterator, typename _Sequence>
47
    class _Safe_iterator;
48
 
49
  template<typename _Iterator, typename _Sequence>
50
    class _Safe_local_iterator;
51
 
52
  template<typename _Sequence>
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,
105
    __msg_inc_istreambuf,
106
    // forward_list
107
    __msg_insert_after_end,
108
    __msg_erase_after_bad,
109
    __msg_valid_range2,
110
    // unordered container local iterators
111
    __msg_local_iter_compare_bad,
112
    __msg_non_empty_range,
113
    // self move assign
114
    __msg_self_move_assign,
115
    // unordered container buckets
116
    __msg_bucket_index_oob,
117
    __msg_valid_load_factor,
118
    __msg_equal_allocs
119
  };
120
 
121
  class _Error_formatter
122
  {
123
    /// Whether an iterator is constant, mutable, or unknown
124
    enum _Constness
125
    {
126
      __unknown_constness,
127
      __const_iterator,
128
      __mutable_iterator,
129
      __last_constness
130
    };
131
 
132
    // The state of the iterator (fine-grained), if we know it.
133
    enum _Iterator_state
134
    {
135
      __unknown_state,
136
      __singular,      // singular, may still be attached to a sequence
137
      __begin,         // dereferenceable, and at the beginning
138
      __middle,        // dereferenceable, not at the beginning
139
      __end,           // past-the-end, may be at beginning if sequence empty
140
      __before_begin,  // before begin
141
      __last_state
142
    };
143
 
144
    // Tags denoting the type of parameter for construction
145
    struct _Is_iterator { };
146
    struct _Is_sequence { };
147
 
148
    // A parameter that may be referenced by an error message
149
    struct _Parameter
150
    {
151
      enum
152
      {
153
        __unused_param,
154
        __iterator,
155
        __sequence,
156
        __integer,
157
        __string
158
      } _M_kind;
159
 
160
      union
161
      {
162
        // When _M_kind == __iterator
163
        struct
164
        {
165
          const char*      _M_name;
166
          const void*      _M_address;
167
          const type_info* _M_type;
168
          _Constness       _M_constness;
169
          _Iterator_state  _M_state;
170
          const void*      _M_sequence;
171
          const type_info* _M_seq_type;
172
        } _M_iterator;
173
 
174
        // When _M_kind == __sequence
175
        struct
176
        {
177
          const char*      _M_name;
178
          const void*      _M_address;
179
          const type_info* _M_type;
180
        } _M_sequence;
181
 
182
        // When _M_kind == __integer
183
        struct
184
        {
185
          const char* _M_name;
186
          long        _M_value;
187
        } _M_integer;
188
 
189
        // When _M_kind == __string
190
        struct
191
        {
192
          const char* _M_name;
193
          const char* _M_value;
194
        } _M_string;
195
      } _M_variant;
196
 
197
      _Parameter() : _M_kind(__unused_param), _M_variant() { }
198
 
199
      _Parameter(long __value, const char* __name)
200
      : _M_kind(__integer), _M_variant()
201
      {
202
        _M_variant._M_integer._M_name = __name;
203
        _M_variant._M_integer._M_value = __value;
204
      }
205
 
206
      _Parameter(const char* __value, const char* __name)
207
      : _M_kind(__string), _M_variant()
208
      {
209
        _M_variant._M_string._M_name = __name;
210
        _M_variant._M_string._M_value = __value;
211
      }
212
 
213
      template<typename _Iterator, typename _Sequence>
214
        _Parameter(const _Safe_iterator<_Iterator, _Sequence>& __it,
215
                   const char* __name, _Is_iterator)
216
        : _M_kind(__iterator),  _M_variant()
217
        {
218
          _M_variant._M_iterator._M_name = __name;
219
          _M_variant._M_iterator._M_address = &__it;
220
#ifdef __GXX_RTTI
221
          _M_variant._M_iterator._M_type = &typeid(__it);
222
#else
223
          _M_variant._M_iterator._M_type = 0;
224
#endif
225
          _M_variant._M_iterator._M_constness =
226
            std::__are_same<_Safe_iterator<_Iterator, _Sequence>,
227
                            typename _Sequence::iterator>::
228
              __value ? __mutable_iterator : __const_iterator;
229
          _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
230
#ifdef __GXX_RTTI
231
          _M_variant._M_iterator._M_seq_type = &typeid(_Sequence);
232
#else
233
          _M_variant._M_iterator._M_seq_type = 0;
234
#endif
235
 
236
          if (__it._M_singular())
237
            _M_variant._M_iterator._M_state = __singular;
238
          else
239
            {
240
              if (__it._M_is_before_begin())
241
                _M_variant._M_iterator._M_state = __before_begin;
242
              else if (__it._M_is_end())
243
                _M_variant._M_iterator._M_state = __end;
244
              else if (__it._M_is_begin())
245
                _M_variant._M_iterator._M_state = __begin;
246
              else
247
                _M_variant._M_iterator._M_state = __middle;
248
            }
249
        }
250
 
251
      template<typename _Iterator, typename _Sequence>
252
        _Parameter(const _Safe_local_iterator<_Iterator, _Sequence>& __it,
253
                   const char* __name, _Is_iterator)
254
        : _M_kind(__iterator),  _M_variant()
255
        {
256
          _M_variant._M_iterator._M_name = __name;
257
          _M_variant._M_iterator._M_address = &__it;
258
#ifdef __GXX_RTTI
259
          _M_variant._M_iterator._M_type = &typeid(__it);
260
#else
261
          _M_variant._M_iterator._M_type = 0;
262
#endif
263
          _M_variant._M_iterator._M_constness =
264
            std::__are_same<_Safe_local_iterator<_Iterator, _Sequence>,
265
                            typename _Sequence::local_iterator>::
266
              __value ? __mutable_iterator : __const_iterator;
267
          _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
268
#ifdef __GXX_RTTI
269
          _M_variant._M_iterator._M_seq_type = &typeid(_Sequence);
270
#else
271
          _M_variant._M_iterator._M_seq_type = 0;
272
#endif
273
 
274
          if (__it._M_singular())
275
            _M_variant._M_iterator._M_state = __singular;
276
          else
277
            {
278
              if (__it._M_is_end())
279
                _M_variant._M_iterator._M_state = __end;
280
              else if (__it._M_is_begin())
281
                _M_variant._M_iterator._M_state = __begin;
282
              else
283
                _M_variant._M_iterator._M_state = __middle;
284
            }
285
        }
286
 
287
      template<typename _Type>
288
        _Parameter(const _Type*& __it, const char* __name, _Is_iterator)
289
        : _M_kind(__iterator), _M_variant()
290
        {
291
          _M_variant._M_iterator._M_name = __name;
292
          _M_variant._M_iterator._M_address = &__it;
293
#ifdef __GXX_RTTI
294
          _M_variant._M_iterator._M_type = &typeid(__it);
295
#else
296
          _M_variant._M_iterator._M_type = 0;
297
#endif
298
          _M_variant._M_iterator._M_constness = __mutable_iterator;
299
          _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
300
          _M_variant._M_iterator._M_sequence = 0;
301
          _M_variant._M_iterator._M_seq_type = 0;
302
        }
303
 
304
      template<typename _Type>
305
        _Parameter(_Type*& __it, const char* __name, _Is_iterator)
306
        : _M_kind(__iterator), _M_variant()
307
        {
308
          _M_variant._M_iterator._M_name = __name;
309
          _M_variant._M_iterator._M_address = &__it;
310
#ifdef __GXX_RTTI
311
          _M_variant._M_iterator._M_type = &typeid(__it);
312
#else
313
          _M_variant._M_iterator._M_type = 0;
314
#endif
315
          _M_variant._M_iterator._M_constness = __const_iterator;
316
          _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
317
          _M_variant._M_iterator._M_sequence = 0;
318
          _M_variant._M_iterator._M_seq_type = 0;
319
        }
320
 
321
      template<typename _Iterator>
322
        _Parameter(const _Iterator& __it, const char* __name, _Is_iterator)
323
        : _M_kind(__iterator), _M_variant()
324
        {
325
          _M_variant._M_iterator._M_name = __name;
326
          _M_variant._M_iterator._M_address = &__it;
327
#ifdef __GXX_RTTI
328
          _M_variant._M_iterator._M_type = &typeid(__it);
329
#else
330
          _M_variant._M_iterator._M_type = 0;
331
#endif
332
          _M_variant._M_iterator._M_constness = __unknown_constness;
333
          _M_variant._M_iterator._M_state =
334
            __gnu_debug::__check_singular(__it)? __singular : __unknown_state;
335
          _M_variant._M_iterator._M_sequence = 0;
336
          _M_variant._M_iterator._M_seq_type = 0;
337
        }
338
 
339
      template<typename _Sequence>
340
        _Parameter(const _Safe_sequence<_Sequence>& __seq,
341
                   const char* __name, _Is_sequence)
342
        : _M_kind(__sequence), _M_variant()
343
        {
344
          _M_variant._M_sequence._M_name = __name;
345
          _M_variant._M_sequence._M_address =
346
            static_cast<const _Sequence*>(&__seq);
347
#ifdef __GXX_RTTI
348
          _M_variant._M_sequence._M_type = &typeid(_Sequence);
349
#else
350
          _M_variant._M_sequence._M_type = 0;
351
#endif
352
        }
353
 
354
      template<typename _Sequence>
355
        _Parameter(const _Sequence& __seq, const char* __name, _Is_sequence)
356
        : _M_kind(__sequence), _M_variant()
357
        {
358
          _M_variant._M_sequence._M_name = __name;
359
          _M_variant._M_sequence._M_address = &__seq;
360
#ifdef __GXX_RTTI
361
          _M_variant._M_sequence._M_type = &typeid(_Sequence);
362
#else
363
          _M_variant._M_sequence._M_type = 0;
364
#endif
365
        }
366
 
367
      void
368
      _M_print_field(const _Error_formatter* __formatter,
369
                     const char* __name) const;
370
 
371
      void
372
      _M_print_description(const _Error_formatter* __formatter) const;
373
    };
374
 
375
    friend struct _Parameter;
376
 
377
  public:
378
    template<typename _Iterator>
379
      const _Error_formatter&
380
      _M_iterator(const _Iterator& __it, const char* __name = 0)  const
381
      {
382
        if (_M_num_parameters < std::size_t(__max_parameters))
383
          _M_parameters[_M_num_parameters++] = _Parameter(__it, __name,
384
                                                          _Is_iterator());
385
        return *this;
386
      }
387
 
388
    const _Error_formatter&
389
    _M_integer(long __value, const char* __name = 0) const
390
    {
391
      if (_M_num_parameters < std::size_t(__max_parameters))
392
        _M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
393
      return *this;
394
    }
395
 
396
    const _Error_formatter&
397
    _M_string(const char* __value, const char* __name = 0) const
398
    {
399
      if (_M_num_parameters < std::size_t(__max_parameters))
400
        _M_parameters[_M_num_parameters++] = _Parameter(__value, __name);
401
      return *this;
402
    }
403
 
404
    template<typename _Sequence>
405
      const _Error_formatter&
406
      _M_sequence(const _Sequence& __seq, const char* __name = 0) const
407
      {
408
        if (_M_num_parameters < std::size_t(__max_parameters))
409
          _M_parameters[_M_num_parameters++] = _Parameter(__seq, __name,
410
                                                          _Is_sequence());
411
        return *this;
412
      }
413
 
414
    const _Error_formatter&
415
    _M_message(const char* __text) const
416
    { _M_text = __text; return *this; }
417
 
418
    const _Error_formatter&
419
    _M_message(_Debug_msg_id __id) const throw ();
420
 
421
    _GLIBCXX_NORETURN void
422
    _M_error() const;
423
 
424
  private:
425
    _Error_formatter(const char* __file, std::size_t __line)
426
    : _M_file(__file), _M_line(__line), _M_num_parameters(0), _M_text(0),
427
      _M_max_length(78), _M_column(1), _M_first_line(true), _M_wordwrap(false)
428
    { _M_get_max_length(); }
429
 
430
    template<typename _Tp>
431
      void
432
      _M_format_word(char*, int, const char*, _Tp) const throw ();
433
 
434
    void
435
    _M_print_word(const char* __word) const;
436
 
437
    void
438
    _M_print_string(const char* __string) const;
439
 
440
    void
441
    _M_get_max_length() const throw ();
442
 
443
    enum { __max_parameters = 9 };
444
 
445
    const char*         _M_file;
446
    std::size_t         _M_line;
447
    mutable _Parameter  _M_parameters[__max_parameters];
448
    mutable std::size_t _M_num_parameters;
449
    mutable const char* _M_text;
450
    mutable std::size_t _M_max_length;
451
    enum { _M_indent = 4 } ;
452
    mutable std::size_t _M_column;
453
    mutable bool        _M_first_line;
454
    mutable bool        _M_wordwrap;
455
 
456
  public:
457
    static _Error_formatter
458
    _M_at(const char* __file, std::size_t __line)
459
    { return _Error_formatter(__file, __line); }
460
  };
461
} // namespace __gnu_debug
462
 
463
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.