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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
//===--- DeclBase.cpp - Declaration AST Node Implementation ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Decl and DeclContext classes.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/DeclBase.h"
#include "clang/AST/ASTContext.h"
#include "llvm/ADT/DenseMap.h"
using namespace clang;
//===----------------------------------------------------------------------===//
// Statistics
//===----------------------------------------------------------------------===//
// temporary statistics gathering
static unsigned nFuncs = 0;
static unsigned nVars = 0;
static unsigned nParmVars = 0;
static unsigned nSUC = 0;
static unsigned nEnumConst = 0;
static unsigned nEnumDecls = 0;
static unsigned nNamespaces = 0;
static unsigned nTypedef = 0;
static unsigned nFieldDecls = 0;
static unsigned nInterfaceDecls = 0;
static unsigned nClassDecls = 0;
static unsigned nMethodDecls = 0;
static unsigned nProtocolDecls = 0;
static unsigned nForwardProtocolDecls = 0;
static unsigned nCategoryDecls = 0;
static unsigned nIvarDecls = 0;
static unsigned nObjCImplementationDecls = 0;
static unsigned nObjCCategoryImpl = 0;
static unsigned nObjCCompatibleAlias = 0;
static unsigned nObjCPropertyDecl = 0;
static unsigned nObjCPropertyImplDecl = 0;
static unsigned nLinkageSpecDecl = 0;
static unsigned nFileScopeAsmDecl = 0;
static bool StatSwitch = false;
// This keeps track of all decl attributes. Since so few decls have attrs, we
// keep them in a hash map instead of wasting space in the Decl class.
typedef llvm::DenseMap<const Decl*, Attr*> DeclAttrMapTy;
static DeclAttrMapTy *DeclAttrs = 0;
const char *Decl::getDeclKindName() const {
switch (DeclKind) {
default: assert(0 && "Unknown decl kind!");
case Namespace: return "Namespace";
case Typedef: return "Typedef";
case Function: return "Function";
case Var: return "Var";
case ParmVar: return "ParmVar";
case EnumConstant: return "EnumConstant";
case ObjCIvar: return "ObjCIvar";
case ObjCInterface: return "ObjCInterface";
case ObjCClass: return "ObjCClass";
case ObjCMethod: return "ObjCMethod";
case ObjCProtocol: return "ObjCProtocol";
case ObjCForwardProtocol: return "ObjCForwardProtocol";
case Struct: return "Struct";
case Union: return "Union";
case Class: return "Class";
case Enum: return "Enum";
}
}
bool Decl::CollectingStats(bool Enable) {
if (Enable)
StatSwitch = true;
return StatSwitch;
}
void Decl::PrintStats() {
fprintf(stderr, "*** Decl Stats:\n");
fprintf(stderr, " %d decls total.\n",
int(nFuncs+nVars+nParmVars+nFieldDecls+nSUC+
nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls+
nNamespaces));
fprintf(stderr, " %d namespace decls, %d each (%d bytes)\n",
nNamespaces, (int)sizeof(NamespaceDecl),
int(nNamespaces*sizeof(NamespaceDecl)));
fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
fprintf(stderr, " %d variable decls, %d each (%d bytes)\n",
nVars, (int)sizeof(VarDecl),
int(nVars*sizeof(VarDecl)));
fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n",
nParmVars, (int)sizeof(ParmVarDecl),
int(nParmVars*sizeof(ParmVarDecl)));
fprintf(stderr, " %d field decls, %d each (%d bytes)\n",
nFieldDecls, (int)sizeof(FieldDecl),
int(nFieldDecls*sizeof(FieldDecl)));
fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n",
nSUC, (int)sizeof(RecordDecl),
int(nSUC*sizeof(RecordDecl)));
fprintf(stderr, " %d enum decls, %d each (%d bytes)\n",
nEnumDecls, (int)sizeof(EnumDecl),
int(nEnumDecls*sizeof(EnumDecl)));
fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n",
nEnumConst, (int)sizeof(EnumConstantDecl),
int(nEnumConst*sizeof(EnumConstantDecl)));
fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n",
nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl)));
// Objective-C decls...
fprintf(stderr, " %d interface decls, %d each (%d bytes)\n",
nInterfaceDecls, (int)sizeof(ObjCInterfaceDecl),
int(nInterfaceDecls*sizeof(ObjCInterfaceDecl)));
fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n",
nIvarDecls, (int)sizeof(ObjCIvarDecl),
int(nIvarDecls*sizeof(ObjCIvarDecl)));
fprintf(stderr, " %d class decls, %d each (%d bytes)\n",
nClassDecls, (int)sizeof(ObjCClassDecl),
int(nClassDecls*sizeof(ObjCClassDecl)));
fprintf(stderr, " %d method decls, %d each (%d bytes)\n",
nMethodDecls, (int)sizeof(ObjCMethodDecl),
int(nMethodDecls*sizeof(ObjCMethodDecl)));
fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n",
nProtocolDecls, (int)sizeof(ObjCProtocolDecl),
int(nProtocolDecls*sizeof(ObjCProtocolDecl)));
fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n",
nForwardProtocolDecls, (int)sizeof(ObjCForwardProtocolDecl),
int(nForwardProtocolDecls*sizeof(ObjCForwardProtocolDecl)));
fprintf(stderr, " %d category decls, %d each (%d bytes)\n",
nCategoryDecls, (int)sizeof(ObjCCategoryDecl),
int(nCategoryDecls*sizeof(ObjCCategoryDecl)));
fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
nObjCImplementationDecls, (int)sizeof(ObjCImplementationDecl),
int(nObjCImplementationDecls*sizeof(ObjCImplementationDecl)));
fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
nObjCCategoryImpl, (int)sizeof(ObjCCategoryImplDecl),
int(nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl)));
fprintf(stderr, " %d compatibility alias decls, %d each (%d bytes)\n",
nObjCCompatibleAlias, (int)sizeof(ObjCCompatibleAliasDecl),
int(nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl)));
fprintf(stderr, " %d property decls, %d each (%d bytes)\n",
nObjCPropertyDecl, (int)sizeof(ObjCPropertyDecl),
int(nObjCPropertyDecl*sizeof(ObjCPropertyDecl)));
fprintf(stderr, " %d property implementation decls, %d each (%d bytes)\n",
nObjCPropertyImplDecl, (int)sizeof(ObjCPropertyImplDecl),
int(nObjCPropertyImplDecl*sizeof(ObjCPropertyImplDecl)));
fprintf(stderr, "Total bytes = %d\n",
int(nFuncs*sizeof(FunctionDecl)+
nVars*sizeof(VarDecl)+nParmVars*sizeof(ParmVarDecl)+
nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+
nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
nTypedef*sizeof(TypedefDecl)+
nInterfaceDecls*sizeof(ObjCInterfaceDecl)+
nIvarDecls*sizeof(ObjCIvarDecl)+
nClassDecls*sizeof(ObjCClassDecl)+
nMethodDecls*sizeof(ObjCMethodDecl)+
nProtocolDecls*sizeof(ObjCProtocolDecl)+
nForwardProtocolDecls*sizeof(ObjCForwardProtocolDecl)+
nCategoryDecls*sizeof(ObjCCategoryDecl)+
nObjCImplementationDecls*sizeof(ObjCImplementationDecl)+
nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl)+
nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl)+
nObjCPropertyDecl*sizeof(ObjCPropertyDecl)+
nObjCPropertyImplDecl*sizeof(ObjCPropertyImplDecl)+
nLinkageSpecDecl*sizeof(LinkageSpecDecl)+
nFileScopeAsmDecl*sizeof(FileScopeAsmDecl)+
nNamespaces*sizeof(NamespaceDecl)));
}
void Decl::addDeclKind(Kind k) {
switch (k) {
case Namespace: nNamespaces++; break;
case Typedef: nTypedef++; break;
case Function: nFuncs++; break;
case Var: nVars++; break;
case ParmVar: nParmVars++; break;
case EnumConstant: nEnumConst++; break;
case Field: nFieldDecls++; break;
case Struct: case Union: case Class: nSUC++; break;
case Enum: nEnumDecls++; break;
case ObjCInterface: nInterfaceDecls++; break;
case ObjCClass: nClassDecls++
|