Chris Lattner | 8937519 | 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 | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/Stmt.h" |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Anna Zaks | 454477c | 2012-09-27 19:45:11 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Chris Lattner | 8d8829e | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 24 | // ObjCListBase |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 27 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 28 | List = nullptr; |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 29 | if (Elts == 0) return; // Setting to an empty list is a noop. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | |
| 31 | |
Chris Lattner | 7c981a7 | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 32 | List = new (Ctx) void*[Elts]; |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 33 | NumElts = Elts; |
| 34 | memcpy(List, InList, sizeof(void*)*Elts); |
| 35 | } |
| 36 | |
Douglas Gregor | 002b671 | 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 | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 47 | //===----------------------------------------------------------------------===// |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 48 | // ObjCInterfaceDecl |
Chris Lattner | 8d8829e | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 49 | //===----------------------------------------------------------------------===// |
| 50 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 51 | void ObjCContainerDecl::anchor() { } |
| 52 | |
Fariborz Jahanian | 6845383 | 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 | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 56 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
David Blaikie | ff7d47a | 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 | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 60 | if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 61 | return ivar; |
| 62 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 63 | return nullptr; |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Argyrios Kyrtzidis | 6de0560 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 66 | // Get the local instance/class method declared in this interface. |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 67 | ObjCMethodDecl * |
Argyrios Kyrtzidis | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 68 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance, |
| 69 | bool AllowHidden) const { |
Douglas Gregor | eed4979 | 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 | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 74 | if (Def->isHidden() && !AllowHidden) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 75 | return nullptr; |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Steve Naroff | c4173fa | 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 | ff7d47a | 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 | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 89 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
Argyrios Kyrtzidis | 6de0560 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 90 | if (MD && MD->isInstanceMethod() == isInstance) |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 91 | return MD; |
| 92 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 93 | return nullptr; |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Nico Weber | 4701ffd | 2014-12-22 05:21:03 +0000 | [diff] [blame^] | 96 | /// \brief This routine returns 'true' if a user declared setter method was |
| 97 | /// 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' |
| 99 | /// property. This is because, user must provide a setter method for the |
| 100 | /// category's 'readwrite' property. |
| 101 | bool ObjCContainerDecl::HasUserDeclaredSetterMethod( |
| 102 | const ObjCPropertyDecl *Property) const { |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 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. |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 115 | for (const auto *Cat : ID->visible_categories()) { |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 116 | if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel)) |
| 117 | if (!MD->isImplicit()) |
| 118 | return true; |
| 119 | if (Cat->IsClassExtension()) |
| 120 | continue; |
Nico Weber | 4701ffd | 2014-12-22 05:21:03 +0000 | [diff] [blame^] | 121 | // Also search through the categories looking for a 'readwrite' |
| 122 | // declaration of this property. If one found, presumably a setter will |
| 123 | // be provided (properties declared in categories will not get |
| 124 | // auto-synthesized). |
Aaron Ballman | d174edf | 2014-03-13 19:11:50 +0000 | [diff] [blame] | 125 | for (const auto *P : Cat->properties()) |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 126 | if (P->getIdentifier() == Property->getIdentifier()) { |
| 127 | if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) |
| 128 | return true; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Also look into protocols, for a user declared instance method. |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 134 | for (const auto *Proto : ID->all_referenced_protocols()) |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 135 | if (Proto->HasUserDeclaredSetterMethod(Property)) |
| 136 | return true; |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 137 | |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 138 | // And in its super class. |
| 139 | ObjCInterfaceDecl *OSC = ID->getSuperClass(); |
| 140 | while (OSC) { |
| 141 | if (OSC->HasUserDeclaredSetterMethod(Property)) |
| 142 | return true; |
| 143 | OSC = OSC->getSuperClass(); |
| 144 | } |
| 145 | } |
| 146 | if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this)) |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 147 | for (const auto *PI : PD->protocols()) |
| 148 | if (PI->HasUserDeclaredSetterMethod(Property)) |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 149 | return true; |
Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 150 | return false; |
| 151 | } |
| 152 | |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 153 | ObjCPropertyDecl * |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 154 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
Jordan Rose | 210bfe9 | 2014-11-19 22:03:46 +0000 | [diff] [blame] | 155 | const IdentifierInfo *propertyID) { |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 156 | // If this context is a hidden protocol definition, don't find any |
| 157 | // property. |
| 158 | if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) { |
| 159 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 160 | if (Def->isHidden()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 161 | return nullptr; |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 162 | } |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 163 | |
David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 164 | DeclContext::lookup_const_result R = DC->lookup(propertyID); |
| 165 | for (DeclContext::lookup_const_iterator I = R.begin(), E = R.end(); I != E; |
| 166 | ++I) |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 167 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) |
| 168 | return PD; |
| 169 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 170 | return nullptr; |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Anna Zaks | 454477c | 2012-09-27 19:45:11 +0000 | [diff] [blame] | 173 | IdentifierInfo * |
| 174 | ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const { |
| 175 | SmallString<128> ivarName; |
| 176 | { |
| 177 | llvm::raw_svector_ostream os(ivarName); |
| 178 | os << '_' << getIdentifier()->getName(); |
| 179 | } |
| 180 | return &Ctx.Idents.get(ivarName.str()); |
| 181 | } |
| 182 | |
Fariborz Jahanian | a054e99 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 183 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 184 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Jordan Rose | 210bfe9 | 2014-11-19 22:03:46 +0000 | [diff] [blame] | 185 | ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration( |
| 186 | const IdentifierInfo *PropertyId) const { |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 187 | // Don't find properties within hidden protocol definitions. |
| 188 | if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) { |
| 189 | if (const ObjCProtocolDecl *Def = Proto->getDefinition()) |
| 190 | if (Def->isHidden()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 191 | return nullptr; |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 194 | if (ObjCPropertyDecl *PD = |
| 195 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 196 | return PD; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 198 | switch (getKind()) { |
| 199 | default: |
| 200 | break; |
| 201 | case Decl::ObjCProtocol: { |
| 202 | const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 203 | for (const auto *I : PID->protocols()) |
| 204 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) |
Fariborz Jahanian | 30a4292 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 205 | return P; |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | case Decl::ObjCInterface: { |
| 209 | const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 210 | // Look through categories (but not extensions). |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 211 | for (const auto *Cat : OID->visible_categories()) { |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 212 | if (!Cat->IsClassExtension()) |
| 213 | if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) |
| 214 | return P; |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 215 | } |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 216 | |
| 217 | // Look through protocols. |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 218 | for (const auto *I : OID->all_referenced_protocols()) |
| 219 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 220 | return P; |
| 221 | |
| 222 | // Finally, check the super class. |
| 223 | if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) |
| 224 | return superClass->FindPropertyDeclaration(PropertyId); |
| 225 | break; |
| 226 | } |
| 227 | case Decl::ObjCCategory: { |
| 228 | const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); |
| 229 | // Look through protocols. |
| 230 | if (!OCD->IsClassExtension()) |
Aaron Ballman | 19a4176 | 2014-03-14 12:55:57 +0000 | [diff] [blame] | 231 | for (const auto *I : OCD->protocols()) |
| 232 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) |
| 233 | return P; |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 234 | break; |
Fariborz Jahanian | dab0484 | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 237 | return nullptr; |
Steve Naroff | f9c6524 | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 238 | } |
| 239 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 240 | void ObjCInterfaceDecl::anchor() { } |
| 241 | |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 242 | /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property |
| 243 | /// with name 'PropertyId' in the primary class; including those in protocols |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 244 | /// (direct or indirect) used by the primary class. |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 245 | /// |
| 246 | ObjCPropertyDecl * |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 247 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 248 | IdentifierInfo *PropertyId) const { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 249 | // FIXME: Should make sure no callers ever do this. |
| 250 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 251 | return nullptr; |
| 252 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 253 | if (data().ExternallyCompleted) |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 254 | LoadExternalDefinition(); |
| 255 | |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 256 | if (ObjCPropertyDecl *PD = |
| 257 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 258 | return PD; |
| 259 | |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 260 | // Look through protocols. |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 261 | for (const auto *I : all_referenced_protocols()) |
| 262 | if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 263 | return P; |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 264 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 265 | return nullptr; |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Fariborz Jahanian | aedaaa4 | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 268 | void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 269 | PropertyDeclOrder &PO) const { |
Aaron Ballman | d174edf | 2014-03-13 19:11:50 +0000 | [diff] [blame] | 270 | for (auto *Prop : properties()) { |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 271 | PM[Prop->getIdentifier()] = Prop; |
Fariborz Jahanian | aedaaa4 | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 272 | PO.push_back(Prop); |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 273 | } |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 274 | for (const auto *PI : all_referenced_protocols()) |
| 275 | PI->collectPropertiesToImplement(PM, PO); |
Anna Zaks | 408f7d0 | 2012-10-31 01:18:22 +0000 | [diff] [blame] | 276 | // Note, the properties declared only in class extensions are still copied |
| 277 | // into the main @interface's property list, and therefore we don't |
| 278 | // explicitly, have to search class extension properties. |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 281 | bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const { |
| 282 | const ObjCInterfaceDecl *Class = this; |
| 283 | while (Class) { |
| 284 | if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) |
| 285 | return true; |
| 286 | Class = Class->getSuperClass(); |
| 287 | } |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const { |
| 292 | const ObjCInterfaceDecl *Class = this; |
| 293 | while (Class) { |
| 294 | if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>()) |
| 295 | return Class; |
| 296 | Class = Class->getSuperClass(); |
| 297 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 298 | return nullptr; |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 301 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 302 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
| 303 | ASTContext &C) |
| 304 | { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 305 | if (data().ExternallyCompleted) |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 306 | LoadExternalDefinition(); |
| 307 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 308 | if (data().AllReferencedProtocols.empty() && |
| 309 | data().ReferencedProtocols.empty()) { |
| 310 | data().AllReferencedProtocols.set(ExtList, ExtNum, C); |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 311 | return; |
| 312 | } |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 313 | |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 314 | // Check for duplicate protocol in class's protocol list. |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 315 | // This is O(n*m). But it is extremely rare and number of protocols in |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 316 | // class or its extension are very few. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 317 | SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 318 | for (unsigned i = 0; i < ExtNum; i++) { |
| 319 | bool protocolExists = false; |
| 320 | ObjCProtocolDecl *ProtoInExtension = ExtList[i]; |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 321 | for (auto *Proto : all_referenced_protocols()) { |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 322 | if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { |
| 323 | protocolExists = true; |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | // Do we want to warn on a protocol in extension class which |
| 328 | // already exist in the class? Probably not. |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 329 | if (!protocolExists) |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 330 | ProtocolRefs.push_back(ProtoInExtension); |
| 331 | } |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 332 | |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 333 | if (ProtocolRefs.empty()) |
| 334 | return; |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 335 | |
Fariborz Jahanian | 8764c74 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 336 | // Merge ProtocolRefs into class's protocol list; |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 337 | for (auto *P : all_referenced_protocols()) { |
| 338 | ProtocolRefs.push_back(P); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 339 | } |
Ted Kremenek | 0ef508d | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 340 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 341 | data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 344 | const ObjCInterfaceDecl * |
| 345 | ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const { |
| 346 | const ObjCInterfaceDecl *IFace = this; |
| 347 | while (IFace) { |
| 348 | if (IFace->hasDesignatedInitializers()) |
| 349 | return IFace; |
| 350 | if (!IFace->inheritsDesignatedInitializers()) |
| 351 | break; |
| 352 | IFace = IFace->getSuperClass(); |
| 353 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 354 | return nullptr; |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 357 | static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) { |
| 358 | for (const auto *MD : D->instance_methods()) { |
| 359 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 360 | return true; |
| 361 | } |
| 362 | for (const auto *Ext : D->visible_extensions()) { |
| 363 | for (const auto *MD : Ext->instance_methods()) { |
| 364 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 365 | return true; |
| 366 | } |
| 367 | } |
Argyrios Kyrtzidis | 441f626 | 2014-04-16 18:32:42 +0000 | [diff] [blame] | 368 | if (const auto *ImplD = D->getImplementation()) { |
Argyrios Kyrtzidis | c747960 | 2014-04-16 18:45:32 +0000 | [diff] [blame] | 369 | for (const auto *MD : ImplD->instance_methods()) { |
| 370 | if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) |
| 371 | return true; |
| 372 | } |
Argyrios Kyrtzidis | 441f626 | 2014-04-16 18:32:42 +0000 | [diff] [blame] | 373 | } |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 374 | return false; |
| 375 | } |
| 376 | |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 377 | bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const { |
| 378 | switch (data().InheritedDesignatedInitializers) { |
| 379 | case DefinitionData::IDI_Inherited: |
| 380 | return true; |
| 381 | case DefinitionData::IDI_NotInherited: |
| 382 | return false; |
| 383 | case DefinitionData::IDI_Unknown: { |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 384 | // If the class introduced initializers we conservatively assume that we |
| 385 | // don't know if any of them is a designated initializer to avoid possible |
| 386 | // misleading warnings. |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 387 | if (isIntroducingInitializers(this)) { |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 388 | data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited; |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 389 | } else { |
Argyrios Kyrtzidis | 357b36a | 2014-04-26 21:28:41 +0000 | [diff] [blame] | 390 | if (auto SuperD = getSuperClass()) { |
| 391 | data().InheritedDesignatedInitializers = |
| 392 | SuperD->declaresOrInheritsDesignatedInitializers() ? |
| 393 | DefinitionData::IDI_Inherited : |
| 394 | DefinitionData::IDI_NotInherited; |
| 395 | } else { |
| 396 | data().InheritedDesignatedInitializers = |
| 397 | DefinitionData::IDI_NotInherited; |
| 398 | } |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 399 | } |
Argyrios Kyrtzidis | 357b36a | 2014-04-26 21:28:41 +0000 | [diff] [blame] | 400 | assert(data().InheritedDesignatedInitializers |
| 401 | != DefinitionData::IDI_Unknown); |
| 402 | return data().InheritedDesignatedInitializers == |
| 403 | DefinitionData::IDI_Inherited; |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | llvm_unreachable("unexpected InheritedDesignatedInitializers value"); |
| 408 | } |
| 409 | |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 410 | void ObjCInterfaceDecl::getDesignatedInitializers( |
| 411 | llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const { |
Fariborz Jahanian | 0c32531 | 2014-03-11 18:56:18 +0000 | [diff] [blame] | 412 | // Check for a complete definition and recover if not so. |
| 413 | if (!isThisDeclarationADefinition()) |
| 414 | return; |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 415 | if (data().ExternallyCompleted) |
| 416 | LoadExternalDefinition(); |
| 417 | |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 418 | const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 419 | if (!IFace) |
| 420 | return; |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 421 | |
Aaron Ballman | f26acce | 2014-03-13 19:50:17 +0000 | [diff] [blame] | 422 | for (const auto *MD : IFace->instance_methods()) |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 423 | if (MD->isThisDeclarationADesignatedInitializer()) |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 424 | Methods.push_back(MD); |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 425 | for (const auto *Ext : IFace->visible_extensions()) { |
| 426 | for (const auto *MD : Ext->instance_methods()) |
| 427 | if (MD->isThisDeclarationADesignatedInitializer()) |
| 428 | Methods.push_back(MD); |
| 429 | } |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 432 | bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel, |
| 433 | const ObjCMethodDecl **InitMethod) const { |
Fariborz Jahanian | 0c32531 | 2014-03-11 18:56:18 +0000 | [diff] [blame] | 434 | // Check for a complete definition and recover if not so. |
| 435 | if (!isThisDeclarationADefinition()) |
| 436 | return false; |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 437 | if (data().ExternallyCompleted) |
| 438 | LoadExternalDefinition(); |
| 439 | |
Argyrios Kyrtzidis | b9a405b | 2013-12-05 07:07:03 +0000 | [diff] [blame] | 440 | const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 441 | if (!IFace) |
| 442 | return false; |
| 443 | |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 444 | if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) { |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 445 | if (MD->isThisDeclarationADesignatedInitializer()) { |
| 446 | if (InitMethod) |
| 447 | *InitMethod = MD; |
| 448 | return true; |
| 449 | } |
| 450 | } |
Argyrios Kyrtzidis | 6af9bc5 | 2014-03-28 22:45:38 +0000 | [diff] [blame] | 451 | for (const auto *Ext : IFace->visible_extensions()) { |
| 452 | if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) { |
| 453 | if (MD->isThisDeclarationADesignatedInitializer()) { |
| 454 | if (InitMethod) |
| 455 | *InitMethod = MD; |
| 456 | return true; |
| 457 | } |
| 458 | } |
| 459 | } |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 463 | void ObjCInterfaceDecl::allocateDefinitionData() { |
| 464 | assert(!hasDefinition() && "ObjC class already has a definition"); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 465 | Data.setPointer(new (getASTContext()) DefinitionData()); |
| 466 | Data.getPointer()->Definition = this; |
Douglas Gregor | 7671e53 | 2011-12-16 16:34:57 +0000 | [diff] [blame] | 467 | |
| 468 | // Make the type point at the definition, now that we have one. |
| 469 | if (TypeForDecl) |
| 470 | cast<ObjCInterfaceType>(TypeForDecl)->Decl = this; |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void ObjCInterfaceDecl::startDefinition() { |
| 474 | allocateDefinitionData(); |
| 475 | |
Douglas Gregor | 66b310c | 2011-12-15 18:03:09 +0000 | [diff] [blame] | 476 | // Update all of the declarations with a pointer to the definition. |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 477 | for (auto RD : redecls()) { |
| 478 | if (RD != this) |
Douglas Gregor | a323c4c | 2011-12-15 18:17:27 +0000 | [diff] [blame] | 479 | RD->Data = Data; |
Douglas Gregor | 66b310c | 2011-12-15 18:03:09 +0000 | [diff] [blame] | 480 | } |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 483 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 484 | ObjCInterfaceDecl *&clsDeclared) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 485 | // FIXME: Should make sure no callers ever do this. |
| 486 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 487 | return nullptr; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 488 | |
| 489 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 4e8b136 | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 490 | LoadExternalDefinition(); |
| 491 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 492 | ObjCInterfaceDecl* ClassDecl = this; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 493 | while (ClassDecl != nullptr) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 494 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 495 | clsDeclared = ClassDecl; |
| 496 | return I; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 497 | } |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 498 | |
Aaron Ballman | f53d8dd | 2014-03-13 21:47:07 +0000 | [diff] [blame] | 499 | for (const auto *Ext : ClassDecl->visible_extensions()) { |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 500 | if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) { |
Fariborz Jahanian | afe1386 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 501 | clsDeclared = ClassDecl; |
| 502 | return I; |
| 503 | } |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 504 | } |
Fariborz Jahanian | afe1386 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 505 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 506 | ClassDecl = ClassDecl->getSuperClass(); |
| 507 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 508 | return nullptr; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Fariborz Jahanian | db3a4c1 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 511 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 512 | /// class whose name is passed as argument. If it is not one of the super classes |
| 513 | /// the it returns NULL. |
| 514 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 515 | const IdentifierInfo*ICName) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 516 | // FIXME: Should make sure no callers ever do this. |
| 517 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 518 | return nullptr; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 519 | |
| 520 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 4e8b136 | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 521 | LoadExternalDefinition(); |
| 522 | |
Fariborz Jahanian | db3a4c1 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 523 | ObjCInterfaceDecl* ClassDecl = this; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 524 | while (ClassDecl != nullptr) { |
Fariborz Jahanian | db3a4c1 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 525 | if (ClassDecl->getIdentifier() == ICName) |
| 526 | return ClassDecl; |
| 527 | ClassDecl = ClassDecl->getSuperClass(); |
| 528 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 529 | return nullptr; |
Fariborz Jahanian | db3a4c1 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Fariborz Jahanian | 56f48d0 | 2013-07-10 21:30:22 +0000 | [diff] [blame] | 532 | ObjCProtocolDecl * |
| 533 | ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) { |
Aaron Ballman | a9f49e3 | 2014-03-13 20:55:22 +0000 | [diff] [blame] | 534 | for (auto *P : all_referenced_protocols()) |
| 535 | if (P->lookupProtocolNamed(Name)) |
| 536 | return P; |
Fariborz Jahanian | 56f48d0 | 2013-07-10 21:30:22 +0000 | [diff] [blame] | 537 | ObjCInterfaceDecl *SuperClass = getSuperClass(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 538 | return SuperClass ? SuperClass->lookupNestedProtocol(Name) : nullptr; |
Fariborz Jahanian | 56f48d0 | 2013-07-10 21:30:22 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 541 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 542 | /// the class, its categories, and its super classes (using a linear search). |
Fariborz Jahanian | 73e244a | 2013-04-25 21:59:34 +0000 | [diff] [blame] | 543 | /// When argument category "C" is specified, any implicit method found |
| 544 | /// in this category is ignored. |
Fariborz Jahanian | c806b90 | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 545 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
Ted Kremenek | 0078150 | 2013-11-23 01:01:29 +0000 | [diff] [blame] | 546 | bool isInstance, |
| 547 | bool shallowCategoryLookup, |
| 548 | bool followSuper, |
Ted Kremenek | f41cf7f1 | 2013-12-10 19:43:48 +0000 | [diff] [blame] | 549 | const ObjCCategoryDecl *C) const |
Ted Kremenek | 0078150 | 2013-11-23 01:01:29 +0000 | [diff] [blame] | 550 | { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 551 | // FIXME: Should make sure no callers ever do this. |
| 552 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 553 | return nullptr; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 554 | |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 555 | const ObjCInterfaceDecl* ClassDecl = this; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 556 | ObjCMethodDecl *MethodDecl = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 558 | if (data().ExternallyCompleted) |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 559 | LoadExternalDefinition(); |
| 560 | |
Ted Kremenek | 0078150 | 2013-11-23 01:01:29 +0000 | [diff] [blame] | 561 | while (ClassDecl) { |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 562 | // 1. Look through primary class. |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 563 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 564 | return MethodDecl; |
Fariborz Jahanian | c806b90 | 2012-04-05 22:14:12 +0000 | [diff] [blame] | 565 | |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 566 | // 2. Didn't find one yet - now look through categories. |
| 567 | for (const auto *Cat : ClassDecl->visible_categories()) |
Fariborz Jahanian | 73e244a | 2013-04-25 21:59:34 +0000 | [diff] [blame] | 568 | if ((MethodDecl = Cat->getMethod(Sel, isInstance))) |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 569 | if (C != Cat || !MethodDecl->isImplicit()) |
Fariborz Jahanian | eb3f100 | 2013-04-24 17:06:38 +0000 | [diff] [blame] | 570 | return MethodDecl; |
Fariborz Jahanian | 29082a5 | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 571 | |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 572 | // 3. Didn't find one yet - look through primary class's protocols. |
| 573 | for (const auto *I : ClassDecl->protocols()) |
| 574 | if ((MethodDecl = I->lookupMethod(Sel, isInstance))) |
| 575 | return MethodDecl; |
| 576 | |
| 577 | // 4. Didn't find one yet - now look through categories' protocols |
| 578 | if (!shallowCategoryLookup) |
| 579 | for (const auto *Cat : ClassDecl->visible_categories()) { |
Fariborz Jahanian | 73e244a | 2013-04-25 21:59:34 +0000 | [diff] [blame] | 580 | // Didn't find one yet - look through protocols. |
| 581 | const ObjCList<ObjCProtocolDecl> &Protocols = |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 582 | Cat->getReferencedProtocols(); |
Fariborz Jahanian | 73e244a | 2013-04-25 21:59:34 +0000 | [diff] [blame] | 583 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 584 | E = Protocols.end(); I != E; ++I) |
| 585 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 586 | if (C != Cat || !MethodDecl->isImplicit()) |
Fariborz Jahanian | eb3f100 | 2013-04-24 17:06:38 +0000 | [diff] [blame] | 587 | return MethodDecl; |
Fariborz Jahanian | 29082a5 | 2012-02-09 21:30:24 +0000 | [diff] [blame] | 588 | } |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 589 | |
| 590 | |
Ted Kremenek | 0078150 | 2013-11-23 01:01:29 +0000 | [diff] [blame] | 591 | if (!followSuper) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 592 | return nullptr; |
Ted Kremenek | 0078150 | 2013-11-23 01:01:29 +0000 | [diff] [blame] | 593 | |
Fariborz Jahanian | 7e3e291 | 2014-08-27 20:34:29 +0000 | [diff] [blame] | 594 | // 5. Get to the super class (if any). |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 595 | ClassDecl = ClassDecl->getSuperClass(); |
| 596 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 597 | return nullptr; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Anna Zaks | c77a3b1 | 2012-07-27 19:07:44 +0000 | [diff] [blame] | 600 | // Will search "local" class/category implementations for a method decl. |
| 601 | // If failed, then we search in class's root for an instance method. |
| 602 | // Returns 0 if no method is found. |
Fariborz Jahanian | ecbbb6e | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 603 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( |
| 604 | const Selector &Sel, |
Anna Zaks | 7044adc | 2012-07-30 20:31:21 +0000 | [diff] [blame] | 605 | bool Instance) const { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 606 | // FIXME: Should make sure no callers ever do this. |
| 607 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 608 | return nullptr; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 609 | |
| 610 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 4e8b136 | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 611 | LoadExternalDefinition(); |
| 612 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 613 | ObjCMethodDecl *Method = nullptr; |
Steve Naroff | bb69c94 | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 614 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
Fariborz Jahanian | ecbbb6e | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 615 | Method = Instance ? ImpDecl->getInstanceMethod(Sel) |
| 616 | : ImpDecl->getClassMethod(Sel); |
Anna Zaks | c77a3b1 | 2012-07-27 19:07:44 +0000 | [diff] [blame] | 617 | |
| 618 | // Look through local category implementations associated with the class. |
| 619 | if (!Method) |
| 620 | Method = Instance ? getCategoryInstanceMethod(Sel) |
| 621 | : getCategoryClassMethod(Sel); |
| 622 | |
| 623 | // Before we give up, check if the selector is an instance method. |
| 624 | // But only in the root. This matches gcc's behavior and what the |
| 625 | // runtime expects. |
| 626 | if (!Instance && !Method && !getSuperClass()) { |
| 627 | Method = lookupInstanceMethod(Sel); |
| 628 | // Look through local category implementations associated |
| 629 | // with the root class. |
| 630 | if (!Method) |
| 631 | Method = lookupPrivateMethod(Sel, true); |
| 632 | } |
| 633 | |
Steve Naroff | bb69c94 | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 634 | if (!Method && getSuperClass()) |
Fariborz Jahanian | ecbbb6e | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 635 | return getSuperClass()->lookupPrivateMethod(Sel, Instance); |
Steve Naroff | bb69c94 | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 636 | return Method; |
| 637 | } |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 638 | |
| 639 | //===----------------------------------------------------------------------===// |
| 640 | // ObjCMethodDecl |
| 641 | //===----------------------------------------------------------------------===// |
| 642 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 643 | ObjCMethodDecl *ObjCMethodDecl::Create( |
| 644 | ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, |
| 645 | Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, |
| 646 | DeclContext *contextDecl, bool isInstance, bool isVariadic, |
| 647 | bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined, |
| 648 | ImplementationControl impControl, bool HasRelatedResultType) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 649 | return new (C, contextDecl) ObjCMethodDecl( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 650 | beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance, |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 651 | isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined, |
| 652 | impControl, HasRelatedResultType); |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 655 | ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 656 | return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 657 | Selector(), QualType(), nullptr, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 660 | bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const { |
| 661 | return getMethodFamily() == OMF_init && |
| 662 | hasAttr<ObjCDesignatedInitializerAttr>(); |
| 663 | } |
| 664 | |
Argyrios Kyrtzidis | fcded9b | 2013-12-03 21:11:43 +0000 | [diff] [blame] | 665 | bool ObjCMethodDecl::isDesignatedInitializerForTheInterface( |
| 666 | const ObjCMethodDecl **InitMethod) const { |
| 667 | if (getMethodFamily() != OMF_init) |
| 668 | return false; |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 669 | const DeclContext *DC = getDeclContext(); |
| 670 | if (isa<ObjCProtocolDecl>(DC)) |
| 671 | return false; |
| 672 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
Argyrios Kyrtzidis | fcded9b | 2013-12-03 21:11:43 +0000 | [diff] [blame] | 673 | return ID->isDesignatedInitializer(getSelector(), InitMethod); |
Argyrios Kyrtzidis | 22bfa2c | 2013-12-03 21:11:36 +0000 | [diff] [blame] | 674 | return false; |
| 675 | } |
| 676 | |
Douglas Gregor | a6017bb | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 677 | Stmt *ObjCMethodDecl::getBody() const { |
| 678 | return Body.get(getASTContext().getExternalSource()); |
| 679 | } |
| 680 | |
Argyrios Kyrtzidis | dcaaa21 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 681 | void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { |
| 682 | assert(PrevMethod); |
| 683 | getASTContext().setObjCMethodRedeclaration(PrevMethod, this); |
| 684 | IsRedeclaration = true; |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 685 | PrevMethod->HasRedeclaration = true; |
Argyrios Kyrtzidis | dcaaa21 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 688 | void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, |
| 689 | ArrayRef<ParmVarDecl*> Params, |
| 690 | ArrayRef<SourceLocation> SelLocs) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 691 | ParamsAndSelLocs = nullptr; |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 692 | NumParams = Params.size(); |
| 693 | if (Params.empty() && SelLocs.empty()) |
| 694 | return; |
| 695 | |
| 696 | unsigned Size = sizeof(ParmVarDecl *) * NumParams + |
| 697 | sizeof(SourceLocation) * SelLocs.size(); |
| 698 | ParamsAndSelLocs = C.Allocate(Size); |
| 699 | std::copy(Params.begin(), Params.end(), getParams()); |
| 700 | std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); |
| 701 | } |
| 702 | |
| 703 | void ObjCMethodDecl::getSelectorLocs( |
| 704 | SmallVectorImpl<SourceLocation> &SelLocs) const { |
| 705 | for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) |
| 706 | SelLocs.push_back(getSelectorLoc(i)); |
| 707 | } |
| 708 | |
| 709 | void ObjCMethodDecl::setMethodParams(ASTContext &C, |
| 710 | ArrayRef<ParmVarDecl*> Params, |
| 711 | ArrayRef<SourceLocation> SelLocs) { |
| 712 | assert((!SelLocs.empty() || isImplicit()) && |
| 713 | "No selector locs for non-implicit method"); |
| 714 | if (isImplicit()) |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 715 | return setParamsAndSelLocs(C, Params, llvm::None); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 716 | |
Argyrios Kyrtzidis | 33b4bfc | 2012-06-16 00:46:02 +0000 | [diff] [blame] | 717 | SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, |
| 718 | DeclEndLoc); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 719 | if (SelLocsKind != SelLoc_NonStandard) |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 720 | return setParamsAndSelLocs(C, Params, llvm::None); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 721 | |
| 722 | setParamsAndSelLocs(C, Params, SelLocs); |
| 723 | } |
| 724 | |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 725 | /// \brief A definition will return its interface declaration. |
| 726 | /// An interface declaration will return its definition. |
| 727 | /// Otherwise it will return itself. |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 728 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() { |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 729 | ASTContext &Ctx = getASTContext(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 730 | ObjCMethodDecl *Redecl = nullptr; |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 731 | if (HasRedeclaration) |
| 732 | Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); |
Argyrios Kyrtzidis | c5e829c | 2011-10-14 06:48:06 +0000 | [diff] [blame] | 733 | if (Redecl) |
| 734 | return Redecl; |
| 735 | |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 736 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 737 | |
Argyrios Kyrtzidis | 0f6d5ca | 2013-05-30 18:53:21 +0000 | [diff] [blame] | 738 | if (!CtxD->isInvalidDecl()) { |
| 739 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 740 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 741 | if (!ImplD->isInvalidDecl()) |
| 742 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 743 | |
Argyrios Kyrtzidis | 0f6d5ca | 2013-05-30 18:53:21 +0000 | [diff] [blame] | 744 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 745 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 746 | if (!ImplD->isInvalidDecl()) |
| 747 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 748 | |
Argyrios Kyrtzidis | 0f6d5ca | 2013-05-30 18:53:21 +0000 | [diff] [blame] | 749 | } else if (ObjCImplementationDecl *ImplD = |
| 750 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 751 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 752 | if (!IFD->isInvalidDecl()) |
| 753 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 754 | |
Argyrios Kyrtzidis | 0f6d5ca | 2013-05-30 18:53:21 +0000 | [diff] [blame] | 755 | } else if (ObjCCategoryImplDecl *CImplD = |
| 756 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
| 757 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
| 758 | if (!CatD->isInvalidDecl()) |
| 759 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
| 760 | } |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Argyrios Kyrtzidis | dcaaa21 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 763 | if (!Redecl && isRedeclaration()) { |
| 764 | // This is the last redeclaration, go back to the first method. |
| 765 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 766 | isInstanceMethod()); |
| 767 | } |
| 768 | |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 769 | return Redecl ? Redecl : this; |
| 770 | } |
| 771 | |
Argyrios Kyrtzidis | f390c43 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 772 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 773 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 774 | |
| 775 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 776 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 777 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 778 | isInstanceMethod())) |
| 779 | return MD; |
| 780 | |
| 781 | } else if (ObjCCategoryImplDecl *CImplD = |
| 782 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | f406f4d | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 783 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | f390c43 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 784 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 785 | isInstanceMethod())) |
| 786 | return MD; |
| 787 | } |
| 788 | |
Argyrios Kyrtzidis | 690dccd | 2011-10-17 19:48:09 +0000 | [diff] [blame] | 789 | if (isRedeclaration()) |
| 790 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 791 | isInstanceMethod()); |
| 792 | |
Argyrios Kyrtzidis | f390c43 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 793 | return this; |
| 794 | } |
| 795 | |
Argyrios Kyrtzidis | 33b4bfc | 2012-06-16 00:46:02 +0000 | [diff] [blame] | 796 | SourceLocation ObjCMethodDecl::getLocEnd() const { |
| 797 | if (Stmt *Body = getBody()) |
| 798 | return Body->getLocEnd(); |
| 799 | return DeclEndLoc; |
| 800 | } |
| 801 | |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 802 | ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { |
| 803 | ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family); |
John McCall | fb55f85 | 2011-03-02 21:01:41 +0000 | [diff] [blame] | 804 | if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 805 | return family; |
| 806 | |
John McCall | 86bc21f | 2011-03-02 11:33:24 +0000 | [diff] [blame] | 807 | // Check for an explicit attribute. |
| 808 | if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { |
| 809 | // The unfortunate necessity of mapping between enums here is due |
| 810 | // to the attributes framework. |
| 811 | switch (attr->getFamily()) { |
| 812 | case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; |
| 813 | case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; |
| 814 | case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; |
| 815 | case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; |
| 816 | case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; |
| 817 | case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; |
| 818 | } |
| 819 | Family = static_cast<unsigned>(family); |
| 820 | return family; |
| 821 | } |
| 822 | |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 823 | family = getSelector().getMethodFamily(); |
| 824 | switch (family) { |
| 825 | case OMF_None: break; |
| 826 | |
| 827 | // init only has a conventional meaning for an instance method, and |
| 828 | // it has to return an object. |
| 829 | case OMF_init: |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 830 | if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType()) |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 831 | family = OMF_None; |
| 832 | break; |
| 833 | |
| 834 | // alloc/copy/new have a conventional meaning for both class and |
| 835 | // instance methods, but they require an object return. |
| 836 | case OMF_alloc: |
| 837 | case OMF_copy: |
| 838 | case OMF_mutableCopy: |
| 839 | case OMF_new: |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 840 | if (!getReturnType()->isObjCObjectPointerType()) |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 841 | family = OMF_None; |
| 842 | break; |
| 843 | |
| 844 | // These selectors have a conventional meaning only for instance methods. |
| 845 | case OMF_dealloc: |
Nico Weber | 1fb8266 | 2011-08-28 22:35:17 +0000 | [diff] [blame] | 846 | case OMF_finalize: |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 847 | case OMF_retain: |
| 848 | case OMF_release: |
| 849 | case OMF_autorelease: |
| 850 | case OMF_retainCount: |
Douglas Gregor | 3382372 | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 851 | case OMF_self: |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 852 | if (!isInstanceMethod()) |
| 853 | family = OMF_None; |
| 854 | break; |
Fariborz Jahanian | b7a7736 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 855 | |
Fariborz Jahanian | 78e9deb | 2014-08-22 16:57:26 +0000 | [diff] [blame] | 856 | case OMF_initialize: |
| 857 | if (isInstanceMethod() || !getReturnType()->isVoidType()) |
| 858 | family = OMF_None; |
| 859 | break; |
| 860 | |
Fariborz Jahanian | b7a7736 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 861 | case OMF_performSelector: |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 862 | if (!isInstanceMethod() || !getReturnType()->isObjCIdType()) |
Fariborz Jahanian | b7a7736 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 863 | family = OMF_None; |
| 864 | else { |
| 865 | unsigned noParams = param_size(); |
| 866 | if (noParams < 1 || noParams > 3) |
| 867 | family = OMF_None; |
| 868 | else { |
Alp Toker | 1f307f4 | 2014-01-25 17:32:04 +0000 | [diff] [blame] | 869 | ObjCMethodDecl::param_type_iterator it = param_type_begin(); |
Fariborz Jahanian | b7a7736 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 870 | QualType ArgT = (*it); |
| 871 | if (!ArgT->isObjCSelType()) { |
| 872 | family = OMF_None; |
| 873 | break; |
| 874 | } |
| 875 | while (--noParams) { |
| 876 | it++; |
| 877 | ArgT = (*it); |
| 878 | if (!ArgT->isObjCIdType()) { |
| 879 | family = OMF_None; |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | break; |
| 886 | |
John McCall | b452625 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // Cache the result. |
| 890 | Family = static_cast<unsigned>(family); |
| 891 | return family; |
| 892 | } |
| 893 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 895 | const ObjCInterfaceDecl *OID) { |
| 896 | QualType selfTy; |
| 897 | if (isInstanceMethod()) { |
| 898 | // There may be no interface context due to error in declaration |
| 899 | // of the interface (which has been reported). Recover gracefully. |
| 900 | if (OID) { |
Daniel Dunbar | aefc2b9 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 901 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 7cae42b | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 902 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 903 | } else { |
| 904 | selfTy = Context.getObjCIdType(); |
| 905 | } |
| 906 | } else // we have a factory method. |
| 907 | selfTy = Context.getObjCClassType(); |
| 908 | |
John McCall | d463132 | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 909 | bool selfIsPseudoStrong = false; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 910 | bool selfIsConsumed = false; |
Ted Kremenek | 1fcdaa9 | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 911 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 912 | if (Context.getLangOpts().ObjCAutoRefCount) { |
Ted Kremenek | 1fcdaa9 | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 913 | if (isInstanceMethod()) { |
| 914 | selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 915 | |
Ted Kremenek | 1fcdaa9 | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 916 | // 'self' is always __strong. It's actually pseudo-strong except |
| 917 | // in init methods (or methods labeled ns_consumes_self), though. |
| 918 | Qualifiers qs; |
| 919 | qs.setObjCLifetime(Qualifiers::OCL_Strong); |
| 920 | selfTy = Context.getQualifiedType(selfTy, qs); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 921 | |
Ted Kremenek | 1fcdaa9 | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 922 | // In addition, 'self' is const unless this is an init method. |
| 923 | if (getMethodFamily() != OMF_init && !selfIsConsumed) { |
| 924 | selfTy = selfTy.withConst(); |
| 925 | selfIsPseudoStrong = true; |
| 926 | } |
| 927 | } |
| 928 | else { |
| 929 | assert(isClassMethod()); |
| 930 | // 'self' is always const in class methods. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 931 | selfTy = selfTy.withConst(); |
John McCall | d463132 | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 932 | selfIsPseudoStrong = true; |
| 933 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | ImplicitParamDecl *self |
| 937 | = ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 938 | &Context.Idents.get("self"), selfTy); |
| 939 | setSelfDecl(self); |
| 940 | |
| 941 | if (selfIsConsumed) |
Aaron Ballman | 36a5350 | 2014-01-16 13:03:14 +0000 | [diff] [blame] | 942 | self->addAttr(NSConsumedAttr::CreateImplicit(Context)); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 943 | |
John McCall | d463132 | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 944 | if (selfIsPseudoStrong) |
| 945 | self->setARCPseudoStrong(true); |
| 946 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 947 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 948 | &Context.Idents.get("_cmd"), |
Steve Naroff | 04f2d14 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 949 | Context.getObjCSelType())); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 952 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 953 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 954 | return ID; |
| 955 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 956 | return CD->getClassInterface(); |
Argyrios Kyrtzidis | 2cee40d | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 957 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 958 | return IMD->getClassInterface(); |
Fariborz Jahanian | 7a58302 | 2014-03-04 22:57:32 +0000 | [diff] [blame] | 959 | if (isa<ObjCProtocolDecl>(getDeclContext())) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 960 | return nullptr; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 961 | llvm_unreachable("unknown method context"); |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Aaron Ballman | 4bfa0de | 2014-08-01 12:58:11 +0000 | [diff] [blame] | 964 | SourceRange ObjCMethodDecl::getReturnTypeSourceRange() const { |
| 965 | const auto *TSI = getReturnTypeSourceInfo(); |
| 966 | if (TSI) |
| 967 | return TSI->getTypeLoc().getSourceRange(); |
| 968 | return SourceRange(); |
| 969 | } |
| 970 | |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 971 | static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, |
| 972 | const ObjCMethodDecl *Method, |
| 973 | SmallVectorImpl<const ObjCMethodDecl *> &Methods, |
| 974 | bool MovedToSuper) { |
| 975 | if (!Container) |
| 976 | return; |
| 977 | |
| 978 | // In categories look for overriden methods from protocols. A method from |
| 979 | // category is not "overriden" since it is considered as the "same" method |
| 980 | // (same USR) as the one from the interface. |
| 981 | if (const ObjCCategoryDecl * |
| 982 | Category = dyn_cast<ObjCCategoryDecl>(Container)) { |
| 983 | // Check whether we have a matching method at this category but only if we |
| 984 | // are at the super class level. |
| 985 | if (MovedToSuper) |
| 986 | if (ObjCMethodDecl * |
| 987 | Overridden = Container->getMethod(Method->getSelector(), |
Argyrios Kyrtzidis | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 988 | Method->isInstanceMethod(), |
| 989 | /*AllowHidden=*/true)) |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 990 | if (Method != Overridden) { |
| 991 | // We found an override at this category; there is no need to look |
| 992 | // into its protocols. |
| 993 | Methods.push_back(Overridden); |
| 994 | return; |
| 995 | } |
| 996 | |
Aaron Ballman | 19a4176 | 2014-03-14 12:55:57 +0000 | [diff] [blame] | 997 | for (const auto *P : Category->protocols()) |
| 998 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 999 | return; |
| 1000 | } |
| 1001 | |
| 1002 | // Check whether we have a matching method at this level. |
| 1003 | if (const ObjCMethodDecl * |
| 1004 | Overridden = Container->getMethod(Method->getSelector(), |
Argyrios Kyrtzidis | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 1005 | Method->isInstanceMethod(), |
| 1006 | /*AllowHidden=*/true)) |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1007 | if (Method != Overridden) { |
| 1008 | // We found an override at this level; there is no need to look |
| 1009 | // into other protocols or categories. |
| 1010 | Methods.push_back(Overridden); |
| 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){ |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 1015 | for (const auto *P : Protocol->protocols()) |
| 1016 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | if (const ObjCInterfaceDecl * |
| 1020 | Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { |
Aaron Ballman | a49c506 | 2014-03-13 20:29:09 +0000 | [diff] [blame] | 1021 | for (const auto *P : Interface->protocols()) |
| 1022 | CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1023 | |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 1024 | for (const auto *Cat : Interface->known_categories()) |
| 1025 | CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper); |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1026 | |
| 1027 | if (const ObjCInterfaceDecl *Super = Interface->getSuperClass()) |
| 1028 | return CollectOverriddenMethodsRecurse(Super, Method, Methods, |
| 1029 | /*MovedToSuper=*/true); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container, |
| 1034 | const ObjCMethodDecl *Method, |
| 1035 | SmallVectorImpl<const ObjCMethodDecl *> &Methods) { |
| 1036 | CollectOverriddenMethodsRecurse(Container, Method, Methods, |
| 1037 | /*MovedToSuper=*/false); |
| 1038 | } |
| 1039 | |
| 1040 | static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, |
| 1041 | SmallVectorImpl<const ObjCMethodDecl *> &overridden) { |
| 1042 | assert(Method->isOverriding()); |
| 1043 | |
| 1044 | if (const ObjCProtocolDecl * |
| 1045 | ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) { |
| 1046 | CollectOverriddenMethods(ProtD, Method, overridden); |
| 1047 | |
| 1048 | } else if (const ObjCImplDecl * |
| 1049 | IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) { |
| 1050 | const ObjCInterfaceDecl *ID = IMD->getClassInterface(); |
| 1051 | if (!ID) |
| 1052 | return; |
| 1053 | // Start searching for overridden methods using the method from the |
| 1054 | // interface as starting point. |
| 1055 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
Argyrios Kyrtzidis | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 1056 | Method->isInstanceMethod(), |
| 1057 | /*AllowHidden=*/true)) |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1058 | Method = IFaceMeth; |
| 1059 | CollectOverriddenMethods(ID, Method, overridden); |
| 1060 | |
| 1061 | } else if (const ObjCCategoryDecl * |
| 1062 | CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) { |
| 1063 | const ObjCInterfaceDecl *ID = CatD->getClassInterface(); |
| 1064 | if (!ID) |
| 1065 | return; |
| 1066 | // Start searching for overridden methods using the method from the |
| 1067 | // interface as starting point. |
| 1068 | if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), |
Argyrios Kyrtzidis | bd8cd3e | 2013-03-29 21:51:48 +0000 | [diff] [blame] | 1069 | Method->isInstanceMethod(), |
| 1070 | /*AllowHidden=*/true)) |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1071 | Method = IFaceMeth; |
| 1072 | CollectOverriddenMethods(ID, Method, overridden); |
| 1073 | |
| 1074 | } else { |
| 1075 | CollectOverriddenMethods( |
| 1076 | dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()), |
| 1077 | Method, overridden); |
| 1078 | } |
| 1079 | } |
| 1080 | |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1081 | void ObjCMethodDecl::getOverriddenMethods( |
| 1082 | SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const { |
| 1083 | const ObjCMethodDecl *Method = this; |
| 1084 | |
| 1085 | if (Method->isRedeclaration()) { |
| 1086 | Method = cast<ObjCContainerDecl>(Method->getDeclContext())-> |
| 1087 | getMethod(Method->getSelector(), Method->isInstanceMethod()); |
| 1088 | } |
| 1089 | |
Argyrios Kyrtzidis | c2091d5 | 2013-04-17 00:09:08 +0000 | [diff] [blame] | 1090 | if (Method->isOverriding()) { |
Argyrios Kyrtzidis | 353f6a4 | 2012-10-09 18:19:01 +0000 | [diff] [blame] | 1091 | collectOverriddenMethodsSlow(Method, Overridden); |
| 1092 | assert(!Overridden.empty() && |
| 1093 | "ObjCMethodDecl's overriding bit is not as expected"); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1097 | const ObjCPropertyDecl * |
| 1098 | ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { |
| 1099 | Selector Sel = getSelector(); |
| 1100 | unsigned NumArgs = Sel.getNumArgs(); |
| 1101 | if (NumArgs > 1) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1102 | return nullptr; |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1103 | |
Jordan Rose | 59e34ec | 2012-10-11 16:02:02 +0000 | [diff] [blame] | 1104 | if (!isInstanceMethod() || getMethodFamily() != OMF_None) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1105 | return nullptr; |
| 1106 | |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1107 | if (isPropertyAccessor()) { |
| 1108 | const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent()); |
Fariborz Jahanian | 37494a1 | 2013-01-12 00:28:34 +0000 | [diff] [blame] | 1109 | // If container is class extension, find its primary class. |
| 1110 | if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(Container)) |
| 1111 | if (CatDecl->IsClassExtension()) |
| 1112 | Container = CatDecl->getClassInterface(); |
| 1113 | |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1114 | bool IsGetter = (NumArgs == 0); |
| 1115 | |
Aaron Ballman | d174edf | 2014-03-13 19:11:50 +0000 | [diff] [blame] | 1116 | for (const auto *I : Container->properties()) { |
Aaron Ballman | dc4bea4 | 2014-03-13 18:47:37 +0000 | [diff] [blame] | 1117 | Selector NextSel = IsGetter ? I->getGetterName() |
| 1118 | : I->getSetterName(); |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1119 | if (NextSel == Sel) |
Aaron Ballman | dc4bea4 | 2014-03-13 18:47:37 +0000 | [diff] [blame] | 1120 | return I; |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | llvm_unreachable("Marked as a property accessor but no property found!"); |
| 1124 | } |
| 1125 | |
| 1126 | if (!CheckOverrides) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1127 | return nullptr; |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1128 | |
| 1129 | typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy; |
| 1130 | OverridesTy Overrides; |
| 1131 | getOverriddenMethods(Overrides); |
| 1132 | for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end(); |
| 1133 | I != E; ++I) { |
| 1134 | if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false)) |
| 1135 | return Prop; |
| 1136 | } |
| 1137 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1138 | return nullptr; |
Jordan Rose | 2bd991a | 2012-10-10 16:42:54 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1141 | //===----------------------------------------------------------------------===// |
| 1142 | // ObjCInterfaceDecl |
| 1143 | //===----------------------------------------------------------------------===// |
| 1144 | |
Douglas Gregor | d53ae83 | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 1145 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1146 | DeclContext *DC, |
| 1147 | SourceLocation atLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | IdentifierInfo *Id, |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1149 | ObjCInterfaceDecl *PrevDecl, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1150 | SourceLocation ClassLoc, |
Douglas Gregor | dc9166c | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1151 | bool isInternal){ |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1152 | ObjCInterfaceDecl *Result = new (C, DC) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1153 | ObjCInterfaceDecl(C, DC, atLoc, Id, ClassLoc, PrevDecl, isInternal); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1154 | Result->Data.setInt(!C.getLangOpts().Modules); |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1155 | C.getObjCInterfaceType(Result, PrevDecl); |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 1156 | return Result; |
| 1157 | } |
| 1158 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1159 | ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(const ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1160 | unsigned ID) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1161 | ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(C, nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1162 | SourceLocation(), |
| 1163 | nullptr, |
| 1164 | SourceLocation(), |
| 1165 | nullptr, false); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1166 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1167 | return Result; |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1170 | ObjCInterfaceDecl::ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, |
| 1171 | SourceLocation AtLoc, IdentifierInfo *Id, |
| 1172 | SourceLocation CLoc, |
| 1173 | ObjCInterfaceDecl *PrevDecl, |
| 1174 | bool IsInternal) |
| 1175 | : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, AtLoc), |
| 1176 | redeclarable_base(C), TypeForDecl(nullptr), Data() { |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1177 | setPreviousDecl(PrevDecl); |
Douglas Gregor | 8125235 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Copy the 'data' pointer over. |
| 1180 | if (PrevDecl) |
| 1181 | Data = PrevDecl->Data; |
| 1182 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1183 | setImplicit(IsInternal); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1186 | void ObjCInterfaceDecl::LoadExternalDefinition() const { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1187 | assert(data().ExternallyCompleted && "Class is not externally completed"); |
| 1188 | data().ExternallyCompleted = false; |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1189 | getASTContext().getExternalSource()->CompleteType( |
| 1190 | const_cast<ObjCInterfaceDecl *>(this)); |
| 1191 | } |
| 1192 | |
| 1193 | void ObjCInterfaceDecl::setExternallyCompleted() { |
| 1194 | assert(getASTContext().getExternalSource() && |
| 1195 | "Class can't be externally completed without an external source"); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1196 | assert(hasDefinition() && |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1197 | "Forward declarations can't be externally completed"); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1198 | data().ExternallyCompleted = true; |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 1201 | void ObjCInterfaceDecl::setHasDesignatedInitializers() { |
Fariborz Jahanian | 0c32531 | 2014-03-11 18:56:18 +0000 | [diff] [blame] | 1202 | // Check for a complete definition and recover if not so. |
| 1203 | if (!isThisDeclarationADefinition()) |
| 1204 | return; |
Argyrios Kyrtzidis | 9ed9e5f | 2013-12-03 21:11:30 +0000 | [diff] [blame] | 1205 | data().HasDesignatedInitializers = true; |
| 1206 | } |
| 1207 | |
Argyrios Kyrtzidis | b66d3cf | 2013-12-03 21:11:49 +0000 | [diff] [blame] | 1208 | bool ObjCInterfaceDecl::hasDesignatedInitializers() const { |
Fariborz Jahanian | 0c32531 | 2014-03-11 18:56:18 +0000 | [diff] [blame] | 1209 | // Check for a complete definition and recover if not so. |
| 1210 | if (!isThisDeclarationADefinition()) |
| 1211 | return false; |
Argyrios Kyrtzidis | b66d3cf | 2013-12-03 21:11:49 +0000 | [diff] [blame] | 1212 | if (data().ExternallyCompleted) |
| 1213 | LoadExternalDefinition(); |
| 1214 | |
| 1215 | return data().HasDesignatedInitializers; |
| 1216 | } |
| 1217 | |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1218 | StringRef |
| 1219 | ObjCInterfaceDecl::getObjCRuntimeNameAsString() const { |
Fariborz Jahanian | a2e5deb | 2014-07-16 19:44:34 +0000 | [diff] [blame] | 1220 | if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>()) |
| 1221 | return ObjCRTName->getMetadataName(); |
| 1222 | |
| 1223 | return getName(); |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | StringRef |
| 1227 | ObjCImplementationDecl::getObjCRuntimeNameAsString() const { |
Fariborz Jahanian | a2e5deb | 2014-07-16 19:44:34 +0000 | [diff] [blame] | 1228 | if (ObjCInterfaceDecl *ID = |
| 1229 | const_cast<ObjCImplementationDecl*>(this)->getClassInterface()) |
| 1230 | return ID->getObjCRuntimeNameAsString(); |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1231 | |
Fariborz Jahanian | a2e5deb | 2014-07-16 19:44:34 +0000 | [diff] [blame] | 1232 | return getName(); |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1235 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
Douglas Gregor | dc9166c | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1236 | if (const ObjCInterfaceDecl *Def = getDefinition()) { |
| 1237 | if (data().ExternallyCompleted) |
| 1238 | LoadExternalDefinition(); |
| 1239 | |
| 1240 | return getASTContext().getObjCImplementation( |
| 1241 | const_cast<ObjCInterfaceDecl*>(Def)); |
| 1242 | } |
| 1243 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1244 | // FIXME: Should make sure no callers ever do this. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1245 | return nullptr; |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
Douglas Gregor | dc9166c | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1249 | getASTContext().setObjCImplementation(getDefinition(), ImplD); |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Fariborz Jahanian | 3c82204 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1252 | namespace { |
| 1253 | struct SynthesizeIvarChunk { |
| 1254 | uint64_t Size; |
| 1255 | ObjCIvarDecl *Ivar; |
| 1256 | SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar) |
| 1257 | : Size(size), Ivar(ivar) {} |
| 1258 | }; |
| 1259 | |
| 1260 | bool operator<(const SynthesizeIvarChunk & LHS, |
| 1261 | const SynthesizeIvarChunk &RHS) { |
| 1262 | return LHS.Size < RHS.Size; |
| 1263 | } |
| 1264 | } |
| 1265 | |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1266 | /// all_declared_ivar_begin - return first ivar declared in this class, |
| 1267 | /// its extensions and its implementation. Lazily build the list on first |
| 1268 | /// access. |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1269 | /// |
| 1270 | /// Caveat: The list returned by this method reflects the current |
| 1271 | /// state of the parser. The cache will be updated for every ivar |
| 1272 | /// added by an extension or the implementation when they are |
| 1273 | /// encountered. |
| 1274 | /// See also ObjCIvarDecl::Create(). |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1275 | ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1276 | // FIXME: Should make sure no callers ever do this. |
| 1277 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1278 | return nullptr; |
| 1279 | |
| 1280 | ObjCIvarDecl *curIvar = nullptr; |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1281 | if (!data().IvarList) { |
| 1282 | if (!ivar_empty()) { |
| 1283 | ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); |
| 1284 | data().IvarList = *I; ++I; |
| 1285 | for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) |
Adrian Prantl | 68a5750 | 2013-02-27 01:31:55 +0000 | [diff] [blame] | 1286 | curIvar->setNextIvar(*I); |
| 1287 | } |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1288 | |
Aaron Ballman | b4a5345 | 2014-03-13 21:57:01 +0000 | [diff] [blame] | 1289 | for (const auto *Ext : known_extensions()) { |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1290 | if (!Ext->ivar_empty()) { |
| 1291 | ObjCCategoryDecl::ivar_iterator |
| 1292 | I = Ext->ivar_begin(), |
| 1293 | E = Ext->ivar_end(); |
| 1294 | if (!data().IvarList) { |
| 1295 | data().IvarList = *I; ++I; |
| 1296 | curIvar = data().IvarList; |
| 1297 | } |
| 1298 | for ( ;I != E; curIvar = *I, ++I) |
| 1299 | curIvar->setNextIvar(*I); |
| 1300 | } |
| 1301 | } |
| 1302 | data().IvarListMissingImplementation = true; |
Adrian Prantl | 68a5750 | 2013-02-27 01:31:55 +0000 | [diff] [blame] | 1303 | } |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1304 | |
| 1305 | // cached and complete! |
| 1306 | if (!data().IvarListMissingImplementation) |
| 1307 | return data().IvarList; |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1308 | |
| 1309 | if (ObjCImplementationDecl *ImplDecl = getImplementation()) { |
Adrian Prantl | a03a85a | 2013-03-06 22:03:30 +0000 | [diff] [blame] | 1310 | data().IvarListMissingImplementation = false; |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1311 | if (!ImplDecl->ivar_empty()) { |
Fariborz Jahanian | 3c82204 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1312 | SmallVector<SynthesizeIvarChunk, 16> layout; |
Aaron Ballman | d6d25de | 2014-03-14 15:16:45 +0000 | [diff] [blame] | 1313 | for (auto *IV : ImplDecl->ivars()) { |
Fariborz Jahanian | 3c82204 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1314 | if (IV->getSynthesize() && !IV->isInvalidDecl()) { |
| 1315 | layout.push_back(SynthesizeIvarChunk( |
| 1316 | IV->getASTContext().getTypeSize(IV->getType()), IV)); |
| 1317 | continue; |
| 1318 | } |
| 1319 | if (!data().IvarList) |
Aaron Ballman | d6d25de | 2014-03-14 15:16:45 +0000 | [diff] [blame] | 1320 | data().IvarList = IV; |
Fariborz Jahanian | 3c82204 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1321 | else |
Aaron Ballman | d6d25de | 2014-03-14 15:16:45 +0000 | [diff] [blame] | 1322 | curIvar->setNextIvar(IV); |
| 1323 | curIvar = IV; |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1324 | } |
Fariborz Jahanian | 3c82204 | 2013-02-13 22:50:36 +0000 | [diff] [blame] | 1325 | |
| 1326 | if (!layout.empty()) { |
| 1327 | // Order synthesized ivars by their size. |
| 1328 | std::stable_sort(layout.begin(), layout.end()); |
| 1329 | unsigned Ix = 0, EIx = layout.size(); |
| 1330 | if (!data().IvarList) { |
| 1331 | data().IvarList = layout[0].Ivar; Ix++; |
| 1332 | curIvar = data().IvarList; |
| 1333 | } |
| 1334 | for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) |
| 1335 | curIvar->setNextIvar(layout[Ix].Ivar); |
| 1336 | } |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1337 | } |
| 1338 | } |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1339 | return data().IvarList; |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1340 | } |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1341 | |
| 1342 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 1343 | /// categories for this class and returns it. Name of the category is passed |
| 1344 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1345 | /// |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1346 | ObjCCategoryDecl * |
| 1347 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
Argyrios Kyrtzidis | 4af2cb3 | 2012-03-02 19:14:29 +0000 | [diff] [blame] | 1348 | // FIXME: Should make sure no callers ever do this. |
| 1349 | if (!hasDefinition()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1350 | return nullptr; |
Argyrios Kyrtzidis | 4af2cb3 | 2012-03-02 19:14:29 +0000 | [diff] [blame] | 1351 | |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1352 | if (data().ExternallyCompleted) |
Douglas Gregor | 7369302 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 1353 | LoadExternalDefinition(); |
| 1354 | |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 1355 | for (auto *Cat : visible_categories()) |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1356 | if (Cat->getIdentifier() == CategoryId) |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 1357 | return Cat; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1358 | |
| 1359 | return nullptr; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1362 | ObjCMethodDecl * |
| 1363 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 1364 | for (const auto *Cat : visible_categories()) { |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1365 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1366 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 1367 | return MD; |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1370 | return nullptr; |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 1374 | for (const auto *Cat : visible_categories()) { |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1375 | if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1376 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 1377 | return MD; |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1378 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1379 | |
| 1380 | return nullptr; |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1383 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 1384 | /// has been implemented in IDecl class, its super class or categories (if |
| 1385 | /// lookupCategory is true). |
| 1386 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 1387 | bool lookupCategory, |
| 1388 | bool RHSIsQualifiedID) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1389 | if (!hasDefinition()) |
| 1390 | return false; |
| 1391 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1392 | ObjCInterfaceDecl *IDecl = this; |
| 1393 | // 1st, look up the class. |
Aaron Ballman | a49c506 | 2014-03-13 20:29:09 +0000 | [diff] [blame] | 1394 | for (auto *PI : IDecl->protocols()){ |
| 1395 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1396 | return true; |
| 1397 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 1398 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 1399 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 1400 | // object. This IMO, should be a bug. |
| 1401 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 1402 | // extensions are not enabled. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | if (RHSIsQualifiedID && |
Aaron Ballman | a49c506 | 2014-03-13 20:29:09 +0000 | [diff] [blame] | 1404 | getASTContext().ProtocolCompatibleWithProtocol(PI, lProto)) |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1405 | return true; |
| 1406 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1408 | // 2nd, look up the category. |
| 1409 | if (lookupCategory) |
Aaron Ballman | 3fe486a | 2014-03-13 21:23:55 +0000 | [diff] [blame] | 1410 | for (const auto *Cat : visible_categories()) { |
Aaron Ballman | 19a4176 | 2014-03-14 12:55:57 +0000 | [diff] [blame] | 1411 | for (auto *PI : Cat->protocols()) |
| 1412 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1413 | return true; |
| 1414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1416 | // 3rd, look up the super class(s) |
| 1417 | if (IDecl->getSuperClass()) |
| 1418 | return |
| 1419 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 1420 | RHSIsQualifiedID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
| 1424 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1425 | //===----------------------------------------------------------------------===// |
| 1426 | // ObjCIvarDecl |
| 1427 | //===----------------------------------------------------------------------===// |
| 1428 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1429 | void ObjCIvarDecl::anchor() { } |
| 1430 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1431 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1432 | SourceLocation StartLoc, |
| 1433 | SourceLocation IdLoc, IdentifierInfo *Id, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1434 | QualType T, TypeSourceInfo *TInfo, |
Fariborz Jahanian | 1872298 | 2010-07-17 00:59:30 +0000 | [diff] [blame] | 1435 | AccessControl ac, Expr *BW, |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 1436 | bool synthesized) { |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1437 | if (DC) { |
| 1438 | // Ivar's can only appear in interfaces, implementations (via synthesized |
| 1439 | // properties), and class extensions (via direct declaration, or synthesized |
| 1440 | // properties). |
| 1441 | // |
| 1442 | // FIXME: This should really be asserting this: |
| 1443 | // (isa<ObjCCategoryDecl>(DC) && |
| 1444 | // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) |
| 1445 | // but unfortunately we sometimes place ivars into non-class extension |
| 1446 | // categories on error. This breaks an AST invariant, and should not be |
| 1447 | // fixed. |
| 1448 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 1449 | isa<ObjCCategoryDecl>(DC)) && |
| 1450 | "Invalid ivar decl context!"); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1451 | // Once a new ivar is created in any of class/class-extension/implementation |
| 1452 | // decl contexts, the previously built IvarList must be rebuilt. |
| 1453 | ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC); |
| 1454 | if (!ID) { |
Eric Christopher | f8378ca | 2012-07-19 22:22:55 +0000 | [diff] [blame] | 1455 | if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1456 | ID = IM->getClassInterface(); |
Eric Christopher | f8378ca | 2012-07-19 22:22:55 +0000 | [diff] [blame] | 1457 | else |
| 1458 | ID = cast<ObjCCategoryDecl>(DC)->getClassInterface(); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1459 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1460 | ID->setIvarList(nullptr); |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1463 | return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW, |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 1464 | synthesized); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1467 | ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1468 | return new (C, ID) ObjCIvarDecl(nullptr, SourceLocation(), SourceLocation(), |
| 1469 | nullptr, QualType(), nullptr, |
| 1470 | ObjCIvarDecl::None, nullptr, false); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Daniel Dunbar | 89947ea | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1473 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 1474 | const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1475 | |
Daniel Dunbar | 89947ea | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1476 | switch (DC->getKind()) { |
| 1477 | default: |
| 1478 | case ObjCCategoryImpl: |
| 1479 | case ObjCProtocol: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1480 | llvm_unreachable("invalid ivar container!"); |
Daniel Dunbar | 89947ea | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Ivars can only appear in class extension categories. |
| 1483 | case ObjCCategory: { |
| 1484 | const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 1485 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 1486 | return CD->getClassInterface(); |
| 1487 | } |
| 1488 | |
| 1489 | case ObjCImplementation: |
| 1490 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 1491 | |
| 1492 | case ObjCInterface: |
| 1493 | return cast<ObjCInterfaceDecl>(DC); |
| 1494 | } |
| 1495 | } |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1496 | |
| 1497 | //===----------------------------------------------------------------------===// |
| 1498 | // ObjCAtDefsFieldDecl |
| 1499 | //===----------------------------------------------------------------------===// |
| 1500 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1501 | void ObjCAtDefsFieldDecl::anchor() { } |
| 1502 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1503 | ObjCAtDefsFieldDecl |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1504 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, |
| 1505 | SourceLocation StartLoc, SourceLocation IdLoc, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1506 | IdentifierInfo *Id, QualType T, Expr *BW) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1507 | return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1510 | ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1511 | unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1512 | return new (C, ID) ObjCAtDefsFieldDecl(nullptr, SourceLocation(), |
| 1513 | SourceLocation(), nullptr, QualType(), |
| 1514 | nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1517 | //===----------------------------------------------------------------------===// |
| 1518 | // ObjCProtocolDecl |
| 1519 | //===----------------------------------------------------------------------===// |
| 1520 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1521 | void ObjCProtocolDecl::anchor() { } |
| 1522 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1523 | ObjCProtocolDecl::ObjCProtocolDecl(ASTContext &C, DeclContext *DC, |
| 1524 | IdentifierInfo *Id, SourceLocation nameLoc, |
Douglas Gregor | 32c1757 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1525 | SourceLocation atStartLoc, |
Douglas Gregor | 05a1f4d | 2012-01-01 22:06:18 +0000 | [diff] [blame] | 1526 | ObjCProtocolDecl *PrevDecl) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1527 | : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), |
| 1528 | redeclarable_base(C), Data() { |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1529 | setPreviousDecl(PrevDecl); |
Douglas Gregor | 32c1757 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1530 | if (PrevDecl) |
| 1531 | Data = PrevDecl->Data; |
| 1532 | } |
| 1533 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1534 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1535 | IdentifierInfo *Id, |
| 1536 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | 1f4bee5 | 2011-10-17 19:48:06 +0000 | [diff] [blame] | 1537 | SourceLocation atStartLoc, |
Douglas Gregor | 05a1f4d | 2012-01-01 22:06:18 +0000 | [diff] [blame] | 1538 | ObjCProtocolDecl *PrevDecl) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1539 | ObjCProtocolDecl *Result = |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1540 | new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1541 | Result->Data.setInt(!C.getLangOpts().Modules); |
Douglas Gregor | 32c1757 | 2012-01-01 20:30:41 +0000 | [diff] [blame] | 1542 | return Result; |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1545 | ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1546 | unsigned ID) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1547 | ObjCProtocolDecl *Result = |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1548 | new (C, ID) ObjCProtocolDecl(C, nullptr, nullptr, SourceLocation(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1549 | SourceLocation(), nullptr); |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1550 | Result->Data.setInt(!C.getLangOpts().Modules); |
| 1551 | return Result; |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Steve Naroff | 114aecb | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 1554 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 1555 | ObjCProtocolDecl *PDecl = this; |
| 1556 | |
| 1557 | if (Name == getIdentifier()) |
| 1558 | return PDecl; |
| 1559 | |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 1560 | for (auto *I : protocols()) |
| 1561 | if ((PDecl = I->lookupProtocolNamed(Name))) |
Steve Naroff | 114aecb | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 1562 | return PDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1564 | return nullptr; |
Steve Naroff | 114aecb | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1567 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1568 | // it inherited. |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1569 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 1570 | bool isInstance) const { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1571 | ObjCMethodDecl *MethodDecl = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 1573 | // If there is no definition or the definition is hidden, we don't find |
| 1574 | // anything. |
| 1575 | const ObjCProtocolDecl *Def = getDefinition(); |
| 1576 | if (!Def || Def->isHidden()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1577 | return nullptr; |
Douglas Gregor | eed4979 | 2013-01-17 00:38:46 +0000 | [diff] [blame] | 1578 | |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 1579 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1580 | return MethodDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1581 | |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 1582 | for (const auto *I : protocols()) |
| 1583 | if ((MethodDecl = I->lookupMethod(Sel, isInstance))) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1584 | return MethodDecl; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1585 | return nullptr; |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1588 | void ObjCProtocolDecl::allocateDefinitionData() { |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 1589 | assert(!Data.getPointer() && "Protocol already has a definition!"); |
| 1590 | Data.setPointer(new (getASTContext()) DefinitionData); |
| 1591 | Data.getPointer()->Definition = this; |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | void ObjCProtocolDecl::startDefinition() { |
| 1595 | allocateDefinitionData(); |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1596 | |
| 1597 | // Update all of the declarations with a pointer to the definition. |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 1598 | for (auto RD : redecls()) |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1599 | RD->Data = this->Data; |
Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Fariborz Jahanian | aedaaa4 | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 1602 | void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, |
| 1603 | PropertyDeclOrder &PO) const { |
Fariborz Jahanian | 0a17f59 | 2013-01-07 21:31:08 +0000 | [diff] [blame] | 1604 | |
| 1605 | if (const ObjCProtocolDecl *PDecl = getDefinition()) { |
Aaron Ballman | d174edf | 2014-03-13 19:11:50 +0000 | [diff] [blame] | 1606 | for (auto *Prop : PDecl->properties()) { |
Fariborz Jahanian | 0a17f59 | 2013-01-07 21:31:08 +0000 | [diff] [blame] | 1607 | // Insert into PM if not there already. |
| 1608 | PM.insert(std::make_pair(Prop->getIdentifier(), Prop)); |
Fariborz Jahanian | aedaaa4 | 2013-02-14 22:33:34 +0000 | [diff] [blame] | 1609 | PO.push_back(Prop); |
Fariborz Jahanian | 0a17f59 | 2013-01-07 21:31:08 +0000 | [diff] [blame] | 1610 | } |
| 1611 | // Scan through protocol's protocols. |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 1612 | for (const auto *PI : PDecl->protocols()) |
| 1613 | PI->collectPropertiesToImplement(PM, PO); |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 1614 | } |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Fariborz Jahanian | 0ebf879 | 2013-05-20 21:20:24 +0000 | [diff] [blame] | 1617 | |
| 1618 | void ObjCProtocolDecl::collectInheritedProtocolProperties( |
| 1619 | const ObjCPropertyDecl *Property, |
| 1620 | ProtocolPropertyMap &PM) const { |
| 1621 | if (const ObjCProtocolDecl *PDecl = getDefinition()) { |
| 1622 | bool MatchFound = false; |
Aaron Ballman | d174edf | 2014-03-13 19:11:50 +0000 | [diff] [blame] | 1623 | for (auto *Prop : PDecl->properties()) { |
Fariborz Jahanian | 0ebf879 | 2013-05-20 21:20:24 +0000 | [diff] [blame] | 1624 | if (Prop == Property) |
| 1625 | continue; |
| 1626 | if (Prop->getIdentifier() == Property->getIdentifier()) { |
| 1627 | PM[PDecl] = Prop; |
| 1628 | MatchFound = true; |
| 1629 | break; |
| 1630 | } |
| 1631 | } |
| 1632 | // Scan through protocol's protocols which did not have a matching property. |
| 1633 | if (!MatchFound) |
Aaron Ballman | 0f6e64d | 2014-03-13 22:58:06 +0000 | [diff] [blame] | 1634 | for (const auto *PI : PDecl->protocols()) |
| 1635 | PI->collectInheritedProtocolProperties(Property, PM); |
Fariborz Jahanian | 0ebf879 | 2013-05-20 21:20:24 +0000 | [diff] [blame] | 1636 | } |
| 1637 | } |
Anna Zaks | 673d76b | 2012-10-18 19:17:53 +0000 | [diff] [blame] | 1638 | |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1639 | StringRef |
| 1640 | ObjCProtocolDecl::getObjCRuntimeNameAsString() const { |
Fariborz Jahanian | a2e5deb | 2014-07-16 19:44:34 +0000 | [diff] [blame] | 1641 | if (ObjCRuntimeNameAttr *ObjCRTName = getAttr<ObjCRuntimeNameAttr>()) |
| 1642 | return ObjCRTName->getMetadataName(); |
| 1643 | |
| 1644 | return getName(); |
Fariborz Jahanian | 451b92a | 2014-07-16 16:16:04 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1647 | //===----------------------------------------------------------------------===// |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1648 | // ObjCCategoryDecl |
| 1649 | //===----------------------------------------------------------------------===// |
| 1650 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1651 | void ObjCCategoryDecl::anchor() { } |
| 1652 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1653 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1654 | SourceLocation AtLoc, |
Douglas Gregor | 071676f | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1655 | SourceLocation ClassNameLoc, |
| 1656 | SourceLocation CategoryNameLoc, |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1657 | IdentifierInfo *Id, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1658 | ObjCInterfaceDecl *IDecl, |
| 1659 | SourceLocation IvarLBraceLoc, |
| 1660 | SourceLocation IvarRBraceLoc) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1661 | ObjCCategoryDecl *CatDecl = |
| 1662 | new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id, |
| 1663 | IDecl, IvarLBraceLoc, IvarRBraceLoc); |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1664 | if (IDecl) { |
| 1665 | // Link this category into its class's category list. |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1666 | CatDecl->NextClassCategory = IDecl->getCategoryListRaw(); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1667 | if (IDecl->hasDefinition()) { |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 1668 | IDecl->setCategoryListRaw(CatDecl); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1669 | if (ASTMutationListener *L = C.getASTMutationListener()) |
| 1670 | L->AddedObjCCategoryToInterface(CatDecl, IDecl); |
| 1671 | } |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | return CatDecl; |
| 1675 | } |
| 1676 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1677 | ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1678 | unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1679 | return new (C, ID) ObjCCategoryDecl(nullptr, SourceLocation(), |
| 1680 | SourceLocation(), SourceLocation(), |
| 1681 | nullptr, nullptr); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1684 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 1685 | return getASTContext().getObjCImplementation( |
| 1686 | const_cast<ObjCCategoryDecl*>(this)); |
| 1687 | } |
| 1688 | |
| 1689 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 1690 | getASTContext().setObjCImplementation(this, ImplD); |
| 1691 | } |
| 1692 | |
| 1693 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1694 | //===----------------------------------------------------------------------===// |
| 1695 | // ObjCCategoryImplDecl |
| 1696 | //===----------------------------------------------------------------------===// |
| 1697 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1698 | void ObjCCategoryImplDecl::anchor() { } |
| 1699 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1700 | ObjCCategoryImplDecl * |
| 1701 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1702 | IdentifierInfo *Id, |
| 1703 | ObjCInterfaceDecl *ClassInterface, |
| 1704 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 1705 | SourceLocation atStartLoc, |
| 1706 | SourceLocation CategoryNameLoc) { |
Fariborz Jahanian | 87b4ae6c | 2011-12-23 00:31:02 +0000 | [diff] [blame] | 1707 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 1708 | ClassInterface = ClassInterface->getDefinition(); |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1709 | return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc, |
| 1710 | atStartLoc, CategoryNameLoc); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1713 | ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, |
| 1714 | unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1715 | return new (C, ID) ObjCCategoryImplDecl(nullptr, nullptr, nullptr, |
| 1716 | SourceLocation(), SourceLocation(), |
| 1717 | SourceLocation()); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Steve Naroff | f406f4d | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 1720 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
Ted Kremenek | e184ac5 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 1721 | // The class interface might be NULL if we are working with invalid code. |
| 1722 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 1723 | return ID->FindCategoryDeclaration(getIdentifier()); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1724 | return nullptr; |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1727 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1728 | void ObjCImplDecl::anchor() { } |
| 1729 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1730 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 9a13efd | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 1731 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 29bd76f | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1732 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1733 | addDecl(property); |
Douglas Gregor | 29bd76f | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1736 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 1737 | ASTContext &Ctx = getASTContext(); |
| 1738 | |
| 1739 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 49c29ee | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1740 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1741 | if (IFace) |
| 1742 | Ctx.setObjCImplementation(IFace, ImplD); |
| 1743 | |
Duncan Sands | 49c29ee | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1744 | } else if (ObjCCategoryImplDecl *ImplD = |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1745 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 1746 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 1747 | Ctx.setObjCImplementation(CD, ImplD); |
| 1748 | } |
| 1749 | |
| 1750 | ClassInterface = IFace; |
| 1751 | } |
| 1752 | |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1753 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Fariborz Jahanian | e92f54a | 2013-03-12 17:43:00 +0000 | [diff] [blame] | 1754 | /// properties implemented in this \@implementation block and returns |
Chris Lattner | aab70d2 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 1755 | /// the implemented property that uses it. |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1756 | /// |
Chris Lattner | a9ca052 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1757 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1758 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
Aaron Ballman | d85eff4 | 2014-03-14 15:02:45 +0000 | [diff] [blame] | 1759 | for (auto *PID : property_impls()) |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1760 | if (PID->getPropertyIvarDecl() && |
| 1761 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 1762 | return PID; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1763 | return nullptr; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
James Dennett | 5207a1c | 2012-06-15 22:30:14 +0000 | [diff] [blame] | 1767 | /// added to the list of those properties \@synthesized/\@dynamic in this |
| 1768 | /// category \@implementation block. |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1769 | /// |
Chris Lattner | a9ca052 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1770 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1771 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
Aaron Ballman | d85eff4 | 2014-03-14 15:02:45 +0000 | [diff] [blame] | 1772 | for (auto *PID : property_impls()) |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1773 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 1774 | return PID; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1775 | return nullptr; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1778 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | 2f56992 | 2012-02-07 11:57:45 +0000 | [diff] [blame] | 1779 | const ObjCCategoryImplDecl &CID) { |
| 1780 | OS << CID.getName(); |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1781 | return OS; |
| 1782 | } |
| 1783 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1784 | //===----------------------------------------------------------------------===// |
| 1785 | // ObjCImplementationDecl |
| 1786 | //===----------------------------------------------------------------------===// |
| 1787 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1788 | void ObjCImplementationDecl::anchor() { } |
| 1789 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1790 | ObjCImplementationDecl * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1792 | ObjCInterfaceDecl *ClassInterface, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1793 | ObjCInterfaceDecl *SuperDecl, |
| 1794 | SourceLocation nameLoc, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1795 | SourceLocation atStartLoc, |
Argyrios Kyrtzidis | fac3162 | 2013-05-03 18:05:44 +0000 | [diff] [blame] | 1796 | SourceLocation superLoc, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 1797 | SourceLocation IvarLBraceLoc, |
| 1798 | SourceLocation IvarRBraceLoc) { |
Fariborz Jahanian | 87b4ae6c | 2011-12-23 00:31:02 +0000 | [diff] [blame] | 1799 | if (ClassInterface && ClassInterface->hasDefinition()) |
| 1800 | ClassInterface = ClassInterface->getDefinition(); |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1801 | return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, |
| 1802 | nameLoc, atStartLoc, superLoc, |
| 1803 | IvarLBraceLoc, IvarRBraceLoc); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1806 | ObjCImplementationDecl * |
| 1807 | ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1808 | return new (C, ID) ObjCImplementationDecl(nullptr, nullptr, nullptr, |
| 1809 | SourceLocation(), SourceLocation()); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
John McCall | 0410e57 | 2011-07-22 04:15:06 +0000 | [diff] [blame] | 1812 | void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, |
| 1813 | CXXCtorInitializer ** initializers, |
| 1814 | unsigned numInitializers) { |
| 1815 | if (numInitializers > 0) { |
| 1816 | NumIvarInitializers = numInitializers; |
| 1817 | CXXCtorInitializer **ivarInitializers = |
| 1818 | new (C) CXXCtorInitializer*[NumIvarInitializers]; |
| 1819 | memcpy(ivarInitializers, initializers, |
| 1820 | numInitializers * sizeof(CXXCtorInitializer*)); |
| 1821 | IvarInitializers = ivarInitializers; |
| 1822 | } |
| 1823 | } |
| 1824 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1825 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | 2f56992 | 2012-02-07 11:57:45 +0000 | [diff] [blame] | 1826 | const ObjCImplementationDecl &ID) { |
| 1827 | OS << ID.getName(); |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1828 | return OS; |
| 1829 | } |
| 1830 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1831 | //===----------------------------------------------------------------------===// |
| 1832 | // ObjCCompatibleAliasDecl |
| 1833 | //===----------------------------------------------------------------------===// |
| 1834 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1835 | void ObjCCompatibleAliasDecl::anchor() { } |
| 1836 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1837 | ObjCCompatibleAliasDecl * |
| 1838 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 1839 | SourceLocation L, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | IdentifierInfo *Id, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1841 | ObjCInterfaceDecl* AliasedClass) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1842 | return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1845 | ObjCCompatibleAliasDecl * |
| 1846 | ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1847 | return new (C, ID) ObjCCompatibleAliasDecl(nullptr, SourceLocation(), |
| 1848 | nullptr, nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1851 | //===----------------------------------------------------------------------===// |
| 1852 | // ObjCPropertyDecl |
| 1853 | //===----------------------------------------------------------------------===// |
| 1854 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1855 | void ObjCPropertyDecl::anchor() { } |
| 1856 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1857 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 1858 | SourceLocation L, |
| 1859 | IdentifierInfo *Id, |
Fariborz Jahanian | da8ec2b | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1860 | SourceLocation AtLoc, |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 1861 | SourceLocation LParenLoc, |
John McCall | 339bb66 | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1862 | TypeSourceInfo *T, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1863 | PropertyControl propControl) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1864 | return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1867 | ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1868 | unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1869 | return new (C, ID) ObjCPropertyDecl(nullptr, SourceLocation(), nullptr, |
| 1870 | SourceLocation(), SourceLocation(), |
| 1871 | nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1874 | //===----------------------------------------------------------------------===// |
| 1875 | // ObjCPropertyImplDecl |
| 1876 | //===----------------------------------------------------------------------===// |
| 1877 | |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1878 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | c25d7a7 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 1879 | DeclContext *DC, |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1880 | SourceLocation atLoc, |
| 1881 | SourceLocation L, |
| 1882 | ObjCPropertyDecl *property, |
Daniel Dunbar | 3b4fdb0 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 1883 | Kind PK, |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1884 | ObjCIvarDecl *ivar, |
| 1885 | SourceLocation ivarLoc) { |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1886 | return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, |
| 1887 | ivarLoc); |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1888 | } |
Chris Lattner | ed0e164 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 1889 | |
Richard Smith | f798172 | 2013-11-22 09:01:48 +0000 | [diff] [blame] | 1890 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1891 | unsigned ID) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1892 | return new (C, ID) ObjCPropertyImplDecl(nullptr, SourceLocation(), |
| 1893 | SourceLocation(), nullptr, Dynamic, |
| 1894 | nullptr, SourceLocation()); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1897 | SourceRange ObjCPropertyImplDecl::getSourceRange() const { |
| 1898 | SourceLocation EndLoc = getLocation(); |
| 1899 | if (IvarLoc.isValid()) |
| 1900 | EndLoc = IvarLoc; |
Chris Lattner | c5ffed4 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1901 | |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1902 | return SourceRange(AtLoc, EndLoc); |
| 1903 | } |