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