Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Decl.cpp - Declaration AST Node Implementation -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Decl class and subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Decl.h" |
Steve Naroff | 980e508 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclObjC.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/Lex/IdentifierTable.h" |
| 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 | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 29 | static unsigned nInterfaceDecls = 0; |
Steve Naroff | 3f128ad | 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 | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 33 | static unsigned nForwardProtocolDecls = 0; |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 34 | static unsigned nCategoryDecls = 0; |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 35 | static unsigned nIvarDecls = 0; |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 36 | static unsigned nObjcImplementationDecls = 0; |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 37 | static unsigned nObjcCategoryImpl = 0; |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 38 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 39 | static bool StatSwitch = false; |
| 40 | |
Steve Naroff | e5ea380 | 2007-09-17 14:49:06 +0000 | [diff] [blame] | 41 | const char *Decl::getDeclKindName() const { |
Steve Naroff | 8c9f13e | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 42 | switch (DeclKind) { |
| 43 | default: assert(0 && "Unknown decl kind!"); |
| 44 | case Typedef: |
| 45 | return "Typedef"; |
| 46 | case Function: |
| 47 | return "Function"; |
| 48 | case BlockVariable: |
| 49 | return "BlockVariable"; |
| 50 | case FileVariable: |
| 51 | return "FileVariable"; |
| 52 | case ParmVariable: |
| 53 | return "ParmVariable"; |
| 54 | case EnumConstant: |
| 55 | return "EnumConstant"; |
| 56 | case ObjcInterface: |
| 57 | return "ObjcInterface"; |
| 58 | case ObjcClass: |
| 59 | return "ObjcClass"; |
| 60 | case ObjcMethod: |
| 61 | return "ObjcMethod"; |
Steve Naroff | 8c9f13e | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 62 | case ObjcProtocol: |
| 63 | return "ObjcProtocol"; |
Fariborz Jahanian | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 64 | case ObjcForwardProtocol: |
| 65 | return "ObjcForwardProtocol"; |
Steve Naroff | 8c9f13e | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 66 | case Struct: |
| 67 | return "Struct"; |
| 68 | case Union: |
| 69 | return "Union"; |
| 70 | case Class: |
| 71 | return "Class"; |
| 72 | case Enum: |
| 73 | return "Enum"; |
| 74 | } |
| 75 | } |
| 76 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 77 | bool Decl::CollectingStats(bool enable) { |
| 78 | if (enable) StatSwitch = true; |
Fariborz Jahanian | 3f5faf7 | 2007-10-04 00:45:27 +0000 | [diff] [blame] | 79 | return StatSwitch; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void Decl::PrintStats() { |
| 83 | fprintf(stderr, "*** Decl Stats:\n"); |
| 84 | fprintf(stderr, " %d decls total.\n", |
| 85 | int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+ |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 86 | nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+ |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 87 | nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | fprintf(stderr, " %d function decls, %d each (%d bytes)\n", |
| 89 | nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl))); |
| 90 | fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n", |
| 91 | nBlockVars, (int)sizeof(BlockVarDecl), |
| 92 | int(nBlockVars*sizeof(BlockVarDecl))); |
| 93 | fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n", |
| 94 | nFileVars, (int)sizeof(FileVarDecl), |
| 95 | int(nFileVars*sizeof(FileVarDecl))); |
| 96 | fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n", |
| 97 | nParmVars, (int)sizeof(ParmVarDecl), |
| 98 | int(nParmVars*sizeof(ParmVarDecl))); |
| 99 | fprintf(stderr, " %d field decls, %d each (%d bytes)\n", |
| 100 | nFieldDecls, (int)sizeof(FieldDecl), |
| 101 | int(nFieldDecls*sizeof(FieldDecl))); |
| 102 | fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n", |
| 103 | nSUC, (int)sizeof(RecordDecl), |
| 104 | int(nSUC*sizeof(RecordDecl))); |
| 105 | fprintf(stderr, " %d enum decls, %d each (%d bytes)\n", |
| 106 | nEnumDecls, (int)sizeof(EnumDecl), |
| 107 | int(nEnumDecls*sizeof(EnumDecl))); |
| 108 | fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n", |
| 109 | nEnumConst, (int)sizeof(EnumConstantDecl), |
| 110 | int(nEnumConst*sizeof(EnumConstantDecl))); |
| 111 | fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n", |
| 112 | nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl))); |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 113 | // Objective-C decls... |
| 114 | fprintf(stderr, " %d interface decls, %d each (%d bytes)\n", |
| 115 | nInterfaceDecls, (int)sizeof(ObjcInterfaceDecl), |
| 116 | int(nInterfaceDecls*sizeof(ObjcInterfaceDecl))); |
| 117 | fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n", |
| 118 | nIvarDecls, (int)sizeof(ObjcIvarDecl), |
| 119 | int(nIvarDecls*sizeof(ObjcIvarDecl))); |
| 120 | fprintf(stderr, " %d class decls, %d each (%d bytes)\n", |
| 121 | nClassDecls, (int)sizeof(ObjcClassDecl), |
| 122 | int(nClassDecls*sizeof(ObjcClassDecl))); |
| 123 | fprintf(stderr, " %d method decls, %d each (%d bytes)\n", |
| 124 | nMethodDecls, (int)sizeof(ObjcMethodDecl), |
| 125 | int(nMethodDecls*sizeof(ObjcMethodDecl))); |
| 126 | fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n", |
| 127 | nProtocolDecls, (int)sizeof(ObjcProtocolDecl), |
| 128 | int(nProtocolDecls*sizeof(ObjcProtocolDecl))); |
Fariborz Jahanian | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 129 | fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n", |
| 130 | nForwardProtocolDecls, (int)sizeof(ObjcForwardProtocolDecl), |
| 131 | int(nForwardProtocolDecls*sizeof(ObjcForwardProtocolDecl))); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 132 | fprintf(stderr, " %d category decls, %d each (%d bytes)\n", |
| 133 | nCategoryDecls, (int)sizeof(ObjcCategoryDecl), |
| 134 | int(nCategoryDecls*sizeof(ObjcCategoryDecl))); |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 135 | |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 136 | fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n", |
| 137 | nObjcImplementationDecls, (int)sizeof(ObjcImplementationDecl), |
| 138 | int(nObjcImplementationDecls*sizeof(ObjcImplementationDecl))); |
| 139 | |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 140 | fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n", |
| 141 | nObjcCategoryImpl, (int)sizeof(ObjcCategoryImplDecl), |
| 142 | int(nObjcCategoryImpl*sizeof(ObjcCategoryImplDecl))); |
| 143 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 144 | fprintf(stderr, "Total bytes = %d\n", |
| 145 | int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+ |
| 146 | nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+ |
| 147 | nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+ |
| 148 | nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+ |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 149 | nTypedef*sizeof(TypedefDecl)) /* FIXME: add Objc decls */); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void Decl::addDeclKind(const Kind k) { |
| 153 | switch (k) { |
| 154 | case Typedef: |
| 155 | nTypedef++; |
| 156 | break; |
| 157 | case Function: |
| 158 | nFuncs++; |
| 159 | break; |
| 160 | case BlockVariable: |
| 161 | nBlockVars++; |
| 162 | break; |
| 163 | case FileVariable: |
| 164 | nFileVars++; |
| 165 | break; |
| 166 | case ParmVariable: |
| 167 | nParmVars++; |
| 168 | break; |
| 169 | case EnumConstant: |
| 170 | nEnumConst++; |
| 171 | break; |
| 172 | case Field: |
| 173 | nFieldDecls++; |
| 174 | break; |
| 175 | case Struct: |
| 176 | case Union: |
| 177 | case Class: |
| 178 | nSUC++; |
| 179 | break; |
| 180 | case Enum: |
| 181 | nEnumDecls++; |
| 182 | break; |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 183 | case ObjcInterface: |
| 184 | nInterfaceDecls++; |
| 185 | break; |
Chris Lattner | 7341c33 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 186 | case ObjcClass: |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 187 | nClassDecls++; |
| 188 | break; |
Chris Lattner | 7341c33 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 189 | case ObjcMethod: |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 190 | nMethodDecls++; |
| 191 | break; |
Chris Lattner | 7341c33 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 192 | case ObjcProtocol: |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 193 | nProtocolDecls++; |
| 194 | break; |
Fariborz Jahanian | 894c57f | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 195 | case ObjcForwardProtocol: |
| 196 | nForwardProtocolDecls++; |
| 197 | break; |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 198 | case ObjcCategory: |
| 199 | nCategoryDecls++; |
| 200 | break; |
Chris Lattner | 7341c33 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 201 | case ObjcIvar: |
Steve Naroff | 3f128ad | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 202 | nIvarDecls++; |
Chris Lattner | 7341c33 | 2007-09-16 19:23:04 +0000 | [diff] [blame] | 203 | break; |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 204 | case ObjcImplementation: |
| 205 | nObjcImplementationDecls++; |
| 206 | break; |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 207 | case ObjcCategoryImpl: |
| 208 | nObjcCategoryImpl++; |
| 209 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
| 213 | // Out-of-line virtual method providing a home for Decl. |
| 214 | Decl::~Decl() { |
| 215 | } |
| 216 | |
Chris Lattner | fd5de47 | 2007-10-06 22:53:46 +0000 | [diff] [blame^] | 217 | const char *NamedDecl::getName() const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 218 | if (const IdentifierInfo *II = getIdentifier()) |
| 219 | return II->getName(); |
| 220 | return ""; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | FunctionDecl::~FunctionDecl() { |
| 225 | delete[] ParamInfo; |
| 226 | } |
| 227 | |
| 228 | unsigned FunctionDecl::getNumParams() const { |
| 229 | return cast<FunctionTypeProto>(getType().getTypePtr())->getNumArgs(); |
| 230 | } |
| 231 | |
| 232 | void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { |
| 233 | assert(ParamInfo == 0 && "Already has param info!"); |
| 234 | assert(NumParams == getNumParams() && "Parameter count mismatch!"); |
| 235 | |
| 236 | // Zero params -> null pointer. |
| 237 | if (NumParams) { |
| 238 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 239 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /// defineBody - When created, RecordDecl's correspond to a forward declared |
| 245 | /// record. This method is used to mark the decl as being defined, with the |
| 246 | /// specified contents. |
| 247 | void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) { |
| 248 | assert(!isDefinition() && "Cannot redefine record!"); |
| 249 | setDefinition(true); |
| 250 | NumMembers = numMembers; |
| 251 | if (numMembers) { |
| 252 | Members = new FieldDecl*[numMembers]; |
| 253 | memcpy(Members, members, numMembers*sizeof(Decl*)); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | FieldDecl* RecordDecl::getMember(IdentifierInfo *name) { |
| 258 | if (Members == 0 || NumMembers < 0) |
| 259 | return 0; |
Fariborz Jahanian | 3f5faf7 | 2007-10-04 00:45:27 +0000 | [diff] [blame] | 260 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 261 | // linear search. When C++ classes come along, will likely need to revisit. |
| 262 | for (int i = 0; i < NumMembers; ++i) { |
| 263 | if (Members[i]->getIdentifier() == name) |
| 264 | return Members[i]; |
| 265 | } |
| 266 | return 0; |
Chris Lattner | 6fa5f09 | 2007-07-12 15:43:07 +0000 | [diff] [blame] | 267 | } |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 268 | |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 269 | void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, |
| 270 | unsigned NumParams) { |
Fariborz Jahanian | e55cd00 | 2007-09-12 18:23:47 +0000 | [diff] [blame] | 271 | assert(ParamInfo == 0 && "Already has param info!"); |
| 272 | |
| 273 | // Zero params -> null pointer. |
| 274 | if (NumParams) { |
| 275 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 276 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 277 | NumMethodParams = NumParams; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | ObjcMethodDecl::~ObjcMethodDecl() { |
| 282 | delete[] ParamInfo; |
| 283 | } |
| 284 | |
Fariborz Jahanian | b04a021 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 285 | /// ObjcAddInstanceVariablesToClass - Inserts instance variables |
| 286 | /// into ObjcInterfaceDecl's fields. |
| 287 | /// |
| 288 | void ObjcInterfaceDecl::ObjcAddInstanceVariablesToClass(ObjcIvarDecl **ivars, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 289 | unsigned numIvars) { |
Fariborz Jahanian | b04a021 | 2007-09-14 21:08:27 +0000 | [diff] [blame] | 290 | NumIvars = numIvars; |
| 291 | if (numIvars) { |
| 292 | Ivars = new ObjcIvarDecl*[numIvars]; |
| 293 | memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*)); |
| 294 | } |
| 295 | } |
| 296 | |
Fariborz Jahanian | d0b90bf | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 297 | /// ObjcAddInstanceVariablesToClassImpl - Checks for correctness of Instance |
| 298 | /// Variables (Ivars) relative to what declared in @implementation;s class. |
| 299 | /// Ivars into ObjcImplementationDecl's fields. |
| 300 | /// |
| 301 | void ObjcImplementationDecl::ObjcAddInstanceVariablesToClassImpl( |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 302 | ObjcIvarDecl **ivars, unsigned numIvars) { |
Fariborz Jahanian | d0b90bf | 2007-09-26 18:27:25 +0000 | [diff] [blame] | 303 | NumIvars = numIvars; |
| 304 | if (numIvars) { |
| 305 | Ivars = new ObjcIvarDecl*[numIvars]; |
| 306 | memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*)); |
| 307 | } |
| 308 | } |
| 309 | |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 310 | /// addObjcMethods - Insert instance and methods declarations into |
| 311 | /// ObjcInterfaceDecl's InsMethods and ClsMethods fields. |
| 312 | /// |
| 313 | void ObjcInterfaceDecl::ObjcAddMethods(ObjcMethodDecl **insMethods, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 314 | unsigned numInsMembers, |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 315 | ObjcMethodDecl **clsMethods, |
| 316 | unsigned numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 317 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 318 | if (numInsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 319 | InstanceMethods = new ObjcMethodDecl*[numInsMembers]; |
| 320 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 321 | } |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 322 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 323 | if (numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 324 | ClassMethods = new ObjcMethodDecl*[numClsMembers]; |
| 325 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 329 | /// ObjcAddProtoMethods - Insert instance and methods declarations into |
| 330 | /// ObjcProtocolDecl's ProtoInsMethods and ProtoClsMethods fields. |
| 331 | /// |
| 332 | void ObjcProtocolDecl::ObjcAddProtoMethods(ObjcMethodDecl **insMethods, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 333 | unsigned numInsMembers, |
| 334 | ObjcMethodDecl **clsMethods, |
| 335 | unsigned numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 336 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 337 | if (numInsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 338 | InstanceMethods = new ObjcMethodDecl*[numInsMembers]; |
| 339 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 340 | } |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 341 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 342 | if (numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 343 | ClassMethods = new ObjcMethodDecl*[numClsMembers]; |
| 344 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 348 | /// ObjcAddCat - Insert instance and methods declarations into |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 349 | /// ObjcCategoryDecl's CatInsMethods and CatClsMethods fields. |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 350 | /// |
| 351 | void ObjcCategoryDecl::ObjcAddCatMethods(ObjcMethodDecl **insMethods, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 352 | unsigned numInsMembers, |
| 353 | ObjcMethodDecl **clsMethods, |
| 354 | unsigned numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 355 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 356 | if (numInsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 357 | InstanceMethods = new ObjcMethodDecl*[numInsMembers]; |
| 358 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 359 | } |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 360 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 361 | if (numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 362 | ClassMethods = new ObjcMethodDecl*[numClsMembers]; |
| 363 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 367 | /// ObjcAddCatImplMethods - Insert instance and methods declarations into |
| 368 | /// ObjcCategoryImplDecl's CatInsMethods and CatClsMethods fields. |
| 369 | /// |
| 370 | void ObjcCategoryImplDecl::ObjcAddCatImplMethods(ObjcMethodDecl **insMethods, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 371 | unsigned numInsMembers, |
| 372 | ObjcMethodDecl **clsMethods, |
| 373 | unsigned numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 374 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 375 | if (numInsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 376 | InstanceMethods = new ObjcMethodDecl*[numInsMembers]; |
| 377 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 378 | } |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 379 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 380 | if (numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 381 | ClassMethods = new ObjcMethodDecl*[numClsMembers]; |
| 382 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Fariborz Jahanian | d0b0154 | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 386 | /// ObjcAddImplMethods - Insert instance and methods declarations into |
| 387 | /// ObjcImplementationDecl's InsMethods and ClsMethods fields. |
| 388 | /// |
| 389 | void ObjcImplementationDecl::ObjcAddImplMethods(ObjcMethodDecl **insMethods, |
Fariborz Jahanian | 5951965 | 2007-10-04 17:06:28 +0000 | [diff] [blame] | 390 | unsigned numInsMembers, |
| 391 | ObjcMethodDecl **clsMethods, |
| 392 | unsigned numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 393 | NumInstanceMethods = numInsMembers; |
Fariborz Jahanian | d0b0154 | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 394 | if (numInsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 395 | InstanceMethods = new ObjcMethodDecl*[numInsMembers]; |
| 396 | memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | d0b0154 | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 397 | } |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 398 | NumClassMethods = numClsMembers; |
Fariborz Jahanian | d0b0154 | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 399 | if (numClsMembers) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 400 | ClassMethods = new ObjcMethodDecl*[numClsMembers]; |
| 401 | memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*)); |
Fariborz Jahanian | d0b0154 | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 405 | // FIXME: look through categories... |
| 406 | ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) { |
| 407 | ObjcInterfaceDecl* ClassDecl = this; |
| 408 | while (ClassDecl != NULL) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 409 | ObjcMethodDecl **methods = ClassDecl->getInstanceMethods(); |
| 410 | int methodCount = ClassDecl->getNumInstanceMethods(); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 411 | for (int i = 0; i < methodCount; ++i) { |
| 412 | if (methods[i]->getSelector() == Sel) { |
| 413 | return methods[i]; |
| 414 | } |
| 415 | } |
| 416 | ClassDecl = ClassDecl->getSuperClass(); |
| 417 | } |
| 418 | return NULL; |
| 419 | } |
| 420 | |
| 421 | // FIXME: look through categories... |
| 422 | ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) { |
| 423 | ObjcInterfaceDecl* ClassDecl = this; |
| 424 | while (ClassDecl != NULL) { |
Fariborz Jahanian | 7ed9e0f | 2007-10-02 22:05:16 +0000 | [diff] [blame] | 425 | ObjcMethodDecl **methods = ClassDecl->getClassMethods(); |
| 426 | int methodCount = ClassDecl->getNumClassMethods(); |
Steve Naroff | 6a8a9a4 | 2007-10-02 20:01:56 +0000 | [diff] [blame] | 427 | for (int i = 0; i < methodCount; ++i) { |
| 428 | if (methods[i]->getSelector() == Sel) { |
| 429 | return methods[i]; |
| 430 | } |
| 431 | } |
| 432 | ClassDecl = ClassDecl->getSuperClass(); |
| 433 | } |
| 434 | return NULL; |
| 435 | } |
| 436 | |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 437 | |