SUNphi  1.0
Demangle.hpp
Go to the documentation of this file.
1 #ifndef _DEMANGLE_HPP
2 #define _DEMANGLE_HPP
3 
4 /// \file Demangle.hpp
5 ///
6 /// \brief Demangle symbols using abi
7 
8 #if __has_include(<cxxabi.h>)
9 
10  #include <cxxabi.h>
11 
12  /// Declares demanglability
13  #define CAN_DEMANGLE
14 
15 #endif
16 
17 #include <utility/String.hpp>
18 
19 namespace SUNphi
20 {
21  /// Demangle a string
22  ///
23  /// If the compiler has no abi functionality, the original string is
24  /// returned.
25  template <typename T> // Type of the demangling object
26  std::string demangle(const T& what) ///< What to demangle
27  {
28 
29 #ifdef CAN_DEMANGLE
30 
31  /// Returned status of demangle
32  int status;
33 
34  /// Demangled
35  char* name=
36  abi::__cxa_demangle(cString(what),0,0,&status);
37 
38  /// Copy the result
39  std::string out=
40  (status==0)?
41  name:
42  what+" (failed demangle)";
43 
44  // Free if succeded
45  if(status==0)
46  free(name);
47 
48  return
49  out;
50 
51 #else
52 
53  return
54  "(unable to demangle)";
55 
56 #endif
57 
58  }
59 }
60 
61 #endif
std::string demangle(const T &what)
Definition: Demangle.hpp:26