Back to home page

EIC code displayed by LXR

 
 

    


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 // core::demangle
0005 //
0006 // Copyright 2014 Peter Dimov
0007 // Copyright 2014 Andrey Semashev
0008 //
0009 // Distributed under the Boost Software License, Version 1.0.
0010 // See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt
0012 
0013 #include <boost/config.hpp>
0014 #include <string>
0015 
0016 #if defined(BOOST_HAS_PRAGMA_ONCE)
0017 # pragma once
0018 #endif
0019 
0020 // __has_include is currently supported by GCC and Clang. However GCC 4.9 may have issues and
0021 // returns 1 for 'defined( __has_include )', while '__has_include' is actually not supported:
0022 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63662
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 // For some archtectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library
0034 // (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement
0035 // abi::__cxa_demangle(). We detect this implementation by checking the include guard here.
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 } // namespace core
0121 
0122 } // namespace boost
0123 
0124 #undef BOOST_CORE_HAS_CXXABI_H
0125 
0126 #endif // #ifndef BOOST_CORE_DEMANGLE_HPP_INCLUDED