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" |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/Stmt.h" |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Anna Zaks | ad0ce53 | 2012-09-27 19:45:11 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===// |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 24 | // ObjCListBase |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 27 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 28 | List = 0; |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 29 | if (Elts == 0) return; // Setting to an empty list is a noop. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | |
| 31 | |
Chris Lattner | 4ee413b | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 32 | List = new (Ctx) void*[Elts]; |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 33 | NumElts = Elts; |
| 34 | memcpy(List, InList, sizeof(void*)*Elts); |
| 35 | } |
| 36 | |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 37 | void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, |
| 38 | const SourceLocation *Locs, ASTContext &Ctx) { |
| 39 | if (Elts == 0) |
| 40 | return; |
| 41 | |
| 42 | Locations = new (Ctx) SourceLocation[Elts]; |
| 43 | memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); |
| 44 | set(InList, Elts, Ctx); |
| 45 | } |
| 46 | |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 47 | //===----------------------------------------------------------------------===// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 48 | // ObjCInterfaceDecl |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 49 | //===----------------------------------------------------------------------===// |
| 50 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 51 | void ObjCContainerDecl::anchor() { } |
| 52 | |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 53 | /// getIvarDecl - This method looks up an ivar in this ContextDecl. |
| 54 | /// |
| 55 | ObjCIvarDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 56 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 57 | lookup_const_result R = lookup(Id); |
| 58 | for (lookup_const_iterator Ivar = R.begin(), IvarEnd = R.end(); |
| 59 | Ivar != IvarEnd; ++Ivar) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 60 | if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 61 | return ivar; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 66 | // Get the local instance/class method declared in this interface. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 67 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 68 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const { |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 69 | // If this context is a hidden protocol definition, don't find any |
| 70 | // methods there. |
| 71 | if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) { |
| 72 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 73 | if (Def->isHidden()) |
| 74 | return 0; |
| 75 | } |
| 76 | |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 77 | // Since instance & class methods can have the same name, the loop below |
| 78 | // ensures we get the correct method. |
| 79 | // |
| 80 | // @interface Whatever |
| 81 | // - (int) class_method; |
| 82 | // + (float) class_method; |
| 83 | // @end |
| 84 | // |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 85 | lookup_const_result R = lookup(Sel); |
| 86 | for (lookup_const_iterator Meth = R.begin(), MethEnd = R.end(); |
| 87 | Meth != MethEnd; ++Meth) { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 88 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 89 | if (MD && MD->isInstanceMethod() == isInstance) |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 90 | return MD; |
| 91 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
Fariborz Jahanian | 5bdaef5 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 95 | /// HasUserDeclaredSetterMethod - This routine returns 'true' if a user declared setter |
| 96 | /// method was found in the class, its protocols, its super classes or categories. |
| 97 | /// It also returns 'true' if one of its categories has declared a 'readwrite' property. |
| 98 | /// This is because, user must provide a setter method for the category's 'readwrite' |
| 99 | /// property. |
| 100 | bool |
| 101 | ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property) const { |
| 102 | Selector Sel = Property->getSetterName(); |
| 103 | lookup_const_result R = lookup(Sel); |
| 104 | for (lookup_const_iterator Meth = R.begin(), MethEnd = R.end(); |
| 105 | Meth != MethEnd; ++Meth) { |
| 106 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 107 | if (MD && MD->isInstanceMethod() && !MD->isImplicit()) |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(this)) { |
| 112 | // Also look into categories, including class extensions, looking |
| 113 | // for a user declared instance method. |
| 114 | for (ObjCInterfaceDecl::visible_categories_iterator |
| 115 | Cat = ID->visible_categories_begin(), |
| 116 | CatEnd = ID->visible_categories_end(); |
| 117 | Cat != CatEnd; |
| 118 | ++Cat) { |
| 119 | if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel)) |
| 120 | if (!MD->isImplicit()) |
| 121 | return true; |
| 122 | if (Cat->IsClassExtension()) |
| 123 | continue; |
| 124 | // Also search through the categories looking for a 'readwrite' declaration |
| 125 | // of this property. If one found, presumably a setter will be provided |
| 126 | // (properties declared in categories will not get auto-synthesized). |
| 127 | for (ObjCContainerDecl::prop_iterator P = Cat->prop_begin(), |
| 128 | E = Cat->prop_end(); P != E; ++P) |
| 129 | if (P->getIdentifier() == Property->getIdentifier()) { |
| 130 | if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) |
| 131 | return true; |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Also look into protocols, for a user declared instance method. |
| 137 | for (ObjCInterfaceDecl::all_protocol_iterator P = |
| 138 | ID->all_referenced_protocol_begin(), |
| 139 | PE = ID->all_referenced_protocol_end(); P != PE; ++P) { |
| 140 | ObjCProtocolDecl *Proto = (*P); |
| 141 | if (Proto->HasUserDeclaredSetterMethod(Property)) |
| 142 | return true; |
| 143 | } |
| 144 | // And in its super class. |
| 145 | ObjCInterfaceDecl *OSC = ID->getSuperClass(); |
| 146 | while (OSC) { |
| 147 | if (OSC->HasUserDeclaredSetterMethod(Property)) |
| 148 | return true; |
| 149 | OSC = OSC->getSuperClass(); |
| 150 | } |
| 151 | } |
| 152 | if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this)) |
| 153 | for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(), |
| 154 | E = PD->protocol_end(); PI != E; ++PI) { |
| 155 | if ((*PI)->HasUserDeclaredSetterMethod(Property)) |
| 156 | return true; |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 161 | ObjCPropertyDecl * |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 162 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 163 | IdentifierInfo *propertyID) { |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 164 | // If this context is a hidden protocol definition, don't find any |
| 165 | // property. |
| 166 | if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) { |
| 167 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 168 | if (Def->isHidden()) |
| 169 | return 0; |
| 170 | } |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 171 | |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 172 | DeclContext::lookup_const_result R = DC->lookup(propertyID); |
| 173 | for (DeclContext::lookup_const_iterator I = R.begin(), E = R.end(); I != E; |
| 174 | ++I) |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 175 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) |
| 176 | return PD; |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Anna Zaks | ad0ce53 | 2012-09-27 19:45:11 +0000 | [diff] [blame] | 181 | IdentifierInfo * |
| 182 | ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const { |
| 183 | SmallString<128> ivarName; |
| 184 | { |
| 185 | llvm::raw_svector_ostream os(ivarName); |
| 186 | os << '_' << getIdentifier()->getName(); |
| 187 | } |
| 188 | return &Ctx.Idents.get(ivarName.str()); |
| 189 | } |
| 190 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 191 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 192 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 193 | ObjCPropertyDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 194 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 195 | // Don't find properties within hidden protocol definitions. |
| 196 | if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) { |
| 197 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 198 | if (Def->isHidden()) |
| 199 | return 0; |
| 200 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 202 | if (ObjCPropertyDecl *PD = |
| 203 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 204 | return PD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 205 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 206 | switch (getKind()) { |
| 207 | default: |
| 208 | break; |
| 209 | case Decl::ObjCProtocol: { |
| 210 | const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); |
| 211 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 212 | E = PID->protocol_end(); I != E; ++I) |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 213 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 214 | return P; |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | case Decl::ObjCInterface: { |
| 218 | const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 219 | // Look through categories (but not extensions). |
| 220 | for (ObjCInterfaceDecl::visible_categories_iterator |
| 221 | Cat = OID->visible_categories_begin(), |
| 222 | CatEnd = OID->visible_categories_end(); |
| 223 | Cat != CatEnd; ++Cat) { |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 224 | if (!Cat->IsClassExtension()) |
| 225 | if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) |
| 226 | return P; |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 227 | } |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 228 | |
| 229 | // Look through protocols. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 230 | for (ObjCInterfaceDecl::all_protocol_iterator |
| 231 | I = OID->all_referenced_protocol_begin(), |
| 232 | E = OID->all_referenced_protocol_end(); I != E; ++I) |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 233 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 234 | return P; |
| 235 | |
| 236 | // Finally, check the super class. |
| 237 | if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) |
| 238 | return superClass->FindPropertyDeclaration(PropertyId); |
| 239 | break; |
| 240 | } |
| 241 | case Decl::ObjCCategory: { |
| 242 | const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); |
| 243 | // Look through protocols. |
| 244 | if (!OCD->IsClassExtension()) |
| 245 | for (ObjCCategoryDecl::protocol_iterator |
| 246 | I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I) |
| 247 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 248 | return P; |
| 249 | |
| 250 | break; |
Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 256 | void ObjCInterfaceDecl::anchor() { } |
| 257 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 258 | /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property |
| 259 | /// with name 'PropertyId' in the primary class; including those in protocols |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 260 | /// (direct or indirect) used by the primary class. |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 261 | /// |
| 262 | ObjCPropertyDecl * |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 263 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 264 | IdentifierInfo *PropertyId) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 265 | // FIXME: Should make sure no callers ever do this. |
| 266 | if (!hasDefinition()) |
| 267 | return 0; |
| 268 | |
| 269 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 270 | LoadExternalDefinition(); |
| 271 | |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 272 | if (ObjCPropertyDecl *PD = |
| 273 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 274 | return PD; |
| 275 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 276 | // Look through protocols. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 277 | for (ObjCInterfaceDecl::all_protocol_iterator |
| 278 | I = all_referenced_protocol_begin(), |
| 279 | E = all_referenced_protocol_end(); I != E; ++I) |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 280 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 281 | return P; |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 282 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 286 | void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 287 | PropertyDeclOrder &PO) const { |
Anna Zaks | b36ea37 | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 288 | for (ObjCContainerDecl::prop_iterator P = prop_begin(), |
| 289 | E = prop_end(); P != E; ++P) { |
| 290 | ObjCPropertyDecl *Prop = *P; |
| 291 | PM[Prop->getIdentifier()] = Prop; |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 292 | PO.push_back(Prop); |
Anna Zaks | b36ea37 | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 293 | } |
| 294 | for (ObjCInterfaceDecl::all_protocol_iterator |
| 295 | PI = all_referenced_protocol_begin(), |
| 296 | E = all_referenced_protocol_end(); PI != E; ++PI) |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 297 | (*PI)->collectPropertiesToImplement(PM, PO); |
Anna Zaks | e63aedd | 2012-10-31 01:18:22 +0000 | [diff] [blame] | 298 | // Note, the properties declared only in class extensions are still copied |
| 299 | // into the main @interface's property list, and therefore we don't |
| 300 | // explicitly, have to search class extension properties. |
Anna Zaks | b36ea37 | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 303 | bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const { |
| 304 | const ObjCInterfaceDecl *Class = this; |
| 305 | while (Class) { |
| 306 | if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) |
| 307 | return true; |
| 308 | Class = Class->getSuperClass(); |
| 309 | } |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const { |
| 314 | const ObjCInterfaceDecl *Class = this; |
| 315 | while (Class) { |
| 316 | if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>()) |
| 317 | return Class; |
| 318 | Class = Class->getSuperClass(); |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 323 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 324 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
| 325 | ASTContext &C) |
| 326 | { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 327 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 328 | LoadExternalDefinition(); |
| 329 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 330 | if (data().AllReferencedProtocols.empty() && |
| 331 | data().ReferencedProtocols.empty()) { |
| 332 | data().AllReferencedProtocols.set(ExtList, ExtNum, C); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 333 | return; |
| 334 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 335 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 336 | // Check for duplicate protocol in class's protocol list. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 337 | // This is O(n*m). But it is extremely rare and number of protocols in |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 338 | // class or its extension are very few. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 339 | SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 340 | for (unsigned i = 0; i < ExtNum; i++) { |
| 341 | bool protocolExists = false; |
| 342 | ObjCProtocolDecl *ProtoInExtension = ExtList[i]; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 343 | for (all_protocol_iterator |
| 344 | p = all_referenced_protocol_begin(), |
| 345 | e = all_referenced_protocol_end(); p != e; ++p) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 346 | ObjCProtocolDecl *Proto = (*p); |
| 347 | if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { |
| 348 | protocolExists = true; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | // Do we want to warn on a protocol in extension class which |
| 353 | // already exist in the class? Probably not. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 354 | if (!protocolExists) |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 355 | ProtocolRefs.push_back(ProtoInExtension); |
| 356 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 357 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 358 | if (ProtocolRefs.empty()) |
| 359 | return; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 360 | |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 361 | // Merge ProtocolRefs into class's protocol list; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 362 | for (all_protocol_iterator p = all_referenced_protocol_begin(), |
| 363 | e = all_referenced_protocol_end(); p != e; ++p) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 364 | ProtocolRefs.push_back(*p); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 365 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 366 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 367 | data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 370 | void ObjCInterfaceDecl::allocateDefinitionData() { |
| 371 | assert(!hasDefinition() && "ObjC class already has a definition"); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 372 | Data.setPointer(new (getASTContext()) DefinitionData()); |
| 373 | Data.getPointer()->Definition = this; |
Douglas Gregor | 8d2dbbf | 2011-12-16 16:34:57 +0000 | [diff] [blame] | 374 | |
| 375 | // Make the type point at the definition, now that we have one. |
| 376 | if (TypeForDecl) |
| 377 | cast<ObjCInterfaceType>(TypeForDecl)->Decl = this; |
Douglas Gregor | 0af5501 | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void ObjCInterfaceDecl::startDefinition() { |
| 381 | allocateDefinitionData(); |
| 382 | |
Douglas Gregor | 53df7a1 | 2011-12-15 18:03:09 +0000 | [diff] [blame] | 383 | // Update all of the declarations with a pointer to the definition. |
| 384 | for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); |
| 385 | RD != RDEnd; ++RD) { |
| 386 | if (*RD != this) |
Douglas Gregor | 26fec63 | 2011-12-15 18:17:27 +0000 | [diff] [blame] | 387 | RD->Data = Data; |
Douglas Gregor | 53df7a1 | 2011-12-15 18:03:09 +0000 | [diff] [blame] | 388 | } |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 391 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 392 | ObjCInterfaceDecl *&clsDeclared) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 393 | // FIXME: Should make sure no callers ever do this. |
| 394 | if (!hasDefinition()) |
| 395 | return 0; |
| 396 | |
| 397 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 398 | LoadExternalDefinition(); |
| 399 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 400 | ObjCInterfaceDecl* ClassDecl = this; |
| 401 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 402 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 403 | clsDeclared = ClassDecl; |
| 404 | return I; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 405 | } |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 406 | |
| 407 | for (ObjCInterfaceDecl::visible_extensions_iterator |
| 408 | Ext = ClassDecl->visible_extensions_begin(), |
| 409 | ExtEnd = ClassDecl->visible_extensions_end(); |
| 410 | Ext != ExtEnd; ++Ext) { |
| 411 | if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) { |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 412 | clsDeclared = ClassDecl; |
| 413 | return I; |
| 414 | } |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 415 | } |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 416 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 417 | ClassDecl = ClassDecl->getSuperClass(); |
| 418 | } |
| 419 | return NULL; |
| 420 | } |
| 421 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 422 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 423 | /// class whose name is passed as argument. If it is not one of the super classes |
| 424 | /// the it returns NULL. |
| 425 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 426 | const IdentifierInfo*ICName) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 427 | // FIXME: Should make sure no callers ever do this. |
| 428 | if (!hasDefinition()) |
| 429 | return 0; |
| 430 | |
| 431 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 432 | LoadExternalDefinition(); |
| 433 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 434 | ObjCInterfaceDecl* ClassDecl = this; |
| 435 | while (ClassDecl != NULL) { |
| 436 | if (ClassDecl->getIdentifier() == ICName) |
| 437 | return ClassDecl; |
| 438 | ClassDecl = ClassDecl->getSuperClass(); |
| 439 | } |
| 440 | return NULL; |
| 441 | } |
| 442 | |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 443 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 444 | /// the class, its categories, and its super classes (using a linear search). |
Fariborz Jahanian | bf393be | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 445 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 446 | bool isInstance, |
| 447 | bool shallowCategoryLookup) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 448 | // FIXME: Should make sure no callers ever do this. |
| 449 | if (!hasDefinition()) |
| 450 | return 0; |
| 451 | |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 452 | const ObjCInterfaceDecl* ClassDecl = this; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 453 | ObjCMethodDecl *MethodDecl = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 455 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 456 | LoadExternalDefinition(); |
| 457 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 458 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 459 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 460 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 462 | // Didn't find one yet - look through protocols. |
Argyrios Kyrtzidis | a5f4441 | 2012-03-13 01:09:41 +0000 | [diff] [blame] | 463 | for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), |
| 464 | E = ClassDecl->protocol_end(); |
| 465 | I != E; ++I) |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 466 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 467 | return MethodDecl; |
Fariborz Jahanian | bf393be | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 468 | |
| 469 | // Didn't find one yet - now look through categories. |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 470 | for (ObjCInterfaceDecl::visible_categories_iterator |
| 471 | Cat = ClassDecl->visible_categories_begin(), |
| 472 | CatEnd = ClassDecl->visible_categories_end(); |
| 473 | Cat != CatEnd; ++Cat) { |
| 474 | if ((MethodDecl = Cat->getMethod(Sel, isInstance))) |
Fariborz Jahanian | bf393be | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 475 | return MethodDecl; |
Fariborz Jahanian | bb3d14e | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 476 | |
Fariborz Jahanian | bf393be | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 477 | if (!shallowCategoryLookup) { |
Fariborz Jahanian | bb3d14e | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 478 | // Didn't find one yet - look through protocols. |
| 479 | const ObjCList<ObjCProtocolDecl> &Protocols = |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 480 | Cat->getReferencedProtocols(); |
Fariborz Jahanian | bb3d14e | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 481 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 482 | E = Protocols.end(); I != E; ++I) |
| 483 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
| 484 | return MethodDecl; |
Fariborz Jahanian | bb3d14e | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 485 | } |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 486 | } |
Fariborz Jahanian | bf393be | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 487 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 488 | ClassDecl = ClassDecl->getSuperClass(); |
| 489 | } |
| 490 | return NULL; |
| 491 | } |
| 492 | |
Anna Zaks | e61354b | 2012-07-27 19:07:44 +0000 | [diff] [blame] | 493 | // Will search "local" class/category implementations for a method decl. |
| 494 | // If failed, then we search in class's root for an instance method. |
| 495 | // Returns 0 if no method is found. |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 496 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( |
| 497 | const Selector &Sel, |
Anna Zaks | ca93ee7 | 2012-07-30 20:31:21 +0000 | [diff] [blame] | 498 | bool Instance) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 499 | // FIXME: Should make sure no callers ever do this. |
| 500 | if (!hasDefinition()) |
| 501 | return 0; |
| 502 | |
| 503 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 504 | LoadExternalDefinition(); |
| 505 | |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 506 | ObjCMethodDecl *Method = 0; |
| 507 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 508 | Method = Instance ? ImpDecl->getInstanceMethod(Sel) |
| 509 | : ImpDecl->getClassMethod(Sel); |
Anna Zaks | e61354b | 2012-07-27 19:07:44 +0000 | [diff] [blame] | 510 | |
| 511 | // Look through local category implementations associated with the class. |
| 512 | if (!Method) |
| 513 | Method = Instance ? getCategoryInstanceMethod(Sel) |
| 514 | : getCategoryClassMethod(Sel); |
| 515 | |
| 516 | // Before we give up, check if the selector is an instance method. |
| 517 | // But only in the root. This matches gcc's behavior and what the |
| 518 | // runtime expects. |
| 519 | if (!Instance && !Method && !getSuperClass()) { |
| 520 | Method = lookupInstanceMethod(Sel); |
| 521 | // Look through local category implementations associated |
| 522 | // with the root class. |
| 523 | if (!Method) |
| 524 | Method = lookupPrivateMethod(Sel, true); |
| 525 | } |
| 526 | |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 527 | if (!Method && getSuperClass()) |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 528 | return getSuperClass()->lookupPrivateMethod(Sel, Instance); |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 529 | return Method; |
| 530 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 531 | |
| 532 | //===----------------------------------------------------------------------===// |
| 533 | // ObjCMethodDecl |
| 534 | //===----------------------------------------------------------------------===// |
| 535 | |
| 536 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | SourceLocation beginLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 538 | SourceLocation endLoc, |
| 539 | Selector SelInfo, QualType T, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 540 | TypeSourceInfo *ResultTInfo, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 541 | DeclContext *contextDecl, |
| 542 | bool isInstance, |
| 543 | bool isVariadic, |
Jordan Rose | 1e4691b | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 544 | bool isPropertyAccessor, |
Argyrios Kyrtzidis | 75cf3e8 | 2011-08-17 19:25:08 +0000 | [diff] [blame] | 545 | bool isImplicitlyDeclared, |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 546 | bool isDefined, |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 547 | ImplementationControl impControl, |
Argyrios Kyrtzidis | da92a7f | 2011-10-03 06:36:29 +0000 | [diff] [blame] | 548 | bool HasRelatedResultType) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 549 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 550 | SelInfo, T, ResultTInfo, contextDecl, |
Jordan Rose | 1e4691b | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 551 | isInstance, isVariadic, isPropertyAccessor, |
| 552 | isImplicitlyDeclared, isDefined, |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 553 | impControl, |
Argyrios Kyrtzidis | da92a7f | 2011-10-03 06:36:29 +0000 | [diff] [blame] | 554 | HasRelatedResultType); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 557 | ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 558 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCMethodDecl)); |
| 559 | return new (Mem) ObjCMethodDecl(SourceLocation(), SourceLocation(), |
| 560 | Selector(), QualType(), 0, 0); |
| 561 | } |
| 562 | |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 563 | Stmt *ObjCMethodDecl::getBody() const { |
| 564 | return Body.get(getASTContext().getExternalSource()); |
| 565 | } |
| 566 | |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 567 | void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { |
| 568 | assert(PrevMethod); |
| 569 | getASTContext().setObjCMethodRedeclaration(PrevMethod, this); |
| 570 | IsRedeclaration = true; |
Argyrios Kyrtzidis | 72b2625 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 571 | PrevMethod->HasRedeclaration = true; |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Argyrios Kyrtzidis | 491306a | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 574 | void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, |
| 575 | ArrayRef<ParmVarDecl*> Params, |
| 576 | ArrayRef<SourceLocation> SelLocs) { |
| 577 | ParamsAndSelLocs = 0; |
| 578 | NumParams = Params.size(); |
| 579 | if (Params.empty() && SelLocs.empty()) |
| 580 | return; |
| 581 | |
| 582 | unsigned Size = sizeof(ParmVarDecl *) * NumParams + |
| 583 | sizeof(SourceLocation) * SelLocs.size(); |
| 584 | ParamsAndSelLocs = C.Allocate(Size); |
| 585 | std::copy(Params.begin(), Params.end(), getParams()); |
| 586 | std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); |
| 587 | } |
| 588 | |
| 589 | void ObjCMethodDecl::getSelectorLocs( |
| 590 | SmallVectorImpl<SourceLocation> &SelLocs) const { |
| 591 | for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) |
| 592 | SelLocs.push_back(getSelectorLoc(i)); |
| 593 | } |
| 594 | |
| 595 | void ObjCMethodDecl::setMethodParams(ASTContext &C, |
| 596 | ArrayRef<ParmVarDecl*> Params, |
| 597 | ArrayRef<SourceLocation> SelLocs) { |
| 598 | assert((!SelLocs.empty() || isImplicit()) && |
| 599 | "No selector locs for non-implicit method"); |
| 600 | if (isImplicit()) |
| 601 | return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); |
| 602 | |
Argyrios Kyrtzidis | a0cff72 | 2012-06-16 00:46:02 +0000 | [diff] [blame] | 603 | SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, |
| 604 | DeclEndLoc); |
Argyrios Kyrtzidis | 491306a | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 605 | if (SelLocsKind != SelLoc_NonStandard) |
| 606 | return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); |
| 607 | |
| 608 | setParamsAndSelLocs(C, Params, SelLocs); |
| 609 | } |
| 610 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 611 | /// \brief A definition will return its interface declaration. |
| 612 | /// An interface declaration will return its definition. |
| 613 | /// Otherwise it will return itself. |
| 614 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { |
| 615 | ASTContext &Ctx = getASTContext(); |
Argyrios Kyrtzidis | 72b2625 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 616 | ObjCMethodDecl *Redecl = 0; |
| 617 | if (HasRedeclaration) |
| 618 | Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); |
Argyrios Kyrtzidis | b40034c | 2011-10-14 06:48:06 +0000 | [diff] [blame] | 619 | if (Redecl) |
| 620 | return Redecl; |
| 621 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 622 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 623 | |
| 624 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 625 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 626 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 627 | |
| 628 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 629 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 630 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 631 | |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 632 | } else if (ObjCImplementationDecl *ImplD = |
| 633 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 634 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 635 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 636 | |
| 637 | } else if (ObjCCategoryImplDecl *CImplD = |
| 638 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 639 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 640 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 643 | if (!Redecl && isRedeclaration()) { |
| 644 | // This is the last redeclaration, go back to the first method. |
| 645 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 646 | isInstanceMethod()); |
| 647 | } |
| 648 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 649 | return Redecl ? Redecl : this; |
| 650 | } |
| 651 | |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 652 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 653 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 654 | |
| 655 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 656 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 657 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 658 | isInstanceMethod())) |
| 659 | return MD; |
| 660 | |
| 661 | } else if (ObjCCategoryImplDecl *CImplD = |
| 662 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 663 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 664 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 665 | isInstanceMethod())) |
| 666 | return MD; |
| 667 | } |
| 668 | |
Argyrios Kyrtzidis | 6d4740e | 2011-10-17 19:48:09 +0000 | [diff] [blame] | 669 | if (isRedeclaration()) |
| 670 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 671 | isInstanceMethod()); |
| 672 | |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 673 | return this; |
| 674 | } |
| 675 | |
Argyrios Kyrtzidis | a0cff72 | 2012-06-16 00:46:02 +0000 | [diff] [blame] | 676 | SourceLocation ObjCMethodDecl::getLocEnd() const { |
| 677 | if (Stmt *Body = getBody()) |
| 678 | return Body->getLocEnd(); |
| 679 | return DeclEndLoc; |
| 680 | } |
| 681 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 682 | ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { |
| 683 | ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family); |
John McCall | d976c8e | 2011-03-02 21:01:41 +0000 | [diff] [blame] | 684 | if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 685 | return family; |
| 686 | |
John McCall | d5313b0 | 2011-03-02 11:33:24 +0000 | [diff] [blame] | 687 | // Check for an explicit attribute. |
| 688 | if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { |
| 689 | // The unfortunate necessity of mapping between enums here is due |
| 690 | // to the attributes framework. |
| 691 | switch (attr->getFamily()) { |
| 692 | case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; |
| 693 | case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; |
| 694 | case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; |
| 695 | case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; |
| 696 | case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; |
| 697 | case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; |
| 698 | } |
| 699 | Family = static_cast<unsigned>(family); |
| 700 | return family; |
| 701 | } |
| 702 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 703 | family = getSelector().getMethodFamily(); |
| 704 | switch (family) { |
| 705 | case OMF_None: break; |
| 706 | |
| 707 | // init only has a conventional meaning for an instance method, and |
| 708 | // it has to return an object. |
| 709 | case OMF_init: |
| 710 | if (!isInstanceMethod() || !getResultType()->isObjCObjectPointerType()) |
| 711 | family = OMF_None; |
| 712 | break; |
| 713 | |
| 714 | // alloc/copy/new have a conventional meaning for both class and |
| 715 | // instance methods, but they require an object return. |
| 716 | case OMF_alloc: |
| 717 | case OMF_copy: |
| 718 | case OMF_mutableCopy: |
| 719 | case OMF_new: |
| 720 | if (!getResultType()->isObjCObjectPointerType()) |
| 721 | family = OMF_None; |
| 722 | break; |
| 723 | |
| 724 | // These selectors have a conventional meaning only for instance methods. |
| 725 | case OMF_dealloc: |
Nico Weber | 80cb6e6 | 2011-08-28 22:35:17 +0000 | [diff] [blame] | 726 | case OMF_finalize: |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 727 | case OMF_retain: |
| 728 | case OMF_release: |
| 729 | case OMF_autorelease: |
| 730 | case OMF_retainCount: |
Douglas Gregor | 926df6c | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 731 | case OMF_self: |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 732 | if (!isInstanceMethod()) |
| 733 | family = OMF_None; |
| 734 | break; |
Fariborz Jahanian | 9670e17 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 735 | |
| 736 | case OMF_performSelector: |
| 737 | if (!isInstanceMethod() || |
| 738 | !getResultType()->isObjCIdType()) |
| 739 | family = OMF_None; |
| 740 | else { |
| 741 | unsigned noParams = param_size(); |
| 742 | if (noParams < 1 || noParams > 3) |
| 743 | family = OMF_None; |
| 744 | else { |
| 745 | ObjCMethodDecl::arg_type_iterator it = arg_type_begin(); |
| 746 | QualType ArgT = (*it); |
| 747 | if (!ArgT->isObjCSelType()) { |
| 748 | family = OMF_None; |
| 749 | break; |
| 750 | } |
| 751 | while (--noParams) { |
| 752 | it++; |
| 753 | ArgT = (*it); |
| 754 | if (!ArgT->isObjCIdType()) { |
| 755 | family = OMF_None; |
| 756 | break; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | break; |
| 762 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Cache the result. |
| 766 | Family = static_cast<unsigned>(family); |
| 767 | return family; |
| 768 | } |
| 769 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 771 | const ObjCInterfaceDecl *OID) { |
| 772 | QualType selfTy; |
| 773 | if (isInstanceMethod()) { |
| 774 | // There may be no interface context due to error in declaration |
| 775 | // of the interface (which has been reported). Recover gracefully. |
| 776 | if (OID) { |
Daniel Dunbar | 3b3a458 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 777 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 778 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 779 | } else { |
| 780 | selfTy = Context.getObjCIdType(); |
| 781 | } |
| 782 | } else // we have a factory method. |
| 783 | selfTy = Context.getObjCClassType(); |
| 784 | |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 785 | bool selfIsPseudoStrong = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 786 | bool selfIsConsumed = false; |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 787 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 788 | if (Context.getLangOpts().ObjCAutoRefCount) { |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 789 | if (isInstanceMethod()) { |
| 790 | selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 791 | |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 792 | // 'self' is always __strong. It's actually pseudo-strong except |
| 793 | // in init methods (or methods labeled ns_consumes_self), though. |
| 794 | Qualifiers qs; |
| 795 | qs.setObjCLifetime(Qualifiers::OCL_Strong); |
| 796 | selfTy = Context.getQualifiedType(selfTy, qs); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 797 | |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 798 | // In addition, 'self' is const unless this is an init method. |
| 799 | if (getMethodFamily() != OMF_init && !selfIsConsumed) { |
| 800 | selfTy = selfTy.withConst(); |
| 801 | selfIsPseudoStrong = true; |
| 802 | } |
| 803 | } |
| 804 | else { |
| 805 | assert(isClassMethod()); |
| 806 | // 'self' is always const in class methods. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 807 | selfTy = selfTy.withConst(); |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 808 | selfIsPseudoStrong = true; |
| 809 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | ImplicitParamDecl *self |
| 813 | = ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 814 | &Context.Idents.get("self"), selfTy); |
| 815 | setSelfDecl(self); |
| 816 | |
| 817 | if (selfIsConsumed) |
| 818 | self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context)); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 819 | |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 820 | if (selfIsPseudoStrong) |
| 821 | self->setARCPseudoStrong(true); |
| 822 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 824 | &Context.Idents.get("_cmd"), |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 825 | Context.getObjCSelType())); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 828 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 829 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 830 | return ID; |
| 831 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 832 | return CD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 833 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 834 | return IMD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 835 | |
| 836 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 837 | llvm_unreachable("unknown method context"); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Argyrios Kyrtzidis | 740ae67 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 840 | static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, |
| 841 | const ObjCMethodDecl *Method, |
| 842 | SmallVectorImpl<const ObjCMethodDecl *> &Methods, |
| 843 | bool MovedToSuper) { |
| 844 | if (!Container) |
| 845 | return; |
| 846 | |
| 847 | // In categories look for overriden methods from protocols. A method from |
| 848 | // category is not "overriden" since it is considered as the "same" method |
| 849 | // (same USR) as the one from the interface. |
| 850 | if (const ObjCCategoryDecl * |
| 851 | Category = dyn_cast<ObjCCategoryDecl>(Container)) { |
| 852 | // Check whether we have a matching method at this category but only if we |
| 853 | // are at the super class level. |
| 854 | if (MovedToSuper) |
| 855 | if (ObjCMethodDecl * |
| 856 | Overridden = Container->getMethod(Method->getSelector(), |
| 857 | Method->isInstanceMethod())) |
| 858 | if (Method != Overridden) { |
| 859 | // We found an override at this category; there is no need to look |
| 860 | // into its protocols. |
| 861 | Methods.push_back(Overridden); |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(), |
| 866 | PEnd = Category->protocol_end(); |
| 867 | P != PEnd; ++P) |
| 868 | CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper); |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | // Check whether we have a matching method at this level. |
| 873 | if (const ObjCMethodDecl * |
| 874 | Overridden = Container->getMethod(Method->getSelector(), |
| 875 | Method->isInstanceMethod())) |
| 876 | if (Method != Overridden) { |
| 877 | // We found an override at this level; there is no need to look |
| 878 | // into other protocols or categories. |
| 879 | Methods.push_back(Overridden); |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){ |
| 884 | for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(), |
| 885 | PEnd = Protocol->protocol_end(); |
| 886 | P != PEnd; ++P) |
| 887 | CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper); |
| 888 | } |
| 889 | |
| 890 | if (const ObjCInterfaceDecl * |
| 891 | Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { |
| 892 | for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(), |
| 893 | PEnd = Interface->protocol_end(); |
| 894 | P != PEnd; ++P) |
| 895 | CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper); |
| 896 | |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 897 | for (ObjCInterfaceDecl::visible_categories_iterator |
| 898 | Cat = Interface->visible_categories_begin(), |
| 899 | CatEnd = Interface->visible_categories_end(); |
| 900 | Cat != CatEnd; ++Cat) { |
| 901 | CollectOverriddenMethodsRecurse(*Cat, Method, Methods, |
Argyrios Kyrtzidis | 740ae67 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 902 | MovedToSuper); |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 903 | } |
Argyrios Kyrtzidis | 740ae67 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 904 | |
| 905 | if (const ObjCInterfaceDecl *Super = Interface->getSuperClass()) |
| 906 | return CollectOverriddenMethodsRecurse(Super, Method, Methods, |
| 907 | /*MovedToSuper=*/true); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container, |
| 912 | const ObjCMethodDecl *Method, |
| 913 | SmallVectorImpl<const ObjCMethodDecl *> &Methods) { |
| 914 | CollectOverriddenMethodsRecurse(Container, Method, Methods, |
| 915 | /*MovedToSuper=*/false); |
| 916 | } |
| 917 | |
| 918 | static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, |
| 919 | SmallVectorImpl<const ObjCMethodDecl *> &overridden) { |
| 920 | assert(Method->isOverriding()); |
| 921 | |
| 922 | if (const ObjCProtocolDecl * |
| 923 | ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) { |
| 924 | CollectOverriddenMethods(ProtD, Method, overridden); |
| 925 | |
| 926 | } else if (const ObjCImplDecl * |
| 927 | IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) { |
| 928 | const ObjCInterfaceDecl *ID = IMD->getClassInterface(); |
| 929 | if (!ID) |
| 930 | return; |
| 931 | // Start searching for overridden methods using the method from the |
| 932 | // interface as starting point. |
| 933 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
| 934 | Method->isInstanceMethod())) |
| 935 | Method = IFaceMeth; |
| 936 | CollectOverriddenMethods(ID, Method, overridden); |
| 937 | |
| 938 | } else if (const ObjCCategoryDecl * |
| 939 | CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) { |
| 940 | const ObjCInterfaceDecl *ID = CatD->getClassInterface(); |
| 941 | if (!ID) |
| 942 | return; |
| 943 | // Start searching for overridden methods using the method from the |
| 944 | // interface as starting point. |
| 945 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
| 946 | Method->isInstanceMethod())) |
| 947 | Method = IFaceMeth; |
| 948 | CollectOverriddenMethods(ID, Method, overridden); |
| 949 | |
| 950 | } else { |
| 951 | CollectOverriddenMethods( |
| 952 | dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()), |
| 953 | Method, overridden); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | static void collectOnCategoriesAfterLocation(SourceLocation Loc, |
| 958 | const ObjCInterfaceDecl *Class, |
| 959 | SourceManager &SM, |
| 960 | const ObjCMethodDecl *Method, |
| 961 | SmallVectorImpl<const ObjCMethodDecl *> &Methods) { |
| 962 | if (!Class) |
| 963 | return; |
| 964 | |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 965 | for (ObjCInterfaceDecl::visible_categories_iterator |
| 966 | Cat = Class->visible_categories_begin(), |
| 967 | CatEnd = Class->visible_categories_end(); |
| 968 | Cat != CatEnd; ++Cat) { |
| 969 | if (SM.isBeforeInTranslationUnit(Loc, Cat->getLocation())) |
| 970 | CollectOverriddenMethodsRecurse(*Cat, Method, Methods, true); |
| 971 | } |
| 972 | |
Argyrios Kyrtzidis | 740ae67 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 973 | collectOnCategoriesAfterLocation(Loc, Class->getSuperClass(), SM, |
| 974 | Method, Methods); |
| 975 | } |
| 976 | |
| 977 | /// \brief Faster collection that is enabled when ObjCMethodDecl::isOverriding() |
| 978 | /// returns false. |
| 979 | /// You'd think that in that case there are no overrides but categories can |
| 980 | /// "introduce" new overridden methods that are missed by Sema because the |
| 981 | /// overrides lookup that it does for methods, inside implementations, will |
| 982 | /// stop at the interface level (if there is a method there) and not look |
| 983 | /// further in super classes. |
Fariborz Jahanian | bf967be | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 984 | /// Methods in an implementation can overide methods in super class's category |
| 985 | /// but not in current class's category. But, such methods |
Argyrios Kyrtzidis | 740ae67 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 986 | static void collectOverriddenMethodsFast(SourceManager &SM, |
| 987 | const ObjCMethodDecl *Method, |
| 988 | SmallVectorImpl<const ObjCMethodDecl *> &Methods) { |
| 989 | assert(!Method->isOverriding()); |
| 990 | |
| 991 | const ObjCContainerDecl * |
| 992 | ContD = cast<ObjCContainerDecl>(Method->getDeclContext()); |
| 993 | if (isa<ObjCInterfaceDecl>(ContD) || isa<ObjCProtocolDecl>(ContD)) |
| 994 | return; |
| 995 | const ObjCInterfaceDecl *Class = Method->getClassInterface(); |
| 996 | if (!Class) |
| 997 | return; |
| 998 | |
| 999 | collectOnCategoriesAfterLocation(Class->getLocation(), Class->getSuperClass(), |
| 1000 | SM, Method, Methods); |
| 1001 | } |
| 1002 | |
| 1003 | void ObjCMethodDecl::getOverriddenMethods( |
| 1004 | SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const { |
| 1005 | const ObjCMethodDecl *Method = this; |
| 1006 | |
| 1007 | if (Method->isRedeclaration()) { |
| 1008 | Method = cast<ObjCContainerDecl>(Method->getDeclContext())-> |
| 1009 | getMethod(Method->getSelector(), Method->isInstanceMethod()); |
| 1010 | } |
| 1011 | |
| 1012 | if (!Method->isOverriding()) { |
| 1013 | collectOverriddenMethodsFast(getASTContext().getSourceManager(), |
| 1014 | Method, Overridden); |
| 1015 | } else { |
| 1016 | collectOverriddenMethodsSlow(Method, Overridden); |
| 1017 | assert(!Overridden.empty() && |
| 1018 | "ObjCMethodDecl's overriding bit is not as expected"); |
| 1019 | } |
| 1020 | } |
| 1021 | |
Jordan Rose | 04bec39 | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1022 | const ObjCPropertyDecl * |
| 1023 | ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { |
| 1024 | Selector Sel = getSelector(); |
| 1025 | unsigned NumArgs = Sel.getNumArgs(); |
| 1026 | if (NumArgs > 1) |
| 1027 | return 0; |
| 1028 | |
Jordan Rose | 50d2b26 | 2012-10-11 16:02:02 +0000 | [diff] [blame] | 1029 | if (!isInstanceMethod() || getMethodFamily() != OMF_None) |
Jordan Rose | 04bec39 | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1030 | return 0; |
| 1031 | |
| 1032 | if (isPropertyAccessor()) { |
| 1033 | const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent()); |
Fariborz Jahanian | c328d9c | 2013-01-12 00:28:34 +0000 | [diff] [blame] | 1034 | // If container is class extension, find its primary class. |
| 1035 | if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(Container)) |
| 1036 | if (CatDecl->IsClassExtension()) |
| 1037 | Container = CatDecl->getClassInterface(); |
| 1038 | |
Jordan Rose | 04bec39 | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1039 | bool IsGetter = (NumArgs == 0); |
| 1040 | |
| 1041 | for (ObjCContainerDecl::prop_iterator I = Container->prop_begin(), |
| 1042 | E = Container->prop_end(); |
| 1043 | I != E; ++I) { |
| 1044 | Selector NextSel = IsGetter ? (*I)->getGetterName() |
| 1045 | : (*I)->getSetterName(); |
| 1046 | if (NextSel == Sel) |
| 1047 | return *I; |
| 1048 | } |
| 1049 | |
| 1050 | llvm_unreachable("Marked as a property accessor but no property found!"); |
| 1051 | } |
| 1052 | |
| 1053 | if (!CheckOverrides) |
| 1054 | return 0; |
| 1055 | |
| 1056 | typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy; |
| 1057 | OverridesTy Overrides; |
| 1058 | getOverriddenMethods(Overrides); |
| 1059 | for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end(); |
| 1060 | I != E; ++I) { |
| 1061 | if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false)) |
| 1062 | return Prop; |
| 1063 | } |
| 1064 | |
| 1065 | return 0; |
| 1066 | |
| 1067 | } |
| 1068 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1069 | //===----------------------------------------------------------------------===// |
| 1070 | // ObjCInterfaceDecl |
| 1071 | //===----------------------------------------------------------------------===// |
| 1072 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 1073 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1074 | DeclContext *DC, |
| 1075 | SourceLocation atLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1076 | IdentifierInfo *Id, |
Douglas Gregor | 0af5501 | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1077 | ObjCInterfaceDecl *PrevDecl, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1078 | SourceLocation ClassLoc, |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1079 | bool isInternal){ |
Douglas Gregor | 0af5501 | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1080 | ObjCInterfaceDecl *Result = new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 1081 | PrevDecl, isInternal); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1082 | Result->Data.setInt(!C.getLangOpts().Modules); |
Douglas Gregor | 0af5501 | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1083 | C.getObjCInterfaceType(Result, PrevDecl); |
Douglas Gregor | 0af5501 | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1084 | return Result; |
| 1085 | } |
| 1086 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1087 | ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, |
| 1088 | unsigned ID) { |
| 1089 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCInterfaceDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1090 | ObjCInterfaceDecl *Result = new (Mem) ObjCInterfaceDecl(0, SourceLocation(), |
| 1091 | 0, SourceLocation(), |
| 1092 | 0, false); |
| 1093 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1094 | return Result; |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | ObjCInterfaceDecl:: |
| 1098 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 1099 | SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl, |
| 1100 | bool isInternal) |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1101 | : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc), |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1102 | TypeForDecl(0), Data() |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1103 | { |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 1104 | setPreviousDeclaration(PrevDecl); |
| 1105 | |
| 1106 | // Copy the 'data' pointer over. |
| 1107 | if (PrevDecl) |
| 1108 | Data = PrevDecl->Data; |
| 1109 | |
Argyrios Kyrtzidis | 40f57ee | 2011-11-15 06:20:21 +0000 | [diff] [blame] | 1110 | setImplicit(isInternal); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1113 | void ObjCInterfaceDecl::LoadExternalDefinition() const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1114 | assert(data().ExternallyCompleted && "Class is not externally completed"); |
| 1115 | data().ExternallyCompleted = false; |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1116 | getASTContext().getExternalSource()->CompleteType( |
| 1117 | const_cast<ObjCInterfaceDecl *>(this)); |
| 1118 | } |
| 1119 | |
| 1120 | void ObjCInterfaceDecl::setExternallyCompleted() { |
| 1121 | assert(getASTContext().getExternalSource() && |
| 1122 | "Class can't be externally completed without an external source"); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1123 | assert(hasDefinition() && |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1124 | "Forward declarations can't be externally completed"); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1125 | data().ExternallyCompleted = true; |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1128 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1129 | if (const ObjCInterfaceDecl *Def = getDefinition()) { |
| 1130 | if (data().ExternallyCompleted) |
| 1131 | LoadExternalDefinition(); |
| 1132 | |
| 1133 | return getASTContext().getObjCImplementation( |
| 1134 | const_cast<ObjCInterfaceDecl*>(Def)); |
| 1135 | } |
| 1136 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1137 | // FIXME: Should make sure no callers ever do this. |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1138 | return 0; |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
Douglas Gregor | 7723fec | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1142 | getASTContext().setObjCImplementation(getDefinition(), ImplD); |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Fariborz Jahanian | 2c5d845 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1145 | namespace { |
| 1146 | struct SynthesizeIvarChunk { |
| 1147 | uint64_t Size; |
| 1148 | ObjCIvarDecl *Ivar; |
| 1149 | SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar) |
| 1150 | : Size(size), Ivar(ivar) {} |
| 1151 | }; |
| 1152 | |
| 1153 | bool operator<(const SynthesizeIvarChunk & LHS, |
| 1154 | const SynthesizeIvarChunk &RHS) { |
| 1155 | return LHS.Size < RHS.Size; |
| 1156 | } |
| 1157 | } |
| 1158 | |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1159 | /// all_declared_ivar_begin - return first ivar declared in this class, |
| 1160 | /// its extensions and its implementation. Lazily build the list on first |
| 1161 | /// access. |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1162 | /// |
| 1163 | /// Caveat: The list returned by this method reflects the current |
| 1164 | /// state of the parser. The cache will be updated for every ivar |
| 1165 | /// added by an extension or the implementation when they are |
| 1166 | /// encountered. |
| 1167 | /// See also ObjCIvarDecl::Create(). |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1168 | ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1169 | // FIXME: Should make sure no callers ever do this. |
| 1170 | if (!hasDefinition()) |
| 1171 | return 0; |
| 1172 | |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1173 | ObjCIvarDecl *curIvar = 0; |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1174 | if (!data().IvarList) { |
| 1175 | if (!ivar_empty()) { |
| 1176 | ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); |
| 1177 | data().IvarList = *I; ++I; |
| 1178 | for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) |
Adrian Prantl | 10b4df7 | 2013-02-27 01:31:55 +0000 | [diff] [blame] | 1179 | curIvar->setNextIvar(*I); |
| 1180 | } |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1181 | |
| 1182 | for (ObjCInterfaceDecl::known_extensions_iterator |
| 1183 | Ext = known_extensions_begin(), |
| 1184 | ExtEnd = known_extensions_end(); |
| 1185 | Ext != ExtEnd; ++Ext) { |
| 1186 | if (!Ext->ivar_empty()) { |
| 1187 | ObjCCategoryDecl::ivar_iterator |
| 1188 | I = Ext->ivar_begin(), |
| 1189 | E = Ext->ivar_end(); |
| 1190 | if (!data().IvarList) { |
| 1191 | data().IvarList = *I; ++I; |
| 1192 | curIvar = data().IvarList; |
| 1193 | } |
| 1194 | for ( ;I != E; curIvar = *I, ++I) |
| 1195 | curIvar->setNextIvar(*I); |
| 1196 | } |
| 1197 | } |
| 1198 | data().IvarListMissingImplementation = true; |
Adrian Prantl | 10b4df7 | 2013-02-27 01:31:55 +0000 | [diff] [blame] | 1199 | } |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1200 | |
| 1201 | // cached and complete! |
| 1202 | if (!data().IvarListMissingImplementation) |
| 1203 | return data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1204 | |
| 1205 | if (ObjCImplementationDecl *ImplDecl = getImplementation()) { |
Adrian Prantl | 4919de6 | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1206 | data().IvarListMissingImplementation = false; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1207 | if (!ImplDecl->ivar_empty()) { |
Fariborz Jahanian | 2c5d845 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1208 | SmallVector<SynthesizeIvarChunk, 16> layout; |
| 1209 | for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(), |
| 1210 | E = ImplDecl->ivar_end(); I != E; ++I) { |
| 1211 | ObjCIvarDecl *IV = *I; |
| 1212 | if (IV->getSynthesize() && !IV->isInvalidDecl()) { |
| 1213 | layout.push_back(SynthesizeIvarChunk( |
| 1214 | IV->getASTContext().getTypeSize(IV->getType()), IV)); |
| 1215 | continue; |
| 1216 | } |
| 1217 | if (!data().IvarList) |
| 1218 | data().IvarList = *I; |
| 1219 | else |
| 1220 | curIvar->setNextIvar(*I); |
| 1221 | curIvar = *I; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1222 | } |
Fariborz Jahanian | 2c5d845 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1223 | |
| 1224 | if (!layout.empty()) { |
| 1225 | // Order synthesized ivars by their size. |
| 1226 | std::stable_sort(layout.begin(), layout.end()); |
| 1227 | unsigned Ix = 0, EIx = layout.size(); |
| 1228 | if (!data().IvarList) { |
| 1229 | data().IvarList = layout[0].Ivar; Ix++; |
| 1230 | curIvar = data().IvarList; |
| 1231 | } |
| 1232 | for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) |
| 1233 | curIvar->setNextIvar(layout[Ix].Ivar); |
| 1234 | } |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1237 | return data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1238 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1239 | |
| 1240 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 1241 | /// categories for this class and returns it. Name of the category is passed |
| 1242 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1243 | /// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1244 | ObjCCategoryDecl * |
| 1245 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
Argyrios Kyrtzidis | 5a61e0c | 2012-03-02 19:14:29 +0000 | [diff] [blame] | 1246 | // FIXME: Should make sure no callers ever do this. |
| 1247 | if (!hasDefinition()) |
| 1248 | return 0; |
| 1249 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1250 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1251 | LoadExternalDefinition(); |
| 1252 | |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1253 | for (visible_categories_iterator Cat = visible_categories_begin(), |
| 1254 | CatEnd = visible_categories_end(); |
| 1255 | Cat != CatEnd; |
| 1256 | ++Cat) { |
| 1257 | if (Cat->getIdentifier() == CategoryId) |
| 1258 | return *Cat; |
| 1259 | } |
| 1260 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1261 | return 0; |
| 1262 | } |
| 1263 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1264 | ObjCMethodDecl * |
| 1265 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1266 | for (visible_categories_iterator Cat = visible_categories_begin(), |
| 1267 | CatEnd = visible_categories_end(); |
| 1268 | Cat != CatEnd; |
| 1269 | ++Cat) { |
| 1270 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1271 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 1272 | return MD; |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1275 | return 0; |
| 1276 | } |
| 1277 | |
| 1278 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1279 | for (visible_categories_iterator Cat = visible_categories_begin(), |
| 1280 | CatEnd = visible_categories_end(); |
| 1281 | Cat != CatEnd; |
| 1282 | ++Cat) { |
| 1283 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1284 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 1285 | return MD; |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1288 | return 0; |
| 1289 | } |
| 1290 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1291 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 1292 | /// has been implemented in IDecl class, its super class or categories (if |
| 1293 | /// lookupCategory is true). |
| 1294 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 1295 | bool lookupCategory, |
| 1296 | bool RHSIsQualifiedID) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1297 | if (!hasDefinition()) |
| 1298 | return false; |
| 1299 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1300 | ObjCInterfaceDecl *IDecl = this; |
| 1301 | // 1st, look up the class. |
Argyrios Kyrtzidis | a5f4441 | 2012-03-13 01:09:41 +0000 | [diff] [blame] | 1302 | for (ObjCInterfaceDecl::protocol_iterator |
| 1303 | PI = IDecl->protocol_begin(), E = IDecl->protocol_end(); PI != E; ++PI){ |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1304 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 1305 | return true; |
| 1306 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 1307 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 1308 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 1309 | // object. This IMO, should be a bug. |
| 1310 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 1311 | // extensions are not enabled. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | if (RHSIsQualifiedID && |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1313 | getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) |
| 1314 | return true; |
| 1315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1317 | // 2nd, look up the category. |
| 1318 | if (lookupCategory) |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1319 | for (visible_categories_iterator Cat = visible_categories_begin(), |
| 1320 | CatEnd = visible_categories_end(); |
| 1321 | Cat != CatEnd; |
| 1322 | ++Cat) { |
| 1323 | for (ObjCCategoryDecl::protocol_iterator PI = Cat->protocol_begin(), |
| 1324 | E = Cat->protocol_end(); |
| 1325 | PI != E; ++PI) |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1326 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 1327 | return true; |
| 1328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1329 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1330 | // 3rd, look up the super class(s) |
| 1331 | if (IDecl->getSuperClass()) |
| 1332 | return |
| 1333 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 1334 | RHSIsQualifiedID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1336 | return false; |
| 1337 | } |
| 1338 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1339 | //===----------------------------------------------------------------------===// |
| 1340 | // ObjCIvarDecl |
| 1341 | //===----------------------------------------------------------------------===// |
| 1342 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1343 | void ObjCIvarDecl::anchor() { } |
| 1344 | |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1345 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1346 | SourceLocation StartLoc, |
| 1347 | SourceLocation IdLoc, IdentifierInfo *Id, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1348 | QualType T, TypeSourceInfo *TInfo, |
Fariborz Jahanian | ad51e74 | 2010-07-17 00:59:30 +0000 | [diff] [blame] | 1349 | AccessControl ac, Expr *BW, |
| 1350 | bool synthesized) { |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1351 | if (DC) { |
| 1352 | // Ivar's can only appear in interfaces, implementations (via synthesized |
| 1353 | // properties), and class extensions (via direct declaration, or synthesized |
| 1354 | // properties). |
| 1355 | // |
| 1356 | // FIXME: This should really be asserting this: |
| 1357 | // (isa<ObjCCategoryDecl>(DC) && |
| 1358 | // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) |
| 1359 | // but unfortunately we sometimes place ivars into non-class extension |
| 1360 | // categories on error. This breaks an AST invariant, and should not be |
| 1361 | // fixed. |
| 1362 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 1363 | isa<ObjCCategoryDecl>(DC)) && |
| 1364 | "Invalid ivar decl context!"); |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1365 | // Once a new ivar is created in any of class/class-extension/implementation |
| 1366 | // decl contexts, the previously built IvarList must be rebuilt. |
| 1367 | ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC); |
| 1368 | if (!ID) { |
Eric Christopher | ffb0c3a | 2012-07-19 22:22:55 +0000 | [diff] [blame] | 1369 | if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1370 | ID = IM->getClassInterface(); |
Eric Christopher | ffb0c3a | 2012-07-19 22:22:55 +0000 | [diff] [blame] | 1371 | else |
| 1372 | ID = cast<ObjCCategoryDecl>(DC)->getClassInterface(); |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1373 | } |
| 1374 | ID->setIvarList(0); |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1377 | return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, |
| 1378 | ac, BW, synthesized); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1381 | ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1382 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCIvarDecl)); |
| 1383 | return new (Mem) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0, |
| 1384 | QualType(), 0, ObjCIvarDecl::None, 0, false); |
| 1385 | } |
| 1386 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1387 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 1388 | const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1389 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1390 | switch (DC->getKind()) { |
| 1391 | default: |
| 1392 | case ObjCCategoryImpl: |
| 1393 | case ObjCProtocol: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1394 | llvm_unreachable("invalid ivar container!"); |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1395 | |
| 1396 | // Ivars can only appear in class extension categories. |
| 1397 | case ObjCCategory: { |
| 1398 | const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 1399 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 1400 | return CD->getClassInterface(); |
| 1401 | } |
| 1402 | |
| 1403 | case ObjCImplementation: |
| 1404 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 1405 | |
| 1406 | case ObjCInterface: |
| 1407 | return cast<ObjCInterfaceDecl>(DC); |
| 1408 | } |
| 1409 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1410 | |
| 1411 | //===----------------------------------------------------------------------===// |
| 1412 | // ObjCAtDefsFieldDecl |
| 1413 | //===----------------------------------------------------------------------===// |
| 1414 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1415 | void ObjCAtDefsFieldDecl::anchor() { } |
| 1416 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1417 | ObjCAtDefsFieldDecl |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1418 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, |
| 1419 | SourceLocation StartLoc, SourceLocation IdLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1420 | IdentifierInfo *Id, QualType T, Expr *BW) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1421 | return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1424 | ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, |
| 1425 | unsigned ID) { |
| 1426 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCAtDefsFieldDecl)); |
| 1427 | return new (Mem) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(), |
| 1428 | 0, QualType(), 0); |
| 1429 | } |
| 1430 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1431 | //===----------------------------------------------------------------------===// |
| 1432 | // ObjCProtocolDecl |
| 1433 | //===----------------------------------------------------------------------===// |
| 1434 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1435 | void ObjCProtocolDecl::anchor() { } |
| 1436 | |
Douglas Gregor | 27c6da2 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1437 | ObjCProtocolDecl::ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id, |
| 1438 | SourceLocation nameLoc, |
| 1439 | SourceLocation atStartLoc, |
Douglas Gregor | c9d3c7e | 2012-01-01 22:06:18 +0000 | [diff] [blame] | 1440 | ObjCProtocolDecl *PrevDecl) |
| 1441 | : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), Data() |
Douglas Gregor | 27c6da2 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1442 | { |
| 1443 | setPreviousDeclaration(PrevDecl); |
| 1444 | if (PrevDecl) |
| 1445 | Data = PrevDecl->Data; |
| 1446 | } |
| 1447 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1448 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1449 | IdentifierInfo *Id, |
| 1450 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | b05d7b2 | 2011-10-17 19:48:06 +0000 | [diff] [blame] | 1451 | SourceLocation atStartLoc, |
Douglas Gregor | c9d3c7e | 2012-01-01 22:06:18 +0000 | [diff] [blame] | 1452 | ObjCProtocolDecl *PrevDecl) { |
Douglas Gregor | 27c6da2 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1453 | ObjCProtocolDecl *Result |
Douglas Gregor | c9d3c7e | 2012-01-01 22:06:18 +0000 | [diff] [blame] | 1454 | = new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1455 | Result->Data.setInt(!C.getLangOpts().Modules); |
Douglas Gregor | 27c6da2 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1456 | return Result; |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1459 | ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, |
| 1460 | unsigned ID) { |
| 1461 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCProtocolDecl)); |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1462 | ObjCProtocolDecl *Result = new (Mem) ObjCProtocolDecl(0, 0, SourceLocation(), |
| 1463 | SourceLocation(), 0); |
| 1464 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1465 | return Result; |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 1468 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 1469 | ObjCProtocolDecl *PDecl = this; |
| 1470 | |
| 1471 | if (Name == getIdentifier()) |
| 1472 | return PDecl; |
| 1473 | |
| 1474 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 1475 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 1476 | return PDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1477 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 1478 | return NULL; |
| 1479 | } |
| 1480 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1481 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1482 | // it inherited. |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1483 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 1484 | bool isInstance) const { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1485 | ObjCMethodDecl *MethodDecl = NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | |
Douglas Gregor | 0f9b9f3 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 1487 | // If there is no definition or the definition is hidden, we don't find |
| 1488 | // anything. |
| 1489 | const ObjCProtocolDecl *Def = getDefinition(); |
| 1490 | if (!Def || Def->isHidden()) |
| 1491 | return NULL; |
| 1492 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1493 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1494 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1495 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1496 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1497 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1498 | return MethodDecl; |
| 1499 | return NULL; |
| 1500 | } |
| 1501 | |
Douglas Gregor | 5e2a1ff | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1502 | void ObjCProtocolDecl::allocateDefinitionData() { |
Douglas Gregor | 6bd9929 | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1503 | assert(!Data.getPointer() && "Protocol already has a definition!"); |
| 1504 | Data.setPointer(new (getASTContext()) DefinitionData); |
| 1505 | Data.getPointer()->Definition = this; |
Douglas Gregor | 5e2a1ff | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | void ObjCProtocolDecl::startDefinition() { |
| 1509 | allocateDefinitionData(); |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1510 | |
| 1511 | // Update all of the declarations with a pointer to the definition. |
| 1512 | for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); |
| 1513 | RD != RDEnd; ++RD) |
| 1514 | RD->Data = this->Data; |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 1517 | void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 1518 | PropertyDeclOrder &PO) const { |
Fariborz Jahanian | cc5a28a | 2013-01-07 21:31:08 +0000 | [diff] [blame] | 1519 | |
| 1520 | if (const ObjCProtocolDecl *PDecl = getDefinition()) { |
| 1521 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 1522 | E = PDecl->prop_end(); P != E; ++P) { |
| 1523 | ObjCPropertyDecl *Prop = *P; |
| 1524 | // Insert into PM if not there already. |
| 1525 | PM.insert(std::make_pair(Prop->getIdentifier(), Prop)); |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 1526 | PO.push_back(Prop); |
Fariborz Jahanian | cc5a28a | 2013-01-07 21:31:08 +0000 | [diff] [blame] | 1527 | } |
| 1528 | // Scan through protocol's protocols. |
| 1529 | for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), |
| 1530 | E = PDecl->protocol_end(); PI != E; ++PI) |
Fariborz Jahanian | cfaed8d | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 1531 | (*PI)->collectPropertiesToImplement(PM, PO); |
Anna Zaks | b36ea37 | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 1532 | } |
Anna Zaks | b36ea37 | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1536 | //===----------------------------------------------------------------------===// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1537 | // ObjCCategoryDecl |
| 1538 | //===----------------------------------------------------------------------===// |
| 1539 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1540 | void ObjCCategoryDecl::anchor() { } |
| 1541 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1542 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1543 | SourceLocation AtLoc, |
| 1544 | SourceLocation ClassNameLoc, |
| 1545 | SourceLocation CategoryNameLoc, |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1546 | IdentifierInfo *Id, |
Fariborz Jahanian | af30029 | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1547 | ObjCInterfaceDecl *IDecl, |
| 1548 | SourceLocation IvarLBraceLoc, |
| 1549 | SourceLocation IvarRBraceLoc) { |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1550 | ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, |
| 1551 | CategoryNameLoc, Id, |
Fariborz Jahanian | af30029 | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1552 | IDecl, |
| 1553 | IvarLBraceLoc, IvarRBraceLoc); |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1554 | if (IDecl) { |
| 1555 | // Link this category into its class's category list. |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1556 | CatDecl->NextClassCategory = IDecl->getCategoryListRaw(); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1557 | if (IDecl->hasDefinition()) { |
Douglas Gregor | d329724 | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1558 | IDecl->setCategoryListRaw(CatDecl); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1559 | if (ASTMutationListener *L = C.getASTMutationListener()) |
| 1560 | L->AddedObjCCategoryToInterface(CatDecl, IDecl); |
| 1561 | } |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | return CatDecl; |
| 1565 | } |
| 1566 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1567 | ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, |
| 1568 | unsigned ID) { |
| 1569 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryDecl)); |
| 1570 | return new (Mem) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), |
| 1571 | SourceLocation(), 0, 0); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1574 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 1575 | return getASTContext().getObjCImplementation( |
| 1576 | const_cast<ObjCCategoryDecl*>(this)); |
| 1577 | } |
| 1578 | |
| 1579 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 1580 | getASTContext().setObjCImplementation(this, ImplD); |
| 1581 | } |
| 1582 | |
| 1583 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1584 | //===----------------------------------------------------------------------===// |
| 1585 | // ObjCCategoryImplDecl |
| 1586 | //===----------------------------------------------------------------------===// |
| 1587 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1588 | void ObjCCategoryImplDecl::anchor() { } |
| 1589 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1590 | ObjCCategoryImplDecl * |
| 1591 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1592 | IdentifierInfo *Id, |
| 1593 | ObjCInterfaceDecl *ClassInterface, |
| 1594 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | c699400 | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 1595 | SourceLocation atStartLoc, |
| 1596 | SourceLocation CategoryNameLoc) { |
Fariborz Jahanian | 712ef87 | 2011-12-23 00:31:02 +0000 | [diff] [blame] | 1597 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 1598 | ClassInterface = ClassInterface->getDefinition(); |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1599 | return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface, |
Argyrios Kyrtzidis | c699400 | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 1600 | nameLoc, atStartLoc, CategoryNameLoc); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1603 | ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, |
| 1604 | unsigned ID) { |
| 1605 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryImplDecl)); |
| 1606 | return new (Mem) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(), |
| 1607 | SourceLocation(), SourceLocation()); |
| 1608 | } |
| 1609 | |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 1610 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 1611 | // The class interface might be NULL if we are working with invalid code. |
| 1612 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 1613 | return ID->FindCategoryDeclaration(getIdentifier()); |
| 1614 | return 0; |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1617 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1618 | void ObjCImplDecl::anchor() { } |
| 1619 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1620 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 1621 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1622 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1623 | addDecl(property); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1626 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 1627 | ASTContext &Ctx = getASTContext(); |
| 1628 | |
| 1629 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1630 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1631 | if (IFace) |
| 1632 | Ctx.setObjCImplementation(IFace, ImplD); |
| 1633 | |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1634 | } else if (ObjCCategoryImplDecl *ImplD = |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1635 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 1636 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 1637 | Ctx.setObjCImplementation(CD, ImplD); |
| 1638 | } |
| 1639 | |
| 1640 | ClassInterface = IFace; |
| 1641 | } |
| 1642 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1643 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Fariborz Jahanian | 6d1cb5c | 2013-03-12 17:43:00 +0000 | [diff] [blame] | 1644 | /// properties implemented in this \@implementation block and returns |
Chris Lattner | d6eed1c | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 1645 | /// the implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1646 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1647 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1648 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 1649 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 1650 | ObjCPropertyImplDecl *PID = *i; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1651 | if (PID->getPropertyIvarDecl() && |
| 1652 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 1653 | return PID; |
| 1654 | } |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
James Dennett | 1c3a46a | 2012-06-15 22:30:14 +0000 | [diff] [blame] | 1659 | /// added to the list of those properties \@synthesized/\@dynamic in this |
| 1660 | /// category \@implementation block. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1661 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1662 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1663 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 1664 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 1665 | ObjCPropertyImplDecl *PID = *i; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1666 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 1667 | return PID; |
| 1668 | } |
| 1669 | return 0; |
| 1670 | } |
| 1671 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1672 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | f978059 | 2012-02-07 11:57:45 +0000 | [diff] [blame] | 1673 | const ObjCCategoryImplDecl &CID) { |
| 1674 | OS << CID.getName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1675 | return OS; |
| 1676 | } |
| 1677 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1678 | //===----------------------------------------------------------------------===// |
| 1679 | // ObjCImplementationDecl |
| 1680 | //===----------------------------------------------------------------------===// |
| 1681 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1682 | void ObjCImplementationDecl::anchor() { } |
| 1683 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1684 | ObjCImplementationDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1686 | ObjCInterfaceDecl *ClassInterface, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1687 | ObjCInterfaceDecl *SuperDecl, |
| 1688 | SourceLocation nameLoc, |
Fariborz Jahanian | af30029 | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1689 | SourceLocation atStartLoc, |
| 1690 | SourceLocation IvarLBraceLoc, |
| 1691 | SourceLocation IvarRBraceLoc) { |
Fariborz Jahanian | 712ef87 | 2011-12-23 00:31:02 +0000 | [diff] [blame] | 1692 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 1693 | ClassInterface = ClassInterface->getDefinition(); |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1694 | return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, |
Fariborz Jahanian | af30029 | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1695 | nameLoc, atStartLoc, |
| 1696 | IvarLBraceLoc, IvarRBraceLoc); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1699 | ObjCImplementationDecl * |
| 1700 | ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1701 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCImplementationDecl)); |
| 1702 | return new (Mem) ObjCImplementationDecl(0, 0, 0, SourceLocation(), |
| 1703 | SourceLocation()); |
| 1704 | } |
| 1705 | |
John McCall | da6d976 | 2011-07-22 04:15:06 +0000 | [diff] [blame] | 1706 | void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, |
| 1707 | CXXCtorInitializer ** initializers, |
| 1708 | unsigned numInitializers) { |
| 1709 | if (numInitializers > 0) { |
| 1710 | NumIvarInitializers = numInitializers; |
| 1711 | CXXCtorInitializer **ivarInitializers = |
| 1712 | new (C) CXXCtorInitializer*[NumIvarInitializers]; |
| 1713 | memcpy(ivarInitializers, initializers, |
| 1714 | numInitializers * sizeof(CXXCtorInitializer*)); |
| 1715 | IvarInitializers = ivarInitializers; |
| 1716 | } |
| 1717 | } |
| 1718 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1719 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | f978059 | 2012-02-07 11:57:45 +0000 | [diff] [blame] | 1720 | const ObjCImplementationDecl &ID) { |
| 1721 | OS << ID.getName(); |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1722 | return OS; |
| 1723 | } |
| 1724 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1725 | //===----------------------------------------------------------------------===// |
| 1726 | // ObjCCompatibleAliasDecl |
| 1727 | //===----------------------------------------------------------------------===// |
| 1728 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1729 | void ObjCCompatibleAliasDecl::anchor() { } |
| 1730 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1731 | ObjCCompatibleAliasDecl * |
| 1732 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 1733 | SourceLocation L, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | IdentifierInfo *Id, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1735 | ObjCInterfaceDecl* AliasedClass) { |
| 1736 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 1737 | } |
| 1738 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1739 | ObjCCompatibleAliasDecl * |
| 1740 | ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1741 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCompatibleAliasDecl)); |
| 1742 | return new (Mem) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0); |
| 1743 | } |
| 1744 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1745 | //===----------------------------------------------------------------------===// |
| 1746 | // ObjCPropertyDecl |
| 1747 | //===----------------------------------------------------------------------===// |
| 1748 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1749 | void ObjCPropertyDecl::anchor() { } |
| 1750 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1751 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 1752 | SourceLocation L, |
| 1753 | IdentifierInfo *Id, |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1754 | SourceLocation AtLoc, |
Fariborz Jahanian | 77bfb8b | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 1755 | SourceLocation LParenLoc, |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1756 | TypeSourceInfo *T, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1757 | PropertyControl propControl) { |
Fariborz Jahanian | 77bfb8b | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 1758 | return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1761 | ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, |
| 1762 | unsigned ID) { |
| 1763 | void * Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyDecl)); |
| 1764 | return new (Mem) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(), |
Fariborz Jahanian | 77bfb8b | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 1765 | SourceLocation(), |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1766 | 0); |
| 1767 | } |
| 1768 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1769 | //===----------------------------------------------------------------------===// |
| 1770 | // ObjCPropertyImplDecl |
| 1771 | //===----------------------------------------------------------------------===// |
| 1772 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1773 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 1774 | DeclContext *DC, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1775 | SourceLocation atLoc, |
| 1776 | SourceLocation L, |
| 1777 | ObjCPropertyDecl *property, |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 1778 | Kind PK, |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1779 | ObjCIvarDecl *ivar, |
| 1780 | SourceLocation ivarLoc) { |
| 1781 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, |
| 1782 | ivarLoc); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1783 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1785 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, |
| 1786 | unsigned ID) { |
| 1787 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyImplDecl)); |
| 1788 | return new (Mem) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(), |
| 1789 | 0, Dynamic, 0, SourceLocation()); |
| 1790 | } |
| 1791 | |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1792 | SourceRange ObjCPropertyImplDecl::getSourceRange() const { |
| 1793 | SourceLocation EndLoc = getLocation(); |
| 1794 | if (IvarLoc.isValid()) |
| 1795 | EndLoc = IvarLoc; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1796 | |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1797 | return SourceRange(AtLoc, EndLoc); |
| 1798 | } |