|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 - 2011 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #include <stk_util/environment/Demangle.hpp> 00010 #include <stdlib.h> 00011 00012 #if __GNUC__ == 3 || __GNUC__ == 4 00013 #include <cxxabi.h> 00014 #endif 00015 00016 // #if defined __xlC__ 00017 // #include <demangle.h> 00018 // #endif 00019 00020 namespace stk_classic { 00021 00022 #ifdef STK_USE_PLATFORM_DEMANGLER 00023 00024 #if defined(__GNUC__) 00025 00026 #if (__GNUC__ == 3) 00027 std::string 00028 demangle( 00029 const char * symbol) 00030 { 00031 #ifdef PURIFY_BUILD 00032 return symbol; 00033 #else 00034 std::string s; 00035 int status = 0; 00036 00037 char *demangled_symbol = abi::__cxa_demangle(symbol, 0, 0, &status); 00038 00039 if (demangled_symbol) { 00040 s = std::string(demangled_symbol); 00041 free(demangled_symbol); 00042 } 00043 00044 if (status != 0) 00045 s = std::string(symbol); 00046 00047 return s; 00048 #endif 00049 } 00050 00051 #elif (__GNUC__ == 4) 00052 std::string 00053 demangle( 00054 const char * symbol) 00055 { 00056 #ifdef PURIFY_BUILD 00057 return symbol; 00058 #else 00059 std::string s; 00060 00061 int status; 00062 00063 char *demangled_symbol = __cxxabiv1::__cxa_demangle(symbol, 0, 0, &status); 00064 00065 if (demangled_symbol) { 00066 s = std::string(demangled_symbol); 00067 free(demangled_symbol); 00068 } 00069 00070 if (status != 0) 00071 s = std::string(symbol); 00072 00073 return s; 00074 #endif 00075 } 00076 00077 #endif // (__GNUC__ == 3) 00078 00079 #elif defined __xlC__ 00080 std::string 00081 demangle( 00082 const char * symbol) 00083 { 00084 return symbol; 00085 // #ifdef PURIFY_BUILD 00086 // return symbol; 00087 // #else 00088 // char *rest; 00089 00090 // Name *name = Demangle(symbol, rest) ; 00091 00092 // std::string s(name ? name->Text() : symbol); 00093 00094 // delete name; 00095 00096 // return s; 00097 // #endif 00098 } 00099 00100 #endif // defined __GNUC__ 00101 00102 #else 00103 const char *demangle(const char *symbol) { 00104 return symbol; 00105 } 00106 #endif // STK_USE_PLATFORM_DEMANGLER 00107 00108 } // namespace stk_classic