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