Sierra Toolkit Version of the Day
Demangle.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 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 namespace stk {
00017 
00018 #ifdef STK_USE_PLATFORM_DEMANGLER
00019 
00020 #if defined(__GNUC__)
00021 
00022 #if (__GNUC__ == 3)
00023 std::string
00024 demangle(
00025   const char *  symbol)
00026 {
00027 #ifdef PURIFY_BUILD
00028   return symbol;
00029 #else
00030   std::string   s;
00031   int   status = 0;
00032 
00033   char *demangled_symbol = abi::__cxa_demangle(symbol, 0, 0, &status);
00034 
00035   if (demangled_symbol) {
00036     s = std::string(demangled_symbol);
00037     free(demangled_symbol);
00038   }
00039 
00040   if (status != 0)
00041     s = std::string(symbol);
00042 
00043   return s;
00044 #endif
00045 }
00046 
00047 #elif (__GNUC__ == 4)
00048 std::string
00049 demangle(
00050   const char *  symbol)
00051 {
00052 #ifdef PURIFY_BUILD
00053   return symbol;
00054 #else
00055   std::string   s;
00056 
00057   int   status;
00058 
00059   char *demangled_symbol = __cxxabiv1::__cxa_demangle(symbol, 0, 0, &status);
00060 
00061   if (demangled_symbol) {
00062     s = std::string(demangled_symbol);
00063     free(demangled_symbol);
00064   }
00065 
00066   if (status != 0)
00067     s = std::string(symbol);
00068 
00069   return s;
00070 #endif
00071 }
00072 #endif // (__GNUC__ == 3)
00073 
00074 #endif // defined(__GNUC__)
00075 
00076 #else
00077 const char *demangle(const char *symbol) {
00078   return symbol;
00079 }
00080 #endif // STK_USE_PLATFORM_DEMANGLER
00081 
00082 } // namespace stk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends