blob: 8487efb8449b406cf43872100e723f120bf76d55 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
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"
Chris Lattner6c2b6eb2008-03-15 06:12:44 +000016#include "clang/AST/ASTContext.h"
Anders Carlssonf78915f2008-02-15 07:04:12 +000017#include "clang/AST/Attr.h"
Chris Lattnerc7229c32007-10-07 08:58:51 +000018#include "clang/Basic/IdentifierTable.h"
Anders Carlssonb0dd2682008-02-15 23:30:50 +000019#include "llvm/ADT/DenseMap.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020using namespace clang;
21
Chris Lattnerd3b90652008-03-15 05:43:15 +000022//===----------------------------------------------------------------------===//
23// Statistics
24//===----------------------------------------------------------------------===//
25
Reid Spencer5f016e22007-07-11 17:01:13 +000026// temporary statistics gathering
27static unsigned nFuncs = 0;
28static unsigned nBlockVars = 0;
29static unsigned nFileVars = 0;
30static unsigned nParmVars = 0;
31static unsigned nSUC = 0;
32static unsigned nEnumConst = 0;
33static unsigned nEnumDecls = 0;
34static unsigned nTypedef = 0;
35static unsigned nFieldDecls = 0;
Steve Naroff3536b442007-09-06 21:24:23 +000036static unsigned nInterfaceDecls = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000037static unsigned nClassDecls = 0;
38static unsigned nMethodDecls = 0;
39static unsigned nProtocolDecls = 0;
Fariborz Jahanian894c57f2007-09-21 15:40:54 +000040static unsigned nForwardProtocolDecls = 0;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +000041static unsigned nCategoryDecls = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000042static unsigned nIvarDecls = 0;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000043static unsigned nObjCImplementationDecls = 0;
44static unsigned nObjCCategoryImpl = 0;
45static unsigned nObjCCompatibleAlias = 0;
46static unsigned nObjCPropertyDecl = 0;
Chris Lattnerc6fdc342008-01-12 07:05:38 +000047static unsigned nLinkageSpecDecl = 0;
Anders Carlssondfab6cb2008-02-08 00:33:21 +000048static unsigned nFileScopeAsmDecl = 0;
Steve Naroff3f128ad2007-09-17 14:16:13 +000049
Reid Spencer5f016e22007-07-11 17:01:13 +000050static bool StatSwitch = false;
51
Anders Carlssonb0dd2682008-02-15 23:30:50 +000052// This keeps track of all decl attributes. Since so few decls have attrs, we
53// keep them in a hash map instead of wasting space in the Decl class.
54typedef llvm::DenseMap<const Decl*, Attr*> DeclAttrMapTy;
55
56static DeclAttrMapTy *DeclAttrs = 0;
57
Steve Naroffe5ea3802007-09-17 14:49:06 +000058const char *Decl::getDeclKindName() const {
Steve Naroff8c9f13e2007-09-16 16:16:00 +000059 switch (DeclKind) {
60 default: assert(0 && "Unknown decl kind!");
Chris Lattnerd3b90652008-03-15 05:43:15 +000061 case Typedef: return "Typedef";
62 case Function: return "Function";
63 case BlockVar: return "BlockVar";
64 case FileVar: return "FileVar";
65 case ParmVar: return "ParmVar";
66 case EnumConstant: return "EnumConstant";
67 case ObjCInterface: return "ObjCInterface";
68 case ObjCClass: return "ObjCClass";
69 case ObjCMethod: return "ObjCMethod";
70 case ObjCProtocol: return "ObjCProtocol";
71 case ObjCForwardProtocol: return "ObjCForwardProtocol";
72 case Struct: return "Struct";
73 case Union: return "Union";
74 case Class: return "Class";
75 case Enum: return "Enum";
Steve Naroff8c9f13e2007-09-16 16:16:00 +000076 }
77}
78
Chris Lattnerd3b90652008-03-15 05:43:15 +000079bool Decl::CollectingStats(bool Enable) {
80 if (Enable)
81 StatSwitch = true;
82 return StatSwitch;
Reid Spencer5f016e22007-07-11 17:01:13 +000083}
84
85void Decl::PrintStats() {
86 fprintf(stderr, "*** Decl Stats:\n");
87 fprintf(stderr, " %d decls total.\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +000088 int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+
89 nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
90 nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
Reid Spencer5f016e22007-07-11 17:01:13 +000091 fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +000092 nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +000093 fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +000094 nBlockVars, (int)sizeof(BlockVarDecl),
95 int(nBlockVars*sizeof(BlockVarDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +000096 fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +000097 nFileVars, (int)sizeof(FileVarDecl),
98 int(nFileVars*sizeof(FileVarDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +000099 fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000100 nParmVars, (int)sizeof(ParmVarDecl),
101 int(nParmVars*sizeof(ParmVarDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +0000102 fprintf(stderr, " %d field decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000103 nFieldDecls, (int)sizeof(FieldDecl),
104 int(nFieldDecls*sizeof(FieldDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +0000105 fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000106 nSUC, (int)sizeof(RecordDecl),
107 int(nSUC*sizeof(RecordDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +0000108 fprintf(stderr, " %d enum decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000109 nEnumDecls, (int)sizeof(EnumDecl),
110 int(nEnumDecls*sizeof(EnumDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +0000111 fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000112 nEnumConst, (int)sizeof(EnumConstantDecl),
113 int(nEnumConst*sizeof(EnumConstantDecl)));
Reid Spencer5f016e22007-07-11 17:01:13 +0000114 fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000115 nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000116 // Objective-C decls...
117 fprintf(stderr, " %d interface decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000118 nInterfaceDecls, (int)sizeof(ObjCInterfaceDecl),
119 int(nInterfaceDecls*sizeof(ObjCInterfaceDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000120 fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000121 nIvarDecls, (int)sizeof(ObjCIvarDecl),
122 int(nIvarDecls*sizeof(ObjCIvarDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000123 fprintf(stderr, " %d class decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000124 nClassDecls, (int)sizeof(ObjCClassDecl),
125 int(nClassDecls*sizeof(ObjCClassDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000126 fprintf(stderr, " %d method decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000127 nMethodDecls, (int)sizeof(ObjCMethodDecl),
128 int(nMethodDecls*sizeof(ObjCMethodDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000129 fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000130 nProtocolDecls, (int)sizeof(ObjCProtocolDecl),
131 int(nProtocolDecls*sizeof(ObjCProtocolDecl)));
Fariborz Jahanian894c57f2007-09-21 15:40:54 +0000132 fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000133 nForwardProtocolDecls, (int)sizeof(ObjCForwardProtocolDecl),
134 int(nForwardProtocolDecls*sizeof(ObjCForwardProtocolDecl)));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000135 fprintf(stderr, " %d category decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000136 nCategoryDecls, (int)sizeof(ObjCCategoryDecl),
137 int(nCategoryDecls*sizeof(ObjCCategoryDecl)));
Steve Naroff3f128ad2007-09-17 14:16:13 +0000138
Fariborz Jahanianccb4f312007-09-25 18:38:09 +0000139 fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000140 nObjCImplementationDecls, (int)sizeof(ObjCImplementationDecl),
141 int(nObjCImplementationDecls*sizeof(ObjCImplementationDecl)));
Fariborz Jahanianccb4f312007-09-25 18:38:09 +0000142
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000143 fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000144 nObjCCategoryImpl, (int)sizeof(ObjCCategoryImplDecl),
145 int(nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl)));
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000146
Fariborz Jahanian243b64b2007-10-11 23:42:27 +0000147 fprintf(stderr, " %d compatibility alias decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000148 nObjCCompatibleAlias, (int)sizeof(ObjCCompatibleAliasDecl),
149 int(nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl)));
Fariborz Jahanian243b64b2007-10-11 23:42:27 +0000150
Fariborz Jahanian82a5fe32007-11-06 22:01:00 +0000151 fprintf(stderr, " %d property decls, %d each (%d bytes)\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000152 nObjCPropertyDecl, (int)sizeof(ObjCPropertyDecl),
153 int(nObjCPropertyDecl*sizeof(ObjCPropertyDecl)));
Fariborz Jahanian82a5fe32007-11-06 22:01:00 +0000154
Reid Spencer5f016e22007-07-11 17:01:13 +0000155 fprintf(stderr, "Total bytes = %d\n",
Chris Lattnerc81c8142008-02-25 21:04:36 +0000156 int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
157 nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+
158 nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+
159 nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
160 nTypedef*sizeof(TypedefDecl)+
Fariborz Jahanian269b10d2008-01-23 01:34:33 +0000161 nInterfaceDecls*sizeof(ObjCInterfaceDecl)+
162 nIvarDecls*sizeof(ObjCIvarDecl)+
163 nClassDecls*sizeof(ObjCClassDecl)+
164 nMethodDecls*sizeof(ObjCMethodDecl)+
165 nProtocolDecls*sizeof(ObjCProtocolDecl)+
166 nForwardProtocolDecls*sizeof(ObjCForwardProtocolDecl)+
167 nCategoryDecls*sizeof(ObjCCategoryDecl)+
168 nObjCImplementationDecls*sizeof(ObjCImplementationDecl)+
169 nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl)+
170 nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl)+
171 nObjCPropertyDecl*sizeof(ObjCPropertyDecl)+
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000172 nLinkageSpecDecl*sizeof(LinkageSpecDecl)+
173 nFileScopeAsmDecl*sizeof(FileScopeAsmDecl)));
Fariborz Jahanian269b10d2008-01-23 01:34:33 +0000174
Reid Spencer5f016e22007-07-11 17:01:13 +0000175}
176
Chris Lattnerd3b90652008-03-15 05:43:15 +0000177void Decl::addDeclKind(Kind k) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000178 switch (k) {
Chris Lattnerd3b90652008-03-15 05:43:15 +0000179 case Typedef: nTypedef++; break;
180 case Function: nFuncs++; break;
181 case BlockVar: nBlockVars++; break;
182 case FileVar: nFileVars++; break;
183 case ParmVar: nParmVars++; break;
184 case EnumConstant: nEnumConst++; break;
185 case Field: nFieldDecls++; break;
186 case Struct: case Union: case Class: nSUC++; break;
187 case Enum: nEnumDecls++; break;
188 case ObjCInterface: nInterfaceDecls++; break;
189 case ObjCClass: nClassDecls++; break;
190 case ObjCMethod: nMethodDecls++; break;
191 case ObjCProtocol: nProtocolDecls++; break;
192 case ObjCForwardProtocol: nForwardProtocolDecls++; break;
193 case ObjCCategory: nCategoryDecls++; break;
194 case ObjCIvar: nIvarDecls++; break;
195 case ObjCImplementation: nObjCImplementationDecls++; break;
196 case ObjCCategoryImpl: nObjCCategoryImpl++; break;
197 case CompatibleAlias: nObjCCompatibleAlias++; break;
198 case PropertyDecl: nObjCPropertyDecl++; break;
199 case LinkageSpec: nLinkageSpecDecl++; break;
200 case FileScopeAsm: nFileScopeAsmDecl++; break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000201 }
202}
203
Chris Lattnerd3b90652008-03-15 05:43:15 +0000204//===----------------------------------------------------------------------===//
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000205// Decl Allocation/Deallocation Method Implementations
206//===----------------------------------------------------------------------===//
207
Chris Lattner9e151e12008-03-15 21:10:16 +0000208BlockVarDecl *BlockVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
209 QualType T, StorageClass S,
210 ScopedDecl *PrevDecl, ASTContext &C) {
211 void *Mem = C.getAllocator().Allocate<BlockVarDecl>();
212 return new (Mem) BlockVarDecl(L, Id, T, S, PrevDecl);
213}
214
215
216FileVarDecl *FileVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
217 QualType T, StorageClass S,
218 ScopedDecl *PrevDecl, ASTContext &C) {
219 void *Mem = C.getAllocator().Allocate<FileVarDecl>();
220 return new (Mem) FileVarDecl(L, Id, T, S, PrevDecl);
221}
222
223ParmVarDecl *ParmVarDecl::Create(SourceLocation L, IdentifierInfo *Id,
224 QualType T, StorageClass S,
225 ScopedDecl *PrevDecl, ASTContext &C) {
226 void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
227 return new (Mem) ParmVarDecl(L, Id, T, S, PrevDecl);
228}
229
Chris Lattnera98e58d2008-03-15 21:24:04 +0000230FunctionDecl *FunctionDecl::Create(ASTContext &C, SourceLocation L,
231 IdentifierInfo *Id, QualType T,
232 StorageClass S, bool isInline,
233 ScopedDecl *PrevDecl) {
234 void *Mem = C.getAllocator().Allocate<FunctionDecl>();
235 return new (Mem) FunctionDecl(L, Id, T, S, isInline, PrevDecl);
236}
237
238
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000239EnumConstantDecl *EnumConstantDecl::Create(SourceLocation L, IdentifierInfo *Id,
240 QualType T, Expr *E,
241 const llvm::APSInt &V,
242 ScopedDecl *PrevDecl, ASTContext &C){
243 void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
244 return new (Mem) EnumConstantDecl(L, Id, T, E, V, PrevDecl);
245}
246
247TypedefDecl *TypedefDecl::Create(SourceLocation L, IdentifierInfo *Id,
248 QualType T, ScopedDecl *PD, ASTContext &C) {
249 void *Mem = C.getAllocator().Allocate<TypedefDecl>();
250 return new (Mem) TypedefDecl(L, Id, T, PD);
251}
252
253EnumDecl *EnumDecl::Create(SourceLocation L, IdentifierInfo *Id,
254 ScopedDecl *PrevDecl, ASTContext &C) {
255 void *Mem = C.getAllocator().Allocate<EnumDecl>();
256 return new (Mem) EnumDecl(L, Id, PrevDecl);
257}
258
259RecordDecl *RecordDecl::Create(Kind DK, SourceLocation L, IdentifierInfo *Id,
260 ScopedDecl *PrevDecl, ASTContext &C) {
261 void *Mem = C.getAllocator().Allocate<RecordDecl>();
262 return new (Mem) RecordDecl(DK, L, Id, PrevDecl);
263}
264
265
266//===----------------------------------------------------------------------===//
Chris Lattnerd3b90652008-03-15 05:43:15 +0000267// Decl Implementation
268//===----------------------------------------------------------------------===//
269
Reid Spencer5f016e22007-07-11 17:01:13 +0000270// Out-of-line virtual method providing a home for Decl.
271Decl::~Decl() {
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000272 if (!HasAttrs)
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000273 return;
274
275 DeclAttrMapTy::iterator it = DeclAttrs->find(this);
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000276 assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
277
278 delete it->second;
279 DeclAttrs->erase(it);
280 if (DeclAttrs->empty()) {
281 delete DeclAttrs;
282 DeclAttrs = 0;
283 }
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000284}
285
Chris Lattnerd3b90652008-03-15 05:43:15 +0000286void Decl::addAttr(Attr *NewAttr) {
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000287 if (!DeclAttrs)
Chris Lattnerd3b90652008-03-15 05:43:15 +0000288 DeclAttrs = new llvm::DenseMap<const Decl*, Attr*>();
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000289
Chris Lattnerd3b90652008-03-15 05:43:15 +0000290 Attr *&ExistingAttr = (*DeclAttrs)[this];
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000291
Chris Lattnerd3b90652008-03-15 05:43:15 +0000292 NewAttr->setNext(ExistingAttr);
293 ExistingAttr = NewAttr;
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000294
295 HasAttrs = true;
296}
297
Chris Lattnerd3b90652008-03-15 05:43:15 +0000298const Attr *Decl::getAttrs() const {
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000299 if (!HasAttrs)
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000300 return 0;
301
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000302 return (*DeclAttrs)[this];
Reid Spencer5f016e22007-07-11 17:01:13 +0000303}
304
Chris Lattnerfd5de472007-10-06 22:53:46 +0000305const char *NamedDecl::getName() const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000306 if (const IdentifierInfo *II = getIdentifier())
307 return II->getName();
308 return "";
309}
310
Reid Spencer5f016e22007-07-11 17:01:13 +0000311FunctionDecl::~FunctionDecl() {
312 delete[] ParamInfo;
313}
314
315unsigned FunctionDecl::getNumParams() const {
Chris Lattnerd3b90652008-03-15 05:43:15 +0000316 if (isa<FunctionTypeNoProto>(getCanonicalType()))
317 return 0;
Chris Lattnerec584d62007-12-06 17:20:20 +0000318 return cast<FunctionTypeProto>(getCanonicalType())->getNumArgs();
Reid Spencer5f016e22007-07-11 17:01:13 +0000319}
320
321void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
322 assert(ParamInfo == 0 && "Already has param info!");
323 assert(NumParams == getNumParams() && "Parameter count mismatch!");
324
325 // Zero params -> null pointer.
326 if (NumParams) {
327 ParamInfo = new ParmVarDecl*[NumParams];
328 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
329 }
330}
331
332
333/// defineBody - When created, RecordDecl's correspond to a forward declared
334/// record. This method is used to mark the decl as being defined, with the
335/// specified contents.
336void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) {
337 assert(!isDefinition() && "Cannot redefine record!");
338 setDefinition(true);
339 NumMembers = numMembers;
340 if (numMembers) {
341 Members = new FieldDecl*[numMembers];
342 memcpy(Members, members, numMembers*sizeof(Decl*));
343 }
344}
345
346FieldDecl* RecordDecl::getMember(IdentifierInfo *name) {
347 if (Members == 0 || NumMembers < 0)
348 return 0;
Fariborz Jahanian3f5faf72007-10-04 00:45:27 +0000349
Reid Spencer5f016e22007-07-11 17:01:13 +0000350 // linear search. When C++ classes come along, will likely need to revisit.
351 for (int i = 0; i < NumMembers; ++i) {
352 if (Members[i]->getIdentifier() == name)
353 return Members[i];
354 }
355 return 0;
Chris Lattner6fa5f092007-07-12 15:43:07 +0000356}
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000357
Chris Lattnerd3b90652008-03-15 05:43:15 +0000358//===----------------------------------------------------------------------===//
359// Objective-C Decl Implementation
360//===----------------------------------------------------------------------===//
361
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000362void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000363 unsigned NumParams) {
Fariborz Jahaniane55cd002007-09-12 18:23:47 +0000364 assert(ParamInfo == 0 && "Already has param info!");
365
366 // Zero params -> null pointer.
367 if (NumParams) {
368 ParamInfo = new ParmVarDecl*[NumParams];
369 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
370 NumMethodParams = NumParams;
371 }
372}
373
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000374ObjCMethodDecl::~ObjCMethodDecl() {
Fariborz Jahaniane55cd002007-09-12 18:23:47 +0000375 delete[] ParamInfo;
376}
377
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000378/// ObjCAddInstanceVariablesToClass - Inserts instance variables
379/// into ObjCInterfaceDecl's fields.
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000380///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000381void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
Steve Naroff60fccee2007-10-29 21:38:07 +0000382 unsigned numIvars,
Steve Narofff908a872007-10-30 02:23:23 +0000383 SourceLocation RBrac) {
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000384 NumIvars = numIvars;
385 if (numIvars) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000386 Ivars = new ObjCIvarDecl*[numIvars];
387 memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000388 }
Steve Narofff908a872007-10-30 02:23:23 +0000389 setLocEnd(RBrac);
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000390}
391
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000392/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000393/// Variables (Ivars) relative to what declared in @implementation;s class.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000394/// Ivars into ObjCImplementationDecl's fields.
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000395///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000396void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl(
397 ObjCIvarDecl **ivars, unsigned numIvars) {
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000398 NumIvars = numIvars;
399 if (numIvars) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000400 Ivars = new ObjCIvarDecl*[numIvars];
401 memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000402 }
403}
404
Steve Naroff60fccee2007-10-29 21:38:07 +0000405/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000406/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000407///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000408void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000409 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000410 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000411 unsigned numClsMembers,
412 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000413 NumInstanceMethods = numInsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000414 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000415 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
416 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000417 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000418 NumClassMethods = numClsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000419 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000420 ClassMethods = new ObjCMethodDecl*[numClsMembers];
421 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000422 }
Steve Narofff908a872007-10-30 02:23:23 +0000423 AtEndLoc = endLoc;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000424}
425
Steve Naroff60fccee2007-10-29 21:38:07 +0000426/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000427/// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000428///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000429void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000430 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000431 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000432 unsigned numClsMembers,
Steve Naroff423cb562007-10-30 13:30:57 +0000433 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000434 NumInstanceMethods = numInsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000435 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000436 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
437 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000438 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000439 NumClassMethods = numClsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000440 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000441 ClassMethods = new ObjCMethodDecl*[numClsMembers];
442 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000443 }
Steve Naroff423cb562007-10-30 13:30:57 +0000444 AtEndLoc = endLoc;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000445}
446
Steve Naroff60fccee2007-10-29 21:38:07 +0000447/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000448/// ObjCCategoryDecl's CatInsMethods and CatClsMethods fields.
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000449///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000450void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000451 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000452 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000453 unsigned numClsMembers,
Steve Naroff423cb562007-10-30 13:30:57 +0000454 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000455 NumInstanceMethods = numInsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000456 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000457 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
458 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000459 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000460 NumClassMethods = numClsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000461 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000462 ClassMethods = new ObjCMethodDecl*[numClsMembers];
463 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000464 }
Steve Naroff423cb562007-10-30 13:30:57 +0000465 AtEndLoc = endLoc;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000466}
467
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000468ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
469 IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
470 ObjCInterfaceDecl* ClassDecl = this;
Steve Naroff03300712007-11-12 13:56:41 +0000471 while (ClassDecl != NULL) {
Chris Lattnerbe6df082007-12-12 07:56:42 +0000472 for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
473 I != E; ++I) {
474 if ((*I)->getIdentifier() == ID) {
Steve Naroff03300712007-11-12 13:56:41 +0000475 clsDeclared = ClassDecl;
Chris Lattnerbe6df082007-12-12 07:56:42 +0000476 return *I;
Steve Naroff03300712007-11-12 13:56:41 +0000477 }
478 }
479 ClassDecl = ClassDecl->getSuperClass();
480 }
481 return NULL;
482}
483
Chris Lattner0157c512007-12-12 07:30:05 +0000484/// lookupInstanceMethod - This method returns an instance method by looking in
Chris Lattner33ef2592007-12-12 08:17:45 +0000485/// the class, its categories, and its super classes (using a linear search).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000486ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
487 ObjCInterfaceDecl* ClassDecl = this;
488 ObjCMethodDecl *MethodDecl = 0;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000489
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000490 while (ClassDecl != NULL) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000491 if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000492 return MethodDecl;
493
Steve Naroffff1afdb2007-10-14 23:13:51 +0000494 // Didn't find one yet - look through protocols.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000495 ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
Steve Naroffff1afdb2007-10-14 23:13:51 +0000496 int numProtocols = ClassDecl->getNumIntfRefProtocols();
497 for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000498 if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000499 return MethodDecl;
Steve Naroffff1afdb2007-10-14 23:13:51 +0000500 }
Steve Naroff3d581382007-10-14 18:27:41 +0000501 // Didn't find one yet - now look through categories.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000502 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
Steve Naroff3d581382007-10-14 18:27:41 +0000503 while (CatDecl) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000504 if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000505 return MethodDecl;
Steve Naroff3d581382007-10-14 18:27:41 +0000506 CatDecl = CatDecl->getNextClassCategory();
507 }
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000508 ClassDecl = ClassDecl->getSuperClass();
509 }
510 return NULL;
511}
512
Steve Naroff3d581382007-10-14 18:27:41 +0000513// lookupClassMethod - This method returns a class method by looking in the
Chris Lattner33ef2592007-12-12 08:17:45 +0000514// class, its categories, and its super classes (using a linear search).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000515ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
516 ObjCInterfaceDecl* ClassDecl = this;
517 ObjCMethodDecl *MethodDecl = 0;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000518
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000519 while (ClassDecl != NULL) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000520 if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000521 return MethodDecl;
522
Steve Naroffff1afdb2007-10-14 23:13:51 +0000523 // Didn't find one yet - look through protocols.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000524 ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
Steve Naroffff1afdb2007-10-14 23:13:51 +0000525 int numProtocols = ClassDecl->getNumIntfRefProtocols();
526 for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000527 if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000528 return MethodDecl;
Steve Naroffff1afdb2007-10-14 23:13:51 +0000529 }
Steve Naroff3d581382007-10-14 18:27:41 +0000530 // Didn't find one yet - now look through categories.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000531 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
Steve Naroff3d581382007-10-14 18:27:41 +0000532 while (CatDecl) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000533 if ((MethodDecl = CatDecl->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000534 return MethodDecl;
Steve Naroff3d581382007-10-14 18:27:41 +0000535 CatDecl = CatDecl->getNextClassCategory();
536 }
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000537 ClassDecl = ClassDecl->getSuperClass();
538 }
539 return NULL;
540}
541
Chris Lattner0157c512007-12-12 07:30:05 +0000542/// lookupInstanceMethod - This method returns an instance method by looking in
543/// the class implementation. Unlike interfaces, we don't look outside the
544/// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000545ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) {
Chris Lattner0157c512007-12-12 07:30:05 +0000546 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
547 if ((*I)->getSelector() == Sel)
548 return *I;
Steve Naroffc43d8682007-11-11 00:10:47 +0000549 return NULL;
550}
551
Chris Lattner0157c512007-12-12 07:30:05 +0000552/// lookupClassMethod - This method returns a class method by looking in
553/// the class implementation. Unlike interfaces, we don't look outside the
554/// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000555ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000556 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
557 I != E; ++I)
558 if ((*I)->getSelector() == Sel)
559 return *I;
Steve Naroffc43d8682007-11-11 00:10:47 +0000560 return NULL;
561}
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000562
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000563// lookupInstanceMethod - This method returns an instance method by looking in
564// the class implementation. Unlike interfaces, we don't look outside the
565// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000566ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000567 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
568 if ((*I)->getSelector() == Sel)
569 return *I;
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000570 return NULL;
571}
572
573// lookupClassMethod - This method returns an instance method by looking in
574// the class implementation. Unlike interfaces, we don't look outside the
575// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000576ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000577 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
578 I != E; ++I)
579 if ((*I)->getSelector() == Sel)
580 return *I;
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000581 return NULL;
582}
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000583
584// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
585// it inherited.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000586ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
587 ObjCMethodDecl *MethodDecl = NULL;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000588
Steve Naroff94a5c332007-12-19 22:27:04 +0000589 if ((MethodDecl = getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000590 return MethodDecl;
591
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000592 if (getNumReferencedProtocols() > 0) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000593 ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000594
Fariborz Jahanianc395bda2007-12-20 19:24:10 +0000595 for (unsigned i = 0; i < getNumReferencedProtocols(); i++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000596 if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000597 return MethodDecl;
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000598 }
599 }
600 return NULL;
601}
602
603// lookupInstanceMethod - Lookup a class method in the protocol and protocols
604// it inherited.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000605ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
606 ObjCMethodDecl *MethodDecl = NULL;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000607
Steve Naroff94a5c332007-12-19 22:27:04 +0000608 if ((MethodDecl = getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000609 return MethodDecl;
610
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000611 if (getNumReferencedProtocols() > 0) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000612 ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000613
Fariborz Jahanianc395bda2007-12-20 19:24:10 +0000614 for(unsigned i = 0; i < getNumReferencedProtocols(); i++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000615 if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000616 return MethodDecl;
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000617 }
618 }
619 return NULL;
620}
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000621
Fariborz Jahanianfaf5e772008-01-17 17:37:26 +0000622/// getSynthesizedMethodSize - Compute size of synthesized method name
623/// as done be the rewrite.
624///
625unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
Fariborz Jahanian847794a2008-01-17 01:36:09 +0000626 // syntesized method name is a concatenation of -/+[class-name selector]
627 // Get length of this name.
Fariborz Jahanianfaf5e772008-01-17 17:37:26 +0000628 unsigned length = 3; // _I_ or _C_
629 length += strlen(getClassInterface()->getName()) +1; // extra for _
630 NamedDecl *MethodContext = getMethodContext();
631 if (ObjCCategoryImplDecl *CID =
632 dyn_cast<ObjCCategoryImplDecl>(MethodContext))
633 length += strlen(CID->getName()) +1;
634 length += getSelector().getName().size(); // selector name
Fariborz Jahanian847794a2008-01-17 01:36:09 +0000635 return length;
636}
637
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000638ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
639 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000640 return ID;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000641 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000642 return CD->getClassInterface();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000643 if (ObjCImplementationDecl *IMD =
644 dyn_cast<ObjCImplementationDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000645 return IMD->getClassInterface();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000646 if (ObjCCategoryImplDecl *CID =
647 dyn_cast<ObjCCategoryImplDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000648 return CID->getClassInterface();
649 assert(false && "unknown method context");
650 return 0;
651}