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" |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 21 | // ObjCListBase |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 24 | void ObjCListBase::Destroy(ASTContext &Ctx) { |
Chris Lattner | 4ee413b | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 25 | Ctx.Deallocate(List); |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 26 | NumElts = 0; |
| 27 | List = 0; |
| 28 | } |
| 29 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 30 | void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { |
Chris Lattner | 11e1e1a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | |
| 34 | |
Chris Lattner | 4ee413b | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 35 | List = new (Ctx) void*[Elts]; |
Chris Lattner | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 36 | NumElts = Elts; |
| 37 | memcpy(List, InList, sizeof(void*)*Elts); |
| 38 | } |
| 39 | |
Douglas Gregor | 18df52b | 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 | 11e1e1a | 2009-02-20 21:16:26 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 57 | // ObjCInterfaceDecl |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Fariborz Jahanian | 496b5a8 | 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 | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 63 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 64 | lookup_const_iterator Ivar, IvarEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 65 | for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) { |
Fariborz Jahanian | 496b5a8 | 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 | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 72 | // Get the local instance/class method declared in this interface. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 73 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 74 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const { |
Steve Naroff | 0de21fd | 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 | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 84 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 85 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 86 | if (MD && MD->isInstanceMethod() == isInstance) |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 87 | return MD; |
| 88 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 92 | ObjCPropertyDecl * |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 93 | ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, |
Ted Kremenek | 9f550ff | 2010-03-15 20:11:46 +0000 | [diff] [blame] | 94 | IdentifierInfo *propertyID) { |
| 95 | |
Ted Kremenek | de09d0c | 2010-03-15 20:11:53 +0000 | [diff] [blame] | 96 | DeclContext::lookup_const_iterator I, E; |
Ted Kremenek | 9f550ff | 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 | 559c0c4 | 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 | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 107 | ObjCPropertyDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 108 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | |
Ted Kremenek | de09d0c | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Ted Kremenek | de09d0c | 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 | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 121 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 122 | return P; |
Ted Kremenek | de09d0c | 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 | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Fariborz Jahanian | a6f14e1 | 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 | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 162 | /// (direct or indirect) used by the primary class. |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 163 | /// |
| 164 | ObjCPropertyDecl * |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 165 | ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 166 | IdentifierInfo *PropertyId) const { |
Ted Kremenek | 37cafb0 | 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 | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 171 | // Look through protocols. |
Ted Kremenek | 37cafb0 | 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 | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 174 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
| 175 | return P; |
Ted Kremenek | 37cafb0 | 2010-03-15 20:30:07 +0000 | [diff] [blame] | 176 | |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 180 | void ObjCInterfaceDecl::mergeClassExtensionProtocolList( |
| 181 | ObjCProtocolDecl *const* ExtList, unsigned ExtNum, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 182 | const SourceLocation *Locs, |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 183 | ASTContext &C) |
| 184 | { |
| 185 | if (ReferencedProtocols.empty()) { |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 186 | ReferencedProtocols.set(ExtList, ExtNum, Locs, C); |
Fariborz Jahanian | 339798e | 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 | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 193 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
Fariborz Jahanian | 339798e | 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 | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 207 | if (!protocolExists) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 208 | ProtocolRefs.push_back(ProtoInExtension); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 209 | ProtocolLocs.push_back(Locs[i]); |
| 210 | } |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 211 | } |
| 212 | if (ProtocolRefs.empty()) |
| 213 | return; |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 214 | // Merge ProtocolRefs into class's protocol list; |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 215 | protocol_loc_iterator pl = protocol_loc_begin(); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 216 | for (protocol_iterator p = protocol_begin(), e = protocol_end(); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 217 | p != e; ++p, ++pl) { |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 218 | ProtocolRefs.push_back(*p); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 219 | ProtocolLocs.push_back(*pl); |
| 220 | } |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 221 | ReferencedProtocols.Destroy(C); |
| 222 | unsigned NumProtoRefs = ProtocolRefs.size(); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 223 | setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 226 | /// getClassExtension - Find class extension of the given class. |
| 227 | // FIXME. can speed it up, if need be. |
| 228 | ObjCCategoryDecl* ObjCInterfaceDecl::getClassExtension() const { |
| 229 | const ObjCInterfaceDecl* ClassDecl = this; |
| 230 | for (ObjCCategoryDecl *CDecl = ClassDecl->getCategoryList(); CDecl; |
| 231 | CDecl = CDecl->getNextClassCategory()) |
| 232 | if (CDecl->IsClassExtension()) |
| 233 | return CDecl; |
| 234 | return 0; |
| 235 | } |
| 236 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 237 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 238 | ObjCInterfaceDecl *&clsDeclared) { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 239 | ObjCInterfaceDecl* ClassDecl = this; |
| 240 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 241 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 242 | clsDeclared = ClassDecl; |
| 243 | return I; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 244 | } |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 245 | if (const ObjCCategoryDecl *CDecl = ClassDecl->getClassExtension()) |
| 246 | if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) { |
| 247 | clsDeclared = ClassDecl; |
| 248 | return I; |
| 249 | } |
| 250 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 251 | ClassDecl = ClassDecl->getSuperClass(); |
| 252 | } |
| 253 | return NULL; |
| 254 | } |
| 255 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 256 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 257 | /// class whose name is passed as argument. If it is not one of the super classes |
| 258 | /// the it returns NULL. |
| 259 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 260 | const IdentifierInfo*ICName) { |
| 261 | ObjCInterfaceDecl* ClassDecl = this; |
| 262 | while (ClassDecl != NULL) { |
| 263 | if (ClassDecl->getIdentifier() == ICName) |
| 264 | return ClassDecl; |
| 265 | ClassDecl = ClassDecl->getSuperClass(); |
| 266 | } |
| 267 | return NULL; |
| 268 | } |
| 269 | |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 270 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 271 | /// the class, its categories, and its super classes (using a linear search). |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 272 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 273 | bool isInstance) const { |
| 274 | const ObjCInterfaceDecl* ClassDecl = this; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 275 | ObjCMethodDecl *MethodDecl = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 277 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 278 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 279 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 281 | // Didn't find one yet - look through protocols. |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 282 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 283 | ClassDecl->getReferencedProtocols(); |
| 284 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 285 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 286 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 287 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 289 | // Didn't find one yet - now look through categories. |
| 290 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 291 | while (CatDecl) { |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 292 | if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 293 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 294 | |
Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 295 | // Didn't find one yet - look through protocols. |
| 296 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 297 | CatDecl->getReferencedProtocols(); |
| 298 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 299 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 300 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Steve Naroff | b558422 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 301 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 302 | CatDecl = CatDecl->getNextClassCategory(); |
| 303 | } |
| 304 | ClassDecl = ClassDecl->getSuperClass(); |
| 305 | } |
| 306 | return NULL; |
| 307 | } |
| 308 | |
Steve Naroff | d789d3d | 2009-10-01 23:46:04 +0000 | [diff] [blame] | 309 | ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod( |
| 310 | const Selector &Sel) { |
| 311 | ObjCMethodDecl *Method = 0; |
| 312 | if (ObjCImplementationDecl *ImpDecl = getImplementation()) |
| 313 | Method = ImpDecl->getInstanceMethod(Sel); |
| 314 | |
| 315 | if (!Method && getSuperClass()) |
| 316 | return getSuperClass()->lookupPrivateInstanceMethod(Sel); |
| 317 | return Method; |
| 318 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 319 | |
| 320 | //===----------------------------------------------------------------------===// |
| 321 | // ObjCMethodDecl |
| 322 | //===----------------------------------------------------------------------===// |
| 323 | |
| 324 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | SourceLocation beginLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 326 | SourceLocation endLoc, |
| 327 | Selector SelInfo, QualType T, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 328 | TypeSourceInfo *ResultTInfo, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 329 | DeclContext *contextDecl, |
| 330 | bool isInstance, |
| 331 | bool isVariadic, |
| 332 | bool isSynthesized, |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 333 | ImplementationControl impControl, |
| 334 | unsigned numSelectorArgs) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 335 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
Douglas Gregor | 4bc1cb6 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 336 | SelInfo, T, ResultTInfo, contextDecl, |
| 337 | isInstance, |
Fariborz Jahanian | 7732cc9 | 2010-04-08 21:29:11 +0000 | [diff] [blame] | 338 | isVariadic, isSynthesized, impControl, |
| 339 | numSelectorArgs); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 342 | void ObjCMethodDecl::Destroy(ASTContext &C) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 343 | if (Body) Body->Destroy(C); |
| 344 | if (SelfDecl) SelfDecl->Destroy(C); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 346 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 347 | if (*I) (*I)->Destroy(C); |
| 348 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 349 | ParamInfo.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 350 | |
| 351 | Decl::Destroy(C); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 354 | /// \brief A definition will return its interface declaration. |
| 355 | /// An interface declaration will return its definition. |
| 356 | /// Otherwise it will return itself. |
| 357 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { |
| 358 | ASTContext &Ctx = getASTContext(); |
| 359 | ObjCMethodDecl *Redecl = 0; |
| 360 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 361 | |
| 362 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 363 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 364 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 365 | |
| 366 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 367 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 368 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 369 | |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 370 | } else if (ObjCImplementationDecl *ImplD = |
| 371 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 372 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 373 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 374 | |
| 375 | } else if (ObjCCategoryImplDecl *CImplD = |
| 376 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 377 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 378 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
Argyrios Kyrtzidis | 57ea6be | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | return Redecl ? Redecl : this; |
| 382 | } |
| 383 | |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 384 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 385 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 386 | |
| 387 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 388 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 389 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 390 | isInstanceMethod())) |
| 391 | return MD; |
| 392 | |
| 393 | } else if (ObjCCategoryImplDecl *CImplD = |
| 394 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 395 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) |
Argyrios Kyrtzidis | e7f9d30 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 396 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 397 | isInstanceMethod())) |
| 398 | return MD; |
| 399 | } |
| 400 | |
| 401 | return this; |
| 402 | } |
| 403 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 405 | const ObjCInterfaceDecl *OID) { |
| 406 | QualType selfTy; |
| 407 | if (isInstanceMethod()) { |
| 408 | // There may be no interface context due to error in declaration |
| 409 | // of the interface (which has been reported). Recover gracefully. |
| 410 | if (OID) { |
Daniel Dunbar | 3b3a458 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 411 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 412 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 413 | } else { |
| 414 | selfTy = Context.getObjCIdType(); |
| 415 | } |
| 416 | } else // we have a factory method. |
| 417 | selfTy = Context.getObjCClassType(); |
| 418 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 420 | &Context.Idents.get("self"), selfTy)); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 421 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 423 | &Context.Idents.get("_cmd"), |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 424 | Context.getObjCSelType())); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 427 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 428 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 429 | return ID; |
| 430 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 431 | return CD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 432 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 433 | return IMD->getClassInterface(); |
Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 434 | |
| 435 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 436 | assert(false && "unknown method context"); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 440 | //===----------------------------------------------------------------------===// |
| 441 | // ObjCInterfaceDecl |
| 442 | //===----------------------------------------------------------------------===// |
| 443 | |
| 444 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
| 445 | DeclContext *DC, |
| 446 | SourceLocation atLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | IdentifierInfo *Id, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 448 | SourceLocation ClassLoc, |
| 449 | bool ForwardDecl, bool isInternal){ |
| 450 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
| 451 | isInternal); |
| 452 | } |
| 453 | |
| 454 | ObjCInterfaceDecl:: |
| 455 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
| 456 | SourceLocation CLoc, bool FD, bool isInternal) |
| 457 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), |
| 458 | TypeForDecl(0), SuperClass(0), |
| 459 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), |
| 460 | ClassLoc(CLoc) { |
| 461 | } |
| 462 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { |
Chris Lattner | d13d302 | 2009-03-31 08:36:08 +0000 | [diff] [blame] | 464 | for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 465 | if (*I) (*I)->Destroy(C); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 467 | // FIXME: CategoryList? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 468 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 469 | // FIXME: Because there is no clear ownership |
| 470 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 471 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
| 472 | Decl::Destroy(C); |
| 473 | } |
| 474 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 475 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
| 476 | return getASTContext().getObjCImplementation( |
| 477 | const_cast<ObjCInterfaceDecl*>(this)); |
| 478 | } |
| 479 | |
| 480 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 481 | getASTContext().setObjCImplementation(this, ImplD); |
| 482 | } |
| 483 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 484 | |
| 485 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 486 | /// categories for this class and returns it. Name of the category is passed |
| 487 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 488 | /// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 489 | ObjCCategoryDecl * |
| 490 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 491 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 492 | Category; Category = Category->getNextClassCategory()) |
| 493 | if (Category->getIdentifier() == CategoryId) |
| 494 | return Category; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 498 | ObjCMethodDecl * |
| 499 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 500 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 501 | Category; Category = Category->getNextClassCategory()) |
| 502 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 503 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 504 | return MD; |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 509 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 510 | Category; Category = Category->getNextClassCategory()) |
| 511 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 512 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 513 | return MD; |
| 514 | return 0; |
| 515 | } |
| 516 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 517 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 518 | /// has been implemented in IDecl class, its super class or categories (if |
| 519 | /// lookupCategory is true). |
| 520 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 521 | bool lookupCategory, |
| 522 | bool RHSIsQualifiedID) { |
| 523 | ObjCInterfaceDecl *IDecl = this; |
| 524 | // 1st, look up the class. |
| 525 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 526 | IDecl->getReferencedProtocols(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 527 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 528 | for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(), |
| 529 | E = Protocols.end(); PI != E; ++PI) { |
| 530 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 531 | return true; |
| 532 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 533 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 534 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 535 | // object. This IMO, should be a bug. |
| 536 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 537 | // extensions are not enabled. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | if (RHSIsQualifiedID && |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 539 | getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) |
| 540 | return true; |
| 541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 543 | // 2nd, look up the category. |
| 544 | if (lookupCategory) |
| 545 | for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; |
| 546 | CDecl = CDecl->getNextClassCategory()) { |
| 547 | for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), |
| 548 | E = CDecl->protocol_end(); PI != E; ++PI) |
| 549 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 550 | return true; |
| 551 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 553 | // 3rd, look up the super class(s) |
| 554 | if (IDecl->getSuperClass()) |
| 555 | return |
| 556 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 557 | RHSIsQualifiedID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 559 | return false; |
| 560 | } |
| 561 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 562 | //===----------------------------------------------------------------------===// |
| 563 | // ObjCIvarDecl |
| 564 | //===----------------------------------------------------------------------===// |
| 565 | |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 566 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 567 | SourceLocation L, IdentifierInfo *Id, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 568 | QualType T, TypeSourceInfo *TInfo, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 569 | AccessControl ac, Expr *BW) { |
Daniel Dunbar | a065492 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 570 | if (DC) { |
| 571 | // Ivar's can only appear in interfaces, implementations (via synthesized |
| 572 | // properties), and class extensions (via direct declaration, or synthesized |
| 573 | // properties). |
| 574 | // |
| 575 | // FIXME: This should really be asserting this: |
| 576 | // (isa<ObjCCategoryDecl>(DC) && |
| 577 | // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) |
| 578 | // but unfortunately we sometimes place ivars into non-class extension |
| 579 | // categories on error. This breaks an AST invariant, and should not be |
| 580 | // fixed. |
| 581 | assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || |
| 582 | isa<ObjCCategoryDecl>(DC)) && |
| 583 | "Invalid ivar decl context!"); |
| 584 | } |
| 585 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 586 | return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 589 | const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { |
| 590 | const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 591 | |
Daniel Dunbar | 27a961a | 2010-04-02 21:13:59 +0000 | [diff] [blame] | 592 | switch (DC->getKind()) { |
| 593 | default: |
| 594 | case ObjCCategoryImpl: |
| 595 | case ObjCProtocol: |
| 596 | assert(0 && "invalid ivar container!"); |
| 597 | return 0; |
| 598 | |
| 599 | // Ivars can only appear in class extension categories. |
| 600 | case ObjCCategory: { |
| 601 | const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); |
| 602 | assert(CD->IsClassExtension() && "invalid container for ivar!"); |
| 603 | return CD->getClassInterface(); |
| 604 | } |
| 605 | |
| 606 | case ObjCImplementation: |
| 607 | return cast<ObjCImplementationDecl>(DC)->getClassInterface(); |
| 608 | |
| 609 | case ObjCInterface: |
| 610 | return cast<ObjCInterfaceDecl>(DC); |
| 611 | } |
| 612 | } |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 613 | |
| 614 | //===----------------------------------------------------------------------===// |
| 615 | // ObjCAtDefsFieldDecl |
| 616 | //===----------------------------------------------------------------------===// |
| 617 | |
| 618 | ObjCAtDefsFieldDecl |
| 619 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 620 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 621 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
| 622 | } |
| 623 | |
| 624 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 625 | this->~ObjCAtDefsFieldDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | C.Deallocate((void *)this); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | //===----------------------------------------------------------------------===// |
| 630 | // ObjCProtocolDecl |
| 631 | //===----------------------------------------------------------------------===// |
| 632 | |
| 633 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | SourceLocation L, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 635 | IdentifierInfo *Id) { |
| 636 | return new (C) ObjCProtocolDecl(DC, L, Id); |
| 637 | } |
| 638 | |
| 639 | void ObjCProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 640 | ReferencedProtocols.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 641 | ObjCContainerDecl::Destroy(C); |
| 642 | } |
| 643 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 644 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 645 | ObjCProtocolDecl *PDecl = this; |
| 646 | |
| 647 | if (Name == getIdentifier()) |
| 648 | return PDecl; |
| 649 | |
| 650 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 651 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 652 | return PDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 654 | return NULL; |
| 655 | } |
| 656 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 657 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 658 | // it inherited. |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 659 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 660 | bool isInstance) const { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 661 | ObjCMethodDecl *MethodDecl = NULL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 663 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 664 | return MethodDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 666 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 667 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 668 | return MethodDecl; |
| 669 | return NULL; |
| 670 | } |
| 671 | |
| 672 | //===----------------------------------------------------------------------===// |
| 673 | // ObjCClassDecl |
| 674 | //===----------------------------------------------------------------------===// |
| 675 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 677 | ObjCInterfaceDecl *const *Elts, |
| 678 | const SourceLocation *Locs, |
| 679 | unsigned nElts, |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 680 | ASTContext &C) |
| 681 | : Decl(ObjCClass, DC, L) { |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 682 | setClassList(C, Elts, Locs, nElts); |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 685 | void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List, |
| 686 | const SourceLocation *Locs, unsigned Num) { |
| 687 | ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num, |
| 688 | llvm::alignof<ObjCClassRef>()); |
| 689 | for (unsigned i = 0; i < Num; ++i) |
| 690 | new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]); |
| 691 | |
| 692 | NumDecls = Num; |
| 693 | } |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 694 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 695 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 696 | SourceLocation L, |
| 697 | ObjCInterfaceDecl *const *Elts, |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 698 | const SourceLocation *Locs, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 699 | unsigned nElts) { |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 700 | return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void ObjCClassDecl::Destroy(ASTContext &C) { |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 704 | // ObjCInterfaceDecls registered with a DeclContext will get destroyed |
| 705 | // when the DeclContext is destroyed. For those created only by a forward |
| 706 | // declaration, the first @class that created the ObjCInterfaceDecl gets |
| 707 | // to destroy it. |
| 708 | // FIXME: Note that this ownership role is very brittle; a better |
| 709 | // polict is surely need in the future. |
| 710 | for (iterator I = begin(), E = end(); I !=E ; ++I) { |
| 711 | ObjCInterfaceDecl *ID = I->getInterface(); |
| 712 | if (ID->isForwardDecl() && ID->getLocStart() == getLocStart()) |
| 713 | ID->Destroy(C); |
| 714 | } |
| 715 | |
| 716 | C.Deallocate(ForwardDecls); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 717 | Decl::Destroy(C); |
| 718 | } |
| 719 | |
Ted Kremenek | 2dbdd62 | 2009-11-18 01:26:56 +0000 | [diff] [blame] | 720 | SourceRange ObjCClassDecl::getSourceRange() const { |
| 721 | // FIXME: We should include the semicolon |
| 722 | assert(NumDecls); |
| 723 | return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation()); |
| 724 | } |
| 725 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 726 | //===----------------------------------------------------------------------===// |
| 727 | // ObjCForwardProtocolDecl |
| 728 | //===----------------------------------------------------------------------===// |
| 729 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 730 | ObjCForwardProtocolDecl:: |
| 731 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 732 | ObjCProtocolDecl *const *Elts, unsigned nElts, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 733 | const SourceLocation *Locs, ASTContext &C) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | : Decl(ObjCForwardProtocol, DC, L) { |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 735 | ReferencedProtocols.set(Elts, nElts, Locs, C); |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 739 | ObjCForwardProtocolDecl * |
| 740 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | SourceLocation L, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 742 | ObjCProtocolDecl *const *Elts, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 743 | unsigned NumElts, |
| 744 | const SourceLocation *Locs) { |
| 745 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 749 | ReferencedProtocols.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 750 | Decl::Destroy(C); |
| 751 | } |
| 752 | |
| 753 | //===----------------------------------------------------------------------===// |
| 754 | // ObjCCategoryDecl |
| 755 | //===----------------------------------------------------------------------===// |
| 756 | |
| 757 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 758 | SourceLocation AtLoc, |
| 759 | SourceLocation ClassNameLoc, |
| 760 | SourceLocation CategoryNameLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 761 | IdentifierInfo *Id) { |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 762 | return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 765 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 766 | return getASTContext().getObjCImplementation( |
| 767 | const_cast<ObjCCategoryDecl*>(this)); |
| 768 | } |
| 769 | |
| 770 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 771 | getASTContext().setObjCImplementation(this, ImplD); |
| 772 | } |
| 773 | |
| 774 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 775 | //===----------------------------------------------------------------------===// |
| 776 | // ObjCCategoryImplDecl |
| 777 | //===----------------------------------------------------------------------===// |
| 778 | |
| 779 | ObjCCategoryImplDecl * |
| 780 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
| 781 | SourceLocation L,IdentifierInfo *Id, |
| 782 | ObjCInterfaceDecl *ClassInterface) { |
| 783 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
| 784 | } |
| 785 | |
Steve Naroff | 0d69b8c | 2009-10-29 21:11:04 +0000 | [diff] [blame] | 786 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 787 | // The class interface might be NULL if we are working with invalid code. |
| 788 | if (const ObjCInterfaceDecl *ID = getClassInterface()) |
| 789 | return ID->FindCategoryDeclaration(getIdentifier()); |
| 790 | return 0; |
Argyrios Kyrtzidis | 4292073 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 793 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 794 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 795 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 796 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 797 | addDecl(property); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 800 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 801 | ASTContext &Ctx = getASTContext(); |
| 802 | |
| 803 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 804 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 805 | if (IFace) |
| 806 | Ctx.setObjCImplementation(IFace, ImplD); |
| 807 | |
Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 808 | } else if (ObjCCategoryImplDecl *ImplD = |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 809 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 810 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 811 | Ctx.setObjCImplementation(CD, ImplD); |
| 812 | } |
| 813 | |
| 814 | ClassInterface = IFace; |
| 815 | } |
| 816 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 817 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | d6eed1c | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 818 | /// properties implemented in this category @implementation block and returns |
| 819 | /// the implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 820 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 821 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 822 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 823 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 824 | ObjCPropertyImplDecl *PID = *i; |
| 825 | if (PID->getPropertyIvarDecl() && |
| 826 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 827 | return PID; |
| 828 | } |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 833 | /// added to the list of those properties @synthesized/@dynamic in this |
| 834 | /// category @implementation block. |
| 835 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 836 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 837 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 838 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 839 | ObjCPropertyImplDecl *PID = *i; |
| 840 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 841 | return PID; |
| 842 | } |
| 843 | return 0; |
| 844 | } |
| 845 | |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame^] | 846 | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
| 847 | const ObjCCategoryImplDecl *CID) { |
| 848 | OS << CID->getName(); |
| 849 | return OS; |
| 850 | } |
| 851 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 852 | //===----------------------------------------------------------------------===// |
| 853 | // ObjCImplementationDecl |
| 854 | //===----------------------------------------------------------------------===// |
| 855 | |
| 856 | ObjCImplementationDecl * |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 858 | SourceLocation L, |
| 859 | ObjCInterfaceDecl *ClassInterface, |
| 860 | ObjCInterfaceDecl *SuperDecl) { |
| 861 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); |
| 862 | } |
| 863 | |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame^] | 864 | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
| 865 | const ObjCImplementationDecl *ID) { |
| 866 | OS << ID->getName(); |
| 867 | return OS; |
| 868 | } |
| 869 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 870 | //===----------------------------------------------------------------------===// |
| 871 | // ObjCCompatibleAliasDecl |
| 872 | //===----------------------------------------------------------------------===// |
| 873 | |
| 874 | ObjCCompatibleAliasDecl * |
| 875 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 876 | SourceLocation L, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | IdentifierInfo *Id, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 878 | ObjCInterfaceDecl* AliasedClass) { |
| 879 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 880 | } |
| 881 | |
| 882 | //===----------------------------------------------------------------------===// |
| 883 | // ObjCPropertyDecl |
| 884 | //===----------------------------------------------------------------------===// |
| 885 | |
| 886 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 887 | SourceLocation L, |
| 888 | IdentifierInfo *Id, |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 889 | SourceLocation AtLoc, |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 890 | QualType T, |
| 891 | PropertyControl propControl) { |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 892 | return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
| 896 | //===----------------------------------------------------------------------===// |
| 897 | // ObjCPropertyImplDecl |
| 898 | //===----------------------------------------------------------------------===// |
| 899 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 900 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 901 | DeclContext *DC, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 902 | SourceLocation atLoc, |
| 903 | SourceLocation L, |
| 904 | ObjCPropertyDecl *property, |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 905 | Kind PK, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 906 | ObjCIvarDecl *ivar) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 907 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 908 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 909 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 910 | |