File indexing completed on 2024-11-15 09:05:00
0001 #ifndef BOOST_CORE_DEMANGLE_HPP_INCLUDED
0002 #define BOOST_CORE_DEMANGLE_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <boost/config.hpp>
0014 #include <string>
0015
0016 #if defined(BOOST_HAS_PRAGMA_ONCE)
0017 # pragma once
0018 #endif
0019
0020
0021
0022
0023 #if defined( __has_include ) && (!defined( BOOST_GCC ) || (__GNUC__ + 0) >= 5)
0024 # if __has_include(<cxxabi.h>)
0025 # define BOOST_CORE_HAS_CXXABI_H
0026 # endif
0027 #elif defined( __GLIBCXX__ ) || defined( __GLIBCPP__ )
0028 # define BOOST_CORE_HAS_CXXABI_H
0029 #endif
0030
0031 #if defined( BOOST_CORE_HAS_CXXABI_H )
0032 # include <cxxabi.h>
0033
0034
0035
0036 # if defined( __GABIXX_CXXABI_H__ )
0037 # undef BOOST_CORE_HAS_CXXABI_H
0038 # else
0039 # include <cstdlib>
0040 # include <cstddef>
0041 # endif
0042 #endif
0043
0044 namespace boost
0045 {
0046
0047 namespace core
0048 {
0049
0050 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT;
0051 inline void demangle_free( char const * name ) BOOST_NOEXCEPT;
0052
0053 class scoped_demangled_name
0054 {
0055 private:
0056 char const * m_p;
0057
0058 public:
0059 explicit scoped_demangled_name( char const * name ) BOOST_NOEXCEPT :
0060 m_p( demangle_alloc( name ) )
0061 {
0062 }
0063
0064 ~scoped_demangled_name() BOOST_NOEXCEPT
0065 {
0066 demangle_free( m_p );
0067 }
0068
0069 char const * get() const BOOST_NOEXCEPT
0070 {
0071 return m_p;
0072 }
0073
0074 BOOST_DELETED_FUNCTION(scoped_demangled_name( scoped_demangled_name const& ))
0075 BOOST_DELETED_FUNCTION(scoped_demangled_name& operator= ( scoped_demangled_name const& ))
0076 };
0077
0078
0079 #if defined( BOOST_CORE_HAS_CXXABI_H )
0080
0081 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT
0082 {
0083 int status = 0;
0084 std::size_t size = 0;
0085 return abi::__cxa_demangle( name, NULL, &size, &status );
0086 }
0087
0088 inline void demangle_free( char const * name ) BOOST_NOEXCEPT
0089 {
0090 std::free( const_cast< char* >( name ) );
0091 }
0092
0093 inline std::string demangle( char const * name )
0094 {
0095 scoped_demangled_name demangled_name( name );
0096 char const * p = demangled_name.get();
0097 if( !p )
0098 p = name;
0099 return p;
0100 }
0101
0102 #else
0103
0104 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT
0105 {
0106 return name;
0107 }
0108
0109 inline void demangle_free( char const * ) BOOST_NOEXCEPT
0110 {
0111 }
0112
0113 inline std::string demangle( char const * name )
0114 {
0115 return name;
0116 }
0117
0118 #endif
0119
0120 }
0121
0122 }
0123
0124 #undef BOOST_CORE_HAS_CXXABI_H
0125
0126 #endif