LLVM  4.0.0
CVTypeVisitor.cpp
Go to the documentation of this file.
1 //===- CVTypeVisitor.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 
16 
17 using namespace llvm;
18 using namespace llvm::codeview;
19 
21  : Callbacks(Callbacks) {}
22 
23 template <typename T>
25  TypeRecordKind RK = static_cast<TypeRecordKind>(Record.Type);
26  T KnownRecord(RK);
27  if (auto EC = Callbacks.visitKnownRecord(Record, KnownRecord))
28  return EC;
29  return Error::success();
30 }
31 
32 template <typename T>
34  TypeVisitorCallbacks &Callbacks) {
35  TypeRecordKind RK = static_cast<TypeRecordKind>(Record.Kind);
36  T KnownRecord(RK);
37  if (auto EC = Callbacks.visitKnownMember(Record, KnownRecord))
38  return EC;
39  return Error::success();
40 }
41 
43  if (auto EC = Callbacks.visitTypeBegin(Record))
44  return EC;
45 
46  switch (Record.Type) {
47  default:
48  if (auto EC = Callbacks.visitUnknownType(Record))
49  return EC;
50  break;
51 #define TYPE_RECORD(EnumName, EnumVal, Name) \
52  case EnumName: { \
53  if (auto EC = visitKnownRecord<Name##Record>(Record, Callbacks)) \
54  return EC; \
55  break; \
56  }
57 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
58  TYPE_RECORD(EnumVal, EnumVal, AliasName)
59 #define MEMBER_RECORD(EnumName, EnumVal, Name)
60 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
61 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
62  }
63 
64  if (auto EC = Callbacks.visitTypeEnd(Record))
65  return EC;
66 
67  return Error::success();
68 }
69 
71  TypeVisitorCallbacks &Callbacks) {
72  if (auto EC = Callbacks.visitMemberBegin(Record))
73  return EC;
74 
75  switch (Record.Kind) {
76  default:
77  if (auto EC = Callbacks.visitUnknownMember(Record))
78  return EC;
79  break;
80 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
81  case EnumName: { \
82  if (auto EC = visitKnownMember<Name##Record>(Record, Callbacks)) \
83  return EC; \
84  break; \
85  }
86 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
87  MEMBER_RECORD(EnumVal, EnumVal, AliasName)
88 #define TYPE_RECORD(EnumName, EnumVal, Name)
89 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
90 #include "llvm/DebugInfo/CodeView/TypeRecords.def"
91  }
92 
93  if (auto EC = Callbacks.visitMemberEnd(Record))
94  return EC;
95 
96  return Error::success();
97 }
98 
100  return ::visitMemberRecord(Record, Callbacks);
101 }
102 
103 /// Visits the type records in Data. Sets the error flag on parse failures.
105  for (auto I : Types) {
106  if (auto EC = visitTypeRecord(I))
107  return EC;
108  }
109  return Error::success();
110 }
111 
113  FieldListDeserializer Deserializer(Reader);
115  Pipeline.addCallbackToPipeline(Deserializer);
116  Pipeline.addCallbackToPipeline(Callbacks);
117 
118  TypeLeafKind Leaf;
119  while (!Reader.empty()) {
120  if (auto EC = Reader.readEnum(Leaf))
121  return EC;
122 
124  Record.Kind = Leaf;
125  if (auto EC = ::visitMemberRecord(Record, Pipeline))
126  return EC;
127  }
128 
129  return Error::success();
130 }
131 
133  msf::ByteStream S(Data);
134  msf::StreamReader SR(S);
135  return visitFieldListMemberStream(SR);
136 }
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:28
CVTypeVisitor(TypeVisitorCallbacks &Callbacks)
Error readEnum(T &Dest)
Definition: StreamReader.h:45
virtual Error visitUnknownMember(CVMemberRecord &Record)
Error visitTypeStream(const CVTypeArray &Types)
Visits the type records in Data. Sets the error flag on parse failures.
virtual Error visitUnknownType(CVType &Record)
Action to take on unknown types. By default, they are ignored.
virtual Error visitTypeEnd(CVType &Record)
TypeRecordKind
Distinguishes individual records in .debug$T section or PDB type stream.
Definition: CodeView.h:21
Error visitTypeRecord(CVType &Record)
static Error visitKnownMember(CVMemberRecord &Record, TypeVisitorCallbacks &Callbacks)
static Error visitMemberRecord(CVMemberRecord &Record, TypeVisitorCallbacks &Callbacks)
static ErrorSuccess success()
Create a success value.
Error visitFieldListMemberStream(ArrayRef< uint8_t > FieldList)
virtual Error visitMemberBegin(CVMemberRecord &Record)
virtual Error visitTypeBegin(CVType &Record)
Paired begin/end actions for all types.
#define I(x, y, z)
Definition: MD5.cpp:54
static Error visitKnownRecord(CVType &Record, TypeVisitorCallbacks &Callbacks)
Lightweight error class with error context and mandatory checking.
void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks)
virtual Error visitMemberEnd(CVMemberRecord &Record)
Error visitMemberRecord(CVMemberRecord &Record)