Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | #ifndef SUPPORT_DEMANGLE_H |
| 11 | #define SUPPORT_DEMANGLE_H |
| 12 | |
| 13 | #include "test_macros.h" |
| 14 | #include <string> |
| 15 | #include <cstdlib> |
| 16 | |
| 17 | #if !defined(TEST_HAS_NO_DEMANGLE) |
| 18 | # if defined(__GNUC__) || defined(__clang__) |
Eric Fiselier | 121baf4 | 2017-01-14 20:21:18 +0000 | [diff] [blame] | 19 | # if __has_include("cxxabi.h") && !defined(_LIBCPP_ABI_MICROSOFT) |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 20 | # include "cxxabi.h" |
| 21 | # else |
| 22 | # define TEST_HAS_NO_DEMANGLE |
| 23 | # endif |
| 24 | # else |
| 25 | # define TEST_HAS_NO_DEMANGLE |
| 26 | # endif |
| 27 | #endif |
| 28 | |
| 29 | #if defined(TEST_HAS_NO_DEMANGLE) |
| 30 | inline std::string demangle(const char* mangled_name) { |
| 31 | return mangled_name; |
| 32 | } |
| 33 | #else |
| 34 | template <size_t N> struct Printer; |
| 35 | inline std::string demangle(const char* mangled_name) { |
| 36 | int status = 0; |
Eric Fiselier | d1e211a | 2017-01-20 00:00:31 +0000 | [diff] [blame] | 37 | char* out = __cxxabiv1::__cxa_demangle(mangled_name, nullptr, nullptr, &status); |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 38 | if (out != nullptr) { |
| 39 | std::string res(out); |
| 40 | std::free(out); |
| 41 | return res; |
| 42 | } |
| 43 | return mangled_name; |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | #endif // SUPPORT_DEMANGLE_H |