Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 1 | //===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C related Decl classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclObjC.h" |
| 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 221fa94 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/Stmt.h" |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Chris Lattner | 8d8829e | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 21 | // ObjCListBase |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 24 | void ObjCListBase::Destroy(ASTContext &Ctx) { |
Chris Lattner | 7c981a7 | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 25 | Ctx.Deallocate(List); |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 26 | NumElts = 0; |
| 27 | List = 0; |
| 28 | } |
| 29 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 30 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 31 | assert(List == 0 && "Elements already set!"); |
| 32 | if (Elts == 0) return; // Setting to an empty list is a noop. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | |
| 34 | |
Chris Lattner | 7c981a7 | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 35 | List = new (Ctx) void*[Elts]; |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 36 | NumElts = Elts; |
| 37 | memcpy(List, InList, sizeof(void*)*Elts); |
| 38 | } |
| 39 | |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 40 | void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, |
| 41 | const SourceLocation *Locs, ASTContext &Ctx) { |
| 42 | if (Elts == 0) |
| 43 | return; |
| 44 | |
| 45 | Locations = new (Ctx) SourceLocation[Elts]; |
| 46 | memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); |
| 47 | set(InList, Elts, Ctx); |
| 48 | } |
| 49 | |
| 50 | void ObjCProtocolList::Destroy(ASTContext &Ctx) { |
| 51 | Ctx.Deallocate(Locations); |
| 52 | Locations = 0; |
| 53 | ObjCList<ObjCProtocolDecl>::Destroy(Ctx); |
| 54 | } |
Chris Lattner | 4d1eb76 | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 57 | // ObjCInterfaceDecl |
Chris Lattner | 8d8829e | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 60 | /// getIvarDecl - This method looks up an ivar in this ContextDecl. |
| 61 | /// |
| 62 | ObjCIvarDecl * |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 63 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 64 | lookup_const_iterator Ivar, IvarEnd; |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 65 | for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) { |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 66 | if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 67 | return ivar; |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
Argyrios Kyrtzidis | 6de0560 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 72 | // Get the local instance/class method declared in this interface. |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 73 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 6de0560 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 74 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const { |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 75 | // Since instance & class methods can have the same name, the loop below |
| 76 | // ensures we get the correct method. |
| 77 | // |
| 78 | // @interface Whatever |
| 79 | // - (int) class_method; |
| 80 | // + (float) class_method; |
| 81 | // @end |
| 82 | // |
| 83 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 84 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 85 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
Argyrios Kyrtzidis | 6de0560 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 86 | if (MD && MD->isInstanceMethod() == isInstance) |
Steve Naroff | c4173fa | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 87 | return MD; |
| 88 | } |
Steve Naroff | 35c62ae | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 92 | ObjCPropertyDecl * |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 93 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 94 | IdentifierInfo *propertyID) { |
| 95 | |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 96 | DeclContext::lookup_const_iterator I, E; |
Ted Kremenek | 4fb821e | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 97 | llvm::tie(I, E) = DC->lookup(propertyID); |
| 98 | for ( ; I != E; ++I) |
| 99 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) |
| 100 | return PD; |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Fariborz Jahanian | a054e99 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 105 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 106 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Fariborz Jahanian | a054e99 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 107 | ObjCPropertyDecl * |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 108 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 110 | if (ObjCPropertyDecl *PD = |
| 111 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 112 | return PD; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 114 | switch (getKind()) { |
| 115 | default: |
| 116 | break; |
| 117 | case Decl::ObjCProtocol: { |
| 118 | const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); |
| 119 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 120 | E = PID->protocol_end(); I != E; ++I) |
Fariborz Jahanian | 30a4292 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 121 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 122 | return P; |
Ted Kremenek | ddcd109 | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | case Decl::ObjCInterface: { |
| 126 | const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); |
| 127 | // Look through categories. |
| 128 | for (ObjCCategoryDecl *Cat = OID->getCategoryList(); |
| 129 | Cat; Cat = Cat->getNextClassCategory()) |
| 130 | if (!Cat->IsClassExtension()) |
| 131 | if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) |
| 132 | return P; |
| 133 | |
| 134 | // Look through protocols. |
| 135 | for (ObjCInterfaceDecl::protocol_iterator |
| 136 | I = OID->protocol_begin(), E = OID->protocol_end(); I != E; ++I) |
| 137 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 138 | return P; |
| 139 | |
| 140 | // Finally, check the super class. |
| 141 | if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) |
| 142 | return superClass->FindPropertyDeclaration(PropertyId); |
| 143 | break; |
| 144 | } |
| 145 | case Decl::ObjCCategory: { |
| 146 | const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); |
| 147 | // Look through protocols. |
| 148 | if (!OCD->IsClassExtension()) |
| 149 | for (ObjCCategoryDecl::protocol_iterator |
| 150 | I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I) |
| 151 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 152 | return P; |
| 153 | |
| 154 | break; |
Fariborz Jahanian | dab0484 | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
Steve Naroff | f9c6524 | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 160 | /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property |
| 161 | /// with name 'PropertyId' in the primary class; including those in protocols |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 162 | /// (direct or indirect) used by the primary class. |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 163 | /// |
| 164 | ObjCPropertyDecl * |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 165 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 166 | IdentifierInfo *PropertyId) const { |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 167 | if (ObjCPropertyDecl *PD = |
| 168 | ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) |
| 169 | return PD; |
| 170 | |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 171 | // Look through protocols. |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 172 | for (ObjCInterfaceDecl::protocol_iterator |
| 173 | I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 174 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 175 | return P; |
Ted Kremenek | d133a86 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 176 | |
Fariborz Jahanian | de8db16 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 180 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 181 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 182 | const SourceLocation *Locs, |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 183 | ASTContext &C) |
| 184 | { |
| 185 | if (ReferencedProtocols.empty()) { |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 186 | ReferencedProtocols.set(ExtList, ExtNum, Locs, C); |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | // Check for duplicate protocol in class's protocol list. |
| 190 | // This is (O)2. But it is extremely rare and number of protocols in |
| 191 | // class or its extension are very few. |
| 192 | llvm::SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 193 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 194 | for (unsigned i = 0; i < ExtNum; i++) { |
| 195 | bool protocolExists = false; |
| 196 | ObjCProtocolDecl *ProtoInExtension = ExtList[i]; |
| 197 | for (protocol_iterator p = protocol_begin(), e = protocol_end(); |
| 198 | p != e; p++) { |
| 199 | ObjCProtocolDecl *Proto = (*p); |
| 200 | if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { |
| 201 | protocolExists = true; |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | // Do we want to warn on a protocol in extension class which |
| 206 | // already exist in the class? Probably not. |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 207 | if (!protocolExists) { |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 208 | ProtocolRefs.push_back(ProtoInExtension); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 209 | ProtocolLocs.push_back(Locs[i]); |
| 210 | } |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 211 | } |
| 212 | if (ProtocolRefs.empty()) |
| 213 | return; |
Fariborz Jahanian | 8764c74 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 214 | // Merge ProtocolRefs into class's protocol list; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 215 | protocol_loc_iterator pl = protocol_loc_begin(); |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 216 | for (protocol_iterator p = protocol_begin(), e = protocol_end(); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 217 | p != e; ++p, ++pl) { |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 218 | ProtocolRefs.push_back(*p); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 219 | ProtocolLocs.push_back(*pl); |
| 220 | } |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 221 | ReferencedProtocols.Destroy(C); |
| 222 | unsigned NumProtoRefs = ProtocolRefs.size(); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 223 | setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C); |
Fariborz Jahanian | 092cd6e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 226 | /// getFirstClassExtension - Find first class extension of the given class. |
| 227 | ObjCCategoryDecl* ObjCInterfaceDecl::getFirstClassExtension() const { |
| 228 | for (ObjCCategoryDecl *CDecl = getCategoryList(); CDecl; |
Fariborz Jahanian | afe1386 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 229 | CDecl = CDecl->getNextClassCategory()) |
| 230 | if (CDecl->IsClassExtension()) |
| 231 | return CDecl; |
| 232 | return 0; |
| 233 | } |
| 234 | |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 235 | /// getNextClassCategory - Find next class extension in list of categories. |
| 236 | const ObjCCategoryDecl* ObjCCategoryDecl::getNextClassExtension() const { |
| 237 | for (const ObjCCategoryDecl *CDecl = getNextClassCategory(); CDecl; |
| 238 | CDecl = CDecl->getNextClassCategory()) |
| 239 | if (CDecl->IsClassExtension()) |
| 240 | return CDecl; |
| 241 | return 0; |
| 242 | } |
| 243 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 244 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 245 | ObjCInterfaceDecl *&clsDeclared) { |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 246 | ObjCInterfaceDecl* ClassDecl = this; |
| 247 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 248 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 6845383 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 249 | clsDeclared = ClassDecl; |
| 250 | return I; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 251 | } |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 252 | for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension(); |
| 253 | CDecl; CDecl = CDecl->getNextClassExtension()) { |
Fariborz Jahanian | afe1386 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 254 | if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) { |
| 255 | clsDeclared = ClassDecl; |
| 256 | return I; |
| 257 | } |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 258 | } |
Fariborz Jahanian | afe1386 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 260 | ClassDecl = ClassDecl->getSuperClass(); |
| 261 | } |
| 262 | return NULL; |
| 263 | } |
| 264 | |
Fariborz Jahanian | db3a4c1 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 265 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 266 | /// class whose name is passed as argument. If it is not one of the super classes |
| 267 | /// the it returns NULL. |
| 268 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 269 | const IdentifierInfo*ICName) { |
| 270 | ObjCInterfaceDecl* ClassDecl = this; |
| 271 | while (ClassDecl != NULL) { |
| 272 | if (ClassDecl->getIdentifier() == ICName) |
| 273 | return ClassDecl; |
| 274 | ClassDecl = ClassDecl->getSuperClass(); |
| 275 | } |
| 276 | return NULL; |
| 277 | } |
| 278 | |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 279 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 280 | /// the class, its categories, and its super classes (using a linear search). |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 281 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 282 | bool isInstance) const { |
| 283 | const ObjCInterfaceDecl* ClassDecl = this; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 284 | ObjCMethodDecl *MethodDecl = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 286 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 287 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 288 | return MethodDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 290 | // Didn't find one yet - look through protocols. |
Chris Lattner | d004505 | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 291 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 292 | ClassDecl->getReferencedProtocols(); |
| 293 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 294 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 295 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 296 | return MethodDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 298 | // Didn't find one yet - now look through categories. |
| 299 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 300 | while (CatDecl) { |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 301 | if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 302 | return MethodDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | |
Steve Naroff | 5fd31b1 | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 304 | // Didn't find one yet - look through protocols. |
| 305 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 306 | CatDecl->getReferencedProtocols(); |
| 307 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 308 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | 553376b | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 309 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Steve Naroff | 8ec2784 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 310 | return MethodDecl; |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 311 | CatDecl = CatDecl->getNextClassCategory(); |
| 312 | } |
| 313 | ClassDecl = ClassDecl->getSuperClass(); |
| 314 | } |
| 315 | return NULL; |
| 316 | } |
| 317 | |
Steve Naroff | bb69c94 | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 318 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod( |
| 319 | const Selector &Sel) { |
| 320 | ObjCMethodDecl *Method = 0; |
| 321 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
| 322 | Method = ImpDecl->getInstanceMethod(Sel); |
| 323 | |
| 324 | if (!Method && getSuperClass()) |
| 325 | return getSuperClass()->lookupPrivateInstanceMethod(Sel); |
| 326 | return Method; |
| 327 | } |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 328 | |
| 329 | //===----------------------------------------------------------------------===// |
| 330 | // ObjCMethodDecl |
| 331 | //===----------------------------------------------------------------------===// |
| 332 | |
| 333 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | SourceLocation beginLoc, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 335 | SourceLocation endLoc, |
| 336 | Selector SelInfo, QualType T, |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 337 | TypeSourceInfo *ResultTInfo, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 338 | DeclContext *contextDecl, |
| 339 | bool isInstance, |
| 340 | bool isVariadic, |
| 341 | bool isSynthesized, |
Fariborz Jahanian | 6e7e8cc | 2010-07-22 18:24:20 +0000 | [diff] [blame^] | 342 | bool isDefined, |
Fariborz Jahanian | d9235db | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 343 | ImplementationControl impControl, |
| 344 | unsigned numSelectorArgs) { |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 345 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 346 | SelInfo, T, ResultTInfo, contextDecl, |
| 347 | isInstance, |
Fariborz Jahanian | 6e7e8cc | 2010-07-22 18:24:20 +0000 | [diff] [blame^] | 348 | isVariadic, isSynthesized, isDefined, |
| 349 | impControl, |
Fariborz Jahanian | d9235db | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 350 | numSelectorArgs); |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 353 | void ObjCMethodDecl::Destroy(ASTContext &C) { |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 354 | if (Body) Body->Destroy(C); |
| 355 | if (SelfDecl) SelfDecl->Destroy(C); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 357 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 358 | if (*I) (*I)->Destroy(C); |
| 359 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 360 | ParamInfo.Destroy(C); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 361 | |
| 362 | Decl::Destroy(C); |
Chris Lattner | 8937519 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 365 | /// \brief A definition will return its interface declaration. |
| 366 | /// An interface declaration will return its definition. |
| 367 | /// Otherwise it will return itself. |
| 368 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { |
| 369 | ASTContext &Ctx = getASTContext(); |
| 370 | ObjCMethodDecl *Redecl = 0; |
| 371 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 372 | |
| 373 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 374 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 375 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 376 | |
| 377 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 378 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 379 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 380 | |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 381 | } else if (ObjCImplementationDecl *ImplD = |
| 382 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 383 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 384 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 385 | |
| 386 | } else if (ObjCCategoryImplDecl *CImplD = |
| 387 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | f406f4d | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 388 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 389 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | a8cf0be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | return Redecl ? Redecl : this; |
| 393 | } |
| 394 | |
Argyrios Kyrtzidis | f390c43 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 395 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 396 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 397 | |
| 398 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 399 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 400 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 401 | isInstanceMethod())) |
| 402 | return MD; |
| 403 | |
| 404 | } else if (ObjCCategoryImplDecl *CImplD = |
| 405 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | f406f4d | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 406 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | f390c43 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 407 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 408 | isInstanceMethod())) |
| 409 | return MD; |
| 410 | } |
| 411 | |
| 412 | return this; |
| 413 | } |
| 414 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 416 | const ObjCInterfaceDecl *OID) { |
| 417 | QualType selfTy; |
| 418 | if (isInstanceMethod()) { |
| 419 | // There may be no interface context due to error in declaration |
| 420 | // of the interface (which has been reported). Recover gracefully. |
| 421 | if (OID) { |
Daniel Dunbar | aefc2b9 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 422 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 7cae42b | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 423 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 424 | } else { |
| 425 | selfTy = Context.getObjCIdType(); |
| 426 | } |
| 427 | } else // we have a factory method. |
| 428 | selfTy = Context.getObjCClassType(); |
| 429 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
Steve Naroff | 04f2d14 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 431 | &Context.Idents.get("self"), selfTy)); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 432 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 434 | &Context.Idents.get("_cmd"), |
Steve Naroff | 04f2d14 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 435 | Context.getObjCSelType())); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 438 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 439 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 440 | return ID; |
| 441 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 442 | return CD->getClassInterface(); |
Argyrios Kyrtzidis | 2cee40d | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 443 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 444 | return IMD->getClassInterface(); |
Argyrios Kyrtzidis | 2cee40d | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 445 | |
| 446 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 447 | assert(false && "unknown method context"); |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 451 | //===----------------------------------------------------------------------===// |
| 452 | // ObjCInterfaceDecl |
| 453 | //===----------------------------------------------------------------------===// |
| 454 | |
| 455 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
| 456 | DeclContext *DC, |
| 457 | SourceLocation atLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | IdentifierInfo *Id, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 459 | SourceLocation ClassLoc, |
| 460 | bool ForwardDecl, bool isInternal){ |
| 461 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
| 462 | isInternal); |
| 463 | } |
| 464 | |
| 465 | ObjCInterfaceDecl:: |
| 466 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
| 467 | SourceLocation CLoc, bool FD, bool isInternal) |
| 468 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), |
| 469 | TypeForDecl(0), SuperClass(0), |
| 470 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), |
| 471 | ClassLoc(CLoc) { |
| 472 | } |
| 473 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 474 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { |
Chris Lattner | d8a47c4 | 2009-03-31 08:36:08 +0000 | [diff] [blame] | 475 | for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 476 | if (*I) (*I)->Destroy(C); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 478 | // FIXME: CategoryList? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 480 | // FIXME: Because there is no clear ownership |
| 481 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 482 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
| 483 | Decl::Destroy(C); |
| 484 | } |
| 485 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 486 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
| 487 | return getASTContext().getObjCImplementation( |
| 488 | const_cast<ObjCInterfaceDecl*>(this)); |
| 489 | } |
| 490 | |
| 491 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 492 | getASTContext().setObjCImplementation(this, ImplD); |
| 493 | } |
| 494 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 495 | |
| 496 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 497 | /// categories for this class and returns it. Name of the category is passed |
| 498 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 499 | /// |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 500 | ObjCCategoryDecl * |
| 501 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 502 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 503 | Category; Category = Category->getNextClassCategory()) |
| 504 | if (Category->getIdentifier() == CategoryId) |
| 505 | return Category; |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
Argyrios Kyrtzidis | 1559d67b | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 509 | ObjCMethodDecl * |
| 510 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 511 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 512 | Category; Category = Category->getNextClassCategory()) |
| 513 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 514 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 515 | return MD; |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 520 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 521 | Category; Category = Category->getNextClassCategory()) |
| 522 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 523 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 524 | return MD; |
| 525 | return 0; |
| 526 | } |
| 527 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 528 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 529 | /// has been implemented in IDecl class, its super class or categories (if |
| 530 | /// lookupCategory is true). |
| 531 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 532 | bool lookupCategory, |
| 533 | bool RHSIsQualifiedID) { |
| 534 | ObjCInterfaceDecl *IDecl = this; |
| 535 | // 1st, look up the class. |
| 536 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 537 | IDecl->getReferencedProtocols(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 539 | for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(), |
| 540 | E = Protocols.end(); PI != E; ++PI) { |
| 541 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 542 | return true; |
| 543 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 544 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 545 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 546 | // object. This IMO, should be a bug. |
| 547 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 548 | // extensions are not enabled. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | if (RHSIsQualifiedID && |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 550 | getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) |
| 551 | return true; |
| 552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 554 | // 2nd, look up the category. |
| 555 | if (lookupCategory) |
| 556 | for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; |
| 557 | CDecl = CDecl->getNextClassCategory()) { |
| 558 | for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), |
| 559 | E = CDecl->protocol_end(); PI != E; ++PI) |
| 560 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 561 | return true; |
| 562 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 564 | // 3rd, look up the super class(s) |
| 565 | if (IDecl->getSuperClass()) |
| 566 | return |
| 567 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 568 | RHSIsQualifiedID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Fariborz Jahanian | 3f8917a | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 573 | //===----------------------------------------------------------------------===// |
| 574 | // ObjCIvarDecl |
| 575 | //===----------------------------------------------------------------------===// |
| 576 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 577 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 578 | SourceLocation L, IdentifierInfo *Id, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 579 | QualType T, TypeSourceInfo *TInfo, |
Fariborz Jahanian | 1872298 | 2010-07-17 00:59:30 +0000 | [diff] [blame] | 580 | AccessControl ac, Expr *BW, |
| 581 | bool synthesized) { |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 582 | if (DC) { |
| 583 | // Ivar's can only appear in interfaces, implementations (via synthesized |
| 584 | // properties), and class extensions (via direct declaration, or synthesized |
| 585 | // properties). |
| 586 | // |
| 587 | // FIXME: This should really be asserting this: |
| 588 | // (isa<ObjCCategoryDecl>(DC) && |
| 589 | // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) |
| 590 | // but unfortunately we sometimes place ivars into non-class extension |
| 591 | // categories on error. This breaks an AST invariant, and should not be |
| 592 | // fixed. |
| 593 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 594 | isa<ObjCCategoryDecl>(DC)) && |
| 595 | "Invalid ivar decl context!"); |
| 596 | } |
| 597 | |
Fariborz Jahanian | 1872298 | 2010-07-17 00:59:30 +0000 | [diff] [blame] | 598 | return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW, synthesized); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Daniel Dunbar | 89947ea | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 601 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 602 | const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 603 | |
Daniel Dunbar | 89947ea | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 604 | switch (DC->getKind()) { |
| 605 | default: |
| 606 | case ObjCCategoryImpl: |
| 607 | case ObjCProtocol: |
| 608 | assert(0 && "invalid ivar container!"); |
| 609 | return 0; |
| 610 | |
| 611 | // Ivars can only appear in class extension categories. |
| 612 | case ObjCCategory: { |
| 613 | const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 614 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 615 | return CD->getClassInterface(); |
| 616 | } |
| 617 | |
| 618 | case ObjCImplementation: |
| 619 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 620 | |
| 621 | case ObjCInterface: |
| 622 | return cast<ObjCInterfaceDecl>(DC); |
| 623 | } |
| 624 | } |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 625 | |
| 626 | //===----------------------------------------------------------------------===// |
| 627 | // ObjCAtDefsFieldDecl |
| 628 | //===----------------------------------------------------------------------===// |
| 629 | |
| 630 | ObjCAtDefsFieldDecl |
| 631 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 632 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 633 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
| 634 | } |
| 635 | |
| 636 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 637 | this->~ObjCAtDefsFieldDecl(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | C.Deallocate((void *)this); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | //===----------------------------------------------------------------------===// |
| 642 | // ObjCProtocolDecl |
| 643 | //===----------------------------------------------------------------------===// |
| 644 | |
| 645 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | SourceLocation L, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 647 | IdentifierInfo *Id) { |
| 648 | return new (C) ObjCProtocolDecl(DC, L, Id); |
| 649 | } |
| 650 | |
| 651 | void ObjCProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 652 | ReferencedProtocols.Destroy(C); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 653 | ObjCContainerDecl::Destroy(C); |
| 654 | } |
| 655 | |
Steve Naroff | 114aecb | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 656 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 657 | ObjCProtocolDecl *PDecl = this; |
| 658 | |
| 659 | if (Name == getIdentifier()) |
| 660 | return PDecl; |
| 661 | |
| 662 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 663 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 664 | return PDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Steve Naroff | 114aecb | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 666 | return NULL; |
| 667 | } |
| 668 | |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 669 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 670 | // it inherited. |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 671 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 672 | bool isInstance) const { |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 673 | ObjCMethodDecl *MethodDecl = NULL; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 675 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 676 | return MethodDecl; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 678 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | e6ed65b | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 679 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 680 | return MethodDecl; |
| 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | //===----------------------------------------------------------------------===// |
| 685 | // ObjCClassDecl |
| 686 | //===----------------------------------------------------------------------===// |
| 687 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 688 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 689 | ObjCInterfaceDecl *const *Elts, |
| 690 | const SourceLocation *Locs, |
| 691 | unsigned nElts, |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 692 | ASTContext &C) |
| 693 | : Decl(ObjCClass, DC, L) { |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 694 | setClassList(C, Elts, Locs, nElts); |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 697 | void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List, |
| 698 | const SourceLocation *Locs, unsigned Num) { |
| 699 | ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num, |
| 700 | llvm::alignof<ObjCClassRef>()); |
| 701 | for (unsigned i = 0; i < Num; ++i) |
| 702 | new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]); |
| 703 | |
| 704 | NumDecls = Num; |
| 705 | } |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 706 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 707 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 708 | SourceLocation L, |
| 709 | ObjCInterfaceDecl *const *Elts, |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 710 | const SourceLocation *Locs, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 711 | unsigned nElts) { |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 712 | return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void ObjCClassDecl::Destroy(ASTContext &C) { |
Ted Kremenek | 9b124e1 | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 716 | // ObjCInterfaceDecls registered with a DeclContext will get destroyed |
| 717 | // when the DeclContext is destroyed. For those created only by a forward |
| 718 | // declaration, the first @class that created the ObjCInterfaceDecl gets |
| 719 | // to destroy it. |
| 720 | // FIXME: Note that this ownership role is very brittle; a better |
| 721 | // polict is surely need in the future. |
| 722 | for (iterator I = begin(), E = end(); I !=E ; ++I) { |
| 723 | ObjCInterfaceDecl *ID = I->getInterface(); |
| 724 | if (ID->isForwardDecl() && ID->getLocStart() == getLocStart()) |
| 725 | ID->Destroy(C); |
| 726 | } |
| 727 | |
| 728 | C.Deallocate(ForwardDecls); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 729 | Decl::Destroy(C); |
| 730 | } |
| 731 | |
Ted Kremenek | 49939c2 | 2009-11-18 01:26:56 +0000 | [diff] [blame] | 732 | SourceRange ObjCClassDecl::getSourceRange() const { |
| 733 | // FIXME: We should include the semicolon |
| 734 | assert(NumDecls); |
| 735 | return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation()); |
| 736 | } |
| 737 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 738 | //===----------------------------------------------------------------------===// |
| 739 | // ObjCForwardProtocolDecl |
| 740 | //===----------------------------------------------------------------------===// |
| 741 | |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 742 | ObjCForwardProtocolDecl:: |
| 743 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 744 | ObjCProtocolDecl *const *Elts, unsigned nElts, |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 745 | const SourceLocation *Locs, ASTContext &C) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | : Decl(ObjCForwardProtocol, DC, L) { |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 747 | ReferencedProtocols.set(Elts, nElts, Locs, C); |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 751 | ObjCForwardProtocolDecl * |
| 752 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | SourceLocation L, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 754 | ObjCProtocolDecl *const *Elts, |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 755 | unsigned NumElts, |
| 756 | const SourceLocation *Locs) { |
| 757 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 2229872 | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 761 | ReferencedProtocols.Destroy(C); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 762 | Decl::Destroy(C); |
| 763 | } |
| 764 | |
| 765 | //===----------------------------------------------------------------------===// |
| 766 | // ObjCCategoryDecl |
| 767 | //===----------------------------------------------------------------------===// |
| 768 | |
| 769 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 071676f | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 770 | SourceLocation AtLoc, |
| 771 | SourceLocation ClassNameLoc, |
| 772 | SourceLocation CategoryNameLoc, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 773 | IdentifierInfo *Id) { |
Douglas Gregor | 071676f | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 774 | return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 777 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 778 | return getASTContext().getObjCImplementation( |
| 779 | const_cast<ObjCCategoryDecl*>(this)); |
| 780 | } |
| 781 | |
| 782 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 783 | getASTContext().setObjCImplementation(this, ImplD); |
| 784 | } |
| 785 | |
| 786 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 787 | //===----------------------------------------------------------------------===// |
| 788 | // ObjCCategoryImplDecl |
| 789 | //===----------------------------------------------------------------------===// |
| 790 | |
| 791 | ObjCCategoryImplDecl * |
| 792 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
| 793 | SourceLocation L,IdentifierInfo *Id, |
| 794 | ObjCInterfaceDecl *ClassInterface) { |
| 795 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
| 796 | } |
| 797 | |
Steve Naroff | f406f4d | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 798 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
Ted Kremenek | e184ac5 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 799 | // The class interface might be NULL if we are working with invalid code. |
| 800 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 801 | return ID->FindCategoryDeclaration(getIdentifier()); |
| 802 | return 0; |
Argyrios Kyrtzidis | a56fa19 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 805 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 806 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 9a13efd | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 807 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 29bd76f | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 808 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 809 | addDecl(property); |
Douglas Gregor | 29bd76f | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 812 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 813 | ASTContext &Ctx = getASTContext(); |
| 814 | |
| 815 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 49c29ee | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 816 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 817 | if (IFace) |
| 818 | Ctx.setObjCImplementation(IFace, ImplD); |
| 819 | |
Duncan Sands | 49c29ee | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 820 | } else if (ObjCCategoryImplDecl *ImplD = |
Argyrios Kyrtzidis | 6d9fab7 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 821 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 822 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 823 | Ctx.setObjCImplementation(CD, ImplD); |
| 824 | } |
| 825 | |
| 826 | ClassInterface = IFace; |
| 827 | } |
| 828 | |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 829 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | aab70d2 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 830 | /// properties implemented in this category @implementation block and returns |
| 831 | /// the implemented property that uses it. |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 832 | /// |
Chris Lattner | a9ca052 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 833 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 834 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 835 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 836 | ObjCPropertyImplDecl *PID = *i; |
| 837 | if (PID->getPropertyIvarDecl() && |
| 838 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 839 | return PID; |
| 840 | } |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 845 | /// added to the list of those properties @synthesized/@dynamic in this |
| 846 | /// category @implementation block. |
| 847 | /// |
Chris Lattner | a9ca052 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 848 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 849 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 850 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | fbbaf6a | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 851 | ObjCPropertyImplDecl *PID = *i; |
| 852 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 853 | return PID; |
| 854 | } |
| 855 | return 0; |
| 856 | } |
| 857 | |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 858 | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
| 859 | const ObjCCategoryImplDecl *CID) { |
| 860 | OS << CID->getName(); |
| 861 | return OS; |
| 862 | } |
| 863 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 864 | //===----------------------------------------------------------------------===// |
| 865 | // ObjCImplementationDecl |
| 866 | //===----------------------------------------------------------------------===// |
| 867 | |
| 868 | ObjCImplementationDecl * |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 870 | SourceLocation L, |
| 871 | ObjCInterfaceDecl *ClassInterface, |
| 872 | ObjCInterfaceDecl *SuperDecl) { |
| 873 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); |
| 874 | } |
| 875 | |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 876 | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
| 877 | const ObjCImplementationDecl *ID) { |
| 878 | OS << ID->getName(); |
| 879 | return OS; |
| 880 | } |
| 881 | |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 882 | //===----------------------------------------------------------------------===// |
| 883 | // ObjCCompatibleAliasDecl |
| 884 | //===----------------------------------------------------------------------===// |
| 885 | |
| 886 | ObjCCompatibleAliasDecl * |
| 887 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 888 | SourceLocation L, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 | IdentifierInfo *Id, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 890 | ObjCInterfaceDecl* AliasedClass) { |
| 891 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 892 | } |
| 893 | |
| 894 | //===----------------------------------------------------------------------===// |
| 895 | // ObjCPropertyDecl |
| 896 | //===----------------------------------------------------------------------===// |
| 897 | |
| 898 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 899 | SourceLocation L, |
| 900 | IdentifierInfo *Id, |
Fariborz Jahanian | da8ec2b | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 901 | SourceLocation AtLoc, |
John McCall | 339bb66 | 2010-06-04 20:50:08 +0000 | [diff] [blame] | 902 | TypeSourceInfo *T, |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 903 | PropertyControl propControl) { |
Fariborz Jahanian | da8ec2b | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 904 | return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T); |
Chris Lattner | f1ccb0c | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | |
| 908 | //===----------------------------------------------------------------------===// |
| 909 | // ObjCPropertyImplDecl |
| 910 | //===----------------------------------------------------------------------===// |
| 911 | |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 912 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | c25d7a7 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 913 | DeclContext *DC, |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 914 | SourceLocation atLoc, |
| 915 | SourceLocation L, |
| 916 | ObjCPropertyDecl *property, |
Daniel Dunbar | 3b4fdb0 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 917 | Kind PK, |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 918 | ObjCIvarDecl *ivar) { |
Steve Naroff | 13ae6f4 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 919 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | 6efdf1d | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 920 | } |
Chris Lattner | ed0e164 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 921 | |
Chris Lattner | c5ffed4 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 922 | |