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