Sierra Toolkit  Version of the Day
Demangle.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 - 2011 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <stk_util/environment/Demangle.hpp>
10 #include <stdlib.h>
11 
12 #if __GNUC__ == 3 || __GNUC__ == 4
13 #include <cxxabi.h>
14 #endif
15 
16 // #if defined __xlC__
17 // #include <demangle.h>
18 // #endif
19 
20 namespace stk_classic {
21 
22 #ifdef STK_USE_PLATFORM_DEMANGLER
23 
24 #if defined(__GNUC__)
25 
26 #if (__GNUC__ == 3)
27 std::string
28 demangle(
29  const char * symbol)
30 {
31 #ifdef PURIFY_BUILD
32  return symbol;
33 #else
34  std::string s;
35  int status = 0;
36 
37  char *demangled_symbol = abi::__cxa_demangle(symbol, 0, 0, &status);
38 
39  if (demangled_symbol) {
40  s = std::string(demangled_symbol);
41  free(demangled_symbol);
42  }
43 
44  if (status != 0)
45  s = std::string(symbol);
46 
47  return s;
48 #endif
49 }
50 
51 #elif (__GNUC__ == 4)
52 std::string
53 demangle(
54  const char * symbol)
55 {
56 #ifdef PURIFY_BUILD
57  return symbol;
58 #else
59  std::string s;
60 
61  int status;
62 
63  char *demangled_symbol = __cxxabiv1::__cxa_demangle(symbol, 0, 0, &status);
64 
65  if (demangled_symbol) {
66  s = std::string(demangled_symbol);
67  free(demangled_symbol);
68  }
69 
70  if (status != 0)
71  s = std::string(symbol);
72 
73  return s;
74 #endif
75 }
76 
77 #endif // (__GNUC__ == 3)
78 
79 #elif defined __xlC__
80 std::string
81 demangle(
82  const char * symbol)
83 {
84  return symbol;
85 // #ifdef PURIFY_BUILD
86 // return symbol;
87 // #else
88 // char *rest;
89 
90 // Name *name = Demangle(symbol, rest) ;
91 
92 // std::string s(name ? name->Text() : symbol);
93 
94 // delete name;
95 
96 // return s;
97 // #endif
98 }
99 
100 #endif // defined __GNUC__
101 
102 #else
103 const char *demangle(const char *symbol) {
104  return symbol;
105 }
106 #endif // STK_USE_PLATFORM_DEMANGLER
107 
108 } // namespace stk_classic
Sierra Toolkit.
const char * demangle(const char *symbol)
Function demangle returns the demangled C++ symbol from the mangled C++ symbol. The mangled named is ...
Definition: Demangle.cpp:103