DeclObjC.cpp revision 0af550115df1f57f17a4f125ff0e8b34820c65d1
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/Stmt.h" 17#include "clang/AST/ASTMutationListener.h" 18#include "llvm/ADT/STLExtras.h" 19using namespace clang; 20 21//===----------------------------------------------------------------------===// 22// ObjCListBase 23//===----------------------------------------------------------------------===// 24 25void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) { 26 List = 0; 27 if (Elts == 0) return; // Setting to an empty list is a noop. 28 29 30 List = new (Ctx) void*[Elts]; 31 NumElts = Elts; 32 memcpy(List, InList, sizeof(void*)*Elts); 33} 34 35void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts, 36 const SourceLocation *Locs, ASTContext &Ctx) { 37 if (Elts == 0) 38 return; 39 40 Locations = new (Ctx) SourceLocation[Elts]; 41 memcpy(Locations, Locs, sizeof(SourceLocation) * Elts); 42 set(InList, Elts, Ctx); 43} 44 45//===----------------------------------------------------------------------===// 46// ObjCInterfaceDecl 47//===----------------------------------------------------------------------===// 48 49/// getIvarDecl - This method looks up an ivar in this ContextDecl. 50/// 51ObjCIvarDecl * 52ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const { 53 lookup_const_iterator Ivar, IvarEnd; 54 for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) { 55 if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar)) 56 return ivar; 57 } 58 return 0; 59} 60 61// Get the local instance/class method declared in this interface. 62ObjCMethodDecl * 63ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const { 64 // Since instance & class methods can have the same name, the loop below 65 // ensures we get the correct method. 66 // 67 // @interface Whatever 68 // - (int) class_method; 69 // + (float) class_method; 70 // @end 71 // 72 lookup_const_iterator Meth, MethEnd; 73 for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) { 74 ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth); 75 if (MD && MD->isInstanceMethod() == isInstance) 76 return MD; 77 } 78 return 0; 79} 80 81ObjCPropertyDecl * 82ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, 83 IdentifierInfo *propertyID) { 84 85 DeclContext::lookup_const_iterator I, E; 86 llvm::tie(I, E) = DC->lookup(propertyID); 87 for ( ; I != E; ++I) 88 if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) 89 return PD; 90 91 return 0; 92} 93 94/// FindPropertyDeclaration - Finds declaration of the property given its name 95/// in 'PropertyId' and returns it. It returns 0, if not found. 96ObjCPropertyDecl * 97ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { 98 99 if (ObjCPropertyDecl *PD = 100 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) 101 return PD; 102 103 switch (getKind()) { 104 default: 105 break; 106 case Decl::ObjCProtocol: { 107 const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this); 108 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), 109 E = PID->protocol_end(); I != E; ++I) 110 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) 111 return P; 112 break; 113 } 114 case Decl::ObjCInterface: { 115 const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this); 116 // Look through categories. 117 for (ObjCCategoryDecl *Cat = OID->getCategoryList(); 118 Cat; Cat = Cat->getNextClassCategory()) 119 if (!Cat->IsClassExtension()) 120 if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId)) 121 return P; 122 123 // Look through protocols. 124 for (ObjCInterfaceDecl::all_protocol_iterator 125 I = OID->all_referenced_protocol_begin(), 126 E = OID->all_referenced_protocol_end(); I != E; ++I) 127 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) 128 return P; 129 130 // Finally, check the super class. 131 if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) 132 return superClass->FindPropertyDeclaration(PropertyId); 133 break; 134 } 135 case Decl::ObjCCategory: { 136 const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this); 137 // Look through protocols. 138 if (!OCD->IsClassExtension()) 139 for (ObjCCategoryDecl::protocol_iterator 140 I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I) 141 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) 142 return P; 143 144 break; 145 } 146 } 147 return 0; 148} 149 150/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property 151/// with name 'PropertyId' in the primary class; including those in protocols 152/// (direct or indirect) used by the primary class. 153/// 154ObjCPropertyDecl * 155ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( 156 IdentifierInfo *PropertyId) const { 157 // FIXME: Should make sure no callers ever do this. 158 if (!hasDefinition()) 159 return 0; 160 161 if (data().ExternallyCompleted) 162 LoadExternalDefinition(); 163 164 if (ObjCPropertyDecl *PD = 165 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId)) 166 return PD; 167 168 // Look through protocols. 169 for (ObjCInterfaceDecl::all_protocol_iterator 170 I = all_referenced_protocol_begin(), 171 E = all_referenced_protocol_end(); I != E; ++I) 172 if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) 173 return P; 174 175 return 0; 176} 177 178void ObjCInterfaceDecl::mergeClassExtensionProtocolList( 179 ObjCProtocolDecl *const* ExtList, unsigned ExtNum, 180 ASTContext &C) 181{ 182 if (data().ExternallyCompleted) 183 LoadExternalDefinition(); 184 185 if (data().AllReferencedProtocols.empty() && 186 data().ReferencedProtocols.empty()) { 187 data().AllReferencedProtocols.set(ExtList, ExtNum, C); 188 return; 189 } 190 191 // Check for duplicate protocol in class's protocol list. 192 // This is O(n*m). But it is extremely rare and number of protocols in 193 // class or its extension are very few. 194 SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs; 195 for (unsigned i = 0; i < ExtNum; i++) { 196 bool protocolExists = false; 197 ObjCProtocolDecl *ProtoInExtension = ExtList[i]; 198 for (all_protocol_iterator 199 p = all_referenced_protocol_begin(), 200 e = all_referenced_protocol_end(); p != e; ++p) { 201 ObjCProtocolDecl *Proto = (*p); 202 if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { 203 protocolExists = true; 204 break; 205 } 206 } 207 // Do we want to warn on a protocol in extension class which 208 // already exist in the class? Probably not. 209 if (!protocolExists) 210 ProtocolRefs.push_back(ProtoInExtension); 211 } 212 213 if (ProtocolRefs.empty()) 214 return; 215 216 // Merge ProtocolRefs into class's protocol list; 217 for (all_protocol_iterator p = all_referenced_protocol_begin(), 218 e = all_referenced_protocol_end(); p != e; ++p) { 219 ProtocolRefs.push_back(*p); 220 } 221 222 data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); 223} 224 225void ObjCInterfaceDecl::allocateDefinitionData() { 226 assert(!hasDefinition() && "ObjC class already has a definition"); 227 Data = new (getASTContext()) DefinitionData(); 228 Data->Definition = this; 229} 230 231void ObjCInterfaceDecl::startDefinition() { 232 allocateDefinitionData(); 233 234 // Update all of the declarations with a pointer to the definition. 235 for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); 236 RD != RDEnd; ++RD) { 237 if (*RD != this) 238 RD->Data = Data; 239 } 240 241 if (ASTMutationListener *L = getASTContext().getASTMutationListener()) 242 L->CompletedObjCForwardRef(this); 243} 244 245/// getFirstClassExtension - Find first class extension of the given class. 246ObjCCategoryDecl* ObjCInterfaceDecl::getFirstClassExtension() const { 247 for (ObjCCategoryDecl *CDecl = getCategoryList(); CDecl; 248 CDecl = CDecl->getNextClassCategory()) 249 if (CDecl->IsClassExtension()) 250 return CDecl; 251 return 0; 252} 253 254/// getNextClassCategory - Find next class extension in list of categories. 255const ObjCCategoryDecl* ObjCCategoryDecl::getNextClassExtension() const { 256 for (const ObjCCategoryDecl *CDecl = getNextClassCategory(); CDecl; 257 CDecl = CDecl->getNextClassCategory()) 258 if (CDecl->IsClassExtension()) 259 return CDecl; 260 return 0; 261} 262 263ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, 264 ObjCInterfaceDecl *&clsDeclared) { 265 // FIXME: Should make sure no callers ever do this. 266 if (!hasDefinition()) 267 return 0; 268 269 if (data().ExternallyCompleted) 270 LoadExternalDefinition(); 271 272 ObjCInterfaceDecl* ClassDecl = this; 273 while (ClassDecl != NULL) { 274 if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { 275 clsDeclared = ClassDecl; 276 return I; 277 } 278 for (const ObjCCategoryDecl *CDecl = ClassDecl->getFirstClassExtension(); 279 CDecl; CDecl = CDecl->getNextClassExtension()) { 280 if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) { 281 clsDeclared = ClassDecl; 282 return I; 283 } 284 } 285 286 ClassDecl = ClassDecl->getSuperClass(); 287 } 288 return NULL; 289} 290 291/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super 292/// class whose name is passed as argument. If it is not one of the super classes 293/// the it returns NULL. 294ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( 295 const IdentifierInfo*ICName) { 296 // FIXME: Should make sure no callers ever do this. 297 if (!hasDefinition()) 298 return 0; 299 300 if (data().ExternallyCompleted) 301 LoadExternalDefinition(); 302 303 ObjCInterfaceDecl* ClassDecl = this; 304 while (ClassDecl != NULL) { 305 if (ClassDecl->getIdentifier() == ICName) 306 return ClassDecl; 307 ClassDecl = ClassDecl->getSuperClass(); 308 } 309 return NULL; 310} 311 312/// lookupMethod - This method returns an instance/class method by looking in 313/// the class, its categories, and its super classes (using a linear search). 314ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, 315 bool isInstance) const { 316 // FIXME: Should make sure no callers ever do this. 317 if (!hasDefinition()) 318 return 0; 319 320 const ObjCInterfaceDecl* ClassDecl = this; 321 ObjCMethodDecl *MethodDecl = 0; 322 323 if (data().ExternallyCompleted) 324 LoadExternalDefinition(); 325 326 while (ClassDecl != NULL) { 327 if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) 328 return MethodDecl; 329 330 // Didn't find one yet - look through protocols. 331 const ObjCList<ObjCProtocolDecl> &Protocols = 332 ClassDecl->getReferencedProtocols(); 333 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 334 E = Protocols.end(); I != E; ++I) 335 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) 336 return MethodDecl; 337 338 // Didn't find one yet - now look through categories. 339 ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList(); 340 while (CatDecl) { 341 if ((MethodDecl = CatDecl->getMethod(Sel, isInstance))) 342 return MethodDecl; 343 344 // Didn't find one yet - look through protocols. 345 const ObjCList<ObjCProtocolDecl> &Protocols = 346 CatDecl->getReferencedProtocols(); 347 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 348 E = Protocols.end(); I != E; ++I) 349 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) 350 return MethodDecl; 351 CatDecl = CatDecl->getNextClassCategory(); 352 } 353 ClassDecl = ClassDecl->getSuperClass(); 354 } 355 return NULL; 356} 357 358ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( 359 const Selector &Sel, 360 bool Instance) { 361 // FIXME: Should make sure no callers ever do this. 362 if (!hasDefinition()) 363 return 0; 364 365 if (data().ExternallyCompleted) 366 LoadExternalDefinition(); 367 368 ObjCMethodDecl *Method = 0; 369 if (ObjCImplementationDecl *ImpDecl = getImplementation()) 370 Method = Instance ? ImpDecl->getInstanceMethod(Sel) 371 : ImpDecl->getClassMethod(Sel); 372 373 if (!Method && getSuperClass()) 374 return getSuperClass()->lookupPrivateMethod(Sel, Instance); 375 return Method; 376} 377 378//===----------------------------------------------------------------------===// 379// ObjCMethodDecl 380//===----------------------------------------------------------------------===// 381 382ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C, 383 SourceLocation beginLoc, 384 SourceLocation endLoc, 385 Selector SelInfo, QualType T, 386 TypeSourceInfo *ResultTInfo, 387 DeclContext *contextDecl, 388 bool isInstance, 389 bool isVariadic, 390 bool isSynthesized, 391 bool isImplicitlyDeclared, 392 bool isDefined, 393 ImplementationControl impControl, 394 bool HasRelatedResultType) { 395 return new (C) ObjCMethodDecl(beginLoc, endLoc, 396 SelInfo, T, ResultTInfo, contextDecl, 397 isInstance, 398 isVariadic, isSynthesized, isImplicitlyDeclared, 399 isDefined, 400 impControl, 401 HasRelatedResultType); 402} 403 404void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) { 405 assert(PrevMethod); 406 getASTContext().setObjCMethodRedeclaration(PrevMethod, this); 407 IsRedeclaration = true; 408 PrevMethod->HasRedeclaration = true; 409} 410 411void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, 412 ArrayRef<ParmVarDecl*> Params, 413 ArrayRef<SourceLocation> SelLocs) { 414 ParamsAndSelLocs = 0; 415 NumParams = Params.size(); 416 if (Params.empty() && SelLocs.empty()) 417 return; 418 419 unsigned Size = sizeof(ParmVarDecl *) * NumParams + 420 sizeof(SourceLocation) * SelLocs.size(); 421 ParamsAndSelLocs = C.Allocate(Size); 422 std::copy(Params.begin(), Params.end(), getParams()); 423 std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); 424} 425 426void ObjCMethodDecl::getSelectorLocs( 427 SmallVectorImpl<SourceLocation> &SelLocs) const { 428 for (unsigned i = 0, e = getNumSelectorLocs(); i != e; ++i) 429 SelLocs.push_back(getSelectorLoc(i)); 430} 431 432void ObjCMethodDecl::setMethodParams(ASTContext &C, 433 ArrayRef<ParmVarDecl*> Params, 434 ArrayRef<SourceLocation> SelLocs) { 435 assert((!SelLocs.empty() || isImplicit()) && 436 "No selector locs for non-implicit method"); 437 if (isImplicit()) 438 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); 439 440 SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc); 441 if (SelLocsKind != SelLoc_NonStandard) 442 return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>()); 443 444 setParamsAndSelLocs(C, Params, SelLocs); 445} 446 447/// \brief A definition will return its interface declaration. 448/// An interface declaration will return its definition. 449/// Otherwise it will return itself. 450ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { 451 ASTContext &Ctx = getASTContext(); 452 ObjCMethodDecl *Redecl = 0; 453 if (HasRedeclaration) 454 Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); 455 if (Redecl) 456 return Redecl; 457 458 Decl *CtxD = cast<Decl>(getDeclContext()); 459 460 if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { 461 if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) 462 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); 463 464 } else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) { 465 if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) 466 Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); 467 468 } else if (ObjCImplementationDecl *ImplD = 469 dyn_cast<ObjCImplementationDecl>(CtxD)) { 470 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) 471 Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); 472 473 } else if (ObjCCategoryImplDecl *CImplD = 474 dyn_cast<ObjCCategoryImplDecl>(CtxD)) { 475 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) 476 Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); 477 } 478 479 if (!Redecl && isRedeclaration()) { 480 // This is the last redeclaration, go back to the first method. 481 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), 482 isInstanceMethod()); 483 } 484 485 return Redecl ? Redecl : this; 486} 487 488ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { 489 Decl *CtxD = cast<Decl>(getDeclContext()); 490 491 if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) { 492 if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) 493 if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), 494 isInstanceMethod())) 495 return MD; 496 497 } else if (ObjCCategoryImplDecl *CImplD = 498 dyn_cast<ObjCCategoryImplDecl>(CtxD)) { 499 if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) 500 if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), 501 isInstanceMethod())) 502 return MD; 503 } 504 505 if (isRedeclaration()) 506 return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(), 507 isInstanceMethod()); 508 509 return this; 510} 511 512ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { 513 ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family); 514 if (family != static_cast<unsigned>(InvalidObjCMethodFamily)) 515 return family; 516 517 // Check for an explicit attribute. 518 if (const ObjCMethodFamilyAttr *attr = getAttr<ObjCMethodFamilyAttr>()) { 519 // The unfortunate necessity of mapping between enums here is due 520 // to the attributes framework. 521 switch (attr->getFamily()) { 522 case ObjCMethodFamilyAttr::OMF_None: family = OMF_None; break; 523 case ObjCMethodFamilyAttr::OMF_alloc: family = OMF_alloc; break; 524 case ObjCMethodFamilyAttr::OMF_copy: family = OMF_copy; break; 525 case ObjCMethodFamilyAttr::OMF_init: family = OMF_init; break; 526 case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; 527 case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; 528 } 529 Family = static_cast<unsigned>(family); 530 return family; 531 } 532 533 family = getSelector().getMethodFamily(); 534 switch (family) { 535 case OMF_None: break; 536 537 // init only has a conventional meaning for an instance method, and 538 // it has to return an object. 539 case OMF_init: 540 if (!isInstanceMethod() || !getResultType()->isObjCObjectPointerType()) 541 family = OMF_None; 542 break; 543 544 // alloc/copy/new have a conventional meaning for both class and 545 // instance methods, but they require an object return. 546 case OMF_alloc: 547 case OMF_copy: 548 case OMF_mutableCopy: 549 case OMF_new: 550 if (!getResultType()->isObjCObjectPointerType()) 551 family = OMF_None; 552 break; 553 554 // These selectors have a conventional meaning only for instance methods. 555 case OMF_dealloc: 556 case OMF_finalize: 557 case OMF_retain: 558 case OMF_release: 559 case OMF_autorelease: 560 case OMF_retainCount: 561 case OMF_self: 562 if (!isInstanceMethod()) 563 family = OMF_None; 564 break; 565 566 case OMF_performSelector: 567 if (!isInstanceMethod() || 568 !getResultType()->isObjCIdType()) 569 family = OMF_None; 570 else { 571 unsigned noParams = param_size(); 572 if (noParams < 1 || noParams > 3) 573 family = OMF_None; 574 else { 575 ObjCMethodDecl::arg_type_iterator it = arg_type_begin(); 576 QualType ArgT = (*it); 577 if (!ArgT->isObjCSelType()) { 578 family = OMF_None; 579 break; 580 } 581 while (--noParams) { 582 it++; 583 ArgT = (*it); 584 if (!ArgT->isObjCIdType()) { 585 family = OMF_None; 586 break; 587 } 588 } 589 } 590 } 591 break; 592 593 } 594 595 // Cache the result. 596 Family = static_cast<unsigned>(family); 597 return family; 598} 599 600void ObjCMethodDecl::createImplicitParams(ASTContext &Context, 601 const ObjCInterfaceDecl *OID) { 602 QualType selfTy; 603 if (isInstanceMethod()) { 604 // There may be no interface context due to error in declaration 605 // of the interface (which has been reported). Recover gracefully. 606 if (OID) { 607 selfTy = Context.getObjCInterfaceType(OID); 608 selfTy = Context.getObjCObjectPointerType(selfTy); 609 } else { 610 selfTy = Context.getObjCIdType(); 611 } 612 } else // we have a factory method. 613 selfTy = Context.getObjCClassType(); 614 615 bool selfIsPseudoStrong = false; 616 bool selfIsConsumed = false; 617 618 if (Context.getLangOptions().ObjCAutoRefCount) { 619 if (isInstanceMethod()) { 620 selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); 621 622 // 'self' is always __strong. It's actually pseudo-strong except 623 // in init methods (or methods labeled ns_consumes_self), though. 624 Qualifiers qs; 625 qs.setObjCLifetime(Qualifiers::OCL_Strong); 626 selfTy = Context.getQualifiedType(selfTy, qs); 627 628 // In addition, 'self' is const unless this is an init method. 629 if (getMethodFamily() != OMF_init && !selfIsConsumed) { 630 selfTy = selfTy.withConst(); 631 selfIsPseudoStrong = true; 632 } 633 } 634 else { 635 assert(isClassMethod()); 636 // 'self' is always const in class methods. 637 selfTy = selfTy.withConst(); 638 selfIsPseudoStrong = true; 639 } 640 } 641 642 ImplicitParamDecl *self 643 = ImplicitParamDecl::Create(Context, this, SourceLocation(), 644 &Context.Idents.get("self"), selfTy); 645 setSelfDecl(self); 646 647 if (selfIsConsumed) 648 self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context)); 649 650 if (selfIsPseudoStrong) 651 self->setARCPseudoStrong(true); 652 653 setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), 654 &Context.Idents.get("_cmd"), 655 Context.getObjCSelType())); 656} 657 658ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { 659 if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext())) 660 return ID; 661 if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext())) 662 return CD->getClassInterface(); 663 if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext())) 664 return IMD->getClassInterface(); 665 666 assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method"); 667 llvm_unreachable("unknown method context"); 668} 669 670//===----------------------------------------------------------------------===// 671// ObjCInterfaceDecl 672//===----------------------------------------------------------------------===// 673 674ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, 675 DeclContext *DC, 676 SourceLocation atLoc, 677 IdentifierInfo *Id, 678 ObjCInterfaceDecl *PrevDecl, 679 SourceLocation ClassLoc, 680 bool isInternal){ 681 ObjCInterfaceDecl *Result = new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, 682 isInternal); 683 C.getObjCInterfaceType(Result, PrevDecl); 684 685 if (PrevDecl) { 686 Result->Data = PrevDecl->Data; 687 Result->setPreviousDeclaration(PrevDecl); 688 } 689 690 return Result; 691} 692 693ObjCInterfaceDecl *ObjCInterfaceDecl::CreateEmpty(ASTContext &C) { 694 return new (C) ObjCInterfaceDecl(0, SourceLocation(), 0, SourceLocation(), 695 false); 696} 697 698ObjCInterfaceDecl:: 699ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id, 700 SourceLocation CLoc, bool isInternal) 701 : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc), 702 TypeForDecl(0), Data() 703{ 704 setImplicit(isInternal); 705} 706 707void ObjCInterfaceDecl::LoadExternalDefinition() const { 708 assert(data().ExternallyCompleted && "Class is not externally completed"); 709 data().ExternallyCompleted = false; 710 getASTContext().getExternalSource()->CompleteType( 711 const_cast<ObjCInterfaceDecl *>(this)); 712} 713 714void ObjCInterfaceDecl::setExternallyCompleted() { 715 assert(getASTContext().getExternalSource() && 716 "Class can't be externally completed without an external source"); 717 assert(hasDefinition() && 718 "Forward declarations can't be externally completed"); 719 data().ExternallyCompleted = true; 720} 721 722ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const { 723 if (const ObjCInterfaceDecl *Def = getDefinition()) { 724 if (data().ExternallyCompleted) 725 LoadExternalDefinition(); 726 727 return getASTContext().getObjCImplementation( 728 const_cast<ObjCInterfaceDecl*>(Def)); 729 } 730 731 // FIXME: Should make sure no callers ever do this. 732 return 0; 733} 734 735void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) { 736 getASTContext().setObjCImplementation(getDefinition(), ImplD); 737} 738 739/// all_declared_ivar_begin - return first ivar declared in this class, 740/// its extensions and its implementation. Lazily build the list on first 741/// access. 742ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() { 743 // FIXME: Should make sure no callers ever do this. 744 if (!hasDefinition()) 745 return 0; 746 747 if (data().IvarList) 748 return data().IvarList; 749 750 ObjCIvarDecl *curIvar = 0; 751 if (!ivar_empty()) { 752 ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end(); 753 data().IvarList = (*I); ++I; 754 for (curIvar = data().IvarList; I != E; curIvar = *I, ++I) 755 curIvar->setNextIvar(*I); 756 } 757 758 for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl; 759 CDecl = CDecl->getNextClassExtension()) { 760 if (!CDecl->ivar_empty()) { 761 ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(), 762 E = CDecl->ivar_end(); 763 if (!data().IvarList) { 764 data().IvarList = (*I); ++I; 765 curIvar = data().IvarList; 766 } 767 for ( ;I != E; curIvar = *I, ++I) 768 curIvar->setNextIvar(*I); 769 } 770 } 771 772 if (ObjCImplementationDecl *ImplDecl = getImplementation()) { 773 if (!ImplDecl->ivar_empty()) { 774 ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(), 775 E = ImplDecl->ivar_end(); 776 if (!data().IvarList) { 777 data().IvarList = (*I); ++I; 778 curIvar = data().IvarList; 779 } 780 for ( ;I != E; curIvar = *I, ++I) 781 curIvar->setNextIvar(*I); 782 } 783 } 784 return data().IvarList; 785} 786 787/// FindCategoryDeclaration - Finds category declaration in the list of 788/// categories for this class and returns it. Name of the category is passed 789/// in 'CategoryId'. If category not found, return 0; 790/// 791ObjCCategoryDecl * 792ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { 793 if (data().ExternallyCompleted) 794 LoadExternalDefinition(); 795 796 for (ObjCCategoryDecl *Category = getCategoryList(); 797 Category; Category = Category->getNextClassCategory()) 798 if (Category->getIdentifier() == CategoryId) 799 return Category; 800 return 0; 801} 802 803ObjCMethodDecl * 804ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { 805 for (ObjCCategoryDecl *Category = getCategoryList(); 806 Category; Category = Category->getNextClassCategory()) 807 if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) 808 if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) 809 return MD; 810 return 0; 811} 812 813ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { 814 for (ObjCCategoryDecl *Category = getCategoryList(); 815 Category; Category = Category->getNextClassCategory()) 816 if (ObjCCategoryImplDecl *Impl = Category->getImplementation()) 817 if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) 818 return MD; 819 return 0; 820} 821 822/// ClassImplementsProtocol - Checks that 'lProto' protocol 823/// has been implemented in IDecl class, its super class or categories (if 824/// lookupCategory is true). 825bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, 826 bool lookupCategory, 827 bool RHSIsQualifiedID) { 828 if (!hasDefinition()) 829 return false; 830 831 ObjCInterfaceDecl *IDecl = this; 832 // 1st, look up the class. 833 const ObjCList<ObjCProtocolDecl> &Protocols = 834 IDecl->getReferencedProtocols(); 835 836 for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(), 837 E = Protocols.end(); PI != E; ++PI) { 838 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) 839 return true; 840 // This is dubious and is added to be compatible with gcc. In gcc, it is 841 // also allowed assigning a protocol-qualified 'id' type to a LHS object 842 // when protocol in qualified LHS is in list of protocols in the rhs 'id' 843 // object. This IMO, should be a bug. 844 // FIXME: Treat this as an extension, and flag this as an error when GCC 845 // extensions are not enabled. 846 if (RHSIsQualifiedID && 847 getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto)) 848 return true; 849 } 850 851 // 2nd, look up the category. 852 if (lookupCategory) 853 for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl; 854 CDecl = CDecl->getNextClassCategory()) { 855 for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(), 856 E = CDecl->protocol_end(); PI != E; ++PI) 857 if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI)) 858 return true; 859 } 860 861 // 3rd, look up the super class(s) 862 if (IDecl->getSuperClass()) 863 return 864 IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, 865 RHSIsQualifiedID); 866 867 return false; 868} 869 870//===----------------------------------------------------------------------===// 871// ObjCIvarDecl 872//===----------------------------------------------------------------------===// 873 874ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, 875 SourceLocation StartLoc, 876 SourceLocation IdLoc, IdentifierInfo *Id, 877 QualType T, TypeSourceInfo *TInfo, 878 AccessControl ac, Expr *BW, 879 bool synthesized) { 880 if (DC) { 881 // Ivar's can only appear in interfaces, implementations (via synthesized 882 // properties), and class extensions (via direct declaration, or synthesized 883 // properties). 884 // 885 // FIXME: This should really be asserting this: 886 // (isa<ObjCCategoryDecl>(DC) && 887 // cast<ObjCCategoryDecl>(DC)->IsClassExtension())) 888 // but unfortunately we sometimes place ivars into non-class extension 889 // categories on error. This breaks an AST invariant, and should not be 890 // fixed. 891 assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) || 892 isa<ObjCCategoryDecl>(DC)) && 893 "Invalid ivar decl context!"); 894 // Once a new ivar is created in any of class/class-extension/implementation 895 // decl contexts, the previously built IvarList must be rebuilt. 896 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(DC); 897 if (!ID) { 898 if (ObjCImplementationDecl *IM = dyn_cast<ObjCImplementationDecl>(DC)) { 899 ID = IM->getClassInterface(); 900 if (BW) 901 IM->setHasSynthBitfield(true); 902 } else { 903 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); 904 ID = CD->getClassInterface(); 905 if (BW) 906 CD->setHasSynthBitfield(true); 907 } 908 } 909 ID->setIvarList(0); 910 } 911 912 return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, 913 ac, BW, synthesized); 914} 915 916const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { 917 const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext()); 918 919 switch (DC->getKind()) { 920 default: 921 case ObjCCategoryImpl: 922 case ObjCProtocol: 923 llvm_unreachable("invalid ivar container!"); 924 925 // Ivars can only appear in class extension categories. 926 case ObjCCategory: { 927 const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC); 928 assert(CD->IsClassExtension() && "invalid container for ivar!"); 929 return CD->getClassInterface(); 930 } 931 932 case ObjCImplementation: 933 return cast<ObjCImplementationDecl>(DC)->getClassInterface(); 934 935 case ObjCInterface: 936 return cast<ObjCInterfaceDecl>(DC); 937 } 938} 939 940//===----------------------------------------------------------------------===// 941// ObjCAtDefsFieldDecl 942//===----------------------------------------------------------------------===// 943 944ObjCAtDefsFieldDecl 945*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, 946 SourceLocation StartLoc, SourceLocation IdLoc, 947 IdentifierInfo *Id, QualType T, Expr *BW) { 948 return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW); 949} 950 951//===----------------------------------------------------------------------===// 952// ObjCProtocolDecl 953//===----------------------------------------------------------------------===// 954 955ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC, 956 IdentifierInfo *Id, 957 SourceLocation nameLoc, 958 SourceLocation atStartLoc, 959 bool isForwardDecl) { 960 return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl); 961} 962 963ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) { 964 ObjCProtocolDecl *PDecl = this; 965 966 if (Name == getIdentifier()) 967 return PDecl; 968 969 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) 970 if ((PDecl = (*I)->lookupProtocolNamed(Name))) 971 return PDecl; 972 973 return NULL; 974} 975 976// lookupMethod - Lookup a instance/class method in the protocol and protocols 977// it inherited. 978ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, 979 bool isInstance) const { 980 ObjCMethodDecl *MethodDecl = NULL; 981 982 if ((MethodDecl = getMethod(Sel, isInstance))) 983 return MethodDecl; 984 985 for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I) 986 if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) 987 return MethodDecl; 988 return NULL; 989} 990 991void ObjCProtocolDecl::completedForwardDecl() { 992 assert(isForwardDecl() && "Only valid to call for forward refs"); 993 isForwardProtoDecl = false; 994 if (ASTMutationListener *L = getASTContext().getASTMutationListener()) 995 L->CompletedObjCForwardRef(this); 996} 997 998//===----------------------------------------------------------------------===// 999// ObjCClassDecl 1000//===----------------------------------------------------------------------===// 1001 1002ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L, 1003 ObjCInterfaceDecl *Interface, 1004 SourceLocation InterfaceLoc) 1005 : Decl(ObjCClass, DC, L), Interface(Interface), InterfaceLoc(InterfaceLoc) 1006{ 1007} 1008 1009ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC, 1010 SourceLocation L, 1011 ObjCInterfaceDecl *Interface, 1012 SourceLocation InterfaceLoc) { 1013 return new (C) ObjCClassDecl(DC, L, Interface, InterfaceLoc); 1014} 1015 1016SourceRange ObjCClassDecl::getSourceRange() const { 1017 return SourceRange(getLocation(), InterfaceLoc); 1018} 1019 1020//===----------------------------------------------------------------------===// 1021// ObjCForwardProtocolDecl 1022//===----------------------------------------------------------------------===// 1023 1024ObjCForwardProtocolDecl:: 1025ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L, 1026 ObjCProtocolDecl *const *Elts, unsigned nElts, 1027 const SourceLocation *Locs, ASTContext &C) 1028: Decl(ObjCForwardProtocol, DC, L) { 1029 ReferencedProtocols.set(Elts, nElts, Locs, C); 1030} 1031 1032 1033ObjCForwardProtocolDecl * 1034ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC, 1035 SourceLocation L, 1036 ObjCProtocolDecl *const *Elts, 1037 unsigned NumElts, 1038 const SourceLocation *Locs) { 1039 return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C); 1040} 1041 1042//===----------------------------------------------------------------------===// 1043// ObjCCategoryDecl 1044//===----------------------------------------------------------------------===// 1045 1046ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC, 1047 SourceLocation AtLoc, 1048 SourceLocation ClassNameLoc, 1049 SourceLocation CategoryNameLoc, 1050 IdentifierInfo *Id, 1051 ObjCInterfaceDecl *IDecl) { 1052 ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, 1053 CategoryNameLoc, Id, 1054 IDecl); 1055 if (IDecl) { 1056 // Link this category into its class's category list. 1057 CatDecl->NextClassCategory = IDecl->getCategoryList(); 1058 if (IDecl->hasDefinition()) { 1059 IDecl->setCategoryList(CatDecl); 1060 if (ASTMutationListener *L = C.getASTMutationListener()) 1061 L->AddedObjCCategoryToInterface(CatDecl, IDecl); 1062 } 1063 } 1064 1065 return CatDecl; 1066} 1067 1068ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, EmptyShell Empty) { 1069 return new (C) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(), 1070 SourceLocation(), 0, 0); 1071} 1072 1073ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const { 1074 return getASTContext().getObjCImplementation( 1075 const_cast<ObjCCategoryDecl*>(this)); 1076} 1077 1078void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) { 1079 getASTContext().setObjCImplementation(this, ImplD); 1080} 1081 1082 1083//===----------------------------------------------------------------------===// 1084// ObjCCategoryImplDecl 1085//===----------------------------------------------------------------------===// 1086 1087ObjCCategoryImplDecl * 1088ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC, 1089 IdentifierInfo *Id, 1090 ObjCInterfaceDecl *ClassInterface, 1091 SourceLocation nameLoc, 1092 SourceLocation atStartLoc, 1093 SourceLocation CategoryNameLoc) { 1094 return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface, 1095 nameLoc, atStartLoc, CategoryNameLoc); 1096} 1097 1098ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { 1099 // The class interface might be NULL if we are working with invalid code. 1100 if (const ObjCInterfaceDecl *ID = getClassInterface()) 1101 return ID->FindCategoryDeclaration(getIdentifier()); 1102 return 0; 1103} 1104 1105 1106void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) { 1107 // FIXME: The context should be correct before we get here. 1108 property->setLexicalDeclContext(this); 1109 addDecl(property); 1110} 1111 1112void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { 1113 ASTContext &Ctx = getASTContext(); 1114 1115 if (ObjCImplementationDecl *ImplD 1116 = dyn_cast_or_null<ObjCImplementationDecl>(this)) { 1117 if (IFace) 1118 Ctx.setObjCImplementation(IFace, ImplD); 1119 1120 } else if (ObjCCategoryImplDecl *ImplD = 1121 dyn_cast_or_null<ObjCCategoryImplDecl>(this)) { 1122 if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) 1123 Ctx.setObjCImplementation(CD, ImplD); 1124 } 1125 1126 ClassInterface = IFace; 1127} 1128 1129/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of 1130/// properties implemented in this category @implementation block and returns 1131/// the implemented property that uses it. 1132/// 1133ObjCPropertyImplDecl *ObjCImplDecl:: 1134FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { 1135 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ 1136 ObjCPropertyImplDecl *PID = *i; 1137 if (PID->getPropertyIvarDecl() && 1138 PID->getPropertyIvarDecl()->getIdentifier() == ivarId) 1139 return PID; 1140 } 1141 return 0; 1142} 1143 1144/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl 1145/// added to the list of those properties @synthesized/@dynamic in this 1146/// category @implementation block. 1147/// 1148ObjCPropertyImplDecl *ObjCImplDecl:: 1149FindPropertyImplDecl(IdentifierInfo *Id) const { 1150 for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ 1151 ObjCPropertyImplDecl *PID = *i; 1152 if (PID->getPropertyDecl()->getIdentifier() == Id) 1153 return PID; 1154 } 1155 return 0; 1156} 1157 1158raw_ostream &clang::operator<<(raw_ostream &OS, 1159 const ObjCCategoryImplDecl *CID) { 1160 OS << CID->getName(); 1161 return OS; 1162} 1163 1164//===----------------------------------------------------------------------===// 1165// ObjCImplementationDecl 1166//===----------------------------------------------------------------------===// 1167 1168ObjCImplementationDecl * 1169ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC, 1170 ObjCInterfaceDecl *ClassInterface, 1171 ObjCInterfaceDecl *SuperDecl, 1172 SourceLocation nameLoc, 1173 SourceLocation atStartLoc) { 1174 return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl, 1175 nameLoc, atStartLoc); 1176} 1177 1178void ObjCImplementationDecl::setIvarInitializers(ASTContext &C, 1179 CXXCtorInitializer ** initializers, 1180 unsigned numInitializers) { 1181 if (numInitializers > 0) { 1182 NumIvarInitializers = numInitializers; 1183 CXXCtorInitializer **ivarInitializers = 1184 new (C) CXXCtorInitializer*[NumIvarInitializers]; 1185 memcpy(ivarInitializers, initializers, 1186 numInitializers * sizeof(CXXCtorInitializer*)); 1187 IvarInitializers = ivarInitializers; 1188 } 1189} 1190 1191raw_ostream &clang::operator<<(raw_ostream &OS, 1192 const ObjCImplementationDecl *ID) { 1193 OS << ID->getName(); 1194 return OS; 1195} 1196 1197//===----------------------------------------------------------------------===// 1198// ObjCCompatibleAliasDecl 1199//===----------------------------------------------------------------------===// 1200 1201ObjCCompatibleAliasDecl * 1202ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC, 1203 SourceLocation L, 1204 IdentifierInfo *Id, 1205 ObjCInterfaceDecl* AliasedClass) { 1206 return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass); 1207} 1208 1209//===----------------------------------------------------------------------===// 1210// ObjCPropertyDecl 1211//===----------------------------------------------------------------------===// 1212 1213ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC, 1214 SourceLocation L, 1215 IdentifierInfo *Id, 1216 SourceLocation AtLoc, 1217 TypeSourceInfo *T, 1218 PropertyControl propControl) { 1219 return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T); 1220} 1221 1222//===----------------------------------------------------------------------===// 1223// ObjCPropertyImplDecl 1224//===----------------------------------------------------------------------===// 1225 1226ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C, 1227 DeclContext *DC, 1228 SourceLocation atLoc, 1229 SourceLocation L, 1230 ObjCPropertyDecl *property, 1231 Kind PK, 1232 ObjCIvarDecl *ivar, 1233 SourceLocation ivarLoc) { 1234 return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar, 1235 ivarLoc); 1236} 1237 1238SourceRange ObjCPropertyImplDecl::getSourceRange() const { 1239 SourceLocation EndLoc = getLocation(); 1240 if (IvarLoc.isValid()) 1241 EndLoc = IvarLoc; 1242 1243 return SourceRange(AtLoc, EndLoc); 1244} 1245