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