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