Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 1 | //===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C related Decl classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclObjC.h" |
| 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/Stmt.h" |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 21 | //===----------------------------------------------------------------------===// |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 22 | // ObjCListBase |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 25 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
Douglas Gregor | ff331c1 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 26 | List = 0; |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 27 | if (Elts == 0) return; // Setting to an empty list is a noop. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 28 | |
| 29 | |
Chris Lattner | 4ee413b | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 30 | List = new (Ctx) void*[Elts]; |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 31 | NumElts = Elts; |
| 32 | memcpy(List, InList, sizeof(void*)*Elts); |
| 33 | } |
| 34 | |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 35 | void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, |
| 36 | const SourceLocation *Locs, ASTContext &Ctx) { |
| 37 | if (Elts == 0) |
| 38 | return; |
| 39 | |
| 40 | Locations = new (Ctx) SourceLocation[Elts]; |
| 41 | memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); |
| 42 | set(InList, Elts, Ctx); |
| 43 | } |
| 44 | |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 46 | // ObjCInterfaceDecl |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 47 | //===----------------------------------------------------------------------===// |
| 48 | |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 49 | /// getIvarDecl - This method looks up an ivar in this ContextDecl. |
| 50 | /// |
| 51 | ObjCIvarDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 52 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 53 | lookup_const_iterator Ivar, IvarEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 54 | for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 55 | if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 56 | return ivar; |
| 57 | } |
| 58 | return 0; |
| 59 | } |
| 60 | |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 61 | // Get the local instance/class method declared in this interface. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 62 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 63 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 64 | // Since instance & class methods can have the same name, the loop below |
| 65 | // ensures we get the correct method. |
| 66 | // |
| 67 | // @interface Whatever |
| 68 | // - (int) class_method; |
| 69 | // + (float) class_method; |
| 70 | // @end |
| 71 | // |
| 72 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 73 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 74 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 75 | if (MD && MD->isInstanceMethod() == isInstance) |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 76 | return MD; |
| 77 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 81 | ObjCPropertyDecl * |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 82 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 83 | IdentifierInfo *propertyID) { |
| 84 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 85 | DeclContext::lookup_const_iterator I, E; |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 86 | llvm::tie(I, E) = DC->lookup(propertyID); |
| 87 | for ( ; I != E; ++I) |
| 88 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) |
| 89 | return PD; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 94 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 95 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 96 | ObjCPropertyDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 97 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 99 | if (ObjCPropertyDecl *PD = |
| 100 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 101 | return PD; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 103 | switch (getKind()) { |
| 104 | default: |
| 105 | break; |
| 106 | case Decl::ObjCProtocol: { |
| 107 | const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); |
| 108 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 109 | E = PID->protocol_end(); I != E; ++I) |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 110 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 111 | return P; |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 112 | break; |
| 113 | } |
| 114 | case Decl::ObjCInterface: { |
| 115 | const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); |
| 116 | // Look through categories. |
| 117 | for (ObjCCategoryDecl *Cat = OID->getCategoryList(); |
| 118 | Cat; Cat = Cat->getNextClassCategory()) |
| 119 | if (!Cat->IsClassExtension()) |
| 120 | if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) |
| 121 | return P; |
| 122 | |
| 123 | // Look through protocols. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 124 | for (ObjCInterfaceDecl::all_protocol_iterator |
| 125 | I = OID->all_referenced_protocol_begin(), |
| 126 | E = OID->all_referenced_protocol_end(); I != E; ++I) |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 127 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 128 | return P; |
| 129 | |
| 130 | // Finally, check the super class. |
| 131 | if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) |
| 132 | return superClass->FindPropertyDeclaration(PropertyId); |
| 133 | break; |
| 134 | } |
| 135 | case Decl::ObjCCategory: { |
| 136 | const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); |
| 137 | // Look through protocols. |
| 138 | if (!OCD->IsClassExtension()) |
| 139 | for (ObjCCategoryDecl::protocol_iterator |
| 140 | I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I) |
| 141 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 142 | return P; |
| 143 | |
| 144 | break; |
Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 145 | } |
| 146 | } |
Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 150 | /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property |
| 151 | /// with name 'PropertyId' in the primary class; including those in protocols |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 152 | /// (direct or indirect) used by the primary class. |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 153 | /// |
| 154 | ObjCPropertyDecl * |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 155 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 156 | IdentifierInfo *PropertyId) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 157 | // FIXME: Should make sure no callers ever do this. |
| 158 | if (!hasDefinition()) |
| 159 | return 0; |
| 160 | |
| 161 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 162 | LoadExternalDefinition(); |
| 163 | |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 164 | if (ObjCPropertyDecl *PD = |
| 165 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 166 | return PD; |
| 167 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 168 | // Look through protocols. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 169 | for (ObjCInterfaceDecl::all_protocol_iterator |
| 170 | I = all_referenced_protocol_begin(), |
| 171 | E = all_referenced_protocol_end(); I != E; ++I) |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 172 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 173 | return P; |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 174 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 178 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 179 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
| 180 | ASTContext &C) |
| 181 | { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 182 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 183 | LoadExternalDefinition(); |
| 184 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 185 | if (data().AllReferencedProtocols.empty() && |
| 186 | data().ReferencedProtocols.empty()) { |
| 187 | data().AllReferencedProtocols.set(ExtList, ExtNum, C); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 188 | return; |
| 189 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 190 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 191 | // Check for duplicate protocol in class's protocol list. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 192 | // This is O(n*m). But it is extremely rare and number of protocols in |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 193 | // class or its extension are very few. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 194 | SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 195 | for (unsigned i = 0; i < ExtNum; i++) { |
| 196 | bool protocolExists = false; |
| 197 | ObjCProtocolDecl *ProtoInExtension = ExtList[i]; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 198 | for (all_protocol_iterator |
| 199 | p = all_referenced_protocol_begin(), |
| 200 | e = all_referenced_protocol_end(); p != e; ++p) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 201 | ObjCProtocolDecl *Proto = (*p); |
| 202 | if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { |
| 203 | protocolExists = true; |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | // Do we want to warn on a protocol in extension class which |
| 208 | // already exist in the class? Probably not. |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 209 | if (!protocolExists) |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 210 | ProtocolRefs.push_back(ProtoInExtension); |
| 211 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 212 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 213 | if (ProtocolRefs.empty()) |
| 214 | return; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 215 | |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 216 | // Merge ProtocolRefs into class's protocol list; |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 217 | for (all_protocol_iterator p = all_referenced_protocol_begin(), |
| 218 | e = all_referenced_protocol_end(); p != e; ++p) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 219 | ProtocolRefs.push_back(*p); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 220 | } |
Ted Kremenek | 53b9441 | 2010-09-01 01:21:15 +0000 | [diff] [blame] | 221 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 222 | data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 225 | void ObjCInterfaceDecl::allocateDefinitionData() { |
| 226 | assert(!hasDefinition() && "ObjC class already has a definition"); |
| 227 | Definition = new (getASTContext()) DefinitionData(); |
| 228 | } |
| 229 | |
| 230 | void ObjCInterfaceDecl::startDefinition() { |
| 231 | allocateDefinitionData(); |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 232 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) |
| 233 | L->CompletedObjCForwardRef(this); |
| 234 | } |
| 235 | |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 236 | /// getFirstClassExtension - Find first class extension of the given class. |
| 237 | ObjCCategoryDecl* ObjCInterfaceDecl::getFirstClassExtension() const { |
| 238 | for (ObjCCategoryDecl *CDecl = getCategoryList(); CDecl; |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 239 | CDecl = CDecl->getNextClassCategory()) |
| 240 | if (CDecl->IsClassExtension()) |
| 241 | return CDecl; |
| 242 | return 0; |
| 243 | } |
| 244 | |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 245 | /// getNextClassCategory - Find next class extension in list of categories. |
| 246 | const ObjCCategoryDecl* ObjCCategoryDecl::getNextClassExtension() const { |
| 247 | for (const ObjCCategoryDecl *CDecl = getNextClassCategory(); CDecl; |
| 248 | CDecl = CDecl->getNextClassCategory()) |
| 249 | if (CDecl->IsClassExtension()) |
| 250 | return CDecl; |
| 251 | return 0; |
| 252 | } |
| 253 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 254 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 255 | ObjCInterfaceDecl *&clsDeclared) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 256 | // FIXME: Should make sure no callers ever do this. |
| 257 | if (!hasDefinition()) |
| 258 | return 0; |
| 259 | |
| 260 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 261 | LoadExternalDefinition(); |
| 262 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 263 | ObjCInterfaceDecl* ClassDecl = this; |
| 264 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 265 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 266 | clsDeclared = ClassDecl; |
| 267 | return I; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 268 | } |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 269 | for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension(); |
| 270 | CDecl; CDecl = CDecl->getNextClassExtension()) { |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 271 | if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) { |
| 272 | clsDeclared = ClassDecl; |
| 273 | return I; |
| 274 | } |
Fariborz Jahanian | 80aa1cd | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 275 | } |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 277 | ClassDecl = ClassDecl->getSuperClass(); |
| 278 | } |
| 279 | return NULL; |
| 280 | } |
| 281 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 282 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 283 | /// class whose name is passed as argument. If it is not one of the super classes |
| 284 | /// the it returns NULL. |
| 285 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 286 | const IdentifierInfo*ICName) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 287 | // FIXME: Should make sure no callers ever do this. |
| 288 | if (!hasDefinition()) |
| 289 | return 0; |
| 290 | |
| 291 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 292 | LoadExternalDefinition(); |
| 293 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 294 | ObjCInterfaceDecl* ClassDecl = this; |
| 295 | while (ClassDecl != NULL) { |
| 296 | if (ClassDecl->getIdentifier() == ICName) |
| 297 | return ClassDecl; |
| 298 | ClassDecl = ClassDecl->getSuperClass(); |
| 299 | } |
| 300 | return NULL; |
| 301 | } |
| 302 | |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 303 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 304 | /// the class, its categories, and its super classes (using a linear search). |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 305 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 306 | bool isInstance) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 307 | // FIXME: Should make sure no callers ever do this. |
| 308 | if (!hasDefinition()) |
| 309 | return 0; |
| 310 | |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 311 | const ObjCInterfaceDecl* ClassDecl = this; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 312 | ObjCMethodDecl *MethodDecl = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 314 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 315 | LoadExternalDefinition(); |
| 316 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 317 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 318 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 319 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 321 | // Didn't find one yet - look through protocols. |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 322 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 323 | ClassDecl->getReferencedProtocols(); |
| 324 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 325 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 326 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 327 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 328 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 329 | // Didn't find one yet - now look through categories. |
| 330 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 331 | while (CatDecl) { |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 332 | if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 333 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | |
Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 335 | // Didn't find one yet - look through protocols. |
| 336 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 337 | CatDecl->getReferencedProtocols(); |
| 338 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 339 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 340 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Steve Naroff | b558422 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 341 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 342 | CatDecl = CatDecl->getNextClassCategory(); |
| 343 | } |
| 344 | ClassDecl = ClassDecl->getSuperClass(); |
| 345 | } |
| 346 | return NULL; |
| 347 | } |
| 348 | |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 349 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( |
| 350 | const Selector &Sel, |
| 351 | bool Instance) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 352 | // FIXME: Should make sure no callers ever do this. |
| 353 | if (!hasDefinition()) |
| 354 | return 0; |
| 355 | |
| 356 | if (data().ExternallyCompleted) |
Argyrios Kyrtzidis | 7c81c2a | 2011-10-19 02:25:16 +0000 | [diff] [blame] | 357 | LoadExternalDefinition(); |
| 358 | |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 359 | ObjCMethodDecl *Method = 0; |
| 360 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 361 | Method = Instance ? ImpDecl->getInstanceMethod(Sel) |
| 362 | : ImpDecl->getClassMethod(Sel); |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 363 | |
| 364 | if (!Method && getSuperClass()) |
Fariborz Jahanian | 74b2756 | 2010-12-03 23:37:08 +0000 | [diff] [blame] | 365 | return getSuperClass()->lookupPrivateMethod(Sel, Instance); |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 366 | return Method; |
| 367 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 368 | |
| 369 | //===----------------------------------------------------------------------===// |
| 370 | // ObjCMethodDecl |
| 371 | //===----------------------------------------------------------------------===// |
| 372 | |
| 373 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | SourceLocation beginLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 375 | SourceLocation endLoc, |
| 376 | Selector SelInfo, QualType T, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 377 | TypeSourceInfo *ResultTInfo, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 378 | DeclContext *contextDecl, |
| 379 | bool isInstance, |
| 380 | bool isVariadic, |
| 381 | bool isSynthesized, |
Argyrios Kyrtzidis | 75cf3e8 | 2011-08-17 19:25:08 +0000 | [diff] [blame] | 382 | bool isImplicitlyDeclared, |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 383 | bool isDefined, |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 384 | ImplementationControl impControl, |
Argyrios Kyrtzidis | da92a7f | 2011-10-03 06:36:29 +0000 | [diff] [blame] | 385 | bool HasRelatedResultType) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 386 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 387 | SelInfo, T, ResultTInfo, contextDecl, |
| 388 | isInstance, |
Argyrios Kyrtzidis | 75cf3e8 | 2011-08-17 19:25:08 +0000 | [diff] [blame] | 389 | isVariadic, isSynthesized, isImplicitlyDeclared, |
| 390 | isDefined, |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 391 | impControl, |
Argyrios Kyrtzidis | da92a7f | 2011-10-03 06:36:29 +0000 | [diff] [blame] | 392 | HasRelatedResultType); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 395 | void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { |
| 396 | assert(PrevMethod); |
| 397 | getASTContext().setObjCMethodRedeclaration(PrevMethod, this); |
| 398 | IsRedeclaration = true; |
Argyrios Kyrtzidis | 72b2625 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 399 | PrevMethod->HasRedeclaration = true; |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Argyrios Kyrtzidis | 491306a | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 402 | void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, |
| 403 | ArrayRef<ParmVarDecl*> Params, |
| 404 | ArrayRef<SourceLocation> SelLocs) { |
| 405 | ParamsAndSelLocs = 0; |
| 406 | NumParams = Params.size(); |
| 407 | if (Params.empty() && SelLocs.empty()) |
| 408 | return; |
| 409 | |
| 410 | unsigned Size = sizeof(ParmVarDecl *) * NumParams + |
| 411 | sizeof(SourceLocation) * SelLocs.size(); |
| 412 | ParamsAndSelLocs = C.Allocate(Size); |
| 413 | std::copy(Params.begin(), Params.end(), getParams()); |
| 414 | std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); |
| 415 | } |
| 416 | |
| 417 | void ObjCMethodDecl::getSelectorLocs( |
| 418 | SmallVectorImpl<SourceLocation> &SelLocs) const { |
| 419 | for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) |
| 420 | SelLocs.push_back(getSelectorLoc(i)); |
| 421 | } |
| 422 | |
| 423 | void ObjCMethodDecl::setMethodParams(ASTContext &C, |
| 424 | ArrayRef<ParmVarDecl*> Params, |
| 425 | ArrayRef<SourceLocation> SelLocs) { |
| 426 | assert((!SelLocs.empty() || isImplicit()) && |
| 427 | "No selector locs for non-implicit method"); |
| 428 | if (isImplicit()) |
| 429 | return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); |
| 430 | |
| 431 | SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc); |
| 432 | if (SelLocsKind != SelLoc_NonStandard) |
| 433 | return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); |
| 434 | |
| 435 | setParamsAndSelLocs(C, Params, SelLocs); |
| 436 | } |
| 437 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 438 | /// \brief A definition will return its interface declaration. |
| 439 | /// An interface declaration will return its definition. |
| 440 | /// Otherwise it will return itself. |
| 441 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { |
| 442 | ASTContext &Ctx = getASTContext(); |
Argyrios Kyrtzidis | 72b2625 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 443 | ObjCMethodDecl *Redecl = 0; |
| 444 | if (HasRedeclaration) |
| 445 | Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); |
Argyrios Kyrtzidis | b40034c | 2011-10-14 06:48:06 +0000 | [diff] [blame] | 446 | if (Redecl) |
| 447 | return Redecl; |
| 448 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 449 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 450 | |
| 451 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 452 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 453 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 454 | |
| 455 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 456 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 457 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 458 | |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 459 | } else if (ObjCImplementationDecl *ImplD = |
| 460 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 461 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 462 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 463 | |
| 464 | } else if (ObjCCategoryImplDecl *CImplD = |
| 465 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 466 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 467 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Argyrios Kyrtzidis | 3a919e7 | 2011-10-14 08:02:31 +0000 | [diff] [blame] | 470 | if (!Redecl && isRedeclaration()) { |
| 471 | // This is the last redeclaration, go back to the first method. |
| 472 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 473 | isInstanceMethod()); |
| 474 | } |
| 475 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 476 | return Redecl ? Redecl : this; |
| 477 | } |
| 478 | |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 479 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 480 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 481 | |
| 482 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 483 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 484 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 485 | isInstanceMethod())) |
| 486 | return MD; |
| 487 | |
| 488 | } else if (ObjCCategoryImplDecl *CImplD = |
| 489 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 490 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 491 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 492 | isInstanceMethod())) |
| 493 | return MD; |
| 494 | } |
| 495 | |
Argyrios Kyrtzidis | 6d4740e | 2011-10-17 19:48:09 +0000 | [diff] [blame] | 496 | if (isRedeclaration()) |
| 497 | return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), |
| 498 | isInstanceMethod()); |
| 499 | |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 500 | return this; |
| 501 | } |
| 502 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 503 | ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { |
| 504 | ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family); |
John McCall | d976c8e | 2011-03-02 21:01:41 +0000 | [diff] [blame] | 505 | if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 506 | return family; |
| 507 | |
John McCall | d5313b0 | 2011-03-02 11:33:24 +0000 | [diff] [blame] | 508 | // Check for an explicit attribute. |
| 509 | if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { |
| 510 | // The unfortunate necessity of mapping between enums here is due |
| 511 | // to the attributes framework. |
| 512 | switch (attr->getFamily()) { |
| 513 | case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; |
| 514 | case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; |
| 515 | case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; |
| 516 | case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; |
| 517 | case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; |
| 518 | case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; |
| 519 | } |
| 520 | Family = static_cast<unsigned>(family); |
| 521 | return family; |
| 522 | } |
| 523 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 524 | family = getSelector().getMethodFamily(); |
| 525 | switch (family) { |
| 526 | case OMF_None: break; |
| 527 | |
| 528 | // init only has a conventional meaning for an instance method, and |
| 529 | // it has to return an object. |
| 530 | case OMF_init: |
| 531 | if (!isInstanceMethod() || !getResultType()->isObjCObjectPointerType()) |
| 532 | family = OMF_None; |
| 533 | break; |
| 534 | |
| 535 | // alloc/copy/new have a conventional meaning for both class and |
| 536 | // instance methods, but they require an object return. |
| 537 | case OMF_alloc: |
| 538 | case OMF_copy: |
| 539 | case OMF_mutableCopy: |
| 540 | case OMF_new: |
| 541 | if (!getResultType()->isObjCObjectPointerType()) |
| 542 | family = OMF_None; |
| 543 | break; |
| 544 | |
| 545 | // These selectors have a conventional meaning only for instance methods. |
| 546 | case OMF_dealloc: |
Nico Weber | 80cb6e6 | 2011-08-28 22:35:17 +0000 | [diff] [blame] | 547 | case OMF_finalize: |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 548 | case OMF_retain: |
| 549 | case OMF_release: |
| 550 | case OMF_autorelease: |
| 551 | case OMF_retainCount: |
Douglas Gregor | 926df6c | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 552 | case OMF_self: |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 553 | if (!isInstanceMethod()) |
| 554 | family = OMF_None; |
| 555 | break; |
Fariborz Jahanian | 9670e17 | 2011-07-05 22:38:59 +0000 | [diff] [blame] | 556 | |
| 557 | case OMF_performSelector: |
| 558 | if (!isInstanceMethod() || |
| 559 | !getResultType()->isObjCIdType()) |
| 560 | family = OMF_None; |
| 561 | else { |
| 562 | unsigned noParams = param_size(); |
| 563 | if (noParams < 1 || noParams > 3) |
| 564 | family = OMF_None; |
| 565 | else { |
| 566 | ObjCMethodDecl::arg_type_iterator it = arg_type_begin(); |
| 567 | QualType ArgT = (*it); |
| 568 | if (!ArgT->isObjCSelType()) { |
| 569 | family = OMF_None; |
| 570 | break; |
| 571 | } |
| 572 | while (--noParams) { |
| 573 | it++; |
| 574 | ArgT = (*it); |
| 575 | if (!ArgT->isObjCIdType()) { |
| 576 | family = OMF_None; |
| 577 | break; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | break; |
| 583 | |
John McCall | 85f3d76 | 2011-03-02 01:50:55 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | // Cache the result. |
| 587 | Family = static_cast<unsigned>(family); |
| 588 | return family; |
| 589 | } |
| 590 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 592 | const ObjCInterfaceDecl *OID) { |
| 593 | QualType selfTy; |
| 594 | if (isInstanceMethod()) { |
| 595 | // There may be no interface context due to error in declaration |
| 596 | // of the interface (which has been reported). Recover gracefully. |
| 597 | if (OID) { |
Daniel Dunbar | 3b3a458 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 598 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 599 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 600 | } else { |
| 601 | selfTy = Context.getObjCIdType(); |
| 602 | } |
| 603 | } else // we have a factory method. |
| 604 | selfTy = Context.getObjCClassType(); |
| 605 | |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 606 | bool selfIsPseudoStrong = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 607 | bool selfIsConsumed = false; |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 608 | |
| 609 | if (Context.getLangOptions().ObjCAutoRefCount) { |
| 610 | if (isInstanceMethod()) { |
| 611 | selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 612 | |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 613 | // 'self' is always __strong. It's actually pseudo-strong except |
| 614 | // in init methods (or methods labeled ns_consumes_self), though. |
| 615 | Qualifiers qs; |
| 616 | qs.setObjCLifetime(Qualifiers::OCL_Strong); |
| 617 | selfTy = Context.getQualifiedType(selfTy, qs); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 618 | |
Ted Kremenek | 2bbcd5c | 2011-11-14 21:59:25 +0000 | [diff] [blame] | 619 | // In addition, 'self' is const unless this is an init method. |
| 620 | if (getMethodFamily() != OMF_init && !selfIsConsumed) { |
| 621 | selfTy = selfTy.withConst(); |
| 622 | selfIsPseudoStrong = true; |
| 623 | } |
| 624 | } |
| 625 | else { |
| 626 | assert(isClassMethod()); |
| 627 | // 'self' is always const in class methods. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 628 | selfTy = selfTy.withConst(); |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 629 | selfIsPseudoStrong = true; |
| 630 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | ImplicitParamDecl *self |
| 634 | = ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 635 | &Context.Idents.get("self"), selfTy); |
| 636 | setSelfDecl(self); |
| 637 | |
| 638 | if (selfIsConsumed) |
| 639 | self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context)); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 640 | |
John McCall | 7acddac | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 641 | if (selfIsPseudoStrong) |
| 642 | self->setARCPseudoStrong(true); |
| 643 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 645 | &Context.Idents.get("_cmd"), |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 646 | Context.getObjCSelType())); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 649 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 650 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 651 | return ID; |
| 652 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 653 | return CD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 654 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 655 | return IMD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 656 | |
| 657 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 658 | llvm_unreachable("unknown method context"); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 661 | //===----------------------------------------------------------------------===// |
| 662 | // ObjCInterfaceDecl |
| 663 | //===----------------------------------------------------------------------===// |
| 664 | |
| 665 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
| 666 | DeclContext *DC, |
| 667 | SourceLocation atLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | IdentifierInfo *Id, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 669 | SourceLocation ClassLoc, |
| 670 | bool ForwardDecl, bool isInternal){ |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 671 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
| 672 | isInternal); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | ObjCInterfaceDecl:: |
| 676 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
Douglas Gregor | deacbdc | 2010-08-11 12:19:30 +0000 | [diff] [blame] | 677 | SourceLocation CLoc, bool FD, bool isInternal) |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 678 | : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc), |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 679 | TypeForDecl(0), Definition(), InitiallyForwardDecl(FD) |
| 680 | { |
Argyrios Kyrtzidis | 40f57ee | 2011-11-15 06:20:21 +0000 | [diff] [blame] | 681 | setImplicit(isInternal); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 684 | void ObjCInterfaceDecl::LoadExternalDefinition() const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 685 | assert(data().ExternallyCompleted && "Class is not externally completed"); |
| 686 | data().ExternallyCompleted = false; |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 687 | getASTContext().getExternalSource()->CompleteType( |
| 688 | const_cast<ObjCInterfaceDecl *>(this)); |
| 689 | } |
| 690 | |
| 691 | void ObjCInterfaceDecl::setExternallyCompleted() { |
| 692 | assert(getASTContext().getExternalSource() && |
| 693 | "Class can't be externally completed without an external source"); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 694 | assert(hasDefinition() && |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 695 | "Forward declarations can't be externally completed"); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 696 | data().ExternallyCompleted = true; |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 699 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 700 | // FIXME: Should make sure no callers ever do this. |
| 701 | if (!hasDefinition()) |
| 702 | return 0; |
| 703 | |
| 704 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 705 | LoadExternalDefinition(); |
| 706 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 707 | return getASTContext().getObjCImplementation( |
| 708 | const_cast<ObjCInterfaceDecl*>(this)); |
| 709 | } |
| 710 | |
| 711 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 712 | getASTContext().setObjCImplementation(this, ImplD); |
| 713 | } |
| 714 | |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 715 | /// all_declared_ivar_begin - return first ivar declared in this class, |
| 716 | /// its extensions and its implementation. Lazily build the list on first |
| 717 | /// access. |
| 718 | ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 719 | // FIXME: Should make sure no callers ever do this. |
| 720 | if (!hasDefinition()) |
| 721 | return 0; |
| 722 | |
| 723 | if (data().IvarList) |
| 724 | return data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 725 | |
| 726 | ObjCIvarDecl *curIvar = 0; |
| 727 | if (!ivar_empty()) { |
| 728 | ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 729 | data().IvarList = (*I); ++I; |
| 730 | for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 731 | curIvar->setNextIvar(*I); |
| 732 | } |
| 733 | |
| 734 | for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl; |
| 735 | CDecl = CDecl->getNextClassExtension()) { |
| 736 | if (!CDecl->ivar_empty()) { |
| 737 | ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(), |
| 738 | E = CDecl->ivar_end(); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 739 | if (!data().IvarList) { |
| 740 | data().IvarList = (*I); ++I; |
| 741 | curIvar = data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 742 | } |
| 743 | for ( ;I != E; curIvar = *I, ++I) |
| 744 | curIvar->setNextIvar(*I); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | if (ObjCImplementationDecl *ImplDecl = getImplementation()) { |
| 749 | if (!ImplDecl->ivar_empty()) { |
| 750 | ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(), |
| 751 | E = ImplDecl->ivar_end(); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 752 | if (!data().IvarList) { |
| 753 | data().IvarList = (*I); ++I; |
| 754 | curIvar = data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 755 | } |
| 756 | for ( ;I != E; curIvar = *I, ++I) |
| 757 | curIvar->setNextIvar(*I); |
| 758 | } |
| 759 | } |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 760 | return data().IvarList; |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 761 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 762 | |
| 763 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 764 | /// categories for this class and returns it. Name of the category is passed |
| 765 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 766 | /// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 767 | ObjCCategoryDecl * |
| 768 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 769 | if (data().ExternallyCompleted) |
Douglas Gregor | 26ac3f3 | 2010-12-01 23:49:52 +0000 | [diff] [blame] | 770 | LoadExternalDefinition(); |
| 771 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 772 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 773 | Category; Category = Category->getNextClassCategory()) |
| 774 | if (Category->getIdentifier() == CategoryId) |
| 775 | return Category; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 779 | ObjCMethodDecl * |
| 780 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 781 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 782 | Category; Category = Category->getNextClassCategory()) |
| 783 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 784 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 785 | return MD; |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 790 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 791 | Category; Category = Category->getNextClassCategory()) |
| 792 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 793 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 794 | return MD; |
| 795 | return 0; |
| 796 | } |
| 797 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 798 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 799 | /// has been implemented in IDecl class, its super class or categories (if |
| 800 | /// lookupCategory is true). |
| 801 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 802 | bool lookupCategory, |
| 803 | bool RHSIsQualifiedID) { |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 804 | if (!hasDefinition()) |
| 805 | return false; |
| 806 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 807 | ObjCInterfaceDecl *IDecl = this; |
| 808 | // 1st, look up the class. |
| 809 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 810 | IDecl->getReferencedProtocols(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 812 | for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(), |
| 813 | E = Protocols.end(); PI != E; ++PI) { |
| 814 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 815 | return true; |
| 816 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 817 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 818 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 819 | // object. This IMO, should be a bug. |
| 820 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 821 | // extensions are not enabled. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | if (RHSIsQualifiedID && |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 823 | getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) |
| 824 | return true; |
| 825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 827 | // 2nd, look up the category. |
| 828 | if (lookupCategory) |
| 829 | for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; |
| 830 | CDecl = CDecl->getNextClassCategory()) { |
| 831 | for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), |
| 832 | E = CDecl->protocol_end(); PI != E; ++PI) |
| 833 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 834 | return true; |
| 835 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 836 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 837 | // 3rd, look up the super class(s) |
| 838 | if (IDecl->getSuperClass()) |
| 839 | return |
| 840 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 841 | RHSIsQualifiedID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 843 | return false; |
| 844 | } |
| 845 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 846 | //===----------------------------------------------------------------------===// |
| 847 | // ObjCIvarDecl |
| 848 | //===----------------------------------------------------------------------===// |
| 849 | |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 850 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 851 | SourceLocation StartLoc, |
| 852 | SourceLocation IdLoc, IdentifierInfo *Id, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 853 | QualType T, TypeSourceInfo *TInfo, |
Fariborz Jahanian | ad51e74 | 2010-07-17 00:59:30 +0000 | [diff] [blame] | 854 | AccessControl ac, Expr *BW, |
| 855 | bool synthesized) { |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 856 | if (DC) { |
| 857 | // Ivar's can only appear in interfaces, implementations (via synthesized |
| 858 | // properties), and class extensions (via direct declaration, or synthesized |
| 859 | // properties). |
| 860 | // |
| 861 | // FIXME: This should really be asserting this: |
| 862 | // (isa<ObjCCategoryDecl>(DC) && |
| 863 | // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) |
| 864 | // but unfortunately we sometimes place ivars into non-class extension |
| 865 | // categories on error. This breaks an AST invariant, and should not be |
| 866 | // fixed. |
| 867 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 868 | isa<ObjCCategoryDecl>(DC)) && |
| 869 | "Invalid ivar decl context!"); |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 870 | // Once a new ivar is created in any of class/class-extension/implementation |
| 871 | // decl contexts, the previously built IvarList must be rebuilt. |
| 872 | ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC); |
| 873 | if (!ID) { |
Fariborz Jahanian | 000835d | 2010-08-23 18:51:39 +0000 | [diff] [blame] | 874 | if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) { |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 875 | ID = IM->getClassInterface(); |
Fariborz Jahanian | 000835d | 2010-08-23 18:51:39 +0000 | [diff] [blame] | 876 | if (BW) |
| 877 | IM->setHasSynthBitfield(true); |
Chad Rosier | 3060178 | 2011-08-17 23:08:45 +0000 | [diff] [blame] | 878 | } else { |
Fariborz Jahanian | 000835d | 2010-08-23 18:51:39 +0000 | [diff] [blame] | 879 | ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 880 | ID = CD->getClassInterface(); |
| 881 | if (BW) |
| 882 | CD->setHasSynthBitfield(true); |
| 883 | } |
Fariborz Jahanian | 2c18bb7 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 884 | } |
| 885 | ID->setIvarList(0); |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 888 | return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, |
| 889 | ac, BW, synthesized); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 892 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 893 | const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 894 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 895 | switch (DC->getKind()) { |
| 896 | default: |
| 897 | case ObjCCategoryImpl: |
| 898 | case ObjCProtocol: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 899 | llvm_unreachable("invalid ivar container!"); |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 900 | |
| 901 | // Ivars can only appear in class extension categories. |
| 902 | case ObjCCategory: { |
| 903 | const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 904 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 905 | return CD->getClassInterface(); |
| 906 | } |
| 907 | |
| 908 | case ObjCImplementation: |
| 909 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 910 | |
| 911 | case ObjCInterface: |
| 912 | return cast<ObjCInterfaceDecl>(DC); |
| 913 | } |
| 914 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 915 | |
| 916 | //===----------------------------------------------------------------------===// |
| 917 | // ObjCAtDefsFieldDecl |
| 918 | //===----------------------------------------------------------------------===// |
| 919 | |
| 920 | ObjCAtDefsFieldDecl |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 921 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, |
| 922 | SourceLocation StartLoc, SourceLocation IdLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 923 | IdentifierInfo *Id, QualType T, Expr *BW) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 924 | return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 927 | //===----------------------------------------------------------------------===// |
| 928 | // ObjCProtocolDecl |
| 929 | //===----------------------------------------------------------------------===// |
| 930 | |
| 931 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 932 | IdentifierInfo *Id, |
| 933 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | b05d7b2 | 2011-10-17 19:48:06 +0000 | [diff] [blame] | 934 | SourceLocation atStartLoc, |
| 935 | bool isForwardDecl) { |
| 936 | return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 939 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 940 | ObjCProtocolDecl *PDecl = this; |
| 941 | |
| 942 | if (Name == getIdentifier()) |
| 943 | return PDecl; |
| 944 | |
| 945 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 946 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 947 | return PDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 949 | return NULL; |
| 950 | } |
| 951 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 952 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 953 | // it inherited. |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 954 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 955 | bool isInstance) const { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 956 | ObjCMethodDecl *MethodDecl = NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 957 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 958 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 959 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 961 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 962 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 963 | return MethodDecl; |
| 964 | return NULL; |
| 965 | } |
| 966 | |
Argyrios Kyrtzidis | ad834d5 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 967 | void ObjCProtocolDecl::completedForwardDecl() { |
| 968 | assert(isForwardDecl() && "Only valid to call for forward refs"); |
| 969 | isForwardProtoDecl = false; |
| 970 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) |
| 971 | L->CompletedObjCForwardRef(this); |
| 972 | } |
| 973 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 974 | //===----------------------------------------------------------------------===// |
| 975 | // ObjCClassDecl |
| 976 | //===----------------------------------------------------------------------===// |
| 977 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
Douglas Gregor | af76472 | 2011-12-14 17:12:03 +0000 | [diff] [blame] | 979 | ObjCInterfaceDecl *Interface, |
| 980 | SourceLocation InterfaceLoc) |
| 981 | : Decl(ObjCClass, DC, L), Interface(Interface), InterfaceLoc(InterfaceLoc) |
| 982 | { |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 983 | } |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 984 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 985 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 986 | SourceLocation L, |
Douglas Gregor | af76472 | 2011-12-14 17:12:03 +0000 | [diff] [blame] | 987 | ObjCInterfaceDecl *Interface, |
| 988 | SourceLocation InterfaceLoc) { |
| 989 | return new (C) ObjCClassDecl(DC, L, Interface, InterfaceLoc); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Ted Kremenek | 2dbdd62 | 2009-11-18 01:26:56 +0000 | [diff] [blame] | 992 | SourceRange ObjCClassDecl::getSourceRange() const { |
Douglas Gregor | af76472 | 2011-12-14 17:12:03 +0000 | [diff] [blame] | 993 | return SourceRange(getLocation(), InterfaceLoc); |
Ted Kremenek | 2dbdd62 | 2009-11-18 01:26:56 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 996 | //===----------------------------------------------------------------------===// |
| 997 | // ObjCForwardProtocolDecl |
| 998 | //===----------------------------------------------------------------------===// |
| 999 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 1000 | ObjCForwardProtocolDecl:: |
| 1001 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 1002 | ObjCProtocolDecl *const *Elts, unsigned nElts, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1003 | const SourceLocation *Locs, ASTContext &C) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | : Decl(ObjCForwardProtocol, DC, L) { |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1005 | ReferencedProtocols.set(Elts, nElts, Locs, C); |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1009 | ObjCForwardProtocolDecl * |
| 1010 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | SourceLocation L, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1012 | ObjCProtocolDecl *const *Elts, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1013 | unsigned NumElts, |
| 1014 | const SourceLocation *Locs) { |
| 1015 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1018 | //===----------------------------------------------------------------------===// |
| 1019 | // ObjCCategoryDecl |
| 1020 | //===----------------------------------------------------------------------===// |
| 1021 | |
| 1022 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 1023 | SourceLocation AtLoc, |
| 1024 | SourceLocation ClassNameLoc, |
| 1025 | SourceLocation CategoryNameLoc, |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1026 | IdentifierInfo *Id, |
| 1027 | ObjCInterfaceDecl *IDecl) { |
| 1028 | ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, |
| 1029 | CategoryNameLoc, Id, |
| 1030 | IDecl); |
| 1031 | if (IDecl) { |
| 1032 | // Link this category into its class's category list. |
| 1033 | CatDecl->NextClassCategory = IDecl->getCategoryList(); |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame^] | 1034 | if (IDecl->hasDefinition()) { |
| 1035 | IDecl->setCategoryList(CatDecl); |
| 1036 | if (ASTMutationListener *L = C.getASTMutationListener()) |
| 1037 | L->AddedObjCCategoryToInterface(CatDecl, IDecl); |
| 1038 | } |
Argyrios Kyrtzidis | 955fadb | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | return CatDecl; |
| 1042 | } |
| 1043 | |
| 1044 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, EmptyShell Empty) { |
| 1045 | return new (C) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), |
| 1046 | SourceLocation(), 0, 0); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1049 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 1050 | return getASTContext().getObjCImplementation( |
| 1051 | const_cast<ObjCCategoryDecl*>(this)); |
| 1052 | } |
| 1053 | |
| 1054 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 1055 | getASTContext().setObjCImplementation(this, ImplD); |
| 1056 | } |
| 1057 | |
| 1058 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1059 | //===----------------------------------------------------------------------===// |
| 1060 | // ObjCCategoryImplDecl |
| 1061 | //===----------------------------------------------------------------------===// |
| 1062 | |
| 1063 | ObjCCategoryImplDecl * |
| 1064 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1065 | IdentifierInfo *Id, |
| 1066 | ObjCInterfaceDecl *ClassInterface, |
| 1067 | SourceLocation nameLoc, |
Argyrios Kyrtzidis | c699400 | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 1068 | SourceLocation atStartLoc, |
| 1069 | SourceLocation CategoryNameLoc) { |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1070 | return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface, |
Argyrios Kyrtzidis | c699400 | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 1071 | nameLoc, atStartLoc, CategoryNameLoc); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 1074 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 1075 | // The class interface might be NULL if we are working with invalid code. |
| 1076 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 1077 | return ID->FindCategoryDeclaration(getIdentifier()); |
| 1078 | return 0; |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1081 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1082 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 1083 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1084 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1085 | addDecl(property); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1088 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 1089 | ASTContext &Ctx = getASTContext(); |
| 1090 | |
| 1091 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1092 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1093 | if (IFace) |
| 1094 | Ctx.setObjCImplementation(IFace, ImplD); |
| 1095 | |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 1096 | } else if (ObjCCategoryImplDecl *ImplD = |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 1097 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 1098 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 1099 | Ctx.setObjCImplementation(CD, ImplD); |
| 1100 | } |
| 1101 | |
| 1102 | ClassInterface = IFace; |
| 1103 | } |
| 1104 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1105 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | d6eed1c | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 1106 | /// properties implemented in this category @implementation block and returns |
| 1107 | /// the implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1108 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1109 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1110 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 1111 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1112 | ObjCPropertyImplDecl *PID = *i; |
| 1113 | if (PID->getPropertyIvarDecl() && |
| 1114 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 1115 | return PID; |
| 1116 | } |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 1121 | /// added to the list of those properties @synthesized/@dynamic in this |
| 1122 | /// category @implementation block. |
| 1123 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 1124 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1125 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 1126 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1127 | ObjCPropertyImplDecl *PID = *i; |
| 1128 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 1129 | return PID; |
| 1130 | } |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1134 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1135 | const ObjCCategoryImplDecl *CID) { |
| 1136 | OS << CID->getName(); |
| 1137 | return OS; |
| 1138 | } |
| 1139 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1140 | //===----------------------------------------------------------------------===// |
| 1141 | // ObjCImplementationDecl |
| 1142 | //===----------------------------------------------------------------------===// |
| 1143 | |
| 1144 | ObjCImplementationDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1146 | ObjCInterfaceDecl *ClassInterface, |
Argyrios Kyrtzidis | 1711fc9 | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 1147 | ObjCInterfaceDecl *SuperDecl, |
| 1148 | SourceLocation nameLoc, |
| 1149 | SourceLocation atStartLoc) { |
| 1150 | return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, |
| 1151 | nameLoc, atStartLoc); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
John McCall | da6d976 | 2011-07-22 04:15:06 +0000 | [diff] [blame] | 1154 | void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, |
| 1155 | CXXCtorInitializer ** initializers, |
| 1156 | unsigned numInitializers) { |
| 1157 | if (numInitializers > 0) { |
| 1158 | NumIvarInitializers = numInitializers; |
| 1159 | CXXCtorInitializer **ivarInitializers = |
| 1160 | new (C) CXXCtorInitializer*[NumIvarInitializers]; |
| 1161 | memcpy(ivarInitializers, initializers, |
| 1162 | numInitializers * sizeof(CXXCtorInitializer*)); |
| 1163 | IvarInitializers = ivarInitializers; |
| 1164 | } |
| 1165 | } |
| 1166 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1167 | raw_ostream &clang::operator<<(raw_ostream &OS, |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1168 | const ObjCImplementationDecl *ID) { |
| 1169 | OS << ID->getName(); |
| 1170 | return OS; |
| 1171 | } |
| 1172 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1173 | //===----------------------------------------------------------------------===// |
| 1174 | // ObjCCompatibleAliasDecl |
| 1175 | //===----------------------------------------------------------------------===// |
| 1176 | |
| 1177 | ObjCCompatibleAliasDecl * |
| 1178 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 1179 | SourceLocation L, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | IdentifierInfo *Id, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1181 | ObjCInterfaceDecl* AliasedClass) { |
| 1182 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 1183 | } |
| 1184 | |
| 1185 | //===----------------------------------------------------------------------===// |
| 1186 | // ObjCPropertyDecl |
| 1187 | //===----------------------------------------------------------------------===// |
| 1188 | |
| 1189 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 1190 | SourceLocation L, |
| 1191 | IdentifierInfo *Id, |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1192 | SourceLocation AtLoc, |
John McCall | 83a230c | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 1193 | TypeSourceInfo *T, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1194 | PropertyControl propControl) { |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 1195 | return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 1198 | //===----------------------------------------------------------------------===// |
| 1199 | // ObjCPropertyImplDecl |
| 1200 | //===----------------------------------------------------------------------===// |
| 1201 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1202 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 1203 | DeclContext *DC, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1204 | SourceLocation atLoc, |
| 1205 | SourceLocation L, |
| 1206 | ObjCPropertyDecl *property, |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 1207 | Kind PK, |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1208 | ObjCIvarDecl *ivar, |
| 1209 | SourceLocation ivarLoc) { |
| 1210 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, |
| 1211 | ivarLoc); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1212 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 1213 | |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1214 | SourceRange ObjCPropertyImplDecl::getSourceRange() const { |
| 1215 | SourceLocation EndLoc = getLocation(); |
| 1216 | if (IvarLoc.isValid()) |
| 1217 | EndLoc = IvarLoc; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1218 | |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1219 | return SourceRange(AtLoc, EndLoc); |
| 1220 | } |