-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUDT.cpp
218 lines (174 loc) · 4.59 KB
/
UDT.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include "stdafx.h"
#include "UDT.h"
#include "DataMember.h"
#include "Function.h"
#include "useful.h"
UDT::UDT()
{
}
UDT::UDT(const std::wstring name) : Name(name)
{
}
UDT::UDT(CComPtr<IDiaSymbol> pIDiaSymbol) : Symbol(pIDiaSymbol)
{
DWORD tag;
checkResult(pIDiaSymbol->get_symTag(&tag));
if(SymTagUDT != tag)
{
throw 0;
}
}
UDT::UDT(const UDT& other) : Symbol(other.Symbol)
{
}
CComPtr<IDiaSymbol> UDT::sym() const
{
return Symbol;
}
CComPtr<IDiaEnumSymbols> UDT::children(enum SymTagEnum type) const
{
CComPtr<IDiaEnumSymbols> pEnumSymbols;
checkResult(sym()->findChildren(type,
NULL,nsNone,&pEnumSymbols));
return pEnumSymbols;
}
std::wstring UDT::getName() const
{
if(Name.empty())
Name = ::getName(sym());
return Name;
}
std::wstring UDT::getKind() const
{
return ::getKind(sym());
}
bool UDT::nested() const
{
BOOL isNested = FALSE;
checkResult(sym()->get_nested(&isNested));
return !!isNested;
}
UDT::Bases UDT::getBases(int depth) const
{
UDT::Bases ret;
CComPtr<IDiaEnumSymbols> pEnumSymbols = children(SymTagBaseClass);
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));//baseClass
DWORD access;
checkResult(pIDiaSymbol->get_access(&access));
CComPtr<IDiaSymbol> pIDiaSymbol2;
checkResult(pIDiaSymbol->get_type(&pIDiaSymbol2));//UDT
UDT udt(pIDiaSymbol2);
UDT::Bases ret_recurse = udt.getBases(depth+1);
ret.insert(ret.end(),ret_recurse.begin(),ret_recurse.end());
ret.push_back(std::pair<UDT,std::pair<int,int> >(udt,std::pair<int,int>(depth,access)));
}
return ret;
}
std::wstring UDT::getEnums() const
{
CComPtr<IDiaEnumSymbols> pEnumSymbols = children(SymTagEnum);
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
std::wstring ret;
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));//baseType
ret += L"enum " + ::getName(pIDiaSymbol) + L" { ";
CComPtr<IDiaEnumSymbols> pEnumConstants;
checkResult(pIDiaSymbol->findChildren(SymTagData, //SymTagConstant
NULL,nsNone,&pEnumConstants));
LONG countConstants;
checkResult(pEnumConstants->get_Count(&countConstants));
for(int j = 0; j < countConstants; ++j)
{
if(j) ret += L", ";
CComPtr<IDiaSymbol> pIDiaConstant;
checkResult(pEnumConstants->Item(j,&pIDiaConstant));//baseType
DWORD tagSym;
checkResult(pIDiaConstant->get_symTag(&tagSym));
ret += ::getName(pIDiaConstant);
}
ret += L" };\n";
}
return ret;
}
std::wstring UDT::getTypedefs() const
{
CComPtr<IDiaEnumSymbols> pEnumSymbols = children(SymTagTypedef);
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
std::wstring ret;
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));//baseType
CComPtr<IDiaSymbol> type;
checkResult(pIDiaSymbol->get_type(&type));
ret += L"typedef " + expandType(type) + L" " + ::getName(pIDiaSymbol) + L";\n";
}
return ret;
}
UDT::DataMembers UDT::getDataMembers() const
{
DataMembers ret;
CComPtr<IDiaEnumSymbols> pEnumSymbols = children(SymTagData);
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));//baseType
DataMember val(pIDiaSymbol);
ret.push_back(val);
}
return ret;
}
UDT::Functions UDT::getFunctions() const
{
Functions ret;
CComPtr<IDiaEnumSymbols> pEnumSymbols;
checkResult(sym()->findChildren(SymTagFunction,
NULL,nsNone,&pEnumSymbols));
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));
Function val(pIDiaSymbol);
ret.push_back(val);
}
return ret;
}
CV_access_e UDT::getDefaultProtection() const
{
std::wstring ret;
DWORD kind = 0;
checkResult(sym()->get_udtKind(&kind));
if(UdtClass == kind)
return CV_private;
return CV_public;
}
UDT::Nested UDT::getNested() const
{
Nested ret;
CComPtr<IDiaEnumSymbols> pEnumSymbols;
checkResult(sym()->findChildren(SymTagUDT,
NULL,nsNone,&pEnumSymbols));
LONG count;
checkResult(pEnumSymbols->get_Count(&count));
for(int i = 0; i < count; ++i)
{
CComPtr<IDiaSymbol> pIDiaSymbol;
checkResult(pEnumSymbols->Item(i,&pIDiaSymbol));
UDT udt(pIDiaSymbol);
ret.push_back(udt);
}
return ret;
}