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" 16 #include "clang/AST/ASTMutationListener.h" 17 #include "clang/AST/Attr.h" 18 #include "clang/AST/Stmt.h" 19 #include "llvm/ADT/STLExtras.h" 20 #include "llvm/ADT/SmallString.h" 21 using namespace clang; 22 23 //===----------------------------------------------------------------------===// 24 // ObjCListBase 25 //===----------------------------------------------------------------------===// 26 27 void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { 28 List = 0; 29 if (Elts == 0) return; // Setting to an empty list is a noop. 30 31 32 List = new (Ctx) void*[Elts]; 33 NumElts = Elts; 34 memcpy(List, InList, sizeof(void*)*Elts); 35 } 36 37 void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, 38 const SourceLocation *Locs, ASTContext &Ctx) { 39 if (Elts == 0) 40 return; 41 42 Locations = new (Ctx) SourceLocation[Elts]; 43 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); 44 set(InList, Elts, Ctx); 45 } 46 47 //===----------------------------------------------------------------------===// 48 // ObjCInterfaceDecl 49 //===----------------------------------------------------------------------===// 50 51 void ObjCContainerDecl::anchor() { } 52 53 /// getIvarDecl - This method looks up an ivar in this ContextDecl. 54 /// 55 ObjCIvarDecl * 56 ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { 57 lookup_const_result R = lookup(Id); 58 for (lookup_const_iterator Ivar = R.begin(), IvarEnd = R.end(); 59 Ivar != IvarEnd; ++Ivar) { 60 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) 61 return ivar; 62 } 63 return 0; 64 } 65 66 // Get the local instance/class method declared in this interface. 67 ObjCMethodDecl * 68 ObjCContainerDecl::getMethod(Selector Sel, bool isInstance, 69 bool AllowHidden) const { 70 // If this context is a hidden protocol definition, don't find any 71 // methods there. 72 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) { 73 if (const ObjCProtocolDecl *Def = Proto->getDefinition()) 74 if (Def->isHidden() && !AllowHidden) 75 return 0; 76 } 77 78 // Since instance & class methods can have the same name, the loop below 79 // ensures we get the correct method. 80 // 81 // @interface Whatever 82 // - (int) class_method; 83 // + (float) class_method; 84 // @end 85 // 86 lookup_const_result R = lookup(Sel); 87 for (lookup_const_iterator Meth = R.begin(), MethEnd = R.end(); 88 Meth != MethEnd; ++Meth) { 89 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); 90 if (MD && MD->isInstanceMethod() == isInstance) 91 return MD; 92 } 93 return 0; 94 } 95 96 /// HasUserDeclaredSetterMethod - This routine returns 'true' if a user declared setter 97 /// method was found in the class, its protocols, its super classes or categories. 98 /// It also returns 'true' if one of its categories has declared a 'readwrite' property. 99 /// This is because, user must provide a setter method for the category's 'readwrite' 100 /// property. 101 bool 102 ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property) const { 103 Selector Sel = Property->getSetterName(); 104 lookup_const_result R = lookup(Sel); 105 for (lookup_const_iterator Meth = R.begin(), MethEnd = R.end(); 106 Meth != MethEnd; ++Meth) { 107 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); 108 if (MD && MD->isInstanceMethod() && !MD->isImplicit()) 109 return true; 110 } 111 112 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(this)) { 113 // Also look into categories, including class extensions, looking 114 // for a user declared instance method. 115 for (const auto *Cat : ID->visible_categories()) { 116 if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel)) 117 if (!MD->isImplicit()) 118 return true; 119 if (Cat->IsClassExtension()) 120 continue; 121 // Also search through the categories looking for a 'readwrite' declaration 122 // of this property. If one found, presumably a setter will be provided 123 // (properties declared in categories will not get auto-synthesized). 124 for (const auto *P : Cat->properties()) 125 if (P->getIdentifier() == Property->getIdentifier()) { 126 if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) 127 return true; 128 break; 129 } 130 } 131 132 // Also look into protocols, for a user declared instance method. 133 for (const auto *Proto : ID->all_referenced_protocols()) 134 if (Proto->HasUserDeclaredSetterMethod(Property)) 135 return true; 136 137 // And in its super class. 138 ObjCInterfaceDecl *OSC = ID->getSuperClass(); 139 while (OSC) { 140 if (OSC->HasUserDeclaredSetterMethod(Property)) 141 return true; 142 OSC = OSC->getSuperClass(); 143 } 144 } 145 if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this)) 146 for (const auto *PI : PD->protocols()) 147 if (PI->HasUserDeclaredSetterMethod(Property)) 148 return true; 149 return false; 150 } 151 152 ObjCPropertyDecl * 153 ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, 154 IdentifierInfo *propertyID) { 155 // If this context is a hidden protocol definition, don't find any 156 // property. 157 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(DC)) { 158 if (const ObjCProtocolDecl *Def = Proto->getDefinition()) 159 if (Def->isHidden()) 160 return 0; 161 } 162 163 DeclContext::lookup_const_result R = DC->lookup(propertyID); 164 for (DeclContext::lookup_const_iterator I = R.begin(), E = R.end(); I != E; 165 ++I) 166 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) 167 return PD; 168 169 return 0; 170 } 171 172 IdentifierInfo * 173 ObjCPropertyDecl::getDefaultSynthIvarName(ASTContext &Ctx) const { 174 SmallString<128> ivarName; 175 { 176 llvm::raw_svector_ostream os(ivarName); 177 os << '_' << getIdentifier()->getName(); 178 } 179 return &Ctx.Idents.get(ivarName.str()); 180 } 181 182 /// FindPropertyDeclaration - Finds declaration of the property given its name 183 /// in 'PropertyId' and returns it. It returns 0, if not found. 184 ObjCPropertyDecl * 185 ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { 186 // Don't find properties within hidden protocol definitions. 187 if (const ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(this)) { 188 if (const ObjCProtocolDecl *Def = Proto->getDefinition()) 189 if (Def->isHidden()) 190 return 0; 191 } 192 193 if (ObjCPropertyDecl *PD = 194 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) 195 return PD; 196 197 switch (getKind()) { 198 default: 199 break; 200 case Decl::ObjCProtocol: { 201 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); 202 for (const auto *I : PID->protocols()) 203 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) 204 return P; 205 break; 206 } 207 case Decl::ObjCInterface: { 208 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); 209 // Look through categories (but not extensions). 210 for (const auto *Cat : OID->visible_categories()) { 211 if (!Cat->IsClassExtension()) 212 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) 213 return P; 214 } 215 216 // Look through protocols. 217 for (const auto *I : OID->all_referenced_protocols()) 218 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) 219 return P; 220 221 // Finally, check the super class. 222 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) 223 return superClass->FindPropertyDeclaration(PropertyId); 224 break; 225 } 226 case Decl::ObjCCategory: { 227 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); 228 // Look through protocols. 229 if (!OCD->IsClassExtension()) 230 for (const auto *I : OCD->protocols()) 231 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) 232 return P; 233 break; 234 } 235 } 236 return 0; 237 } 238 239 void ObjCInterfaceDecl::anchor() { } 240 241 /// FindPropertyVisibleInPrimaryClass - Finds declaration of the property 242 /// with name 'PropertyId' in the primary class; including those in protocols 243 /// (direct or indirect) used by the primary class. 244 /// 245 ObjCPropertyDecl * 246 ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( 247 IdentifierInfo *PropertyId) const { 248 // FIXME: Should make sure no callers ever do this. 249 if (!hasDefinition()) 250 return 0; 251 252 if (data().ExternallyCompleted) 253 LoadExternalDefinition(); 254 255 if (ObjCPropertyDecl *PD = 256 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) 257 return PD; 258 259 // Look through protocols. 260 for (const auto *I : all_referenced_protocols()) 261 if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) 262 return P; 263 264 return 0; 265 } 266 267 void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, 268 PropertyDeclOrder &PO) const { 269 for (auto *Prop : properties()) { 270 PM[Prop->getIdentifier()] = Prop; 271 PO.push_back(Prop); 272 } 273 for (const auto *PI : all_referenced_protocols()) 274 PI->collectPropertiesToImplement(PM, PO); 275 // Note, the properties declared only in class extensions are still copied 276 // into the main @interface's property list, and therefore we don't 277 // explicitly, have to search class extension properties. 278 } 279 280 bool ObjCInterfaceDecl::isArcWeakrefUnavailable() const { 281 const ObjCInterfaceDecl *Class = this; 282 while (Class) { 283 if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) 284 return true; 285 Class = Class->getSuperClass(); 286 } 287 return false; 288 } 289 290 const ObjCInterfaceDecl *ObjCInterfaceDecl::isObjCRequiresPropertyDefs() const { 291 const ObjCInterfaceDecl *Class = this; 292 while (Class) { 293 if (Class->hasAttr<ObjCRequiresPropertyDefsAttr>()) 294 return Class; 295 Class = Class->getSuperClass(); 296 } 297 return 0; 298 } 299 300 void ObjCInterfaceDecl::mergeClassExtensionProtocolList( 301 ObjCProtocolDecl *const* ExtList, unsigned ExtNum, 302 ASTContext &C) 303 { 304 if (data().ExternallyCompleted) 305 LoadExternalDefinition(); 306 307 if (data().AllReferencedProtocols.empty() && 308 data().ReferencedProtocols.empty()) { 309 data().AllReferencedProtocols.set(ExtList, ExtNum, C); 310 return; 311 } 312 313 // Check for duplicate protocol in class's protocol list. 314 // This is O(n*m). But it is extremely rare and number of protocols in 315 // class or its extension are very few. 316 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; 317 for (unsigned i = 0; i < ExtNum; i++) { 318 bool protocolExists = false; 319 ObjCProtocolDecl *ProtoInExtension = ExtList[i]; 320 for (auto *Proto : all_referenced_protocols()) { 321 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { 322 protocolExists = true; 323 break; 324 } 325 } 326 // Do we want to warn on a protocol in extension class which 327 // already exist in the class? Probably not. 328 if (!protocolExists) 329 ProtocolRefs.push_back(ProtoInExtension); 330 } 331 332 if (ProtocolRefs.empty()) 333 return; 334 335 // Merge ProtocolRefs into class's protocol list; 336 for (auto *P : all_referenced_protocols()) { 337 ProtocolRefs.push_back(P); 338 } 339 340 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); 341 } 342 343 const ObjCInterfaceDecl * 344 ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const { 345 const ObjCInterfaceDecl *IFace = this; 346 while (IFace) { 347 if (IFace->hasDesignatedInitializers()) 348 return IFace; 349 if (!IFace->inheritsDesignatedInitializers()) 350 break; 351 IFace = IFace->getSuperClass(); 352 } 353 return 0; 354 } 355 356 static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) { 357 for (const auto *MD : D->instance_methods()) { 358 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) 359 return true; 360 } 361 for (const auto *Ext : D->visible_extensions()) { 362 for (const auto *MD : Ext->instance_methods()) { 363 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) 364 return true; 365 } 366 } 367 if (const auto *ImplD = D->getImplementation()) { 368 for (const auto *MD : ImplD->instance_methods()) { 369 if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) 370 return true; 371 } 372 } 373 return false; 374 } 375 376 bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const { 377 switch (data().InheritedDesignatedInitializers) { 378 case DefinitionData::IDI_Inherited: 379 return true; 380 case DefinitionData::IDI_NotInherited: 381 return false; 382 case DefinitionData::IDI_Unknown: { 383 // If the class introduced initializers we conservatively assume that we 384 // don't know if any of them is a designated initializer to avoid possible 385 // misleading warnings. 386 if (isIntroducingInitializers(this)) { 387 data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited; 388 return false; 389 } else { 390 data().InheritedDesignatedInitializers = DefinitionData::IDI_Inherited; 391 return true; 392 } 393 } 394 } 395 396 llvm_unreachable("unexpected InheritedDesignatedInitializers value"); 397 } 398 399 void ObjCInterfaceDecl::getDesignatedInitializers( 400 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const { 401 // Check for a complete definition and recover if not so. 402 if (!isThisDeclarationADefinition()) 403 return; 404 if (data().ExternallyCompleted) 405 LoadExternalDefinition(); 406 407 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); 408 if (!IFace) 409 return; 410 411 for (const auto *MD : IFace->instance_methods()) 412 if (MD->isThisDeclarationADesignatedInitializer()) 413 Methods.push_back(MD); 414 for (const auto *Ext : IFace->visible_extensions()) { 415 for (const auto *MD : Ext->instance_methods()) 416 if (MD->isThisDeclarationADesignatedInitializer()) 417 Methods.push_back(MD); 418 } 419 } 420 421 bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel, 422 const ObjCMethodDecl **InitMethod) const { 423 // Check for a complete definition and recover if not so. 424 if (!isThisDeclarationADefinition()) 425 return false; 426 if (data().ExternallyCompleted) 427 LoadExternalDefinition(); 428 429 const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); 430 if (!IFace) 431 return false; 432 433 if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) { 434 if (MD->isThisDeclarationADesignatedInitializer()) { 435 if (InitMethod) 436 *InitMethod = MD; 437 return true; 438 } 439 } 440 for (const auto *Ext : IFace->visible_extensions()) { 441 if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) { 442 if (MD->isThisDeclarationADesignatedInitializer()) { 443 if (InitMethod) 444 *InitMethod = MD; 445 return true; 446 } 447 } 448 } 449 return false; 450 } 451 452 void ObjCInterfaceDecl::allocateDefinitionData() { 453 assert(!hasDefinition() && "ObjC class already has a definition"); 454 Data.setPointer(new (getASTContext()) DefinitionData()); 455 Data.getPointer()->Definition = this; 456 457 // Make the type point at the definition, now that we have one. 458 if (TypeForDecl) 459 cast<ObjCInterfaceType>(TypeForDecl)->Decl = this; 460 } 461 462 void ObjCInterfaceDecl::startDefinition() { 463 allocateDefinitionData(); 464 465 // Update all of the declarations with a pointer to the definition. 466 for (auto RD : redecls()) { 467 if (RD != this) 468 RD->Data = Data; 469 } 470 } 471 472 ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, 473 ObjCInterfaceDecl *&clsDeclared) { 474 // FIXME: Should make sure no callers ever do this. 475 if (!hasDefinition()) 476 return 0; 477 478 if (data().ExternallyCompleted) 479 LoadExternalDefinition(); 480 481 ObjCInterfaceDecl* ClassDecl = this; 482 while (ClassDecl != NULL) { 483 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { 484 clsDeclared = ClassDecl; 485 return I; 486 } 487 488 for (const auto *Ext : ClassDecl->visible_extensions()) { 489 if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) { 490 clsDeclared = ClassDecl; 491 return I; 492 } 493 } 494 495 ClassDecl = ClassDecl->getSuperClass(); 496 } 497 return NULL; 498 } 499 500 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super 501 /// class whose name is passed as argument. If it is not one of the super classes 502 /// the it returns NULL. 503 ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( 504 const IdentifierInfo*ICName) { 505 // FIXME: Should make sure no callers ever do this. 506 if (!hasDefinition()) 507 return 0; 508 509 if (data().ExternallyCompleted) 510 LoadExternalDefinition(); 511 512 ObjCInterfaceDecl* ClassDecl = this; 513 while (ClassDecl != NULL) { 514 if (ClassDecl->getIdentifier() == ICName) 515 return ClassDecl; 516 ClassDecl = ClassDecl->getSuperClass(); 517 } 518 return NULL; 519 } 520 521 ObjCProtocolDecl * 522 ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) { 523 for (auto *P : all_referenced_protocols()) 524 if (P->lookupProtocolNamed(Name)) 525 return P; 526 ObjCInterfaceDecl *SuperClass = getSuperClass(); 527 return SuperClass ? SuperClass->lookupNestedProtocol(Name) : NULL; 528 } 529 530 /// lookupMethod - This method returns an instance/class method by looking in 531 /// the class, its categories, and its super classes (using a linear search). 532 /// When argument category "C" is specified, any implicit method found 533 /// in this category is ignored. 534 ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, 535 bool isInstance, 536 bool shallowCategoryLookup, 537 bool followSuper, 538 const ObjCCategoryDecl *C) const 539 { 540 // FIXME: Should make sure no callers ever do this. 541 if (!hasDefinition()) 542 return 0; 543 544 const ObjCInterfaceDecl* ClassDecl = this; 545 ObjCMethodDecl *MethodDecl = 0; 546 547 if (data().ExternallyCompleted) 548 LoadExternalDefinition(); 549 550 while (ClassDecl) { 551 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) 552 return MethodDecl; 553 554 // Didn't find one yet - look through protocols. 555 for (const auto *I : ClassDecl->protocols()) 556 if ((MethodDecl = I->lookupMethod(Sel, isInstance))) 557 return MethodDecl; 558 559 // Didn't find one yet - now look through categories. 560 for (const auto *Cat : ClassDecl->visible_categories()) { 561 if ((MethodDecl = Cat->getMethod(Sel, isInstance))) 562 if (C != Cat || !MethodDecl->isImplicit()) 563 return MethodDecl; 564 565 if (!shallowCategoryLookup) { 566 // Didn't find one yet - look through protocols. 567 const ObjCList<ObjCProtocolDecl> &Protocols = 568 Cat->getReferencedProtocols(); 569 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 570 E = Protocols.end(); I != E; ++I) 571 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) 572 if (C != Cat || !MethodDecl->isImplicit()) 573 return MethodDecl; 574 } 575 } 576 577 if (!followSuper) 578 return NULL; 579 580 // Get the super class (if any). 581 ClassDecl = ClassDecl->getSuperClass(); 582 } 583 return NULL; 584 } 585 586 // Will search "local" class/category implementations for a method decl. 587 // If failed, then we search in class's root for an instance method. 588 // Returns 0 if no method is found. 589 ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( 590 const Selector &Sel, 591 bool Instance) const { 592 // FIXME: Should make sure no callers ever do this. 593 if (!hasDefinition()) 594 return 0; 595 596 if (data().ExternallyCompleted) 597 LoadExternalDefinition(); 598 599 ObjCMethodDecl *Method = 0; 600 if (ObjCImplementationDecl *ImpDecl = getImplementation()) 601 Method = Instance ? ImpDecl->getInstanceMethod(Sel) 602 : ImpDecl->getClassMethod(Sel); 603 604 // Look through local category implementations associated with the class. 605 if (!Method) 606 Method = Instance ? getCategoryInstanceMethod(Sel) 607 : getCategoryClassMethod(Sel); 608 609 // Before we give up, check if the selector is an instance method. 610 // But only in the root. This matches gcc's behavior and what the 611 // runtime expects. 612 if (!Instance && !Method && !getSuperClass()) { 613 Method = lookupInstanceMethod(Sel); 614 // Look through local category implementations associated 615 // with the root class. 616 if (!Method) 617 Method = lookupPrivateMethod(Sel, true); 618 } 619 620 if (!Method && getSuperClass()) 621 return getSuperClass()->lookupPrivateMethod(Sel, Instance); 622 return Method; 623 } 624 625 //===----------------------------------------------------------------------===// 626 // ObjCMethodDecl 627 //===----------------------------------------------------------------------===// 628 629 ObjCMethodDecl *ObjCMethodDecl::Create( 630 ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, 631 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, 632 DeclContext *contextDecl, bool isInstance, bool isVariadic, 633 bool isPropertyAccessor, bool isImplicitlyDeclared, bool isDefined, 634 ImplementationControl impControl, bool HasRelatedResultType) { 635 return new (C, contextDecl) ObjCMethodDecl( 636 beginLoc, endLoc, SelInfo, T, ReturnTInfo, contextDecl, isInstance, 637 isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined, 638 impControl, HasRelatedResultType); 639 } 640 641 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 642 return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(), 643 Selector(), QualType(), 0, 0); 644 } 645 646 bool ObjCMethodDecl::isThisDeclarationADesignatedInitializer() const { 647 return getMethodFamily() == OMF_init && 648 hasAttr<ObjCDesignatedInitializerAttr>(); 649 } 650 651 bool ObjCMethodDecl::isDesignatedInitializerForTheInterface( 652 const ObjCMethodDecl **InitMethod) const { 653 if (getMethodFamily() != OMF_init) 654 return false; 655 const DeclContext *DC = getDeclContext(); 656 if (isa<ObjCProtocolDecl>(DC)) 657 return false; 658 if (const ObjCInterfaceDecl *ID = getClassInterface()) 659 return ID->isDesignatedInitializer(getSelector(), InitMethod); 660 return false; 661 } 662 663 Stmt *ObjCMethodDecl::getBody() const { 664 return Body.get(getASTContext().getExternalSource()); 665 } 666 667 void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { 668 assert(PrevMethod); 669 getASTContext().setObjCMethodRedeclaration(PrevMethod, this); 670 IsRedeclaration = true; 671 PrevMethod->HasRedeclaration = true; 672 } 673 674 void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, 675 ArrayRef<ParmVarDecl*> Params, 676 ArrayRef<SourceLocation> SelLocs) { 677 ParamsAndSelLocs = 0; 678 NumParams = Params.size(); 679 if (Params.empty() && SelLocs.empty()) 680 return; 681 682 unsigned Size = sizeof(ParmVarDecl *) * NumParams + 683 sizeof(SourceLocation) * SelLocs.size(); 684 ParamsAndSelLocs = C.Allocate(Size); 685 std::copy(Params.begin(), Params.end(), getParams()); 686 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 687 } 688 689 void ObjCMethodDecl::getSelectorLocs( 690 SmallVectorImpl<SourceLocation> &SelLocs) const { 691 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 692 SelLocs.push_back(getSelectorLoc(i)); 693 } 694 695 void ObjCMethodDecl::setMethodParams(ASTContext &C, 696 ArrayRef<ParmVarDecl*> Params, 697 ArrayRef<SourceLocation> SelLocs) { 698 assert((!SelLocs.empty() || isImplicit()) && 699 "No selector locs for non-implicit method"); 700 if (isImplicit()) 701 return setParamsAndSelLocs(C, Params, llvm::None); 702 703 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, 704 DeclEndLoc); 705 if (SelLocsKind != SelLoc_NonStandard) 706 return setParamsAndSelLocs(C, Params, llvm::None); 707 708 setParamsAndSelLocs(C, Params, SelLocs); 709 } 710 711 /// \brief A definition will return its interface declaration. 712 /// An interface declaration will return its definition. 713 /// Otherwise it will return itself. 714 ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { 715 ASTContext &Ctx = getASTContext(); 716 ObjCMethodDecl *Redecl = 0; 717 if (HasRedeclaration) 718 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); 719 if (Redecl) 720 return Redecl; 721 722 Decl *CtxD = cast<Decl>(getDeclContext()); 723 724 if (!CtxD->isInvalidDecl()) { 725 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { 726 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) 727 if (!ImplD->isInvalidDecl()) 728 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); 729 730 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { 731 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) 732 if (!ImplD->isInvalidDecl()) 733 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); 734 735 } else if (ObjCImplementationDecl *ImplD = 736 dyn_cast<ObjCImplementationDecl>(CtxD)) { 737 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) 738 if (!IFD->isInvalidDecl()) 739 Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); 740 741 } else if (ObjCCategoryImplDecl *CImplD = 742 dyn_cast<ObjCCategoryImplDecl>(CtxD)) { 743 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) 744 if (!CatD->isInvalidDecl()) 745 Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); 746 } 747 } 748 749 if (!Redecl && isRedeclaration()) { 750 // This is the last redeclaration, go back to the first method. 751 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), 752 isInstanceMethod()); 753 } 754 755 return Redecl ? Redecl : this; 756 } 757 758 ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { 759 Decl *CtxD = cast<Decl>(getDeclContext()); 760 761 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { 762 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) 763 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), 764 isInstanceMethod())) 765 return MD; 766 767 } else if (ObjCCategoryImplDecl *CImplD = 768 dyn_cast<ObjCCategoryImplDecl>(CtxD)) { 769 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) 770 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), 771 isInstanceMethod())) 772 return MD; 773 } 774 775 if (isRedeclaration()) 776 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), 777 isInstanceMethod()); 778 779 return this; 780 } 781 782 SourceLocation ObjCMethodDecl::getLocEnd() const { 783 if (Stmt *Body = getBody()) 784 return Body->getLocEnd(); 785 return DeclEndLoc; 786 } 787 788 ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { 789 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family); 790 if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) 791 return family; 792 793 // Check for an explicit attribute. 794 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { 795 // The unfortunate necessity of mapping between enums here is due 796 // to the attributes framework. 797 switch (attr->getFamily()) { 798 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; 799 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; 800 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; 801 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; 802 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; 803 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; 804 } 805 Family = static_cast<unsigned>(family); 806 return family; 807 } 808 809 family = getSelector().getMethodFamily(); 810 switch (family) { 811 case OMF_None: break; 812 813 // init only has a conventional meaning for an instance method, and 814 // it has to return an object. 815 case OMF_init: 816 if (!isInstanceMethod() || !getReturnType()->isObjCObjectPointerType()) 817 family = OMF_None; 818 break; 819 820 // alloc/copy/new have a conventional meaning for both class and 821 // instance methods, but they require an object return. 822 case OMF_alloc: 823 case OMF_copy: 824 case OMF_mutableCopy: 825 case OMF_new: 826 if (!getReturnType()->isObjCObjectPointerType()) 827 family = OMF_None; 828 break; 829 830 // These selectors have a conventional meaning only for instance methods. 831 case OMF_dealloc: 832 case OMF_finalize: 833 case OMF_retain: 834 case OMF_release: 835 case OMF_autorelease: 836 case OMF_retainCount: 837 case OMF_self: 838 if (!isInstanceMethod()) 839 family = OMF_None; 840 break; 841 842 case OMF_performSelector: 843 if (!isInstanceMethod() || !getReturnType()->isObjCIdType()) 844 family = OMF_None; 845 else { 846 unsigned noParams = param_size(); 847 if (noParams < 1 || noParams > 3) 848 family = OMF_None; 849 else { 850 ObjCMethodDecl::param_type_iterator it = param_type_begin(); 851 QualType ArgT = (*it); 852 if (!ArgT->isObjCSelType()) { 853 family = OMF_None; 854 break; 855 } 856 while (--noParams) { 857 it++; 858 ArgT = (*it); 859 if (!ArgT->isObjCIdType()) { 860 family = OMF_None; 861 break; 862 } 863 } 864 } 865 } 866 break; 867 868 } 869 870 // Cache the result. 871 Family = static_cast<unsigned>(family); 872 return family; 873 } 874 875 void ObjCMethodDecl::createImplicitParams(ASTContext &Context, 876 const ObjCInterfaceDecl *OID) { 877 QualType selfTy; 878 if (isInstanceMethod()) { 879 // There may be no interface context due to error in declaration 880 // of the interface (which has been reported). Recover gracefully. 881 if (OID) { 882 selfTy = Context.getObjCInterfaceType(OID); 883 selfTy = Context.getObjCObjectPointerType(selfTy); 884 } else { 885 selfTy = Context.getObjCIdType(); 886 } 887 } else // we have a factory method. 888 selfTy = Context.getObjCClassType(); 889 890 bool selfIsPseudoStrong = false; 891 bool selfIsConsumed = false; 892 893 if (Context.getLangOpts().ObjCAutoRefCount) { 894 if (isInstanceMethod()) { 895 selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); 896 897 // 'self' is always __strong. It's actually pseudo-strong except 898 // in init methods (or methods labeled ns_consumes_self), though. 899 Qualifiers qs; 900 qs.setObjCLifetime(Qualifiers::OCL_Strong); 901 selfTy = Context.getQualifiedType(selfTy, qs); 902 903 // In addition, 'self' is const unless this is an init method. 904 if (getMethodFamily() != OMF_init && !selfIsConsumed) { 905 selfTy = selfTy.withConst(); 906 selfIsPseudoStrong = true; 907 } 908 } 909 else { 910 assert(isClassMethod()); 911 // 'self' is always const in class methods. 912 selfTy = selfTy.withConst(); 913 selfIsPseudoStrong = true; 914 } 915 } 916 917 ImplicitParamDecl *self 918 = ImplicitParamDecl::Create(Context, this, SourceLocation(), 919 &Context.Idents.get("self"), selfTy); 920 setSelfDecl(self); 921 922 if (selfIsConsumed) 923 self->addAttr(NSConsumedAttr::CreateImplicit(Context)); 924 925 if (selfIsPseudoStrong) 926 self->setARCPseudoStrong(true); 927 928 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), 929 &Context.Idents.get("_cmd"), 930 Context.getObjCSelType())); 931 } 932 933 ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { 934 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) 935 return ID; 936 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) 937 return CD->getClassInterface(); 938 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) 939 return IMD->getClassInterface(); 940 if (isa<ObjCProtocolDecl>(getDeclContext())) 941 return 0; 942 llvm_unreachable("unknown method context"); 943 } 944 945 static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container, 946 const ObjCMethodDecl *Method, 947 SmallVectorImpl<const ObjCMethodDecl *> &Methods, 948 bool MovedToSuper) { 949 if (!Container) 950 return; 951 952 // In categories look for overriden methods from protocols. A method from 953 // category is not "overriden" since it is considered as the "same" method 954 // (same USR) as the one from the interface. 955 if (const ObjCCategoryDecl * 956 Category = dyn_cast<ObjCCategoryDecl>(Container)) { 957 // Check whether we have a matching method at this category but only if we 958 // are at the super class level. 959 if (MovedToSuper) 960 if (ObjCMethodDecl * 961 Overridden = Container->getMethod(Method->getSelector(), 962 Method->isInstanceMethod(), 963 /*AllowHidden=*/true)) 964 if (Method != Overridden) { 965 // We found an override at this category; there is no need to look 966 // into its protocols. 967 Methods.push_back(Overridden); 968 return; 969 } 970 971 for (const auto *P : Category->protocols()) 972 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); 973 return; 974 } 975 976 // Check whether we have a matching method at this level. 977 if (const ObjCMethodDecl * 978 Overridden = Container->getMethod(Method->getSelector(), 979 Method->isInstanceMethod(), 980 /*AllowHidden=*/true)) 981 if (Method != Overridden) { 982 // We found an override at this level; there is no need to look 983 // into other protocols or categories. 984 Methods.push_back(Overridden); 985 return; 986 } 987 988 if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){ 989 for (const auto *P : Protocol->protocols()) 990 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); 991 } 992 993 if (const ObjCInterfaceDecl * 994 Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { 995 for (const auto *P : Interface->protocols()) 996 CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); 997 998 for (const auto *Cat : Interface->known_categories()) 999 CollectOverriddenMethodsRecurse(Cat, Method, Methods, MovedToSuper); 1000 1001 if (const ObjCInterfaceDecl *Super = Interface->getSuperClass()) 1002 return CollectOverriddenMethodsRecurse(Super, Method, Methods, 1003 /*MovedToSuper=*/true); 1004 } 1005 } 1006 1007 static inline void CollectOverriddenMethods(const ObjCContainerDecl *Container, 1008 const ObjCMethodDecl *Method, 1009 SmallVectorImpl<const ObjCMethodDecl *> &Methods) { 1010 CollectOverriddenMethodsRecurse(Container, Method, Methods, 1011 /*MovedToSuper=*/false); 1012 } 1013 1014 static void collectOverriddenMethodsSlow(const ObjCMethodDecl *Method, 1015 SmallVectorImpl<const ObjCMethodDecl *> &overridden) { 1016 assert(Method->isOverriding()); 1017 1018 if (const ObjCProtocolDecl * 1019 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) { 1020 CollectOverriddenMethods(ProtD, Method, overridden); 1021 1022 } else if (const ObjCImplDecl * 1023 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) { 1024 const ObjCInterfaceDecl *ID = IMD->getClassInterface(); 1025 if (!ID) 1026 return; 1027 // Start searching for overridden methods using the method from the 1028 // interface as starting point. 1029 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), 1030 Method->isInstanceMethod(), 1031 /*AllowHidden=*/true)) 1032 Method = IFaceMeth; 1033 CollectOverriddenMethods(ID, Method, overridden); 1034 1035 } else if (const ObjCCategoryDecl * 1036 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) { 1037 const ObjCInterfaceDecl *ID = CatD->getClassInterface(); 1038 if (!ID) 1039 return; 1040 // Start searching for overridden methods using the method from the 1041 // interface as starting point. 1042 if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), 1043 Method->isInstanceMethod(), 1044 /*AllowHidden=*/true)) 1045 Method = IFaceMeth; 1046 CollectOverriddenMethods(ID, Method, overridden); 1047 1048 } else { 1049 CollectOverriddenMethods( 1050 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()), 1051 Method, overridden); 1052 } 1053 } 1054 1055 void ObjCMethodDecl::getOverriddenMethods( 1056 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const { 1057 const ObjCMethodDecl *Method = this; 1058 1059 if (Method->isRedeclaration()) { 1060 Method = cast<ObjCContainerDecl>(Method->getDeclContext())-> 1061 getMethod(Method->getSelector(), Method->isInstanceMethod()); 1062 } 1063 1064 if (Method->isOverriding()) { 1065 collectOverriddenMethodsSlow(Method, Overridden); 1066 assert(!Overridden.empty() && 1067 "ObjCMethodDecl's overriding bit is not as expected"); 1068 } 1069 } 1070 1071 const ObjCPropertyDecl * 1072 ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { 1073 Selector Sel = getSelector(); 1074 unsigned NumArgs = Sel.getNumArgs(); 1075 if (NumArgs > 1) 1076 return 0; 1077 1078 if (!isInstanceMethod() || getMethodFamily() != OMF_None) 1079 return 0; 1080 1081 if (isPropertyAccessor()) { 1082 const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent()); 1083 // If container is class extension, find its primary class. 1084 if (const ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(Container)) 1085 if (CatDecl->IsClassExtension()) 1086 Container = CatDecl->getClassInterface(); 1087 1088 bool IsGetter = (NumArgs == 0); 1089 1090 for (const auto *I : Container->properties()) { 1091 Selector NextSel = IsGetter ? I->getGetterName() 1092 : I->getSetterName(); 1093 if (NextSel == Sel) 1094 return I; 1095 } 1096 1097 llvm_unreachable("Marked as a property accessor but no property found!"); 1098 } 1099 1100 if (!CheckOverrides) 1101 return 0; 1102 1103 typedef SmallVector<const ObjCMethodDecl *, 8> OverridesTy; 1104 OverridesTy Overrides; 1105 getOverriddenMethods(Overrides); 1106 for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end(); 1107 I != E; ++I) { 1108 if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false)) 1109 return Prop; 1110 } 1111 1112 return 0; 1113 1114 } 1115 1116 //===----------------------------------------------------------------------===// 1117 // ObjCInterfaceDecl 1118 //===----------------------------------------------------------------------===// 1119 1120 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C, 1121 DeclContext *DC, 1122 SourceLocation atLoc, 1123 IdentifierInfo *Id, 1124 ObjCInterfaceDecl *PrevDecl, 1125 SourceLocation ClassLoc, 1126 bool isInternal){ 1127 ObjCInterfaceDecl *Result = new (C, DC) 1128 ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, PrevDecl, isInternal); 1129 Result->Data.setInt(!C.getLangOpts().Modules); 1130 C.getObjCInterfaceType(Result, PrevDecl); 1131 return Result; 1132 } 1133 1134 ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, 1135 unsigned ID) { 1136 ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(0, SourceLocation(), 1137 0, SourceLocation(), 1138 0, false); 1139 Result->Data.setInt(!C.getLangOpts().Modules); 1140 return Result; 1141 } 1142 1143 ObjCInterfaceDecl:: 1144 ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 1145 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl, 1146 bool isInternal) 1147 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc), 1148 TypeForDecl(0), Data() 1149 { 1150 setPreviousDecl(PrevDecl); 1151 1152 // Copy the 'data' pointer over. 1153 if (PrevDecl) 1154 Data = PrevDecl->Data; 1155 1156 setImplicit(isInternal); 1157 } 1158 1159 void ObjCInterfaceDecl::LoadExternalDefinition() const { 1160 assert(data().ExternallyCompleted && "Class is not externally completed"); 1161 data().ExternallyCompleted = false; 1162 getASTContext().getExternalSource()->CompleteType( 1163 const_cast<ObjCInterfaceDecl *>(this)); 1164 } 1165 1166 void ObjCInterfaceDecl::setExternallyCompleted() { 1167 assert(getASTContext().getExternalSource() && 1168 "Class can't be externally completed without an external source"); 1169 assert(hasDefinition() && 1170 "Forward declarations can't be externally completed"); 1171 data().ExternallyCompleted = true; 1172 } 1173 1174 void ObjCInterfaceDecl::setHasDesignatedInitializers() { 1175 // Check for a complete definition and recover if not so. 1176 if (!isThisDeclarationADefinition()) 1177 return; 1178 data().HasDesignatedInitializers = true; 1179 } 1180 1181 bool ObjCInterfaceDecl::hasDesignatedInitializers() const { 1182 // Check for a complete definition and recover if not so. 1183 if (!isThisDeclarationADefinition()) 1184 return false; 1185 if (data().ExternallyCompleted) 1186 LoadExternalDefinition(); 1187 1188 return data().HasDesignatedInitializers; 1189 } 1190 1191 ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { 1192 if (const ObjCInterfaceDecl *Def = getDefinition()) { 1193 if (data().ExternallyCompleted) 1194 LoadExternalDefinition(); 1195 1196 return getASTContext().getObjCImplementation( 1197 const_cast<ObjCInterfaceDecl*>(Def)); 1198 } 1199 1200 // FIXME: Should make sure no callers ever do this. 1201 return 0; 1202 } 1203 1204 void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { 1205 getASTContext().setObjCImplementation(getDefinition(), ImplD); 1206 } 1207 1208 namespace { 1209 struct SynthesizeIvarChunk { 1210 uint64_t Size; 1211 ObjCIvarDecl *Ivar; 1212 SynthesizeIvarChunk(uint64_t size, ObjCIvarDecl *ivar) 1213 : Size(size), Ivar(ivar) {} 1214 }; 1215 1216 bool operator<(const SynthesizeIvarChunk & LHS, 1217 const SynthesizeIvarChunk &RHS) { 1218 return LHS.Size < RHS.Size; 1219 } 1220 } 1221 1222 /// all_declared_ivar_begin - return first ivar declared in this class, 1223 /// its extensions and its implementation. Lazily build the list on first 1224 /// access. 1225 /// 1226 /// Caveat: The list returned by this method reflects the current 1227 /// state of the parser. The cache will be updated for every ivar 1228 /// added by an extension or the implementation when they are 1229 /// encountered. 1230 /// See also ObjCIvarDecl::Create(). 1231 ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { 1232 // FIXME: Should make sure no callers ever do this. 1233 if (!hasDefinition()) 1234 return 0; 1235 1236 ObjCIvarDecl *curIvar = 0; 1237 if (!data().IvarList) { 1238 if (!ivar_empty()) { 1239 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); 1240 data().IvarList = *I; ++I; 1241 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) 1242 curIvar->setNextIvar(*I); 1243 } 1244 1245 for (const auto *Ext : known_extensions()) { 1246 if (!Ext->ivar_empty()) { 1247 ObjCCategoryDecl::ivar_iterator 1248 I = Ext->ivar_begin(), 1249 E = Ext->ivar_end(); 1250 if (!data().IvarList) { 1251 data().IvarList = *I; ++I; 1252 curIvar = data().IvarList; 1253 } 1254 for ( ;I != E; curIvar = *I, ++I) 1255 curIvar->setNextIvar(*I); 1256 } 1257 } 1258 data().IvarListMissingImplementation = true; 1259 } 1260 1261 // cached and complete! 1262 if (!data().IvarListMissingImplementation) 1263 return data().IvarList; 1264 1265 if (ObjCImplementationDecl *ImplDecl = getImplementation()) { 1266 data().IvarListMissingImplementation = false; 1267 if (!ImplDecl->ivar_empty()) { 1268 SmallVector<SynthesizeIvarChunk, 16> layout; 1269 for (auto *IV : ImplDecl->ivars()) { 1270 if (IV->getSynthesize() && !IV->isInvalidDecl()) { 1271 layout.push_back(SynthesizeIvarChunk( 1272 IV->getASTContext().getTypeSize(IV->getType()), IV)); 1273 continue; 1274 } 1275 if (!data().IvarList) 1276 data().IvarList = IV; 1277 else 1278 curIvar->setNextIvar(IV); 1279 curIvar = IV; 1280 } 1281 1282 if (!layout.empty()) { 1283 // Order synthesized ivars by their size. 1284 std::stable_sort(layout.begin(), layout.end()); 1285 unsigned Ix = 0, EIx = layout.size(); 1286 if (!data().IvarList) { 1287 data().IvarList = layout[0].Ivar; Ix++; 1288 curIvar = data().IvarList; 1289 } 1290 for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) 1291 curIvar->setNextIvar(layout[Ix].Ivar); 1292 } 1293 } 1294 } 1295 return data().IvarList; 1296 } 1297 1298 /// FindCategoryDeclaration - Finds category declaration in the list of 1299 /// categories for this class and returns it. Name of the category is passed 1300 /// in 'CategoryId'. If category not found, return 0; 1301 /// 1302 ObjCCategoryDecl * 1303 ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { 1304 // FIXME: Should make sure no callers ever do this. 1305 if (!hasDefinition()) 1306 return 0; 1307 1308 if (data().ExternallyCompleted) 1309 LoadExternalDefinition(); 1310 1311 for (auto *Cat : visible_categories()) 1312 if (Cat->getIdentifier() == CategoryId) 1313 return Cat; 1314 1315 return 0; 1316 } 1317 1318 ObjCMethodDecl * 1319 ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { 1320 for (const auto *Cat : visible_categories()) { 1321 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) 1322 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) 1323 return MD; 1324 } 1325 1326 return 0; 1327 } 1328 1329 ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { 1330 for (const auto *Cat : visible_categories()) { 1331 if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) 1332 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) 1333 return MD; 1334 } 1335 1336 return 0; 1337 } 1338 1339 /// ClassImplementsProtocol - Checks that 'lProto' protocol 1340 /// has been implemented in IDecl class, its super class or categories (if 1341 /// lookupCategory is true). 1342 bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, 1343 bool lookupCategory, 1344 bool RHSIsQualifiedID) { 1345 if (!hasDefinition()) 1346 return false; 1347 1348 ObjCInterfaceDecl *IDecl = this; 1349 // 1st, look up the class. 1350 for (auto *PI : IDecl->protocols()){ 1351 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) 1352 return true; 1353 // This is dubious and is added to be compatible with gcc. In gcc, it is 1354 // also allowed assigning a protocol-qualified 'id' type to a LHS object 1355 // when protocol in qualified LHS is in list of protocols in the rhs 'id' 1356 // object. This IMO, should be a bug. 1357 // FIXME: Treat this as an extension, and flag this as an error when GCC 1358 // extensions are not enabled. 1359 if (RHSIsQualifiedID && 1360 getASTContext().ProtocolCompatibleWithProtocol(PI, lProto)) 1361 return true; 1362 } 1363 1364 // 2nd, look up the category. 1365 if (lookupCategory) 1366 for (const auto *Cat : visible_categories()) { 1367 for (auto *PI : Cat->protocols()) 1368 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) 1369 return true; 1370 } 1371 1372 // 3rd, look up the super class(s) 1373 if (IDecl->getSuperClass()) 1374 return 1375 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, 1376 RHSIsQualifiedID); 1377 1378 return false; 1379 } 1380 1381 //===----------------------------------------------------------------------===// 1382 // ObjCIvarDecl 1383 //===----------------------------------------------------------------------===// 1384 1385 void ObjCIvarDecl::anchor() { } 1386 1387 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, 1388 SourceLocation StartLoc, 1389 SourceLocation IdLoc, IdentifierInfo *Id, 1390 QualType T, TypeSourceInfo *TInfo, 1391 AccessControl ac, Expr *BW, 1392 bool synthesized) { 1393 if (DC) { 1394 // Ivar's can only appear in interfaces, implementations (via synthesized 1395 // properties), and class extensions (via direct declaration, or synthesized 1396 // properties). 1397 // 1398 // FIXME: This should really be asserting this: 1399 // (isa<ObjCCategoryDecl>(DC) && 1400 // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) 1401 // but unfortunately we sometimes place ivars into non-class extension 1402 // categories on error. This breaks an AST invariant, and should not be 1403 // fixed. 1404 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || 1405 isa<ObjCCategoryDecl>(DC)) && 1406 "Invalid ivar decl context!"); 1407 // Once a new ivar is created in any of class/class-extension/implementation 1408 // decl contexts, the previously built IvarList must be rebuilt. 1409 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC); 1410 if (!ID) { 1411 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) 1412 ID = IM->getClassInterface(); 1413 else 1414 ID = cast<ObjCCategoryDecl>(DC)->getClassInterface(); 1415 } 1416 ID->setIvarList(0); 1417 } 1418 1419 return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW, 1420 synthesized); 1421 } 1422 1423 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1424 return new (C, ID) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0, 1425 QualType(), 0, ObjCIvarDecl::None, 0, false); 1426 } 1427 1428 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { 1429 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); 1430 1431 switch (DC->getKind()) { 1432 default: 1433 case ObjCCategoryImpl: 1434 case ObjCProtocol: 1435 llvm_unreachable("invalid ivar container!"); 1436 1437 // Ivars can only appear in class extension categories. 1438 case ObjCCategory: { 1439 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); 1440 assert(CD->IsClassExtension() && "invalid container for ivar!"); 1441 return CD->getClassInterface(); 1442 } 1443 1444 case ObjCImplementation: 1445 return cast<ObjCImplementationDecl>(DC)->getClassInterface(); 1446 1447 case ObjCInterface: 1448 return cast<ObjCInterfaceDecl>(DC); 1449 } 1450 } 1451 1452 //===----------------------------------------------------------------------===// 1453 // ObjCAtDefsFieldDecl 1454 //===----------------------------------------------------------------------===// 1455 1456 void ObjCAtDefsFieldDecl::anchor() { } 1457 1458 ObjCAtDefsFieldDecl 1459 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, 1460 SourceLocation StartLoc, SourceLocation IdLoc, 1461 IdentifierInfo *Id, QualType T, Expr *BW) { 1462 return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); 1463 } 1464 1465 ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, 1466 unsigned ID) { 1467 return new (C, ID) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(), 1468 0, QualType(), 0); 1469 } 1470 1471 //===----------------------------------------------------------------------===// 1472 // ObjCProtocolDecl 1473 //===----------------------------------------------------------------------===// 1474 1475 void ObjCProtocolDecl::anchor() { } 1476 1477 ObjCProtocolDecl::ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id, 1478 SourceLocation nameLoc, 1479 SourceLocation atStartLoc, 1480 ObjCProtocolDecl *PrevDecl) 1481 : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc), Data() 1482 { 1483 setPreviousDecl(PrevDecl); 1484 if (PrevDecl) 1485 Data = PrevDecl->Data; 1486 } 1487 1488 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, 1489 IdentifierInfo *Id, 1490 SourceLocation nameLoc, 1491 SourceLocation atStartLoc, 1492 ObjCProtocolDecl *PrevDecl) { 1493 ObjCProtocolDecl *Result = 1494 new (C, DC) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl); 1495 Result->Data.setInt(!C.getLangOpts().Modules); 1496 return Result; 1497 } 1498 1499 ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, 1500 unsigned ID) { 1501 ObjCProtocolDecl *Result = 1502 new (C, ID) ObjCProtocolDecl(0, 0, SourceLocation(), SourceLocation(), 0); 1503 Result->Data.setInt(!C.getLangOpts().Modules); 1504 return Result; 1505 } 1506 1507 ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { 1508 ObjCProtocolDecl *PDecl = this; 1509 1510 if (Name == getIdentifier()) 1511 return PDecl; 1512 1513 for (auto *I : protocols()) 1514 if ((PDecl = I->lookupProtocolNamed(Name))) 1515 return PDecl; 1516 1517 return NULL; 1518 } 1519 1520 // lookupMethod - Lookup a instance/class method in the protocol and protocols 1521 // it inherited. 1522 ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, 1523 bool isInstance) const { 1524 ObjCMethodDecl *MethodDecl = NULL; 1525 1526 // If there is no definition or the definition is hidden, we don't find 1527 // anything. 1528 const ObjCProtocolDecl *Def = getDefinition(); 1529 if (!Def || Def->isHidden()) 1530 return NULL; 1531 1532 if ((MethodDecl = getMethod(Sel, isInstance))) 1533 return MethodDecl; 1534 1535 for (const auto *I : protocols()) 1536 if ((MethodDecl = I->lookupMethod(Sel, isInstance))) 1537 return MethodDecl; 1538 return NULL; 1539 } 1540 1541 void ObjCProtocolDecl::allocateDefinitionData() { 1542 assert(!Data.getPointer() && "Protocol already has a definition!"); 1543 Data.setPointer(new (getASTContext()) DefinitionData); 1544 Data.getPointer()->Definition = this; 1545 } 1546 1547 void ObjCProtocolDecl::startDefinition() { 1548 allocateDefinitionData(); 1549 1550 // Update all of the declarations with a pointer to the definition. 1551 for (auto RD : redecls()) 1552 RD->Data = this->Data; 1553 } 1554 1555 void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM, 1556 PropertyDeclOrder &PO) const { 1557 1558 if (const ObjCProtocolDecl *PDecl = getDefinition()) { 1559 for (auto *Prop : PDecl->properties()) { 1560 // Insert into PM if not there already. 1561 PM.insert(std::make_pair(Prop->getIdentifier(), Prop)); 1562 PO.push_back(Prop); 1563 } 1564 // Scan through protocol's protocols. 1565 for (const auto *PI : PDecl->protocols()) 1566 PI->collectPropertiesToImplement(PM, PO); 1567 } 1568 } 1569 1570 1571 void ObjCProtocolDecl::collectInheritedProtocolProperties( 1572 const ObjCPropertyDecl *Property, 1573 ProtocolPropertyMap &PM) const { 1574 if (const ObjCProtocolDecl *PDecl = getDefinition()) { 1575 bool MatchFound = false; 1576 for (auto *Prop : PDecl->properties()) { 1577 if (Prop == Property) 1578 continue; 1579 if (Prop->getIdentifier() == Property->getIdentifier()) { 1580 PM[PDecl] = Prop; 1581 MatchFound = true; 1582 break; 1583 } 1584 } 1585 // Scan through protocol's protocols which did not have a matching property. 1586 if (!MatchFound) 1587 for (const auto *PI : PDecl->protocols()) 1588 PI->collectInheritedProtocolProperties(Property, PM); 1589 } 1590 } 1591 1592 //===----------------------------------------------------------------------===// 1593 // ObjCCategoryDecl 1594 //===----------------------------------------------------------------------===// 1595 1596 void ObjCCategoryDecl::anchor() { } 1597 1598 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, 1599 SourceLocation AtLoc, 1600 SourceLocation ClassNameLoc, 1601 SourceLocation CategoryNameLoc, 1602 IdentifierInfo *Id, 1603 ObjCInterfaceDecl *IDecl, 1604 SourceLocation IvarLBraceLoc, 1605 SourceLocation IvarRBraceLoc) { 1606 ObjCCategoryDecl *CatDecl = 1607 new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id, 1608 IDecl, IvarLBraceLoc, IvarRBraceLoc); 1609 if (IDecl) { 1610 // Link this category into its class's category list. 1611 CatDecl->NextClassCategory = IDecl->getCategoryListRaw(); 1612 if (IDecl->hasDefinition()) { 1613 IDecl->setCategoryListRaw(CatDecl); 1614 if (ASTMutationListener *L = C.getASTMutationListener()) 1615 L->AddedObjCCategoryToInterface(CatDecl, IDecl); 1616 } 1617 } 1618 1619 return CatDecl; 1620 } 1621 1622 ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, 1623 unsigned ID) { 1624 return new (C, ID) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), 1625 SourceLocation(), 0, 0); 1626 } 1627 1628 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { 1629 return getASTContext().getObjCImplementation( 1630 const_cast<ObjCCategoryDecl*>(this)); 1631 } 1632 1633 void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { 1634 getASTContext().setObjCImplementation(this, ImplD); 1635 } 1636 1637 1638 //===----------------------------------------------------------------------===// 1639 // ObjCCategoryImplDecl 1640 //===----------------------------------------------------------------------===// 1641 1642 void ObjCCategoryImplDecl::anchor() { } 1643 1644 ObjCCategoryImplDecl * 1645 ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, 1646 IdentifierInfo *Id, 1647 ObjCInterfaceDecl *ClassInterface, 1648 SourceLocation nameLoc, 1649 SourceLocation atStartLoc, 1650 SourceLocation CategoryNameLoc) { 1651 if (ClassInterface && ClassInterface->hasDefinition()) 1652 ClassInterface = ClassInterface->getDefinition(); 1653 return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc, 1654 atStartLoc, CategoryNameLoc); 1655 } 1656 1657 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, 1658 unsigned ID) { 1659 return new (C, ID) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(), 1660 SourceLocation(), SourceLocation()); 1661 } 1662 1663 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { 1664 // The class interface might be NULL if we are working with invalid code. 1665 if (const ObjCInterfaceDecl *ID = getClassInterface()) 1666 return ID->FindCategoryDeclaration(getIdentifier()); 1667 return 0; 1668 } 1669 1670 1671 void ObjCImplDecl::anchor() { } 1672 1673 void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { 1674 // FIXME: The context should be correct before we get here. 1675 property->setLexicalDeclContext(this); 1676 addDecl(property); 1677 } 1678 1679 void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { 1680 ASTContext &Ctx = getASTContext(); 1681 1682 if (ObjCImplementationDecl *ImplD 1683 = dyn_cast_or_null<ObjCImplementationDecl>(this)) { 1684 if (IFace) 1685 Ctx.setObjCImplementation(IFace, ImplD); 1686 1687 } else if (ObjCCategoryImplDecl *ImplD = 1688 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { 1689 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) 1690 Ctx.setObjCImplementation(CD, ImplD); 1691 } 1692 1693 ClassInterface = IFace; 1694 } 1695 1696 /// FindPropertyImplIvarDecl - This method lookup the ivar in the list of 1697 /// properties implemented in this \@implementation block and returns 1698 /// the implemented property that uses it. 1699 /// 1700 ObjCPropertyImplDecl *ObjCImplDecl:: 1701 FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { 1702 for (auto *PID : property_impls()) 1703 if (PID->getPropertyIvarDecl() && 1704 PID->getPropertyIvarDecl()->getIdentifier() == ivarId) 1705 return PID; 1706 return 0; 1707 } 1708 1709 /// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl 1710 /// added to the list of those properties \@synthesized/\@dynamic in this 1711 /// category \@implementation block. 1712 /// 1713 ObjCPropertyImplDecl *ObjCImplDecl:: 1714 FindPropertyImplDecl(IdentifierInfo *Id) const { 1715 for (auto *PID : property_impls()) 1716 if (PID->getPropertyDecl()->getIdentifier() == Id) 1717 return PID; 1718 return 0; 1719 } 1720 1721 raw_ostream &clang::operator<<(raw_ostream &OS, 1722 const ObjCCategoryImplDecl &CID) { 1723 OS << CID.getName(); 1724 return OS; 1725 } 1726 1727 //===----------------------------------------------------------------------===// 1728 // ObjCImplementationDecl 1729 //===----------------------------------------------------------------------===// 1730 1731 void ObjCImplementationDecl::anchor() { } 1732 1733 ObjCImplementationDecl * 1734 ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, 1735 ObjCInterfaceDecl *ClassInterface, 1736 ObjCInterfaceDecl *SuperDecl, 1737 SourceLocation nameLoc, 1738 SourceLocation atStartLoc, 1739 SourceLocation superLoc, 1740 SourceLocation IvarLBraceLoc, 1741 SourceLocation IvarRBraceLoc) { 1742 if (ClassInterface && ClassInterface->hasDefinition()) 1743 ClassInterface = ClassInterface->getDefinition(); 1744 return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, 1745 nameLoc, atStartLoc, superLoc, 1746 IvarLBraceLoc, IvarRBraceLoc); 1747 } 1748 1749 ObjCImplementationDecl * 1750 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1751 return new (C, ID) ObjCImplementationDecl(0, 0, 0, SourceLocation(), 1752 SourceLocation()); 1753 } 1754 1755 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, 1756 CXXCtorInitializer ** initializers, 1757 unsigned numInitializers) { 1758 if (numInitializers > 0) { 1759 NumIvarInitializers = numInitializers; 1760 CXXCtorInitializer **ivarInitializers = 1761 new (C) CXXCtorInitializer*[NumIvarInitializers]; 1762 memcpy(ivarInitializers, initializers, 1763 numInitializers * sizeof(CXXCtorInitializer*)); 1764 IvarInitializers = ivarInitializers; 1765 } 1766 } 1767 1768 raw_ostream &clang::operator<<(raw_ostream &OS, 1769 const ObjCImplementationDecl &ID) { 1770 OS << ID.getName(); 1771 return OS; 1772 } 1773 1774 //===----------------------------------------------------------------------===// 1775 // ObjCCompatibleAliasDecl 1776 //===----------------------------------------------------------------------===// 1777 1778 void ObjCCompatibleAliasDecl::anchor() { } 1779 1780 ObjCCompatibleAliasDecl * 1781 ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, 1782 SourceLocation L, 1783 IdentifierInfo *Id, 1784 ObjCInterfaceDecl* AliasedClass) { 1785 return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); 1786 } 1787 1788 ObjCCompatibleAliasDecl * 1789 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1790 return new (C, ID) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0); 1791 } 1792 1793 //===----------------------------------------------------------------------===// 1794 // ObjCPropertyDecl 1795 //===----------------------------------------------------------------------===// 1796 1797 void ObjCPropertyDecl::anchor() { } 1798 1799 ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, 1800 SourceLocation L, 1801 IdentifierInfo *Id, 1802 SourceLocation AtLoc, 1803 SourceLocation LParenLoc, 1804 TypeSourceInfo *T, 1805 PropertyControl propControl) { 1806 return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T); 1807 } 1808 1809 ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, 1810 unsigned ID) { 1811 return new (C, ID) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(), 1812 SourceLocation(), 0); 1813 } 1814 1815 //===----------------------------------------------------------------------===// 1816 // ObjCPropertyImplDecl 1817 //===----------------------------------------------------------------------===// 1818 1819 ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, 1820 DeclContext *DC, 1821 SourceLocation atLoc, 1822 SourceLocation L, 1823 ObjCPropertyDecl *property, 1824 Kind PK, 1825 ObjCIvarDecl *ivar, 1826 SourceLocation ivarLoc) { 1827 return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, 1828 ivarLoc); 1829 } 1830 1831 ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, 1832 unsigned ID) { 1833 return new (C, ID) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(), 1834 0, Dynamic, 0, SourceLocation()); 1835 } 1836 1837 SourceRange ObjCPropertyImplDecl::getSourceRange() const { 1838 SourceLocation EndLoc = getLocation(); 1839 if (IvarLoc.isValid()) 1840 EndLoc = IvarLoc; 1841 1842 return SourceRange(AtLoc, EndLoc); 1843 } 1844