diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2015-05-29 21:29:07 +0000 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2015-05-29 21:29:07 +0000 |
commit | adad2a7d908a58b22431e05dc4f4efba3b990ea2 (patch) | |
tree | 4ecd5b0b0c4b5cb8aeeff48b582990fbbcb62202 /libstdc++-v3/src | |
parent | 8fd0be756e29db9d02e4d7e3d951a10d3f17ecd6 (diff) | |
download | gcc-adad2a7d908a58b22431e05dc4f4efba3b990ea2.zip gcc-adad2a7d908a58b22431e05dc4f4efba3b990ea2.tar.gz gcc-adad2a7d908a58b22431e05dc4f4efba3b990ea2.tar.bz2 |
2015-05-29 François Dumont fdumont@gcc.gnu.org>
* include/debug/debug.h (_GLIBCXX_DEBUG_ASSERT,
_GLIBCXX_DEBUG_PEDASSERT, _GLIBCXX_DEBUG_ONLY): Move definition...
* include/debug/assertions.h: ...here, new.
* include/debug/formatter.h
(_Error_formatter::_Is_iterator_value_type): New.
(_Error_formatter::_Is_instance): New.
(_Error_formatter::_Parameter): Make public and not friend anymore.
(_Error_formatter::_Parameter::__instance): New _M_kind enum entry.
(_Error_formatter::_Parameter::__iterator_value_type): New _M_kind enum
entry.
(_Error_formatter::_Parameter::_Type): New.
(_Error_formatter::_Parameter::_Instance): New, inherit from
latter.
(union _Error_formatter::_Parameter::_M_variant): Reorganize.
(_Parameter(_Iterator const&, const char*, _Is_iterator)): Make all
overloads take iterator through a const reference.
(_Parameter(const _Iterator&, const char*, _Is_iterator_value_type)):
New.
(_Parameter(const _Type&, const char*, _Is_instance)): New.
(_Error_formatter::_M_print_type): Delete.
(_Error_formatter::_M_iterator_value_type): New.
(_Error_formatter::_M_instance): New.
* include/Makefile.am: Add new above debug file.
* include/Makefile.in: Regenerate.
* include/debug/functions.h
(__check_dereferenceable(const _Safe_iterator<>&),
__valid_range(const _Safe_iterator<>&),
__is_safe_random_iterator<_Safe_iterator<>>): Move...
* include/debug/safe_iterator.h: ... here.
Replace debug.h include with assertions.h.
(__check_singular_aux): Move...
* include/debug/safe_base.h: ... here.
* include/debug/functions.h
(__check_dereferenceable(const _Safe_local_iterator<>&),
__valid_range(const _Safe_local_iterator<>&): Move...
* include/debug/safe_local_iterator.h: ...here.
* include/debug/safe_sequence.h: Replace debug.h with assertions.h.
Remove _Safe_iterator declaration.
* include/debug/safe_unordered_container.h: Replace debug.h with
assertions.h.
* include/debug/array: Replace safe_sequence.h include with
formatter.h and macros.h.
* include/debug/deque: Include functions.tcc.
* include/debug/forward_list: Likewise.
* include/debug/list: Likewise.
* include/debug/string: Likewise.
* include/debug/vector: Likewise.
* include/bits/unique_ptr.h: Replace debug.h include with new
assertions.h.
* include/bits/stl_iterator_base_funcs.h: Likewise.
* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
Adjust dg-error line number.
* testsuite/23_containers/array/tuple_interface/
tuple_element_debug_neg.cc: Likewise.
* src/c++11/debug.cc: Adapt.
From-SVN: r223877
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r-- | libstdc++-v3/src/c++11/debug.cc | 237 |
1 files changed, 154 insertions, 83 deletions
diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index f51435a..f60e31f 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -519,8 +519,123 @@ namespace __gnu_debug if (_M_local_iterators == __it) _M_local_iterators = __it->_M_next; } +} + +namespace +{ + void + print_type(const __gnu_debug::_Error_formatter* __formatter, + const type_info* __info, + const char* __unknown_name) + { + if (!__info) + __formatter->_M_print_word(__unknown_name); + else + { + int __status; + char* __demangled_name = + __cxxabiv1::__cxa_demangle(__info->name(), NULL, NULL, &__status); + __formatter->_M_print_word(__status == 0 + ? __demangled_name : __info->name()); + free(__demangled_name); + } + } + + bool + print_field( + const __gnu_debug::_Error_formatter* __formatter, + const char* __name, + const __gnu_debug::_Error_formatter::_Parameter::_Type& __variant) + { + if (strcmp(__name, "name") == 0) + { + assert(__variant._M_name); + __formatter->_M_print_word(__variant._M_name); + } + else if (strcmp(__name, "type") == 0) + print_type(__formatter, __variant._M_type, "<unknown type>"); + else + return false; + + return true; + } + + bool + print_field( + const __gnu_debug::_Error_formatter* __formatter, + const char* __name, + const __gnu_debug::_Error_formatter::_Parameter::_Instance& __variant) + { + const __gnu_debug::_Error_formatter::_Parameter::_Type& __type = __variant; + if (print_field(__formatter, __name, __type)) + { } + else if (strcmp(__name, "address") == 0) + { + const int __bufsize = 64; + char __buf[__bufsize]; + __formatter->_M_format_word(__buf, __bufsize, "%p", + __variant._M_address); + __formatter->_M_print_word(__buf); + } + else + return false; + + return true; + } void + print_description( + const __gnu_debug::_Error_formatter* __formatter, + const __gnu_debug::_Error_formatter::_Parameter::_Type& __variant) + { + if (__variant._M_name) + { + const int __bufsize = 64; + char __buf[__bufsize]; + __formatter->_M_format_word(__buf, __bufsize, "\"%s\" ", + __variant._M_name); + __formatter->_M_print_word(__buf); + } + + if (__variant._M_type) + { + __formatter->_M_print_word(" type = "); + print_type(__formatter, __variant._M_type, "<unknown type>"); + __formatter->_M_print_word(";\n"); + } + } + + + void + print_description( + const __gnu_debug::_Error_formatter* __formatter, + const __gnu_debug::_Error_formatter::_Parameter::_Instance& __variant) + { + const int __bufsize = 64; + char __buf[__bufsize]; + + if (__variant._M_name) + { + __formatter->_M_format_word(__buf, __bufsize, "\"%s\" ", + __variant._M_name); + __formatter->_M_print_word(__buf); + } + + __formatter->_M_format_word(__buf, __bufsize, "@ 0x%p {\n", + __variant._M_address); + __formatter->_M_print_word(__buf); + + if (__variant._M_type) + { + __formatter->_M_print_word(" type = "); + print_type(__formatter, __variant._M_type, "<unknown type>"); + } + } +} + +namespace __gnu_debug +{ + void _Error_formatter::_Parameter:: _M_print_field(const _Error_formatter* __formatter, const char* __name) const { @@ -531,20 +646,8 @@ namespace __gnu_debug switch (_M_kind) { case __iterator: - if (strcmp(__name, "name") == 0) - { - assert(_M_variant._M_iterator._M_name); - __formatter->_M_print_word(_M_variant._M_iterator._M_name); - } - else if (strcmp(__name, "address") == 0) - { - __formatter->_M_format_word(__buf, __bufsize, "%p", - _M_variant._M_iterator._M_address); - __formatter->_M_print_word(__buf); - } - else if (strcmp(__name, "type") == 0) - __formatter->_M_print_type(_M_variant._M_iterator._M_type, - "<unknown type>"); + if (print_field(__formatter, __name, _M_variant._M_iterator)) + { } else if (strcmp(__name, "constness") == 0) { static const char* __constness_names[__last_constness] = @@ -579,28 +682,13 @@ namespace __gnu_debug __formatter->_M_print_word(__buf); } else if (strcmp(__name, "seq_type") == 0) - __formatter->_M_print_type(_M_variant._M_iterator._M_seq_type, - "<unknown seq_type>"); + print_type(__formatter, _M_variant._M_iterator._M_seq_type, + "<unknown seq_type>"); else assert(false); break; case __sequence: - if (strcmp(__name, "name") == 0) - { - assert(_M_variant._M_sequence._M_name); - __formatter->_M_print_word(_M_variant._M_sequence._M_name); - } - else if (strcmp(__name, "address") == 0) - { - assert(_M_variant._M_sequence._M_address); - __formatter->_M_format_word(__buf, __bufsize, "%p", - _M_variant._M_sequence._M_address); - __formatter->_M_print_word(__buf); - } - else if (strcmp(__name, "type") == 0) - __formatter->_M_print_type(_M_variant._M_sequence._M_type, - "<unknown type>"); - else + if (!print_field(__formatter, __name, _M_variant._M_sequence)) assert(false); break; case __integer: @@ -621,6 +709,14 @@ namespace __gnu_debug else assert(false); break; + case __instance: + if (!print_field(__formatter, __name, _M_variant._M_instance)) + assert(false); + break; + case __iterator_value_type: + if (!print_field(__formatter, __name, _M_variant._M_iterator_value_type)) + assert(false); + break; default: assert(false); break; @@ -638,21 +734,10 @@ namespace __gnu_debug { case __iterator: __formatter->_M_print_word("iterator "); - if (_M_variant._M_iterator._M_name) - { - __formatter->_M_format_word(__buf, __bufsize, "\"%s\" ", - _M_variant._M_iterator._M_name); - __formatter->_M_print_word(__buf); - } + print_description(__formatter, _M_variant._M_iterator); - __formatter->_M_format_word(__buf, __bufsize, "@ 0x%p {\n", - _M_variant._M_iterator._M_address); - __formatter->_M_print_word(__buf); if (_M_variant._M_iterator._M_type) { - __formatter->_M_print_word("type = "); - _M_print_field(__formatter, "type"); - if (_M_variant._M_iterator._M_constness != __unknown_constness) { __formatter->_M_print_word(" ("); @@ -687,25 +772,25 @@ namespace __gnu_debug break; case __sequence: __formatter->_M_print_word("sequence "); - if (_M_variant._M_sequence._M_name) - { - __formatter->_M_format_word(__buf, __bufsize, "\"%s\" ", - _M_variant._M_sequence._M_name); - __formatter->_M_print_word(__buf); - } - - __formatter->_M_format_word(__buf, __bufsize, "@ 0x%p {\n", - _M_variant._M_sequence._M_address); - __formatter->_M_print_word(__buf); + print_description(__formatter, _M_variant._M_sequence); if (_M_variant._M_sequence._M_type) - { - __formatter->_M_print_word(" type = "); - _M_print_field(__formatter, "type"); - __formatter->_M_print_word(";\n"); - } + __formatter->_M_print_word(";\n"); + __formatter->_M_print_word("}\n"); break; + case __instance: + __formatter->_M_print_word("instance "); + print_description(__formatter, _M_variant._M_instance); + + if (_M_variant._M_instance._M_type) + __formatter->_M_print_word(";\n"); + + break; + case __iterator_value_type: + __formatter->_M_print_word("iterator::value_type "); + print_description(__formatter, _M_variant._M_iterator_value_type); + break; default: break; } @@ -756,6 +841,8 @@ namespace __gnu_debug { case _Parameter::__iterator: case _Parameter::__sequence: + case _Parameter::__instance: + case _Parameter::__iterator_value_type: if (!__has_noninteger_parameters) { _M_first_line = true; @@ -879,9 +966,9 @@ namespace __gnu_debug // Get the parameter number assert(*__start >= '1' && *__start <= '9'); - size_t __param = *__start - '0'; - --__param; - assert(__param < _M_num_parameters); + size_t __param_index = *__start - '0' - 1; + assert(__param_index < _M_num_parameters); + const auto& __param = _M_parameters[__param_index]; // '.' separates the parameter number from the field // name, if there is one. @@ -891,14 +978,14 @@ namespace __gnu_debug assert(*__start == ';'); ++__start; __buf[0] = '\0'; - if (_M_parameters[__param]._M_kind == _Parameter::__integer) + if (__param._M_kind == _Parameter::__integer) { _M_format_word(__buf, __bufsize, "%ld", - _M_parameters[__param]._M_variant._M_integer._M_value); + __param._M_variant._M_integer._M_value); _M_print_word(__buf); } - else if (_M_parameters[__param]._M_kind == _Parameter::__string) - _M_print_string(_M_parameters[__param]._M_variant._M_string._M_value); + else if (__param._M_kind == _Parameter::__string) + _M_print_string(__param._M_variant._M_string._M_value); continue; } @@ -916,23 +1003,7 @@ namespace __gnu_debug ++__start; __field[__field_idx] = 0; - _M_parameters[__param]._M_print_field(this, __field); - } - } - - void - _Error_formatter::_M_print_type(const type_info* __info, - const char* __unknown_name) const - { - if (!__info) - _M_print_word(__unknown_name); - else - { - int __status; - char* __demangled_name = - __cxxabiv1::__cxa_demangle(__info->name(), NULL, NULL, &__status); - _M_print_word(__status == 0 ? __demangled_name : __info->name()); - free(__demangled_name); + __param._M_print_field(this, __field); } } |