1 //===--- DeclCXX.cpp - C++ 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 C++ related Decl classes. 11 // 12 //===----------------------------------------------------------------------===// 13 #include "clang/AST/DeclCXX.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/ASTLambda.h" 16 #include "clang/AST/ASTMutationListener.h" 17 #include "clang/AST/CXXInheritance.h" 18 #include "clang/AST/DeclTemplate.h" 19 #include "clang/AST/Expr.h" 20 #include "clang/AST/ExprCXX.h" 21 #include "clang/AST/TypeLoc.h" 22 #include "clang/Basic/IdentifierTable.h" 23 #include "llvm/ADT/STLExtras.h" 24 #include "llvm/ADT/SmallPtrSet.h" 25 using namespace clang; 26 27 //===----------------------------------------------------------------------===// 28 // Decl Allocation/Deallocation Method Implementations 29 //===----------------------------------------------------------------------===// 30 31 void AccessSpecDecl::anchor() { } 32 33 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 34 return new (C, ID) AccessSpecDecl(EmptyShell()); 35 } 36 37 void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const { 38 ExternalASTSource *Source = C.getExternalSource(); 39 assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set"); 40 assert(Source && "getFromExternalSource with no external source"); 41 42 for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I) 43 I.setDecl(cast<NamedDecl>(Source->GetExternalDecl( 44 reinterpret_cast<uintptr_t>(I.getDecl()) >> 2))); 45 Impl.Decls.setLazy(false); 46 } 47 48 CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) 49 : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), 50 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), 51 Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true), 52 HasPrivateFields(false), HasProtectedFields(false), 53 HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), 54 HasOnlyCMembers(true), HasInClassInitializer(false), 55 HasUninitializedReferenceMember(false), HasUninitializedFields(false), 56 NeedOverloadResolutionForMoveConstructor(false), 57 NeedOverloadResolutionForMoveAssignment(false), 58 NeedOverloadResolutionForDestructor(false), 59 DefaultedMoveConstructorIsDeleted(false), 60 DefaultedMoveAssignmentIsDeleted(false), 61 DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All), 62 DeclaredNonTrivialSpecialMembers(0), HasIrrelevantDestructor(true), 63 HasConstexprNonCopyMoveConstructor(false), 64 HasDefaultedDefaultConstructor(false), 65 DefaultedDefaultConstructorIsConstexpr(true), 66 HasConstexprDefaultConstructor(false), 67 HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false), 68 UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), 69 ImplicitCopyConstructorHasConstParam(true), 70 ImplicitCopyAssignmentHasConstParam(true), 71 HasDeclaredCopyConstructorWithConstParam(false), 72 HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false), 73 IsParsingBaseSpecifiers(false), NumBases(0), NumVBases(0), Bases(), 74 VBases(), Definition(D), FirstFriend() {} 75 76 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { 77 return Bases.get(Definition->getASTContext().getExternalSource()); 78 } 79 80 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { 81 return VBases.get(Definition->getASTContext().getExternalSource()); 82 } 83 84 CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, 85 DeclContext *DC, SourceLocation StartLoc, 86 SourceLocation IdLoc, IdentifierInfo *Id, 87 CXXRecordDecl *PrevDecl) 88 : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), 89 DefinitionData(PrevDecl ? PrevDecl->DefinitionData 90 : DefinitionDataPtr(this)), 91 TemplateOrInstantiation() {} 92 93 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, 94 DeclContext *DC, SourceLocation StartLoc, 95 SourceLocation IdLoc, IdentifierInfo *Id, 96 CXXRecordDecl* PrevDecl, 97 bool DelayTypeCreation) { 98 CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, 99 IdLoc, Id, PrevDecl); 100 R->MayHaveOutOfDateDef = C.getLangOpts().Modules; 101 102 // FIXME: DelayTypeCreation seems like such a hack 103 if (!DelayTypeCreation) 104 C.getTypeDeclType(R, PrevDecl); 105 return R; 106 } 107 108 CXXRecordDecl * 109 CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, 110 TypeSourceInfo *Info, SourceLocation Loc, 111 bool Dependent, bool IsGeneric, 112 LambdaCaptureDefault CaptureDefault) { 113 CXXRecordDecl *R = 114 new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, 115 nullptr, nullptr); 116 R->IsBeingDefined = true; 117 R->DefinitionData = 118 new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, 119 CaptureDefault); 120 R->MayHaveOutOfDateDef = false; 121 R->setImplicit(true); 122 C.getTypeDeclType(R, /*PrevDecl=*/nullptr); 123 return R; 124 } 125 126 CXXRecordDecl * 127 CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { 128 CXXRecordDecl *R = new (C, ID) CXXRecordDecl( 129 CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), 130 nullptr, nullptr); 131 R->MayHaveOutOfDateDef = false; 132 return R; 133 } 134 135 void 136 CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, 137 unsigned NumBases) { 138 ASTContext &C = getASTContext(); 139 140 if (!data().Bases.isOffset() && data().NumBases > 0) 141 C.Deallocate(data().getBases()); 142 143 if (NumBases) { 144 // C++ [dcl.init.aggr]p1: 145 // An aggregate is [...] a class with [...] no base classes [...]. 146 data().Aggregate = false; 147 148 // C++ [class]p4: 149 // A POD-struct is an aggregate class... 150 data().PlainOldData = false; 151 } 152 153 // The set of seen virtual base types. 154 llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; 155 156 // The virtual bases of this class. 157 SmallVector<const CXXBaseSpecifier *, 8> VBases; 158 159 data().Bases = new(C) CXXBaseSpecifier [NumBases]; 160 data().NumBases = NumBases; 161 for (unsigned i = 0; i < NumBases; ++i) { 162 data().getBases()[i] = *Bases[i]; 163 // Keep track of inherited vbases for this base class. 164 const CXXBaseSpecifier *Base = Bases[i]; 165 QualType BaseType = Base->getType(); 166 // Skip dependent types; we can't do any checking on them now. 167 if (BaseType->isDependentType()) 168 continue; 169 CXXRecordDecl *BaseClassDecl 170 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); 171 172 // A class with a non-empty base class is not empty. 173 // FIXME: Standard ref? 174 if (!BaseClassDecl->isEmpty()) { 175 if (!data().Empty) { 176 // C++0x [class]p7: 177 // A standard-layout class is a class that: 178 // [...] 179 // -- either has no non-static data members in the most derived 180 // class and at most one base class with non-static data members, 181 // or has no base classes with non-static data members, and 182 // If this is the second non-empty base, then neither of these two 183 // clauses can be true. 184 data().IsStandardLayout = false; 185 } 186 187 data().Empty = false; 188 data().HasNoNonEmptyBases = false; 189 } 190 191 // C++ [class.virtual]p1: 192 // A class that declares or inherits a virtual function is called a 193 // polymorphic class. 194 if (BaseClassDecl->isPolymorphic()) 195 data().Polymorphic = true; 196 197 // C++0x [class]p7: 198 // A standard-layout class is a class that: [...] 199 // -- has no non-standard-layout base classes 200 if (!BaseClassDecl->isStandardLayout()) 201 data().IsStandardLayout = false; 202 203 // Record if this base is the first non-literal field or base. 204 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C)) 205 data().HasNonLiteralTypeFieldsOrBases = true; 206 207 // Now go through all virtual bases of this base and add them. 208 for (const auto &VBase : BaseClassDecl->vbases()) { 209 // Add this base if it's not already in the list. 210 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) { 211 VBases.push_back(&VBase); 212 213 // C++11 [class.copy]p8: 214 // The implicitly-declared copy constructor for a class X will have 215 // the form 'X::X(const X&)' if each [...] virtual base class B of X 216 // has a copy constructor whose first parameter is of type 217 // 'const B&' or 'const volatile B&' [...] 218 if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl()) 219 if (!VBaseDecl->hasCopyConstructorWithConstParam()) 220 data().ImplicitCopyConstructorHasConstParam = false; 221 } 222 } 223 224 if (Base->isVirtual()) { 225 // Add this base if it's not already in the list. 226 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second) 227 VBases.push_back(Base); 228 229 // C++0x [meta.unary.prop] is_empty: 230 // T is a class type, but not a union type, with ... no virtual base 231 // classes 232 data().Empty = false; 233 234 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: 235 // A [default constructor, copy/move constructor, or copy/move assignment 236 // operator for a class X] is trivial [...] if: 237 // -- class X has [...] no virtual base classes 238 data().HasTrivialSpecialMembers &= SMF_Destructor; 239 240 // C++0x [class]p7: 241 // A standard-layout class is a class that: [...] 242 // -- has [...] no virtual base classes 243 data().IsStandardLayout = false; 244 245 // C++11 [dcl.constexpr]p4: 246 // In the definition of a constexpr constructor [...] 247 // -- the class shall not have any virtual base classes 248 data().DefaultedDefaultConstructorIsConstexpr = false; 249 } else { 250 // C++ [class.ctor]p5: 251 // A default constructor is trivial [...] if: 252 // -- all the direct base classes of its class have trivial default 253 // constructors. 254 if (!BaseClassDecl->hasTrivialDefaultConstructor()) 255 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 256 257 // C++0x [class.copy]p13: 258 // A copy/move constructor for class X is trivial if [...] 259 // [...] 260 // -- the constructor selected to copy/move each direct base class 261 // subobject is trivial, and 262 if (!BaseClassDecl->hasTrivialCopyConstructor()) 263 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; 264 // If the base class doesn't have a simple move constructor, we'll eagerly 265 // declare it and perform overload resolution to determine which function 266 // it actually calls. If it does have a simple move constructor, this 267 // check is correct. 268 if (!BaseClassDecl->hasTrivialMoveConstructor()) 269 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; 270 271 // C++0x [class.copy]p27: 272 // A copy/move assignment operator for class X is trivial if [...] 273 // [...] 274 // -- the assignment operator selected to copy/move each direct base 275 // class subobject is trivial, and 276 if (!BaseClassDecl->hasTrivialCopyAssignment()) 277 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; 278 // If the base class doesn't have a simple move assignment, we'll eagerly 279 // declare it and perform overload resolution to determine which function 280 // it actually calls. If it does have a simple move assignment, this 281 // check is correct. 282 if (!BaseClassDecl->hasTrivialMoveAssignment()) 283 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; 284 285 // C++11 [class.ctor]p6: 286 // If that user-written default constructor would satisfy the 287 // requirements of a constexpr constructor, the implicitly-defined 288 // default constructor is constexpr. 289 if (!BaseClassDecl->hasConstexprDefaultConstructor()) 290 data().DefaultedDefaultConstructorIsConstexpr = false; 291 } 292 293 // C++ [class.ctor]p3: 294 // A destructor is trivial if all the direct base classes of its class 295 // have trivial destructors. 296 if (!BaseClassDecl->hasTrivialDestructor()) 297 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 298 299 if (!BaseClassDecl->hasIrrelevantDestructor()) 300 data().HasIrrelevantDestructor = false; 301 302 // C++11 [class.copy]p18: 303 // The implicitly-declared copy assignment oeprator for a class X will 304 // have the form 'X& X::operator=(const X&)' if each direct base class B 305 // of X has a copy assignment operator whose parameter is of type 'const 306 // B&', 'const volatile B&', or 'B' [...] 307 if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) 308 data().ImplicitCopyAssignmentHasConstParam = false; 309 310 // C++11 [class.copy]p8: 311 // The implicitly-declared copy constructor for a class X will have 312 // the form 'X::X(const X&)' if each direct [...] base class B of X 313 // has a copy constructor whose first parameter is of type 314 // 'const B&' or 'const volatile B&' [...] 315 if (!BaseClassDecl->hasCopyConstructorWithConstParam()) 316 data().ImplicitCopyConstructorHasConstParam = false; 317 318 // A class has an Objective-C object member if... or any of its bases 319 // has an Objective-C object member. 320 if (BaseClassDecl->hasObjectMember()) 321 setHasObjectMember(true); 322 323 if (BaseClassDecl->hasVolatileMember()) 324 setHasVolatileMember(true); 325 326 // Keep track of the presence of mutable fields. 327 if (BaseClassDecl->hasMutableFields()) 328 data().HasMutableFields = true; 329 330 if (BaseClassDecl->hasUninitializedReferenceMember()) 331 data().HasUninitializedReferenceMember = true; 332 333 if (!BaseClassDecl->allowConstDefaultInit()) 334 data().HasUninitializedFields = true; 335 336 addedClassSubobject(BaseClassDecl); 337 } 338 339 if (VBases.empty()) { 340 data().IsParsingBaseSpecifiers = false; 341 return; 342 } 343 344 // Create base specifier for any direct or indirect virtual bases. 345 data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; 346 data().NumVBases = VBases.size(); 347 for (int I = 0, E = VBases.size(); I != E; ++I) { 348 QualType Type = VBases[I]->getType(); 349 if (!Type->isDependentType()) 350 addedClassSubobject(Type->getAsCXXRecordDecl()); 351 data().getVBases()[I] = *VBases[I]; 352 } 353 354 data().IsParsingBaseSpecifiers = false; 355 } 356 357 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) { 358 // C++11 [class.copy]p11: 359 // A defaulted copy/move constructor for a class X is defined as 360 // deleted if X has: 361 // -- a direct or virtual base class B that cannot be copied/moved [...] 362 // -- a non-static data member of class type M (or array thereof) 363 // that cannot be copied or moved [...] 364 if (!Subobj->hasSimpleMoveConstructor()) 365 data().NeedOverloadResolutionForMoveConstructor = true; 366 367 // C++11 [class.copy]p23: 368 // A defaulted copy/move assignment operator for a class X is defined as 369 // deleted if X has: 370 // -- a direct or virtual base class B that cannot be copied/moved [...] 371 // -- a non-static data member of class type M (or array thereof) 372 // that cannot be copied or moved [...] 373 if (!Subobj->hasSimpleMoveAssignment()) 374 data().NeedOverloadResolutionForMoveAssignment = true; 375 376 // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5: 377 // A defaulted [ctor or dtor] for a class X is defined as 378 // deleted if X has: 379 // -- any direct or virtual base class [...] has a type with a destructor 380 // that is deleted or inaccessible from the defaulted [ctor or dtor]. 381 // -- any non-static data member has a type with a destructor 382 // that is deleted or inaccessible from the defaulted [ctor or dtor]. 383 if (!Subobj->hasSimpleDestructor()) { 384 data().NeedOverloadResolutionForMoveConstructor = true; 385 data().NeedOverloadResolutionForDestructor = true; 386 } 387 } 388 389 bool CXXRecordDecl::hasAnyDependentBases() const { 390 if (!isDependentContext()) 391 return false; 392 393 return !forallBases([](const CXXRecordDecl *) { return true; }); 394 } 395 396 bool CXXRecordDecl::isTriviallyCopyable() const { 397 // C++0x [class]p5: 398 // A trivially copyable class is a class that: 399 // -- has no non-trivial copy constructors, 400 if (hasNonTrivialCopyConstructor()) return false; 401 // -- has no non-trivial move constructors, 402 if (hasNonTrivialMoveConstructor()) return false; 403 // -- has no non-trivial copy assignment operators, 404 if (hasNonTrivialCopyAssignment()) return false; 405 // -- has no non-trivial move assignment operators, and 406 if (hasNonTrivialMoveAssignment()) return false; 407 // -- has a trivial destructor. 408 if (!hasTrivialDestructor()) return false; 409 410 return true; 411 } 412 413 void CXXRecordDecl::markedVirtualFunctionPure() { 414 // C++ [class.abstract]p2: 415 // A class is abstract if it has at least one pure virtual function. 416 data().Abstract = true; 417 } 418 419 void CXXRecordDecl::addedMember(Decl *D) { 420 if (!D->isImplicit() && 421 !isa<FieldDecl>(D) && 422 !isa<IndirectFieldDecl>(D) && 423 (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class || 424 cast<TagDecl>(D)->getTagKind() == TTK_Interface)) 425 data().HasOnlyCMembers = false; 426 427 // Ignore friends and invalid declarations. 428 if (D->getFriendObjectKind() || D->isInvalidDecl()) 429 return; 430 431 FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); 432 if (FunTmpl) 433 D = FunTmpl->getTemplatedDecl(); 434 435 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 436 if (Method->isVirtual()) { 437 // C++ [dcl.init.aggr]p1: 438 // An aggregate is an array or a class with [...] no virtual functions. 439 data().Aggregate = false; 440 441 // C++ [class]p4: 442 // A POD-struct is an aggregate class... 443 data().PlainOldData = false; 444 445 // Virtual functions make the class non-empty. 446 // FIXME: Standard ref? 447 data().Empty = false; 448 449 // C++ [class.virtual]p1: 450 // A class that declares or inherits a virtual function is called a 451 // polymorphic class. 452 data().Polymorphic = true; 453 454 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: 455 // A [default constructor, copy/move constructor, or copy/move 456 // assignment operator for a class X] is trivial [...] if: 457 // -- class X has no virtual functions [...] 458 data().HasTrivialSpecialMembers &= SMF_Destructor; 459 460 // C++0x [class]p7: 461 // A standard-layout class is a class that: [...] 462 // -- has no virtual functions 463 data().IsStandardLayout = false; 464 } 465 } 466 467 // Notify the listener if an implicit member was added after the definition 468 // was completed. 469 if (!isBeingDefined() && D->isImplicit()) 470 if (ASTMutationListener *L = getASTMutationListener()) 471 L->AddedCXXImplicitMember(data().Definition, D); 472 473 // The kind of special member this declaration is, if any. 474 unsigned SMKind = 0; 475 476 // Handle constructors. 477 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 478 if (!Constructor->isImplicit()) { 479 // Note that we have a user-declared constructor. 480 data().UserDeclaredConstructor = true; 481 482 // C++ [class]p4: 483 // A POD-struct is an aggregate class [...] 484 // Since the POD bit is meant to be C++03 POD-ness, clear it even if the 485 // type is technically an aggregate in C++0x since it wouldn't be in 03. 486 data().PlainOldData = false; 487 } 488 489 // Technically, "user-provided" is only defined for special member 490 // functions, but the intent of the standard is clearly that it should apply 491 // to all functions. 492 bool UserProvided = Constructor->isUserProvided(); 493 494 if (Constructor->isDefaultConstructor()) { 495 SMKind |= SMF_DefaultConstructor; 496 497 if (UserProvided) 498 data().UserProvidedDefaultConstructor = true; 499 if (Constructor->isConstexpr()) 500 data().HasConstexprDefaultConstructor = true; 501 if (Constructor->isDefaulted()) 502 data().HasDefaultedDefaultConstructor = true; 503 } 504 505 if (!FunTmpl) { 506 unsigned Quals; 507 if (Constructor->isCopyConstructor(Quals)) { 508 SMKind |= SMF_CopyConstructor; 509 510 if (Quals & Qualifiers::Const) 511 data().HasDeclaredCopyConstructorWithConstParam = true; 512 } else if (Constructor->isMoveConstructor()) 513 SMKind |= SMF_MoveConstructor; 514 } 515 516 // Record if we see any constexpr constructors which are neither copy 517 // nor move constructors. 518 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) 519 data().HasConstexprNonCopyMoveConstructor = true; 520 521 // C++ [dcl.init.aggr]p1: 522 // An aggregate is an array or a class with no user-declared 523 // constructors [...]. 524 // C++11 [dcl.init.aggr]p1: 525 // An aggregate is an array or a class with no user-provided 526 // constructors [...]. 527 if (getASTContext().getLangOpts().CPlusPlus11 528 ? UserProvided : !Constructor->isImplicit()) 529 data().Aggregate = false; 530 } 531 532 // Handle destructors. 533 if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) { 534 SMKind |= SMF_Destructor; 535 536 if (DD->isUserProvided()) 537 data().HasIrrelevantDestructor = false; 538 // If the destructor is explicitly defaulted and not trivial or not public 539 // or if the destructor is deleted, we clear HasIrrelevantDestructor in 540 // finishedDefaultedOrDeletedMember. 541 542 // C++11 [class.dtor]p5: 543 // A destructor is trivial if [...] the destructor is not virtual. 544 if (DD->isVirtual()) 545 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 546 } 547 548 // Handle member functions. 549 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 550 if (Method->isCopyAssignmentOperator()) { 551 SMKind |= SMF_CopyAssignment; 552 553 const ReferenceType *ParamTy = 554 Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); 555 if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) 556 data().HasDeclaredCopyAssignmentWithConstParam = true; 557 } 558 559 if (Method->isMoveAssignmentOperator()) 560 SMKind |= SMF_MoveAssignment; 561 562 // Keep the list of conversion functions up-to-date. 563 if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { 564 // FIXME: We use the 'unsafe' accessor for the access specifier here, 565 // because Sema may not have set it yet. That's really just a misdesign 566 // in Sema. However, LLDB *will* have set the access specifier correctly, 567 // and adds declarations after the class is technically completed, 568 // so completeDefinition()'s overriding of the access specifiers doesn't 569 // work. 570 AccessSpecifier AS = Conversion->getAccessUnsafe(); 571 572 if (Conversion->getPrimaryTemplate()) { 573 // We don't record specializations. 574 } else { 575 ASTContext &Ctx = getASTContext(); 576 ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx); 577 NamedDecl *Primary = 578 FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion); 579 if (Primary->getPreviousDecl()) 580 Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()), 581 Primary, AS); 582 else 583 Conversions.addDecl(Ctx, Primary, AS); 584 } 585 } 586 587 if (SMKind) { 588 // If this is the first declaration of a special member, we no longer have 589 // an implicit trivial special member. 590 data().HasTrivialSpecialMembers &= 591 data().DeclaredSpecialMembers | ~SMKind; 592 593 if (!Method->isImplicit() && !Method->isUserProvided()) { 594 // This method is user-declared but not user-provided. We can't work out 595 // whether it's trivial yet (not until we get to the end of the class). 596 // We'll handle this method in finishedDefaultedOrDeletedMember. 597 } else if (Method->isTrivial()) 598 data().HasTrivialSpecialMembers |= SMKind; 599 else 600 data().DeclaredNonTrivialSpecialMembers |= SMKind; 601 602 // Note when we have declared a declared special member, and suppress the 603 // implicit declaration of this special member. 604 data().DeclaredSpecialMembers |= SMKind; 605 606 if (!Method->isImplicit()) { 607 data().UserDeclaredSpecialMembers |= SMKind; 608 609 // C++03 [class]p4: 610 // A POD-struct is an aggregate class that has [...] no user-defined 611 // copy assignment operator and no user-defined destructor. 612 // 613 // Since the POD bit is meant to be C++03 POD-ness, and in C++03, 614 // aggregates could not have any constructors, clear it even for an 615 // explicitly defaulted or deleted constructor. 616 // type is technically an aggregate in C++0x since it wouldn't be in 03. 617 // 618 // Also, a user-declared move assignment operator makes a class non-POD. 619 // This is an extension in C++03. 620 data().PlainOldData = false; 621 } 622 } 623 624 return; 625 } 626 627 // Handle non-static data members. 628 if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { 629 // C++ [class.bit]p2: 630 // A declaration for a bit-field that omits the identifier declares an 631 // unnamed bit-field. Unnamed bit-fields are not members and cannot be 632 // initialized. 633 if (Field->isUnnamedBitfield()) 634 return; 635 636 // C++ [dcl.init.aggr]p1: 637 // An aggregate is an array or a class (clause 9) with [...] no 638 // private or protected non-static data members (clause 11). 639 // 640 // A POD must be an aggregate. 641 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { 642 data().Aggregate = false; 643 data().PlainOldData = false; 644 } 645 646 // C++0x [class]p7: 647 // A standard-layout class is a class that: 648 // [...] 649 // -- has the same access control for all non-static data members, 650 switch (D->getAccess()) { 651 case AS_private: data().HasPrivateFields = true; break; 652 case AS_protected: data().HasProtectedFields = true; break; 653 case AS_public: data().HasPublicFields = true; break; 654 case AS_none: llvm_unreachable("Invalid access specifier"); 655 }; 656 if ((data().HasPrivateFields + data().HasProtectedFields + 657 data().HasPublicFields) > 1) 658 data().IsStandardLayout = false; 659 660 // Keep track of the presence of mutable fields. 661 if (Field->isMutable()) 662 data().HasMutableFields = true; 663 664 // C++11 [class.union]p8, DR1460: 665 // If X is a union, a non-static data member of X that is not an anonymous 666 // union is a variant member of X. 667 if (isUnion() && !Field->isAnonymousStructOrUnion()) 668 data().HasVariantMembers = true; 669 670 // C++0x [class]p9: 671 // A POD struct is a class that is both a trivial class and a 672 // standard-layout class, and has no non-static data members of type 673 // non-POD struct, non-POD union (or array of such types). 674 // 675 // Automatic Reference Counting: the presence of a member of Objective-C pointer type 676 // that does not explicitly have no lifetime makes the class a non-POD. 677 ASTContext &Context = getASTContext(); 678 QualType T = Context.getBaseElementType(Field->getType()); 679 if (T->isObjCRetainableType() || T.isObjCGCStrong()) { 680 if (!Context.getLangOpts().ObjCAutoRefCount) { 681 setHasObjectMember(true); 682 } else if (T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) { 683 // Objective-C Automatic Reference Counting: 684 // If a class has a non-static data member of Objective-C pointer 685 // type (or array thereof), it is a non-POD type and its 686 // default constructor (if any), copy constructor, move constructor, 687 // copy assignment operator, move assignment operator, and destructor are 688 // non-trivial. 689 setHasObjectMember(true); 690 struct DefinitionData &Data = data(); 691 Data.PlainOldData = false; 692 Data.HasTrivialSpecialMembers = 0; 693 Data.HasIrrelevantDestructor = false; 694 } 695 } else if (!T.isCXX98PODType(Context)) 696 data().PlainOldData = false; 697 698 if (T->isReferenceType()) { 699 if (!Field->hasInClassInitializer()) 700 data().HasUninitializedReferenceMember = true; 701 702 // C++0x [class]p7: 703 // A standard-layout class is a class that: 704 // -- has no non-static data members of type [...] reference, 705 data().IsStandardLayout = false; 706 } 707 708 if (!Field->hasInClassInitializer() && !Field->isMutable()) { 709 if (CXXRecordDecl *FieldType = Field->getType()->getAsCXXRecordDecl()) { 710 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) 711 data().HasUninitializedFields = true; 712 } else { 713 data().HasUninitializedFields = true; 714 } 715 } 716 717 // Record if this field is the first non-literal or volatile field or base. 718 if (!T->isLiteralType(Context) || T.isVolatileQualified()) 719 data().HasNonLiteralTypeFieldsOrBases = true; 720 721 if (Field->hasInClassInitializer() || 722 (Field->isAnonymousStructOrUnion() && 723 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) { 724 data().HasInClassInitializer = true; 725 726 // C++11 [class]p5: 727 // A default constructor is trivial if [...] no non-static data member 728 // of its class has a brace-or-equal-initializer. 729 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 730 731 // C++11 [dcl.init.aggr]p1: 732 // An aggregate is a [...] class with [...] no 733 // brace-or-equal-initializers for non-static data members. 734 // 735 // This rule was removed in C++1y. 736 if (!getASTContext().getLangOpts().CPlusPlus14) 737 data().Aggregate = false; 738 739 // C++11 [class]p10: 740 // A POD struct is [...] a trivial class. 741 data().PlainOldData = false; 742 } 743 744 // C++11 [class.copy]p23: 745 // A defaulted copy/move assignment operator for a class X is defined 746 // as deleted if X has: 747 // -- a non-static data member of reference type 748 if (T->isReferenceType()) 749 data().DefaultedMoveAssignmentIsDeleted = true; 750 751 if (const RecordType *RecordTy = T->getAs<RecordType>()) { 752 CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); 753 if (FieldRec->getDefinition()) { 754 addedClassSubobject(FieldRec); 755 756 // We may need to perform overload resolution to determine whether a 757 // field can be moved if it's const or volatile qualified. 758 if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) { 759 data().NeedOverloadResolutionForMoveConstructor = true; 760 data().NeedOverloadResolutionForMoveAssignment = true; 761 } 762 763 // C++11 [class.ctor]p5, C++11 [class.copy]p11: 764 // A defaulted [special member] for a class X is defined as 765 // deleted if: 766 // -- X is a union-like class that has a variant member with a 767 // non-trivial [corresponding special member] 768 if (isUnion()) { 769 if (FieldRec->hasNonTrivialMoveConstructor()) 770 data().DefaultedMoveConstructorIsDeleted = true; 771 if (FieldRec->hasNonTrivialMoveAssignment()) 772 data().DefaultedMoveAssignmentIsDeleted = true; 773 if (FieldRec->hasNonTrivialDestructor()) 774 data().DefaultedDestructorIsDeleted = true; 775 } 776 777 // C++0x [class.ctor]p5: 778 // A default constructor is trivial [...] if: 779 // -- for all the non-static data members of its class that are of 780 // class type (or array thereof), each such class has a trivial 781 // default constructor. 782 if (!FieldRec->hasTrivialDefaultConstructor()) 783 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 784 785 // C++0x [class.copy]p13: 786 // A copy/move constructor for class X is trivial if [...] 787 // [...] 788 // -- for each non-static data member of X that is of class type (or 789 // an array thereof), the constructor selected to copy/move that 790 // member is trivial; 791 if (!FieldRec->hasTrivialCopyConstructor()) 792 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; 793 // If the field doesn't have a simple move constructor, we'll eagerly 794 // declare the move constructor for this class and we'll decide whether 795 // it's trivial then. 796 if (!FieldRec->hasTrivialMoveConstructor()) 797 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; 798 799 // C++0x [class.copy]p27: 800 // A copy/move assignment operator for class X is trivial if [...] 801 // [...] 802 // -- for each non-static data member of X that is of class type (or 803 // an array thereof), the assignment operator selected to 804 // copy/move that member is trivial; 805 if (!FieldRec->hasTrivialCopyAssignment()) 806 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; 807 // If the field doesn't have a simple move assignment, we'll eagerly 808 // declare the move assignment for this class and we'll decide whether 809 // it's trivial then. 810 if (!FieldRec->hasTrivialMoveAssignment()) 811 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; 812 813 if (!FieldRec->hasTrivialDestructor()) 814 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 815 if (!FieldRec->hasIrrelevantDestructor()) 816 data().HasIrrelevantDestructor = false; 817 if (FieldRec->hasObjectMember()) 818 setHasObjectMember(true); 819 if (FieldRec->hasVolatileMember()) 820 setHasVolatileMember(true); 821 822 // C++0x [class]p7: 823 // A standard-layout class is a class that: 824 // -- has no non-static data members of type non-standard-layout 825 // class (or array of such types) [...] 826 if (!FieldRec->isStandardLayout()) 827 data().IsStandardLayout = false; 828 829 // C++0x [class]p7: 830 // A standard-layout class is a class that: 831 // [...] 832 // -- has no base classes of the same type as the first non-static 833 // data member. 834 // We don't want to expend bits in the state of the record decl 835 // tracking whether this is the first non-static data member so we 836 // cheat a bit and use some of the existing state: the empty bit. 837 // Virtual bases and virtual methods make a class non-empty, but they 838 // also make it non-standard-layout so we needn't check here. 839 // A non-empty base class may leave the class standard-layout, but not 840 // if we have arrived here, and have at least one non-static data 841 // member. If IsStandardLayout remains true, then the first non-static 842 // data member must come through here with Empty still true, and Empty 843 // will subsequently be set to false below. 844 if (data().IsStandardLayout && data().Empty) { 845 for (const auto &BI : bases()) { 846 if (Context.hasSameUnqualifiedType(BI.getType(), T)) { 847 data().IsStandardLayout = false; 848 break; 849 } 850 } 851 } 852 853 // Keep track of the presence of mutable fields. 854 if (FieldRec->hasMutableFields()) 855 data().HasMutableFields = true; 856 857 // C++11 [class.copy]p13: 858 // If the implicitly-defined constructor would satisfy the 859 // requirements of a constexpr constructor, the implicitly-defined 860 // constructor is constexpr. 861 // C++11 [dcl.constexpr]p4: 862 // -- every constructor involved in initializing non-static data 863 // members [...] shall be a constexpr constructor 864 if (!Field->hasInClassInitializer() && 865 !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) 866 // The standard requires any in-class initializer to be a constant 867 // expression. We consider this to be a defect. 868 data().DefaultedDefaultConstructorIsConstexpr = false; 869 870 // C++11 [class.copy]p8: 871 // The implicitly-declared copy constructor for a class X will have 872 // the form 'X::X(const X&)' if [...] for all the non-static data 873 // members of X that are of a class type M (or array thereof), each 874 // such class type has a copy constructor whose first parameter is 875 // of type 'const M&' or 'const volatile M&'. 876 if (!FieldRec->hasCopyConstructorWithConstParam()) 877 data().ImplicitCopyConstructorHasConstParam = false; 878 879 // C++11 [class.copy]p18: 880 // The implicitly-declared copy assignment oeprator for a class X will 881 // have the form 'X& X::operator=(const X&)' if [...] for all the 882 // non-static data members of X that are of a class type M (or array 883 // thereof), each such class type has a copy assignment operator whose 884 // parameter is of type 'const M&', 'const volatile M&' or 'M'. 885 if (!FieldRec->hasCopyAssignmentWithConstParam()) 886 data().ImplicitCopyAssignmentHasConstParam = false; 887 888 if (FieldRec->hasUninitializedReferenceMember() && 889 !Field->hasInClassInitializer()) 890 data().HasUninitializedReferenceMember = true; 891 892 // C++11 [class.union]p8, DR1460: 893 // a non-static data member of an anonymous union that is a member of 894 // X is also a variant member of X. 895 if (FieldRec->hasVariantMembers() && 896 Field->isAnonymousStructOrUnion()) 897 data().HasVariantMembers = true; 898 } 899 } else { 900 // Base element type of field is a non-class type. 901 if (!T->isLiteralType(Context) || 902 (!Field->hasInClassInitializer() && !isUnion())) 903 data().DefaultedDefaultConstructorIsConstexpr = false; 904 905 // C++11 [class.copy]p23: 906 // A defaulted copy/move assignment operator for a class X is defined 907 // as deleted if X has: 908 // -- a non-static data member of const non-class type (or array 909 // thereof) 910 if (T.isConstQualified()) 911 data().DefaultedMoveAssignmentIsDeleted = true; 912 } 913 914 // C++0x [class]p7: 915 // A standard-layout class is a class that: 916 // [...] 917 // -- either has no non-static data members in the most derived 918 // class and at most one base class with non-static data members, 919 // or has no base classes with non-static data members, and 920 // At this point we know that we have a non-static data member, so the last 921 // clause holds. 922 if (!data().HasNoNonEmptyBases) 923 data().IsStandardLayout = false; 924 925 // If this is not a zero-length bit-field, then the class is not empty. 926 if (data().Empty) { 927 if (!Field->isBitField() || 928 (!Field->getBitWidth()->isTypeDependent() && 929 !Field->getBitWidth()->isValueDependent() && 930 Field->getBitWidthValue(Context) != 0)) 931 data().Empty = false; 932 } 933 } 934 935 // Handle using declarations of conversion functions. 936 if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) { 937 if (Shadow->getDeclName().getNameKind() 938 == DeclarationName::CXXConversionFunctionName) { 939 ASTContext &Ctx = getASTContext(); 940 data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess()); 941 } 942 } 943 } 944 945 void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { 946 assert(!D->isImplicit() && !D->isUserProvided()); 947 948 // The kind of special member this declaration is, if any. 949 unsigned SMKind = 0; 950 951 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 952 if (Constructor->isDefaultConstructor()) { 953 SMKind |= SMF_DefaultConstructor; 954 if (Constructor->isConstexpr()) 955 data().HasConstexprDefaultConstructor = true; 956 } 957 if (Constructor->isCopyConstructor()) 958 SMKind |= SMF_CopyConstructor; 959 else if (Constructor->isMoveConstructor()) 960 SMKind |= SMF_MoveConstructor; 961 else if (Constructor->isConstexpr()) 962 // We may now know that the constructor is constexpr. 963 data().HasConstexprNonCopyMoveConstructor = true; 964 } else if (isa<CXXDestructorDecl>(D)) { 965 SMKind |= SMF_Destructor; 966 if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted()) 967 data().HasIrrelevantDestructor = false; 968 } else if (D->isCopyAssignmentOperator()) 969 SMKind |= SMF_CopyAssignment; 970 else if (D->isMoveAssignmentOperator()) 971 SMKind |= SMF_MoveAssignment; 972 973 // Update which trivial / non-trivial special members we have. 974 // addedMember will have skipped this step for this member. 975 if (D->isTrivial()) 976 data().HasTrivialSpecialMembers |= SMKind; 977 else 978 data().DeclaredNonTrivialSpecialMembers |= SMKind; 979 } 980 981 bool CXXRecordDecl::isCLike() const { 982 if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || 983 !TemplateOrInstantiation.isNull()) 984 return false; 985 if (!hasDefinition()) 986 return true; 987 988 return isPOD() && data().HasOnlyCMembers; 989 } 990 991 bool CXXRecordDecl::isGenericLambda() const { 992 if (!isLambda()) return false; 993 return getLambdaData().IsGenericLambda; 994 } 995 996 CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const { 997 if (!isLambda()) return nullptr; 998 DeclarationName Name = 999 getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); 1000 DeclContext::lookup_result Calls = lookup(Name); 1001 1002 assert(!Calls.empty() && "Missing lambda call operator!"); 1003 assert(Calls.size() == 1 && "More than one lambda call operator!"); 1004 1005 NamedDecl *CallOp = Calls.front(); 1006 if (FunctionTemplateDecl *CallOpTmpl = 1007 dyn_cast<FunctionTemplateDecl>(CallOp)) 1008 return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl()); 1009 1010 return cast<CXXMethodDecl>(CallOp); 1011 } 1012 1013 CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { 1014 if (!isLambda()) return nullptr; 1015 DeclarationName Name = 1016 &getASTContext().Idents.get(getLambdaStaticInvokerName()); 1017 DeclContext::lookup_result Invoker = lookup(Name); 1018 if (Invoker.empty()) return nullptr; 1019 assert(Invoker.size() == 1 && "More than one static invoker operator!"); 1020 NamedDecl *InvokerFun = Invoker.front(); 1021 if (FunctionTemplateDecl *InvokerTemplate = 1022 dyn_cast<FunctionTemplateDecl>(InvokerFun)) 1023 return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl()); 1024 1025 return cast<CXXMethodDecl>(InvokerFun); 1026 } 1027 1028 void CXXRecordDecl::getCaptureFields( 1029 llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, 1030 FieldDecl *&ThisCapture) const { 1031 Captures.clear(); 1032 ThisCapture = nullptr; 1033 1034 LambdaDefinitionData &Lambda = getLambdaData(); 1035 RecordDecl::field_iterator Field = field_begin(); 1036 for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; 1037 C != CEnd; ++C, ++Field) { 1038 if (C->capturesThis()) 1039 ThisCapture = *Field; 1040 else if (C->capturesVariable()) 1041 Captures[C->getCapturedVar()] = *Field; 1042 } 1043 assert(Field == field_end()); 1044 } 1045 1046 TemplateParameterList * 1047 CXXRecordDecl::getGenericLambdaTemplateParameterList() const { 1048 if (!isLambda()) return nullptr; 1049 CXXMethodDecl *CallOp = getLambdaCallOperator(); 1050 if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate()) 1051 return Tmpl->getTemplateParameters(); 1052 return nullptr; 1053 } 1054 1055 static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { 1056 QualType T = 1057 cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction()) 1058 ->getConversionType(); 1059 return Context.getCanonicalType(T); 1060 } 1061 1062 /// Collect the visible conversions of a base class. 1063 /// 1064 /// \param Record a base class of the class we're considering 1065 /// \param InVirtual whether this base class is a virtual base (or a base 1066 /// of a virtual base) 1067 /// \param Access the access along the inheritance path to this base 1068 /// \param ParentHiddenTypes the conversions provided by the inheritors 1069 /// of this base 1070 /// \param Output the set to which to add conversions from non-virtual bases 1071 /// \param VOutput the set to which to add conversions from virtual bases 1072 /// \param HiddenVBaseCs the set of conversions which were hidden in a 1073 /// virtual base along some inheritance path 1074 static void CollectVisibleConversions(ASTContext &Context, 1075 CXXRecordDecl *Record, 1076 bool InVirtual, 1077 AccessSpecifier Access, 1078 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, 1079 ASTUnresolvedSet &Output, 1080 UnresolvedSetImpl &VOutput, 1081 llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { 1082 // The set of types which have conversions in this class or its 1083 // subclasses. As an optimization, we don't copy the derived set 1084 // unless it might change. 1085 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; 1086 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; 1087 1088 // Collect the direct conversions and figure out which conversions 1089 // will be hidden in the subclasses. 1090 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); 1091 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); 1092 if (ConvI != ConvE) { 1093 HiddenTypesBuffer = ParentHiddenTypes; 1094 HiddenTypes = &HiddenTypesBuffer; 1095 1096 for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { 1097 CanQualType ConvType(GetConversionType(Context, I.getDecl())); 1098 bool Hidden = ParentHiddenTypes.count(ConvType); 1099 if (!Hidden) 1100 HiddenTypesBuffer.insert(ConvType); 1101 1102 // If this conversion is hidden and we're in a virtual base, 1103 // remember that it's hidden along some inheritance path. 1104 if (Hidden && InVirtual) 1105 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); 1106 1107 // If this conversion isn't hidden, add it to the appropriate output. 1108 else if (!Hidden) { 1109 AccessSpecifier IAccess 1110 = CXXRecordDecl::MergeAccess(Access, I.getAccess()); 1111 1112 if (InVirtual) 1113 VOutput.addDecl(I.getDecl(), IAccess); 1114 else 1115 Output.addDecl(Context, I.getDecl(), IAccess); 1116 } 1117 } 1118 } 1119 1120 // Collect information recursively from any base classes. 1121 for (const auto &I : Record->bases()) { 1122 const RecordType *RT = I.getType()->getAs<RecordType>(); 1123 if (!RT) continue; 1124 1125 AccessSpecifier BaseAccess 1126 = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); 1127 bool BaseInVirtual = InVirtual || I.isVirtual(); 1128 1129 CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); 1130 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, 1131 *HiddenTypes, Output, VOutput, HiddenVBaseCs); 1132 } 1133 } 1134 1135 /// Collect the visible conversions of a class. 1136 /// 1137 /// This would be extremely straightforward if it weren't for virtual 1138 /// bases. It might be worth special-casing that, really. 1139 static void CollectVisibleConversions(ASTContext &Context, 1140 CXXRecordDecl *Record, 1141 ASTUnresolvedSet &Output) { 1142 // The collection of all conversions in virtual bases that we've 1143 // found. These will be added to the output as long as they don't 1144 // appear in the hidden-conversions set. 1145 UnresolvedSet<8> VBaseCs; 1146 1147 // The set of conversions in virtual bases that we've determined to 1148 // be hidden. 1149 llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; 1150 1151 // The set of types hidden by classes derived from this one. 1152 llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; 1153 1154 // Go ahead and collect the direct conversions and add them to the 1155 // hidden-types set. 1156 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); 1157 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); 1158 Output.append(Context, ConvI, ConvE); 1159 for (; ConvI != ConvE; ++ConvI) 1160 HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); 1161 1162 // Recursively collect conversions from base classes. 1163 for (const auto &I : Record->bases()) { 1164 const RecordType *RT = I.getType()->getAs<RecordType>(); 1165 if (!RT) continue; 1166 1167 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), 1168 I.isVirtual(), I.getAccessSpecifier(), 1169 HiddenTypes, Output, VBaseCs, HiddenVBaseCs); 1170 } 1171 1172 // Add any unhidden conversions provided by virtual bases. 1173 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); 1174 I != E; ++I) { 1175 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) 1176 Output.addDecl(Context, I.getDecl(), I.getAccess()); 1177 } 1178 } 1179 1180 /// getVisibleConversionFunctions - get all conversion functions visible 1181 /// in current class; including conversion function templates. 1182 llvm::iterator_range<CXXRecordDecl::conversion_iterator> 1183 CXXRecordDecl::getVisibleConversionFunctions() { 1184 ASTContext &Ctx = getASTContext(); 1185 1186 ASTUnresolvedSet *Set; 1187 if (bases_begin() == bases_end()) { 1188 // If root class, all conversions are visible. 1189 Set = &data().Conversions.get(Ctx); 1190 } else { 1191 Set = &data().VisibleConversions.get(Ctx); 1192 // If visible conversion list is not evaluated, evaluate it. 1193 if (!data().ComputedVisibleConversions) { 1194 CollectVisibleConversions(Ctx, this, *Set); 1195 data().ComputedVisibleConversions = true; 1196 } 1197 } 1198 return llvm::make_range(Set->begin(), Set->end()); 1199 } 1200 1201 void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { 1202 // This operation is O(N) but extremely rare. Sema only uses it to 1203 // remove UsingShadowDecls in a class that were followed by a direct 1204 // declaration, e.g.: 1205 // class A : B { 1206 // using B::operator int; 1207 // operator int(); 1208 // }; 1209 // This is uncommon by itself and even more uncommon in conjunction 1210 // with sufficiently large numbers of directly-declared conversions 1211 // that asymptotic behavior matters. 1212 1213 ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext()); 1214 for (unsigned I = 0, E = Convs.size(); I != E; ++I) { 1215 if (Convs[I].getDecl() == ConvDecl) { 1216 Convs.erase(I); 1217 assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() 1218 && "conversion was found multiple times in unresolved set"); 1219 return; 1220 } 1221 } 1222 1223 llvm_unreachable("conversion not found in set!"); 1224 } 1225 1226 CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { 1227 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1228 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); 1229 1230 return nullptr; 1231 } 1232 1233 MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { 1234 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); 1235 } 1236 1237 void 1238 CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, 1239 TemplateSpecializationKind TSK) { 1240 assert(TemplateOrInstantiation.isNull() && 1241 "Previous template or instantiation?"); 1242 assert(!isa<ClassTemplatePartialSpecializationDecl>(this)); 1243 TemplateOrInstantiation 1244 = new (getASTContext()) MemberSpecializationInfo(RD, TSK); 1245 } 1246 1247 ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const { 1248 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>(); 1249 } 1250 1251 void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { 1252 TemplateOrInstantiation = Template; 1253 } 1254 1255 TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ 1256 if (const ClassTemplateSpecializationDecl *Spec 1257 = dyn_cast<ClassTemplateSpecializationDecl>(this)) 1258 return Spec->getSpecializationKind(); 1259 1260 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1261 return MSInfo->getTemplateSpecializationKind(); 1262 1263 return TSK_Undeclared; 1264 } 1265 1266 void 1267 CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 1268 if (ClassTemplateSpecializationDecl *Spec 1269 = dyn_cast<ClassTemplateSpecializationDecl>(this)) { 1270 Spec->setSpecializationKind(TSK); 1271 return; 1272 } 1273 1274 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { 1275 MSInfo->setTemplateSpecializationKind(TSK); 1276 return; 1277 } 1278 1279 llvm_unreachable("Not a class template or member class specialization"); 1280 } 1281 1282 const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { 1283 // If it's a class template specialization, find the template or partial 1284 // specialization from which it was instantiated. 1285 if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) { 1286 auto From = TD->getInstantiatedFrom(); 1287 if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) { 1288 while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { 1289 if (NewCTD->isMemberSpecialization()) 1290 break; 1291 CTD = NewCTD; 1292 } 1293 return CTD->getTemplatedDecl()->getDefinition(); 1294 } 1295 if (auto *CTPSD = 1296 From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { 1297 while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { 1298 if (NewCTPSD->isMemberSpecialization()) 1299 break; 1300 CTPSD = NewCTPSD; 1301 } 1302 return CTPSD->getDefinition(); 1303 } 1304 } 1305 1306 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { 1307 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { 1308 const CXXRecordDecl *RD = this; 1309 while (auto *NewRD = RD->getInstantiatedFromMemberClass()) 1310 RD = NewRD; 1311 return RD->getDefinition(); 1312 } 1313 } 1314 1315 assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) && 1316 "couldn't find pattern for class template instantiation"); 1317 return nullptr; 1318 } 1319 1320 CXXDestructorDecl *CXXRecordDecl::getDestructor() const { 1321 ASTContext &Context = getASTContext(); 1322 QualType ClassType = Context.getTypeDeclType(this); 1323 1324 DeclarationName Name 1325 = Context.DeclarationNames.getCXXDestructorName( 1326 Context.getCanonicalType(ClassType)); 1327 1328 DeclContext::lookup_result R = lookup(Name); 1329 if (R.empty()) 1330 return nullptr; 1331 1332 CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(R.front()); 1333 return Dtor; 1334 } 1335 1336 bool CXXRecordDecl::isAnyDestructorNoReturn() const { 1337 // Destructor is noreturn. 1338 if (const CXXDestructorDecl *Destructor = getDestructor()) 1339 if (Destructor->isNoReturn()) 1340 return true; 1341 1342 // Check base classes destructor for noreturn. 1343 for (const auto &Base : bases()) 1344 if (Base.getType()->getAsCXXRecordDecl()->isAnyDestructorNoReturn()) 1345 return true; 1346 1347 // Check fields for noreturn. 1348 for (const auto *Field : fields()) 1349 if (const CXXRecordDecl *RD = 1350 Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()) 1351 if (RD->isAnyDestructorNoReturn()) 1352 return true; 1353 1354 // All destructors are not noreturn. 1355 return false; 1356 } 1357 1358 void CXXRecordDecl::completeDefinition() { 1359 completeDefinition(nullptr); 1360 } 1361 1362 void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { 1363 RecordDecl::completeDefinition(); 1364 1365 // If the class may be abstract (but hasn't been marked as such), check for 1366 // any pure final overriders. 1367 if (mayBeAbstract()) { 1368 CXXFinalOverriderMap MyFinalOverriders; 1369 if (!FinalOverriders) { 1370 getFinalOverriders(MyFinalOverriders); 1371 FinalOverriders = &MyFinalOverriders; 1372 } 1373 1374 bool Done = false; 1375 for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), 1376 MEnd = FinalOverriders->end(); 1377 M != MEnd && !Done; ++M) { 1378 for (OverridingMethods::iterator SO = M->second.begin(), 1379 SOEnd = M->second.end(); 1380 SO != SOEnd && !Done; ++SO) { 1381 assert(SO->second.size() > 0 && 1382 "All virtual functions have overridding virtual functions"); 1383 1384 // C++ [class.abstract]p4: 1385 // A class is abstract if it contains or inherits at least one 1386 // pure virtual function for which the final overrider is pure 1387 // virtual. 1388 if (SO->second.front().Method->isPure()) { 1389 data().Abstract = true; 1390 Done = true; 1391 break; 1392 } 1393 } 1394 } 1395 } 1396 1397 // Set access bits correctly on the directly-declared conversions. 1398 for (conversion_iterator I = conversion_begin(), E = conversion_end(); 1399 I != E; ++I) 1400 I.setAccess((*I)->getAccess()); 1401 } 1402 1403 bool CXXRecordDecl::mayBeAbstract() const { 1404 if (data().Abstract || isInvalidDecl() || !data().Polymorphic || 1405 isDependentContext()) 1406 return false; 1407 1408 for (const auto &B : bases()) { 1409 CXXRecordDecl *BaseDecl 1410 = cast<CXXRecordDecl>(B.getType()->getAs<RecordType>()->getDecl()); 1411 if (BaseDecl->isAbstract()) 1412 return true; 1413 } 1414 1415 return false; 1416 } 1417 1418 void CXXMethodDecl::anchor() { } 1419 1420 bool CXXMethodDecl::isStatic() const { 1421 const CXXMethodDecl *MD = getCanonicalDecl(); 1422 1423 if (MD->getStorageClass() == SC_Static) 1424 return true; 1425 1426 OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator(); 1427 return isStaticOverloadedOperator(OOK); 1428 } 1429 1430 static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, 1431 const CXXMethodDecl *BaseMD) { 1432 for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(), 1433 E = DerivedMD->end_overridden_methods(); I != E; ++I) { 1434 const CXXMethodDecl *MD = *I; 1435 if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) 1436 return true; 1437 if (recursivelyOverrides(MD, BaseMD)) 1438 return true; 1439 } 1440 return false; 1441 } 1442 1443 CXXMethodDecl * 1444 CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, 1445 bool MayBeBase) { 1446 if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) 1447 return this; 1448 1449 // Lookup doesn't work for destructors, so handle them separately. 1450 if (isa<CXXDestructorDecl>(this)) { 1451 CXXMethodDecl *MD = RD->getDestructor(); 1452 if (MD) { 1453 if (recursivelyOverrides(MD, this)) 1454 return MD; 1455 if (MayBeBase && recursivelyOverrides(this, MD)) 1456 return MD; 1457 } 1458 return nullptr; 1459 } 1460 1461 for (auto *ND : RD->lookup(getDeclName())) { 1462 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND); 1463 if (!MD) 1464 continue; 1465 if (recursivelyOverrides(MD, this)) 1466 return MD; 1467 if (MayBeBase && recursivelyOverrides(this, MD)) 1468 return MD; 1469 } 1470 1471 for (const auto &I : RD->bases()) { 1472 const RecordType *RT = I.getType()->getAs<RecordType>(); 1473 if (!RT) 1474 continue; 1475 const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); 1476 CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); 1477 if (T) 1478 return T; 1479 } 1480 1481 return nullptr; 1482 } 1483 1484 CXXMethodDecl * 1485 CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1486 SourceLocation StartLoc, 1487 const DeclarationNameInfo &NameInfo, 1488 QualType T, TypeSourceInfo *TInfo, 1489 StorageClass SC, bool isInline, 1490 bool isConstexpr, SourceLocation EndLocation) { 1491 return new (C, RD) CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, 1492 T, TInfo, SC, isInline, isConstexpr, 1493 EndLocation); 1494 } 1495 1496 CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1497 return new (C, ID) CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(), 1498 DeclarationNameInfo(), QualType(), nullptr, 1499 SC_None, false, false, SourceLocation()); 1500 } 1501 1502 bool CXXMethodDecl::isUsualDeallocationFunction() const { 1503 if (getOverloadedOperator() != OO_Delete && 1504 getOverloadedOperator() != OO_Array_Delete) 1505 return false; 1506 1507 // C++ [basic.stc.dynamic.deallocation]p2: 1508 // A template instance is never a usual deallocation function, 1509 // regardless of its signature. 1510 if (getPrimaryTemplate()) 1511 return false; 1512 1513 // C++ [basic.stc.dynamic.deallocation]p2: 1514 // If a class T has a member deallocation function named operator delete 1515 // with exactly one parameter, then that function is a usual (non-placement) 1516 // deallocation function. [...] 1517 if (getNumParams() == 1) 1518 return true; 1519 1520 // C++ [basic.stc.dynamic.deallocation]p2: 1521 // [...] If class T does not declare such an operator delete but does 1522 // declare a member deallocation function named operator delete with 1523 // exactly two parameters, the second of which has type std::size_t (18.1), 1524 // then this function is a usual deallocation function. 1525 ASTContext &Context = getASTContext(); 1526 if (getNumParams() != 2 || 1527 !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), 1528 Context.getSizeType())) 1529 return false; 1530 1531 // This function is a usual deallocation function if there are no 1532 // single-parameter deallocation functions of the same kind. 1533 DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); 1534 for (DeclContext::lookup_result::iterator I = R.begin(), E = R.end(); 1535 I != E; ++I) { 1536 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) 1537 if (FD->getNumParams() == 1) 1538 return false; 1539 } 1540 1541 return true; 1542 } 1543 1544 bool CXXMethodDecl::isCopyAssignmentOperator() const { 1545 // C++0x [class.copy]p17: 1546 // A user-declared copy assignment operator X::operator= is a non-static 1547 // non-template member function of class X with exactly one parameter of 1548 // type X, X&, const X&, volatile X& or const volatile X&. 1549 if (/*operator=*/getOverloadedOperator() != OO_Equal || 1550 /*non-static*/ isStatic() || 1551 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() || 1552 getNumParams() != 1) 1553 return false; 1554 1555 QualType ParamType = getParamDecl(0)->getType(); 1556 if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) 1557 ParamType = Ref->getPointeeType(); 1558 1559 ASTContext &Context = getASTContext(); 1560 QualType ClassType 1561 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1562 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1563 } 1564 1565 bool CXXMethodDecl::isMoveAssignmentOperator() const { 1566 // C++0x [class.copy]p19: 1567 // A user-declared move assignment operator X::operator= is a non-static 1568 // non-template member function of class X with exactly one parameter of type 1569 // X&&, const X&&, volatile X&&, or const volatile X&&. 1570 if (getOverloadedOperator() != OO_Equal || isStatic() || 1571 getPrimaryTemplate() || getDescribedFunctionTemplate() || 1572 getNumParams() != 1) 1573 return false; 1574 1575 QualType ParamType = getParamDecl(0)->getType(); 1576 if (!isa<RValueReferenceType>(ParamType)) 1577 return false; 1578 ParamType = ParamType->getPointeeType(); 1579 1580 ASTContext &Context = getASTContext(); 1581 QualType ClassType 1582 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1583 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1584 } 1585 1586 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { 1587 assert(MD->isCanonicalDecl() && "Method is not canonical!"); 1588 assert(!MD->getParent()->isDependentContext() && 1589 "Can't add an overridden method to a class template!"); 1590 assert(MD->isVirtual() && "Method is not virtual!"); 1591 1592 getASTContext().addOverriddenMethod(this, MD); 1593 } 1594 1595 CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { 1596 if (isa<CXXConstructorDecl>(this)) return nullptr; 1597 return getASTContext().overridden_methods_begin(this); 1598 } 1599 1600 CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { 1601 if (isa<CXXConstructorDecl>(this)) return nullptr; 1602 return getASTContext().overridden_methods_end(this); 1603 } 1604 1605 unsigned CXXMethodDecl::size_overridden_methods() const { 1606 if (isa<CXXConstructorDecl>(this)) return 0; 1607 return getASTContext().overridden_methods_size(this); 1608 } 1609 1610 QualType CXXMethodDecl::getThisType(ASTContext &C) const { 1611 // C++ 9.3.2p1: The type of this in a member function of a class X is X*. 1612 // If the member function is declared const, the type of this is const X*, 1613 // if the member function is declared volatile, the type of this is 1614 // volatile X*, and if the member function is declared const volatile, 1615 // the type of this is const volatile X*. 1616 1617 assert(isInstance() && "No 'this' for static methods!"); 1618 1619 QualType ClassTy = C.getTypeDeclType(getParent()); 1620 ClassTy = C.getQualifiedType(ClassTy, 1621 Qualifiers::fromCVRMask(getTypeQualifiers())); 1622 return C.getPointerType(ClassTy); 1623 } 1624 1625 bool CXXMethodDecl::hasInlineBody() const { 1626 // If this function is a template instantiation, look at the template from 1627 // which it was instantiated. 1628 const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); 1629 if (!CheckFn) 1630 CheckFn = this; 1631 1632 const FunctionDecl *fn; 1633 return CheckFn->hasBody(fn) && !fn->isOutOfLine(); 1634 } 1635 1636 bool CXXMethodDecl::isLambdaStaticInvoker() const { 1637 const CXXRecordDecl *P = getParent(); 1638 if (P->isLambda()) { 1639 if (const CXXMethodDecl *StaticInvoker = P->getLambdaStaticInvoker()) { 1640 if (StaticInvoker == this) return true; 1641 if (P->isGenericLambda() && this->isFunctionTemplateSpecialization()) 1642 return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl(); 1643 } 1644 } 1645 return false; 1646 } 1647 1648 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1649 TypeSourceInfo *TInfo, bool IsVirtual, 1650 SourceLocation L, Expr *Init, 1651 SourceLocation R, 1652 SourceLocation EllipsisLoc) 1653 : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 1654 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 1655 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1656 { 1657 } 1658 1659 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1660 FieldDecl *Member, 1661 SourceLocation MemberLoc, 1662 SourceLocation L, Expr *Init, 1663 SourceLocation R) 1664 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1665 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1666 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1667 { 1668 } 1669 1670 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1671 IndirectFieldDecl *Member, 1672 SourceLocation MemberLoc, 1673 SourceLocation L, Expr *Init, 1674 SourceLocation R) 1675 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1676 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1677 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1678 { 1679 } 1680 1681 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1682 TypeSourceInfo *TInfo, 1683 SourceLocation L, Expr *Init, 1684 SourceLocation R) 1685 : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init), 1686 LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false), 1687 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1688 { 1689 } 1690 1691 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1692 FieldDecl *Member, 1693 SourceLocation MemberLoc, 1694 SourceLocation L, Expr *Init, 1695 SourceLocation R, 1696 VarDecl **Indices, 1697 unsigned NumIndices) 1698 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1699 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1700 IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) 1701 { 1702 std::uninitialized_copy(Indices, Indices + NumIndices, 1703 getTrailingObjects<VarDecl *>()); 1704 } 1705 1706 CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, 1707 FieldDecl *Member, 1708 SourceLocation MemberLoc, 1709 SourceLocation L, Expr *Init, 1710 SourceLocation R, 1711 VarDecl **Indices, 1712 unsigned NumIndices) { 1713 void *Mem = Context.Allocate(totalSizeToAlloc<VarDecl *>(NumIndices), 1714 llvm::alignOf<CXXCtorInitializer>()); 1715 return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, 1716 Indices, NumIndices); 1717 } 1718 1719 TypeLoc CXXCtorInitializer::getBaseClassLoc() const { 1720 if (isBaseInitializer()) 1721 return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); 1722 else 1723 return TypeLoc(); 1724 } 1725 1726 const Type *CXXCtorInitializer::getBaseClass() const { 1727 if (isBaseInitializer()) 1728 return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); 1729 else 1730 return nullptr; 1731 } 1732 1733 SourceLocation CXXCtorInitializer::getSourceLocation() const { 1734 if (isInClassMemberInitializer()) 1735 return getAnyMember()->getLocation(); 1736 1737 if (isAnyMemberInitializer()) 1738 return getMemberLocation(); 1739 1740 if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>()) 1741 return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); 1742 1743 return SourceLocation(); 1744 } 1745 1746 SourceRange CXXCtorInitializer::getSourceRange() const { 1747 if (isInClassMemberInitializer()) { 1748 FieldDecl *D = getAnyMember(); 1749 if (Expr *I = D->getInClassInitializer()) 1750 return I->getSourceRange(); 1751 return SourceRange(); 1752 } 1753 1754 return SourceRange(getSourceLocation(), getRParenLoc()); 1755 } 1756 1757 void CXXConstructorDecl::anchor() { } 1758 1759 CXXConstructorDecl * 1760 CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1761 return new (C, ID) CXXConstructorDecl(C, nullptr, SourceLocation(), 1762 DeclarationNameInfo(), QualType(), 1763 nullptr, false, false, false, false); 1764 } 1765 1766 CXXConstructorDecl * 1767 CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1768 SourceLocation StartLoc, 1769 const DeclarationNameInfo &NameInfo, 1770 QualType T, TypeSourceInfo *TInfo, 1771 bool isExplicit, bool isInline, 1772 bool isImplicitlyDeclared, bool isConstexpr) { 1773 assert(NameInfo.getName().getNameKind() 1774 == DeclarationName::CXXConstructorName && 1775 "Name must refer to a constructor"); 1776 return new (C, RD) CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1777 isExplicit, isInline, 1778 isImplicitlyDeclared, isConstexpr); 1779 } 1780 1781 CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { 1782 return CtorInitializers.get(getASTContext().getExternalSource()); 1783 } 1784 1785 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { 1786 assert(isDelegatingConstructor() && "Not a delegating constructor!"); 1787 Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); 1788 if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E)) 1789 return Construct->getConstructor(); 1790 1791 return nullptr; 1792 } 1793 1794 bool CXXConstructorDecl::isDefaultConstructor() const { 1795 // C++ [class.ctor]p5: 1796 // A default constructor for a class X is a constructor of class 1797 // X that can be called without an argument. 1798 return (getNumParams() == 0) || 1799 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); 1800 } 1801 1802 bool 1803 CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { 1804 return isCopyOrMoveConstructor(TypeQuals) && 1805 getParamDecl(0)->getType()->isLValueReferenceType(); 1806 } 1807 1808 bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { 1809 return isCopyOrMoveConstructor(TypeQuals) && 1810 getParamDecl(0)->getType()->isRValueReferenceType(); 1811 } 1812 1813 /// \brief Determine whether this is a copy or move constructor. 1814 bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { 1815 // C++ [class.copy]p2: 1816 // A non-template constructor for class X is a copy constructor 1817 // if its first parameter is of type X&, const X&, volatile X& or 1818 // const volatile X&, and either there are no other parameters 1819 // or else all other parameters have default arguments (8.3.6). 1820 // C++0x [class.copy]p3: 1821 // A non-template constructor for class X is a move constructor if its 1822 // first parameter is of type X&&, const X&&, volatile X&&, or 1823 // const volatile X&&, and either there are no other parameters or else 1824 // all other parameters have default arguments. 1825 if ((getNumParams() < 1) || 1826 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1827 (getPrimaryTemplate() != nullptr) || 1828 (getDescribedFunctionTemplate() != nullptr)) 1829 return false; 1830 1831 const ParmVarDecl *Param = getParamDecl(0); 1832 1833 // Do we have a reference type? 1834 const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); 1835 if (!ParamRefType) 1836 return false; 1837 1838 // Is it a reference to our class type? 1839 ASTContext &Context = getASTContext(); 1840 1841 CanQualType PointeeType 1842 = Context.getCanonicalType(ParamRefType->getPointeeType()); 1843 CanQualType ClassTy 1844 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1845 if (PointeeType.getUnqualifiedType() != ClassTy) 1846 return false; 1847 1848 // FIXME: other qualifiers? 1849 1850 // We have a copy or move constructor. 1851 TypeQuals = PointeeType.getCVRQualifiers(); 1852 return true; 1853 } 1854 1855 bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { 1856 // C++ [class.conv.ctor]p1: 1857 // A constructor declared without the function-specifier explicit 1858 // that can be called with a single parameter specifies a 1859 // conversion from the type of its first parameter to the type of 1860 // its class. Such a constructor is called a converting 1861 // constructor. 1862 if (isExplicit() && !AllowExplicit) 1863 return false; 1864 1865 return (getNumParams() == 0 && 1866 getType()->getAs<FunctionProtoType>()->isVariadic()) || 1867 (getNumParams() == 1) || 1868 (getNumParams() > 1 && 1869 (getParamDecl(1)->hasDefaultArg() || 1870 getParamDecl(1)->isParameterPack())); 1871 } 1872 1873 bool CXXConstructorDecl::isSpecializationCopyingObject() const { 1874 if ((getNumParams() < 1) || 1875 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1876 (getDescribedFunctionTemplate() != nullptr)) 1877 return false; 1878 1879 const ParmVarDecl *Param = getParamDecl(0); 1880 1881 ASTContext &Context = getASTContext(); 1882 CanQualType ParamType = Context.getCanonicalType(Param->getType()); 1883 1884 // Is it the same as our our class type? 1885 CanQualType ClassTy 1886 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1887 if (ParamType.getUnqualifiedType() != ClassTy) 1888 return false; 1889 1890 return true; 1891 } 1892 1893 const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { 1894 // Hack: we store the inherited constructor in the overridden method table 1895 method_iterator It = getASTContext().overridden_methods_begin(this); 1896 if (It == getASTContext().overridden_methods_end(this)) 1897 return nullptr; 1898 1899 return cast<CXXConstructorDecl>(*It); 1900 } 1901 1902 void 1903 CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ 1904 // Hack: we store the inherited constructor in the overridden method table 1905 assert(getASTContext().overridden_methods_size(this) == 0 && 1906 "Base ctor already set."); 1907 getASTContext().addOverriddenMethod(this, BaseCtor); 1908 } 1909 1910 void CXXDestructorDecl::anchor() { } 1911 1912 CXXDestructorDecl * 1913 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1914 return new (C, ID) 1915 CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), 1916 QualType(), nullptr, false, false); 1917 } 1918 1919 CXXDestructorDecl * 1920 CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1921 SourceLocation StartLoc, 1922 const DeclarationNameInfo &NameInfo, 1923 QualType T, TypeSourceInfo *TInfo, 1924 bool isInline, bool isImplicitlyDeclared) { 1925 assert(NameInfo.getName().getNameKind() 1926 == DeclarationName::CXXDestructorName && 1927 "Name must refer to a destructor"); 1928 return new (C, RD) CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1929 isInline, isImplicitlyDeclared); 1930 } 1931 1932 void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD) { 1933 auto *First = cast<CXXDestructorDecl>(getFirstDecl()); 1934 if (OD && !First->OperatorDelete) { 1935 First->OperatorDelete = OD; 1936 if (auto *L = getASTMutationListener()) 1937 L->ResolvedOperatorDelete(First, OD); 1938 } 1939 } 1940 1941 void CXXConversionDecl::anchor() { } 1942 1943 CXXConversionDecl * 1944 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1945 return new (C, ID) CXXConversionDecl(C, nullptr, SourceLocation(), 1946 DeclarationNameInfo(), QualType(), 1947 nullptr, false, false, false, 1948 SourceLocation()); 1949 } 1950 1951 CXXConversionDecl * 1952 CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1953 SourceLocation StartLoc, 1954 const DeclarationNameInfo &NameInfo, 1955 QualType T, TypeSourceInfo *TInfo, 1956 bool isInline, bool isExplicit, 1957 bool isConstexpr, SourceLocation EndLocation) { 1958 assert(NameInfo.getName().getNameKind() 1959 == DeclarationName::CXXConversionFunctionName && 1960 "Name must refer to a conversion function"); 1961 return new (C, RD) CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1962 isInline, isExplicit, isConstexpr, 1963 EndLocation); 1964 } 1965 1966 bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { 1967 return isImplicit() && getParent()->isLambda() && 1968 getConversionType()->isBlockPointerType(); 1969 } 1970 1971 void LinkageSpecDecl::anchor() { } 1972 1973 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, 1974 DeclContext *DC, 1975 SourceLocation ExternLoc, 1976 SourceLocation LangLoc, 1977 LanguageIDs Lang, 1978 bool HasBraces) { 1979 return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces); 1980 } 1981 1982 LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, 1983 unsigned ID) { 1984 return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(), 1985 SourceLocation(), lang_c, false); 1986 } 1987 1988 void UsingDirectiveDecl::anchor() { } 1989 1990 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, 1991 SourceLocation L, 1992 SourceLocation NamespaceLoc, 1993 NestedNameSpecifierLoc QualifierLoc, 1994 SourceLocation IdentLoc, 1995 NamedDecl *Used, 1996 DeclContext *CommonAncestor) { 1997 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) 1998 Used = NS->getOriginalNamespace(); 1999 return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, 2000 IdentLoc, Used, CommonAncestor); 2001 } 2002 2003 UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, 2004 unsigned ID) { 2005 return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(), 2006 SourceLocation(), 2007 NestedNameSpecifierLoc(), 2008 SourceLocation(), nullptr, nullptr); 2009 } 2010 2011 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { 2012 if (NamespaceAliasDecl *NA = 2013 dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) 2014 return NA->getNamespace(); 2015 return cast_or_null<NamespaceDecl>(NominatedNamespace); 2016 } 2017 2018 NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, 2019 SourceLocation StartLoc, SourceLocation IdLoc, 2020 IdentifierInfo *Id, NamespaceDecl *PrevDecl) 2021 : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), 2022 redeclarable_base(C), LocStart(StartLoc), RBraceLoc(), 2023 AnonOrFirstNamespaceAndInline(nullptr, Inline) { 2024 setPreviousDecl(PrevDecl); 2025 2026 if (PrevDecl) 2027 AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); 2028 } 2029 2030 NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, 2031 bool Inline, SourceLocation StartLoc, 2032 SourceLocation IdLoc, IdentifierInfo *Id, 2033 NamespaceDecl *PrevDecl) { 2034 return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, 2035 PrevDecl); 2036 } 2037 2038 NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2039 return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), 2040 SourceLocation(), nullptr, nullptr); 2041 } 2042 2043 NamespaceDecl *NamespaceDecl::getOriginalNamespace() { 2044 if (isFirstDecl()) 2045 return this; 2046 2047 return AnonOrFirstNamespaceAndInline.getPointer(); 2048 } 2049 2050 const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const { 2051 if (isFirstDecl()) 2052 return this; 2053 2054 return AnonOrFirstNamespaceAndInline.getPointer(); 2055 } 2056 2057 bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); } 2058 2059 NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() { 2060 return getNextRedeclaration(); 2061 } 2062 NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() { 2063 return getPreviousDecl(); 2064 } 2065 NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() { 2066 return getMostRecentDecl(); 2067 } 2068 2069 void NamespaceAliasDecl::anchor() { } 2070 2071 NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() { 2072 return getNextRedeclaration(); 2073 } 2074 NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() { 2075 return getPreviousDecl(); 2076 } 2077 NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() { 2078 return getMostRecentDecl(); 2079 } 2080 2081 NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, 2082 SourceLocation UsingLoc, 2083 SourceLocation AliasLoc, 2084 IdentifierInfo *Alias, 2085 NestedNameSpecifierLoc QualifierLoc, 2086 SourceLocation IdentLoc, 2087 NamedDecl *Namespace) { 2088 // FIXME: Preserve the aliased namespace as written. 2089 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) 2090 Namespace = NS->getOriginalNamespace(); 2091 return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, 2092 QualifierLoc, IdentLoc, Namespace); 2093 } 2094 2095 NamespaceAliasDecl * 2096 NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2097 return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(), 2098 SourceLocation(), nullptr, 2099 NestedNameSpecifierLoc(), 2100 SourceLocation(), nullptr); 2101 } 2102 2103 void UsingShadowDecl::anchor() { } 2104 2105 UsingShadowDecl * 2106 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2107 return new (C, ID) UsingShadowDecl(C, nullptr, SourceLocation(), 2108 nullptr, nullptr); 2109 } 2110 2111 UsingDecl *UsingShadowDecl::getUsingDecl() const { 2112 const UsingShadowDecl *Shadow = this; 2113 while (const UsingShadowDecl *NextShadow = 2114 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) 2115 Shadow = NextShadow; 2116 return cast<UsingDecl>(Shadow->UsingOrNextShadow); 2117 } 2118 2119 void UsingDecl::anchor() { } 2120 2121 void UsingDecl::addShadowDecl(UsingShadowDecl *S) { 2122 assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && 2123 "declaration already in set"); 2124 assert(S->getUsingDecl() == this); 2125 2126 if (FirstUsingShadow.getPointer()) 2127 S->UsingOrNextShadow = FirstUsingShadow.getPointer(); 2128 FirstUsingShadow.setPointer(S); 2129 } 2130 2131 void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { 2132 assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && 2133 "declaration not in set"); 2134 assert(S->getUsingDecl() == this); 2135 2136 // Remove S from the shadow decl chain. This is O(n) but hopefully rare. 2137 2138 if (FirstUsingShadow.getPointer() == S) { 2139 FirstUsingShadow.setPointer( 2140 dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); 2141 S->UsingOrNextShadow = this; 2142 return; 2143 } 2144 2145 UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); 2146 while (Prev->UsingOrNextShadow != S) 2147 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); 2148 Prev->UsingOrNextShadow = S->UsingOrNextShadow; 2149 S->UsingOrNextShadow = this; 2150 } 2151 2152 UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, 2153 NestedNameSpecifierLoc QualifierLoc, 2154 const DeclarationNameInfo &NameInfo, 2155 bool HasTypename) { 2156 return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename); 2157 } 2158 2159 UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2160 return new (C, ID) UsingDecl(nullptr, SourceLocation(), 2161 NestedNameSpecifierLoc(), DeclarationNameInfo(), 2162 false); 2163 } 2164 2165 SourceRange UsingDecl::getSourceRange() const { 2166 SourceLocation Begin = isAccessDeclaration() 2167 ? getQualifierLoc().getBeginLoc() : UsingLocation; 2168 return SourceRange(Begin, getNameInfo().getEndLoc()); 2169 } 2170 2171 void UnresolvedUsingValueDecl::anchor() { } 2172 2173 UnresolvedUsingValueDecl * 2174 UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, 2175 SourceLocation UsingLoc, 2176 NestedNameSpecifierLoc QualifierLoc, 2177 const DeclarationNameInfo &NameInfo) { 2178 return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, 2179 QualifierLoc, NameInfo); 2180 } 2181 2182 UnresolvedUsingValueDecl * 2183 UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2184 return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(), 2185 SourceLocation(), 2186 NestedNameSpecifierLoc(), 2187 DeclarationNameInfo()); 2188 } 2189 2190 SourceRange UnresolvedUsingValueDecl::getSourceRange() const { 2191 SourceLocation Begin = isAccessDeclaration() 2192 ? getQualifierLoc().getBeginLoc() : UsingLocation; 2193 return SourceRange(Begin, getNameInfo().getEndLoc()); 2194 } 2195 2196 void UnresolvedUsingTypenameDecl::anchor() { } 2197 2198 UnresolvedUsingTypenameDecl * 2199 UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, 2200 SourceLocation UsingLoc, 2201 SourceLocation TypenameLoc, 2202 NestedNameSpecifierLoc QualifierLoc, 2203 SourceLocation TargetNameLoc, 2204 DeclarationName TargetName) { 2205 return new (C, DC) UnresolvedUsingTypenameDecl( 2206 DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc, 2207 TargetName.getAsIdentifierInfo()); 2208 } 2209 2210 UnresolvedUsingTypenameDecl * 2211 UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2212 return new (C, ID) UnresolvedUsingTypenameDecl( 2213 nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(), 2214 SourceLocation(), nullptr); 2215 } 2216 2217 void StaticAssertDecl::anchor() { } 2218 2219 StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, 2220 SourceLocation StaticAssertLoc, 2221 Expr *AssertExpr, 2222 StringLiteral *Message, 2223 SourceLocation RParenLoc, 2224 bool Failed) { 2225 return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, 2226 RParenLoc, Failed); 2227 } 2228 2229 StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, 2230 unsigned ID) { 2231 return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr, 2232 nullptr, SourceLocation(), false); 2233 } 2234 2235 MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC, 2236 SourceLocation L, DeclarationName N, 2237 QualType T, TypeSourceInfo *TInfo, 2238 SourceLocation StartL, 2239 IdentifierInfo *Getter, 2240 IdentifierInfo *Setter) { 2241 return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter); 2242 } 2243 2244 MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C, 2245 unsigned ID) { 2246 return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(), 2247 DeclarationName(), QualType(), nullptr, 2248 SourceLocation(), nullptr, nullptr); 2249 } 2250 2251 static const char *getAccessName(AccessSpecifier AS) { 2252 switch (AS) { 2253 case AS_none: 2254 llvm_unreachable("Invalid access specifier!"); 2255 case AS_public: 2256 return "public"; 2257 case AS_private: 2258 return "private"; 2259 case AS_protected: 2260 return "protected"; 2261 } 2262 llvm_unreachable("Invalid access specifier!"); 2263 } 2264 2265 const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, 2266 AccessSpecifier AS) { 2267 return DB << getAccessName(AS); 2268 } 2269 2270 const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB, 2271 AccessSpecifier AS) { 2272 return DB << getAccessName(AS); 2273 } 2274