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