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