Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
demangle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include <string>
5#include <typeinfo>
6
7#if defined(__GNUG__)
8#include <cxxabi.h>
9#elif defined(_MSC_VER)
10#include <DbgHelp.h>
11#include <windows.h>
12// link against Dbghelp.lib
13#pragma comment(lib, "Dbghelp.lib")
14#endif
15
17{
18
22inline std::string demangle(const char* name)
23{
24#if defined(__GNUG__)
25 int status = 0;
26 char* dem = abi::__cxa_demangle(name, nullptr, nullptr, &status);
27 std::string out = (status == 0 && dem) ? dem : name;
28 std::free(dem);
29 return out;
30#elif defined(_MSC_VER)
31 char buffer[1024] = {};
32 // UNDNAME_COMPLETE gives full undecoration
33 if (UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE))
34 return std::string(buffer);
35 else
36 return name;
37#else
38 return name;
39#endif
40}
41
42template <typename T> std::string demangle_type() { return demangle(typeid(T).name()); }
43
44} // namespace uni20::demangle
Definition demangle.hpp:17
std::string demangle_type()
Definition demangle.hpp:42
std::string demangle(const char *name)
Turn a compiler‐mangled name into a human‐readable one.
Definition demangle.hpp:22