File indexing completed on 2026-05-10 08:44:34
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_SUPPORT_TYPENAME_H
0010 #define LLVM_SUPPORT_TYPENAME_H
0011
0012 #include "llvm/ADT/StringRef.h"
0013
0014 namespace llvm {
0015
0016 namespace detail {
0017 template <typename DesiredTypeName> inline StringRef getTypeNameImpl() {
0018 #if defined(__clang__) || defined(__GNUC__)
0019 StringRef Name = __PRETTY_FUNCTION__;
0020
0021 StringRef Key = "DesiredTypeName = ";
0022 Name = Name.substr(Name.find(Key));
0023 assert(!Name.empty() && "Unable to find the template parameter!");
0024 Name = Name.drop_front(Key.size());
0025
0026 assert(Name.ends_with("]") && "Name doesn't end in the substitution key!");
0027 return Name.drop_back(1);
0028 #elif defined(_MSC_VER)
0029 StringRef Name = __FUNCSIG__;
0030
0031 StringRef Key = "getTypeNameImpl<";
0032 Name = Name.substr(Name.find(Key));
0033 assert(!Name.empty() && "Unable to find the function name!");
0034 Name = Name.drop_front(Key.size());
0035
0036 for (StringRef Prefix : {"class ", "struct ", "union ", "enum "})
0037 if (Name.starts_with(Prefix)) {
0038 Name = Name.drop_front(Prefix.size());
0039 break;
0040 }
0041
0042 auto AnglePos = Name.rfind('>');
0043 assert(AnglePos != StringRef::npos && "Unable to find the closing '>'!");
0044 return Name.substr(0, AnglePos);
0045 #else
0046
0047
0048 return "UNKNOWN_TYPE";
0049 #endif
0050 }
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template <typename DesiredTypeName> inline StringRef getTypeName() {
0064 static StringRef Name = detail::getTypeNameImpl<DesiredTypeName>();
0065 return Name;
0066 }
0067
0068 }
0069
0070 #endif