forked from boostorg/core
Merge branch 'develop'
This commit is contained in:
103
include/boost/core/demangled_name.hpp
Normal file
103
include/boost/core/demangled_name.hpp
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#ifndef BOOST_CORE_DEMANGLED_NAME_HPP_INCLUDED
|
||||||
|
#define BOOST_CORE_DEMANGLED_NAME_HPP_INCLUDED
|
||||||
|
|
||||||
|
// MS compatible compilers support #pragma once
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// core::demangled_name( BOOST_CORE_TYPEID(T) )
|
||||||
|
//
|
||||||
|
// Copyright 2014 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/core/typeinfo.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
|
||||||
|
# include <cxxabi.h>
|
||||||
|
# include <cstdlib>
|
||||||
|
# include <cstddef>
|
||||||
|
# define BOOST_CORE_HAS_CXXABI_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace core
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
#if defined( BOOST_CORE_HAS_CXXABI_H )
|
||||||
|
|
||||||
|
// lifted from boost/exception/detail/type_info.hpp
|
||||||
|
|
||||||
|
inline std::string demangle( char const * name )
|
||||||
|
{
|
||||||
|
struct auto_free
|
||||||
|
{
|
||||||
|
explicit auto_free( char * ptr ): p( ptr )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~auto_free()
|
||||||
|
{
|
||||||
|
std::free( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
char * p;
|
||||||
|
};
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
std::size_t size = 0;
|
||||||
|
|
||||||
|
auto_free demangled( abi::__cxa_demangle( name, NULL, &size, &status ) );
|
||||||
|
|
||||||
|
if( demangled.p )
|
||||||
|
{
|
||||||
|
return demangled.p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
inline std::string demangle( char const * name )
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
inline std::string demangled_name( core::typeinfo const & ti )
|
||||||
|
{
|
||||||
|
#if defined( BOOST_NO_TYPEID )
|
||||||
|
|
||||||
|
return ti.name();
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
return core::detail::demangle( ti.name() );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#undef BOOST_CORE_HAS_CXXABI_H
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_CORE_DEMANGLED_NAME_HPP_INCLUDED
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <boost/core/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/core/typeinfo.hpp>
|
#include <boost/core/typeinfo.hpp>
|
||||||
|
#include <boost/core/demangled_name.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@@ -36,7 +37,7 @@ template< class T > inline void test_trait_impl( char const * trait, void (*)( T
|
|||||||
{
|
{
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||||
<< file << "(" << line << "): predicate '" << trait << "' ["
|
<< file << "(" << line << "): predicate '" << trait << "' ["
|
||||||
<< BOOST_CORE_TYPEID(T).name() << "]"
|
<< boost::core::demangled_name( BOOST_CORE_TYPEID(T) ) << "]"
|
||||||
<< " test failed in function '" << function
|
<< " test failed in function '" << function
|
||||||
<< "' (should have been " << ( expected? "true": "false" ) << ")"
|
<< "' (should have been " << ( expected? "true": "false" ) << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@@ -68,3 +68,5 @@ run typeinfo_test.cpp : : : <rtti>off : typeinfo_test_no_rtti ;
|
|||||||
|
|
||||||
run iterator_test.cpp ;
|
run iterator_test.cpp ;
|
||||||
run detail_iterator_test.cpp ;
|
run detail_iterator_test.cpp ;
|
||||||
|
|
||||||
|
run demangled_name_test.cpp : : : <test-info>always_show_run_output ;
|
||||||
|
24
test/demangled_name_test.cpp
Normal file
24
test/demangled_name_test.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// Trivial test for core::demangled_name
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 Peter Dimov
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/core/demangled_name.hpp>
|
||||||
|
#include <boost/core/typeinfo.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
template<class T1, class T2> struct Y1
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
typedef Y1<int, long> T;
|
||||||
|
std::cout << boost::core::demangled_name( BOOST_CORE_TYPEID( T ) );
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user