LLVM  4.0.0
TypeDatabase.cpp
Go to the documentation of this file.
1 //===- TypeDatabase.cpp --------------------------------------- *- C++ --*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
12 using namespace llvm;
13 using namespace llvm::codeview;
14 
15 namespace {
16 struct SimpleTypeEntry {
19 };
20 }
21 
22 /// The names here all end in "*". If the simple type is a pointer type, we
23 /// return the whole name. Otherwise we lop off the last character in our
24 /// StringRef.
25 static const SimpleTypeEntry SimpleTypeNames[] = {
26  {"void*", SimpleTypeKind::Void},
27  {"<not translated>*", SimpleTypeKind::NotTranslated},
28  {"HRESULT*", SimpleTypeKind::HResult},
29  {"signed char*", SimpleTypeKind::SignedCharacter},
30  {"unsigned char*", SimpleTypeKind::UnsignedCharacter},
32  {"wchar_t*", SimpleTypeKind::WideCharacter},
33  {"char16_t*", SimpleTypeKind::Character16},
34  {"char32_t*", SimpleTypeKind::Character32},
35  {"__int8*", SimpleTypeKind::SByte},
36  {"unsigned __int8*", SimpleTypeKind::Byte},
37  {"short*", SimpleTypeKind::Int16Short},
38  {"unsigned short*", SimpleTypeKind::UInt16Short},
39  {"__int16*", SimpleTypeKind::Int16},
40  {"unsigned __int16*", SimpleTypeKind::UInt16},
41  {"long*", SimpleTypeKind::Int32Long},
42  {"unsigned long*", SimpleTypeKind::UInt32Long},
43  {"int*", SimpleTypeKind::Int32},
44  {"unsigned*", SimpleTypeKind::UInt32},
45  {"__int64*", SimpleTypeKind::Int64Quad},
46  {"unsigned __int64*", SimpleTypeKind::UInt64Quad},
47  {"__int64*", SimpleTypeKind::Int64},
48  {"unsigned __int64*", SimpleTypeKind::UInt64},
49  {"__int128*", SimpleTypeKind::Int128},
50  {"unsigned __int128*", SimpleTypeKind::UInt128},
51  {"__half*", SimpleTypeKind::Float16},
52  {"float*", SimpleTypeKind::Float32},
54  {"__float48*", SimpleTypeKind::Float48},
55  {"double*", SimpleTypeKind::Float64},
56  {"long double*", SimpleTypeKind::Float80},
57  {"__float128*", SimpleTypeKind::Float128},
58  {"_Complex float*", SimpleTypeKind::Complex32},
59  {"_Complex double*", SimpleTypeKind::Complex64},
60  {"_Complex long double*", SimpleTypeKind::Complex80},
61  {"_Complex __float128*", SimpleTypeKind::Complex128},
62  {"bool*", SimpleTypeKind::Boolean8},
63  {"__bool16*", SimpleTypeKind::Boolean16},
64  {"__bool32*", SimpleTypeKind::Boolean32},
65  {"__bool64*", SimpleTypeKind::Boolean64},
66 };
67 
68 /// Gets the type index for the next type record.
70  return TypeIndex(TypeIndex::FirstNonSimpleIndex + CVUDTNames.size());
71 }
72 
73 /// Records the name of a type, and reserves its type index.
75  CVUDTNames.push_back(Name);
76  TypeRecords.push_back(Data);
77 }
78 
79 /// Saves the name in a StringSet and creates a stable StringRef.
81  return TypeNameStorage.save(TypeName);
82 }
83 
85  if (Index.isNoneType())
86  return "<no type>";
87 
88  if (Index.isSimple()) {
89  // This is a simple type.
90  for (const auto &SimpleTypeName : SimpleTypeNames) {
91  if (SimpleTypeName.Kind == Index.getSimpleKind()) {
93  return SimpleTypeName.Name.drop_back(1);
94  // Otherwise, this is a pointer type. We gloss over the distinction
95  // between near, far, 64, 32, etc, and just give a pointer type.
96  return SimpleTypeName.Name;
97  }
98  }
99  return "<unknown simple type>";
100  }
101 
103  if (I < CVUDTNames.size())
104  return CVUDTNames[I];
105 
106  return "<unknown UDT>";
107 }
108 
111  return I < CVUDTNames.size();
112 }
113 
114 uint32_t TypeDatabase::size() const { return CVUDTNames.size(); }
bool isSimple() const
Definition: TypeIndex.h:105
StringRef getTypeName(TypeIndex Index) const
StringRef saveTypeName(StringRef TypeName)
Saves the name in a StringSet and creates a stable StringRef.
bool isNoneType() const
Definition: TypeIndex.h:107
TypeIndex getNextTypeIndex() const
Gets the type index for the next type record.
bool containsTypeIndex(TypeIndex Index) const
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:91
A 32-bit type reference.
Definition: TypeIndex.h:89
void recordType(StringRef Name, CVType Data)
Records the name of a type, and reserves its type index.
uint32_t getIndex() const
Definition: TypeIndex.h:103
static const SimpleTypeEntry SimpleTypeNames[]
The names here all end in "*".
SimpleTypeKind getSimpleKind() const
Definition: TypeIndex.h:109
StringRef save(const char *S)
Definition: StringSaver.h:26
#define I(x, y, z)
Definition: MD5.cpp:54
const unsigned Kind
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:114
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition: StringRef.h:643