blob: da7aab9bcca2b83e51797ff6bb8784dc9971bd0d [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Decl class and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
Steve Naroff980e5082007-10-01 19:00:59 +000015#include "clang/AST/DeclObjC.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Lex/IdentifierTable.h"
17using namespace clang;
18
19// temporary statistics gathering
20static unsigned nFuncs = 0;
21static unsigned nBlockVars = 0;
22static unsigned nFileVars = 0;
23static unsigned nParmVars = 0;
24static unsigned nSUC = 0;
25static unsigned nEnumConst = 0;
26static unsigned nEnumDecls = 0;
27static unsigned nTypedef = 0;
28static unsigned nFieldDecls = 0;
Steve Naroff3536b442007-09-06 21:24:23 +000029static unsigned nInterfaceDecls = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000030static unsigned nClassDecls = 0;
31static unsigned nMethodDecls = 0;
32static unsigned nProtocolDecls = 0;
Fariborz Jahanian894c57f2007-09-21 15:40:54 +000033static unsigned nForwardProtocolDecls = 0;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +000034static unsigned nCategoryDecls = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000035static unsigned nIvarDecls = 0;
Fariborz Jahanianccb4f312007-09-25 18:38:09 +000036static unsigned nObjcImplementationDecls = 0;
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +000037static unsigned nObjcCategoryImpl = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000038
Reid Spencer5f016e22007-07-11 17:01:13 +000039static bool StatSwitch = false;
40
Steve Naroffe5ea3802007-09-17 14:49:06 +000041const char *Decl::getDeclKindName() const {
Steve Naroff8c9f13e2007-09-16 16:16:00 +000042 switch (DeclKind) {
43 default: assert(0 && "Unknown decl kind!");
44 case Typedef:
45 return "Typedef";
46 case Function:
47 return "Function";
48 case BlockVariable:
49 return "BlockVariable";
50 case FileVariable:
51 return "FileVariable";
52 case ParmVariable:
53 return "ParmVariable";
54 case EnumConstant:
55 return "EnumConstant";
56 case ObjcInterface:
57 return "ObjcInterface";
58 case ObjcClass:
59 return "ObjcClass";
60 case ObjcMethod:
61 return "ObjcMethod";
Steve Naroff8c9f13e2007-09-16 16:16:00 +000062 case ObjcProtocol:
63 return "ObjcProtocol";
Fariborz Jahanian894c57f2007-09-21 15:40:54 +000064 case ObjcForwardProtocol:
65 return "ObjcForwardProtocol";
Steve Naroff8c9f13e2007-09-16 16:16:00 +000066 case Struct:
67 return "Struct";
68 case Union:
69 return "Union";
70 case Class:
71 return "Class";
72 case Enum:
73 return "Enum";
74 }
75}
76
Reid Spencer5f016e22007-07-11 17:01:13 +000077bool Decl::CollectingStats(bool enable) {
78 if (enable) StatSwitch = true;
Fariborz Jahanian3f5faf72007-10-04 00:45:27 +000079 return StatSwitch;
Reid Spencer5f016e22007-07-11 17:01:13 +000080}
81
82void Decl::PrintStats() {
83 fprintf(stderr, "*** Decl Stats:\n");
84 fprintf(stderr, " %d decls total.\n",
85 int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+
Steve Naroff3f128ad2007-09-17 14:16:13 +000086 nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +000087 nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
Reid Spencer5f016e22007-07-11 17:01:13 +000088 fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
89 nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
90 fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n",
91 nBlockVars, (int)sizeof(BlockVarDecl),
92 int(nBlockVars*sizeof(BlockVarDecl)));
93 fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n",
94 nFileVars, (int)sizeof(FileVarDecl),
95 int(nFileVars*sizeof(FileVarDecl)));
96 fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n",
97 nParmVars, (int)sizeof(ParmVarDecl),
98 int(nParmVars*sizeof(ParmVarDecl)));
99 fprintf(stderr, " %d field decls, %d each (%d bytes)\n",
100 nFieldDecls, (int)sizeof(FieldDecl),
101 int(nFieldDecls*sizeof(FieldDecl)));
102 fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n",
103 nSUC, (int)sizeof(RecordDecl),
104 int(nSUC*sizeof(RecordDecl)));
105 fprintf(stderr, " %d enum decls, %d each (%d bytes)\n",
106 nEnumDecls, (int)sizeof(EnumDecl),
107 int(nEnumDecls*sizeof(EnumDecl)));
108 fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n",
109 nEnumConst, (int)sizeof(EnumConstantDecl),
110 int(nEnumConst*sizeof(EnumConstantDecl)));
111 fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n",
112 nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000113 // Objective-C decls...
114 fprintf(stderr, " %d interface decls, %d each (%d bytes)\n",
115 nInterfaceDecls, (int)sizeof(ObjcInterfaceDecl),
116 int(nInterfaceDecls*sizeof(ObjcInterfaceDecl)));
117 fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n",
118 nIvarDecls, (int)sizeof(ObjcIvarDecl),
119 int(nIvarDecls*sizeof(ObjcIvarDecl)));
120 fprintf(stderr, " %d class decls, %d each (%d bytes)\n",
121 nClassDecls, (int)sizeof(ObjcClassDecl),
122 int(nClassDecls*sizeof(ObjcClassDecl)));
123 fprintf(stderr, " %d method decls, %d each (%d bytes)\n",
124 nMethodDecls, (int)sizeof(ObjcMethodDecl),
125 int(nMethodDecls*sizeof(ObjcMethodDecl)));
126 fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n",
127 nProtocolDecls, (int)sizeof(ObjcProtocolDecl),
128 int(nProtocolDecls*sizeof(ObjcProtocolDecl)));
Fariborz Jahanian894c57f2007-09-21 15:40:54 +0000129 fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n",
130 nForwardProtocolDecls, (int)sizeof(ObjcForwardProtocolDecl),
131 int(nForwardProtocolDecls*sizeof(ObjcForwardProtocolDecl)));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000132 fprintf(stderr, " %d category decls, %d each (%d bytes)\n",
133 nCategoryDecls, (int)sizeof(ObjcCategoryDecl),
134 int(nCategoryDecls*sizeof(ObjcCategoryDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000135
Fariborz Jahanianccb4f312007-09-25 18:38:09 +0000136 fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
137 nObjcImplementationDecls, (int)sizeof(ObjcImplementationDecl),
138 int(nObjcImplementationDecls*sizeof(ObjcImplementationDecl)));
139
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000140 fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
141 nObjcCategoryImpl, (int)sizeof(ObjcCategoryImplDecl),
142 int(nObjcCategoryImpl*sizeof(ObjcCategoryImplDecl)));
143
Reid Spencer5f016e22007-07-11 17:01:13 +0000144 fprintf(stderr, "Total bytes = %d\n",
145 int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
146 nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+
147 nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+
148 nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
Steve Naroff3f128ad2007-09-17 14:16:13 +0000149 nTypedef*sizeof(TypedefDecl)) /* FIXME: add Objc decls */);
Reid Spencer5f016e22007-07-11 17:01:13 +0000150}
151
152void Decl::addDeclKind(const Kind k) {
153 switch (k) {
154 case Typedef:
155 nTypedef++;
156 break;
157 case Function:
158 nFuncs++;
159 break;
160 case BlockVariable:
161 nBlockVars++;
162 break;
163 case FileVariable:
164 nFileVars++;
165 break;
166 case ParmVariable:
167 nParmVars++;
168 break;
169 case EnumConstant:
170 nEnumConst++;
171 break;
172 case Field:
173 nFieldDecls++;
174 break;
175 case Struct:
176 case Union:
177 case Class:
178 nSUC++;
179 break;
180 case Enum:
181 nEnumDecls++;
182 break;
Steve Naroff3536b442007-09-06 21:24:23 +0000183 case ObjcInterface:
184 nInterfaceDecls++;
185 break;
Chris Lattner7341c332007-09-16 19:23:04 +0000186 case ObjcClass:
Steve Naroff3f128ad2007-09-17 14:16:13 +0000187 nClassDecls++;
188 break;
Chris Lattner7341c332007-09-16 19:23:04 +0000189 case ObjcMethod:
Steve Naroff3f128ad2007-09-17 14:16:13 +0000190 nMethodDecls++;
191 break;
Chris Lattner7341c332007-09-16 19:23:04 +0000192 case ObjcProtocol:
Steve Naroff3f128ad2007-09-17 14:16:13 +0000193 nProtocolDecls++;
194 break;
Fariborz Jahanian894c57f2007-09-21 15:40:54 +0000195 case ObjcForwardProtocol:
196 nForwardProtocolDecls++;
197 break;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000198 case ObjcCategory:
199 nCategoryDecls++;
200 break;
Chris Lattner7341c332007-09-16 19:23:04 +0000201 case ObjcIvar:
Steve Naroff3f128ad2007-09-17 14:16:13 +0000202 nIvarDecls++;
Chris Lattner7341c332007-09-16 19:23:04 +0000203 break;
Fariborz Jahanianccb4f312007-09-25 18:38:09 +0000204 case ObjcImplementation:
205 nObjcImplementationDecls++;
206 break;
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000207 case ObjcCategoryImpl:
208 nObjcCategoryImpl++;
209 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000210 }
211}
212
213// Out-of-line virtual method providing a home for Decl.
214Decl::~Decl() {
215}
216
Chris Lattnerfd5de472007-10-06 22:53:46 +0000217const char *NamedDecl::getName() const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000218 if (const IdentifierInfo *II = getIdentifier())
219 return II->getName();
220 return "";
221}
222
223
224FunctionDecl::~FunctionDecl() {
225 delete[] ParamInfo;
226}
227
228unsigned FunctionDecl::getNumParams() const {
229 return cast<FunctionTypeProto>(getType().getTypePtr())->getNumArgs();
230}
231
232void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
233 assert(ParamInfo == 0 && "Already has param info!");
234 assert(NumParams == getNumParams() && "Parameter count mismatch!");
235
236 // Zero params -> null pointer.
237 if (NumParams) {
238 ParamInfo = new ParmVarDecl*[NumParams];
239 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
240 }
241}
242
243
244/// defineBody - When created, RecordDecl's correspond to a forward declared
245/// record. This method is used to mark the decl as being defined, with the
246/// specified contents.
247void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) {
248 assert(!isDefinition() && "Cannot redefine record!");
249 setDefinition(true);
250 NumMembers = numMembers;
251 if (numMembers) {
252 Members = new FieldDecl*[numMembers];
253 memcpy(Members, members, numMembers*sizeof(Decl*));
254 }
255}
256
257FieldDecl* RecordDecl::getMember(IdentifierInfo *name) {
258 if (Members == 0 || NumMembers < 0)
259 return 0;
Fariborz Jahanian3f5faf72007-10-04 00:45:27 +0000260
Reid Spencer5f016e22007-07-11 17:01:13 +0000261 // linear search. When C++ classes come along, will likely need to revisit.
262 for (int i = 0; i < NumMembers; ++i) {
263 if (Members[i]->getIdentifier() == name)
264 return Members[i];
265 }
266 return 0;
Chris Lattner6fa5f092007-07-12 15:43:07 +0000267}
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000268
Fariborz Jahanian59519652007-10-04 17:06:28 +0000269void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
270 unsigned NumParams) {
Fariborz Jahaniane55cd002007-09-12 18:23:47 +0000271 assert(ParamInfo == 0 && "Already has param info!");
272
273 // Zero params -> null pointer.
274 if (NumParams) {
275 ParamInfo = new ParmVarDecl*[NumParams];
276 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
277 NumMethodParams = NumParams;
278 }
279}
280
281ObjcMethodDecl::~ObjcMethodDecl() {
282 delete[] ParamInfo;
283}
284
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000285/// ObjcAddInstanceVariablesToClass - Inserts instance variables
286/// into ObjcInterfaceDecl's fields.
287///
288void ObjcInterfaceDecl::ObjcAddInstanceVariablesToClass(ObjcIvarDecl **ivars,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000289 unsigned numIvars) {
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000290 NumIvars = numIvars;
291 if (numIvars) {
292 Ivars = new ObjcIvarDecl*[numIvars];
293 memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*));
294 }
295}
296
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000297/// ObjcAddInstanceVariablesToClassImpl - Checks for correctness of Instance
298/// Variables (Ivars) relative to what declared in @implementation;s class.
299/// Ivars into ObjcImplementationDecl's fields.
300///
301void ObjcImplementationDecl::ObjcAddInstanceVariablesToClassImpl(
Fariborz Jahanian59519652007-10-04 17:06:28 +0000302 ObjcIvarDecl **ivars, unsigned numIvars) {
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000303 NumIvars = numIvars;
304 if (numIvars) {
305 Ivars = new ObjcIvarDecl*[numIvars];
306 memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*));
307 }
308}
309
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000310/// addObjcMethods - Insert instance and methods declarations into
311/// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
312///
313void ObjcInterfaceDecl::ObjcAddMethods(ObjcMethodDecl **insMethods,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000314 unsigned numInsMembers,
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000315 ObjcMethodDecl **clsMethods,
316 unsigned numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000317 NumInstanceMethods = numInsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000318 if (numInsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000319 InstanceMethods = new ObjcMethodDecl*[numInsMembers];
320 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000321 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000322 NumClassMethods = numClsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000323 if (numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000324 ClassMethods = new ObjcMethodDecl*[numClsMembers];
325 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000326 }
327}
328
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000329/// ObjcAddProtoMethods - Insert instance and methods declarations into
330/// ObjcProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
331///
332void ObjcProtocolDecl::ObjcAddProtoMethods(ObjcMethodDecl **insMethods,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000333 unsigned numInsMembers,
334 ObjcMethodDecl **clsMethods,
335 unsigned numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000336 NumInstanceMethods = numInsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000337 if (numInsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000338 InstanceMethods = new ObjcMethodDecl*[numInsMembers];
339 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000340 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000341 NumClassMethods = numClsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000342 if (numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000343 ClassMethods = new ObjcMethodDecl*[numClsMembers];
344 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000345 }
346}
347
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000348/// ObjcAddCat - Insert instance and methods declarations into
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000349/// ObjcCategoryDecl's CatInsMethods and CatClsMethods fields.
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000350///
351void ObjcCategoryDecl::ObjcAddCatMethods(ObjcMethodDecl **insMethods,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000352 unsigned numInsMembers,
353 ObjcMethodDecl **clsMethods,
354 unsigned numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000355 NumInstanceMethods = numInsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000356 if (numInsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000357 InstanceMethods = new ObjcMethodDecl*[numInsMembers];
358 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000359 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000360 NumClassMethods = numClsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000361 if (numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000362 ClassMethods = new ObjcMethodDecl*[numClsMembers];
363 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000364 }
365}
366
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000367/// ObjcAddCatImplMethods - Insert instance and methods declarations into
368/// ObjcCategoryImplDecl's CatInsMethods and CatClsMethods fields.
369///
370void ObjcCategoryImplDecl::ObjcAddCatImplMethods(ObjcMethodDecl **insMethods,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000371 unsigned numInsMembers,
372 ObjcMethodDecl **clsMethods,
373 unsigned numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000374 NumInstanceMethods = numInsMembers;
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000375 if (numInsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000376 InstanceMethods = new ObjcMethodDecl*[numInsMembers];
377 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000378 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000379 NumClassMethods = numClsMembers;
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000380 if (numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000381 ClassMethods = new ObjcMethodDecl*[numClsMembers];
382 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000383 }
384}
385
Fariborz Jahaniand0b01542007-09-27 18:57:03 +0000386/// ObjcAddImplMethods - Insert instance and methods declarations into
387/// ObjcImplementationDecl's InsMethods and ClsMethods fields.
388///
389void ObjcImplementationDecl::ObjcAddImplMethods(ObjcMethodDecl **insMethods,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000390 unsigned numInsMembers,
391 ObjcMethodDecl **clsMethods,
392 unsigned numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000393 NumInstanceMethods = numInsMembers;
Fariborz Jahaniand0b01542007-09-27 18:57:03 +0000394 if (numInsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000395 InstanceMethods = new ObjcMethodDecl*[numInsMembers];
396 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahaniand0b01542007-09-27 18:57:03 +0000397 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000398 NumClassMethods = numClsMembers;
Fariborz Jahaniand0b01542007-09-27 18:57:03 +0000399 if (numClsMembers) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000400 ClassMethods = new ObjcMethodDecl*[numClsMembers];
401 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
Fariborz Jahaniand0b01542007-09-27 18:57:03 +0000402 }
403}
404
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000405// FIXME: look through categories...
406ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
407 ObjcInterfaceDecl* ClassDecl = this;
408 while (ClassDecl != NULL) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000409 ObjcMethodDecl **methods = ClassDecl->getInstanceMethods();
410 int methodCount = ClassDecl->getNumInstanceMethods();
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000411 for (int i = 0; i < methodCount; ++i) {
412 if (methods[i]->getSelector() == Sel) {
413 return methods[i];
414 }
415 }
416 ClassDecl = ClassDecl->getSuperClass();
417 }
418 return NULL;
419}
420
421// FIXME: look through categories...
422ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) {
423 ObjcInterfaceDecl* ClassDecl = this;
424 while (ClassDecl != NULL) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000425 ObjcMethodDecl **methods = ClassDecl->getClassMethods();
426 int methodCount = ClassDecl->getNumClassMethods();
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000427 for (int i = 0; i < methodCount; ++i) {
428 if (methods[i]->getSelector() == Sel) {
429 return methods[i];
430 }
431 }
432 ClassDecl = ClassDecl->getSuperClass();
433 }
434 return NULL;
435}
436
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000437