blob: 7fa679cbc08302a8450a7f88a45649e9ccfdb25a [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 Lattnerc63e6602008-03-15 21:32:50 +0000208BlockVarDecl *BlockVarDecl::Create(ASTContext &C, SourceLocation L,
209 IdentifierInfo *Id, QualType T,
210 StorageClass S, ScopedDecl *PrevDecl) {
Chris Lattner9e151e12008-03-15 21:10:16 +0000211 void *Mem = C.getAllocator().Allocate<BlockVarDecl>();
212 return new (Mem) BlockVarDecl(L, Id, T, S, PrevDecl);
213}
214
215
Chris Lattnerc63e6602008-03-15 21:32:50 +0000216FileVarDecl *FileVarDecl::Create(ASTContext &C, SourceLocation L,
217 IdentifierInfo *Id, QualType T, StorageClass S,
218 ScopedDecl *PrevDecl) {
Chris Lattner9e151e12008-03-15 21:10:16 +0000219 void *Mem = C.getAllocator().Allocate<FileVarDecl>();
220 return new (Mem) FileVarDecl(L, Id, T, S, PrevDecl);
221}
222
Chris Lattnerc63e6602008-03-15 21:32:50 +0000223ParmVarDecl *ParmVarDecl::Create(ASTContext &C, SourceLocation L,
224 IdentifierInfo *Id, QualType T, StorageClass S,
225 ScopedDecl *PrevDecl) {
Chris Lattner9e151e12008-03-15 21:10:16 +0000226 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 Lattnerc63e6602008-03-15 21:32:50 +0000239EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, SourceLocation L,
240 IdentifierInfo *Id, QualType T,
241 Expr *E, const llvm::APSInt &V,
242 ScopedDecl *PrevDecl){
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000243 void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
244 return new (Mem) EnumConstantDecl(L, Id, T, E, V, PrevDecl);
245}
246
Chris Lattnerc63e6602008-03-15 21:32:50 +0000247TypedefDecl *TypedefDecl::Create(ASTContext &C, SourceLocation L,
248 IdentifierInfo *Id, QualType T,
249 ScopedDecl *PD) {
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000250 void *Mem = C.getAllocator().Allocate<TypedefDecl>();
251 return new (Mem) TypedefDecl(L, Id, T, PD);
252}
253
Chris Lattnerc63e6602008-03-15 21:32:50 +0000254EnumDecl *EnumDecl::Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id,
255 ScopedDecl *PrevDecl) {
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000256 void *Mem = C.getAllocator().Allocate<EnumDecl>();
257 return new (Mem) EnumDecl(L, Id, PrevDecl);
258}
259
Chris Lattnerc63e6602008-03-15 21:32:50 +0000260RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, SourceLocation L,
261 IdentifierInfo *Id, ScopedDecl *PrevDecl) {
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000262 void *Mem = C.getAllocator().Allocate<RecordDecl>();
263 return new (Mem) RecordDecl(DK, L, Id, PrevDecl);
264}
265
266
267//===----------------------------------------------------------------------===//
Chris Lattnerd3b90652008-03-15 05:43:15 +0000268// Decl Implementation
269//===----------------------------------------------------------------------===//
270
Reid Spencer5f016e22007-07-11 17:01:13 +0000271// Out-of-line virtual method providing a home for Decl.
272Decl::~Decl() {
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000273 if (!HasAttrs)
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000274 return;
275
276 DeclAttrMapTy::iterator it = DeclAttrs->find(this);
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000277 assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
278
279 delete it->second;
280 DeclAttrs->erase(it);
281 if (DeclAttrs->empty()) {
282 delete DeclAttrs;
283 DeclAttrs = 0;
284 }
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000285}
286
Chris Lattnerd3b90652008-03-15 05:43:15 +0000287void Decl::addAttr(Attr *NewAttr) {
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000288 if (!DeclAttrs)
Chris Lattnerd3b90652008-03-15 05:43:15 +0000289 DeclAttrs = new llvm::DenseMap<const Decl*, Attr*>();
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000290
Chris Lattnerd3b90652008-03-15 05:43:15 +0000291 Attr *&ExistingAttr = (*DeclAttrs)[this];
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000292
Chris Lattnerd3b90652008-03-15 05:43:15 +0000293 NewAttr->setNext(ExistingAttr);
294 ExistingAttr = NewAttr;
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000295
296 HasAttrs = true;
297}
298
Chris Lattnerd3b90652008-03-15 05:43:15 +0000299const Attr *Decl::getAttrs() const {
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000300 if (!HasAttrs)
Anders Carlssonb0dd2682008-02-15 23:30:50 +0000301 return 0;
302
Anders Carlssoneb7adf32008-02-16 03:37:41 +0000303 return (*DeclAttrs)[this];
Reid Spencer5f016e22007-07-11 17:01:13 +0000304}
305
Chris Lattnerfd5de472007-10-06 22:53:46 +0000306const char *NamedDecl::getName() const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000307 if (const IdentifierInfo *II = getIdentifier())
308 return II->getName();
309 return "";
310}
311
Reid Spencer5f016e22007-07-11 17:01:13 +0000312FunctionDecl::~FunctionDecl() {
313 delete[] ParamInfo;
314}
315
316unsigned FunctionDecl::getNumParams() const {
Chris Lattnerd3b90652008-03-15 05:43:15 +0000317 if (isa<FunctionTypeNoProto>(getCanonicalType()))
318 return 0;
Chris Lattnerec584d62007-12-06 17:20:20 +0000319 return cast<FunctionTypeProto>(getCanonicalType())->getNumArgs();
Reid Spencer5f016e22007-07-11 17:01:13 +0000320}
321
322void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
323 assert(ParamInfo == 0 && "Already has param info!");
324 assert(NumParams == getNumParams() && "Parameter count mismatch!");
325
326 // Zero params -> null pointer.
327 if (NumParams) {
328 ParamInfo = new ParmVarDecl*[NumParams];
329 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
330 }
331}
332
333
334/// defineBody - When created, RecordDecl's correspond to a forward declared
335/// record. This method is used to mark the decl as being defined, with the
336/// specified contents.
337void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) {
338 assert(!isDefinition() && "Cannot redefine record!");
339 setDefinition(true);
340 NumMembers = numMembers;
341 if (numMembers) {
342 Members = new FieldDecl*[numMembers];
343 memcpy(Members, members, numMembers*sizeof(Decl*));
344 }
345}
346
347FieldDecl* RecordDecl::getMember(IdentifierInfo *name) {
348 if (Members == 0 || NumMembers < 0)
349 return 0;
Fariborz Jahanian3f5faf72007-10-04 00:45:27 +0000350
Reid Spencer5f016e22007-07-11 17:01:13 +0000351 // linear search. When C++ classes come along, will likely need to revisit.
352 for (int i = 0; i < NumMembers; ++i) {
353 if (Members[i]->getIdentifier() == name)
354 return Members[i];
355 }
356 return 0;
Chris Lattner6fa5f092007-07-12 15:43:07 +0000357}
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000358
Chris Lattnerd3b90652008-03-15 05:43:15 +0000359//===----------------------------------------------------------------------===//
360// Objective-C Decl Implementation
361//===----------------------------------------------------------------------===//
362
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000363void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
Fariborz Jahanian59519652007-10-04 17:06:28 +0000364 unsigned NumParams) {
Fariborz Jahaniane55cd002007-09-12 18:23:47 +0000365 assert(ParamInfo == 0 && "Already has param info!");
366
367 // Zero params -> null pointer.
368 if (NumParams) {
369 ParamInfo = new ParmVarDecl*[NumParams];
370 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
371 NumMethodParams = NumParams;
372 }
373}
374
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000375ObjCMethodDecl::~ObjCMethodDecl() {
Fariborz Jahaniane55cd002007-09-12 18:23:47 +0000376 delete[] ParamInfo;
377}
378
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000379/// ObjCAddInstanceVariablesToClass - Inserts instance variables
380/// into ObjCInterfaceDecl's fields.
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000381///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000382void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
Steve Naroff60fccee2007-10-29 21:38:07 +0000383 unsigned numIvars,
Steve Narofff908a872007-10-30 02:23:23 +0000384 SourceLocation RBrac) {
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000385 NumIvars = numIvars;
386 if (numIvars) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000387 Ivars = new ObjCIvarDecl*[numIvars];
388 memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000389 }
Steve Narofff908a872007-10-30 02:23:23 +0000390 setLocEnd(RBrac);
Fariborz Jahanianb04a0212007-09-14 21:08:27 +0000391}
392
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000393/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000394/// Variables (Ivars) relative to what declared in @implementation;s class.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000395/// Ivars into ObjCImplementationDecl's fields.
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000396///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000397void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl(
398 ObjCIvarDecl **ivars, unsigned numIvars) {
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000399 NumIvars = numIvars;
400 if (numIvars) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000401 Ivars = new ObjCIvarDecl*[numIvars];
402 memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000403 }
404}
405
Steve Naroff60fccee2007-10-29 21:38:07 +0000406/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000407/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000408///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000409void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000410 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000411 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000412 unsigned numClsMembers,
413 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000414 NumInstanceMethods = numInsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000415 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000416 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
417 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000418 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000419 NumClassMethods = numClsMembers;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000420 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000421 ClassMethods = new ObjCMethodDecl*[numClsMembers];
422 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000423 }
Steve Narofff908a872007-10-30 02:23:23 +0000424 AtEndLoc = endLoc;
Fariborz Jahaniane3a2ca72007-09-10 20:33:04 +0000425}
426
Steve Naroff60fccee2007-10-29 21:38:07 +0000427/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000428/// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000429///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000430void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000431 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000432 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000433 unsigned numClsMembers,
Steve Naroff423cb562007-10-30 13:30:57 +0000434 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000435 NumInstanceMethods = numInsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000436 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000437 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
438 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000439 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000440 NumClassMethods = numClsMembers;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000441 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000442 ClassMethods = new ObjCMethodDecl*[numClsMembers];
443 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000444 }
Steve Naroff423cb562007-10-30 13:30:57 +0000445 AtEndLoc = endLoc;
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000446}
447
Steve Naroff60fccee2007-10-29 21:38:07 +0000448/// addMethods - Insert instance and methods declarations into
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000449/// ObjCCategoryDecl's CatInsMethods and CatClsMethods fields.
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000450///
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000451void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000452 unsigned numInsMembers,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000453 ObjCMethodDecl **clsMethods,
Steve Naroff60fccee2007-10-29 21:38:07 +0000454 unsigned numClsMembers,
Steve Naroff423cb562007-10-30 13:30:57 +0000455 SourceLocation endLoc) {
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000456 NumInstanceMethods = numInsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000457 if (numInsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000458 InstanceMethods = new ObjCMethodDecl*[numInsMembers];
459 memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000460 }
Fariborz Jahanian7ed9e0f2007-10-02 22:05:16 +0000461 NumClassMethods = numClsMembers;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000462 if (numClsMembers) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000463 ClassMethods = new ObjCMethodDecl*[numClsMembers];
464 memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000465 }
Steve Naroff423cb562007-10-30 13:30:57 +0000466 AtEndLoc = endLoc;
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000467}
468
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000469ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
470 IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
471 ObjCInterfaceDecl* ClassDecl = this;
Steve Naroff03300712007-11-12 13:56:41 +0000472 while (ClassDecl != NULL) {
Chris Lattnerbe6df082007-12-12 07:56:42 +0000473 for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
474 I != E; ++I) {
475 if ((*I)->getIdentifier() == ID) {
Steve Naroff03300712007-11-12 13:56:41 +0000476 clsDeclared = ClassDecl;
Chris Lattnerbe6df082007-12-12 07:56:42 +0000477 return *I;
Steve Naroff03300712007-11-12 13:56:41 +0000478 }
479 }
480 ClassDecl = ClassDecl->getSuperClass();
481 }
482 return NULL;
483}
484
Chris Lattner0157c512007-12-12 07:30:05 +0000485/// lookupInstanceMethod - This method returns an instance method by looking in
Chris Lattner33ef2592007-12-12 08:17:45 +0000486/// the class, its categories, and its super classes (using a linear search).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000487ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
488 ObjCInterfaceDecl* ClassDecl = this;
489 ObjCMethodDecl *MethodDecl = 0;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000490
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000491 while (ClassDecl != NULL) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000492 if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000493 return MethodDecl;
494
Steve Naroffff1afdb2007-10-14 23:13:51 +0000495 // Didn't find one yet - look through protocols.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000496 ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
Steve Naroffff1afdb2007-10-14 23:13:51 +0000497 int numProtocols = ClassDecl->getNumIntfRefProtocols();
498 for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000499 if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000500 return MethodDecl;
Steve Naroffff1afdb2007-10-14 23:13:51 +0000501 }
Steve Naroff3d581382007-10-14 18:27:41 +0000502 // Didn't find one yet - now look through categories.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000503 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
Steve Naroff3d581382007-10-14 18:27:41 +0000504 while (CatDecl) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000505 if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000506 return MethodDecl;
Steve Naroff3d581382007-10-14 18:27:41 +0000507 CatDecl = CatDecl->getNextClassCategory();
508 }
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000509 ClassDecl = ClassDecl->getSuperClass();
510 }
511 return NULL;
512}
513
Steve Naroff3d581382007-10-14 18:27:41 +0000514// lookupClassMethod - This method returns a class method by looking in the
Chris Lattner33ef2592007-12-12 08:17:45 +0000515// class, its categories, and its super classes (using a linear search).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000516ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
517 ObjCInterfaceDecl* ClassDecl = this;
518 ObjCMethodDecl *MethodDecl = 0;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000519
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000520 while (ClassDecl != NULL) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000521 if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000522 return MethodDecl;
523
Steve Naroffff1afdb2007-10-14 23:13:51 +0000524 // Didn't find one yet - look through protocols.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000525 ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
Steve Naroffff1afdb2007-10-14 23:13:51 +0000526 int numProtocols = ClassDecl->getNumIntfRefProtocols();
527 for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000528 if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000529 return MethodDecl;
Steve Naroffff1afdb2007-10-14 23:13:51 +0000530 }
Steve Naroff3d581382007-10-14 18:27:41 +0000531 // Didn't find one yet - now look through categories.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000532 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
Steve Naroff3d581382007-10-14 18:27:41 +0000533 while (CatDecl) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000534 if ((MethodDecl = CatDecl->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000535 return MethodDecl;
Steve Naroff3d581382007-10-14 18:27:41 +0000536 CatDecl = CatDecl->getNextClassCategory();
537 }
Steve Naroff6a8a9a42007-10-02 20:01:56 +0000538 ClassDecl = ClassDecl->getSuperClass();
539 }
540 return NULL;
541}
542
Chris Lattner0157c512007-12-12 07:30:05 +0000543/// lookupInstanceMethod - This method returns an instance method by looking in
544/// the class implementation. Unlike interfaces, we don't look outside the
545/// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000546ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) {
Chris Lattner0157c512007-12-12 07:30:05 +0000547 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
548 if ((*I)->getSelector() == Sel)
549 return *I;
Steve Naroffc43d8682007-11-11 00:10:47 +0000550 return NULL;
551}
552
Chris Lattner0157c512007-12-12 07:30:05 +0000553/// lookupClassMethod - This method returns a class method by looking in
554/// the class implementation. Unlike interfaces, we don't look outside the
555/// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000556ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000557 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
558 I != E; ++I)
559 if ((*I)->getSelector() == Sel)
560 return *I;
Steve Naroffc43d8682007-11-11 00:10:47 +0000561 return NULL;
562}
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000563
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000564// lookupInstanceMethod - This method returns an instance method by looking in
565// the class implementation. Unlike interfaces, we don't look outside the
566// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000567ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000568 for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
569 if ((*I)->getSelector() == Sel)
570 return *I;
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000571 return NULL;
572}
573
574// lookupClassMethod - This method returns an instance method by looking in
575// the class implementation. Unlike interfaces, we don't look outside the
576// implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000577ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) {
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000578 for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
579 I != E; ++I)
580 if ((*I)->getSelector() == Sel)
581 return *I;
Steve Naroffe1e6c0d2007-11-12 22:05:31 +0000582 return NULL;
583}
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000584
585// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
586// it inherited.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000587ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
588 ObjCMethodDecl *MethodDecl = NULL;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000589
Steve Naroff94a5c332007-12-19 22:27:04 +0000590 if ((MethodDecl = getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000591 return MethodDecl;
592
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000593 if (getNumReferencedProtocols() > 0) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000594 ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000595
Fariborz Jahanianc395bda2007-12-20 19:24:10 +0000596 for (unsigned i = 0; i < getNumReferencedProtocols(); i++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000597 if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000598 return MethodDecl;
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000599 }
600 }
601 return NULL;
602}
603
604// lookupInstanceMethod - Lookup a class method in the protocol and protocols
605// it inherited.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000606ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
607 ObjCMethodDecl *MethodDecl = NULL;
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000608
Steve Naroff94a5c332007-12-19 22:27:04 +0000609 if ((MethodDecl = getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000610 return MethodDecl;
611
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000612 if (getNumReferencedProtocols() > 0) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000613 ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000614
Fariborz Jahanianc395bda2007-12-20 19:24:10 +0000615 for(unsigned i = 0; i < getNumReferencedProtocols(); i++) {
Steve Naroff94a5c332007-12-19 22:27:04 +0000616 if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000617 return MethodDecl;
Fariborz Jahanian7dd82832007-12-07 21:21:21 +0000618 }
619 }
620 return NULL;
621}
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000622
Fariborz Jahanianfaf5e772008-01-17 17:37:26 +0000623/// getSynthesizedMethodSize - Compute size of synthesized method name
624/// as done be the rewrite.
625///
626unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
Fariborz Jahanian847794a2008-01-17 01:36:09 +0000627 // syntesized method name is a concatenation of -/+[class-name selector]
628 // Get length of this name.
Fariborz Jahanianfaf5e772008-01-17 17:37:26 +0000629 unsigned length = 3; // _I_ or _C_
630 length += strlen(getClassInterface()->getName()) +1; // extra for _
631 NamedDecl *MethodContext = getMethodContext();
632 if (ObjCCategoryImplDecl *CID =
633 dyn_cast<ObjCCategoryImplDecl>(MethodContext))
634 length += strlen(CID->getName()) +1;
635 length += getSelector().getName().size(); // selector name
Fariborz Jahanian847794a2008-01-17 01:36:09 +0000636 return length;
637}
638
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000639ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
640 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000641 return ID;
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000642 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000643 return CD->getClassInterface();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000644 if (ObjCImplementationDecl *IMD =
645 dyn_cast<ObjCImplementationDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000646 return IMD->getClassInterface();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000647 if (ObjCCategoryImplDecl *CID =
648 dyn_cast<ObjCCategoryImplDecl>(MethodContext))
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000649 return CID->getClassInterface();
650 assert(false && "unknown method context");
651 return 0;
652}