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. |
| 33 | |
Chris Lattner | 4ee413b | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 34 | |
| 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 | |
| 40 | |
| 41 | //===----------------------------------------------------------------------===// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 42 | // ObjCInterfaceDecl |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 43 | //===----------------------------------------------------------------------===// |
| 44 | |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 45 | /// getIvarDecl - This method looks up an ivar in this ContextDecl. |
| 46 | /// |
| 47 | ObjCIvarDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 48 | ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 49 | lookup_const_iterator Ivar, IvarEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 50 | for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 51 | if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) |
| 52 | return ivar; |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 57 | // Get the local instance method declared in this interface. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 58 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 59 | ObjCContainerDecl::getInstanceMethod(Selector Sel) const { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 60 | // Since instance & class methods can have the same name, the loop below |
| 61 | // ensures we get the correct method. |
| 62 | // |
| 63 | // @interface Whatever |
| 64 | // - (int) class_method; |
| 65 | // + (float) class_method; |
| 66 | // @end |
| 67 | // |
| 68 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 69 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 70 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 71 | if (MD && MD->isInstanceMethod()) |
| 72 | return MD; |
| 73 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | // Get the local class method declared in this interface. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 78 | ObjCMethodDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 79 | ObjCContainerDecl::getClassMethod(Selector Sel) const { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 80 | // Since instance & class methods can have the same name, the loop below |
| 81 | // ensures we get the correct method. |
| 82 | // |
| 83 | // @interface Whatever |
| 84 | // - (int) class_method; |
| 85 | // + (float) class_method; |
| 86 | // @end |
| 87 | // |
| 88 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 89 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 90 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 91 | if (MD && MD->isClassMethod()) |
| 92 | return MD; |
| 93 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 97 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 98 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Steve Naroff | 93983f8 | 2009-01-11 12:47:58 +0000 | [diff] [blame] | 99 | /// FIXME: Convert to DeclContext lookup... |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 100 | /// |
| 101 | ObjCPropertyDecl * |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 102 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
| 103 | for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 104 | if ((*I)->getIdentifier() == PropertyId) |
| 105 | return *I; |
| 106 | |
Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 107 | const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this); |
| 108 | if (PID) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 109 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 110 | E = PID->protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 111 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 112 | return P; |
Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 115 | if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) { |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 116 | // Look through categories. |
| 117 | for (ObjCCategoryDecl *Category = OID->getCategoryList(); |
| 118 | Category; Category = Category->getNextClassCategory()) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 119 | if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId)) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 120 | return P; |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 121 | } |
| 122 | // Look through protocols. |
| 123 | for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(), |
| 124 | E = OID->protocol_end(); I != E; ++I) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 125 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 126 | return P; |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 127 | } |
| 128 | if (OID->getSuperClass()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 129 | return OID->getSuperClass()->FindPropertyDeclaration(PropertyId); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 130 | } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) { |
Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 131 | // Look through protocols. |
| 132 | for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(), |
| 133 | E = OCD->protocol_end(); I != E; ++I) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 134 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 135 | return P; |
Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 141 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, |
| 142 | ObjCInterfaceDecl *&clsDeclared) { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 143 | ObjCInterfaceDecl* ClassDecl = this; |
| 144 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 145 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { |
Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 146 | clsDeclared = ClassDecl; |
| 147 | return I; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 148 | } |
| 149 | ClassDecl = ClassDecl->getSuperClass(); |
| 150 | } |
| 151 | return NULL; |
| 152 | } |
| 153 | |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 154 | /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super |
| 155 | /// class whose name is passed as argument. If it is not one of the super classes |
| 156 | /// the it returns NULL. |
| 157 | ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( |
| 158 | const IdentifierInfo*ICName) { |
| 159 | ObjCInterfaceDecl* ClassDecl = this; |
| 160 | while (ClassDecl != NULL) { |
| 161 | if (ClassDecl->getIdentifier() == ICName) |
| 162 | return ClassDecl; |
| 163 | ClassDecl = ClassDecl->getSuperClass(); |
| 164 | } |
| 165 | return NULL; |
| 166 | } |
| 167 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 168 | /// lookupInstanceMethod - This method returns an instance method by looking in |
| 169 | /// the class, its categories, and its super classes (using a linear search). |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 170 | ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 171 | ObjCInterfaceDecl* ClassDecl = this; |
| 172 | ObjCMethodDecl *MethodDecl = 0; |
| 173 | |
| 174 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 175 | if ((MethodDecl = ClassDecl->getInstanceMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 176 | return MethodDecl; |
| 177 | |
| 178 | // Didn't find one yet - look through protocols. |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 179 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 180 | ClassDecl->getReferencedProtocols(); |
| 181 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 182 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 183 | if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 184 | return MethodDecl; |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 186 | // Didn't find one yet - now look through categories. |
| 187 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 188 | while (CatDecl) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 189 | if ((MethodDecl = CatDecl->getInstanceMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 190 | return MethodDecl; |
Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 191 | |
| 192 | // Didn't find one yet - look through protocols. |
| 193 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 194 | CatDecl->getReferencedProtocols(); |
| 195 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 196 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 197 | if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) |
Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 198 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 199 | CatDecl = CatDecl->getNextClassCategory(); |
| 200 | } |
| 201 | ClassDecl = ClassDecl->getSuperClass(); |
| 202 | } |
| 203 | return NULL; |
| 204 | } |
| 205 | |
| 206 | // lookupClassMethod - This method returns a class method by looking in the |
| 207 | // class, its categories, and its super classes (using a linear search). |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 208 | ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 209 | ObjCInterfaceDecl* ClassDecl = this; |
| 210 | ObjCMethodDecl *MethodDecl = 0; |
| 211 | |
| 212 | while (ClassDecl != NULL) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 213 | if ((MethodDecl = ClassDecl->getClassMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 214 | return MethodDecl; |
| 215 | |
| 216 | // Didn't find one yet - look through protocols. |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 217 | for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), |
| 218 | E = ClassDecl->protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 219 | if ((MethodDecl = (*I)->lookupClassMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 220 | return MethodDecl; |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 222 | // Didn't find one yet - now look through categories. |
| 223 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 224 | while (CatDecl) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 225 | if ((MethodDecl = CatDecl->getClassMethod(Sel))) |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 226 | return MethodDecl; |
Steve Naroff | b558422 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 227 | |
| 228 | // Didn't find one yet - look through protocols. |
| 229 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 230 | CatDecl->getReferencedProtocols(); |
| 231 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 232 | E = Protocols.end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 233 | if ((MethodDecl = (*I)->lookupClassMethod(Sel))) |
Steve Naroff | b558422 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 234 | return MethodDecl; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 235 | CatDecl = CatDecl->getNextClassCategory(); |
| 236 | } |
| 237 | ClassDecl = ClassDecl->getSuperClass(); |
| 238 | } |
| 239 | return NULL; |
| 240 | } |
| 241 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 242 | |
| 243 | |
| 244 | //===----------------------------------------------------------------------===// |
| 245 | // ObjCMethodDecl |
| 246 | //===----------------------------------------------------------------------===// |
| 247 | |
| 248 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
| 249 | SourceLocation beginLoc, |
| 250 | SourceLocation endLoc, |
| 251 | Selector SelInfo, QualType T, |
| 252 | DeclContext *contextDecl, |
| 253 | bool isInstance, |
| 254 | bool isVariadic, |
| 255 | bool isSynthesized, |
| 256 | ImplementationControl impControl) { |
| 257 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
| 258 | SelInfo, T, contextDecl, |
| 259 | isInstance, |
| 260 | isVariadic, isSynthesized, impControl); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 263 | void ObjCMethodDecl::Destroy(ASTContext &C) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 264 | if (Body) Body->Destroy(C); |
| 265 | if (SelfDecl) SelfDecl->Destroy(C); |
| 266 | |
| 267 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 268 | if (*I) (*I)->Destroy(C); |
| 269 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 270 | ParamInfo.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 271 | |
| 272 | Decl::Destroy(C); |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 275 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
| 276 | const ObjCInterfaceDecl *OID) { |
| 277 | QualType selfTy; |
| 278 | if (isInstanceMethod()) { |
| 279 | // There may be no interface context due to error in declaration |
| 280 | // of the interface (which has been reported). Recover gracefully. |
| 281 | if (OID) { |
Daniel Dunbar | 3b3a458 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 282 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 283 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 284 | } else { |
| 285 | selfTy = Context.getObjCIdType(); |
| 286 | } |
| 287 | } else // we have a factory method. |
| 288 | selfTy = Context.getObjCClassType(); |
| 289 | |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 290 | setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 291 | &Context.Idents.get("self"), selfTy)); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 292 | |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 293 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 294 | &Context.Idents.get("_cmd"), |
| 295 | Context.getObjCSelType())); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
| 299 | |
| 300 | /// getSynthesizedMethodSize - Compute size of synthesized method name |
| 301 | /// as done be the rewrite. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 302 | /// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 303 | unsigned ObjCMethodDecl::getSynthesizedMethodSize() const { |
| 304 | // syntesized method name is a concatenation of -/+[class-name selector] |
| 305 | // Get length of this name. |
| 306 | unsigned length = 3; // _I_ or _C_ |
| 307 | length += getClassInterface()->getNameAsString().size()+1; // extra for _ |
| 308 | if (const ObjCCategoryImplDecl *CID = |
| 309 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
| 310 | length += CID->getNameAsString().size()+1; |
| 311 | length += getSelector().getAsString().size(); // selector name |
| 312 | return length; |
| 313 | } |
| 314 | |
| 315 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 316 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 317 | return ID; |
| 318 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 319 | return CD->getClassInterface(); |
| 320 | if (ObjCImplementationDecl *IMD = |
| 321 | dyn_cast<ObjCImplementationDecl>(getDeclContext())) |
| 322 | return IMD->getClassInterface(); |
| 323 | if (ObjCCategoryImplDecl *CID = |
| 324 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
| 325 | return CID->getClassInterface(); |
| 326 | assert(false && "unknown method context"); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 330 | //===----------------------------------------------------------------------===// |
| 331 | // ObjCInterfaceDecl |
| 332 | //===----------------------------------------------------------------------===// |
| 333 | |
| 334 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
| 335 | DeclContext *DC, |
| 336 | SourceLocation atLoc, |
| 337 | IdentifierInfo *Id, |
| 338 | SourceLocation ClassLoc, |
| 339 | bool ForwardDecl, bool isInternal){ |
| 340 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
| 341 | isInternal); |
| 342 | } |
| 343 | |
| 344 | ObjCInterfaceDecl:: |
| 345 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
| 346 | SourceLocation CLoc, bool FD, bool isInternal) |
| 347 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), |
| 348 | TypeForDecl(0), SuperClass(0), |
| 349 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), |
| 350 | ClassLoc(CLoc) { |
| 351 | } |
| 352 | |
| 353 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { |
Chris Lattner | d13d302 | 2009-03-31 08:36:08 +0000 | [diff] [blame] | 354 | for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 355 | if (*I) (*I)->Destroy(C); |
| 356 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 357 | IVars.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 358 | // FIXME: CategoryList? |
| 359 | |
| 360 | // FIXME: Because there is no clear ownership |
| 361 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 362 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
| 363 | Decl::Destroy(C); |
| 364 | } |
| 365 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 366 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
| 367 | return getASTContext().getObjCImplementation( |
| 368 | const_cast<ObjCInterfaceDecl*>(this)); |
| 369 | } |
| 370 | |
| 371 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 372 | getASTContext().setObjCImplementation(this, ImplD); |
| 373 | } |
| 374 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 375 | |
| 376 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 377 | /// categories for this class and returns it. Name of the category is passed |
| 378 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 379 | /// |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 380 | ObjCCategoryDecl * |
| 381 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 382 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 383 | Category; Category = Category->getNextClassCategory()) |
| 384 | if (Category->getIdentifier() == CategoryId) |
| 385 | return Category; |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | |
Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame^] | 389 | ObjCMethodDecl * |
| 390 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 391 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 392 | Category; Category = Category->getNextClassCategory()) |
| 393 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 394 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 395 | return MD; |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 400 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 401 | Category; Category = Category->getNextClassCategory()) |
| 402 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 403 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 404 | return MD; |
| 405 | return 0; |
| 406 | } |
| 407 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 408 | //===----------------------------------------------------------------------===// |
| 409 | // ObjCIvarDecl |
| 410 | //===----------------------------------------------------------------------===// |
| 411 | |
| 412 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC, |
| 413 | SourceLocation L, IdentifierInfo *Id, |
| 414 | QualType T, AccessControl ac, Expr *BW) { |
| 415 | return new (C) ObjCIvarDecl(DC, L, Id, T, ac, BW); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | |
| 420 | //===----------------------------------------------------------------------===// |
| 421 | // ObjCAtDefsFieldDecl |
| 422 | //===----------------------------------------------------------------------===// |
| 423 | |
| 424 | ObjCAtDefsFieldDecl |
| 425 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 426 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 427 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
| 428 | } |
| 429 | |
| 430 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 431 | this->~ObjCAtDefsFieldDecl(); |
| 432 | C.Deallocate((void *)this); |
| 433 | } |
| 434 | |
| 435 | //===----------------------------------------------------------------------===// |
| 436 | // ObjCProtocolDecl |
| 437 | //===----------------------------------------------------------------------===// |
| 438 | |
| 439 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
| 440 | SourceLocation L, |
| 441 | IdentifierInfo *Id) { |
| 442 | return new (C) ObjCProtocolDecl(DC, L, Id); |
| 443 | } |
| 444 | |
| 445 | void ObjCProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 446 | ReferencedProtocols.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 447 | ObjCContainerDecl::Destroy(C); |
| 448 | } |
| 449 | |
Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 450 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 451 | ObjCProtocolDecl *PDecl = this; |
| 452 | |
| 453 | if (Name == getIdentifier()) |
| 454 | return PDecl; |
| 455 | |
| 456 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 457 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 458 | return PDecl; |
| 459 | |
| 460 | return NULL; |
| 461 | } |
| 462 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 463 | // lookupInstanceMethod - Lookup a instance method in the protocol and protocols |
| 464 | // it inherited. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 465 | ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 466 | ObjCMethodDecl *MethodDecl = NULL; |
| 467 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 468 | if ((MethodDecl = getInstanceMethod(Sel))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 469 | return MethodDecl; |
| 470 | |
| 471 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 472 | if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 473 | return MethodDecl; |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | // lookupInstanceMethod - Lookup a class method in the protocol and protocols |
| 478 | // it inherited. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 479 | ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 480 | ObjCMethodDecl *MethodDecl = NULL; |
| 481 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 482 | if ((MethodDecl = getClassMethod(Sel))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 483 | return MethodDecl; |
| 484 | |
| 485 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 486 | if ((MethodDecl = (*I)->lookupClassMethod(Sel))) |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 487 | return MethodDecl; |
| 488 | return NULL; |
| 489 | } |
| 490 | |
| 491 | //===----------------------------------------------------------------------===// |
| 492 | // ObjCClassDecl |
| 493 | //===----------------------------------------------------------------------===// |
| 494 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 495 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
| 496 | ObjCInterfaceDecl *const *Elts, unsigned nElts, |
| 497 | ASTContext &C) |
| 498 | : Decl(ObjCClass, DC, L) { |
| 499 | ForwardDecls.set(Elts, nElts, C); |
| 500 | } |
| 501 | |
| 502 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 503 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 504 | SourceLocation L, |
| 505 | ObjCInterfaceDecl *const *Elts, |
| 506 | unsigned nElts) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 507 | return new (C) ObjCClassDecl(DC, L, Elts, nElts, C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void ObjCClassDecl::Destroy(ASTContext &C) { |
| 511 | |
| 512 | // FIXME: There is no clear ownership policy now for referenced |
| 513 | // ObjCInterfaceDecls. Some of them can be forward declarations that |
| 514 | // are never later defined (in which case the ObjCClassDecl owns them) |
| 515 | // or the ObjCInterfaceDecl later becomes a real definition later. Ideally |
| 516 | // we should have separate objects for forward declarations and definitions, |
| 517 | // obviating this problem. Because of this situation, referenced |
| 518 | // ObjCInterfaceDecls are destroyed in ~TranslationUnit. |
| 519 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 520 | ForwardDecls.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 521 | Decl::Destroy(C); |
| 522 | } |
| 523 | |
| 524 | //===----------------------------------------------------------------------===// |
| 525 | // ObjCForwardProtocolDecl |
| 526 | //===----------------------------------------------------------------------===// |
| 527 | |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 528 | ObjCForwardProtocolDecl:: |
| 529 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 530 | ObjCProtocolDecl *const *Elts, unsigned nElts, |
| 531 | ASTContext &C) |
| 532 | : Decl(ObjCForwardProtocol, DC, L) { |
| 533 | ReferencedProtocols.set(Elts, nElts, C); |
| 534 | } |
| 535 | |
| 536 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 537 | ObjCForwardProtocolDecl * |
| 538 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
| 539 | SourceLocation L, |
| 540 | ObjCProtocolDecl *const *Elts, |
| 541 | unsigned NumElts) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 542 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 546 | ReferencedProtocols.Destroy(C); |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 547 | Decl::Destroy(C); |
| 548 | } |
| 549 | |
| 550 | //===----------------------------------------------------------------------===// |
| 551 | // ObjCCategoryDecl |
| 552 | //===----------------------------------------------------------------------===// |
| 553 | |
| 554 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
| 555 | SourceLocation L, |
| 556 | IdentifierInfo *Id) { |
| 557 | return new (C) ObjCCategoryDecl(DC, L, Id); |
| 558 | } |
| 559 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 560 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 561 | return getASTContext().getObjCImplementation( |
| 562 | const_cast<ObjCCategoryDecl*>(this)); |
| 563 | } |
| 564 | |
| 565 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 566 | getASTContext().setObjCImplementation(this, ImplD); |
| 567 | } |
| 568 | |
| 569 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 570 | //===----------------------------------------------------------------------===// |
| 571 | // ObjCCategoryImplDecl |
| 572 | //===----------------------------------------------------------------------===// |
| 573 | |
| 574 | ObjCCategoryImplDecl * |
| 575 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
| 576 | SourceLocation L,IdentifierInfo *Id, |
| 577 | ObjCInterfaceDecl *ClassInterface) { |
| 578 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
| 579 | } |
| 580 | |
| 581 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 582 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 583 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 584 | property->setLexicalDeclContext(this); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 585 | addDecl(property); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 588 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 589 | ASTContext &Ctx = getASTContext(); |
| 590 | |
| 591 | if (ObjCImplementationDecl *ImplD |
| 592 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) |
| 593 | if (IFace) |
| 594 | Ctx.setObjCImplementation(IFace, ImplD); |
| 595 | |
| 596 | else if (ObjCCategoryImplDecl *ImplD = |
| 597 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 598 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 599 | Ctx.setObjCImplementation(CD, ImplD); |
| 600 | } |
| 601 | |
| 602 | ClassInterface = IFace; |
| 603 | } |
| 604 | |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 605 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | d6eed1c | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 606 | /// properties implemented in this category @implementation block and returns |
| 607 | /// the implemented property that uses it. |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 608 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 609 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 610 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 611 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 612 | ObjCPropertyImplDecl *PID = *i; |
| 613 | if (PID->getPropertyIvarDecl() && |
| 614 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 615 | return PID; |
| 616 | } |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 621 | /// added to the list of those properties @synthesized/@dynamic in this |
| 622 | /// category @implementation block. |
| 623 | /// |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 624 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 625 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 626 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 627 | ObjCPropertyImplDecl *PID = *i; |
| 628 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 629 | return PID; |
| 630 | } |
| 631 | return 0; |
| 632 | } |
| 633 | |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 634 | // getInstanceMethod - This method returns an instance method by looking in |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 635 | // the class implementation. Unlike interfaces, we don't look outside the |
| 636 | // implementation. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 637 | ObjCMethodDecl *ObjCImplDecl::getInstanceMethod(Selector Sel) const { |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 638 | // Since instance & class methods can have the same name, the loop below |
| 639 | // ensures we get the correct method. |
| 640 | // |
| 641 | // @interface Whatever |
| 642 | // - (int) class_method; |
| 643 | // + (float) class_method; |
| 644 | // @end |
| 645 | // |
| 646 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 647 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 648 | Meth != MethEnd; ++Meth) { |
| 649 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 650 | if (MD && MD->isInstanceMethod()) |
| 651 | return MD; |
| 652 | } |
| 653 | return 0; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 656 | // getClassMethod - This method returns an instance method by looking in |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 657 | // the class implementation. Unlike interfaces, we don't look outside the |
| 658 | // implementation. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 659 | ObjCMethodDecl *ObjCImplDecl::getClassMethod(Selector Sel) const { |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 660 | // Since instance & class methods can have the same name, the loop below |
| 661 | // ensures we get the correct method. |
| 662 | // |
| 663 | // @interface Whatever |
| 664 | // - (int) class_method; |
| 665 | // + (float) class_method; |
| 666 | // @end |
| 667 | // |
| 668 | lookup_const_iterator Meth, MethEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 669 | for (llvm::tie(Meth, MethEnd) = lookup(Sel); |
Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 670 | Meth != MethEnd; ++Meth) { |
| 671 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); |
| 672 | if (MD && MD->isClassMethod()) |
| 673 | return MD; |
| 674 | } |
| 675 | return 0; |
Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 678 | //===----------------------------------------------------------------------===// |
| 679 | // ObjCImplementationDecl |
| 680 | //===----------------------------------------------------------------------===// |
| 681 | |
| 682 | ObjCImplementationDecl * |
| 683 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
| 684 | SourceLocation L, |
| 685 | ObjCInterfaceDecl *ClassInterface, |
| 686 | ObjCInterfaceDecl *SuperDecl) { |
| 687 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); |
| 688 | } |
| 689 | |
Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 690 | //===----------------------------------------------------------------------===// |
| 691 | // ObjCCompatibleAliasDecl |
| 692 | //===----------------------------------------------------------------------===// |
| 693 | |
| 694 | ObjCCompatibleAliasDecl * |
| 695 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 696 | SourceLocation L, |
| 697 | IdentifierInfo *Id, |
| 698 | ObjCInterfaceDecl* AliasedClass) { |
| 699 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 700 | } |
| 701 | |
| 702 | //===----------------------------------------------------------------------===// |
| 703 | // ObjCPropertyDecl |
| 704 | //===----------------------------------------------------------------------===// |
| 705 | |
| 706 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 707 | SourceLocation L, |
| 708 | IdentifierInfo *Id, |
| 709 | QualType T, |
| 710 | PropertyControl propControl) { |
| 711 | return new (C) ObjCPropertyDecl(DC, L, Id, T); |
| 712 | } |
| 713 | |
| 714 | |
| 715 | //===----------------------------------------------------------------------===// |
| 716 | // ObjCPropertyImplDecl |
| 717 | //===----------------------------------------------------------------------===// |
| 718 | |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 719 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 720 | DeclContext *DC, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 721 | SourceLocation atLoc, |
| 722 | SourceLocation L, |
| 723 | ObjCPropertyDecl *property, |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 724 | Kind PK, |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 725 | ObjCIvarDecl *ivar) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 726 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 727 | } |
Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 728 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 729 | |