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