clang API Documentation

DeclCXX.cpp
Go to the documentation of this file.
00001 //===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the C++ related Decl classes.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #include "clang/AST/DeclCXX.h"
00014 #include "clang/AST/ASTContext.h"
00015 #include "clang/AST/ASTLambda.h"
00016 #include "clang/AST/ASTMutationListener.h"
00017 #include "clang/AST/CXXInheritance.h"
00018 #include "clang/AST/DeclTemplate.h"
00019 #include "clang/AST/Expr.h"
00020 #include "clang/AST/ExprCXX.h"
00021 #include "clang/AST/TypeLoc.h"
00022 #include "clang/Basic/IdentifierTable.h"
00023 #include "llvm/ADT/STLExtras.h"
00024 #include "llvm/ADT/SmallPtrSet.h"
00025 using namespace clang;
00026 
00027 //===----------------------------------------------------------------------===//
00028 // Decl Allocation/Deallocation Method Implementations
00029 //===----------------------------------------------------------------------===//
00030 
00031 void AccessSpecDecl::anchor() { }
00032 
00033 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
00034   return new (C, ID) AccessSpecDecl(EmptyShell());
00035 }
00036 
00037 void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
00038   ExternalASTSource *Source = C.getExternalSource();
00039   assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set");
00040   assert(Source && "getFromExternalSource with no external source");
00041 
00042   for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I)
00043     I.setDecl(cast<NamedDecl>(Source->GetExternalDecl(
00044         reinterpret_cast<uintptr_t>(I.getDecl()) >> 2)));
00045   Impl.Decls.setLazy(false);
00046 }
00047 
00048 CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
00049   : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0),
00050     Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
00051     Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true),
00052     HasPrivateFields(false), HasProtectedFields(false), HasPublicFields(false),
00053     HasMutableFields(false), HasVariantMembers(false), HasOnlyCMembers(true),
00054     HasInClassInitializer(false), HasUninitializedReferenceMember(false),
00055     NeedOverloadResolutionForMoveConstructor(false),
00056     NeedOverloadResolutionForMoveAssignment(false),
00057     NeedOverloadResolutionForDestructor(false),
00058     DefaultedMoveConstructorIsDeleted(false),
00059     DefaultedMoveAssignmentIsDeleted(false),
00060     DefaultedDestructorIsDeleted(false),
00061     HasTrivialSpecialMembers(SMF_All),
00062     DeclaredNonTrivialSpecialMembers(0),
00063     HasIrrelevantDestructor(true),
00064     HasConstexprNonCopyMoveConstructor(false),
00065     DefaultedDefaultConstructorIsConstexpr(true),
00066     HasConstexprDefaultConstructor(false),
00067     HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false),
00068     UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0),
00069     ImplicitCopyConstructorHasConstParam(true),
00070     ImplicitCopyAssignmentHasConstParam(true),
00071     HasDeclaredCopyConstructorWithConstParam(false),
00072     HasDeclaredCopyAssignmentWithConstParam(false),
00073     IsLambda(false), IsParsingBaseSpecifiers(false), NumBases(0), NumVBases(0),
00074     Bases(), VBases(),
00075     Definition(D), FirstFriend() {
00076 }
00077 
00078 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
00079   return Bases.get(Definition->getASTContext().getExternalSource());
00080 }
00081 
00082 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const {
00083   return VBases.get(Definition->getASTContext().getExternalSource());
00084 }
00085 
00086 CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C,
00087                              DeclContext *DC, SourceLocation StartLoc,
00088                              SourceLocation IdLoc, IdentifierInfo *Id,
00089                              CXXRecordDecl *PrevDecl)
00090     : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl),
00091       DefinitionData(PrevDecl ? PrevDecl->DefinitionData
00092                               : DefinitionDataPtr(this)),
00093       TemplateOrInstantiation() {}
00094 
00095 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK,
00096                                      DeclContext *DC, SourceLocation StartLoc,
00097                                      SourceLocation IdLoc, IdentifierInfo *Id,
00098                                      CXXRecordDecl* PrevDecl,
00099                                      bool DelayTypeCreation) {
00100   CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc,
00101                                                IdLoc, Id, PrevDecl);
00102   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
00103 
00104   // FIXME: DelayTypeCreation seems like such a hack
00105   if (!DelayTypeCreation)
00106     C.getTypeDeclType(R, PrevDecl);
00107   return R;
00108 }
00109 
00110 CXXRecordDecl *
00111 CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
00112                             TypeSourceInfo *Info, SourceLocation Loc,
00113                             bool Dependent, bool IsGeneric,
00114                             LambdaCaptureDefault CaptureDefault) {
00115   CXXRecordDecl *R =
00116       new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc,
00117                                 nullptr, nullptr);
00118   R->IsBeingDefined = true;
00119   R->DefinitionData =
00120       new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric,
00121                                           CaptureDefault);
00122   R->MayHaveOutOfDateDef = false;
00123   R->setImplicit(true);
00124   C.getTypeDeclType(R, /*PrevDecl=*/nullptr);
00125   return R;
00126 }
00127 
00128 CXXRecordDecl *
00129 CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
00130   CXXRecordDecl *R = new (C, ID) CXXRecordDecl(
00131       CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(),
00132       nullptr, nullptr);
00133   R->MayHaveOutOfDateDef = false;
00134   return R;
00135 }
00136 
00137 void
00138 CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
00139                         unsigned NumBases) {
00140   ASTContext &C = getASTContext();
00141 
00142   if (!data().Bases.isOffset() && data().NumBases > 0)
00143     C.Deallocate(data().getBases());
00144 
00145   if (NumBases) {
00146     // C++ [dcl.init.aggr]p1:
00147     //   An aggregate is [...] a class with [...] no base classes [...].
00148     data().Aggregate = false;
00149 
00150     // C++ [class]p4:
00151     //   A POD-struct is an aggregate class...
00152     data().PlainOldData = false;
00153   }
00154 
00155   // The set of seen virtual base types.
00156   llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
00157   
00158   // The virtual bases of this class.
00159   SmallVector<const CXXBaseSpecifier *, 8> VBases;
00160 
00161   data().Bases = new(C) CXXBaseSpecifier [NumBases];
00162   data().NumBases = NumBases;
00163   for (unsigned i = 0; i < NumBases; ++i) {
00164     data().getBases()[i] = *Bases[i];
00165     // Keep track of inherited vbases for this base class.
00166     const CXXBaseSpecifier *Base = Bases[i];
00167     QualType BaseType = Base->getType();
00168     // Skip dependent types; we can't do any checking on them now.
00169     if (BaseType->isDependentType())
00170       continue;
00171     CXXRecordDecl *BaseClassDecl
00172       = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
00173 
00174     // A class with a non-empty base class is not empty.
00175     // FIXME: Standard ref?
00176     if (!BaseClassDecl->isEmpty()) {
00177       if (!data().Empty) {
00178         // C++0x [class]p7:
00179         //   A standard-layout class is a class that:
00180         //    [...]
00181         //    -- either has no non-static data members in the most derived
00182         //       class and at most one base class with non-static data members,
00183         //       or has no base classes with non-static data members, and
00184         // If this is the second non-empty base, then neither of these two
00185         // clauses can be true.
00186         data().IsStandardLayout = false;
00187       }
00188 
00189       data().Empty = false;
00190       data().HasNoNonEmptyBases = false;
00191     }
00192     
00193     // C++ [class.virtual]p1:
00194     //   A class that declares or inherits a virtual function is called a 
00195     //   polymorphic class.
00196     if (BaseClassDecl->isPolymorphic())
00197       data().Polymorphic = true;
00198 
00199     // C++0x [class]p7:
00200     //   A standard-layout class is a class that: [...]
00201     //    -- has no non-standard-layout base classes
00202     if (!BaseClassDecl->isStandardLayout())
00203       data().IsStandardLayout = false;
00204 
00205     // Record if this base is the first non-literal field or base.
00206     if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
00207       data().HasNonLiteralTypeFieldsOrBases = true;
00208     
00209     // Now go through all virtual bases of this base and add them.
00210     for (const auto &VBase : BaseClassDecl->vbases()) {
00211       // Add this base if it's not already in the list.
00212       if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType()))) {
00213         VBases.push_back(&VBase);
00214 
00215         // C++11 [class.copy]p8:
00216         //   The implicitly-declared copy constructor for a class X will have
00217         //   the form 'X::X(const X&)' if each [...] virtual base class B of X
00218         //   has a copy constructor whose first parameter is of type
00219         //   'const B&' or 'const volatile B&' [...]
00220         if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl())
00221           if (!VBaseDecl->hasCopyConstructorWithConstParam())
00222             data().ImplicitCopyConstructorHasConstParam = false;
00223       }
00224     }
00225 
00226     if (Base->isVirtual()) {
00227       // Add this base if it's not already in the list.
00228       if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)))
00229         VBases.push_back(Base);
00230 
00231       // C++0x [meta.unary.prop] is_empty:
00232       //    T is a class type, but not a union type, with ... no virtual base
00233       //    classes
00234       data().Empty = false;
00235 
00236       // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
00237       //   A [default constructor, copy/move constructor, or copy/move assignment
00238       //   operator for a class X] is trivial [...] if:
00239       //    -- class X has [...] no virtual base classes
00240       data().HasTrivialSpecialMembers &= SMF_Destructor;
00241 
00242       // C++0x [class]p7:
00243       //   A standard-layout class is a class that: [...]
00244       //    -- has [...] no virtual base classes
00245       data().IsStandardLayout = false;
00246 
00247       // C++11 [dcl.constexpr]p4:
00248       //   In the definition of a constexpr constructor [...]
00249       //    -- the class shall not have any virtual base classes
00250       data().DefaultedDefaultConstructorIsConstexpr = false;
00251     } else {
00252       // C++ [class.ctor]p5:
00253       //   A default constructor is trivial [...] if:
00254       //    -- all the direct base classes of its class have trivial default
00255       //       constructors.
00256       if (!BaseClassDecl->hasTrivialDefaultConstructor())
00257         data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
00258 
00259       // C++0x [class.copy]p13:
00260       //   A copy/move constructor for class X is trivial if [...]
00261       //    [...]
00262       //    -- the constructor selected to copy/move each direct base class
00263       //       subobject is trivial, and
00264       if (!BaseClassDecl->hasTrivialCopyConstructor())
00265         data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
00266       // If the base class doesn't have a simple move constructor, we'll eagerly
00267       // declare it and perform overload resolution to determine which function
00268       // it actually calls. If it does have a simple move constructor, this
00269       // check is correct.
00270       if (!BaseClassDecl->hasTrivialMoveConstructor())
00271         data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
00272 
00273       // C++0x [class.copy]p27:
00274       //   A copy/move assignment operator for class X is trivial if [...]
00275       //    [...]
00276       //    -- the assignment operator selected to copy/move each direct base
00277       //       class subobject is trivial, and
00278       if (!BaseClassDecl->hasTrivialCopyAssignment())
00279         data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
00280       // If the base class doesn't have a simple move assignment, we'll eagerly
00281       // declare it and perform overload resolution to determine which function
00282       // it actually calls. If it does have a simple move assignment, this
00283       // check is correct.
00284       if (!BaseClassDecl->hasTrivialMoveAssignment())
00285         data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
00286 
00287       // C++11 [class.ctor]p6:
00288       //   If that user-written default constructor would satisfy the
00289       //   requirements of a constexpr constructor, the implicitly-defined
00290       //   default constructor is constexpr.
00291       if (!BaseClassDecl->hasConstexprDefaultConstructor())
00292         data().DefaultedDefaultConstructorIsConstexpr = false;
00293     }
00294 
00295     // C++ [class.ctor]p3:
00296     //   A destructor is trivial if all the direct base classes of its class
00297     //   have trivial destructors.
00298     if (!BaseClassDecl->hasTrivialDestructor())
00299       data().HasTrivialSpecialMembers &= ~SMF_Destructor;
00300 
00301     if (!BaseClassDecl->hasIrrelevantDestructor())
00302       data().HasIrrelevantDestructor = false;
00303 
00304     // C++11 [class.copy]p18:
00305     //   The implicitly-declared copy assignment oeprator for a class X will
00306     //   have the form 'X& X::operator=(const X&)' if each direct base class B
00307     //   of X has a copy assignment operator whose parameter is of type 'const
00308     //   B&', 'const volatile B&', or 'B' [...]
00309     if (!BaseClassDecl->hasCopyAssignmentWithConstParam())
00310       data().ImplicitCopyAssignmentHasConstParam = false;
00311 
00312     // C++11 [class.copy]p8:
00313     //   The implicitly-declared copy constructor for a class X will have
00314     //   the form 'X::X(const X&)' if each direct [...] base class B of X
00315     //   has a copy constructor whose first parameter is of type
00316     //   'const B&' or 'const volatile B&' [...]
00317     if (!BaseClassDecl->hasCopyConstructorWithConstParam())
00318       data().ImplicitCopyConstructorHasConstParam = false;
00319 
00320     // A class has an Objective-C object member if... or any of its bases
00321     // has an Objective-C object member.
00322     if (BaseClassDecl->hasObjectMember())
00323       setHasObjectMember(true);
00324     
00325     if (BaseClassDecl->hasVolatileMember())
00326       setHasVolatileMember(true);
00327 
00328     // Keep track of the presence of mutable fields.
00329     if (BaseClassDecl->hasMutableFields())
00330       data().HasMutableFields = true;
00331 
00332     if (BaseClassDecl->hasUninitializedReferenceMember())
00333       data().HasUninitializedReferenceMember = true;
00334 
00335     addedClassSubobject(BaseClassDecl);
00336   }
00337   
00338   if (VBases.empty()) {
00339     data().IsParsingBaseSpecifiers = false;
00340     return;
00341   }
00342 
00343   // Create base specifier for any direct or indirect virtual bases.
00344   data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
00345   data().NumVBases = VBases.size();
00346   for (int I = 0, E = VBases.size(); I != E; ++I) {
00347     QualType Type = VBases[I]->getType();
00348     if (!Type->isDependentType())
00349       addedClassSubobject(Type->getAsCXXRecordDecl());
00350     data().getVBases()[I] = *VBases[I];
00351   }
00352 
00353   data().IsParsingBaseSpecifiers = false;
00354 }
00355 
00356 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
00357   // C++11 [class.copy]p11:
00358   //   A defaulted copy/move constructor for a class X is defined as
00359   //   deleted if X has:
00360   //    -- a direct or virtual base class B that cannot be copied/moved [...]
00361   //    -- a non-static data member of class type M (or array thereof)
00362   //       that cannot be copied or moved [...]
00363   if (!Subobj->hasSimpleMoveConstructor())
00364     data().NeedOverloadResolutionForMoveConstructor = true;
00365 
00366   // C++11 [class.copy]p23:
00367   //   A defaulted copy/move assignment operator for a class X is defined as
00368   //   deleted if X has:
00369   //    -- a direct or virtual base class B that cannot be copied/moved [...]
00370   //    -- a non-static data member of class type M (or array thereof)
00371   //        that cannot be copied or moved [...]
00372   if (!Subobj->hasSimpleMoveAssignment())
00373     data().NeedOverloadResolutionForMoveAssignment = true;
00374 
00375   // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5:
00376   //   A defaulted [ctor or dtor] for a class X is defined as
00377   //   deleted if X has:
00378   //    -- any direct or virtual base class [...] has a type with a destructor
00379   //       that is deleted or inaccessible from the defaulted [ctor or dtor].
00380   //    -- any non-static data member has a type with a destructor
00381   //       that is deleted or inaccessible from the defaulted [ctor or dtor].
00382   if (!Subobj->hasSimpleDestructor()) {
00383     data().NeedOverloadResolutionForMoveConstructor = true;
00384     data().NeedOverloadResolutionForDestructor = true;
00385   }
00386 }
00387 
00388 /// Callback function for CXXRecordDecl::forallBases that acknowledges
00389 /// that it saw a base class.
00390 static bool SawBase(const CXXRecordDecl *, void *) {
00391   return true;
00392 }
00393 
00394 bool CXXRecordDecl::hasAnyDependentBases() const {
00395   if (!isDependentContext())
00396     return false;
00397 
00398   return !forallBases(SawBase, nullptr);
00399 }
00400 
00401 bool CXXRecordDecl::isTriviallyCopyable() const {
00402   // C++0x [class]p5:
00403   //   A trivially copyable class is a class that:
00404   //   -- has no non-trivial copy constructors,
00405   if (hasNonTrivialCopyConstructor()) return false;
00406   //   -- has no non-trivial move constructors,
00407   if (hasNonTrivialMoveConstructor()) return false;
00408   //   -- has no non-trivial copy assignment operators,
00409   if (hasNonTrivialCopyAssignment()) return false;
00410   //   -- has no non-trivial move assignment operators, and
00411   if (hasNonTrivialMoveAssignment()) return false;
00412   //   -- has a trivial destructor.
00413   if (!hasTrivialDestructor()) return false;
00414 
00415   return true;
00416 }
00417 
00418 void CXXRecordDecl::markedVirtualFunctionPure() {
00419   // C++ [class.abstract]p2: 
00420   //   A class is abstract if it has at least one pure virtual function.
00421   data().Abstract = true;
00422 }
00423 
00424 void CXXRecordDecl::addedMember(Decl *D) {
00425   if (!D->isImplicit() &&
00426       !isa<FieldDecl>(D) &&
00427       !isa<IndirectFieldDecl>(D) &&
00428       (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class ||
00429         cast<TagDecl>(D)->getTagKind() == TTK_Interface))
00430     data().HasOnlyCMembers = false;
00431 
00432   // Ignore friends and invalid declarations.
00433   if (D->getFriendObjectKind() || D->isInvalidDecl())
00434     return;
00435   
00436   FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
00437   if (FunTmpl)
00438     D = FunTmpl->getTemplatedDecl();
00439   
00440   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
00441     if (Method->isVirtual()) {
00442       // C++ [dcl.init.aggr]p1:
00443       //   An aggregate is an array or a class with [...] no virtual functions.
00444       data().Aggregate = false;
00445       
00446       // C++ [class]p4:
00447       //   A POD-struct is an aggregate class...
00448       data().PlainOldData = false;
00449       
00450       // Virtual functions make the class non-empty.
00451       // FIXME: Standard ref?
00452       data().Empty = false;
00453 
00454       // C++ [class.virtual]p1:
00455       //   A class that declares or inherits a virtual function is called a 
00456       //   polymorphic class.
00457       data().Polymorphic = true;
00458 
00459       // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
00460       //   A [default constructor, copy/move constructor, or copy/move
00461       //   assignment operator for a class X] is trivial [...] if:
00462       //    -- class X has no virtual functions [...]
00463       data().HasTrivialSpecialMembers &= SMF_Destructor;
00464 
00465       // C++0x [class]p7:
00466       //   A standard-layout class is a class that: [...]
00467       //    -- has no virtual functions
00468       data().IsStandardLayout = false;
00469     }
00470   }
00471 
00472   // Notify the listener if an implicit member was added after the definition
00473   // was completed.
00474   if (!isBeingDefined() && D->isImplicit())
00475     if (ASTMutationListener *L = getASTMutationListener())
00476       L->AddedCXXImplicitMember(data().Definition, D);
00477 
00478   // The kind of special member this declaration is, if any.
00479   unsigned SMKind = 0;
00480 
00481   // Handle constructors.
00482   if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
00483     if (!Constructor->isImplicit()) {
00484       // Note that we have a user-declared constructor.
00485       data().UserDeclaredConstructor = true;
00486 
00487       // C++ [class]p4:
00488       //   A POD-struct is an aggregate class [...]
00489       // Since the POD bit is meant to be C++03 POD-ness, clear it even if the
00490       // type is technically an aggregate in C++0x since it wouldn't be in 03.
00491       data().PlainOldData = false;
00492     }
00493 
00494     // Technically, "user-provided" is only defined for special member
00495     // functions, but the intent of the standard is clearly that it should apply
00496     // to all functions.
00497     bool UserProvided = Constructor->isUserProvided();
00498 
00499     if (Constructor->isDefaultConstructor()) {
00500       SMKind |= SMF_DefaultConstructor;
00501 
00502       if (UserProvided)
00503         data().UserProvidedDefaultConstructor = true;
00504       if (Constructor->isConstexpr())
00505         data().HasConstexprDefaultConstructor = true;
00506     }
00507 
00508     if (!FunTmpl) {
00509       unsigned Quals;
00510       if (Constructor->isCopyConstructor(Quals)) {
00511         SMKind |= SMF_CopyConstructor;
00512 
00513         if (Quals & Qualifiers::Const)
00514           data().HasDeclaredCopyConstructorWithConstParam = true;
00515       } else if (Constructor->isMoveConstructor())
00516         SMKind |= SMF_MoveConstructor;
00517     }
00518 
00519     // Record if we see any constexpr constructors which are neither copy
00520     // nor move constructors.
00521     if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
00522       data().HasConstexprNonCopyMoveConstructor = true;
00523 
00524     // C++ [dcl.init.aggr]p1:
00525     //   An aggregate is an array or a class with no user-declared
00526     //   constructors [...].
00527     // C++11 [dcl.init.aggr]p1:
00528     //   An aggregate is an array or a class with no user-provided
00529     //   constructors [...].
00530     if (getASTContext().getLangOpts().CPlusPlus11
00531           ? UserProvided : !Constructor->isImplicit())
00532       data().Aggregate = false;
00533   }
00534 
00535   // Handle destructors.
00536   if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) {
00537     SMKind |= SMF_Destructor;
00538 
00539     if (DD->isUserProvided())
00540       data().HasIrrelevantDestructor = false;
00541     // If the destructor is explicitly defaulted and not trivial or not public
00542     // or if the destructor is deleted, we clear HasIrrelevantDestructor in
00543     // finishedDefaultedOrDeletedMember.
00544 
00545     // C++11 [class.dtor]p5:
00546     //   A destructor is trivial if [...] the destructor is not virtual.
00547     if (DD->isVirtual())
00548       data().HasTrivialSpecialMembers &= ~SMF_Destructor;
00549   }
00550 
00551   // Handle member functions.
00552   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
00553     if (Method->isCopyAssignmentOperator()) {
00554       SMKind |= SMF_CopyAssignment;
00555 
00556       const ReferenceType *ParamTy =
00557         Method->getParamDecl(0)->getType()->getAs<ReferenceType>();
00558       if (!ParamTy || ParamTy->getPointeeType().isConstQualified())
00559         data().HasDeclaredCopyAssignmentWithConstParam = true;
00560     }
00561 
00562     if (Method->isMoveAssignmentOperator())
00563       SMKind |= SMF_MoveAssignment;
00564 
00565     // Keep the list of conversion functions up-to-date.
00566     if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) {
00567       // FIXME: We use the 'unsafe' accessor for the access specifier here,
00568       // because Sema may not have set it yet. That's really just a misdesign
00569       // in Sema. However, LLDB *will* have set the access specifier correctly,
00570       // and adds declarations after the class is technically completed,
00571       // so completeDefinition()'s overriding of the access specifiers doesn't
00572       // work.
00573       AccessSpecifier AS = Conversion->getAccessUnsafe();
00574 
00575       if (Conversion->getPrimaryTemplate()) {
00576         // We don't record specializations.
00577       } else {
00578         ASTContext &Ctx = getASTContext();
00579         ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
00580         NamedDecl *Primary =
00581             FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion);
00582         if (Primary->getPreviousDecl())
00583           Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
00584                               Primary, AS);
00585         else
00586           Conversions.addDecl(Ctx, Primary, AS);
00587       }
00588     }
00589 
00590     if (SMKind) {
00591       // If this is the first declaration of a special member, we no longer have
00592       // an implicit trivial special member.
00593       data().HasTrivialSpecialMembers &=
00594         data().DeclaredSpecialMembers | ~SMKind;
00595 
00596       if (!Method->isImplicit() && !Method->isUserProvided()) {
00597         // This method is user-declared but not user-provided. We can't work out
00598         // whether it's trivial yet (not until we get to the end of the class).
00599         // We'll handle this method in finishedDefaultedOrDeletedMember.
00600       } else if (Method->isTrivial())
00601         data().HasTrivialSpecialMembers |= SMKind;
00602       else
00603         data().DeclaredNonTrivialSpecialMembers |= SMKind;
00604 
00605       // Note when we have declared a declared special member, and suppress the
00606       // implicit declaration of this special member.
00607       data().DeclaredSpecialMembers |= SMKind;
00608 
00609       if (!Method->isImplicit()) {
00610         data().UserDeclaredSpecialMembers |= SMKind;
00611 
00612         // C++03 [class]p4:
00613         //   A POD-struct is an aggregate class that has [...] no user-defined
00614         //   copy assignment operator and no user-defined destructor.
00615         //
00616         // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
00617         // aggregates could not have any constructors, clear it even for an
00618         // explicitly defaulted or deleted constructor.
00619         // type is technically an aggregate in C++0x since it wouldn't be in 03.
00620         //
00621         // Also, a user-declared move assignment operator makes a class non-POD.
00622         // This is an extension in C++03.
00623         data().PlainOldData = false;
00624       }
00625     }
00626 
00627     return;
00628   }
00629 
00630   // Handle non-static data members.
00631   if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) {
00632     // C++ [class.bit]p2:
00633     //   A declaration for a bit-field that omits the identifier declares an 
00634     //   unnamed bit-field. Unnamed bit-fields are not members and cannot be 
00635     //   initialized.
00636     if (Field->isUnnamedBitfield())
00637       return;
00638     
00639     // C++ [dcl.init.aggr]p1:
00640     //   An aggregate is an array or a class (clause 9) with [...] no
00641     //   private or protected non-static data members (clause 11).
00642     //
00643     // A POD must be an aggregate.    
00644     if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
00645       data().Aggregate = false;
00646       data().PlainOldData = false;
00647     }
00648 
00649     // C++0x [class]p7:
00650     //   A standard-layout class is a class that:
00651     //    [...]
00652     //    -- has the same access control for all non-static data members,
00653     switch (D->getAccess()) {
00654     case AS_private:    data().HasPrivateFields = true;   break;
00655     case AS_protected:  data().HasProtectedFields = true; break;
00656     case AS_public:     data().HasPublicFields = true;    break;
00657     case AS_none:       llvm_unreachable("Invalid access specifier");
00658     };
00659     if ((data().HasPrivateFields + data().HasProtectedFields +
00660          data().HasPublicFields) > 1)
00661       data().IsStandardLayout = false;
00662 
00663     // Keep track of the presence of mutable fields.
00664     if (Field->isMutable())
00665       data().HasMutableFields = true;
00666 
00667     // C++11 [class.union]p8, DR1460:
00668     //   If X is a union, a non-static data member of X that is not an anonymous
00669     //   union is a variant member of X.
00670     if (isUnion() && !Field->isAnonymousStructOrUnion())
00671       data().HasVariantMembers = true;
00672 
00673     // C++0x [class]p9:
00674     //   A POD struct is a class that is both a trivial class and a 
00675     //   standard-layout class, and has no non-static data members of type 
00676     //   non-POD struct, non-POD union (or array of such types).
00677     //
00678     // Automatic Reference Counting: the presence of a member of Objective-C pointer type
00679     // that does not explicitly have no lifetime makes the class a non-POD.
00680     ASTContext &Context = getASTContext();
00681     QualType T = Context.getBaseElementType(Field->getType());
00682     if (T->isObjCRetainableType() || T.isObjCGCStrong()) {
00683       if (!Context.getLangOpts().ObjCAutoRefCount) {
00684         setHasObjectMember(true);
00685       } else if (T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) {
00686         // Objective-C Automatic Reference Counting:
00687         //   If a class has a non-static data member of Objective-C pointer
00688         //   type (or array thereof), it is a non-POD type and its
00689         //   default constructor (if any), copy constructor, move constructor,
00690         //   copy assignment operator, move assignment operator, and destructor are
00691         //   non-trivial.
00692         setHasObjectMember(true);
00693         struct DefinitionData &Data = data();
00694         Data.PlainOldData = false;
00695         Data.HasTrivialSpecialMembers = 0;
00696         Data.HasIrrelevantDestructor = false;
00697       }
00698     } else if (!T.isCXX98PODType(Context))
00699       data().PlainOldData = false;
00700     
00701     if (T->isReferenceType()) {
00702       if (!Field->hasInClassInitializer())
00703         data().HasUninitializedReferenceMember = true;
00704 
00705       // C++0x [class]p7:
00706       //   A standard-layout class is a class that:
00707       //    -- has no non-static data members of type [...] reference,
00708       data().IsStandardLayout = false;
00709     }
00710 
00711     // Record if this field is the first non-literal or volatile field or base.
00712     if (!T->isLiteralType(Context) || T.isVolatileQualified())
00713       data().HasNonLiteralTypeFieldsOrBases = true;
00714 
00715     if (Field->hasInClassInitializer() ||
00716         (Field->isAnonymousStructOrUnion() &&
00717          Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
00718       data().HasInClassInitializer = true;
00719 
00720       // C++11 [class]p5:
00721       //   A default constructor is trivial if [...] no non-static data member
00722       //   of its class has a brace-or-equal-initializer.
00723       data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
00724 
00725       // C++11 [dcl.init.aggr]p1:
00726       //   An aggregate is a [...] class with [...] no
00727       //   brace-or-equal-initializers for non-static data members.
00728       //
00729       // This rule was removed in C++1y.
00730       if (!getASTContext().getLangOpts().CPlusPlus14)
00731         data().Aggregate = false;
00732 
00733       // C++11 [class]p10:
00734       //   A POD struct is [...] a trivial class.
00735       data().PlainOldData = false;
00736     }
00737 
00738     // C++11 [class.copy]p23:
00739     //   A defaulted copy/move assignment operator for a class X is defined
00740     //   as deleted if X has:
00741     //    -- a non-static data member of reference type
00742     if (T->isReferenceType())
00743       data().DefaultedMoveAssignmentIsDeleted = true;
00744 
00745     if (const RecordType *RecordTy = T->getAs<RecordType>()) {
00746       CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
00747       if (FieldRec->getDefinition()) {
00748         addedClassSubobject(FieldRec);
00749 
00750         // We may need to perform overload resolution to determine whether a
00751         // field can be moved if it's const or volatile qualified.
00752         if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) {
00753           data().NeedOverloadResolutionForMoveConstructor = true;
00754           data().NeedOverloadResolutionForMoveAssignment = true;
00755         }
00756 
00757         // C++11 [class.ctor]p5, C++11 [class.copy]p11:
00758         //   A defaulted [special member] for a class X is defined as
00759         //   deleted if:
00760         //    -- X is a union-like class that has a variant member with a
00761         //       non-trivial [corresponding special member]
00762         if (isUnion()) {
00763           if (FieldRec->hasNonTrivialMoveConstructor())
00764             data().DefaultedMoveConstructorIsDeleted = true;
00765           if (FieldRec->hasNonTrivialMoveAssignment())
00766             data().DefaultedMoveAssignmentIsDeleted = true;
00767           if (FieldRec->hasNonTrivialDestructor())
00768             data().DefaultedDestructorIsDeleted = true;
00769         }
00770 
00771         // C++0x [class.ctor]p5:
00772         //   A default constructor is trivial [...] if:
00773         //    -- for all the non-static data members of its class that are of
00774         //       class type (or array thereof), each such class has a trivial
00775         //       default constructor.
00776         if (!FieldRec->hasTrivialDefaultConstructor())
00777           data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
00778 
00779         // C++0x [class.copy]p13:
00780         //   A copy/move constructor for class X is trivial if [...]
00781         //    [...]
00782         //    -- for each non-static data member of X that is of class type (or
00783         //       an array thereof), the constructor selected to copy/move that
00784         //       member is trivial;
00785         if (!FieldRec->hasTrivialCopyConstructor())
00786           data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
00787         // If the field doesn't have a simple move constructor, we'll eagerly
00788         // declare the move constructor for this class and we'll decide whether
00789         // it's trivial then.
00790         if (!FieldRec->hasTrivialMoveConstructor())
00791           data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
00792 
00793         // C++0x [class.copy]p27:
00794         //   A copy/move assignment operator for class X is trivial if [...]
00795         //    [...]
00796         //    -- for each non-static data member of X that is of class type (or
00797         //       an array thereof), the assignment operator selected to
00798         //       copy/move that member is trivial;
00799         if (!FieldRec->hasTrivialCopyAssignment())
00800           data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
00801         // If the field doesn't have a simple move assignment, we'll eagerly
00802         // declare the move assignment for this class and we'll decide whether
00803         // it's trivial then.
00804         if (!FieldRec->hasTrivialMoveAssignment())
00805           data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
00806 
00807         if (!FieldRec->hasTrivialDestructor())
00808           data().HasTrivialSpecialMembers &= ~SMF_Destructor;
00809         if (!FieldRec->hasIrrelevantDestructor())
00810           data().HasIrrelevantDestructor = false;
00811         if (FieldRec->hasObjectMember())
00812           setHasObjectMember(true);
00813         if (FieldRec->hasVolatileMember())
00814           setHasVolatileMember(true);
00815 
00816         // C++0x [class]p7:
00817         //   A standard-layout class is a class that:
00818         //    -- has no non-static data members of type non-standard-layout
00819         //       class (or array of such types) [...]
00820         if (!FieldRec->isStandardLayout())
00821           data().IsStandardLayout = false;
00822 
00823         // C++0x [class]p7:
00824         //   A standard-layout class is a class that:
00825         //    [...]
00826         //    -- has no base classes of the same type as the first non-static
00827         //       data member.
00828         // We don't want to expend bits in the state of the record decl
00829         // tracking whether this is the first non-static data member so we
00830         // cheat a bit and use some of the existing state: the empty bit.
00831         // Virtual bases and virtual methods make a class non-empty, but they
00832         // also make it non-standard-layout so we needn't check here.
00833         // A non-empty base class may leave the class standard-layout, but not
00834         // if we have arrived here, and have at least one non-static data
00835         // member. If IsStandardLayout remains true, then the first non-static
00836         // data member must come through here with Empty still true, and Empty
00837         // will subsequently be set to false below.
00838         if (data().IsStandardLayout && data().Empty) {
00839           for (const auto &BI : bases()) {
00840             if (Context.hasSameUnqualifiedType(BI.getType(), T)) {
00841               data().IsStandardLayout = false;
00842               break;
00843             }
00844           }
00845         }
00846         
00847         // Keep track of the presence of mutable fields.
00848         if (FieldRec->hasMutableFields())
00849           data().HasMutableFields = true;
00850 
00851         // C++11 [class.copy]p13:
00852         //   If the implicitly-defined constructor would satisfy the
00853         //   requirements of a constexpr constructor, the implicitly-defined
00854         //   constructor is constexpr.
00855         // C++11 [dcl.constexpr]p4:
00856         //    -- every constructor involved in initializing non-static data
00857         //       members [...] shall be a constexpr constructor
00858         if (!Field->hasInClassInitializer() &&
00859             !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
00860           // The standard requires any in-class initializer to be a constant
00861           // expression. We consider this to be a defect.
00862           data().DefaultedDefaultConstructorIsConstexpr = false;
00863 
00864         // C++11 [class.copy]p8:
00865         //   The implicitly-declared copy constructor for a class X will have
00866         //   the form 'X::X(const X&)' if [...] for all the non-static data
00867         //   members of X that are of a class type M (or array thereof), each
00868         //   such class type has a copy constructor whose first parameter is
00869         //   of type 'const M&' or 'const volatile M&'.
00870         if (!FieldRec->hasCopyConstructorWithConstParam())
00871           data().ImplicitCopyConstructorHasConstParam = false;
00872 
00873         // C++11 [class.copy]p18:
00874         //   The implicitly-declared copy assignment oeprator for a class X will
00875         //   have the form 'X& X::operator=(const X&)' if [...] for all the
00876         //   non-static data members of X that are of a class type M (or array
00877         //   thereof), each such class type has a copy assignment operator whose
00878         //   parameter is of type 'const M&', 'const volatile M&' or 'M'.
00879         if (!FieldRec->hasCopyAssignmentWithConstParam())
00880           data().ImplicitCopyAssignmentHasConstParam = false;
00881 
00882         if (FieldRec->hasUninitializedReferenceMember() &&
00883             !Field->hasInClassInitializer())
00884           data().HasUninitializedReferenceMember = true;
00885 
00886         // C++11 [class.union]p8, DR1460:
00887         //   a non-static data member of an anonymous union that is a member of
00888         //   X is also a variant member of X.
00889         if (FieldRec->hasVariantMembers() &&
00890             Field->isAnonymousStructOrUnion())
00891           data().HasVariantMembers = true;
00892       }
00893     } else {
00894       // Base element type of field is a non-class type.
00895       if (!T->isLiteralType(Context) ||
00896           (!Field->hasInClassInitializer() && !isUnion()))
00897         data().DefaultedDefaultConstructorIsConstexpr = false;
00898 
00899       // C++11 [class.copy]p23:
00900       //   A defaulted copy/move assignment operator for a class X is defined
00901       //   as deleted if X has:
00902       //    -- a non-static data member of const non-class type (or array
00903       //       thereof)
00904       if (T.isConstQualified())
00905         data().DefaultedMoveAssignmentIsDeleted = true;
00906     }
00907 
00908     // C++0x [class]p7:
00909     //   A standard-layout class is a class that:
00910     //    [...]
00911     //    -- either has no non-static data members in the most derived
00912     //       class and at most one base class with non-static data members,
00913     //       or has no base classes with non-static data members, and
00914     // At this point we know that we have a non-static data member, so the last
00915     // clause holds.
00916     if (!data().HasNoNonEmptyBases)
00917       data().IsStandardLayout = false;
00918 
00919     // If this is not a zero-length bit-field, then the class is not empty.
00920     if (data().Empty) {
00921       if (!Field->isBitField() ||
00922           (!Field->getBitWidth()->isTypeDependent() &&
00923            !Field->getBitWidth()->isValueDependent() &&
00924            Field->getBitWidthValue(Context) != 0))
00925         data().Empty = false;
00926     }
00927   }
00928   
00929   // Handle using declarations of conversion functions.
00930   if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) {
00931     if (Shadow->getDeclName().getNameKind()
00932           == DeclarationName::CXXConversionFunctionName) {
00933       ASTContext &Ctx = getASTContext();
00934       data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
00935     }
00936   }
00937 }
00938 
00939 void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
00940   assert(!D->isImplicit() && !D->isUserProvided());
00941 
00942   // The kind of special member this declaration is, if any.
00943   unsigned SMKind = 0;
00944 
00945   if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
00946     if (Constructor->isDefaultConstructor()) {
00947       SMKind |= SMF_DefaultConstructor;
00948       if (Constructor->isConstexpr())
00949         data().HasConstexprDefaultConstructor = true;
00950     }
00951     if (Constructor->isCopyConstructor())
00952       SMKind |= SMF_CopyConstructor;
00953     else if (Constructor->isMoveConstructor())
00954       SMKind |= SMF_MoveConstructor;
00955     else if (Constructor->isConstexpr())
00956       // We may now know that the constructor is constexpr.
00957       data().HasConstexprNonCopyMoveConstructor = true;
00958   } else if (isa<CXXDestructorDecl>(D)) {
00959     SMKind |= SMF_Destructor;
00960     if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted())
00961       data().HasIrrelevantDestructor = false;
00962   } else if (D->isCopyAssignmentOperator())
00963     SMKind |= SMF_CopyAssignment;
00964   else if (D->isMoveAssignmentOperator())
00965     SMKind |= SMF_MoveAssignment;
00966 
00967   // Update which trivial / non-trivial special members we have.
00968   // addedMember will have skipped this step for this member.
00969   if (D->isTrivial())
00970     data().HasTrivialSpecialMembers |= SMKind;
00971   else
00972     data().DeclaredNonTrivialSpecialMembers |= SMKind;
00973 }
00974 
00975 bool CXXRecordDecl::isCLike() const {
00976   if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface ||
00977       !TemplateOrInstantiation.isNull())
00978     return false;
00979   if (!hasDefinition())
00980     return true;
00981 
00982   return isPOD() && data().HasOnlyCMembers;
00983 }
00984  
00985 bool CXXRecordDecl::isGenericLambda() const { 
00986   if (!isLambda()) return false;
00987   return getLambdaData().IsGenericLambda;
00988 }
00989 
00990 CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const {
00991   if (!isLambda()) return nullptr;
00992   DeclarationName Name = 
00993     getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
00994   DeclContext::lookup_const_result Calls = lookup(Name);
00995 
00996   assert(!Calls.empty() && "Missing lambda call operator!");
00997   assert(Calls.size() == 1 && "More than one lambda call operator!"); 
00998    
00999   NamedDecl *CallOp = Calls.front();
01000   if (FunctionTemplateDecl *CallOpTmpl = 
01001                     dyn_cast<FunctionTemplateDecl>(CallOp)) 
01002     return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
01003   
01004   return cast<CXXMethodDecl>(CallOp);
01005 }
01006 
01007 CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
01008   if (!isLambda()) return nullptr;
01009   DeclarationName Name = 
01010     &getASTContext().Idents.get(getLambdaStaticInvokerName());
01011   DeclContext::lookup_const_result Invoker = lookup(Name);
01012   if (Invoker.empty()) return nullptr;
01013   assert(Invoker.size() == 1 && "More than one static invoker operator!");  
01014   NamedDecl *InvokerFun = Invoker.front();
01015   if (FunctionTemplateDecl *InvokerTemplate =
01016                   dyn_cast<FunctionTemplateDecl>(InvokerFun)) 
01017     return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
01018   
01019   return cast<CXXMethodDecl>(InvokerFun); 
01020 }
01021 
01022 void CXXRecordDecl::getCaptureFields(
01023        llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
01024        FieldDecl *&ThisCapture) const {
01025   Captures.clear();
01026   ThisCapture = nullptr;
01027 
01028   LambdaDefinitionData &Lambda = getLambdaData();
01029   RecordDecl::field_iterator Field = field_begin();
01030   for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures;
01031        C != CEnd; ++C, ++Field) {
01032     if (C->capturesThis())
01033       ThisCapture = *Field;
01034     else if (C->capturesVariable())
01035       Captures[C->getCapturedVar()] = *Field;
01036   }
01037   assert(Field == field_end());
01038 }
01039 
01040 TemplateParameterList * 
01041 CXXRecordDecl::getGenericLambdaTemplateParameterList() const {
01042   if (!isLambda()) return nullptr;
01043   CXXMethodDecl *CallOp = getLambdaCallOperator();     
01044   if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate())
01045     return Tmpl->getTemplateParameters();
01046   return nullptr;
01047 }
01048 
01049 static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
01050   QualType T =
01051       cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction())
01052           ->getConversionType();
01053   return Context.getCanonicalType(T);
01054 }
01055 
01056 /// Collect the visible conversions of a base class.
01057 ///
01058 /// \param Record a base class of the class we're considering
01059 /// \param InVirtual whether this base class is a virtual base (or a base
01060 ///   of a virtual base)
01061 /// \param Access the access along the inheritance path to this base
01062 /// \param ParentHiddenTypes the conversions provided by the inheritors
01063 ///   of this base
01064 /// \param Output the set to which to add conversions from non-virtual bases
01065 /// \param VOutput the set to which to add conversions from virtual bases
01066 /// \param HiddenVBaseCs the set of conversions which were hidden in a
01067 ///   virtual base along some inheritance path
01068 static void CollectVisibleConversions(ASTContext &Context,
01069                                       CXXRecordDecl *Record,
01070                                       bool InVirtual,
01071                                       AccessSpecifier Access,
01072                   const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
01073                                       ASTUnresolvedSet &Output,
01074                                       UnresolvedSetImpl &VOutput,
01075                            llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
01076   // The set of types which have conversions in this class or its
01077   // subclasses.  As an optimization, we don't copy the derived set
01078   // unless it might change.
01079   const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
01080   llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
01081 
01082   // Collect the direct conversions and figure out which conversions
01083   // will be hidden in the subclasses.
01084   CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
01085   CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
01086   if (ConvI != ConvE) {
01087     HiddenTypesBuffer = ParentHiddenTypes;
01088     HiddenTypes = &HiddenTypesBuffer;
01089 
01090     for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) {
01091       CanQualType ConvType(GetConversionType(Context, I.getDecl()));
01092       bool Hidden = ParentHiddenTypes.count(ConvType);
01093       if (!Hidden)
01094         HiddenTypesBuffer.insert(ConvType);
01095 
01096       // If this conversion is hidden and we're in a virtual base,
01097       // remember that it's hidden along some inheritance path.
01098       if (Hidden && InVirtual)
01099         HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
01100 
01101       // If this conversion isn't hidden, add it to the appropriate output.
01102       else if (!Hidden) {
01103         AccessSpecifier IAccess
01104           = CXXRecordDecl::MergeAccess(Access, I.getAccess());
01105 
01106         if (InVirtual)
01107           VOutput.addDecl(I.getDecl(), IAccess);
01108         else
01109           Output.addDecl(Context, I.getDecl(), IAccess);
01110       }
01111     }
01112   }
01113 
01114   // Collect information recursively from any base classes.
01115   for (const auto &I : Record->bases()) {
01116     const RecordType *RT = I.getType()->getAs<RecordType>();
01117     if (!RT) continue;
01118 
01119     AccessSpecifier BaseAccess
01120       = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
01121     bool BaseInVirtual = InVirtual || I.isVirtual();
01122 
01123     CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
01124     CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
01125                               *HiddenTypes, Output, VOutput, HiddenVBaseCs);
01126   }
01127 }
01128 
01129 /// Collect the visible conversions of a class.
01130 ///
01131 /// This would be extremely straightforward if it weren't for virtual
01132 /// bases.  It might be worth special-casing that, really.
01133 static void CollectVisibleConversions(ASTContext &Context,
01134                                       CXXRecordDecl *Record,
01135                                       ASTUnresolvedSet &Output) {
01136   // The collection of all conversions in virtual bases that we've
01137   // found.  These will be added to the output as long as they don't
01138   // appear in the hidden-conversions set.
01139   UnresolvedSet<8> VBaseCs;
01140   
01141   // The set of conversions in virtual bases that we've determined to
01142   // be hidden.
01143   llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs;
01144 
01145   // The set of types hidden by classes derived from this one.
01146   llvm::SmallPtrSet<CanQualType, 8> HiddenTypes;
01147 
01148   // Go ahead and collect the direct conversions and add them to the
01149   // hidden-types set.
01150   CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
01151   CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
01152   Output.append(Context, ConvI, ConvE);
01153   for (; ConvI != ConvE; ++ConvI)
01154     HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
01155 
01156   // Recursively collect conversions from base classes.
01157   for (const auto &I : Record->bases()) {
01158     const RecordType *RT = I.getType()->getAs<RecordType>();
01159     if (!RT) continue;
01160 
01161     CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
01162                               I.isVirtual(), I.getAccessSpecifier(),
01163                               HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
01164   }
01165 
01166   // Add any unhidden conversions provided by virtual bases.
01167   for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
01168          I != E; ++I) {
01169     if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
01170       Output.addDecl(Context, I.getDecl(), I.getAccess());
01171   }
01172 }
01173 
01174 /// getVisibleConversionFunctions - get all conversion functions visible
01175 /// in current class; including conversion function templates.
01176 std::pair<CXXRecordDecl::conversion_iterator,CXXRecordDecl::conversion_iterator>
01177 CXXRecordDecl::getVisibleConversionFunctions() {
01178   ASTContext &Ctx = getASTContext();
01179 
01180   ASTUnresolvedSet *Set;
01181   if (bases_begin() == bases_end()) {
01182     // If root class, all conversions are visible.
01183     Set = &data().Conversions.get(Ctx);
01184   } else {
01185     Set = &data().VisibleConversions.get(Ctx);
01186     // If visible conversion list is not evaluated, evaluate it.
01187     if (!data().ComputedVisibleConversions) {
01188       CollectVisibleConversions(Ctx, this, *Set);
01189       data().ComputedVisibleConversions = true;
01190     }
01191   }
01192   return std::make_pair(Set->begin(), Set->end());
01193 }
01194 
01195 void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) {
01196   // This operation is O(N) but extremely rare.  Sema only uses it to
01197   // remove UsingShadowDecls in a class that were followed by a direct
01198   // declaration, e.g.:
01199   //   class A : B {
01200   //     using B::operator int;
01201   //     operator int();
01202   //   };
01203   // This is uncommon by itself and even more uncommon in conjunction
01204   // with sufficiently large numbers of directly-declared conversions
01205   // that asymptotic behavior matters.
01206 
01207   ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
01208   for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
01209     if (Convs[I].getDecl() == ConvDecl) {
01210       Convs.erase(I);
01211       assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end()
01212              && "conversion was found multiple times in unresolved set");
01213       return;
01214     }
01215   }
01216 
01217   llvm_unreachable("conversion not found in set!");
01218 }
01219 
01220 CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
01221   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
01222     return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
01223 
01224   return nullptr;
01225 }
01226 
01227 void 
01228 CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
01229                                              TemplateSpecializationKind TSK) {
01230   assert(TemplateOrInstantiation.isNull() && 
01231          "Previous template or instantiation?");
01232   assert(!isa<ClassTemplatePartialSpecializationDecl>(this));
01233   TemplateOrInstantiation 
01234     = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
01235 }
01236 
01237 TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{
01238   if (const ClassTemplateSpecializationDecl *Spec
01239         = dyn_cast<ClassTemplateSpecializationDecl>(this))
01240     return Spec->getSpecializationKind();
01241   
01242   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
01243     return MSInfo->getTemplateSpecializationKind();
01244   
01245   return TSK_Undeclared;
01246 }
01247 
01248 void 
01249 CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
01250   if (ClassTemplateSpecializationDecl *Spec
01251       = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
01252     Spec->setSpecializationKind(TSK);
01253     return;
01254   }
01255   
01256   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
01257     MSInfo->setTemplateSpecializationKind(TSK);
01258     return;
01259   }
01260   
01261   llvm_unreachable("Not a class template or member class specialization");
01262 }
01263 
01264 const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {
01265   // If it's a class template specialization, find the template or partial
01266   // specialization from which it was instantiated.
01267   if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
01268     auto From = TD->getInstantiatedFrom();
01269     if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) {
01270       while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) {
01271         if (NewCTD->isMemberSpecialization())
01272           break;
01273         CTD = NewCTD;
01274       }
01275       return CTD->getTemplatedDecl();
01276     }
01277     if (auto *CTPSD =
01278             From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
01279       while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) {
01280         if (NewCTPSD->isMemberSpecialization())
01281           break;
01282         CTPSD = NewCTPSD;
01283       }
01284       return CTPSD;
01285     }
01286   }
01287 
01288   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
01289     if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
01290       const CXXRecordDecl *RD = this;
01291       while (auto *NewRD = RD->getInstantiatedFromMemberClass())
01292         RD = NewRD;
01293       return RD;
01294     }
01295   }
01296 
01297   assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) &&
01298          "couldn't find pattern for class template instantiation");
01299   return nullptr;
01300 }
01301 
01302 CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
01303   ASTContext &Context = getASTContext();
01304   QualType ClassType = Context.getTypeDeclType(this);
01305 
01306   DeclarationName Name
01307     = Context.DeclarationNames.getCXXDestructorName(
01308                                           Context.getCanonicalType(ClassType));
01309 
01310   DeclContext::lookup_const_result R = lookup(Name);
01311   if (R.empty())
01312     return nullptr;
01313 
01314   CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(R.front());
01315   return Dtor;
01316 }
01317 
01318 void CXXRecordDecl::completeDefinition() {
01319   completeDefinition(nullptr);
01320 }
01321 
01322 void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
01323   RecordDecl::completeDefinition();
01324   
01325   // If the class may be abstract (but hasn't been marked as such), check for
01326   // any pure final overriders.
01327   if (mayBeAbstract()) {
01328     CXXFinalOverriderMap MyFinalOverriders;
01329     if (!FinalOverriders) {
01330       getFinalOverriders(MyFinalOverriders);
01331       FinalOverriders = &MyFinalOverriders;
01332     }
01333     
01334     bool Done = false;
01335     for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), 
01336                                      MEnd = FinalOverriders->end();
01337          M != MEnd && !Done; ++M) {
01338       for (OverridingMethods::iterator SO = M->second.begin(), 
01339                                     SOEnd = M->second.end();
01340            SO != SOEnd && !Done; ++SO) {
01341         assert(SO->second.size() > 0 && 
01342                "All virtual functions have overridding virtual functions");
01343         
01344         // C++ [class.abstract]p4:
01345         //   A class is abstract if it contains or inherits at least one
01346         //   pure virtual function for which the final overrider is pure
01347         //   virtual.
01348         if (SO->second.front().Method->isPure()) {
01349           data().Abstract = true;
01350           Done = true;
01351           break;
01352         }
01353       }
01354     }
01355   }
01356   
01357   // Set access bits correctly on the directly-declared conversions.
01358   for (conversion_iterator I = conversion_begin(), E = conversion_end();
01359        I != E; ++I)
01360     I.setAccess((*I)->getAccess());
01361 }
01362 
01363 bool CXXRecordDecl::mayBeAbstract() const {
01364   if (data().Abstract || isInvalidDecl() || !data().Polymorphic ||
01365       isDependentContext())
01366     return false;
01367   
01368   for (const auto &B : bases()) {
01369     CXXRecordDecl *BaseDecl 
01370       = cast<CXXRecordDecl>(B.getType()->getAs<RecordType>()->getDecl());
01371     if (BaseDecl->isAbstract())
01372       return true;
01373   }
01374   
01375   return false;
01376 }
01377 
01378 void CXXMethodDecl::anchor() { }
01379 
01380 bool CXXMethodDecl::isStatic() const {
01381   const CXXMethodDecl *MD = getCanonicalDecl();
01382 
01383   if (MD->getStorageClass() == SC_Static)
01384     return true;
01385 
01386   OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator();
01387   return isStaticOverloadedOperator(OOK);
01388 }
01389 
01390 static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
01391                                  const CXXMethodDecl *BaseMD) {
01392   for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(),
01393          E = DerivedMD->end_overridden_methods(); I != E; ++I) {
01394     const CXXMethodDecl *MD = *I;
01395     if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
01396       return true;
01397     if (recursivelyOverrides(MD, BaseMD))
01398       return true;
01399   }
01400   return false;
01401 }
01402 
01403 CXXMethodDecl *
01404 CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD,
01405                                              bool MayBeBase) {
01406   if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
01407     return this;
01408 
01409   // Lookup doesn't work for destructors, so handle them separately.
01410   if (isa<CXXDestructorDecl>(this)) {
01411     CXXMethodDecl *MD = RD->getDestructor();
01412     if (MD) {
01413       if (recursivelyOverrides(MD, this))
01414         return MD;
01415       if (MayBeBase && recursivelyOverrides(this, MD))
01416         return MD;
01417     }
01418     return nullptr;
01419   }
01420 
01421   lookup_const_result Candidates = RD->lookup(getDeclName());
01422   for (NamedDecl * const * I = Candidates.begin(); I != Candidates.end(); ++I) {
01423     CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*I);
01424     if (!MD)
01425       continue;
01426     if (recursivelyOverrides(MD, this))
01427       return MD;
01428     if (MayBeBase && recursivelyOverrides(this, MD))
01429       return MD;
01430   }
01431 
01432   for (const auto &I : RD->bases()) {
01433     const RecordType *RT = I.getType()->getAs<RecordType>();
01434     if (!RT)
01435       continue;
01436     const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
01437     CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base);
01438     if (T)
01439       return T;
01440   }
01441 
01442   return nullptr;
01443 }
01444 
01445 CXXMethodDecl *
01446 CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
01447                       SourceLocation StartLoc,
01448                       const DeclarationNameInfo &NameInfo,
01449                       QualType T, TypeSourceInfo *TInfo,
01450                       StorageClass SC, bool isInline,
01451                       bool isConstexpr, SourceLocation EndLocation) {
01452   return new (C, RD) CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo,
01453                                    T, TInfo, SC, isInline, isConstexpr,
01454                                    EndLocation);
01455 }
01456 
01457 CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
01458   return new (C, ID) CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(),
01459                                    DeclarationNameInfo(), QualType(), nullptr,
01460                                    SC_None, false, false, SourceLocation());
01461 }
01462 
01463 bool CXXMethodDecl::isUsualDeallocationFunction() const {
01464   if (getOverloadedOperator() != OO_Delete &&
01465       getOverloadedOperator() != OO_Array_Delete)
01466     return false;
01467 
01468   // C++ [basic.stc.dynamic.deallocation]p2:
01469   //   A template instance is never a usual deallocation function,
01470   //   regardless of its signature.
01471   if (getPrimaryTemplate())
01472     return false;
01473 
01474   // C++ [basic.stc.dynamic.deallocation]p2:
01475   //   If a class T has a member deallocation function named operator delete 
01476   //   with exactly one parameter, then that function is a usual (non-placement)
01477   //   deallocation function. [...]
01478   if (getNumParams() == 1)
01479     return true;
01480   
01481   // C++ [basic.stc.dynamic.deallocation]p2:
01482   //   [...] If class T does not declare such an operator delete but does 
01483   //   declare a member deallocation function named operator delete with 
01484   //   exactly two parameters, the second of which has type std::size_t (18.1),
01485   //   then this function is a usual deallocation function.
01486   ASTContext &Context = getASTContext();
01487   if (getNumParams() != 2 ||
01488       !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(),
01489                                       Context.getSizeType()))
01490     return false;
01491                  
01492   // This function is a usual deallocation function if there are no 
01493   // single-parameter deallocation functions of the same kind.
01494   DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName());
01495   for (DeclContext::lookup_const_result::iterator I = R.begin(), E = R.end();
01496        I != E; ++I) {
01497     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I))
01498       if (FD->getNumParams() == 1)
01499         return false;
01500   }
01501   
01502   return true;
01503 }
01504 
01505 bool CXXMethodDecl::isCopyAssignmentOperator() const {
01506   // C++0x [class.copy]p17:
01507   //  A user-declared copy assignment operator X::operator= is a non-static 
01508   //  non-template member function of class X with exactly one parameter of 
01509   //  type X, X&, const X&, volatile X& or const volatile X&.
01510   if (/*operator=*/getOverloadedOperator() != OO_Equal ||
01511       /*non-static*/ isStatic() || 
01512       /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() ||
01513       getNumParams() != 1)
01514     return false;
01515       
01516   QualType ParamType = getParamDecl(0)->getType();
01517   if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>())
01518     ParamType = Ref->getPointeeType();
01519   
01520   ASTContext &Context = getASTContext();
01521   QualType ClassType
01522     = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
01523   return Context.hasSameUnqualifiedType(ClassType, ParamType);
01524 }
01525 
01526 bool CXXMethodDecl::isMoveAssignmentOperator() const {
01527   // C++0x [class.copy]p19:
01528   //  A user-declared move assignment operator X::operator= is a non-static
01529   //  non-template member function of class X with exactly one parameter of type
01530   //  X&&, const X&&, volatile X&&, or const volatile X&&.
01531   if (getOverloadedOperator() != OO_Equal || isStatic() ||
01532       getPrimaryTemplate() || getDescribedFunctionTemplate() ||
01533       getNumParams() != 1)
01534     return false;
01535 
01536   QualType ParamType = getParamDecl(0)->getType();
01537   if (!isa<RValueReferenceType>(ParamType))
01538     return false;
01539   ParamType = ParamType->getPointeeType();
01540 
01541   ASTContext &Context = getASTContext();
01542   QualType ClassType
01543     = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
01544   return Context.hasSameUnqualifiedType(ClassType, ParamType);
01545 }
01546 
01547 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
01548   assert(MD->isCanonicalDecl() && "Method is not canonical!");
01549   assert(!MD->getParent()->isDependentContext() &&
01550          "Can't add an overridden method to a class template!");
01551   assert(MD->isVirtual() && "Method is not virtual!");
01552 
01553   getASTContext().addOverriddenMethod(this, MD);
01554 }
01555 
01556 CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
01557   if (isa<CXXConstructorDecl>(this)) return nullptr;
01558   return getASTContext().overridden_methods_begin(this);
01559 }
01560 
01561 CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
01562   if (isa<CXXConstructorDecl>(this)) return nullptr;
01563   return getASTContext().overridden_methods_end(this);
01564 }
01565 
01566 unsigned CXXMethodDecl::size_overridden_methods() const {
01567   if (isa<CXXConstructorDecl>(this)) return 0;
01568   return getASTContext().overridden_methods_size(this);
01569 }
01570 
01571 QualType CXXMethodDecl::getThisType(ASTContext &C) const {
01572   // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
01573   // If the member function is declared const, the type of this is const X*,
01574   // if the member function is declared volatile, the type of this is
01575   // volatile X*, and if the member function is declared const volatile,
01576   // the type of this is const volatile X*.
01577 
01578   assert(isInstance() && "No 'this' for static methods!");
01579 
01580   QualType ClassTy = C.getTypeDeclType(getParent());
01581   ClassTy = C.getQualifiedType(ClassTy,
01582                                Qualifiers::fromCVRMask(getTypeQualifiers()));
01583   return C.getPointerType(ClassTy);
01584 }
01585 
01586 bool CXXMethodDecl::hasInlineBody() const {
01587   // If this function is a template instantiation, look at the template from 
01588   // which it was instantiated.
01589   const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
01590   if (!CheckFn)
01591     CheckFn = this;
01592   
01593   const FunctionDecl *fn;
01594   return CheckFn->hasBody(fn) && !fn->isOutOfLine();
01595 }
01596 
01597 bool CXXMethodDecl::isLambdaStaticInvoker() const {
01598   const CXXRecordDecl *P = getParent();
01599   if (P->isLambda()) {
01600     if (const CXXMethodDecl *StaticInvoker = P->getLambdaStaticInvoker()) {
01601       if (StaticInvoker == this) return true;
01602       if (P->isGenericLambda() && this->isFunctionTemplateSpecialization())
01603         return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl();
01604     }
01605   }
01606   return false;
01607 }
01608 
01609 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
01610                                        TypeSourceInfo *TInfo, bool IsVirtual,
01611                                        SourceLocation L, Expr *Init,
01612                                        SourceLocation R,
01613                                        SourceLocation EllipsisLoc)
01614   : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 
01615     LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 
01616     IsWritten(false), SourceOrderOrNumArrayIndices(0)
01617 {
01618 }
01619 
01620 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
01621                                        FieldDecl *Member,
01622                                        SourceLocation MemberLoc,
01623                                        SourceLocation L, Expr *Init,
01624                                        SourceLocation R)
01625   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
01626     LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
01627     IsWritten(false), SourceOrderOrNumArrayIndices(0)
01628 {
01629 }
01630 
01631 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
01632                                        IndirectFieldDecl *Member,
01633                                        SourceLocation MemberLoc,
01634                                        SourceLocation L, Expr *Init,
01635                                        SourceLocation R)
01636   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
01637     LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
01638     IsWritten(false), SourceOrderOrNumArrayIndices(0)
01639 {
01640 }
01641 
01642 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
01643                                        TypeSourceInfo *TInfo,
01644                                        SourceLocation L, Expr *Init, 
01645                                        SourceLocation R)
01646   : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init),
01647     LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false),
01648     IsWritten(false), SourceOrderOrNumArrayIndices(0)
01649 {
01650 }
01651 
01652 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
01653                                        FieldDecl *Member,
01654                                        SourceLocation MemberLoc,
01655                                        SourceLocation L, Expr *Init,
01656                                        SourceLocation R,
01657                                        VarDecl **Indices,
01658                                        unsigned NumIndices)
01659   : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 
01660     LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
01661     IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices)
01662 {
01663   VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
01664   memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *));
01665 }
01666 
01667 CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context,
01668                                                FieldDecl *Member, 
01669                                                SourceLocation MemberLoc,
01670                                                SourceLocation L, Expr *Init,
01671                                                SourceLocation R,
01672                                                VarDecl **Indices,
01673                                                unsigned NumIndices) {
01674   void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) +
01675                                sizeof(VarDecl *) * NumIndices,
01676                                llvm::alignOf<CXXCtorInitializer>());
01677   return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R,
01678                                       Indices, NumIndices);
01679 }
01680 
01681 TypeLoc CXXCtorInitializer::getBaseClassLoc() const {
01682   if (isBaseInitializer())
01683     return Initializee.get<TypeSourceInfo*>()->getTypeLoc();
01684   else
01685     return TypeLoc();
01686 }
01687 
01688 const Type *CXXCtorInitializer::getBaseClass() const {
01689   if (isBaseInitializer())
01690     return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr();
01691   else
01692     return nullptr;
01693 }
01694 
01695 SourceLocation CXXCtorInitializer::getSourceLocation() const {
01696   if (isAnyMemberInitializer())
01697     return getMemberLocation();
01698 
01699   if (isInClassMemberInitializer())
01700     return getAnyMember()->getLocation();
01701   
01702   if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>())
01703     return TSInfo->getTypeLoc().getLocalSourceRange().getBegin();
01704   
01705   return SourceLocation();
01706 }
01707 
01708 SourceRange CXXCtorInitializer::getSourceRange() const {
01709   if (isInClassMemberInitializer()) {
01710     FieldDecl *D = getAnyMember();
01711     if (Expr *I = D->getInClassInitializer())
01712       return I->getSourceRange();
01713     return SourceRange();
01714   }
01715 
01716   return SourceRange(getSourceLocation(), getRParenLoc());
01717 }
01718 
01719 void CXXConstructorDecl::anchor() { }
01720 
01721 CXXConstructorDecl *
01722 CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
01723   return new (C, ID) CXXConstructorDecl(C, nullptr, SourceLocation(),
01724                                         DeclarationNameInfo(), QualType(),
01725                                         nullptr, false, false, false, false);
01726 }
01727 
01728 CXXConstructorDecl *
01729 CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
01730                            SourceLocation StartLoc,
01731                            const DeclarationNameInfo &NameInfo,
01732                            QualType T, TypeSourceInfo *TInfo,
01733                            bool isExplicit, bool isInline,
01734                            bool isImplicitlyDeclared, bool isConstexpr) {
01735   assert(NameInfo.getName().getNameKind()
01736          == DeclarationName::CXXConstructorName &&
01737          "Name must refer to a constructor");
01738   return new (C, RD) CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo,
01739                                         isExplicit, isInline,
01740                                         isImplicitlyDeclared, isConstexpr);
01741 }
01742 
01743 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
01744   assert(isDelegatingConstructor() && "Not a delegating constructor!");
01745   Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
01746   if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E))
01747     return Construct->getConstructor();
01748 
01749   return nullptr;
01750 }
01751 
01752 bool CXXConstructorDecl::isDefaultConstructor() const {
01753   // C++ [class.ctor]p5:
01754   //   A default constructor for a class X is a constructor of class
01755   //   X that can be called without an argument.
01756   return (getNumParams() == 0) ||
01757          (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg());
01758 }
01759 
01760 bool
01761 CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
01762   return isCopyOrMoveConstructor(TypeQuals) &&
01763          getParamDecl(0)->getType()->isLValueReferenceType();
01764 }
01765 
01766 bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
01767   return isCopyOrMoveConstructor(TypeQuals) &&
01768     getParamDecl(0)->getType()->isRValueReferenceType();
01769 }
01770 
01771 /// \brief Determine whether this is a copy or move constructor.
01772 bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
01773   // C++ [class.copy]p2:
01774   //   A non-template constructor for class X is a copy constructor
01775   //   if its first parameter is of type X&, const X&, volatile X& or
01776   //   const volatile X&, and either there are no other parameters
01777   //   or else all other parameters have default arguments (8.3.6).
01778   // C++0x [class.copy]p3:
01779   //   A non-template constructor for class X is a move constructor if its
01780   //   first parameter is of type X&&, const X&&, volatile X&&, or 
01781   //   const volatile X&&, and either there are no other parameters or else 
01782   //   all other parameters have default arguments.
01783   if ((getNumParams() < 1) ||
01784       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
01785       (getPrimaryTemplate() != nullptr) ||
01786       (getDescribedFunctionTemplate() != nullptr))
01787     return false;
01788   
01789   const ParmVarDecl *Param = getParamDecl(0);
01790   
01791   // Do we have a reference type? 
01792   const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>();
01793   if (!ParamRefType)
01794     return false;
01795   
01796   // Is it a reference to our class type?
01797   ASTContext &Context = getASTContext();
01798   
01799   CanQualType PointeeType
01800     = Context.getCanonicalType(ParamRefType->getPointeeType());
01801   CanQualType ClassTy 
01802     = Context.getCanonicalType(Context.getTagDeclType(getParent()));
01803   if (PointeeType.getUnqualifiedType() != ClassTy)
01804     return false;
01805   
01806   // FIXME: other qualifiers?
01807   
01808   // We have a copy or move constructor.
01809   TypeQuals = PointeeType.getCVRQualifiers();
01810   return true;  
01811 }
01812 
01813 bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
01814   // C++ [class.conv.ctor]p1:
01815   //   A constructor declared without the function-specifier explicit
01816   //   that can be called with a single parameter specifies a
01817   //   conversion from the type of its first parameter to the type of
01818   //   its class. Such a constructor is called a converting
01819   //   constructor.
01820   if (isExplicit() && !AllowExplicit)
01821     return false;
01822 
01823   return (getNumParams() == 0 &&
01824           getType()->getAs<FunctionProtoType>()->isVariadic()) ||
01825          (getNumParams() == 1) ||
01826          (getNumParams() > 1 &&
01827           (getParamDecl(1)->hasDefaultArg() ||
01828            getParamDecl(1)->isParameterPack()));
01829 }
01830 
01831 bool CXXConstructorDecl::isSpecializationCopyingObject() const {
01832   if ((getNumParams() < 1) ||
01833       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
01834       (getPrimaryTemplate() == nullptr) ||
01835       (getDescribedFunctionTemplate() != nullptr))
01836     return false;
01837 
01838   const ParmVarDecl *Param = getParamDecl(0);
01839 
01840   ASTContext &Context = getASTContext();
01841   CanQualType ParamType = Context.getCanonicalType(Param->getType());
01842   
01843   // Is it the same as our our class type?
01844   CanQualType ClassTy 
01845     = Context.getCanonicalType(Context.getTagDeclType(getParent()));
01846   if (ParamType.getUnqualifiedType() != ClassTy)
01847     return false;
01848   
01849   return true;  
01850 }
01851 
01852 const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const {
01853   // Hack: we store the inherited constructor in the overridden method table
01854   method_iterator It = getASTContext().overridden_methods_begin(this);
01855   if (It == getASTContext().overridden_methods_end(this))
01856     return nullptr;
01857 
01858   return cast<CXXConstructorDecl>(*It);
01859 }
01860 
01861 void
01862 CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){
01863   // Hack: we store the inherited constructor in the overridden method table
01864   assert(getASTContext().overridden_methods_size(this) == 0 &&
01865          "Base ctor already set.");
01866   getASTContext().addOverriddenMethod(this, BaseCtor);
01867 }
01868 
01869 void CXXDestructorDecl::anchor() { }
01870 
01871 CXXDestructorDecl *
01872 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
01873   return new (C, ID)
01874       CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(),
01875                         QualType(), nullptr, false, false);
01876 }
01877 
01878 CXXDestructorDecl *
01879 CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
01880                           SourceLocation StartLoc,
01881                           const DeclarationNameInfo &NameInfo,
01882                           QualType T, TypeSourceInfo *TInfo,
01883                           bool isInline, bool isImplicitlyDeclared) {
01884   assert(NameInfo.getName().getNameKind()
01885          == DeclarationName::CXXDestructorName &&
01886          "Name must refer to a destructor");
01887   return new (C, RD) CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo,
01888                                        isInline, isImplicitlyDeclared);
01889 }
01890 
01891 void CXXConversionDecl::anchor() { }
01892 
01893 CXXConversionDecl *
01894 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
01895   return new (C, ID) CXXConversionDecl(C, nullptr, SourceLocation(),
01896                                        DeclarationNameInfo(), QualType(),
01897                                        nullptr, false, false, false,
01898                                        SourceLocation());
01899 }
01900 
01901 CXXConversionDecl *
01902 CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
01903                           SourceLocation StartLoc,
01904                           const DeclarationNameInfo &NameInfo,
01905                           QualType T, TypeSourceInfo *TInfo,
01906                           bool isInline, bool isExplicit,
01907                           bool isConstexpr, SourceLocation EndLocation) {
01908   assert(NameInfo.getName().getNameKind()
01909          == DeclarationName::CXXConversionFunctionName &&
01910          "Name must refer to a conversion function");
01911   return new (C, RD) CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo,
01912                                        isInline, isExplicit, isConstexpr,
01913                                        EndLocation);
01914 }
01915 
01916 bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
01917   return isImplicit() && getParent()->isLambda() &&
01918          getConversionType()->isBlockPointerType();
01919 }
01920 
01921 void LinkageSpecDecl::anchor() { }
01922 
01923 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
01924                                          DeclContext *DC,
01925                                          SourceLocation ExternLoc,
01926                                          SourceLocation LangLoc,
01927                                          LanguageIDs Lang,
01928                                          bool HasBraces) {
01929   return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
01930 }
01931 
01932 LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C,
01933                                                      unsigned ID) {
01934   return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(),
01935                                      SourceLocation(), lang_c, false);
01936 }
01937 
01938 void UsingDirectiveDecl::anchor() { }
01939 
01940 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
01941                                                SourceLocation L,
01942                                                SourceLocation NamespaceLoc,
01943                                            NestedNameSpecifierLoc QualifierLoc,
01944                                                SourceLocation IdentLoc,
01945                                                NamedDecl *Used,
01946                                                DeclContext *CommonAncestor) {
01947   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
01948     Used = NS->getOriginalNamespace();
01949   return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
01950                                         IdentLoc, Used, CommonAncestor);
01951 }
01952 
01953 UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C,
01954                                                            unsigned ID) {
01955   return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
01956                                         SourceLocation(),
01957                                         NestedNameSpecifierLoc(),
01958                                         SourceLocation(), nullptr, nullptr);
01959 }
01960 
01961 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
01962   if (NamespaceAliasDecl *NA =
01963         dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
01964     return NA->getNamespace();
01965   return cast_or_null<NamespaceDecl>(NominatedNamespace);
01966 }
01967 
01968 NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
01969                              SourceLocation StartLoc, SourceLocation IdLoc,
01970                              IdentifierInfo *Id, NamespaceDecl *PrevDecl)
01971     : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
01972       redeclarable_base(C), LocStart(StartLoc), RBraceLoc(),
01973       AnonOrFirstNamespaceAndInline(nullptr, Inline) {
01974   setPreviousDecl(PrevDecl);
01975 
01976   if (PrevDecl)
01977     AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace());
01978 }
01979 
01980 NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
01981                                      bool Inline, SourceLocation StartLoc,
01982                                      SourceLocation IdLoc, IdentifierInfo *Id,
01983                                      NamespaceDecl *PrevDecl) {
01984   return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id,
01985                                    PrevDecl);
01986 }
01987 
01988 NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
01989   return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
01990                                    SourceLocation(), nullptr, nullptr);
01991 }
01992 
01993 NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
01994   return getNextRedeclaration();
01995 }
01996 NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
01997   return getPreviousDecl();
01998 }
01999 NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
02000   return getMostRecentDecl();
02001 }
02002 
02003 void NamespaceAliasDecl::anchor() { }
02004 
02005 NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
02006   return getNextRedeclaration();
02007 }
02008 NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
02009   return getPreviousDecl();
02010 }
02011 NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
02012   return getMostRecentDecl();
02013 }
02014 
02015 NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
02016                                                SourceLocation UsingLoc,
02017                                                SourceLocation AliasLoc,
02018                                                IdentifierInfo *Alias,
02019                                            NestedNameSpecifierLoc QualifierLoc,
02020                                                SourceLocation IdentLoc,
02021                                                NamedDecl *Namespace) {
02022   // FIXME: Preserve the aliased namespace as written.
02023   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
02024     Namespace = NS->getOriginalNamespace();
02025   return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
02026                                         QualifierLoc, IdentLoc, Namespace);
02027 }
02028 
02029 NamespaceAliasDecl *
02030 NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
02031   return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
02032                                         SourceLocation(), nullptr,
02033                                         NestedNameSpecifierLoc(),
02034                                         SourceLocation(), nullptr);
02035 }
02036 
02037 void UsingShadowDecl::anchor() { }
02038 
02039 UsingShadowDecl *
02040 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
02041   return new (C, ID) UsingShadowDecl(C, nullptr, SourceLocation(),
02042                                      nullptr, nullptr);
02043 }
02044 
02045 UsingDecl *UsingShadowDecl::getUsingDecl() const {
02046   const UsingShadowDecl *Shadow = this;
02047   while (const UsingShadowDecl *NextShadow =
02048          dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
02049     Shadow = NextShadow;
02050   return cast<UsingDecl>(Shadow->UsingOrNextShadow);
02051 }
02052 
02053 void UsingDecl::anchor() { }
02054 
02055 void UsingDecl::addShadowDecl(UsingShadowDecl *S) {
02056   assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() &&
02057          "declaration already in set");
02058   assert(S->getUsingDecl() == this);
02059 
02060   if (FirstUsingShadow.getPointer())
02061     S->UsingOrNextShadow = FirstUsingShadow.getPointer();
02062   FirstUsingShadow.setPointer(S);
02063 }
02064 
02065 void UsingDecl::removeShadowDecl(UsingShadowDecl *S) {
02066   assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() &&
02067          "declaration not in set");
02068   assert(S->getUsingDecl() == this);
02069 
02070   // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
02071 
02072   if (FirstUsingShadow.getPointer() == S) {
02073     FirstUsingShadow.setPointer(
02074       dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
02075     S->UsingOrNextShadow = this;
02076     return;
02077   }
02078 
02079   UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
02080   while (Prev->UsingOrNextShadow != S)
02081     Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
02082   Prev->UsingOrNextShadow = S->UsingOrNextShadow;
02083   S->UsingOrNextShadow = this;
02084 }
02085 
02086 UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL,
02087                              NestedNameSpecifierLoc QualifierLoc,
02088                              const DeclarationNameInfo &NameInfo,
02089                              bool HasTypename) {
02090   return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
02091 }
02092 
02093 UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
02094   return new (C, ID) UsingDecl(nullptr, SourceLocation(),
02095                                NestedNameSpecifierLoc(), DeclarationNameInfo(),
02096                                false);
02097 }
02098 
02099 SourceRange UsingDecl::getSourceRange() const {
02100   SourceLocation Begin = isAccessDeclaration()
02101     ? getQualifierLoc().getBeginLoc() : UsingLocation;
02102   return SourceRange(Begin, getNameInfo().getEndLoc());
02103 }
02104 
02105 void UnresolvedUsingValueDecl::anchor() { }
02106 
02107 UnresolvedUsingValueDecl *
02108 UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
02109                                  SourceLocation UsingLoc,
02110                                  NestedNameSpecifierLoc QualifierLoc,
02111                                  const DeclarationNameInfo &NameInfo) {
02112   return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
02113                                               QualifierLoc, NameInfo);
02114 }
02115 
02116 UnresolvedUsingValueDecl *
02117 UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
02118   return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
02119                                               SourceLocation(),
02120                                               NestedNameSpecifierLoc(),
02121                                               DeclarationNameInfo());
02122 }
02123 
02124 SourceRange UnresolvedUsingValueDecl::getSourceRange() const {
02125   SourceLocation Begin = isAccessDeclaration()
02126     ? getQualifierLoc().getBeginLoc() : UsingLocation;
02127   return SourceRange(Begin, getNameInfo().getEndLoc());
02128 }
02129 
02130 void UnresolvedUsingTypenameDecl::anchor() { }
02131 
02132 UnresolvedUsingTypenameDecl *
02133 UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
02134                                     SourceLocation UsingLoc,
02135                                     SourceLocation TypenameLoc,
02136                                     NestedNameSpecifierLoc QualifierLoc,
02137                                     SourceLocation TargetNameLoc,
02138                                     DeclarationName TargetName) {
02139   return new (C, DC) UnresolvedUsingTypenameDecl(
02140       DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
02141       TargetName.getAsIdentifierInfo());
02142 }
02143 
02144 UnresolvedUsingTypenameDecl *
02145 UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
02146   return new (C, ID) UnresolvedUsingTypenameDecl(
02147       nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(),
02148       SourceLocation(), nullptr);
02149 }
02150 
02151 void StaticAssertDecl::anchor() { }
02152 
02153 StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
02154                                            SourceLocation StaticAssertLoc,
02155                                            Expr *AssertExpr,
02156                                            StringLiteral *Message,
02157                                            SourceLocation RParenLoc,
02158                                            bool Failed) {
02159   return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
02160                                       RParenLoc, Failed);
02161 }
02162 
02163 StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C,
02164                                                        unsigned ID) {
02165   return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
02166                                       nullptr, SourceLocation(), false);
02167 }
02168 
02169 MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC,
02170                                        SourceLocation L, DeclarationName N,
02171                                        QualType T, TypeSourceInfo *TInfo,
02172                                        SourceLocation StartL,
02173                                        IdentifierInfo *Getter,
02174                                        IdentifierInfo *Setter) {
02175   return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
02176 }
02177 
02178 MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C,
02179                                                    unsigned ID) {
02180   return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
02181                                     DeclarationName(), QualType(), nullptr,
02182                                     SourceLocation(), nullptr, nullptr);
02183 }
02184 
02185 static const char *getAccessName(AccessSpecifier AS) {
02186   switch (AS) {
02187     case AS_none:
02188       llvm_unreachable("Invalid access specifier!");
02189     case AS_public:
02190       return "public";
02191     case AS_private:
02192       return "private";
02193     case AS_protected:
02194       return "protected";
02195   }
02196   llvm_unreachable("Invalid access specifier!");
02197 }
02198 
02199 const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
02200                                            AccessSpecifier AS) {
02201   return DB << getAccessName(AS);
02202 }
02203 
02204 const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB,
02205                                            AccessSpecifier AS) {
02206   return DB << getAccessName(AS);
02207 }