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" |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Chris Lattner | 114add6 | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 19 | //===----------------------------------------------------------------------===// |
| 20 | // ObjC Decl Allocation/Deallocation Method Implementations |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 23 | ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, |
| 24 | SourceLocation beginLoc, |
Chris Lattner | 114add6 | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 25 | SourceLocation endLoc, |
| 26 | Selector SelInfo, QualType T, |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 27 | DeclContext *contextDecl, |
Daniel Dunbar | d8bd682 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 28 | bool isInstance, |
Chris Lattner | 114add6 | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 29 | bool isVariadic, |
Fariborz Jahanian | 5f2e224 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 30 | bool isSynthesized, |
Chris Lattner | f735583 | 2008-03-16 00:58:16 +0000 | [diff] [blame] | 31 | ImplementationControl impControl) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 32 | return new (C) ObjCMethodDecl(beginLoc, endLoc, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 33 | SelInfo, T, contextDecl, |
Daniel Dunbar | d8bd682 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 34 | isInstance, |
Fariborz Jahanian | 5f2e224 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 35 | isVariadic, isSynthesized, impControl); |
Chris Lattner | 0db541b | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 36 | } |
Chris Lattner | 114add6 | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 37 | |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 38 | void ObjCMethodDecl::Destroy(ASTContext& C) { |
| 39 | if (Body) Body->Destroy(C); |
| 40 | if (SelfDecl) SelfDecl->Destroy(C); |
| 41 | |
| 42 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 43 | if (*I) (*I)->Destroy(C); |
Chris Lattner | ae53888 | 2009-02-20 05:54:35 +0000 | [diff] [blame] | 44 | |
| 45 | delete [] ParamInfo; |
| 46 | ParamInfo = 0; |
| 47 | |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 48 | Decl::Destroy(C); |
| 49 | } |
| 50 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 51 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 52 | ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 53 | DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 54 | SourceLocation atLoc, |
Steve Naroff | 7c37174 | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 55 | IdentifierInfo *Id, |
| 56 | SourceLocation ClassLoc, |
Chris Lattner | 0db541b | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 57 | bool ForwardDecl, bool isInternal){ |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 58 | return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl, |
Chris Lattner | 0db541b | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 59 | isInternal); |
| 60 | } |
| 61 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 62 | ObjCInterfaceDecl:: |
| 63 | ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, |
| 64 | SourceLocation CLoc, bool FD, bool isInternal) |
| 65 | : ObjCContainerDecl(ObjCInterface, DC, atLoc, Id), |
| 66 | TypeForDecl(0), SuperClass(0), Ivars(0), NumIvars(0), |
| 67 | CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal), |
| 68 | ClassLoc(CLoc) { |
Steve Naroff | d9d4d50 | 2009-01-07 17:57:40 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 71 | void ObjCInterfaceDecl::Destroy(ASTContext &C) { |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 72 | for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I) |
| 73 | if (*I) (*I)->Destroy(C); |
| 74 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 75 | delete [] Ivars; |
| 76 | Ivars = 0; |
| 77 | // FIXME: CategoryList? |
| 78 | |
Ted Kremenek | 22db160 | 2008-06-06 17:21:42 +0000 | [diff] [blame] | 79 | // FIXME: Because there is no clear ownership |
| 80 | // role between ObjCInterfaceDecls and the ObjCPropertyDecls that they |
| 81 | // reference, we destroy ObjCPropertyDecls in ~TranslationUnit. |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 82 | Decl::Destroy(C); |
| 83 | } |
| 84 | |
| 85 | |
Argiris Kirtzidis | 96e79bf | 2009-02-17 20:20:37 +0000 | [diff] [blame] | 86 | ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC, |
| 87 | SourceLocation L, IdentifierInfo *Id, |
| 88 | QualType T, AccessControl ac, Expr *BW) { |
| 89 | return new (C) ObjCIvarDecl(DC, L, Id, T, ac, BW); |
Chris Lattner | 114add6 | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Ted Kremenek | e5bedfe | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 92 | |
| 93 | ObjCAtDefsFieldDecl |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 94 | *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
Ted Kremenek | e5bedfe | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 95 | IdentifierInfo *Id, QualType T, Expr *BW) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 96 | return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW); |
Ted Kremenek | e5bedfe | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) { |
| 100 | this->~ObjCAtDefsFieldDecl(); |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 101 | C.Deallocate((void *)this); |
Ted Kremenek | e5bedfe | 2008-08-20 03:26:33 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 104 | ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 105 | SourceLocation L, |
Chris Lattner | 7afba9c | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 106 | IdentifierInfo *Id) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 107 | return new (C) ObjCProtocolDecl(DC, L, Id); |
Chris Lattner | 180f7e2 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Chris Lattner | ae53888 | 2009-02-20 05:54:35 +0000 | [diff] [blame] | 110 | void ObjCProtocolDecl::Destroy(ASTContext &C) { |
Ted Kremenek | c906e5e | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 111 | delete [] PropertyDecl; |
Chris Lattner | ae53888 | 2009-02-20 05:54:35 +0000 | [diff] [blame] | 112 | PropertyDecl = 0; |
| 113 | ObjCContainerDecl::Destroy(C); |
Ted Kremenek | c906e5e | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Ted Kremenek | c906e5e | 2008-06-06 19:48:57 +0000 | [diff] [blame] | 116 | |
Chris Lattner | ae53888 | 2009-02-20 05:54:35 +0000 | [diff] [blame] | 117 | |
| 118 | |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 119 | ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 120 | SourceLocation L, |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 121 | ObjCInterfaceDecl **Elts, unsigned nElts) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 122 | return new (C) ObjCClassDecl(DC, L, Elts, nElts); |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 125 | ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, |
| 126 | ObjCInterfaceDecl **Elts, unsigned nElts) |
| 127 | : Decl(ObjCClass, DC, L) { |
| 128 | if (nElts) { |
| 129 | ForwardDecls = new ObjCInterfaceDecl*[nElts]; |
| 130 | memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*)); |
| 131 | } else { |
| 132 | ForwardDecls = 0; |
| 133 | } |
| 134 | NumForwardDecls = nElts; |
Ted Kremenek | ff29162 | 2008-06-06 20:11:53 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 137 | void ObjCClassDecl::Destroy(ASTContext &C) { |
Ted Kremenek | ff29162 | 2008-06-06 20:11:53 +0000 | [diff] [blame] | 138 | |
| 139 | // FIXME: There is no clear ownership policy now for referenced |
| 140 | // ObjCInterfaceDecls. Some of them can be forward declarations that |
| 141 | // are never later defined (in which case the ObjCClassDecl owns them) |
| 142 | // or the ObjCInterfaceDecl later becomes a real definition later. Ideally |
| 143 | // we should have separate objects for forward declarations and definitions, |
| 144 | // obviating this problem. Because of this situation, referenced |
| 145 | // ObjCInterfaceDecls are destroyed in ~TranslationUnit. |
| 146 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 147 | delete [] ForwardDecls; |
| 148 | ForwardDecls = 0; |
| 149 | |
Ted Kremenek | ff29162 | 2008-06-06 20:11:53 +0000 | [diff] [blame] | 150 | Decl::Destroy(C); |
| 151 | } |
| 152 | |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 153 | ObjCForwardProtocolDecl * |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 154 | ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 155 | SourceLocation L, |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 156 | ObjCProtocolDecl **Elts, unsigned NumElts) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 157 | return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts); |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 160 | ObjCForwardProtocolDecl:: |
| 161 | ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, |
| 162 | ObjCProtocolDecl **Elts, unsigned nElts) |
| 163 | : Decl(ObjCForwardProtocol, DC, L) { |
| 164 | NumReferencedProtocols = nElts; |
| 165 | if (nElts) { |
| 166 | ReferencedProtocols = new ObjCProtocolDecl*[nElts]; |
| 167 | memcpy(ReferencedProtocols, Elts, nElts*sizeof(ObjCProtocolDecl*)); |
| 168 | } else { |
| 169 | ReferencedProtocols = 0; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void ObjCForwardProtocolDecl::Destroy(ASTContext &C) { |
Ted Kremenek | 1e5e0bf | 2008-06-06 21:05:33 +0000 | [diff] [blame] | 174 | delete [] ReferencedProtocols; |
Chris Lattner | 3e27e63 | 2009-02-20 06:03:09 +0000 | [diff] [blame^] | 175 | ReferencedProtocols = 0; |
Ted Kremenek | 1e5e0bf | 2008-06-06 21:05:33 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 178 | ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 179 | SourceLocation L, |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 180 | IdentifierInfo *Id) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 181 | return new (C) ObjCCategoryDecl(DC, L, Id); |
Chris Lattner | e29dc83 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Chris Lattner | 1b6de33 | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 184 | ObjCCategoryImplDecl * |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 185 | ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 186 | SourceLocation L,IdentifierInfo *Id, |
Chris Lattner | 1b6de33 | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 187 | ObjCInterfaceDecl *ClassInterface) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 188 | return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface); |
Chris Lattner | 1b6de33 | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | ObjCImplementationDecl * |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 192 | ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 193 | SourceLocation L, |
Chris Lattner | 1b6de33 | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 194 | ObjCInterfaceDecl *ClassInterface, |
| 195 | ObjCInterfaceDecl *SuperDecl) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 196 | return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl); |
Chris Lattner | 1b6de33 | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 197 | } |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 198 | |
Chris Lattner | 2d1c431 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 199 | ObjCCompatibleAliasDecl * |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 200 | ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 201 | SourceLocation L, |
Chris Lattner | 2d1c431 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 202 | IdentifierInfo *Id, |
| 203 | ObjCInterfaceDecl* AliasedClass) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 204 | return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); |
Chris Lattner | 2d1c431 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 207 | ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
Fariborz Jahanian | e707172 | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 208 | SourceLocation L, |
Fariborz Jahanian | 0ceb4be | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 209 | IdentifierInfo *Id, |
Fariborz Jahanian | 4aa72a7 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 210 | QualType T, |
| 211 | PropertyControl propControl) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 212 | return new (C) ObjCPropertyDecl(DC, L, Id, T); |
Chris Lattner | 2d1c431 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 215 | //===----------------------------------------------------------------------===// |
| 216 | // Objective-C Decl Implementation |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | |
Fariborz Jahanian | 91dd9d3 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 219 | void ObjCMethodDecl::createImplicitParams(ASTContext &Context, |
| 220 | const ObjCInterfaceDecl *OID) { |
Daniel Dunbar | 8811637 | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 221 | QualType selfTy; |
Douglas Gregor | 5d76484 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 222 | if (isInstanceMethod()) { |
Daniel Dunbar | 8811637 | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 223 | // There may be no interface context due to error in declaration |
| 224 | // of the interface (which has been reported). Recover gracefully. |
Fariborz Jahanian | 91dd9d3 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 225 | if (OID) { |
| 226 | selfTy = Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl *>(OID)); |
Daniel Dunbar | 8811637 | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 227 | selfTy = Context.getPointerType(selfTy); |
| 228 | } else { |
| 229 | selfTy = Context.getObjCIdType(); |
| 230 | } |
| 231 | } else // we have a factory method. |
| 232 | selfTy = Context.getObjCClassType(); |
| 233 | |
| 234 | SelfDecl = ImplicitParamDecl::Create(Context, this, |
| 235 | SourceLocation(), |
| 236 | &Context.Idents.get("self"), |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 237 | selfTy); |
Daniel Dunbar | 8811637 | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 238 | |
| 239 | CmdDecl = ImplicitParamDecl::Create(Context, this, |
| 240 | SourceLocation(), |
| 241 | &Context.Idents.get("_cmd"), |
Douglas Gregor | af8ad2b | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 242 | Context.getObjCSelType()); |
Daniel Dunbar | 8811637 | 2008-08-26 06:08:30 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 245 | void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, |
| 246 | unsigned NumParams) { |
| 247 | assert(ParamInfo == 0 && "Already has param info!"); |
| 248 | |
| 249 | // Zero params -> null pointer. |
| 250 | if (NumParams) { |
| 251 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 252 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 253 | NumMethodParams = NumParams; |
| 254 | } |
| 255 | } |
| 256 | |
Fariborz Jahanian | ef8a3df | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 257 | /// FindCategoryDeclaration - Finds category declaration in the list of |
| 258 | /// categories for this class and returns it. Name of the category is passed |
| 259 | /// in 'CategoryId'. If category not found, return 0; |
| 260 | /// |
| 261 | ObjCCategoryDecl * |
| 262 | ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { |
| 263 | for (ObjCCategoryDecl *Category = getCategoryList(); |
| 264 | Category; Category = Category->getNextClassCategory()) |
| 265 | if (Category->getIdentifier() == CategoryId) |
| 266 | return Category; |
| 267 | return 0; |
| 268 | } |
| 269 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 270 | /// ObjCAddInstanceVariablesToClass - Inserts instance variables |
| 271 | /// into ObjCInterfaceDecl's fields. |
| 272 | /// |
| 273 | void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars, |
| 274 | unsigned numIvars, |
| 275 | SourceLocation RBrac) { |
| 276 | NumIvars = numIvars; |
| 277 | if (numIvars) { |
| 278 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 279 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
| 280 | } |
| 281 | setLocEnd(RBrac); |
| 282 | } |
| 283 | |
Fariborz Jahanian | 0977239 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 284 | /// lookupFieldDeclForIvar - looks up a field decl' in the laid out |
| 285 | /// storage which matches this 'ivar'. |
| 286 | /// |
| 287 | FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context, |
Fariborz Jahanian | 86008c0 | 2008-12-15 20:35:07 +0000 | [diff] [blame] | 288 | const ObjCIvarDecl *ivar) { |
Fariborz Jahanian | 0556b15 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 289 | const RecordDecl *RecordForDecl = Context.addRecordToClass(this); |
Fariborz Jahanian | 0977239 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 290 | assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class"); |
| 291 | DeclarationName Member = ivar->getDeclName(); |
Fariborz Jahanian | 0556b15 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 292 | DeclContext::lookup_result Lookup = (const_cast< RecordDecl *>(RecordForDecl)) |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 293 | ->lookup(Member); |
Fariborz Jahanian | 0977239 | 2008-12-13 22:20:28 +0000 | [diff] [blame] | 294 | assert((Lookup.first != Lookup.second) && "field decl not found"); |
| 295 | FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first); |
| 296 | assert(MemberDecl && "field decl not found"); |
| 297 | return MemberDecl; |
| 298 | } |
| 299 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 300 | /// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance |
| 301 | /// Variables (Ivars) relative to what declared in @implementation;s class. |
| 302 | /// Ivars into ObjCImplementationDecl's fields. |
| 303 | /// |
| 304 | void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( |
| 305 | ObjCIvarDecl **ivars, unsigned numIvars) { |
| 306 | NumIvars = numIvars; |
| 307 | if (numIvars) { |
| 308 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 309 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
| 310 | } |
| 311 | } |
| 312 | |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 313 | // Get the local instance method declared in this interface. |
| 314 | // FIXME: handle overloading, instance & class methods can have the same name. |
| 315 | ObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const { |
| 316 | lookup_const_result MethodResult = lookup(Sel); |
| 317 | if (MethodResult.first) |
| 318 | return const_cast<ObjCMethodDecl*>( |
| 319 | dyn_cast<ObjCMethodDecl>(*MethodResult.first)); |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | // Get the local class method declared in this interface. |
| 324 | ObjCMethodDecl *ObjCContainerDecl::getClassMethod(Selector Sel) const { |
| 325 | lookup_const_result MethodResult = lookup(Sel); |
| 326 | if (MethodResult.first) |
| 327 | return const_cast<ObjCMethodDecl*>( |
| 328 | dyn_cast<ObjCMethodDecl>(*MethodResult.first)); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | unsigned ObjCContainerDecl::getNumInstanceMethods() const { |
| 333 | unsigned sum = 0; |
| 334 | for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I != E; ++I) |
| 335 | sum++; |
| 336 | return sum; |
| 337 | } |
| 338 | unsigned ObjCContainerDecl::getNumClassMethods() const { |
| 339 | unsigned sum = 0; |
| 340 | for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I != E; ++I) |
| 341 | sum++; |
| 342 | return sum; |
| 343 | } |
Steve Naroff | 56af200 | 2009-01-11 01:06:09 +0000 | [diff] [blame] | 344 | unsigned ObjCContainerDecl::getNumProperties() const { |
| 345 | unsigned sum = 0; |
| 346 | for (prop_iterator I=prop_begin(), E=prop_end(); I != E; ++I) |
| 347 | sum++; |
| 348 | return sum; |
| 349 | } |
Steve Naroff | ab63fd6 | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 350 | |
Fariborz Jahanian | ef8a3df | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 351 | /// FindPropertyDeclaration - Finds declaration of the property given its name |
| 352 | /// in 'PropertyId' and returns it. It returns 0, if not found. |
Steve Naroff | dcf1e84 | 2009-01-11 12:47:58 +0000 | [diff] [blame] | 353 | /// FIXME: Convert to DeclContext lookup... |
Fariborz Jahanian | ef8a3df | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 354 | /// |
| 355 | ObjCPropertyDecl * |
Steve Naroff | 451f83c | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 356 | ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { |
| 357 | for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I) { |
Fariborz Jahanian | ef8a3df | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 358 | ObjCPropertyDecl *property = *I; |
| 359 | if (property->getIdentifier() == PropertyId) |
| 360 | return property; |
| 361 | } |
Fariborz Jahanian | faca5e2 | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 362 | const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this); |
| 363 | if (PID) { |
| 364 | for (ObjCProtocolDecl::protocol_iterator P = PID->protocol_begin(), |
| 365 | E = PID->protocol_end(); |
| 366 | P != E; ++P) |
| 367 | if (ObjCPropertyDecl *property = |
| 368 | (*P)->FindPropertyDeclaration(PropertyId)) |
| 369 | return property; |
| 370 | } |
| 371 | |
Fariborz Jahanian | 6b0ed6f | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 372 | if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) { |
Steve Naroff | 451f83c | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 373 | // Look through categories. |
| 374 | for (ObjCCategoryDecl *Category = OID->getCategoryList(); |
| 375 | Category; Category = Category->getNextClassCategory()) { |
| 376 | ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId); |
| 377 | if (property) |
| 378 | return property; |
| 379 | } |
| 380 | // Look through protocols. |
| 381 | for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(), |
| 382 | E = OID->protocol_end(); I != E; ++I) { |
| 383 | ObjCProtocolDecl *Protocol = *I; |
| 384 | ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); |
| 385 | if (property) |
| 386 | return property; |
| 387 | } |
| 388 | if (OID->getSuperClass()) |
| 389 | return OID->getSuperClass()->FindPropertyDeclaration(PropertyId); |
Steve Naroff | d1f0eb4 | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 390 | } |
Fariborz Jahanian | 6b0ed6f | 2009-01-19 18:16:19 +0000 | [diff] [blame] | 391 | else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) { |
| 392 | // Look through protocols. |
| 393 | for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(), |
| 394 | E = OCD->protocol_end(); I != E; ++I) { |
| 395 | ObjCProtocolDecl *Protocol = *I; |
| 396 | ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); |
| 397 | if (property) |
| 398 | return property; |
| 399 | } |
| 400 | } |
Steve Naroff | d1f0eb4 | 2008-06-05 13:55:23 +0000 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 404 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable( |
| 405 | IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) { |
| 406 | ObjCInterfaceDecl* ClassDecl = this; |
| 407 | while (ClassDecl != NULL) { |
| 408 | for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end(); |
| 409 | I != E; ++I) { |
| 410 | if ((*I)->getIdentifier() == ID) { |
| 411 | clsDeclared = ClassDecl; |
| 412 | return *I; |
| 413 | } |
| 414 | } |
| 415 | ClassDecl = ClassDecl->getSuperClass(); |
| 416 | } |
| 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | /// lookupInstanceMethod - This method returns an instance method by looking in |
| 421 | /// the class, its categories, and its super classes (using a linear search). |
| 422 | ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) { |
| 423 | ObjCInterfaceDecl* ClassDecl = this; |
| 424 | ObjCMethodDecl *MethodDecl = 0; |
| 425 | |
| 426 | while (ClassDecl != NULL) { |
| 427 | if ((MethodDecl = ClassDecl->getInstanceMethod(Sel))) |
| 428 | return MethodDecl; |
| 429 | |
| 430 | // Didn't find one yet - look through protocols. |
Chris Lattner | 8bcb525 | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 431 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 432 | ClassDecl->getReferencedProtocols(); |
| 433 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 434 | E = Protocols.end(); I != E; ++I) |
| 435 | if ((MethodDecl = (*I)->getInstanceMethod(Sel))) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 436 | return MethodDecl; |
Chris Lattner | 8bcb525 | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 437 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 438 | // Didn't find one yet - now look through categories. |
| 439 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 440 | while (CatDecl) { |
| 441 | if ((MethodDecl = CatDecl->getInstanceMethod(Sel))) |
| 442 | return MethodDecl; |
Steve Naroff | af15180 | 2008-12-08 20:57:28 +0000 | [diff] [blame] | 443 | |
| 444 | // Didn't find one yet - look through protocols. |
| 445 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 446 | CatDecl->getReferencedProtocols(); |
| 447 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 448 | E = Protocols.end(); I != E; ++I) |
| 449 | if ((MethodDecl = (*I)->getInstanceMethod(Sel))) |
| 450 | return MethodDecl; |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 451 | CatDecl = CatDecl->getNextClassCategory(); |
| 452 | } |
| 453 | ClassDecl = ClassDecl->getSuperClass(); |
| 454 | } |
| 455 | return NULL; |
| 456 | } |
| 457 | |
| 458 | // lookupClassMethod - This method returns a class method by looking in the |
| 459 | // class, its categories, and its super classes (using a linear search). |
| 460 | ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { |
| 461 | ObjCInterfaceDecl* ClassDecl = this; |
| 462 | ObjCMethodDecl *MethodDecl = 0; |
| 463 | |
| 464 | while (ClassDecl != NULL) { |
| 465 | if ((MethodDecl = ClassDecl->getClassMethod(Sel))) |
| 466 | return MethodDecl; |
| 467 | |
| 468 | // Didn't find one yet - look through protocols. |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 469 | for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(), |
| 470 | E = ClassDecl->protocol_end(); I != E; ++I) |
Chris Lattner | 8bcb525 | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 471 | if ((MethodDecl = (*I)->getClassMethod(Sel))) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 472 | return MethodDecl; |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 473 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 474 | // Didn't find one yet - now look through categories. |
| 475 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
| 476 | while (CatDecl) { |
| 477 | if ((MethodDecl = CatDecl->getClassMethod(Sel))) |
| 478 | return MethodDecl; |
| 479 | CatDecl = CatDecl->getNextClassCategory(); |
| 480 | } |
| 481 | ClassDecl = ClassDecl->getSuperClass(); |
| 482 | } |
| 483 | return NULL; |
| 484 | } |
| 485 | |
Daniel Dunbar | dd24b9a | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 486 | /// getInstanceMethod - This method returns an instance method by |
| 487 | /// looking in the class implementation. Unlike interfaces, we don't |
| 488 | /// look outside the implementation. |
| 489 | ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) const { |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 490 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 491 | if ((*I)->getSelector() == Sel) |
| 492 | return *I; |
| 493 | return NULL; |
| 494 | } |
| 495 | |
Daniel Dunbar | dd24b9a | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 496 | /// getClassMethod - This method returns a class method by looking in |
| 497 | /// the class implementation. Unlike interfaces, we don't look outside |
| 498 | /// the implementation. |
| 499 | ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) const { |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 500 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 501 | I != E; ++I) |
| 502 | if ((*I)->getSelector() == Sel) |
| 503 | return *I; |
| 504 | return NULL; |
| 505 | } |
| 506 | |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 507 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 508 | /// added to the list of those properties @synthesized/@dynamic in this |
| 509 | /// @implementation block. |
| 510 | /// |
| 511 | ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 512 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 513 | ObjCPropertyImplDecl *PID = *i; |
| 514 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 515 | return PID; |
| 516 | } |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Fariborz Jahanian | 17eb888 | 2008-12-05 22:36:19 +0000 | [diff] [blame] | 521 | /// properties implemented in this @implementation block and returns the |
| 522 | /// implemented property that uses it. |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 523 | /// |
| 524 | ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 525 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) { |
| 526 | ObjCPropertyImplDecl *PID = *i; |
| 527 | if (PID->getPropertyIvarDecl() && |
| 528 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 529 | return PID; |
| 530 | } |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of |
Chris Lattner | 715e848 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 535 | /// properties implemented in this category @implementation block and returns |
| 536 | /// the implemented property that uses it. |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 537 | /// |
Chris Lattner | 715e848 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 538 | ObjCPropertyImplDecl *ObjCCategoryImplDecl:: |
| 539 | FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { |
| 540 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 541 | ObjCPropertyImplDecl *PID = *i; |
| 542 | if (PID->getPropertyIvarDecl() && |
| 543 | PID->getPropertyIvarDecl()->getIdentifier() == ivarId) |
| 544 | return PID; |
| 545 | } |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl |
| 550 | /// added to the list of those properties @synthesized/@dynamic in this |
| 551 | /// category @implementation block. |
| 552 | /// |
Chris Lattner | 715e848 | 2009-02-16 19:24:31 +0000 | [diff] [blame] | 553 | ObjCPropertyImplDecl *ObjCCategoryImplDecl:: |
| 554 | FindPropertyImplDecl(IdentifierInfo *Id) const { |
| 555 | for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ |
Fariborz Jahanian | 6834228 | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 556 | ObjCPropertyImplDecl *PID = *i; |
| 557 | if (PID->getPropertyDecl()->getIdentifier() == Id) |
| 558 | return PID; |
| 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 563 | // lookupInstanceMethod - This method returns an instance method by looking in |
| 564 | // the class implementation. Unlike interfaces, we don't look outside the |
| 565 | // implementation. |
Daniel Dunbar | dd24b9a | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 566 | ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) const { |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 567 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 568 | if ((*I)->getSelector() == Sel) |
| 569 | return *I; |
| 570 | return NULL; |
| 571 | } |
| 572 | |
| 573 | // lookupClassMethod - This method returns an instance method by looking in |
| 574 | // the class implementation. Unlike interfaces, we don't look outside the |
| 575 | // implementation. |
Daniel Dunbar | dd24b9a | 2008-08-26 06:53:45 +0000 | [diff] [blame] | 576 | ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) const { |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 577 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 578 | I != E; ++I) |
| 579 | if ((*I)->getSelector() == Sel) |
| 580 | return *I; |
| 581 | return NULL; |
| 582 | } |
| 583 | |
| 584 | // lookupInstanceMethod - Lookup a instance method in the protocol and protocols |
| 585 | // it inherited. |
| 586 | ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { |
| 587 | ObjCMethodDecl *MethodDecl = NULL; |
| 588 | |
| 589 | if ((MethodDecl = getInstanceMethod(Sel))) |
| 590 | return MethodDecl; |
| 591 | |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 592 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Steve Naroff | 30fb1da | 2008-12-18 15:50:41 +0000 | [diff] [blame] | 593 | if ((MethodDecl = (*I)->lookupInstanceMethod(Sel))) |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 594 | return MethodDecl; |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 595 | return NULL; |
| 596 | } |
| 597 | |
| 598 | // lookupInstanceMethod - Lookup a class method in the protocol and protocols |
| 599 | // it inherited. |
| 600 | ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { |
| 601 | ObjCMethodDecl *MethodDecl = NULL; |
| 602 | |
| 603 | if ((MethodDecl = getClassMethod(Sel))) |
| 604 | return MethodDecl; |
| 605 | |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 606 | for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) |
Steve Naroff | 30fb1da | 2008-12-18 15:50:41 +0000 | [diff] [blame] | 607 | if ((MethodDecl = (*I)->lookupClassMethod(Sel))) |
Chris Lattner | 0be0882 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 608 | return MethodDecl; |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | /// getSynthesizedMethodSize - Compute size of synthesized method name |
| 613 | /// as done be the rewrite. |
| 614 | /// |
| 615 | unsigned ObjCMethodDecl::getSynthesizedMethodSize() const { |
| 616 | // syntesized method name is a concatenation of -/+[class-name selector] |
| 617 | // Get length of this name. |
| 618 | unsigned length = 3; // _I_ or _C_ |
Chris Lattner | d120b9e | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 619 | length += getClassInterface()->getNameAsString().size()+1; // extra for _ |
Steve Naroff | 438be77 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 620 | if (const ObjCCategoryImplDecl *CID = |
| 621 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
Chris Lattner | d120b9e | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 622 | length += CID->getNameAsString().size()+1; |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 623 | length += getSelector().getAsString().size(); // selector name |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 624 | return length; |
| 625 | } |
| 626 | |
Chris Lattner | 052fbcd | 2008-04-06 05:25:03 +0000 | [diff] [blame] | 627 | ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { |
Steve Naroff | 438be77 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 628 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 629 | return ID; |
Steve Naroff | 438be77 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 630 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 631 | return CD->getClassInterface(); |
| 632 | if (ObjCImplementationDecl *IMD = |
Steve Naroff | 438be77 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 633 | dyn_cast<ObjCImplementationDecl>(getDeclContext())) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 634 | return IMD->getClassInterface(); |
Steve Naroff | 438be77 | 2009-01-08 19:41:02 +0000 | [diff] [blame] | 635 | if (ObjCCategoryImplDecl *CID = |
| 636 | dyn_cast<ObjCCategoryImplDecl>(getDeclContext())) |
Chris Lattner | 10318b8 | 2008-03-16 00:19:01 +0000 | [diff] [blame] | 637 | return CID->getClassInterface(); |
| 638 | assert(false && "unknown method context"); |
| 639 | return 0; |
| 640 | } |
Chris Lattner | 4485961 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 641 | |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 642 | ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, |
Douglas Gregor | 6e4fa2c | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 643 | DeclContext *DC, |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 644 | SourceLocation atLoc, |
| 645 | SourceLocation L, |
| 646 | ObjCPropertyDecl *property, |
Daniel Dunbar | 14117fc | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 647 | Kind PK, |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 648 | ObjCIvarDecl *ivar) { |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 649 | return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar); |
Fariborz Jahanian | dc0569e | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 650 | } |
Chris Lattner | 4485961 | 2008-03-17 01:19:02 +0000 | [diff] [blame] | 651 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 652 | |