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