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