-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathUdtFieldDefinition.h
173 lines (147 loc) · 3.12 KB
/
UdtFieldDefinition.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
#include "UdtFieldDefinitionBase.h"
#include <string>
class UdtFieldDefinition
: public UdtFieldDefinitionBase
{
public:
struct Settings
{
bool UseStdInt = false;
};
void
VisitBaseType(
const SYMBOL* Symbol
) override
{
//
// BaseType:
// short/int/long/...
//
if (Symbol->BaseType == btFloat && Symbol->Size == 10)
{
m_Comment += " /* 80-bit float */";
}
if (Symbol->IsConst)
{
m_TypePrefix += "const ";
}
if (Symbol->IsVolatile)
{
m_TypePrefix += "volatile ";
}
//
// If this returns null, it probably means BasicTypeMapMSVC and/or BasicTypeMapStdInt are out of date compared to MS DIA.
// Output the (non-compilable) type "<unknown_type>" instead of crashing.
//
const CHAR* BasicTypeString = PDB::GetBasicTypeString(Symbol, m_Settings->UseStdInt);
m_TypePrefix += (BasicTypeString != nullptr ? BasicTypeString : "<unknown_type>");
}
void
VisitPointerTypeEnd(
const SYMBOL* Symbol
) override
{
if (Symbol->u.Pointer.IsReference)
{
m_TypePrefix += "&";
}
else
{
m_TypePrefix += "*";
}
if (Symbol->IsConst)
{
m_TypePrefix += " const";
}
if (Symbol->IsVolatile)
{
m_TypePrefix += " volatile";
}
}
void
VisitArrayTypeEnd(
const SYMBOL* Symbol
) override
{
//
// To my knowledge, array elements can't be declared like that.
//
// if (Symbol->IsConst)
// {
// m_TypePrefix += " const";
// }
//
// if (Symbol->IsVolatile)
// {
// m_TypePrefix += " volatile";
// }
//
if (Symbol->u.Array.ElementCount == 0)
{
//
// Apparently array with 0 element count can exist in PDB.
// But XYZ Name[0] is not compilable.
// This hack "converts" the zero-sized array into the pointer.
//
// Also, size of the symbol is set to 1 instead of 0,
// otherwise we would end up in anonymous union.
//
const_cast<SYMBOL*>(Symbol)->Size = 1;
m_TypePrefix += "*";
m_Comment += " /* zero-length array */";
}
else
{
m_TypeSuffix += "[" + std::to_string(Symbol->u.Array.ElementCount) + "]";
}
}
void
VisitFunctionTypeEnd(
const SYMBOL* Symbol
) override
{
//
// #TODO:
// Currently, show void* instead of functions.
//
m_TypePrefix += "void";
m_Comment += " /* function */";
}
void
SetMemberName(
const CHAR* MemberName
) override
{
m_MemberName = MemberName ? MemberName : std::string();
}
std::string
GetPrintableDefinition() const override
{
return m_TypePrefix + " " + m_MemberName + m_TypeSuffix + m_Comment;
}
void
SetSettings(
void* MemberDefinitionSettings
) override
{
static Settings DefaultSettings;
if (MemberDefinitionSettings == nullptr)
{
MemberDefinitionSettings = &DefaultSettings;
}
m_Settings = static_cast<Settings*>(MemberDefinitionSettings);
}
virtual
void*
GetSettings() override
{
return &m_Settings;
}
private:
std::string m_TypePrefix; // "int*"
std::string m_MemberName; // "XYZ"
std::string m_TypeSuffix; // "[8]"
std::string m_Comment;
Settings* m_Settings;
};