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. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 33 | |
| 34 | |
Chris Lattner | cf6c828 | 2009-02-20 21:44:01 +0000 | [diff] [blame] | 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; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 86 | |
Fariborz Jahanian | faca5e2 | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 87 | const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this); |
| 88 | if (PID) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 89 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 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 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 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 | |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 148 | /// lookupMethod - This method returns an instance/class method by looking in |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 149 | /// the class, its categories, and its super classes (using a linear search). |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 150 | ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, |
| 151 | bool isInstance) const { |
| 152 | const ObjCInterfaceDecl* ClassDecl = this; |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 153 | ObjCMethodDecl *MethodDecl = 0; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 154 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 155 | while (ClassDecl != NULL) { |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 156 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 157 | return MethodDecl; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 158 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 159 | // Didn't find one yet - look through protocols. |
Chris Lattner | 8bcb525 | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 160 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 161 | ClassDecl->getReferencedProtocols(); |
| 162 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 163 | E = Protocols.end(); I != E; ++I) |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 164 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 165 | return MethodDecl; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 166 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 167 | // Didn't find one yet - now look through categories. |
| 168 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 169 | while (CatDecl) { |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 170 | if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 171 | return MethodDecl; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 172 | |
Steve Naroff | af15180 | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 173 | // Didn't find one yet - look through protocols. |
| 174 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 175 | CatDecl->getReferencedProtocols(); |
| 176 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 177 | E = Protocols.end(); I != E; ++I) |
Argiris Kirtzidis | 9ac39f3 | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 178 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Steve Naroff | 0ba2484 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 179 | return MethodDecl; |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 180 | CatDecl = CatDecl->getNextClassCategory(); |
| 181 | } |
| 182 | ClassDecl = ClassDecl->getSuperClass(); |
| 183 | } |
| 184 | return NULL; |
| 185 | } |
| 186 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 187 | |
| 188 | |
| 189 | //===----------------------------------------------------------------------===// |
| 190 | // ObjCMethodDecl |
| 191 | //===----------------------------------------------------------------------===// |
| 192 | |
| 193 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 194 | SourceLocation beginLoc, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 195 | SourceLocation endLoc, |
| 196 | Selector SelInfo, QualType T, |
| 197 | DeclContext *contextDecl, |
| 198 | bool isInstance, |
| 199 | bool isVariadic, |
| 200 | bool isSynthesized, |
| 201 | ImplementationControl impControl) { |
| 202 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
| 203 | SelInfo, T, contextDecl, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 204 | isInstance, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 205 | isVariadic, isSynthesized, impControl); |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 208 | void ObjCMethodDecl::Destroy(ASTContext &C) { |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 209 | if (Body) Body->Destroy(C); |
| 210 | if (SelfDecl) SelfDecl->Destroy(C); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 211 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 212 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 213 | if (*I) (*I)->Destroy(C); |
| 214 | |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 215 | ParamInfo.Destroy(C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 216 | |
| 217 | Decl::Destroy(C); |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Argiris Kirtzidis | 29c3387 | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 220 | /// \brief A definition will return its interface declaration. |
| 221 | /// An interface declaration will return its definition. |
| 222 | /// Otherwise it will return itself. |
| 223 | ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { |
| 224 | ASTContext &Ctx = getASTContext(); |
| 225 | ObjCMethodDecl *Redecl = 0; |
| 226 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 227 | |
| 228 | if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { |
| 229 | if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) |
| 230 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 231 | |
| 232 | } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { |
| 233 | if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) |
| 234 | Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); |
| 235 | |
Argiris Kirtzidis | 0f3b842 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 236 | } else if (ObjCImplementationDecl *ImplD = |
| 237 | dyn_cast<ObjCImplementationDecl>(CtxD)) { |
Argiris Kirtzidis | 29c3387 | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 238 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 239 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); |
Argiris Kirtzidis | 0f3b842 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 240 | |
| 241 | } else if (ObjCCategoryImplDecl *CImplD = |
| 242 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
| 243 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryClass()) |
| 244 | Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); |
Argiris Kirtzidis | 29c3387 | 2009-07-21 00:06:36 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return Redecl ? Redecl : this; |
| 248 | } |
| 249 | |
Argiris Kirtzidis | 029f787 | 2009-07-28 05:11:17 +0000 | [diff] [blame] | 250 | ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { |
| 251 | Decl *CtxD = cast<Decl>(getDeclContext()); |
| 252 | |
| 253 | if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { |
| 254 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) |
| 255 | if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), |
| 256 | isInstanceMethod())) |
| 257 | return MD; |
| 258 | |
| 259 | } else if (ObjCCategoryImplDecl *CImplD = |
| 260 | dyn_cast<ObjCCategoryImplDecl>(CtxD)) { |
| 261 | if (ObjCCategoryDecl *CatD = CImplD->getCategoryClass()) |
| 262 | if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), |
| 263 | isInstanceMethod())) |
| 264 | return MD; |
| 265 | } |
| 266 | |
| 267 | return this; |
| 268 | } |
| 269 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 270 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 271 | const ObjCInterfaceDecl *OID) { |
| 272 | QualType selfTy; |
| 273 | if (isInstanceMethod()) { |
| 274 | // There may be no interface context due to error in declaration |
| 275 | // of the interface (which has been reported). Recover gracefully. |
| 276 | if (OID) { |
Daniel Dunbar | be1ff27 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 277 | selfTy = Context.getObjCInterfaceType(OID); |
Steve Naroff | 329ec22 | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 278 | selfTy = Context.getObjCObjectPointerType(selfTy); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 279 | } else { |
| 280 | selfTy = Context.getObjCIdType(); |
| 281 | } |
| 282 | } else // we have a factory method. |
| 283 | selfTy = Context.getObjCClassType(); |
| 284 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 285 | setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
Steve Naroff | 79ea0e0 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 286 | &Context.Idents.get("self"), selfTy)); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 287 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 288 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), |
| 289 | &Context.Idents.get("_cmd"), |
Steve Naroff | 79ea0e0 | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 290 | Context.getObjCSelType())); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 293 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
| 294 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
| 295 | return ID; |
| 296 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
| 297 | return CD->getClassInterface(); |
Argiris Kirtzidis | a06e3ba | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 298 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 299 | return IMD->getClassInterface(); |
Argiris Kirtzidis | a06e3ba | 2009-07-28 05:10:52 +0000 | [diff] [blame] | 300 | |
| 301 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 302 | assert(false && "unknown method context"); |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 306 | //===----------------------------------------------------------------------===// |
| 307 | // ObjCInterfaceDecl |
| 308 | //===----------------------------------------------------------------------===// |
| 309 | |
| 310 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
| 311 | DeclContext *DC, |
| 312 | SourceLocation atLoc, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 313 | IdentifierInfo *Id, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 314 | SourceLocation ClassLoc, |
| 315 | bool ForwardDecl, bool isInternal){ |
| 316 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
| 317 | isInternal); |
| 318 | } |
| 319 | |
| 320 | ObjCInterfaceDecl:: |
| 321 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
| 322 | SourceLocation CLoc, bool FD, bool isInternal) |
| 323 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), |
| 324 | TypeForDecl(0), SuperClass(0), |
| 325 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), |
| 326 | ClassLoc(CLoc) { |
| 327 | } |
| 328 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 329 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { |
Chris Lattner | eff36ed | 2009-03-31 08:36:08 +0000 | [diff] [blame] | 330 | for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I) |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 331 | if (*I) (*I)->Destroy(C); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 332 | |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 333 | IVars.Destroy(C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 334 | // FIXME: CategoryList? |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 335 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 336 | // FIXME: Because there is no clear ownership |
| 337 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 338 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
| 339 | Decl::Destroy(C); |
| 340 | } |
| 341 | |
Argiris Kirtzidis | 3a4d983 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 342 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { |
| 343 | return getASTContext().getObjCImplementation( |
| 344 | const_cast<ObjCInterfaceDecl*>(this)); |
| 345 | } |
| 346 | |
| 347 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { |
| 348 | getASTContext().setObjCImplementation(this, ImplD); |
| 349 | } |
| 350 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 351 | |
| 352 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 353 | /// categories for this class and returns it. Name of the category is passed |
| 354 | /// in 'CategoryId'. If category not found, return 0; |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 355 | /// |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 356 | ObjCCategoryDecl * |
| 357 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 358 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 359 | Category; Category = Category->getNextClassCategory()) |
| 360 | if (Category->getIdentifier() == CategoryId) |
| 361 | return Category; |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
Argiris Kirtzidis | 2009686 | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 365 | ObjCMethodDecl * |
| 366 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { |
| 367 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 368 | Category; Category = Category->getNextClassCategory()) |
| 369 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 370 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) |
| 371 | return MD; |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { |
| 376 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 377 | Category; Category = Category->getNextClassCategory()) |
| 378 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) |
| 379 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) |
| 380 | return MD; |
| 381 | return 0; |
| 382 | } |
| 383 | |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 384 | /// ClassImplementsProtocol - Checks that 'lProto' protocol |
| 385 | /// has been implemented in IDecl class, its super class or categories (if |
| 386 | /// lookupCategory is true). |
| 387 | bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, |
| 388 | bool lookupCategory, |
| 389 | bool RHSIsQualifiedID) { |
| 390 | ObjCInterfaceDecl *IDecl = this; |
| 391 | // 1st, look up the class. |
| 392 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 393 | IDecl->getReferencedProtocols(); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 394 | |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 395 | for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(), |
| 396 | E = Protocols.end(); PI != E; ++PI) { |
| 397 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 398 | return true; |
| 399 | // This is dubious and is added to be compatible with gcc. In gcc, it is |
| 400 | // also allowed assigning a protocol-qualified 'id' type to a LHS object |
| 401 | // when protocol in qualified LHS is in list of protocols in the rhs 'id' |
| 402 | // object. This IMO, should be a bug. |
| 403 | // FIXME: Treat this as an extension, and flag this as an error when GCC |
| 404 | // extensions are not enabled. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 405 | if (RHSIsQualifiedID && |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 406 | getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) |
| 407 | return true; |
| 408 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 409 | |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 410 | // 2nd, look up the category. |
| 411 | if (lookupCategory) |
| 412 | for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; |
| 413 | CDecl = CDecl->getNextClassCategory()) { |
| 414 | for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), |
| 415 | E = CDecl->protocol_end(); PI != E; ++PI) |
| 416 | if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) |
| 417 | return true; |
| 418 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 419 | |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 420 | // 3rd, look up the super class(s) |
| 421 | if (IDecl->getSuperClass()) |
| 422 | return |
| 423 | IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, |
| 424 | RHSIsQualifiedID); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 425 | |
Fariborz Jahanian | 92c7b16 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 429 | //===----------------------------------------------------------------------===// |
| 430 | // ObjCIvarDecl |
| 431 | //===----------------------------------------------------------------------===// |
| 432 | |
| 433 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC, |
| 434 | SourceLocation L, IdentifierInfo *Id, |
Argiris Kirtzidis | b17120c | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 435 | QualType T, DeclaratorInfo *DInfo, |
| 436 | AccessControl ac, Expr *BW) { |
| 437 | return new (C) ObjCIvarDecl(DC, L, Id, T, DInfo, ac, BW); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
| 441 | |
| 442 | //===----------------------------------------------------------------------===// |
| 443 | // ObjCAtDefsFieldDecl |
| 444 | //===----------------------------------------------------------------------===// |
| 445 | |
| 446 | ObjCAtDefsFieldDecl |
| 447 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 448 | IdentifierInfo *Id, QualType T, Expr *BW) { |
| 449 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
| 450 | } |
| 451 | |
| 452 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 453 | this->~ObjCAtDefsFieldDecl(); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 454 | C.Deallocate((void *)this); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | //===----------------------------------------------------------------------===// |
| 458 | // ObjCProtocolDecl |
| 459 | //===----------------------------------------------------------------------===// |
| 460 | |
| 461 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 462 | SourceLocation L, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 463 | IdentifierInfo *Id) { |
| 464 | return new (C) ObjCProtocolDecl(DC, L, Id); |
| 465 | } |
| 466 | |
| 467 | void ObjCProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 468 | ReferencedProtocols.Destroy(C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 469 | ObjCContainerDecl::Destroy(C); |
| 470 | } |
| 471 | |
Steve Naroff | 98e71b8 | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 472 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { |
| 473 | ObjCProtocolDecl *PDecl = this; |
| 474 | |
| 475 | if (Name == getIdentifier()) |
| 476 | return PDecl; |
| 477 | |
| 478 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
| 479 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) |
| 480 | return PDecl; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 481 | |
Steve Naroff | 98e71b8 | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 482 | return NULL; |
| 483 | } |
| 484 | |
Argiris Kirtzidis | aba400c | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 485 | // lookupMethod - Lookup a instance/class method in the protocol and protocols |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 486 | // it inherited. |
Argiris Kirtzidis | aba400c | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 487 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, |
| 488 | bool isInstance) const { |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 489 | ObjCMethodDecl *MethodDecl = NULL; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 490 | |
Argiris Kirtzidis | aba400c | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 491 | if ((MethodDecl = getMethod(Sel, isInstance))) |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 492 | return MethodDecl; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 493 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 494 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Argiris Kirtzidis | aba400c | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 495 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 496 | return MethodDecl; |
| 497 | return NULL; |
| 498 | } |
| 499 | |
| 500 | //===----------------------------------------------------------------------===// |
| 501 | // ObjCClassDecl |
| 502 | //===----------------------------------------------------------------------===// |
| 503 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 504 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 505 | ObjCInterfaceDecl *const *Elts, unsigned nElts, |
| 506 | ASTContext &C) |
| 507 | : Decl(ObjCClass, DC, L) { |
| 508 | ForwardDecls.set(Elts, nElts, C); |
| 509 | } |
| 510 | |
| 511 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 512 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
| 513 | SourceLocation L, |
| 514 | ObjCInterfaceDecl *const *Elts, |
| 515 | unsigned nElts) { |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 516 | return new (C) ObjCClassDecl(DC, L, Elts, nElts, C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void ObjCClassDecl::Destroy(ASTContext &C) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 520 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 521 | // FIXME: There is no clear ownership policy now for referenced |
| 522 | // ObjCInterfaceDecls. Some of them can be forward declarations that |
| 523 | // are never later defined (in which case the ObjCClassDecl owns them) |
| 524 | // or the ObjCInterfaceDecl later becomes a real definition later. Ideally |
| 525 | // we should have separate objects for forward declarations and definitions, |
| 526 | // obviating this problem. Because of this situation, referenced |
| 527 | // ObjCInterfaceDecls are destroyed in ~TranslationUnit. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 528 | |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 529 | ForwardDecls.Destroy(C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 530 | Decl::Destroy(C); |
| 531 | } |
| 532 | |
| 533 | //===----------------------------------------------------------------------===// |
| 534 | // ObjCForwardProtocolDecl |
| 535 | //===----------------------------------------------------------------------===// |
| 536 | |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 537 | ObjCForwardProtocolDecl:: |
| 538 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 539 | ObjCProtocolDecl *const *Elts, unsigned nElts, |
| 540 | ASTContext &C) |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 541 | : Decl(ObjCForwardProtocol, DC, L) { |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 542 | ReferencedProtocols.set(Elts, nElts, C); |
| 543 | } |
| 544 | |
| 545 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 546 | ObjCForwardProtocolDecl * |
| 547 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 548 | SourceLocation L, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 549 | ObjCProtocolDecl *const *Elts, |
| 550 | unsigned NumElts) { |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 551 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { |
Chris Lattner | df6133b | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 555 | ReferencedProtocols.Destroy(C); |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 556 | Decl::Destroy(C); |
| 557 | } |
| 558 | |
| 559 | //===----------------------------------------------------------------------===// |
| 560 | // ObjCCategoryDecl |
| 561 | //===----------------------------------------------------------------------===// |
| 562 | |
| 563 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
| 564 | SourceLocation L, |
| 565 | IdentifierInfo *Id) { |
| 566 | return new (C) ObjCCategoryDecl(DC, L, Id); |
| 567 | } |
| 568 | |
Argiris Kirtzidis | 3a4d983 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 569 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { |
| 570 | return getASTContext().getObjCImplementation( |
| 571 | const_cast<ObjCCategoryDecl*>(this)); |
| 572 | } |
| 573 | |
| 574 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { |
| 575 | getASTContext().setObjCImplementation(this, ImplD); |
| 576 | } |
| 577 | |
| 578 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 579 | //===----------------------------------------------------------------------===// |
| 580 | // ObjCCategoryImplDecl |
| 581 | //===----------------------------------------------------------------------===// |
| 582 | |
| 583 | ObjCCategoryImplDecl * |
| 584 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
| 585 | SourceLocation L,IdentifierInfo *Id, |
| 586 | ObjCInterfaceDecl *ClassInterface) { |
| 587 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
| 588 | } |
| 589 | |
Argiris Kirtzidis | 0f3b842 | 2009-07-28 05:11:05 +0000 | [diff] [blame] | 590 | ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryClass() const { |
| 591 | return getClassInterface()->FindCategoryDeclaration(getIdentifier()); |
| 592 | } |
| 593 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 594 | |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 595 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { |
Douglas Gregor | bd336c5 | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 596 | // FIXME: The context should be correct before we get here. |
Douglas Gregor | cd19b57 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 597 | property->setLexicalDeclContext(this); |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 598 | addDecl(property); |
Douglas Gregor | cd19b57 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Argiris Kirtzidis | 3a4d983 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 601 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { |
| 602 | ASTContext &Ctx = getASTContext(); |
| 603 | |
| 604 | if (ObjCImplementationDecl *ImplD |
Duncan Sands | 57f4dfe | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 605 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { |
Argiris Kirtzidis | 3a4d983 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 606 | if (IFace) |
| 607 | Ctx.setObjCImplementation(IFace, ImplD); |
| 608 | |
Duncan Sands | 57f4dfe | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 609 | } else if (ObjCCategoryImplDecl *ImplD = |
Argiris Kirtzidis | 3a4d983 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 610 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { |
| 611 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) |
| 612 | Ctx.setObjCImplementation(CD, ImplD); |
| 613 | } |
| 614 | |
| 615 | ClassInterface = IFace; |
| 616 | } |
| 617 | |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 618 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | 715e848 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 619 | /// properties implemented in this category @implementation block and returns |
| 620 | /// the implemented property that uses it. |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 621 | /// |
Chris Lattner | 649b3da | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 622 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 623 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 624 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 625 | ObjCPropertyImplDecl *PID = *i; |
| 626 | if (PID->getPropertyIvarDecl() && |
| 627 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 628 | return PID; |
| 629 | } |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 634 | /// added to the list of those properties @synthesized/@dynamic in this |
| 635 | /// category @implementation block. |
| 636 | /// |
Chris Lattner | 649b3da | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 637 | ObjCPropertyImplDecl *ObjCImplDecl:: |
Argiris Kirtzidis | ab6e38a | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 638 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 639 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 640 | ObjCPropertyImplDecl *PID = *i; |
| 641 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 642 | return PID; |
| 643 | } |
| 644 | return 0; |
| 645 | } |
| 646 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 647 | //===----------------------------------------------------------------------===// |
| 648 | // ObjCImplementationDecl |
| 649 | //===----------------------------------------------------------------------===// |
| 650 | |
| 651 | ObjCImplementationDecl * |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 652 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 653 | SourceLocation L, |
| 654 | ObjCInterfaceDecl *ClassInterface, |
| 655 | ObjCInterfaceDecl *SuperDecl) { |
| 656 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); |
| 657 | } |
| 658 | |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 659 | //===----------------------------------------------------------------------===// |
| 660 | // ObjCCompatibleAliasDecl |
| 661 | //===----------------------------------------------------------------------===// |
| 662 | |
| 663 | ObjCCompatibleAliasDecl * |
| 664 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
| 665 | SourceLocation L, |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 666 | IdentifierInfo *Id, |
Chris Lattner | 13f6360 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 667 | ObjCInterfaceDecl* AliasedClass) { |
| 668 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
| 669 | } |
| 670 | |
| 671 | //===----------------------------------------------------------------------===// |
| 672 | // ObjCPropertyDecl |
| 673 | //===----------------------------------------------------------------------===// |
| 674 | |
| 675 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
| 676 | SourceLocation L, |
| 677 | IdentifierInfo *Id, |
| 678 | QualType T, |
| 679 | PropertyControl propControl) { |
| 680 | return new (C) ObjCPropertyDecl(DC, L, Id, T); |
| 681 | } |
| 682 | |
| 683 | |
| 684 | //===----------------------------------------------------------------------===// |
| 685 | // ObjCPropertyImplDecl |
| 686 | //===----------------------------------------------------------------------===// |
| 687 | |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 688 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 689 | DeclContext *DC, |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 690 | SourceLocation atLoc, |
| 691 | SourceLocation L, |
| 692 | ObjCPropertyDecl *property, |
Daniel Dunbar | 14117fc | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 693 | Kind PK, |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 694 | ObjCIvarDecl *ivar) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 695 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 696 | } |
Chris Lattner | 4485961 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 697 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 698 | |