Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Decl.cpp - Declaration AST Node Implementation -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Decl class and subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Decl.h" |
Steve Naroff | 3fafa10 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 2fd1c65 | 2007-10-07 08:58:51 +0000 | [diff] [blame] | 16 | #include "clang/Basic/IdentifierTable.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
| 19 | // temporary statistics gathering |
| 20 | static unsigned nFuncs = 0; |
| 21 | static unsigned nBlockVars = 0; |
| 22 | static unsigned nFileVars = 0; |
| 23 | static unsigned nParmVars = 0; |
| 24 | static unsigned nSUC = 0; |
| 25 | static unsigned nEnumConst = 0; |
| 26 | static unsigned nEnumDecls = 0; |
| 27 | static unsigned nTypedef = 0; |
| 28 | static unsigned nFieldDecls = 0; |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 29 | static unsigned nInterfaceDecls = 0; |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 30 | static unsigned nClassDecls = 0; |
| 31 | static unsigned nMethodDecls = 0; |
| 32 | static unsigned nProtocolDecls = 0; |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 33 | static unsigned nForwardProtocolDecls = 0; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 34 | static unsigned nCategoryDecls = 0; |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 35 | static unsigned nIvarDecls = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 36 | static unsigned nObjCImplementationDecls = 0; |
| 37 | static unsigned nObjCCategoryImpl = 0; |
| 38 | static unsigned nObjCCompatibleAlias = 0; |
| 39 | static unsigned nObjCPropertyDecl = 0; |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 40 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 41 | static bool StatSwitch = false; |
| 42 | |
Steve Naroff | 590aba8 | 2007-09-17 14:49:06 +0000 | [diff] [blame] | 43 | const char *Decl::getDeclKindName() const { |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 44 | switch (DeclKind) { |
| 45 | default: assert(0 && "Unknown decl kind!"); |
| 46 | case Typedef: |
| 47 | return "Typedef"; |
| 48 | case Function: |
| 49 | return "Function"; |
Chris Lattner | 3289bca | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 50 | case BlockVar: |
| 51 | return "BlockVar"; |
| 52 | case FileVar: |
| 53 | return "FileVar"; |
| 54 | case ParmVar: |
| 55 | return "ParmVar"; |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 56 | case EnumConstant: |
| 57 | return "EnumConstant"; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 58 | case ObjCInterface: |
| 59 | return "ObjCInterface"; |
| 60 | case ObjCClass: |
| 61 | return "ObjCClass"; |
| 62 | case ObjCMethod: |
| 63 | return "ObjCMethod"; |
| 64 | case ObjCProtocol: |
| 65 | return "ObjCProtocol"; |
| 66 | case ObjCForwardProtocol: |
| 67 | return "ObjCForwardProtocol"; |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 68 | case Struct: |
| 69 | return "Struct"; |
| 70 | case Union: |
| 71 | return "Union"; |
| 72 | case Class: |
| 73 | return "Class"; |
| 74 | case Enum: |
| 75 | return "Enum"; |
| 76 | } |
| 77 | } |
| 78 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 79 | bool Decl::CollectingStats(bool enable) { |
| 80 | if (enable) StatSwitch = true; |
Fariborz Jahanian | cbc36d4 | 2007-10-04 00:45:27 +0000 | [diff] [blame] | 81 | return StatSwitch; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void Decl::PrintStats() { |
| 85 | fprintf(stderr, "*** Decl Stats:\n"); |
| 86 | fprintf(stderr, " %d decls total.\n", |
| 87 | int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+ |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 88 | nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+ |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 89 | nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 90 | fprintf(stderr, " %d function decls, %d each (%d bytes)\n", |
| 91 | nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl))); |
| 92 | fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n", |
| 93 | nBlockVars, (int)sizeof(BlockVarDecl), |
| 94 | int(nBlockVars*sizeof(BlockVarDecl))); |
| 95 | fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n", |
| 96 | nFileVars, (int)sizeof(FileVarDecl), |
| 97 | int(nFileVars*sizeof(FileVarDecl))); |
| 98 | fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n", |
| 99 | nParmVars, (int)sizeof(ParmVarDecl), |
| 100 | int(nParmVars*sizeof(ParmVarDecl))); |
| 101 | fprintf(stderr, " %d field decls, %d each (%d bytes)\n", |
| 102 | nFieldDecls, (int)sizeof(FieldDecl), |
| 103 | int(nFieldDecls*sizeof(FieldDecl))); |
| 104 | fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n", |
| 105 | nSUC, (int)sizeof(RecordDecl), |
| 106 | int(nSUC*sizeof(RecordDecl))); |
| 107 | fprintf(stderr, " %d enum decls, %d each (%d bytes)\n", |
| 108 | nEnumDecls, (int)sizeof(EnumDecl), |
| 109 | int(nEnumDecls*sizeof(EnumDecl))); |
| 110 | fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n", |
| 111 | nEnumConst, (int)sizeof(EnumConstantDecl), |
| 112 | int(nEnumConst*sizeof(EnumConstantDecl))); |
| 113 | fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n", |
| 114 | nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 115 | // Objective-C decls... |
| 116 | fprintf(stderr, " %d interface decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 117 | nInterfaceDecls, (int)sizeof(ObjCInterfaceDecl), |
| 118 | int(nInterfaceDecls*sizeof(ObjCInterfaceDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 119 | fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 120 | nIvarDecls, (int)sizeof(ObjCIvarDecl), |
| 121 | int(nIvarDecls*sizeof(ObjCIvarDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 122 | fprintf(stderr, " %d class decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 123 | nClassDecls, (int)sizeof(ObjCClassDecl), |
| 124 | int(nClassDecls*sizeof(ObjCClassDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 125 | fprintf(stderr, " %d method decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 126 | nMethodDecls, (int)sizeof(ObjCMethodDecl), |
| 127 | int(nMethodDecls*sizeof(ObjCMethodDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 128 | fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 129 | nProtocolDecls, (int)sizeof(ObjCProtocolDecl), |
| 130 | int(nProtocolDecls*sizeof(ObjCProtocolDecl))); |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 131 | fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 132 | nForwardProtocolDecls, (int)sizeof(ObjCForwardProtocolDecl), |
| 133 | int(nForwardProtocolDecls*sizeof(ObjCForwardProtocolDecl))); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 134 | fprintf(stderr, " %d category decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 135 | nCategoryDecls, (int)sizeof(ObjCCategoryDecl), |
| 136 | int(nCategoryDecls*sizeof(ObjCCategoryDecl))); |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 137 | |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 138 | fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 139 | nObjCImplementationDecls, (int)sizeof(ObjCImplementationDecl), |
| 140 | int(nObjCImplementationDecls*sizeof(ObjCImplementationDecl))); |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 141 | |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 142 | fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 143 | nObjCCategoryImpl, (int)sizeof(ObjCCategoryImplDecl), |
| 144 | int(nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl))); |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 145 | |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 146 | fprintf(stderr, " %d compatibility alias decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 147 | nObjCCompatibleAlias, (int)sizeof(ObjCCompatibleAliasDecl), |
| 148 | int(nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl))); |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 149 | |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 150 | fprintf(stderr, " %d property decls, %d each (%d bytes)\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 151 | nObjCPropertyDecl, (int)sizeof(ObjCPropertyDecl), |
| 152 | int(nObjCPropertyDecl*sizeof(ObjCPropertyDecl))); |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 153 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 154 | fprintf(stderr, "Total bytes = %d\n", |
| 155 | int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+ |
| 156 | nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+ |
| 157 | nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+ |
| 158 | nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+ |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 159 | nTypedef*sizeof(TypedefDecl)) /* FIXME: add ObjC decls */); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void Decl::addDeclKind(const Kind k) { |
| 163 | switch (k) { |
| 164 | case Typedef: |
| 165 | nTypedef++; |
| 166 | break; |
| 167 | case Function: |
| 168 | nFuncs++; |
| 169 | break; |
Chris Lattner | 3289bca | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 170 | case BlockVar: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 171 | nBlockVars++; |
| 172 | break; |
Chris Lattner | 3289bca | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 173 | case FileVar: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 174 | nFileVars++; |
| 175 | break; |
Chris Lattner | 3289bca | 2007-10-08 21:37:32 +0000 | [diff] [blame] | 176 | case ParmVar: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 177 | nParmVars++; |
| 178 | break; |
| 179 | case EnumConstant: |
| 180 | nEnumConst++; |
| 181 | break; |
| 182 | case Field: |
| 183 | nFieldDecls++; |
| 184 | break; |
| 185 | case Struct: |
| 186 | case Union: |
| 187 | case Class: |
| 188 | nSUC++; |
| 189 | break; |
| 190 | case Enum: |
| 191 | nEnumDecls++; |
| 192 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 193 | case ObjCInterface: |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 194 | nInterfaceDecls++; |
| 195 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 196 | case ObjCClass: |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 197 | nClassDecls++; |
| 198 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 199 | case ObjCMethod: |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 200 | nMethodDecls++; |
| 201 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 202 | case ObjCProtocol: |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 203 | nProtocolDecls++; |
| 204 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 205 | case ObjCForwardProtocol: |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 206 | nForwardProtocolDecls++; |
| 207 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 208 | case ObjCCategory: |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 209 | nCategoryDecls++; |
| 210 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 211 | case ObjCIvar: |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 212 | nIvarDecls++; |
Chris Lattner | b15b438 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 213 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 214 | case ObjCImplementation: |
| 215 | nObjCImplementationDecls++; |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 216 | break; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 217 | case ObjCCategoryImpl: |
| 218 | nObjCCategoryImpl++; |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 219 | break; |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 220 | case CompatibleAlias: |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 221 | nObjCCompatibleAlias++; |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 222 | break; |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 223 | case PropertyDecl: |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 224 | nObjCPropertyDecl++; |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 225 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | // Out-of-line virtual method providing a home for Decl. |
| 230 | Decl::~Decl() { |
| 231 | } |
| 232 | |
Chris Lattner | 910435b | 2007-10-06 22:53:46 +0000 | [diff] [blame] | 233 | const char *NamedDecl::getName() const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 234 | if (const IdentifierInfo *II = getIdentifier()) |
| 235 | return II->getName(); |
| 236 | return ""; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | FunctionDecl::~FunctionDecl() { |
| 241 | delete[] ParamInfo; |
| 242 | } |
| 243 | |
| 244 | unsigned FunctionDecl::getNumParams() const { |
Chris Lattner | 23d411b | 2007-12-06 17:20:20 +0000 | [diff] [blame] | 245 | if (isa<FunctionTypeNoProto>(getCanonicalType())) return 0; |
| 246 | return cast<FunctionTypeProto>(getCanonicalType())->getNumArgs(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { |
| 250 | assert(ParamInfo == 0 && "Already has param info!"); |
| 251 | assert(NumParams == getNumParams() && "Parameter count mismatch!"); |
| 252 | |
| 253 | // Zero params -> null pointer. |
| 254 | if (NumParams) { |
| 255 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 256 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | |
| 261 | /// defineBody - When created, RecordDecl's correspond to a forward declared |
| 262 | /// record. This method is used to mark the decl as being defined, with the |
| 263 | /// specified contents. |
| 264 | void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) { |
| 265 | assert(!isDefinition() && "Cannot redefine record!"); |
| 266 | setDefinition(true); |
| 267 | NumMembers = numMembers; |
| 268 | if (numMembers) { |
| 269 | Members = new FieldDecl*[numMembers]; |
| 270 | memcpy(Members, members, numMembers*sizeof(Decl*)); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | FieldDecl* RecordDecl::getMember(IdentifierInfo *name) { |
| 275 | if (Members == 0 || NumMembers < 0) |
| 276 | return 0; |
Fariborz Jahanian | cbc36d4 | 2007-10-04 00:45:27 +0000 | [diff] [blame] | 277 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 278 | // linear search. When C++ classes come along, will likely need to revisit. |
| 279 | for (int i = 0; i < NumMembers; ++i) { |
| 280 | if (Members[i]->getIdentifier() == name) |
| 281 | return Members[i]; |
| 282 | } |
| 283 | return 0; |
| 284 | } |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 285 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 286 | void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, |
Fariborz Jahanian | 84082af | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 287 | unsigned NumParams) { |
Fariborz Jahanian | 86f74a4 | 2007-09-12 18:23:47 +0000 | [diff] [blame] | 288 | assert(ParamInfo == 0 && "Already has param info!"); |
| 289 | |
| 290 | // Zero params -> null pointer. |
| 291 | if (NumParams) { |
| 292 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 293 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 294 | NumMethodParams = NumParams; |
| 295 | } |
| 296 | } |
| 297 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 298 | ObjCMethodDecl::~ObjCMethodDecl() { |
Fariborz Jahanian | 86f74a4 | 2007-09-12 18:23:47 +0000 | [diff] [blame] | 299 | delete[] ParamInfo; |
| 300 | } |
| 301 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 302 | /// ObjCAddInstanceVariablesToClass - Inserts instance variables |
| 303 | /// into ObjCInterfaceDecl's fields. |
Fariborz Jahanian | ebcc9b6 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 304 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 305 | void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 306 | unsigned numIvars, |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 307 | SourceLocation RBrac) { |
Fariborz Jahanian | ebcc9b6 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 308 | NumIvars = numIvars; |
| 309 | if (numIvars) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 310 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 311 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
Fariborz Jahanian | ebcc9b6 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 312 | } |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 313 | setLocEnd(RBrac); |
Fariborz Jahanian | ebcc9b6 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 316 | /// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 317 | /// Variables (Ivars) relative to what declared in @implementation;s class. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 318 | /// Ivars into ObjCImplementationDecl's fields. |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 319 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 320 | void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( |
| 321 | ObjCIvarDecl **ivars, unsigned numIvars) { |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 322 | NumIvars = numIvars; |
| 323 | if (numIvars) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 324 | Ivars = new ObjCIvarDecl*[numIvars]; |
| 325 | memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*)); |
Fariborz Jahanian | d34caf9 | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 329 | /// addMethods - Insert instance and methods declarations into |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 330 | /// ObjCInterfaceDecl's InsMethods and ClsMethods fields. |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 331 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 332 | void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 333 | unsigned numInsMembers, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 334 | ObjCMethodDecl **clsMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 335 | unsigned numClsMembers, |
| 336 | SourceLocation endLoc) { |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 337 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 338 | if (numInsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 339 | InstanceMethods = new ObjCMethodDecl*[numInsMembers]; |
| 340 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 341 | } |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 342 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 343 | if (numClsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 344 | ClassMethods = new ObjCMethodDecl*[numClsMembers]; |
| 345 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 346 | } |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 347 | AtEndLoc = endLoc; |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 350 | /// addMethods - Insert instance and methods declarations into |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 351 | /// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields. |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 352 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 353 | void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 354 | unsigned numInsMembers, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 355 | ObjCMethodDecl **clsMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 356 | unsigned numClsMembers, |
Steve Naroff | 667f168 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 357 | SourceLocation endLoc) { |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 358 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 359 | if (numInsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 360 | InstanceMethods = new ObjCMethodDecl*[numInsMembers]; |
| 361 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 362 | } |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 363 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 364 | if (numClsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 365 | ClassMethods = new ObjCMethodDecl*[numClsMembers]; |
| 366 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 367 | } |
Steve Naroff | 667f168 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 368 | AtEndLoc = endLoc; |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 371 | /// addMethods - Insert instance and methods declarations into |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 372 | /// ObjCCategoryDecl's CatInsMethods and CatClsMethods fields. |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 373 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 374 | void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 375 | unsigned numInsMembers, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 376 | ObjCMethodDecl **clsMethods, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 377 | unsigned numClsMembers, |
Steve Naroff | 667f168 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 378 | SourceLocation endLoc) { |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 379 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 380 | if (numInsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 381 | InstanceMethods = new ObjCMethodDecl*[numInsMembers]; |
| 382 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 383 | } |
Fariborz Jahanian | 1c095a7 | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 384 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 385 | if (numClsMembers) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 386 | ClassMethods = new ObjCMethodDecl*[numClsMembers]; |
| 387 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*)); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 388 | } |
Steve Naroff | 667f168 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 389 | AtEndLoc = endLoc; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 392 | ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable( |
| 393 | IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) { |
| 394 | ObjCInterfaceDecl* ClassDecl = this; |
Steve Naroff | dd2e26c | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 395 | while (ClassDecl != NULL) { |
Chris Lattner | c7b0675 | 2007-12-12 07:56:42 +0000 | [diff] [blame] | 396 | for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end(); |
| 397 | I != E; ++I) { |
| 398 | if ((*I)->getIdentifier() == ID) { |
Steve Naroff | dd2e26c | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 399 | clsDeclared = ClassDecl; |
Chris Lattner | c7b0675 | 2007-12-12 07:56:42 +0000 | [diff] [blame] | 400 | return *I; |
Steve Naroff | dd2e26c | 2007-11-12 13:56:41 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | ClassDecl = ClassDecl->getSuperClass(); |
| 404 | } |
| 405 | return NULL; |
| 406 | } |
| 407 | |
Chris Lattner | ac9ab53 | 2007-12-12 07:30:05 +0000 | [diff] [blame] | 408 | /// lookupInstanceMethod - This method returns an instance method by looking in |
Chris Lattner | 73e795c | 2007-12-12 08:17:45 +0000 | [diff] [blame] | 409 | /// the class, its categories, and its super classes (using a linear search). |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 410 | ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) { |
| 411 | ObjCInterfaceDecl* ClassDecl = this; |
| 412 | ObjCMethodDecl *MethodDecl = 0; |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 413 | |
Steve Naroff | fa465d1 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 414 | while (ClassDecl != NULL) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 415 | if ((MethodDecl = ClassDecl->getInstanceMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 416 | return MethodDecl; |
| 417 | |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 418 | // Didn't find one yet - look through protocols. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 419 | ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols(); |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 420 | int numProtocols = ClassDecl->getNumIntfRefProtocols(); |
| 421 | for (int pIdx = 0; pIdx < numProtocols; pIdx++) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 422 | if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 423 | return MethodDecl; |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 424 | } |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 425 | // Didn't find one yet - now look through categories. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 426 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 427 | while (CatDecl) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 428 | if ((MethodDecl = CatDecl->getInstanceMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 429 | return MethodDecl; |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 430 | CatDecl = CatDecl->getNextClassCategory(); |
| 431 | } |
Steve Naroff | fa465d1 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 432 | ClassDecl = ClassDecl->getSuperClass(); |
| 433 | } |
| 434 | return NULL; |
| 435 | } |
| 436 | |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 437 | // lookupClassMethod - This method returns a class method by looking in the |
Chris Lattner | 73e795c | 2007-12-12 08:17:45 +0000 | [diff] [blame] | 438 | // class, its categories, and its super classes (using a linear search). |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 439 | ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) { |
| 440 | ObjCInterfaceDecl* ClassDecl = this; |
| 441 | ObjCMethodDecl *MethodDecl = 0; |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 442 | |
Steve Naroff | fa465d1 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 443 | while (ClassDecl != NULL) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 444 | if ((MethodDecl = ClassDecl->getClassMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 445 | return MethodDecl; |
| 446 | |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 447 | // Didn't find one yet - look through protocols. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 448 | ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols(); |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 449 | int numProtocols = ClassDecl->getNumIntfRefProtocols(); |
| 450 | for (int pIdx = 0; pIdx < numProtocols; pIdx++) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 451 | if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 452 | return MethodDecl; |
Steve Naroff | 705380b | 2007-10-14 23:13:51 +0000 | [diff] [blame] | 453 | } |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 454 | // Didn't find one yet - now look through categories. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 455 | ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 456 | while (CatDecl) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 457 | if ((MethodDecl = CatDecl->getClassMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 458 | return MethodDecl; |
Steve Naroff | f66d84a | 2007-10-14 18:27:41 +0000 | [diff] [blame] | 459 | CatDecl = CatDecl->getNextClassCategory(); |
| 460 | } |
Steve Naroff | fa465d1 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 461 | ClassDecl = ClassDecl->getSuperClass(); |
| 462 | } |
| 463 | return NULL; |
| 464 | } |
| 465 | |
Chris Lattner | ac9ab53 | 2007-12-12 07:30:05 +0000 | [diff] [blame] | 466 | /// lookupInstanceMethod - This method returns an instance method by looking in |
| 467 | /// the class implementation. Unlike interfaces, we don't look outside the |
| 468 | /// implementation. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 469 | ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) { |
Chris Lattner | ac9ab53 | 2007-12-12 07:30:05 +0000 | [diff] [blame] | 470 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 471 | if ((*I)->getSelector() == Sel) |
| 472 | return *I; |
Steve Naroff | b1c7ad9 | 2007-11-11 00:10:47 +0000 | [diff] [blame] | 473 | return NULL; |
| 474 | } |
| 475 | |
Chris Lattner | ac9ab53 | 2007-12-12 07:30:05 +0000 | [diff] [blame] | 476 | /// lookupClassMethod - This method returns a class method by looking in |
| 477 | /// the class implementation. Unlike interfaces, we don't look outside the |
| 478 | /// implementation. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 479 | ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) { |
Chris Lattner | dea5bec | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 480 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 481 | I != E; ++I) |
| 482 | if ((*I)->getSelector() == Sel) |
| 483 | return *I; |
Steve Naroff | b1c7ad9 | 2007-11-11 00:10:47 +0000 | [diff] [blame] | 484 | return NULL; |
| 485 | } |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 486 | |
Steve Naroff | 3123363 | 2007-11-12 22:05:31 +0000 | [diff] [blame] | 487 | // lookupInstanceMethod - This method returns an instance method by looking in |
| 488 | // the class implementation. Unlike interfaces, we don't look outside the |
| 489 | // implementation. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 490 | ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) { |
Chris Lattner | dea5bec | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 491 | for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I) |
| 492 | if ((*I)->getSelector() == Sel) |
| 493 | return *I; |
Steve Naroff | 3123363 | 2007-11-12 22:05:31 +0000 | [diff] [blame] | 494 | return NULL; |
| 495 | } |
| 496 | |
| 497 | // lookupClassMethod - This method returns an instance method by looking in |
| 498 | // the class implementation. Unlike interfaces, we don't look outside the |
| 499 | // implementation. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 500 | ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) { |
Chris Lattner | dea5bec | 2007-12-12 07:46:12 +0000 | [diff] [blame] | 501 | for (classmeth_iterator I = classmeth_begin(), E = classmeth_end(); |
| 502 | I != E; ++I) |
| 503 | if ((*I)->getSelector() == Sel) |
| 504 | return *I; |
Steve Naroff | 3123363 | 2007-11-12 22:05:31 +0000 | [diff] [blame] | 505 | return NULL; |
| 506 | } |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 507 | |
| 508 | // lookupInstanceMethod - Lookup a instance method in the protocol and protocols |
| 509 | // it inherited. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 510 | ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) { |
| 511 | ObjCMethodDecl *MethodDecl = NULL; |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 512 | |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 513 | if ((MethodDecl = getInstanceMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 514 | return MethodDecl; |
| 515 | |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 516 | if (getNumReferencedProtocols() > 0) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 517 | ObjCProtocolDecl **RefPDecl = getReferencedProtocols(); |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 518 | |
Fariborz Jahanian | 8782907 | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 519 | for (unsigned i = 0; i < getNumReferencedProtocols(); i++) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 520 | if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 521 | return MethodDecl; |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | // lookupInstanceMethod - Lookup a class method in the protocol and protocols |
| 528 | // it inherited. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 529 | ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) { |
| 530 | ObjCMethodDecl *MethodDecl = NULL; |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 531 | |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 532 | if ((MethodDecl = getClassMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 533 | return MethodDecl; |
| 534 | |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 535 | if (getNumReferencedProtocols() > 0) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 536 | ObjCProtocolDecl **RefPDecl = getReferencedProtocols(); |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 537 | |
Fariborz Jahanian | 8782907 | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 538 | for(unsigned i = 0; i < getNumReferencedProtocols(); i++) { |
Steve Naroff | 74273de | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 539 | if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel))) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 540 | return MethodDecl; |
Fariborz Jahanian | be4283c | 2007-12-07 21:21:21 +0000 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | return NULL; |
| 544 | } |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 545 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 546 | ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const { |
| 547 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext)) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 548 | return ID; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 549 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(MethodContext)) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 550 | return CD->getClassInterface(); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 551 | if (ObjCImplementationDecl *IMD = |
| 552 | dyn_cast<ObjCImplementationDecl>(MethodContext)) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 553 | return IMD->getClassInterface(); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 554 | if (ObjCCategoryImplDecl *CID = |
| 555 | dyn_cast<ObjCCategoryImplDecl>(MethodContext)) |
Steve Naroff | 2ce399a | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 556 | return CID->getClassInterface(); |
| 557 | assert(false && "unknown method context"); |
| 558 | return 0; |
| 559 | } |