Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 1 | //===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C related Decl classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclObjC.h" |
| 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/Stmt.h" |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 19 | //===----------------------------------------------------------------------===// |
| 20 | // ObjC Decl Allocation/Deallocation Method Implementations |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 23 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
| 24 | SourceLocation beginLoc, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 25 | SourceLocation endLoc, |
| 26 | Selector SelInfo, QualType T, |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 27 | DeclContext *contextDecl, |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 28 | bool isInstance, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 29 | bool isVariadic, |
Fariborz Jahanian | 4607034 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 30 | bool isSynthesized, |
Chris Lattner | b06fa3b | 2008-03-16 00:58:16 +0000 | [diff] [blame] | 31 | ImplementationControl impControl) { |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 32 | void *Mem = C.getAllocator().Allocate<ObjCMethodDecl>(); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 33 | return new (Mem) ObjCMethodDecl(beginLoc, endLoc, |
| 34 | SelInfo, T, contextDecl, |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 35 | isInstance, |
Fariborz Jahanian | 4607034 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 36 | isVariadic, isSynthesized, impControl); |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 37 | } |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 38 | |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 39 | ObjCMethodDecl::~ObjCMethodDecl() { |
| 40 | delete [] ParamInfo; |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void ObjCMethodDecl::Destroy(ASTContext& C) { |
| 44 | if (Body) Body->Destroy(C); |
| 45 | if (SelfDecl) SelfDecl->Destroy(C); |
| 46 | |
| 47 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 48 | if (*I) (*I)->Destroy(C); |
| 49 | |
| 50 | Decl::Destroy(C); |
| 51 | } |
| 52 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 53 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 54 | DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 55 | SourceLocation atLoc, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 56 | IdentifierInfo *Id, |
| 57 | SourceLocation ClassLoc, |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 58 | bool ForwardDecl, bool isInternal){ |
| 59 | void *Mem = C.getAllocator().Allocate<ObjCInterfaceDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 60 | return new (Mem) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 61 | isInternal); |
| 62 | } |
| 63 | |
Steve Naroff | e4f039e | 2009-01-07 17:57:40 +0000 | [diff] [blame] | 64 | ObjCContainerDecl::~ObjCContainerDecl() { |
Steve Naroff | e4f039e | 2009-01-07 17:57:40 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | ObjCInterfaceDecl::~ObjCInterfaceDecl() { |
| 68 | delete [] Ivars; |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 69 | // FIXME: CategoryList? |
| 70 | } |
| 71 | |
| 72 | void ObjCInterfaceDecl::Destroy(ASTContext& C) { |
| 73 | for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I) |
| 74 | if (*I) (*I)->Destroy(C); |
| 75 | |
Ted Kremenek | 1a726d7 | 2008-06-06 17:21:42 +0000 | [diff] [blame] | 76 | // FIXME: Because there is no clear ownership |
| 77 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 78 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 79 | Decl::Destroy(C); |
| 80 | } |
| 81 | |
| 82 | |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 83 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, |
Ted Kremenek | b8db21d | 2008-07-23 18:04:17 +0000 | [diff] [blame] | 84 | IdentifierInfo *Id, QualType T, |
| 85 | AccessControl ac, Expr *BW) { |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 86 | void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>(); |
Ted Kremenek | b8db21d | 2008-07-23 18:04:17 +0000 | [diff] [blame] | 87 | return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW); |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Ted Kremenek | 01e6779 | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 90 | |
| 91 | ObjCAtDefsFieldDecl |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 92 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
Ted Kremenek | 01e6779 | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 93 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 94 | void *Mem = C.getAllocator().Allocate<ObjCAtDefsFieldDecl>(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 95 | return new (Mem) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
Ted Kremenek | 01e6779 | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 99 | this->~ObjCAtDefsFieldDecl(); |
| 100 | C.getAllocator().Deallocate((void *)this); |
| 101 | } |
| 102 | |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 103 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 104 | SourceLocation L, |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 105 | IdentifierInfo *Id) { |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 106 | void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 107 | return new (Mem) ObjCProtocolDecl(DC, L, Id); |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Ted Kremenek | 1c8a413 | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 110 | ObjCProtocolDecl::~ObjCProtocolDecl() { |
Ted Kremenek | 1c8a413 | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 111 | delete [] PropertyDecl; |
| 112 | } |
| 113 | |
Ted Kremenek | 1c8a413 | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 115 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 116 | SourceLocation L, |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 117 | ObjCInterfaceDecl **Elts, unsigned nElts) { |
| 118 | void *Mem = C.getAllocator().Allocate<ObjCClassDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 119 | return new (Mem) ObjCClassDecl(DC, L, Elts, nElts); |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Ted Kremenek | 400d95f | 2008-06-06 20:11:53 +0000 | [diff] [blame] | 122 | ObjCClassDecl::~ObjCClassDecl() { |
| 123 | delete [] ForwardDecls; |
| 124 | } |
| 125 | |
| 126 | void ObjCClassDecl::Destroy(ASTContext& C) { |
| 127 | |
| 128 | // FIXME: There is no clear ownership policy now for referenced |
| 129 | // ObjCInterfaceDecls. Some of them can be forward declarations that |
| 130 | // are never later defined (in which case the ObjCClassDecl owns them) |
| 131 | // or the ObjCInterfaceDecl later becomes a real definition later. Ideally |
| 132 | // we should have separate objects for forward declarations and definitions, |
| 133 | // obviating this problem. Because of this situation, referenced |
| 134 | // ObjCInterfaceDecls are destroyed in ~TranslationUnit. |
| 135 | |
| 136 | Decl::Destroy(C); |
| 137 | } |
| 138 | |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 139 | ObjCForwardProtocolDecl * |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 140 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 141 | SourceLocation L, |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 142 | ObjCProtocolDecl **Elts, unsigned NumElts) { |
| 143 | void *Mem = C.getAllocator().Allocate<ObjCForwardProtocolDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 144 | return new (Mem) ObjCForwardProtocolDecl(DC, L, Elts, NumElts); |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Ted Kremenek | 05ac3ef | 2008-06-06 21:05:33 +0000 | [diff] [blame] | 147 | ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() { |
| 148 | delete [] ReferencedProtocols; |
| 149 | } |
| 150 | |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 151 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 152 | SourceLocation L, |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 153 | IdentifierInfo *Id) { |
| 154 | void *Mem = C.getAllocator().Allocate<ObjCCategoryDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 155 | return new (Mem) ObjCCategoryDecl(DC, L, Id); |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 158 | ObjCCategoryImplDecl * |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 159 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 160 | SourceLocation L,IdentifierInfo *Id, |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 161 | ObjCInterfaceDecl *ClassInterface) { |
| 162 | void *Mem = C.getAllocator().Allocate<ObjCCategoryImplDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 163 | return new (Mem) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | ObjCImplementationDecl * |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 167 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 168 | SourceLocation L, |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 169 | IdentifierInfo *Id, |
| 170 | ObjCInterfaceDecl *ClassInterface, |
| 171 | ObjCInterfaceDecl *SuperDecl) { |
| 172 | void *Mem = C.getAllocator().Allocate<ObjCImplementationDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 173 | return new (Mem) ObjCImplementationDecl(DC, L, Id, ClassInterface, SuperDecl); |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 174 | } |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 175 | |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 176 | ObjCCompatibleAliasDecl * |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 177 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 178 | SourceLocation L, |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 179 | IdentifierInfo *Id, |
| 180 | ObjCInterfaceDecl* AliasedClass) { |
| 181 | void *Mem = C.getAllocator().Allocate<ObjCCompatibleAliasDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 182 | return new (Mem) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 185 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 186 | SourceLocation L, |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 187 | IdentifierInfo *Id, |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 188 | QualType T, |
| 189 | PropertyControl propControl) { |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 190 | void *Mem = C.getAllocator().Allocate<ObjCPropertyDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 191 | return new (Mem) ObjCPropertyDecl(DC, L, Id, T); |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 194 | //===----------------------------------------------------------------------===// |
| 195 | // Objective-C Decl Implementation |
| 196 | //===----------------------------------------------------------------------===// |
| 197 | |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 198 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
| 199 | const ObjCInterfaceDecl *OID) { |
Daniel Dunbar | 08a356c | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 200 | QualType selfTy; |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 201 | if (isInstanceMethod()) { |
Daniel Dunbar | 08a356c | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 202 | // There may be no interface context due to error in declaration |
| 203 | // of the interface (which has been reported). Recover gracefully. |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 204 | if (OID) { |
| 205 | selfTy = Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl *>(OID)); |
Daniel Dunbar | 08a356c | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 206 | selfTy = Context.getPointerType(selfTy); |
| 207 | } else { |
| 208 | selfTy = Context.getObjCIdType(); |
| 209 | } |
| 210 | } else // we have a factory method. |
| 211 | selfTy = Context.getObjCClassType(); |
| 212 | |
| 213 | SelfDecl = ImplicitParamDecl::Create(Context, this, |
| 214 | SourceLocation(), |
| 215 | &Context.Idents.get("self"), |
| 216 | selfTy, 0); |
| 217 | |
| 218 | CmdDecl = ImplicitParamDecl::Create(Context, this, |
| 219 | SourceLocation(), |
| 220 | &Context.Idents.get("_cmd"), |
| 221 | Context.getObjCSelType(), 0); |
| 222 | } |
| 223 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 224 | void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, |
| 225 | unsigned NumParams) { |
| 226 | assert(ParamInfo == 0 && "Already has param info!"); |
| 227 | |
| 228 | // Zero params -> null pointer. |
| 229 | if (NumParams) { |
| 230 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 231 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 232 | NumMethodParams = NumParams; |
| 233 | } |
| 234 | } |
| 235 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 236 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 237 | /// categories for this class and returns it. Name of the category is passed |
| 238 | /// in 'CategoryId'. If category not found, return 0; |
| 239 | /// |
| 240 | ObjCCategoryDecl * |
| 241 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 242 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 243 | Category; Category = Category->getNextClassCategory()) |
| 244 | if (Category->getIdentifier() == CategoryId) |
| 245 | return Category; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | /// FindIvarDeclaration - Find an Ivar declaration in this class given its |
| 250 | /// name in 'IvarId'. On failure to find, return 0; |
| 251 | /// |
| 252 | ObjCIvarDecl * |
| 253 | ObjCInterfaceDecl::FindIvarDeclaration(IdentifierInfo *IvarId) const { |
| 254 | for (ObjCInterfaceDecl::ivar_iterator IVI = ivar_begin(), |
| 255 | IVE = ivar_end(); IVI != IVE; ++IVI) { |
| 256 | ObjCIvarDecl* Ivar = (*IVI); |
| 257 | if (Ivar->getIdentifier() == IvarId) |
| 258 | return Ivar; |
| 259 | } |
Fariborz Jahanian | c70bee8 | 2008-04-21 23:57:08 +0000 | [diff] [blame] | 260 | if (getSuperClass()) |
| 261 | return getSuperClass()->FindIvarDeclaration(IvarId); |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 265 | /// ObjCAddInstanceVariablesToClass - Inserts instance variables |
| 266 | /// into ObjCInterfaceDecl's fields. |
| 267 | /// |
| 268 | void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars, |
| 269 | unsigned numIvars, |
| 270 | SourceLocation RBrac) { |
| 271 | NumIvars = numIvars; |
| 272 | if (numIvars) { |
| 273 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 274 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
| 275 | } |
| 276 | setLocEnd(RBrac); |
| 277 | } |
| 278 | |
Fariborz Jahanian | aaa63a7 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 279 | /// lookupFieldDeclForIvar - looks up a field decl' in the laid out |
| 280 | /// storage which matches this 'ivar'. |
| 281 | /// |
| 282 | FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, |
Fariborz Jahanian | fd64bb6 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 283 | const ObjCIvarDecl *ivar) { |
Fariborz Jahanian | a769c00 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 284 | const RecordDecl *RecordForDecl = Context.addRecordToClass(this); |
Fariborz Jahanian | aaa63a7 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 285 | assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class"); |
| 286 | DeclarationName Member = ivar->getDeclName(); |
Fariborz Jahanian | a769c00 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 287 | DeclContext::lookup_result Lookup = (const_cast< RecordDecl *>(RecordForDecl)) |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 288 | ->lookup(Member); |
Fariborz Jahanian | aaa63a7 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 289 | assert((Lookup.first != Lookup.second) && "field decl not found"); |
| 290 | FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first); |
| 291 | assert(MemberDecl && "field decl not found"); |
| 292 | return MemberDecl; |
| 293 | } |
| 294 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 295 | /// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance |
| 296 | /// Variables (Ivars) relative to what declared in @implementation;s class. |
| 297 | /// Ivars into ObjCImplementationDecl's fields. |
| 298 | /// |
| 299 | void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( |
| 300 | ObjCIvarDecl **ivars, unsigned numIvars) { |
| 301 | NumIvars = numIvars; |
| 302 | if (numIvars) { |
| 303 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 304 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
| 305 | } |
| 306 | } |
| 307 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 308 | // Get the local instance method declared in this interface. |
| 309 | // FIXME: handle overloading, instance & class methods can have the same name. |
| 310 | ObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const { |
| 311 | lookup_const_result MethodResult = lookup(Sel); |
| 312 | if (MethodResult.first) |
| 313 | return const_cast<ObjCMethodDecl*>( |
| 314 | dyn_cast<ObjCMethodDecl>(*MethodResult.first)); |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | // Get the local class method declared in this interface. |
| 319 | ObjCMethodDecl *ObjCContainerDecl::getClassMethod(Selector Sel) const { |
| 320 | lookup_const_result MethodResult = lookup(Sel); |
| 321 | if (MethodResult.first) |
| 322 | return const_cast<ObjCMethodDecl*>( |
| 323 | dyn_cast<ObjCMethodDecl>(*MethodResult.first)); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | unsigned ObjCContainerDecl::getNumInstanceMethods() const { |
| 328 | unsigned sum = 0; |
| 329 | for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I != E; ++I) |
| 330 | sum++; |
| 331 | return sum; |
| 332 | } |
| 333 | unsigned ObjCContainerDecl::getNumClassMethods() const { |
| 334 | unsigned sum = 0; |
| 335 | for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I != E; ++I) |
| 336 | sum++; |
| 337 | return sum; |
| 338 | } |
Steve Naroff | 6327e0d | 2009-01-11 01:06:09 +0000 | [diff] [blame] | 339 | unsigned ObjCContainerDecl::getNumProperties() const { |
| 340 | unsigned sum = 0; |
| 341 | for (prop_iterator I=prop_begin(), E=prop_end(); I != E; ++I) |
| 342 | sum++; |
| 343 | return sum; |
| 344 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 345 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 346 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 347 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Steve Naroff | 93983f8 | 2009-01-11 12:47:58 +0000 | [diff] [blame] | 348 | /// FIXME: Convert to DeclContext lookup... |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 349 | /// |
| 350 | ObjCPropertyDecl * |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 351 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
| 352 | for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I) { |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 353 | ObjCPropertyDecl *property = *I; |
| 354 | if (property->getIdentifier() == PropertyId) |
| 355 | return property; |
| 356 | } |
Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 357 | const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this); |
| 358 | if (PID) { |
| 359 | for (ObjCProtocolDecl::protocol_iterator P = PID->protocol_begin(), |
| 360 | E = PID->protocol_end(); |
| 361 | P != E; ++P) |
| 362 | if (ObjCPropertyDecl *property = |
| 363 | (*P)->FindPropertyDeclaration(PropertyId)) |
| 364 | return property; |
| 365 | } |
| 366 | |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 367 | const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this); |
| 368 | if (OID) { |
| 369 | // Look through categories. |
| 370 | for (ObjCCategoryDecl *Category = OID->getCategoryList(); |
| 371 | Category; Category = Category->getNextClassCategory()) { |
| 372 | ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId); |
| 373 | if (property) |
| 374 | return property; |
| 375 | } |
| 376 | // Look through protocols. |
| 377 | for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(), |
| 378 | E = OID->protocol_end(); I != E; ++I) { |
| 379 | ObjCProtocolDecl *Protocol = *I; |
| 380 | ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); |
| 381 | if (property) |
| 382 | return property; |
| 383 | } |
| 384 | if (OID->getSuperClass()) |
| 385 | return OID->getSuperClass()->FindPropertyDeclaration(PropertyId); |
Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 390 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable( |
| 391 | IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) { |
| 392 | ObjCInterfaceDecl* ClassDecl = this; |
| 393 | while (ClassDecl != NULL) { |
| 394 | for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end(); |
| 395 | I != E; ++I) { |
| 396 | if ((*I)->getIdentifier() == ID) { |
| 397 | clsDeclared = ClassDecl; |
| 398 | return *I; |
| 399 | } |
| 400 | } |
| 401 | ClassDecl = ClassDecl->getSuperClass(); |
| 402 | } |
| 403 | return NULL; |
| 404 | } |
| 405 | |
| 406 | /// lookupInstanceMethod - This method returns an instance method by looking in |
| 407 | /// the class, its categories, and its super classes (using a linear search). |
| 408 | ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) { |
| 409 | ObjCInterfaceDecl* ClassDecl = this; |
| 410 | ObjCMethodDecl *MethodDecl = 0; |
| 411 | |
| 412 | while (ClassDecl != NULL) { |
| 413 | if ((MethodDecl = ClassDecl->getInstanceMethod(Sel))) |
| 414 | return MethodDecl; |
| 415 | |
| 416 | // Didn't find one yet - look through protocols. |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 417 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 418 | ClassDecl->getReferencedProtocols(); |
| 419 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 420 | E = Protocols.end(); I != E; ++I) |
| 421 | if ((MethodDecl = (*I)->getInstanceMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 422 | return MethodDecl; |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 424 | // Didn't find one yet - now look through categories. |
| 425 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 426 | while (CatDecl) { |
| 427 | if ((MethodDecl = CatDecl->getInstanceMethod(Sel))) |
| 428 | return MethodDecl; |
Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 429 | |
| 430 | // Didn't find one yet - look through protocols. |
| 431 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 432 | CatDecl->getReferencedProtocols(); |
| 433 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 434 | E = Protocols.end(); I != E; ++I) |
| 435 | if ((MethodDecl = (*I)->getInstanceMethod(Sel))) |
| 436 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 437 | CatDecl = CatDecl->getNextClassCategory(); |
| 438 | } |
| 439 | ClassDecl = ClassDecl->getSuperClass(); |
| 440 | } |
| 441 | return NULL; |
| 442 | } |
| 443 | |
| 444 | // lookupClassMethod - This method returns a class method by looking in the |
| 445 | // class, its categories, and its super classes (using a linear search). |
| 446 | ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { |
| 447 | ObjCInterfaceDecl* ClassDecl = this; |
| 448 | ObjCMethodDecl *MethodDecl = 0; |
| 449 | |
| 450 | while (ClassDecl != NULL) { |
| 451 | if ((MethodDecl = ClassDecl->getClassMethod(Sel))) |
| 452 | return MethodDecl; |
| 453 | |
| 454 | // Didn't find one yet - look through protocols. |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 455 | for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), |
| 456 | E = ClassDecl->protocol_end(); I != E; ++I) |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 457 | if ((MethodDecl = (*I)->getClassMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 458 | return MethodDecl; |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 459 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 460 | // Didn't find one yet - now look through categories. |
| 461 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 462 | while (CatDecl) { |
| 463 | if ((MethodDecl = CatDecl->getClassMethod(Sel))) |
| 464 | return MethodDecl; |
| 465 | CatDecl = CatDecl->getNextClassCategory(); |
| 466 | } |
| 467 | ClassDecl = ClassDecl->getSuperClass(); |
| 468 | } |
| 469 | return NULL; |
| 470 | } |
| 471 | |
Daniel Dunbar | 3216dcd | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 472 | /// getInstanceMethod - This method returns an instance method by |
| 473 | /// looking in the class implementation. Unlike interfaces, we don't |
| 474 | /// look outside the implementation. |
| 475 | ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) const { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 476 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 477 | if ((*I)->getSelector() == Sel) |
| 478 | return *I; |
| 479 | return NULL; |
| 480 | } |
| 481 | |
Daniel Dunbar | 3216dcd | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 482 | /// getClassMethod - This method returns a class method by looking in |
| 483 | /// the class implementation. Unlike interfaces, we don't look outside |
| 484 | /// the implementation. |
| 485 | ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) const { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 486 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 487 | I != E; ++I) |
| 488 | if ((*I)->getSelector() == Sel) |
| 489 | return *I; |
| 490 | return NULL; |
| 491 | } |
| 492 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 493 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 494 | /// added to the list of those properties @synthesized/@dynamic in this |
| 495 | /// @implementation block. |
| 496 | /// |
| 497 | ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 498 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 499 | ObjCPropertyImplDecl *PID = *i; |
| 500 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 501 | return PID; |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Fariborz Jahanian | 9482a4f | 2008-12-05 22:36:19 +0000 | [diff] [blame] | 507 | /// properties implemented in this @implementation block and returns the |
| 508 | /// implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 509 | /// |
| 510 | ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 511 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 512 | ObjCPropertyImplDecl *PID = *i; |
| 513 | if (PID->getPropertyIvarDecl() && |
| 514 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 515 | return PID; |
| 516 | } |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Fariborz Jahanian | 9482a4f | 2008-12-05 22:36:19 +0000 | [diff] [blame] | 521 | /// properties implemented in this category @implementation block and returns the |
| 522 | /// implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 523 | /// |
| 524 | ObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 525 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 526 | ObjCPropertyImplDecl *PID = *i; |
| 527 | if (PID->getPropertyIvarDecl() && |
| 528 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 529 | return PID; |
| 530 | } |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 535 | /// added to the list of those properties @synthesized/@dynamic in this |
| 536 | /// category @implementation block. |
| 537 | /// |
| 538 | ObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 539 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 540 | ObjCPropertyImplDecl *PID = *i; |
| 541 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 542 | return PID; |
| 543 | } |
| 544 | return 0; |
| 545 | } |
| 546 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 547 | // lookupInstanceMethod - This method returns an instance method by looking in |
| 548 | // the class implementation. Unlike interfaces, we don't look outside the |
| 549 | // implementation. |
Daniel Dunbar | 3216dcd | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 550 | ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) const { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 551 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 552 | if ((*I)->getSelector() == Sel) |
| 553 | return *I; |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | // lookupClassMethod - This method returns an instance method by looking in |
| 558 | // the class implementation. Unlike interfaces, we don't look outside the |
| 559 | // implementation. |
Daniel Dunbar | 3216dcd | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 560 | ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) const { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 561 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 562 | I != E; ++I) |
| 563 | if ((*I)->getSelector() == Sel) |
| 564 | return *I; |
| 565 | return NULL; |
| 566 | } |
| 567 | |
| 568 | // lookupInstanceMethod - Lookup a instance method in the protocol and protocols |
| 569 | // it inherited. |
| 570 | ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { |
| 571 | ObjCMethodDecl *MethodDecl = NULL; |
| 572 | |
| 573 | if ((MethodDecl = getInstanceMethod(Sel))) |
| 574 | return MethodDecl; |
| 575 | |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 576 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Steve Naroff | d8df682 | 2008-12-18 15:50:41 +0000 | [diff] [blame] | 577 | if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 578 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 579 | return NULL; |
| 580 | } |
| 581 | |
| 582 | // lookupInstanceMethod - Lookup a class method in the protocol and protocols |
| 583 | // it inherited. |
| 584 | ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { |
| 585 | ObjCMethodDecl *MethodDecl = NULL; |
| 586 | |
| 587 | if ((MethodDecl = getClassMethod(Sel))) |
| 588 | return MethodDecl; |
| 589 | |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 590 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Steve Naroff | d8df682 | 2008-12-18 15:50:41 +0000 | [diff] [blame] | 591 | if ((MethodDecl = (*I)->lookupClassMethod(Sel))) |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 592 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 593 | return NULL; |
| 594 | } |
| 595 | |
| 596 | /// getSynthesizedMethodSize - Compute size of synthesized method name |
| 597 | /// as done be the rewrite. |
| 598 | /// |
| 599 | unsigned ObjCMethodDecl::getSynthesizedMethodSize() const { |
| 600 | // syntesized method name is a concatenation of -/+[class-name selector] |
| 601 | // Get length of this name. |
| 602 | unsigned length = 3; // _I_ or _C_ |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 603 | length += getClassInterface()->getNameAsString().size()+1; // extra for _ |
Steve Naroff | 3e0a540 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 604 | if (const ObjCCategoryImplDecl *CID = |
| 605 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 606 | length += CID->getNameAsString().size()+1; |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 607 | length += getSelector().getAsString().size(); // selector name |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 608 | return length; |
| 609 | } |
| 610 | |
Chris Lattner | 5619688 | 2008-04-06 05:25:03 +0000 | [diff] [blame] | 611 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
Steve Naroff | 3e0a540 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 612 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 613 | return ID; |
Steve Naroff | 3e0a540 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 614 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 615 | return CD->getClassInterface(); |
| 616 | if (ObjCImplementationDecl *IMD = |
Steve Naroff | 3e0a540 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 617 | dyn_cast<ObjCImplementationDecl>(getDeclContext())) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 618 | return IMD->getClassInterface(); |
Steve Naroff | 3e0a540 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 619 | if (ObjCCategoryImplDecl *CID = |
| 620 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 621 | return CID->getClassInterface(); |
| 622 | assert(false && "unknown method context"); |
| 623 | return 0; |
| 624 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 625 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 626 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 627 | DeclContext *DC, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 628 | SourceLocation atLoc, |
| 629 | SourceLocation L, |
| 630 | ObjCPropertyDecl *property, |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 631 | Kind PK, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 632 | ObjCIvarDecl *ivar) { |
| 633 | void *Mem = C.getAllocator().Allocate<ObjCPropertyImplDecl>(); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 634 | return new (Mem) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 635 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 636 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 637 | |