| 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 |  | 
| Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 57 | // Get the local instance/class method declared in this interface. | 
| Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 58 | ObjCMethodDecl * | 
| Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 59 | ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) 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); | 
| Argyrios Kyrtzidis | 467c0b1 | 2009-07-25 22:15:22 +0000 | [diff] [blame] | 71 | if (MD && MD->isInstanceMethod() == isInstance) | 
| Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 72 | return MD; | 
|  | 73 | } | 
| Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 74 | return 0; | 
|  | 75 | } | 
|  | 76 |  | 
| Fariborz Jahanian | 559c0c4 | 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 | 93983f8 | 2009-01-11 12:47:58 +0000 | [diff] [blame] | 79 | /// FIXME: Convert to DeclContext lookup... | 
| Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 80 | /// | 
|  | 81 | ObjCPropertyDecl * | 
| Argyrios Kyrtzidis | 17945a0 | 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 | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 84 | if ((*I)->getIdentifier() == PropertyId) | 
|  | 85 | return *I; | 
|  | 86 |  | 
| Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 87 | const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this); | 
|  | 88 | if (PID) { | 
| Chris Lattner | ab35163 | 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) | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 91 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 92 | return P; | 
| Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 93 | } | 
|  | 94 |  | 
| Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 95 | if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) { | 
| Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 96 | // Look through categories. | 
|  | 97 | for (ObjCCategoryDecl *Category = OID->getCategoryList(); | 
|  | 98 | Category; Category = Category->getNextClassCategory()) { | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 99 | if (ObjCPropertyDecl *P = Category->FindPropertyDeclaration(PropertyId)) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 100 | return P; | 
| Steve Naroff | 09c4719 | 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) { | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 105 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 106 | return P; | 
| Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 107 | } | 
|  | 108 | if (OID->getSuperClass()) | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 109 | return OID->getSuperClass()->FindPropertyDeclaration(PropertyId); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 110 | } else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) { | 
| Fariborz Jahanian | f034e9c | 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) { | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 114 | if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 115 | return P; | 
| Fariborz Jahanian | f034e9c | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 116 | } | 
|  | 117 | } | 
| Steve Naroff | 3d2c22b | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 118 | return 0; | 
|  | 119 | } | 
|  | 120 |  | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 121 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, | 
|  | 122 | ObjCInterfaceDecl *&clsDeclared) { | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 123 | ObjCInterfaceDecl* ClassDecl = this; | 
|  | 124 | while (ClassDecl != NULL) { | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 125 | if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { | 
| Fariborz Jahanian | 496b5a8 | 2009-06-05 18:16:35 +0000 | [diff] [blame] | 126 | clsDeclared = ClassDecl; | 
|  | 127 | return I; | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 128 | } | 
|  | 129 | ClassDecl = ClassDecl->getSuperClass(); | 
|  | 130 | } | 
|  | 131 | return NULL; | 
|  | 132 | } | 
|  | 133 |  | 
| Fariborz Jahanian | cd18762 | 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 |  | 
| Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 148 | /// lookupMethod - This method returns an instance/class method by looking in | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 149 | /// the class, its categories, and its super classes (using a linear search). | 
| Argyrios Kyrtzidis | aa5420c | 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 | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 153 | ObjCMethodDecl *MethodDecl = 0; | 
|  | 154 |  | 
|  | 155 | while (ClassDecl != NULL) { | 
| Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 156 | if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 157 | return MethodDecl; | 
|  | 158 |  | 
|  | 159 | // Didn't find one yet - look through protocols. | 
| Chris Lattner | 3db6cae | 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) | 
| Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 164 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 165 | return MethodDecl; | 
| Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 166 |  | 
| Chris Lattner | 1e03a56 | 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) { | 
| Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 170 | if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 171 | return MethodDecl; | 
| Steve Naroff | b79c01e | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 172 |  | 
|  | 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) | 
| Argyrios Kyrtzidis | aa5420c | 2009-07-25 22:15:51 +0000 | [diff] [blame] | 178 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) | 
| Steve Naroff | b558422 | 2009-02-26 11:32:02 +0000 | [diff] [blame] | 179 | return MethodDecl; | 
| Chris Lattner | 1e03a56 | 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 | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 187 |  | 
|  | 188 |  | 
|  | 189 | //===----------------------------------------------------------------------===// | 
|  | 190 | // ObjCMethodDecl | 
|  | 191 | //===----------------------------------------------------------------------===// | 
|  | 192 |  | 
|  | 193 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, | 
|  | 194 | SourceLocation beginLoc, | 
|  | 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, | 
|  | 204 | isInstance, | 
|  | 205 | isVariadic, isSynthesized, impControl); | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 208 | void ObjCMethodDecl::Destroy(ASTContext &C) { | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 209 | if (Body) Body->Destroy(C); | 
|  | 210 | if (SelfDecl) SelfDecl->Destroy(C); | 
|  | 211 |  | 
|  | 212 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) | 
|  | 213 | if (*I) (*I)->Destroy(C); | 
|  | 214 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 215 | ParamInfo.Destroy(C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 216 |  | 
|  | 217 | Decl::Destroy(C); | 
| Chris Lattner | 1e03a56 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 218 | } | 
|  | 219 |  | 
| Argyrios Kyrtzidis | 57ea6be | 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 |  | 
|  | 236 | } else if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(CtxD)) { | 
|  | 237 | if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) | 
|  | 238 | Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | return Redecl ? Redecl : this; | 
|  | 242 | } | 
|  | 243 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 244 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, | 
|  | 245 | const ObjCInterfaceDecl *OID) { | 
|  | 246 | QualType selfTy; | 
|  | 247 | if (isInstanceMethod()) { | 
|  | 248 | // There may be no interface context due to error in declaration | 
|  | 249 | // of the interface (which has been reported). Recover gracefully. | 
|  | 250 | if (OID) { | 
| Daniel Dunbar | 3b3a458 | 2009-04-22 04:34:53 +0000 | [diff] [blame] | 251 | selfTy = Context.getObjCInterfaceType(OID); | 
| Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 252 | selfTy = Context.getObjCObjectPointerType(selfTy); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 253 | } else { | 
|  | 254 | selfTy = Context.getObjCIdType(); | 
|  | 255 | } | 
|  | 256 | } else // we have a factory method. | 
|  | 257 | selfTy = Context.getObjCClassType(); | 
|  | 258 |  | 
| Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 259 | setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), | 
|  | 260 | &Context.Idents.get("self"), selfTy)); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 261 |  | 
| Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 262 | setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), | 
|  | 263 | &Context.Idents.get("_cmd"), | 
|  | 264 | Context.getObjCSelType())); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
|  | 267 |  | 
|  | 268 |  | 
|  | 269 | /// getSynthesizedMethodSize - Compute size of synthesized method name | 
|  | 270 | /// as done be the rewrite. | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 271 | /// | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 272 | unsigned ObjCMethodDecl::getSynthesizedMethodSize() const { | 
|  | 273 | // syntesized method name is a concatenation of -/+[class-name selector] | 
|  | 274 | // Get length of this name. | 
|  | 275 | unsigned length = 3;  // _I_ or _C_ | 
|  | 276 | length += getClassInterface()->getNameAsString().size()+1; // extra for _ | 
|  | 277 | if (const ObjCCategoryImplDecl *CID = | 
|  | 278 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) | 
|  | 279 | length += CID->getNameAsString().size()+1; | 
|  | 280 | length += getSelector().getAsString().size(); // selector name | 
|  | 281 | return length; | 
|  | 282 | } | 
|  | 283 |  | 
|  | 284 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { | 
|  | 285 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) | 
|  | 286 | return ID; | 
|  | 287 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) | 
|  | 288 | return CD->getClassInterface(); | 
| Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame^] | 289 | if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 290 | return IMD->getClassInterface(); | 
| Argyrios Kyrtzidis | a853037 | 2009-07-28 05:10:52 +0000 | [diff] [blame^] | 291 |  | 
|  | 292 | assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 293 | assert(false && "unknown method context"); | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 294 | return 0; | 
|  | 295 | } | 
|  | 296 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 297 | //===----------------------------------------------------------------------===// | 
|  | 298 | // ObjCInterfaceDecl | 
|  | 299 | //===----------------------------------------------------------------------===// | 
|  | 300 |  | 
|  | 301 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, | 
|  | 302 | DeclContext *DC, | 
|  | 303 | SourceLocation atLoc, | 
|  | 304 | IdentifierInfo *Id, | 
|  | 305 | SourceLocation ClassLoc, | 
|  | 306 | bool ForwardDecl, bool isInternal){ | 
|  | 307 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, | 
|  | 308 | isInternal); | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | ObjCInterfaceDecl:: | 
|  | 312 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, | 
|  | 313 | SourceLocation CLoc, bool FD, bool isInternal) | 
|  | 314 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), | 
|  | 315 | TypeForDecl(0), SuperClass(0), | 
|  | 316 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), | 
|  | 317 | ClassLoc(CLoc) { | 
|  | 318 | } | 
|  | 319 |  | 
|  | 320 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { | 
| Chris Lattner | d13d302 | 2009-03-31 08:36:08 +0000 | [diff] [blame] | 321 | for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 322 | if (*I) (*I)->Destroy(C); | 
|  | 323 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 324 | IVars.Destroy(C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 325 | // FIXME: CategoryList? | 
|  | 326 |  | 
|  | 327 | // FIXME: Because there is no clear ownership | 
|  | 328 | //  role between ObjCInterfaceDecls and the ObjCPropertyDecls that they | 
|  | 329 | //  reference, we destroy ObjCPropertyDecls in ~TranslationUnit. | 
|  | 330 | Decl::Destroy(C); | 
|  | 331 | } | 
|  | 332 |  | 
| Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 333 | ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { | 
|  | 334 | return getASTContext().getObjCImplementation( | 
|  | 335 | const_cast<ObjCInterfaceDecl*>(this)); | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { | 
|  | 339 | getASTContext().setObjCImplementation(this, ImplD); | 
|  | 340 | } | 
|  | 341 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 342 |  | 
|  | 343 | /// FindCategoryDeclaration - Finds category declaration in the list of | 
|  | 344 | /// categories for this class and returns it. Name of the category is passed | 
|  | 345 | /// in 'CategoryId'. If category not found, return 0; | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 346 | /// | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 347 | ObjCCategoryDecl * | 
|  | 348 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { | 
|  | 349 | for (ObjCCategoryDecl *Category = getCategoryList(); | 
|  | 350 | Category; Category = Category->getNextClassCategory()) | 
|  | 351 | if (Category->getIdentifier() == CategoryId) | 
|  | 352 | return Category; | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 353 | return 0; | 
|  | 354 | } | 
|  | 355 |  | 
| Argyrios Kyrtzidis | 1cb35dd | 2009-07-21 00:06:20 +0000 | [diff] [blame] | 356 | ObjCMethodDecl * | 
|  | 357 | ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { | 
|  | 358 | for (ObjCCategoryDecl *Category = getCategoryList(); | 
|  | 359 | Category; Category = Category->getNextClassCategory()) | 
|  | 360 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) | 
|  | 361 | if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) | 
|  | 362 | return MD; | 
|  | 363 | return 0; | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { | 
|  | 367 | for (ObjCCategoryDecl *Category = getCategoryList(); | 
|  | 368 | Category; Category = Category->getNextClassCategory()) | 
|  | 369 | if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) | 
|  | 370 | if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) | 
|  | 371 | return MD; | 
|  | 372 | return 0; | 
|  | 373 | } | 
|  | 374 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 375 | //===----------------------------------------------------------------------===// | 
|  | 376 | // ObjCIvarDecl | 
|  | 377 | //===----------------------------------------------------------------------===// | 
|  | 378 |  | 
|  | 379 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 380 | SourceLocation L, IdentifierInfo *Id, | 
|  | 381 | QualType T, AccessControl ac, Expr *BW) { | 
|  | 382 | return new (C) ObjCIvarDecl(DC, L, Id, T, ac, BW); | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 |  | 
|  | 386 |  | 
|  | 387 | //===----------------------------------------------------------------------===// | 
|  | 388 | // ObjCAtDefsFieldDecl | 
|  | 389 | //===----------------------------------------------------------------------===// | 
|  | 390 |  | 
|  | 391 | ObjCAtDefsFieldDecl | 
|  | 392 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, | 
|  | 393 | IdentifierInfo *Id, QualType T, Expr *BW) { | 
|  | 394 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); | 
|  | 395 | } | 
|  | 396 |  | 
|  | 397 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { | 
|  | 398 | this->~ObjCAtDefsFieldDecl(); | 
|  | 399 | C.Deallocate((void *)this); | 
|  | 400 | } | 
|  | 401 |  | 
|  | 402 | //===----------------------------------------------------------------------===// | 
|  | 403 | // ObjCProtocolDecl | 
|  | 404 | //===----------------------------------------------------------------------===// | 
|  | 405 |  | 
|  | 406 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 407 | SourceLocation L, | 
|  | 408 | IdentifierInfo *Id) { | 
|  | 409 | return new (C) ObjCProtocolDecl(DC, L, Id); | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | void ObjCProtocolDecl::Destroy(ASTContext &C) { | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 413 | ReferencedProtocols.Destroy(C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 414 | ObjCContainerDecl::Destroy(C); | 
|  | 415 | } | 
|  | 416 |  | 
| Steve Naroff | 91b0b0c | 2009-03-01 16:12:44 +0000 | [diff] [blame] | 417 | ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { | 
|  | 418 | ObjCProtocolDecl *PDecl = this; | 
|  | 419 |  | 
|  | 420 | if (Name == getIdentifier()) | 
|  | 421 | return PDecl; | 
|  | 422 |  | 
|  | 423 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) | 
|  | 424 | if ((PDecl = (*I)->lookupProtocolNamed(Name))) | 
|  | 425 | return PDecl; | 
|  | 426 |  | 
|  | 427 | return NULL; | 
|  | 428 | } | 
|  | 429 |  | 
| Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 430 | // lookupMethod - Lookup a instance/class method in the protocol and protocols | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 431 | // it inherited. | 
| Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 432 | ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, | 
|  | 433 | bool isInstance) const { | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 434 | ObjCMethodDecl *MethodDecl = NULL; | 
|  | 435 |  | 
| Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 436 | if ((MethodDecl = getMethod(Sel, isInstance))) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 437 | return MethodDecl; | 
|  | 438 |  | 
|  | 439 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) | 
| Argyrios Kyrtzidis | 094e2bb | 2009-07-25 22:15:38 +0000 | [diff] [blame] | 440 | if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 441 | return MethodDecl; | 
|  | 442 | return NULL; | 
|  | 443 | } | 
|  | 444 |  | 
|  | 445 | //===----------------------------------------------------------------------===// | 
|  | 446 | // ObjCClassDecl | 
|  | 447 | //===----------------------------------------------------------------------===// | 
|  | 448 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 449 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, | 
|  | 450 | ObjCInterfaceDecl *const *Elts, unsigned nElts, | 
|  | 451 | ASTContext &C) | 
|  | 452 | : Decl(ObjCClass, DC, L) { | 
|  | 453 | ForwardDecls.set(Elts, nElts, C); | 
|  | 454 | } | 
|  | 455 |  | 
|  | 456 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 457 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 458 | SourceLocation L, | 
|  | 459 | ObjCInterfaceDecl *const *Elts, | 
|  | 460 | unsigned nElts) { | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 461 | return new (C) ObjCClassDecl(DC, L, Elts, nElts, C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
|  | 464 | void ObjCClassDecl::Destroy(ASTContext &C) { | 
|  | 465 |  | 
|  | 466 | // FIXME: There is no clear ownership policy now for referenced | 
|  | 467 | //  ObjCInterfaceDecls.  Some of them can be forward declarations that | 
|  | 468 | //  are never later defined (in which case the ObjCClassDecl owns them) | 
|  | 469 | //  or the ObjCInterfaceDecl later becomes a real definition later.  Ideally | 
|  | 470 | //  we should have separate objects for forward declarations and definitions, | 
|  | 471 | //  obviating this problem.  Because of this situation, referenced | 
|  | 472 | //  ObjCInterfaceDecls are destroyed in ~TranslationUnit. | 
|  | 473 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 474 | ForwardDecls.Destroy(C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 475 | Decl::Destroy(C); | 
|  | 476 | } | 
|  | 477 |  | 
|  | 478 | //===----------------------------------------------------------------------===// | 
|  | 479 | // ObjCForwardProtocolDecl | 
|  | 480 | //===----------------------------------------------------------------------===// | 
|  | 481 |  | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 482 | ObjCForwardProtocolDecl:: | 
|  | 483 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, | 
|  | 484 | ObjCProtocolDecl *const *Elts, unsigned nElts, | 
|  | 485 | ASTContext &C) | 
|  | 486 | : Decl(ObjCForwardProtocol, DC, L) { | 
|  | 487 | ReferencedProtocols.set(Elts, nElts, C); | 
|  | 488 | } | 
|  | 489 |  | 
|  | 490 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 491 | ObjCForwardProtocolDecl * | 
|  | 492 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 493 | SourceLocation L, | 
|  | 494 | ObjCProtocolDecl *const *Elts, | 
|  | 495 | unsigned NumElts) { | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 496 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 497 | } | 
|  | 498 |  | 
|  | 499 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { | 
| Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 500 | ReferencedProtocols.Destroy(C); | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 501 | Decl::Destroy(C); | 
|  | 502 | } | 
|  | 503 |  | 
|  | 504 | //===----------------------------------------------------------------------===// | 
|  | 505 | // ObjCCategoryDecl | 
|  | 506 | //===----------------------------------------------------------------------===// | 
|  | 507 |  | 
|  | 508 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 509 | SourceLocation L, | 
|  | 510 | IdentifierInfo *Id) { | 
|  | 511 | return new (C) ObjCCategoryDecl(DC, L, Id); | 
|  | 512 | } | 
|  | 513 |  | 
| Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 514 | ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { | 
|  | 515 | return getASTContext().getObjCImplementation( | 
|  | 516 | const_cast<ObjCCategoryDecl*>(this)); | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { | 
|  | 520 | getASTContext().setObjCImplementation(this, ImplD); | 
|  | 521 | } | 
|  | 522 |  | 
|  | 523 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 524 | //===----------------------------------------------------------------------===// | 
|  | 525 | // ObjCCategoryImplDecl | 
|  | 526 | //===----------------------------------------------------------------------===// | 
|  | 527 |  | 
|  | 528 | ObjCCategoryImplDecl * | 
|  | 529 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 530 | SourceLocation L,IdentifierInfo *Id, | 
|  | 531 | ObjCInterfaceDecl *ClassInterface) { | 
|  | 532 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); | 
|  | 533 | } | 
|  | 534 |  | 
|  | 535 |  | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 536 | void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { | 
| Douglas Gregor | 2c2d43c | 2009-04-23 02:42:49 +0000 | [diff] [blame] | 537 | // FIXME: The context should be correct before we get here. | 
| Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 538 | property->setLexicalDeclContext(this); | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 539 | addDecl(property); | 
| Douglas Gregor | 653f1b1 | 2009-04-23 01:02:12 +0000 | [diff] [blame] | 540 | } | 
|  | 541 |  | 
| Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 542 | void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { | 
|  | 543 | ASTContext &Ctx = getASTContext(); | 
|  | 544 |  | 
|  | 545 | if (ObjCImplementationDecl *ImplD | 
| Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 546 | = dyn_cast_or_null<ObjCImplementationDecl>(this)) { | 
| Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 547 | if (IFace) | 
|  | 548 | Ctx.setObjCImplementation(IFace, ImplD); | 
|  | 549 |  | 
| Duncan Sands | 98f2cca | 2009-07-21 07:56:29 +0000 | [diff] [blame] | 550 | } else if (ObjCCategoryImplDecl *ImplD = | 
| Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 551 | dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { | 
|  | 552 | if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) | 
|  | 553 | Ctx.setObjCImplementation(CD, ImplD); | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 | ClassInterface = IFace; | 
|  | 557 | } | 
|  | 558 |  | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 559 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of | 
| Chris Lattner | d6eed1c | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 560 | /// properties implemented in this category @implementation block and returns | 
|  | 561 | /// the implemented property that uses it. | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 562 | /// | 
| Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 563 | ObjCPropertyImplDecl *ObjCImplDecl:: | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 564 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { | 
|  | 565 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 566 | ObjCPropertyImplDecl *PID = *i; | 
|  | 567 | if (PID->getPropertyIvarDecl() && | 
|  | 568 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) | 
|  | 569 | return PID; | 
|  | 570 | } | 
|  | 571 | return 0; | 
|  | 572 | } | 
|  | 573 |  | 
|  | 574 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl | 
|  | 575 | /// added to the list of those properties @synthesized/@dynamic in this | 
|  | 576 | /// category @implementation block. | 
|  | 577 | /// | 
| Chris Lattner | 3aa1861 | 2009-02-28 18:42:10 +0000 | [diff] [blame] | 578 | ObjCPropertyImplDecl *ObjCImplDecl:: | 
| Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 579 | FindPropertyImplDecl(IdentifierInfo *Id) const { | 
|  | 580 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ | 
| Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 581 | ObjCPropertyImplDecl *PID = *i; | 
|  | 582 | if (PID->getPropertyDecl()->getIdentifier() == Id) | 
|  | 583 | return PID; | 
|  | 584 | } | 
|  | 585 | return 0; | 
|  | 586 | } | 
|  | 587 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 588 | //===----------------------------------------------------------------------===// | 
|  | 589 | // ObjCImplementationDecl | 
|  | 590 | //===----------------------------------------------------------------------===// | 
|  | 591 |  | 
|  | 592 | ObjCImplementationDecl * | 
|  | 593 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 594 | SourceLocation L, | 
|  | 595 | ObjCInterfaceDecl *ClassInterface, | 
|  | 596 | ObjCInterfaceDecl *SuperDecl) { | 
|  | 597 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); | 
|  | 598 | } | 
|  | 599 |  | 
| Chris Lattner | ab35163 | 2009-02-20 20:59:54 +0000 | [diff] [blame] | 600 | //===----------------------------------------------------------------------===// | 
|  | 601 | // ObjCCompatibleAliasDecl | 
|  | 602 | //===----------------------------------------------------------------------===// | 
|  | 603 |  | 
|  | 604 | ObjCCompatibleAliasDecl * | 
|  | 605 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 606 | SourceLocation L, | 
|  | 607 | IdentifierInfo *Id, | 
|  | 608 | ObjCInterfaceDecl* AliasedClass) { | 
|  | 609 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); | 
|  | 610 | } | 
|  | 611 |  | 
|  | 612 | //===----------------------------------------------------------------------===// | 
|  | 613 | // ObjCPropertyDecl | 
|  | 614 | //===----------------------------------------------------------------------===// | 
|  | 615 |  | 
|  | 616 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, | 
|  | 617 | SourceLocation L, | 
|  | 618 | IdentifierInfo *Id, | 
|  | 619 | QualType T, | 
|  | 620 | PropertyControl propControl) { | 
|  | 621 | return new (C) ObjCPropertyDecl(DC, L, Id, T); | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 |  | 
|  | 625 | //===----------------------------------------------------------------------===// | 
|  | 626 | // ObjCPropertyImplDecl | 
|  | 627 | //===----------------------------------------------------------------------===// | 
|  | 628 |  | 
| Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 629 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, | 
| Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 630 | DeclContext *DC, | 
| Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 631 | SourceLocation atLoc, | 
|  | 632 | SourceLocation L, | 
|  | 633 | ObjCPropertyDecl *property, | 
| Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 634 | Kind PK, | 
| Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 635 | ObjCIvarDecl *ivar) { | 
| Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 636 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); | 
| Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 637 | } | 
| Chris Lattner | f4af515 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 638 |  | 
| Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 639 |  |