LLVM  4.0.0
TypeDatabaseVisitor.cpp
Go to the documentation of this file.
1 //===- TypeDatabaseVisitor.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 #include "llvm/ADT/SmallString.h"
13 
14 using namespace llvm;
15 
16 using namespace llvm::codeview;
17 
19  assert(!IsInFieldList);
20  // Reset Name to the empty string. If the visitor sets it, we know it.
21  Name = "";
22 
23  if (Record.Type == LF_FIELDLIST) {
24  // Record that we're in a field list so that members do not get assigned
25  // type indices.
26  IsInFieldList = true;
27  }
28  return Error::success();
29 }
30 
32  if (CVR.Type == LF_FIELDLIST) {
33  assert(IsInFieldList);
34  IsInFieldList = false;
35  }
36  assert(!IsInFieldList);
37 
38  // Record every type that is not a field list member, even if Name is empty.
39  // CVUDTNames is indexed by type index, and must have one entry for every
40  // type. Field list members are not recorded, and are only referenced by
41  // their containing field list record.
42  TypeDB.recordType(Name, CVR);
43  return Error::success();
44 }
45 
47  assert(IsInFieldList);
48  // Reset Name to the empty string. If the visitor sets it, we know it.
49  Name = "";
50  return Error::success();
51 }
52 
54  assert(IsInFieldList);
55  return Error::success();
56 }
57 
59  FieldListRecord &FieldList) {
60  Name = "<field list>";
61  return Error::success();
62 }
63 
66  // Put this in the database so it gets printed with LF_UDT_SRC_LINE.
67  Name = String.getString();
68  return Error::success();
69 }
70 
72  auto Indices = Args.getIndices();
73  uint32_t Size = Indices.size();
74  SmallString<256> TypeName("(");
75  for (uint32_t I = 0; I < Size; ++I) {
76  StringRef ArgTypeName = TypeDB.getTypeName(Indices[I]);
77  TypeName.append(ArgTypeName);
78  if (I + 1 != Size)
79  TypeName.append(", ");
80  }
81  TypeName.push_back(')');
82  Name = TypeDB.saveTypeName(TypeName);
83  return Error::success();
84 }
85 
87  Name = Class.getName();
88  return Error::success();
89 }
90 
92  Name = Union.getName();
93  return Error::success();
94 }
95 
97  Name = Enum.getName();
98  return Error::success();
99 }
100 
102  Name = AT.getName();
103  return Error::success();
104 }
105 
107  Name = VFT.getName();
108  return Error::success();
109 }
110 
113  Name = Id.getName();
114  return Error::success();
115 }
116 
118  ProcedureRecord &Proc) {
119  StringRef ReturnTypeName = TypeDB.getTypeName(Proc.getReturnType());
120  StringRef ArgListTypeName = TypeDB.getTypeName(Proc.getArgumentList());
121  SmallString<256> TypeName(ReturnTypeName);
122  TypeName.push_back(' ');
123  TypeName.append(ArgListTypeName);
124  Name = TypeDB.saveTypeName(TypeName);
125  return Error::success();
126 }
127 
129  MemberFunctionRecord &MF) {
130  StringRef ReturnTypeName = TypeDB.getTypeName(MF.getReturnType());
131  StringRef ClassTypeName = TypeDB.getTypeName(MF.getClassType());
132  StringRef ArgListTypeName = TypeDB.getTypeName(MF.getArgumentList());
133  SmallString<256> TypeName(ReturnTypeName);
134  TypeName.push_back(' ');
135  TypeName.append(ClassTypeName);
136  TypeName.append("::");
137  TypeName.append(ArgListTypeName);
138  Name = TypeDB.saveTypeName(TypeName);
139  return Error::success();
140 }
141 
143  Name = Func.getName();
144  return Error::success();
145 }
146 
149  Name = TS.getName();
150  return Error::success();
151 }
152 
154 
155  if (Ptr.isPointerToMember()) {
156  const MemberPointerInfo &MI = Ptr.getMemberInfo();
157 
158  StringRef PointeeName = TypeDB.getTypeName(Ptr.getReferentType());
159  StringRef ClassName = TypeDB.getTypeName(MI.getContainingType());
160  SmallString<256> TypeName(PointeeName);
161  TypeName.push_back(' ');
162  TypeName.append(ClassName);
163  TypeName.append("::*");
164  Name = TypeDB.saveTypeName(TypeName);
165  } else {
166  SmallString<256> TypeName;
167  if (Ptr.isConst())
168  TypeName.append("const ");
169  if (Ptr.isVolatile())
170  TypeName.append("volatile ");
171  if (Ptr.isUnaligned())
172  TypeName.append("__unaligned ");
173 
174  TypeName.append(TypeDB.getTypeName(Ptr.getReferentType()));
175 
177  TypeName.append("&");
178  else if (Ptr.getMode() == PointerMode::RValueReference)
179  TypeName.append("&&");
180  else if (Ptr.getMode() == PointerMode::Pointer)
181  TypeName.append("*");
182 
183  if (!TypeName.empty())
184  Name = TypeDB.saveTypeName(TypeName);
185  }
186  return Error::success();
187 }
188 
190  uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers());
191 
192  StringRef ModifiedName = TypeDB.getTypeName(Mod.getModifiedType());
193  SmallString<256> TypeName;
194  if (Mods & uint16_t(ModifierOptions::Const))
195  TypeName.append("const ");
196  if (Mods & uint16_t(ModifierOptions::Volatile))
197  TypeName.append("volatile ");
198  if (Mods & uint16_t(ModifierOptions::Unaligned))
199  TypeName.append("__unaligned ");
200  TypeName.append(ModifiedName);
201  Name = TypeDB.saveTypeName(TypeName);
202  return Error::success();
203 }
204 
206  VFTableShapeRecord &Shape) {
207  Name = TypeDB.saveTypeName("<vftable " + utostr(Shape.getEntryCount()) +
208  " methods>");
209  return Error::success();
210 }
211 
213  NestedTypeRecord &Nested) {
214  Name = Nested.getName();
215  return Error::success();
216 }
217 
219  OneMethodRecord &Method) {
220  Name = Method.getName();
221  return Error::success();
222 }
223 
225  OverloadedMethodRecord &Method) {
226  Name = Method.getName();
227  return Error::success();
228 }
229 
232  Name = Field.getName();
233  return Error::success();
234 }
235 
237  StaticDataMemberRecord &Field) {
238  Name = Field.getName();
239  return Error::success();
240 }
241 
243  EnumeratorRecord &Enum) {
244  Name = Enum.getName();
245  return Error::success();
246 }
247 
249  BaseClassRecord &Base) {
250  return Error::success();
251 }
252 
254  VirtualBaseClassRecord &VBase) {
255  return Error::success();
256 }
257 
259  ListContinuationRecord &Cont) {
260  return Error::success();
261 }
262 
264  CVType &CVR, UdtModSourceLineRecord &ModSourceLine) {
265  return Error::success();
266 }
267 
269  UdtSourceLineRecord &SourceLine) {
270  return Error::success();
271 }
272 
274  return Error::success();
275 }
276 
278  CVType &CVR, MethodOverloadListRecord &Overloads) {
279  return Error::success();
280 }
281 
283  return Error::success();
284 }
285 
287  VFPtrRecord &VFP) {
288  return Error::success();
289 }
StringRef getTypeName(TypeIndex Index) const
StringRef getName() const
Definition: TypeRecord.h:364
TypeIndex getArgumentList() const
Definition: TypeRecord.h:172
StringRef saveTypeName(StringRef TypeName)
Saves the name in a StringSet and creates a stable StringRef.
Error visitTypeEnd(CVType &Record) override
Error visitTypeBegin(CVType &Record) override
Paired begin/end actions for all types.
StringRef getString() const
Definition: TypeRecord.h:596
bool isPointerToMember() const
Definition: TypeRecord.h:319
StringRef getName() const
Definition: TypeRecord.h:400
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
TypeIndex getContainingType() const
Definition: TypeRecord.h:113
static Error visitKnownRecord(CVSymbol &Record, SymbolVisitorCallbacks &Callbacks)
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:79
void recordType(StringRef Name, CVType Data)
Records the name of a type, and reserves its type index.
StringRef getName() const
Definition: TypeRecord.h:806
TypeIndex getReturnType() const
Definition: TypeRecord.h:168
Error visitMemberBegin(CVMemberRecord &Record) override
StringRef getName() const
Definition: TypeRecord.h:737
void append(in_iter S, in_iter E)
Append from an iterator pair.
Definition: SmallString.h:75
static Error visitKnownMember(CVMemberRecord &Record, TypeVisitorCallbacks &Callbacks)
StringRef getName() const
Definition: TypeRecord.h:855
LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records together.
Definition: TypeRecord.h:936
For method overload sets. LF_METHOD.
Definition: TypeRecord.h:766
StringRef getName() const
Definition: TypeRecord.h:703
ModifierOptions getModifiers() const
Definition: TypeRecord.h:147
static ErrorSuccess success()
Create a success value.
PointerMode getMode() const
Definition: TypeRecord.h:304
Error visitMemberEnd(CVMemberRecord &Record) override
TypeIndex getModifiedType() const
Definition: TypeRecord.h:146
ArrayRef< TypeIndex > getIndices() const
Definition: TypeRecord.h:252
TypeIndex getArgumentList() const
Definition: TypeRecord.h:206
StringRef getName() const
Definition: TypeRecord.h:433
#define I(x, y, z)
Definition: MD5.cpp:54
MemberPointerInfo getMemberInfo() const
Definition: TypeRecord.h:317
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
static TraceState * TS
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
int * Ptr
TypeIndex getReferentType() const
Definition: TypeRecord.h:297
StringRef getName() const
Definition: TypeRecord.h:617