Ted Kremenek | 4b7c983 | 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 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 21 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 22 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/STLExtras.h" |
Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallPtrSet.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | // Decl Allocation/Deallocation Method Implementations |
| 29 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 30 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 31 | void AccessSpecDecl::anchor() { } |
| 32 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 33 | AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 34 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(AccessSpecDecl)); |
| 35 | return new (Mem) AccessSpecDecl(EmptyShell()); |
| 36 | } |
| 37 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 38 | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 39 | : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), |
Eli Friedman | 97c134e | 2009-08-15 22:23:00 +0000 | [diff] [blame] | 40 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 41 | Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true), |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 42 | HasPrivateFields(false), HasProtectedFields(false), HasPublicFields(false), |
Argyrios Kyrtzidis | 4fe19b5 | 2012-01-26 18:28:08 +0000 | [diff] [blame] | 43 | HasMutableFields(false), HasOnlyCMembers(true), |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 44 | HasInClassInitializer(false), |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 45 | HasTrivialSpecialMembers(SMF_All), |
| 46 | HasIrrelevantDestructor(true), |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 47 | HasConstexprNonCopyMoveConstructor(false), |
| 48 | DefaultedDefaultConstructorIsConstexpr(true), |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 49 | HasConstexprDefaultConstructor(false), |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 50 | HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false), |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 51 | UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 52 | ImplicitCopyConstructorHasConstParam(true), |
| 53 | ImplicitCopyAssignmentHasConstParam(true), |
| 54 | HasDeclaredCopyConstructorWithConstParam(false), |
| 55 | HasDeclaredCopyAssignmentWithConstParam(false), |
| 56 | FailedImplicitMoveConstructor(false), FailedImplicitMoveAssignment(false), |
| 57 | IsLambda(false), NumBases(0), NumVBases(0), Bases(), VBases(), |
| 58 | Definition(D), FirstFriend(0) { |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Benjamin Kramer | ee3096a | 2012-07-04 17:03:33 +0000 | [diff] [blame] | 61 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { |
| 62 | return Bases.get(Definition->getASTContext().getExternalSource()); |
| 63 | } |
| 64 | |
| 65 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { |
| 66 | return VBases.get(Definition->getASTContext().getExternalSource()); |
| 67 | } |
| 68 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 69 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 70 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 71 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl) |
| 72 | : RecordDecl(K, TK, DC, StartLoc, IdLoc, Id, PrevDecl), |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 73 | DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 74 | TemplateOrInstantiation() { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 75 | |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 76 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 77 | DeclContext *DC, SourceLocation StartLoc, |
| 78 | SourceLocation IdLoc, IdentifierInfo *Id, |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 79 | CXXRecordDecl* PrevDecl, |
| 80 | bool DelayTypeCreation) { |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 81 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, StartLoc, IdLoc, |
| 82 | Id, PrevDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 84 | // FIXME: DelayTypeCreation seems like such a hack |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 85 | if (!DelayTypeCreation) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | C.getTypeDeclType(R, PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 87 | return R; |
| 88 | } |
| 89 | |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 90 | CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 91 | TypeSourceInfo *Info, SourceLocation Loc, |
| 92 | bool Dependent) { |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 93 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TTK_Class, DC, Loc, Loc, |
| 94 | 0, 0); |
| 95 | R->IsBeingDefined = true; |
Eli Friedman | 8da8a66 | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 96 | R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, Dependent); |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 97 | C.getTypeDeclType(R, /*PrevDecl=*/0); |
| 98 | return R; |
| 99 | } |
| 100 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 101 | CXXRecordDecl * |
| 102 | CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
| 103 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXRecordDecl)); |
| 104 | return new (Mem) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), |
| 105 | SourceLocation(), 0, 0); |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | void |
Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 109 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 110 | unsigned NumBases) { |
Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 111 | ASTContext &C = getASTContext(); |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 113 | if (!data().Bases.isOffset() && data().NumBases > 0) |
| 114 | C.Deallocate(data().getBases()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Richard Smith | dd67723 | 2011-10-18 20:08:55 +0000 | [diff] [blame] | 116 | if (NumBases) { |
| 117 | // C++ [dcl.init.aggr]p1: |
| 118 | // An aggregate is [...] a class with [...] no base classes [...]. |
| 119 | data().Aggregate = false; |
| 120 | |
| 121 | // C++ [class]p4: |
| 122 | // A POD-struct is an aggregate class... |
| 123 | data().PlainOldData = false; |
| 124 | } |
| 125 | |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 126 | // The set of seen virtual base types. |
Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 127 | llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 128 | |
| 129 | // The virtual bases of this class. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 130 | SmallVector<const CXXBaseSpecifier *, 8> VBases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 132 | data().Bases = new(C) CXXBaseSpecifier [NumBases]; |
| 133 | data().NumBases = NumBases; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 134 | for (unsigned i = 0; i < NumBases; ++i) { |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 135 | data().getBases()[i] = *Bases[i]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 136 | // Keep track of inherited vbases for this base class. |
| 137 | const CXXBaseSpecifier *Base = Bases[i]; |
| 138 | QualType BaseType = Base->getType(); |
Douglas Gregor | 5fe8c04 | 2010-02-27 00:25:28 +0000 | [diff] [blame] | 139 | // Skip dependent types; we can't do any checking on them now. |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 140 | if (BaseType->isDependentType()) |
| 141 | continue; |
| 142 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 143 | = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 144 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 145 | // A class with a non-empty base class is not empty. |
| 146 | // FIXME: Standard ref? |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 147 | if (!BaseClassDecl->isEmpty()) { |
| 148 | if (!data().Empty) { |
| 149 | // C++0x [class]p7: |
| 150 | // A standard-layout class is a class that: |
| 151 | // [...] |
| 152 | // -- either has no non-static data members in the most derived |
| 153 | // class and at most one base class with non-static data members, |
| 154 | // or has no base classes with non-static data members, and |
| 155 | // If this is the second non-empty base, then neither of these two |
| 156 | // clauses can be true. |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 157 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 160 | data().Empty = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 161 | data().HasNoNonEmptyBases = false; |
| 162 | } |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 163 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 164 | // C++ [class.virtual]p1: |
| 165 | // A class that declares or inherits a virtual function is called a |
| 166 | // polymorphic class. |
| 167 | if (BaseClassDecl->isPolymorphic()) |
| 168 | data().Polymorphic = true; |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 169 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 170 | // C++0x [class]p7: |
| 171 | // A standard-layout class is a class that: [...] |
| 172 | // -- has no non-standard-layout base classes |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 173 | if (!BaseClassDecl->isStandardLayout()) |
| 174 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 175 | |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 176 | // Record if this base is the first non-literal field or base. |
| 177 | if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType()) |
| 178 | data().HasNonLiteralTypeFieldsOrBases = true; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 179 | |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 180 | // Now go through all virtual bases of this base and add them. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | for (CXXRecordDecl::base_class_iterator VBase = |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 182 | BaseClassDecl->vbases_begin(), |
| 183 | E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 184 | // Add this base if it's not already in the list. |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 185 | if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType()))) { |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 186 | VBases.push_back(VBase); |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 187 | |
| 188 | // C++11 [class.copy]p8: |
| 189 | // The implicitly-declared copy constructor for a class X will have |
| 190 | // the form 'X::X(const X&)' if each [...] virtual base class B of X |
| 191 | // has a copy constructor whose first parameter is of type |
| 192 | // 'const B&' or 'const volatile B&' [...] |
| 193 | if (CXXRecordDecl *VBaseDecl = VBase->getType()->getAsCXXRecordDecl()) |
| 194 | if (!VBaseDecl->hasCopyConstructorWithConstParam()) |
| 195 | data().ImplicitCopyConstructorHasConstParam = false; |
| 196 | } |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 197 | } |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 198 | |
| 199 | if (Base->isVirtual()) { |
| 200 | // Add this base if it's not already in the list. |
Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 201 | if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType))) |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 202 | VBases.push_back(Base); |
| 203 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 204 | // C++0x [meta.unary.prop] is_empty: |
| 205 | // T is a class type, but not a union type, with ... no virtual base |
| 206 | // classes |
| 207 | data().Empty = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 208 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 209 | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: |
| 210 | // A [default constructor, copy/move constructor, or copy/move assignment |
| 211 | // operator for a class X] is trivial [...] if: |
| 212 | // -- class X has [...] no virtual base classes |
| 213 | data().HasTrivialSpecialMembers &= SMF_Destructor; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 214 | |
| 215 | // C++0x [class]p7: |
| 216 | // A standard-layout class is a class that: [...] |
| 217 | // -- has [...] no virtual base classes |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 218 | data().IsStandardLayout = false; |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 219 | |
| 220 | // C++11 [dcl.constexpr]p4: |
| 221 | // In the definition of a constexpr constructor [...] |
| 222 | // -- the class shall not have any virtual base classes |
| 223 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 224 | } else { |
| 225 | // C++ [class.ctor]p5: |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 226 | // A default constructor is trivial [...] if: |
| 227 | // -- all the direct base classes of its class have trivial default |
| 228 | // constructors. |
| 229 | if (!BaseClassDecl->hasTrivialDefaultConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 230 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
| 231 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 232 | // C++0x [class.copy]p13: |
| 233 | // A copy/move constructor for class X is trivial if [...] |
| 234 | // [...] |
| 235 | // -- the constructor selected to copy/move each direct base class |
| 236 | // subobject is trivial, and |
| 237 | // FIXME: C++0x: We need to only consider the selected constructor |
Richard Smith | 93af2b8 | 2012-11-14 07:36:28 +0000 | [diff] [blame] | 238 | // instead of all of them. For now, we treat a move constructor as being |
| 239 | // non-trivial if it calls anything other than a trivial move constructor. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 240 | if (!BaseClassDecl->hasTrivialCopyConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 241 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 242 | if (!BaseClassDecl->hasTrivialMoveConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 243 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 244 | |
| 245 | // C++0x [class.copy]p27: |
| 246 | // A copy/move assignment operator for class X is trivial if [...] |
| 247 | // [...] |
| 248 | // -- the assignment operator selected to copy/move each direct base |
| 249 | // class subobject is trivial, and |
| 250 | // FIXME: C++0x: We need to only consider the selected operator instead |
| 251 | // of all of them. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 252 | if (!BaseClassDecl->hasTrivialCopyAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 253 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 254 | if (!BaseClassDecl->hasTrivialMoveAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 255 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 256 | |
| 257 | // C++11 [class.ctor]p6: |
Richard Smith | de8facc | 2012-01-11 18:26:05 +0000 | [diff] [blame] | 258 | // If that user-written default constructor would satisfy the |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 259 | // requirements of a constexpr constructor, the implicitly-defined |
| 260 | // default constructor is constexpr. |
| 261 | if (!BaseClassDecl->hasConstexprDefaultConstructor()) |
| 262 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 263 | } |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 264 | |
| 265 | // C++ [class.ctor]p3: |
| 266 | // A destructor is trivial if all the direct base classes of its class |
| 267 | // have trivial destructors. |
| 268 | if (!BaseClassDecl->hasTrivialDestructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 269 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 270 | |
| 271 | if (!BaseClassDecl->hasIrrelevantDestructor()) |
| 272 | data().HasIrrelevantDestructor = false; |
| 273 | |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 274 | // C++11 [class.copy]p18: |
| 275 | // The implicitly-declared copy assignment oeprator for a class X will |
| 276 | // have the form 'X& X::operator=(const X&)' if each direct base class B |
| 277 | // of X has a copy assignment operator whose parameter is of type 'const |
| 278 | // B&', 'const volatile B&', or 'B' [...] |
| 279 | if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) |
| 280 | data().ImplicitCopyAssignmentHasConstParam = false; |
| 281 | |
| 282 | // C++11 [class.copy]p8: |
| 283 | // The implicitly-declared copy constructor for a class X will have |
| 284 | // the form 'X::X(const X&)' if each direct [...] base class B of X |
| 285 | // has a copy constructor whose first parameter is of type |
| 286 | // 'const B&' or 'const volatile B&' [...] |
| 287 | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) |
| 288 | data().ImplicitCopyConstructorHasConstParam = false; |
| 289 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 290 | // A class has an Objective-C object member if... or any of its bases |
| 291 | // has an Objective-C object member. |
| 292 | if (BaseClassDecl->hasObjectMember()) |
| 293 | setHasObjectMember(true); |
| 294 | |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 295 | // Keep track of the presence of mutable fields. |
| 296 | if (BaseClassDecl->hasMutableFields()) |
| 297 | data().HasMutableFields = true; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 298 | } |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 299 | |
| 300 | if (VBases.empty()) |
| 301 | return; |
| 302 | |
| 303 | // Create base specifier for any direct or indirect virtual bases. |
| 304 | data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; |
| 305 | data().NumVBases = VBases.size(); |
Richard Smith | 9f8ee2e | 2011-07-12 23:49:11 +0000 | [diff] [blame] | 306 | for (int I = 0, E = VBases.size(); I != E; ++I) |
| 307 | data().getVBases()[I] = *VBases[I]; |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Douglas Gregor | 9edad9b | 2010-01-14 17:47:39 +0000 | [diff] [blame] | 310 | /// Callback function for CXXRecordDecl::forallBases that acknowledges |
| 311 | /// that it saw a base class. |
| 312 | static bool SawBase(const CXXRecordDecl *, void *) { |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | bool CXXRecordDecl::hasAnyDependentBases() const { |
| 317 | if (!isDependentContext()) |
| 318 | return false; |
| 319 | |
| 320 | return !forallBases(SawBase, 0); |
| 321 | } |
| 322 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 323 | bool CXXRecordDecl::hasConstCopyConstructor() const { |
| 324 | return getCopyConstructor(Qualifiers::Const) != 0; |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 327 | bool CXXRecordDecl::isTriviallyCopyable() const { |
| 328 | // C++0x [class]p5: |
| 329 | // A trivially copyable class is a class that: |
| 330 | // -- has no non-trivial copy constructors, |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 331 | if (hasNonTrivialCopyConstructor()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 332 | // -- has no non-trivial move constructors, |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 333 | if (hasNonTrivialMoveConstructor()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 334 | // -- has no non-trivial copy assignment operators, |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 335 | if (hasNonTrivialCopyAssignment()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 336 | // -- has no non-trivial move assignment operators, and |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 337 | if (hasNonTrivialMoveAssignment()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 338 | // -- has a trivial destructor. |
| 339 | if (!hasTrivialDestructor()) return false; |
| 340 | |
| 341 | return true; |
| 342 | } |
| 343 | |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 344 | /// \brief Perform a simplistic form of overload resolution that only considers |
| 345 | /// cv-qualifiers on a single parameter, and return the best overload candidate |
| 346 | /// (if there is one). |
| 347 | static CXXMethodDecl * |
| 348 | GetBestOverloadCandidateSimple( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 349 | const SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) { |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 350 | if (Cands.empty()) |
| 351 | return 0; |
| 352 | if (Cands.size() == 1) |
| 353 | return Cands[0].first; |
| 354 | |
| 355 | unsigned Best = 0, N = Cands.size(); |
| 356 | for (unsigned I = 1; I != N; ++I) |
Douglas Gregor | 61d0b6b | 2011-04-28 00:56:09 +0000 | [diff] [blame] | 357 | if (Cands[Best].second.compatiblyIncludes(Cands[I].second)) |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 358 | Best = I; |
| 359 | |
Benjamin Kramer | 2cd7f41 | 2012-07-30 15:53:26 +0000 | [diff] [blame] | 360 | for (unsigned I = 0; I != N; ++I) |
| 361 | if (I != Best && Cands[Best].second.compatiblyIncludes(Cands[I].second)) |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | |
| 364 | return Cands[Best].first; |
| 365 | } |
| 366 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 367 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(unsigned TypeQuals) const{ |
| 368 | ASTContext &Context = getASTContext(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 369 | QualType ClassType |
| 370 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | DeclarationName ConstructorName |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 372 | = Context.DeclarationNames.getCXXConstructorName( |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 373 | Context.getCanonicalType(ClassType)); |
| 374 | unsigned FoundTQs; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 375 | SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 376 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 377 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 378 | Con != ConEnd; ++Con) { |
Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 379 | // C++ [class.copy]p2: |
| 380 | // A non-template constructor for class X is a copy constructor if [...] |
| 381 | if (isa<FunctionTemplateDecl>(*Con)) |
| 382 | continue; |
| 383 | |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 384 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 385 | if (Constructor->isCopyConstructor(FoundTQs)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 386 | if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) || |
| 387 | (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const))) |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 388 | Found.push_back(std::make_pair( |
| 389 | const_cast<CXXConstructorDecl *>(Constructor), |
| 390 | Qualifiers::fromCVRMask(FoundTQs))); |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 391 | } |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 392 | } |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 393 | |
| 394 | return cast_or_null<CXXConstructorDecl>( |
| 395 | GetBestOverloadCandidateSimple(Found)); |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 398 | CXXConstructorDecl *CXXRecordDecl::getMoveConstructor() const { |
| 399 | for (ctor_iterator I = ctor_begin(), E = ctor_end(); I != E; ++I) |
| 400 | if (I->isMoveConstructor()) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 401 | return *I; |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
Douglas Gregor | b87786f | 2010-07-01 17:48:08 +0000 | [diff] [blame] | 406 | CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const { |
| 407 | ASTContext &Context = getASTContext(); |
| 408 | QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this)); |
| 409 | DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 410 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 411 | SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; |
Douglas Gregor | b87786f | 2010-07-01 17:48:08 +0000 | [diff] [blame] | 412 | DeclContext::lookup_const_iterator Op, OpEnd; |
| 413 | for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) { |
| 414 | // C++ [class.copy]p9: |
| 415 | // A user-declared copy assignment operator is a non-static non-template |
| 416 | // member function of class X with exactly one parameter of type X, X&, |
| 417 | // const X&, volatile X& or const volatile X&. |
| 418 | const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op); |
| 419 | if (!Method || Method->isStatic() || Method->getPrimaryTemplate()) |
| 420 | continue; |
| 421 | |
| 422 | const FunctionProtoType *FnType |
| 423 | = Method->getType()->getAs<FunctionProtoType>(); |
| 424 | assert(FnType && "Overloaded operator has no prototype."); |
| 425 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 426 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 427 | continue; |
| 428 | |
| 429 | QualType ArgType = FnType->getArgType(0); |
| 430 | Qualifiers Quals; |
| 431 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { |
| 432 | ArgType = Ref->getPointeeType(); |
| 433 | // If we have a const argument and we have a reference to a non-const, |
| 434 | // this function does not match. |
| 435 | if (ArgIsConst && !ArgType.isConstQualified()) |
| 436 | continue; |
| 437 | |
| 438 | Quals = ArgType.getQualifiers(); |
| 439 | } else { |
| 440 | // By-value copy-assignment operators are treated like const X& |
| 441 | // copy-assignment operators. |
| 442 | Quals = Qualifiers::fromCVRMask(Qualifiers::Const); |
| 443 | } |
| 444 | |
| 445 | if (!Context.hasSameUnqualifiedType(ArgType, Class)) |
| 446 | continue; |
| 447 | |
| 448 | // Save this copy-assignment operator. It might be "the one". |
| 449 | Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals)); |
| 450 | } |
| 451 | |
| 452 | // Use a simplistic form of overload resolution to find the candidate. |
| 453 | return GetBestOverloadCandidateSimple(Found); |
| 454 | } |
| 455 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 456 | CXXMethodDecl *CXXRecordDecl::getMoveAssignmentOperator() const { |
| 457 | for (method_iterator I = method_begin(), E = method_end(); I != E; ++I) |
| 458 | if (I->isMoveAssignmentOperator()) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 459 | return *I; |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Douglas Gregor | 2138664 | 2010-09-28 21:55:22 +0000 | [diff] [blame] | 464 | void CXXRecordDecl::markedVirtualFunctionPure() { |
| 465 | // C++ [class.abstract]p2: |
| 466 | // A class is abstract if it has at least one pure virtual function. |
| 467 | data().Abstract = true; |
| 468 | } |
| 469 | |
Richard Smith | 3f5f558 | 2012-06-08 21:09:22 +0000 | [diff] [blame] | 470 | void CXXRecordDecl::markedConstructorConstexpr(CXXConstructorDecl *CD) { |
Richard Smith | d3861ce | 2012-06-10 07:07:24 +0000 | [diff] [blame] | 471 | if (!CD->isCopyOrMoveConstructor()) |
Richard Smith | 3f5f558 | 2012-06-08 21:09:22 +0000 | [diff] [blame] | 472 | data().HasConstexprNonCopyMoveConstructor = true; |
| 473 | |
| 474 | if (CD->isDefaultConstructor()) |
| 475 | data().HasConstexprDefaultConstructor = true; |
| 476 | } |
| 477 | |
Douglas Gregor | 2138664 | 2010-09-28 21:55:22 +0000 | [diff] [blame] | 478 | void CXXRecordDecl::addedMember(Decl *D) { |
Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 479 | if (!D->isImplicit() && |
| 480 | !isa<FieldDecl>(D) && |
| 481 | !isa<IndirectFieldDecl>(D) && |
| 482 | (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class || |
| 483 | cast<TagDecl>(D)->getTagKind() == TTK_Interface)) |
| 484 | data().HasOnlyCMembers = false; |
| 485 | |
| 486 | // Ignore friends and invalid declarations. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 487 | if (D->getFriendObjectKind() || D->isInvalidDecl()) |
Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 488 | return; |
| 489 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 490 | FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); |
| 491 | if (FunTmpl) |
| 492 | D = FunTmpl->getTemplatedDecl(); |
| 493 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 494 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 495 | if (Method->isVirtual()) { |
| 496 | // C++ [dcl.init.aggr]p1: |
| 497 | // An aggregate is an array or a class with [...] no virtual functions. |
| 498 | data().Aggregate = false; |
| 499 | |
| 500 | // C++ [class]p4: |
| 501 | // A POD-struct is an aggregate class... |
| 502 | data().PlainOldData = false; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 503 | |
| 504 | // Virtual functions make the class non-empty. |
| 505 | // FIXME: Standard ref? |
| 506 | data().Empty = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 507 | |
| 508 | // C++ [class.virtual]p1: |
| 509 | // A class that declares or inherits a virtual function is called a |
| 510 | // polymorphic class. |
| 511 | data().Polymorphic = true; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 512 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 513 | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: |
| 514 | // A [default constructor, copy/move constructor, or copy/move |
| 515 | // assignment operator for a class X] is trivial [...] if: |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 516 | // -- class X has no virtual functions [...] |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 517 | data().HasTrivialSpecialMembers &= SMF_Destructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 518 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 519 | // C++0x [class]p7: |
| 520 | // A standard-layout class is a class that: [...] |
| 521 | // -- has no virtual functions |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 522 | data().IsStandardLayout = false; |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 523 | } |
| 524 | } |
Argyrios Kyrtzidis | 046c03b | 2010-10-20 23:48:42 +0000 | [diff] [blame] | 525 | |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 526 | // Notify the listener if an implicit member was added after the definition |
| 527 | // was completed. |
| 528 | if (!isBeingDefined() && D->isImplicit()) |
| 529 | if (ASTMutationListener *L = getASTMutationListener()) |
| 530 | L->AddedCXXImplicitMember(data().Definition, D); |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 531 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 532 | // The kind of special member this declaration is, if any. |
| 533 | unsigned SMKind = 0; |
| 534 | |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 535 | // Handle constructors. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 536 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 537 | if (!Constructor->isImplicit()) { |
| 538 | // Note that we have a user-declared constructor. |
| 539 | data().UserDeclaredConstructor = true; |
| 540 | |
| 541 | // C++ [class]p4: |
| 542 | // A POD-struct is an aggregate class [...] |
| 543 | // Since the POD bit is meant to be C++03 POD-ness, clear it even if the |
| 544 | // type is technically an aggregate in C++0x since it wouldn't be in 03. |
| 545 | data().PlainOldData = false; |
| 546 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 547 | |
Richard Smith | 017ab77 | 2011-09-05 02:13:09 +0000 | [diff] [blame] | 548 | // Technically, "user-provided" is only defined for special member |
| 549 | // functions, but the intent of the standard is clearly that it should apply |
| 550 | // to all functions. |
| 551 | bool UserProvided = Constructor->isUserProvided(); |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 552 | |
Sean Hunt | 37b8c9e | 2011-05-09 21:45:35 +0000 | [diff] [blame] | 553 | if (Constructor->isDefaultConstructor()) { |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 554 | SMKind |= SMF_DefaultConstructor; |
| 555 | |
| 556 | if (UserProvided) |
Sean Hunt | cdee3fe | 2011-05-11 22:34:38 +0000 | [diff] [blame] | 557 | data().UserProvidedDefaultConstructor = true; |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 558 | if (Constructor->isConstexpr()) |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 559 | data().HasConstexprDefaultConstructor = true; |
Sean Hunt | 37b8c9e | 2011-05-09 21:45:35 +0000 | [diff] [blame] | 560 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 561 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 562 | if (!FunTmpl) { |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 563 | unsigned Quals; |
| 564 | if (Constructor->isCopyConstructor(Quals)) { |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 565 | SMKind |= SMF_CopyConstructor; |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 566 | |
| 567 | if (Quals & Qualifiers::Const) |
| 568 | data().HasDeclaredCopyConstructorWithConstParam = true; |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 569 | } else if (Constructor->isMoveConstructor()) |
| 570 | SMKind |= SMF_MoveConstructor; |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 571 | } |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 572 | |
| 573 | // Record if we see any constexpr constructors which are neither copy |
| 574 | // nor move constructors. |
| 575 | if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) |
Richard Smith | 6b8bc07 | 2011-08-10 18:11:37 +0000 | [diff] [blame] | 576 | data().HasConstexprNonCopyMoveConstructor = true; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 577 | |
Sean Hunt | 37b8c9e | 2011-05-09 21:45:35 +0000 | [diff] [blame] | 578 | // C++ [dcl.init.aggr]p1: |
| 579 | // An aggregate is an array or a class with no user-declared |
| 580 | // constructors [...]. |
| 581 | // C++0x [dcl.init.aggr]p1: |
| 582 | // An aggregate is an array or a class with no user-provided |
| 583 | // constructors [...]. |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 584 | if (getASTContext().getLangOpts().CPlusPlus0x |
| 585 | ? UserProvided : !Constructor->isImplicit()) |
Sean Hunt | 37b8c9e | 2011-05-09 21:45:35 +0000 | [diff] [blame] | 586 | data().Aggregate = false; |
Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 587 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 588 | |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 589 | // Handle destructors. |
Sean Hunt | cf34e75 | 2011-05-16 22:41:40 +0000 | [diff] [blame] | 590 | if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) { |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 591 | SMKind |= SMF_Destructor; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 592 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 593 | if (!DD->isImplicit()) |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 594 | data().HasIrrelevantDestructor = false; |
| 595 | |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 596 | // C++11 [class.dtor]p5: |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 597 | // A destructor is trivial if [...] the destructor is not virtual. |
| 598 | if (DD->isVirtual()) |
| 599 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 600 | } |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 601 | |
| 602 | // Handle member functions. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 603 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 604 | if (Method->isCopyAssignmentOperator()) { |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 605 | SMKind |= SMF_CopyAssignment; |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 606 | |
| 607 | const ReferenceType *ParamTy = |
| 608 | Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); |
| 609 | if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) |
| 610 | data().HasDeclaredCopyAssignmentWithConstParam = true; |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 611 | } |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 612 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 613 | if (Method->isMoveAssignmentOperator()) |
| 614 | SMKind |= SMF_MoveAssignment; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 615 | |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 616 | // Keep the list of conversion functions up-to-date. |
| 617 | if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 618 | // FIXME: We intentionally don't use the decl's access here because it |
| 619 | // hasn't been set yet. That's really just a misdesign in Sema. |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 620 | if (Conversion->getPrimaryTemplate()) { |
| 621 | // We don't record specializations. |
| 622 | } else if (FunTmpl) { |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 623 | if (FunTmpl->getPreviousDecl()) |
| 624 | data().Conversions.replace(FunTmpl->getPreviousDecl(), |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 625 | FunTmpl); |
| 626 | else |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 627 | data().Conversions.addDecl(getASTContext(), FunTmpl); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 628 | } else { |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 629 | if (Conversion->getPreviousDecl()) |
| 630 | data().Conversions.replace(Conversion->getPreviousDecl(), |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 631 | Conversion); |
| 632 | else |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 633 | data().Conversions.addDecl(getASTContext(), Conversion); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 636 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 637 | if (SMKind) { |
| 638 | // Note when we have declared a declared special member, and suppress the |
| 639 | // implicit declaration of this special member. |
| 640 | data().DeclaredSpecialMembers |= SMKind; |
| 641 | |
| 642 | if (!Method->isImplicit()) { |
| 643 | data().UserDeclaredSpecialMembers |= SMKind; |
| 644 | |
| 645 | // C++03 [class]p4: |
| 646 | // A POD-struct is an aggregate class that has [...] no user-defined |
| 647 | // copy assignment operator and no user-defined destructor. |
| 648 | // |
| 649 | // Since the POD bit is meant to be C++03 POD-ness, and in C++03, |
| 650 | // aggregates could not have any constructors, clear it even for an |
| 651 | // explicitly defaulted or deleted constructor. |
| 652 | // type is technically an aggregate in C++0x since it wouldn't be in 03. |
| 653 | // |
| 654 | // Also, a user-declared move assignment operator makes a class non-POD. |
| 655 | // This is an extension in C++03. |
| 656 | data().PlainOldData = false; |
| 657 | } |
| 658 | |
| 659 | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25, |
| 660 | // C++11 [class.dtor]p5: |
| 661 | // A [special member] is trivial if it is not user-provided [...] |
| 662 | // FIXME: This is bogus. A class can have both (say) a trivial copy |
| 663 | // constructor *and* a user-provided copy constructor. |
| 664 | if (Method->isUserProvided()) |
| 665 | data().HasTrivialSpecialMembers &= ~SMKind; |
| 666 | } |
| 667 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 668 | return; |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 669 | } |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 670 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 671 | // Handle non-static data members. |
| 672 | if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { |
Douglas Gregor | d61db33 | 2011-10-10 17:22:13 +0000 | [diff] [blame] | 673 | // C++ [class.bit]p2: |
| 674 | // A declaration for a bit-field that omits the identifier declares an |
| 675 | // unnamed bit-field. Unnamed bit-fields are not members and cannot be |
| 676 | // initialized. |
| 677 | if (Field->isUnnamedBitfield()) |
| 678 | return; |
| 679 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 680 | // C++ [dcl.init.aggr]p1: |
| 681 | // An aggregate is an array or a class (clause 9) with [...] no |
| 682 | // private or protected non-static data members (clause 11). |
| 683 | // |
| 684 | // A POD must be an aggregate. |
| 685 | if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { |
| 686 | data().Aggregate = false; |
| 687 | data().PlainOldData = false; |
| 688 | } |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 689 | |
| 690 | // C++0x [class]p7: |
| 691 | // A standard-layout class is a class that: |
| 692 | // [...] |
| 693 | // -- has the same access control for all non-static data members, |
| 694 | switch (D->getAccess()) { |
| 695 | case AS_private: data().HasPrivateFields = true; break; |
| 696 | case AS_protected: data().HasProtectedFields = true; break; |
| 697 | case AS_public: data().HasPublicFields = true; break; |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 698 | case AS_none: llvm_unreachable("Invalid access specifier"); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 699 | }; |
| 700 | if ((data().HasPrivateFields + data().HasProtectedFields + |
| 701 | data().HasPublicFields) > 1) |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 702 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 703 | |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 704 | // Keep track of the presence of mutable fields. |
| 705 | if (Field->isMutable()) |
| 706 | data().HasMutableFields = true; |
| 707 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 708 | // C++0x [class]p9: |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 709 | // A POD struct is a class that is both a trivial class and a |
| 710 | // standard-layout class, and has no non-static data members of type |
| 711 | // non-POD struct, non-POD union (or array of such types). |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 712 | // |
| 713 | // Automatic Reference Counting: the presence of a member of Objective-C pointer type |
| 714 | // that does not explicitly have no lifetime makes the class a non-POD. |
| 715 | // However, we delay setting PlainOldData to false in this case so that |
| 716 | // Sema has a chance to diagnostic causes where the same class will be |
Douglas Gregor | 3fe52ff | 2012-07-23 04:23:39 +0000 | [diff] [blame] | 717 | // non-POD with Automatic Reference Counting but a POD without ARC. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 718 | // In this case, the class will become a non-POD class when we complete |
| 719 | // the definition. |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 720 | ASTContext &Context = getASTContext(); |
| 721 | QualType T = Context.getBaseElementType(Field->getType()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 722 | if (T->isObjCRetainableType() || T.isObjCGCStrong()) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 723 | if (!Context.getLangOpts().ObjCAutoRefCount || |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 724 | T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) |
| 725 | setHasObjectMember(true); |
| 726 | } else if (!T.isPODType(Context)) |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 727 | data().PlainOldData = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 728 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 729 | if (T->isReferenceType()) { |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 730 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 731 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 732 | // C++0x [class]p7: |
| 733 | // A standard-layout class is a class that: |
| 734 | // -- has no non-static data members of type [...] reference, |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 735 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Richard Smith | 86c3ae4 | 2012-02-13 03:54:03 +0000 | [diff] [blame] | 738 | // Record if this field is the first non-literal or volatile field or base. |
| 739 | if (!T->isLiteralType() || T.isVolatileQualified()) |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 740 | data().HasNonLiteralTypeFieldsOrBases = true; |
| 741 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 742 | if (Field->hasInClassInitializer()) { |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 743 | data().HasInClassInitializer = true; |
| 744 | |
| 745 | // C++11 [class]p5: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 746 | // A default constructor is trivial if [...] no non-static data member |
| 747 | // of its class has a brace-or-equal-initializer. |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 748 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 749 | |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 750 | // C++11 [dcl.init.aggr]p1: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 751 | // An aggregate is a [...] class with [...] no |
| 752 | // brace-or-equal-initializers for non-static data members. |
| 753 | data().Aggregate = false; |
| 754 | |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 755 | // C++11 [class]p10: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 756 | // A POD struct is [...] a trivial class. |
| 757 | data().PlainOldData = false; |
| 758 | } |
| 759 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 760 | if (const RecordType *RecordTy = T->getAs<RecordType>()) { |
| 761 | CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); |
| 762 | if (FieldRec->getDefinition()) { |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 763 | // C++0x [class.ctor]p5: |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 764 | // A default constructor is trivial [...] if: |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 765 | // -- for all the non-static data members of its class that are of |
| 766 | // class type (or array thereof), each such class has a trivial |
| 767 | // default constructor. |
| 768 | if (!FieldRec->hasTrivialDefaultConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 769 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 770 | |
| 771 | // C++0x [class.copy]p13: |
| 772 | // A copy/move constructor for class X is trivial if [...] |
| 773 | // [...] |
| 774 | // -- for each non-static data member of X that is of class type (or |
| 775 | // an array thereof), the constructor selected to copy/move that |
| 776 | // member is trivial; |
| 777 | // FIXME: C++0x: We don't correctly model 'selected' constructors. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 778 | if (!FieldRec->hasTrivialCopyConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 779 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 780 | if (!FieldRec->hasTrivialMoveConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 781 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 782 | |
| 783 | // C++0x [class.copy]p27: |
| 784 | // A copy/move assignment operator for class X is trivial if [...] |
| 785 | // [...] |
| 786 | // -- for each non-static data member of X that is of class type (or |
| 787 | // an array thereof), the assignment operator selected to |
| 788 | // copy/move that member is trivial; |
| 789 | // FIXME: C++0x: We don't correctly model 'selected' operators. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 790 | if (!FieldRec->hasTrivialCopyAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 791 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 792 | if (!FieldRec->hasTrivialMoveAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 793 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 794 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 795 | if (!FieldRec->hasTrivialDestructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 796 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 797 | if (!FieldRec->hasIrrelevantDestructor()) |
| 798 | data().HasIrrelevantDestructor = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 799 | if (FieldRec->hasObjectMember()) |
| 800 | setHasObjectMember(true); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 801 | |
| 802 | // C++0x [class]p7: |
| 803 | // A standard-layout class is a class that: |
| 804 | // -- has no non-static data members of type non-standard-layout |
| 805 | // class (or array of such types) [...] |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 806 | if (!FieldRec->isStandardLayout()) |
| 807 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 808 | |
| 809 | // C++0x [class]p7: |
| 810 | // A standard-layout class is a class that: |
| 811 | // [...] |
| 812 | // -- has no base classes of the same type as the first non-static |
| 813 | // data member. |
| 814 | // We don't want to expend bits in the state of the record decl |
| 815 | // tracking whether this is the first non-static data member so we |
| 816 | // cheat a bit and use some of the existing state: the empty bit. |
| 817 | // Virtual bases and virtual methods make a class non-empty, but they |
| 818 | // also make it non-standard-layout so we needn't check here. |
| 819 | // A non-empty base class may leave the class standard-layout, but not |
| 820 | // if we have arrived here, and have at least on non-static data |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 821 | // member. If IsStandardLayout remains true, then the first non-static |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 822 | // data member must come through here with Empty still true, and Empty |
| 823 | // will subsequently be set to false below. |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 824 | if (data().IsStandardLayout && data().Empty) { |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 825 | for (CXXRecordDecl::base_class_const_iterator BI = bases_begin(), |
| 826 | BE = bases_end(); |
| 827 | BI != BE; ++BI) { |
| 828 | if (Context.hasSameUnqualifiedType(BI->getType(), T)) { |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 829 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 830 | break; |
| 831 | } |
| 832 | } |
| 833 | } |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 834 | |
| 835 | // Keep track of the presence of mutable fields. |
| 836 | if (FieldRec->hasMutableFields()) |
| 837 | data().HasMutableFields = true; |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 838 | |
| 839 | // C++11 [class.copy]p13: |
| 840 | // If the implicitly-defined constructor would satisfy the |
| 841 | // requirements of a constexpr constructor, the implicitly-defined |
| 842 | // constructor is constexpr. |
| 843 | // C++11 [dcl.constexpr]p4: |
| 844 | // -- every constructor involved in initializing non-static data |
| 845 | // members [...] shall be a constexpr constructor |
| 846 | if (!Field->hasInClassInitializer() && |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 847 | !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 848 | // The standard requires any in-class initializer to be a constant |
| 849 | // expression. We consider this to be a defect. |
| 850 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 851 | |
| 852 | // C++11 [class.copy]p8: |
| 853 | // The implicitly-declared copy constructor for a class X will have |
| 854 | // the form 'X::X(const X&)' if [...] for all the non-static data |
| 855 | // members of X that are of a class type M (or array thereof), each |
| 856 | // such class type has a copy constructor whose first parameter is |
| 857 | // of type 'const M&' or 'const volatile M&'. |
| 858 | if (!FieldRec->hasCopyConstructorWithConstParam()) |
| 859 | data().ImplicitCopyConstructorHasConstParam = false; |
| 860 | |
| 861 | // C++11 [class.copy]p18: |
| 862 | // The implicitly-declared copy assignment oeprator for a class X will |
| 863 | // have the form 'X& X::operator=(const X&)' if [...] for all the |
| 864 | // non-static data members of X that are of a class type M (or array |
| 865 | // thereof), each such class type has a copy assignment operator whose |
| 866 | // parameter is of type 'const M&', 'const volatile M&' or 'M'. |
| 867 | if (!FieldRec->hasCopyAssignmentWithConstParam()) |
| 868 | data().ImplicitCopyAssignmentHasConstParam = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 869 | } |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 870 | } else { |
| 871 | // Base element type of field is a non-class type. |
Richard Smith | d3861ce | 2012-06-10 07:07:24 +0000 | [diff] [blame] | 872 | if (!T->isLiteralType() || |
| 873 | (!Field->hasInClassInitializer() && !isUnion())) |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 874 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 875 | } |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 876 | |
| 877 | // C++0x [class]p7: |
| 878 | // A standard-layout class is a class that: |
| 879 | // [...] |
| 880 | // -- either has no non-static data members in the most derived |
| 881 | // class and at most one base class with non-static data members, |
| 882 | // or has no base classes with non-static data members, and |
| 883 | // At this point we know that we have a non-static data member, so the last |
| 884 | // clause holds. |
| 885 | if (!data().HasNoNonEmptyBases) |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 886 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 887 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 888 | // If this is not a zero-length bit-field, then the class is not empty. |
| 889 | if (data().Empty) { |
Richard Smith | a6b8b2c | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 890 | if (!Field->isBitField() || |
| 891 | (!Field->getBitWidth()->isTypeDependent() && |
| 892 | !Field->getBitWidth()->isValueDependent() && |
| 893 | Field->getBitWidthValue(Context) != 0)) |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 894 | data().Empty = false; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 895 | } |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 896 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 897 | |
| 898 | // Handle using declarations of conversion functions. |
| 899 | if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) |
| 900 | if (Shadow->getDeclName().getNameKind() |
| 901 | == DeclarationName::CXXConversionFunctionName) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 902 | data().Conversions.addDecl(getASTContext(), Shadow, Shadow->getAccess()); |
Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | bool CXXRecordDecl::isCLike() const { |
| 906 | if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || |
| 907 | !TemplateOrInstantiation.isNull()) |
| 908 | return false; |
| 909 | if (!hasDefinition()) |
| 910 | return true; |
Argyrios Kyrtzidis | 277b156 | 2012-01-23 16:58:45 +0000 | [diff] [blame] | 911 | |
Argyrios Kyrtzidis | c221411 | 2012-02-01 06:36:44 +0000 | [diff] [blame] | 912 | return isPOD() && data().HasOnlyCMembers; |
Argyrios Kyrtzidis | 277b156 | 2012-01-23 16:58:45 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 915 | void CXXRecordDecl::getCaptureFields( |
| 916 | llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
Eli Friedman | 41105ad | 2012-02-11 00:18:00 +0000 | [diff] [blame] | 917 | FieldDecl *&ThisCapture) const { |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 918 | Captures.clear(); |
| 919 | ThisCapture = 0; |
| 920 | |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 921 | LambdaDefinitionData &Lambda = getLambdaData(); |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 922 | RecordDecl::field_iterator Field = field_begin(); |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 923 | for (LambdaExpr::Capture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 924 | C != CEnd; ++C, ++Field) { |
| 925 | if (C->capturesThis()) { |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 926 | ThisCapture = *Field; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 927 | continue; |
| 928 | } |
| 929 | |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 930 | Captures[C->getCapturedVar()] = *Field; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
| 934 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 935 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { |
| 936 | QualType T; |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 937 | if (isa<UsingShadowDecl>(Conv)) |
| 938 | Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl(); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 939 | if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv)) |
| 940 | T = ConvTemp->getTemplatedDecl()->getResultType(); |
| 941 | else |
| 942 | T = cast<CXXConversionDecl>(Conv)->getConversionType(); |
| 943 | return Context.getCanonicalType(T); |
Fariborz Jahanian | 0351a1e | 2009-10-07 20:43:36 +0000 | [diff] [blame] | 944 | } |
| 945 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 946 | /// Collect the visible conversions of a base class. |
| 947 | /// |
James Dennett | a125350 | 2012-06-15 22:28:09 +0000 | [diff] [blame] | 948 | /// \param Record a base class of the class we're considering |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 949 | /// \param InVirtual whether this base class is a virtual base (or a base |
| 950 | /// of a virtual base) |
| 951 | /// \param Access the access along the inheritance path to this base |
| 952 | /// \param ParentHiddenTypes the conversions provided by the inheritors |
| 953 | /// of this base |
| 954 | /// \param Output the set to which to add conversions from non-virtual bases |
| 955 | /// \param VOutput the set to which to add conversions from virtual bases |
| 956 | /// \param HiddenVBaseCs the set of conversions which were hidden in a |
| 957 | /// virtual base along some inheritance path |
| 958 | static void CollectVisibleConversions(ASTContext &Context, |
| 959 | CXXRecordDecl *Record, |
| 960 | bool InVirtual, |
| 961 | AccessSpecifier Access, |
| 962 | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 963 | ASTUnresolvedSet &Output, |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 964 | UnresolvedSetImpl &VOutput, |
| 965 | llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { |
| 966 | // The set of types which have conversions in this class or its |
| 967 | // subclasses. As an optimization, we don't copy the derived set |
| 968 | // unless it might change. |
| 969 | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; |
| 970 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; |
| 971 | |
| 972 | // Collect the direct conversions and figure out which conversions |
| 973 | // will be hidden in the subclasses. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 974 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
| 975 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
| 976 | if (ConvI != ConvE) { |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 977 | HiddenTypesBuffer = ParentHiddenTypes; |
| 978 | HiddenTypes = &HiddenTypesBuffer; |
| 979 | |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 980 | for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { |
Richard Smith | f108c63 | 2012-05-06 00:04:32 +0000 | [diff] [blame] | 981 | CanQualType ConvType(GetConversionType(Context, I.getDecl())); |
| 982 | bool Hidden = ParentHiddenTypes.count(ConvType); |
| 983 | if (!Hidden) |
| 984 | HiddenTypesBuffer.insert(ConvType); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 985 | |
| 986 | // If this conversion is hidden and we're in a virtual base, |
| 987 | // remember that it's hidden along some inheritance path. |
| 988 | if (Hidden && InVirtual) |
| 989 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); |
| 990 | |
| 991 | // If this conversion isn't hidden, add it to the appropriate output. |
| 992 | else if (!Hidden) { |
| 993 | AccessSpecifier IAccess |
| 994 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); |
| 995 | |
| 996 | if (InVirtual) |
| 997 | VOutput.addDecl(I.getDecl(), IAccess); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 998 | else |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 999 | Output.addDecl(Context, I.getDecl(), IAccess); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | } |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1003 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1004 | // Collect information recursively from any base classes. |
| 1005 | for (CXXRecordDecl::base_class_iterator |
| 1006 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 1007 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1008 | if (!RT) continue; |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1009 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1010 | AccessSpecifier BaseAccess |
| 1011 | = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier()); |
| 1012 | bool BaseInVirtual = InVirtual || I->isVirtual(); |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1013 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1014 | CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); |
| 1015 | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, |
| 1016 | *HiddenTypes, Output, VOutput, HiddenVBaseCs); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1017 | } |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1018 | } |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1019 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1020 | /// Collect the visible conversions of a class. |
| 1021 | /// |
| 1022 | /// This would be extremely straightforward if it weren't for virtual |
| 1023 | /// bases. It might be worth special-casing that, really. |
| 1024 | static void CollectVisibleConversions(ASTContext &Context, |
| 1025 | CXXRecordDecl *Record, |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1026 | ASTUnresolvedSet &Output) { |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1027 | // The collection of all conversions in virtual bases that we've |
| 1028 | // found. These will be added to the output as long as they don't |
| 1029 | // appear in the hidden-conversions set. |
| 1030 | UnresolvedSet<8> VBaseCs; |
| 1031 | |
| 1032 | // The set of conversions in virtual bases that we've determined to |
| 1033 | // be hidden. |
| 1034 | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; |
| 1035 | |
| 1036 | // The set of types hidden by classes derived from this one. |
| 1037 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; |
| 1038 | |
| 1039 | // Go ahead and collect the direct conversions and add them to the |
| 1040 | // hidden-types set. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1041 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
| 1042 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1043 | Output.append(Context, ConvI, ConvE); |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1044 | for (; ConvI != ConvE; ++ConvI) |
| 1045 | HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1046 | |
| 1047 | // Recursively collect conversions from base classes. |
| 1048 | for (CXXRecordDecl::base_class_iterator |
| 1049 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 1050 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1051 | if (!RT) continue; |
| 1052 | |
| 1053 | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), |
| 1054 | I->isVirtual(), I->getAccessSpecifier(), |
| 1055 | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); |
| 1056 | } |
| 1057 | |
| 1058 | // Add any unhidden conversions provided by virtual bases. |
| 1059 | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); |
| 1060 | I != E; ++I) { |
| 1061 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1062 | Output.addDecl(Context, I.getDecl(), I.getAccess()); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1063 | } |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | /// getVisibleConversionFunctions - get all conversion functions visible |
| 1067 | /// in current class; including conversion function templates. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1068 | std::pair<CXXRecordDecl::conversion_iterator,CXXRecordDecl::conversion_iterator> |
| 1069 | CXXRecordDecl::getVisibleConversionFunctions() { |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1070 | // If root class, all conversions are visible. |
| 1071 | if (bases_begin() == bases_end()) |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1072 | return std::make_pair(data().Conversions.begin(), data().Conversions.end()); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1073 | // If visible conversion list is already evaluated, return it. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1074 | if (!data().ComputedVisibleConversions) { |
| 1075 | CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); |
| 1076 | data().ComputedVisibleConversions = true; |
| 1077 | } |
| 1078 | return std::make_pair(data().VisibleConversions.begin(), |
| 1079 | data().VisibleConversions.end()); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 1082 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { |
| 1083 | // This operation is O(N) but extremely rare. Sema only uses it to |
| 1084 | // remove UsingShadowDecls in a class that were followed by a direct |
| 1085 | // declaration, e.g.: |
| 1086 | // class A : B { |
| 1087 | // using B::operator int; |
| 1088 | // operator int(); |
| 1089 | // }; |
| 1090 | // This is uncommon by itself and even more uncommon in conjunction |
| 1091 | // with sufficiently large numbers of directly-declared conversions |
| 1092 | // that asymptotic behavior matters. |
| 1093 | |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1094 | ASTUnresolvedSet &Convs = data().Conversions; |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 1095 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { |
| 1096 | if (Convs[I].getDecl() == ConvDecl) { |
| 1097 | Convs.erase(I); |
| 1098 | assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() |
| 1099 | && "conversion was found multiple times in unresolved set"); |
| 1100 | return; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | llvm_unreachable("conversion not found in set!"); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 1105 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1107 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1108 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1109 | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1114 | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { |
| 1115 | return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); |
| 1116 | } |
| 1117 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1118 | void |
| 1119 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, |
| 1120 | TemplateSpecializationKind TSK) { |
| 1121 | assert(TemplateOrInstantiation.isNull() && |
| 1122 | "Previous template or instantiation?"); |
| 1123 | assert(!isa<ClassTemplateSpecializationDecl>(this)); |
| 1124 | TemplateOrInstantiation |
| 1125 | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); |
| 1126 | } |
| 1127 | |
Anders Carlsson | b13e357 | 2009-12-07 06:33:48 +0000 | [diff] [blame] | 1128 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ |
| 1129 | if (const ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1130 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) |
| 1131 | return Spec->getSpecializationKind(); |
| 1132 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1133 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1134 | return MSInfo->getTemplateSpecializationKind(); |
| 1135 | |
| 1136 | return TSK_Undeclared; |
| 1137 | } |
| 1138 | |
| 1139 | void |
| 1140 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
| 1141 | if (ClassTemplateSpecializationDecl *Spec |
| 1142 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
| 1143 | Spec->setSpecializationKind(TSK); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1147 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1148 | MSInfo->setTemplateSpecializationKind(TSK); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1152 | llvm_unreachable("Not a class template or member class specialization"); |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Douglas Gregor | 1d110e0 | 2010-07-01 14:13:13 +0000 | [diff] [blame] | 1155 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { |
| 1156 | ASTContext &Context = getASTContext(); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1157 | QualType ClassType = Context.getTypeDeclType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
| 1159 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 1160 | = Context.DeclarationNames.getCXXDestructorName( |
| 1161 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1162 | |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 1163 | DeclContext::lookup_const_iterator I, E; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | llvm::tie(I, E) = lookup(Name); |
Sebastian Redl | d4b25cb | 2010-09-02 23:19:42 +0000 | [diff] [blame] | 1165 | if (I == E) |
| 1166 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | |
Anders Carlsson | 5ec02ae | 2009-12-02 17:15:43 +0000 | [diff] [blame] | 1168 | CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1169 | return Dtor; |
| 1170 | } |
| 1171 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 1172 | void CXXRecordDecl::completeDefinition() { |
| 1173 | completeDefinition(0); |
| 1174 | } |
| 1175 | |
| 1176 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { |
| 1177 | RecordDecl::completeDefinition(); |
| 1178 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1179 | if (hasObjectMember() && getASTContext().getLangOpts().ObjCAutoRefCount) { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1180 | // Objective-C Automatic Reference Counting: |
| 1181 | // If a class has a non-static data member of Objective-C pointer |
| 1182 | // type (or array thereof), it is a non-POD type and its |
Douglas Gregor | 3fe52ff | 2012-07-23 04:23:39 +0000 | [diff] [blame] | 1183 | // default constructor (if any), copy constructor, move constructor, |
| 1184 | // copy assignment operator, move assignment operator, and destructor are |
| 1185 | // non-trivial. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1186 | struct DefinitionData &Data = data(); |
| 1187 | Data.PlainOldData = false; |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame^] | 1188 | Data.HasTrivialSpecialMembers = 0; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1189 | Data.HasIrrelevantDestructor = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 1192 | // If the class may be abstract (but hasn't been marked as such), check for |
| 1193 | // any pure final overriders. |
| 1194 | if (mayBeAbstract()) { |
| 1195 | CXXFinalOverriderMap MyFinalOverriders; |
| 1196 | if (!FinalOverriders) { |
| 1197 | getFinalOverriders(MyFinalOverriders); |
| 1198 | FinalOverriders = &MyFinalOverriders; |
| 1199 | } |
| 1200 | |
| 1201 | bool Done = false; |
| 1202 | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), |
| 1203 | MEnd = FinalOverriders->end(); |
| 1204 | M != MEnd && !Done; ++M) { |
| 1205 | for (OverridingMethods::iterator SO = M->second.begin(), |
| 1206 | SOEnd = M->second.end(); |
| 1207 | SO != SOEnd && !Done; ++SO) { |
| 1208 | assert(SO->second.size() > 0 && |
| 1209 | "All virtual functions have overridding virtual functions"); |
| 1210 | |
| 1211 | // C++ [class.abstract]p4: |
| 1212 | // A class is abstract if it contains or inherits at least one |
| 1213 | // pure virtual function for which the final overrider is pure |
| 1214 | // virtual. |
| 1215 | if (SO->second.front().Method->isPure()) { |
| 1216 | data().Abstract = true; |
| 1217 | Done = true; |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 1223 | |
| 1224 | // Set access bits correctly on the directly-declared conversions. |
| 1225 | for (UnresolvedSetIterator I = data().Conversions.begin(), |
| 1226 | E = data().Conversions.end(); |
| 1227 | I != E; ++I) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1228 | I.setAccess((*I)->getAccess()); |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | bool CXXRecordDecl::mayBeAbstract() const { |
| 1232 | if (data().Abstract || isInvalidDecl() || !data().Polymorphic || |
| 1233 | isDependentContext()) |
| 1234 | return false; |
| 1235 | |
| 1236 | for (CXXRecordDecl::base_class_const_iterator B = bases_begin(), |
| 1237 | BEnd = bases_end(); |
| 1238 | B != BEnd; ++B) { |
| 1239 | CXXRecordDecl *BaseDecl |
| 1240 | = cast<CXXRecordDecl>(B->getType()->getAs<RecordType>()->getDecl()); |
| 1241 | if (BaseDecl->isAbstract()) |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
| 1245 | return false; |
| 1246 | } |
| 1247 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1248 | void CXXMethodDecl::anchor() { } |
| 1249 | |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1250 | static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, |
| 1251 | const CXXMethodDecl *BaseMD) { |
| 1252 | for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(), |
| 1253 | E = DerivedMD->end_overridden_methods(); I != E; ++I) { |
| 1254 | const CXXMethodDecl *MD = *I; |
| 1255 | if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) |
| 1256 | return true; |
| 1257 | if (recursivelyOverrides(MD, BaseMD)) |
| 1258 | return true; |
| 1259 | } |
| 1260 | return false; |
| 1261 | } |
| 1262 | |
| 1263 | CXXMethodDecl * |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1264 | CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
| 1265 | bool MayBeBase) { |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1266 | if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) |
| 1267 | return this; |
| 1268 | |
| 1269 | // Lookup doesn't work for destructors, so handle them separately. |
| 1270 | if (isa<CXXDestructorDecl>(this)) { |
| 1271 | CXXMethodDecl *MD = RD->getDestructor(); |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1272 | if (MD) { |
| 1273 | if (recursivelyOverrides(MD, this)) |
| 1274 | return MD; |
| 1275 | if (MayBeBase && recursivelyOverrides(this, MD)) |
| 1276 | return MD; |
| 1277 | } |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1278 | return NULL; |
| 1279 | } |
| 1280 | |
| 1281 | lookup_const_result Candidates = RD->lookup(getDeclName()); |
| 1282 | for (NamedDecl * const * I = Candidates.first; I != Candidates.second; ++I) { |
| 1283 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*I); |
| 1284 | if (!MD) |
| 1285 | continue; |
| 1286 | if (recursivelyOverrides(MD, this)) |
| 1287 | return MD; |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1288 | if (MayBeBase && recursivelyOverrides(this, MD)) |
| 1289 | return MD; |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), |
| 1293 | E = RD->bases_end(); I != E; ++I) { |
| 1294 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1295 | if (!RT) |
| 1296 | continue; |
| 1297 | const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); |
| 1298 | CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); |
| 1299 | if (T) |
| 1300 | return T; |
| 1301 | } |
| 1302 | |
| 1303 | return NULL; |
| 1304 | } |
| 1305 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1306 | CXXMethodDecl * |
| 1307 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1308 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1309 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1310 | QualType T, TypeSourceInfo *TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1311 | bool isStatic, StorageClass SCAsWritten, bool isInline, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1312 | bool isConstexpr, SourceLocation EndLocation) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1313 | return new (C) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1314 | isStatic, SCAsWritten, isInline, isConstexpr, |
| 1315 | EndLocation); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1318 | CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1319 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXMethodDecl)); |
| 1320 | return new (Mem) CXXMethodDecl(CXXMethod, 0, SourceLocation(), |
| 1321 | DeclarationNameInfo(), QualType(), |
| 1322 | 0, false, SC_None, false, false, |
| 1323 | SourceLocation()); |
| 1324 | } |
| 1325 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1326 | bool CXXMethodDecl::isUsualDeallocationFunction() const { |
| 1327 | if (getOverloadedOperator() != OO_Delete && |
| 1328 | getOverloadedOperator() != OO_Array_Delete) |
| 1329 | return false; |
Douglas Gregor | 6d90870 | 2010-02-26 05:06:18 +0000 | [diff] [blame] | 1330 | |
| 1331 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1332 | // A template instance is never a usual deallocation function, |
| 1333 | // regardless of its signature. |
| 1334 | if (getPrimaryTemplate()) |
| 1335 | return false; |
| 1336 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1337 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1338 | // If a class T has a member deallocation function named operator delete |
| 1339 | // with exactly one parameter, then that function is a usual (non-placement) |
| 1340 | // deallocation function. [...] |
| 1341 | if (getNumParams() == 1) |
| 1342 | return true; |
| 1343 | |
| 1344 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1345 | // [...] If class T does not declare such an operator delete but does |
| 1346 | // declare a member deallocation function named operator delete with |
| 1347 | // exactly two parameters, the second of which has type std::size_t (18.1), |
| 1348 | // then this function is a usual deallocation function. |
| 1349 | ASTContext &Context = getASTContext(); |
| 1350 | if (getNumParams() != 2 || |
Chandler Carruth | e228ba9 | 2010-02-08 18:54:05 +0000 | [diff] [blame] | 1351 | !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), |
| 1352 | Context.getSizeType())) |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1353 | return false; |
| 1354 | |
| 1355 | // This function is a usual deallocation function if there are no |
| 1356 | // single-parameter deallocation functions of the same kind. |
| 1357 | for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName()); |
| 1358 | R.first != R.second; ++R.first) { |
| 1359 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first)) |
| 1360 | if (FD->getNumParams() == 1) |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | return true; |
| 1365 | } |
| 1366 | |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1367 | bool CXXMethodDecl::isCopyAssignmentOperator() const { |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1368 | // C++0x [class.copy]p17: |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1369 | // A user-declared copy assignment operator X::operator= is a non-static |
| 1370 | // non-template member function of class X with exactly one parameter of |
| 1371 | // type X, X&, const X&, volatile X& or const volatile X&. |
| 1372 | if (/*operator=*/getOverloadedOperator() != OO_Equal || |
| 1373 | /*non-static*/ isStatic() || |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1374 | /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate()) |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1375 | return false; |
| 1376 | |
| 1377 | QualType ParamType = getParamDecl(0)->getType(); |
| 1378 | if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) |
| 1379 | ParamType = Ref->getPointeeType(); |
| 1380 | |
| 1381 | ASTContext &Context = getASTContext(); |
| 1382 | QualType ClassType |
| 1383 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
| 1384 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
| 1385 | } |
| 1386 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1387 | bool CXXMethodDecl::isMoveAssignmentOperator() const { |
| 1388 | // C++0x [class.copy]p19: |
| 1389 | // A user-declared move assignment operator X::operator= is a non-static |
| 1390 | // non-template member function of class X with exactly one parameter of type |
| 1391 | // X&&, const X&&, volatile X&&, or const volatile X&&. |
| 1392 | if (getOverloadedOperator() != OO_Equal || isStatic() || |
| 1393 | getPrimaryTemplate() || getDescribedFunctionTemplate()) |
| 1394 | return false; |
| 1395 | |
| 1396 | QualType ParamType = getParamDecl(0)->getType(); |
| 1397 | if (!isa<RValueReferenceType>(ParamType)) |
| 1398 | return false; |
| 1399 | ParamType = ParamType->getPointeeType(); |
| 1400 | |
| 1401 | ASTContext &Context = getASTContext(); |
| 1402 | QualType ClassType |
| 1403 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
| 1404 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
| 1405 | } |
| 1406 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1407 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 1408 | assert(MD->isCanonicalDecl() && "Method is not canonical!"); |
Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 1409 | assert(!MD->getParent()->isDependentContext() && |
| 1410 | "Can't add an overridden method to a class template!"); |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1411 | assert(MD->isVirtual() && "Method is not virtual!"); |
Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 1412 | |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1413 | getASTContext().addOverriddenMethod(this, MD); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1417 | if (isa<CXXConstructorDecl>(this)) return 0; |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1418 | return getASTContext().overridden_methods_begin(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1422 | if (isa<CXXConstructorDecl>(this)) return 0; |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1423 | return getASTContext().overridden_methods_end(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1426 | unsigned CXXMethodDecl::size_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1427 | if (isa<CXXConstructorDecl>(this)) return 0; |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1428 | return getASTContext().overridden_methods_size(this); |
| 1429 | } |
| 1430 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1431 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 1432 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 1433 | // If the member function is declared const, the type of this is const X*, |
| 1434 | // if the member function is declared volatile, the type of this is |
| 1435 | // volatile X*, and if the member function is declared const volatile, |
| 1436 | // the type of this is const volatile X*. |
| 1437 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1438 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 1439 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 1440 | QualType ClassTy = C.getTypeDeclType(getParent()); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1441 | ClassTy = C.getQualifiedType(ClassTy, |
| 1442 | Qualifiers::fromCVRMask(getTypeQualifiers())); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 1443 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1446 | bool CXXMethodDecl::hasInlineBody() const { |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 1447 | // If this function is a template instantiation, look at the template from |
| 1448 | // which it was instantiated. |
| 1449 | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); |
| 1450 | if (!CheckFn) |
| 1451 | CheckFn = this; |
| 1452 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1453 | const FunctionDecl *fn; |
Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1454 | return CheckFn->hasBody(fn) && !fn->isOutOfLine(); |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
Douglas Gregor | 27dd7d9 | 2012-02-17 03:02:34 +0000 | [diff] [blame] | 1457 | bool CXXMethodDecl::isLambdaStaticInvoker() const { |
| 1458 | return getParent()->isLambda() && |
| 1459 | getIdentifier() && getIdentifier()->getName() == "__invoke"; |
| 1460 | } |
| 1461 | |
| 1462 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1463 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1464 | TypeSourceInfo *TInfo, bool IsVirtual, |
| 1465 | SourceLocation L, Expr *Init, |
| 1466 | SourceLocation R, |
| 1467 | SourceLocation EllipsisLoc) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1468 | : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1469 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), |
| 1470 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1471 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1474 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1475 | FieldDecl *Member, |
| 1476 | SourceLocation MemberLoc, |
| 1477 | SourceLocation L, Expr *Init, |
| 1478 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1479 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1480 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1481 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1482 | { |
| 1483 | } |
| 1484 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1485 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1486 | IndirectFieldDecl *Member, |
| 1487 | SourceLocation MemberLoc, |
| 1488 | SourceLocation L, Expr *Init, |
| 1489 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1490 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1491 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1492 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1493 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1496 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1497 | TypeSourceInfo *TInfo, |
| 1498 | SourceLocation L, Expr *Init, |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1499 | SourceLocation R) |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1500 | : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init), |
| 1501 | LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false), |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1502 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1503 | { |
| 1504 | } |
| 1505 | |
| 1506 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1507 | FieldDecl *Member, |
| 1508 | SourceLocation MemberLoc, |
| 1509 | SourceLocation L, Expr *Init, |
| 1510 | SourceLocation R, |
| 1511 | VarDecl **Indices, |
| 1512 | unsigned NumIndices) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1513 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1514 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1515 | IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1516 | { |
| 1517 | VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1); |
| 1518 | memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *)); |
| 1519 | } |
| 1520 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1521 | CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, |
| 1522 | FieldDecl *Member, |
| 1523 | SourceLocation MemberLoc, |
| 1524 | SourceLocation L, Expr *Init, |
| 1525 | SourceLocation R, |
| 1526 | VarDecl **Indices, |
| 1527 | unsigned NumIndices) { |
| 1528 | void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) + |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1529 | sizeof(VarDecl *) * NumIndices, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1530 | llvm::alignOf<CXXCtorInitializer>()); |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1531 | return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, |
| 1532 | Indices, NumIndices); |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1535 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1536 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1537 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1538 | else |
| 1539 | return TypeLoc(); |
| 1540 | } |
| 1541 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1542 | const Type *CXXCtorInitializer::getBaseClass() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1543 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1544 | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1545 | else |
| 1546 | return 0; |
| 1547 | } |
| 1548 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1549 | SourceLocation CXXCtorInitializer::getSourceLocation() const { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1550 | if (isAnyMemberInitializer()) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1551 | return getMemberLocation(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1552 | |
| 1553 | if (isInClassMemberInitializer()) |
| 1554 | return getAnyMember()->getLocation(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1555 | |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1556 | if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>()) |
| 1557 | return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); |
| 1558 | |
| 1559 | return SourceLocation(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1562 | SourceRange CXXCtorInitializer::getSourceRange() const { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1563 | if (isInClassMemberInitializer()) { |
| 1564 | FieldDecl *D = getAnyMember(); |
| 1565 | if (Expr *I = D->getInClassInitializer()) |
| 1566 | return I->getSourceRange(); |
| 1567 | return SourceRange(); |
| 1568 | } |
| 1569 | |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1570 | return SourceRange(getSourceLocation(), getRParenLoc()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1573 | void CXXConstructorDecl::anchor() { } |
| 1574 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1575 | CXXConstructorDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1576 | CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1577 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConstructorDecl)); |
| 1578 | return new (Mem) CXXConstructorDecl(0, SourceLocation(),DeclarationNameInfo(), |
| 1579 | QualType(), 0, false, false, false,false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | CXXConstructorDecl * |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1583 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1584 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1585 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1586 | QualType T, TypeSourceInfo *TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1587 | bool isExplicit, bool isInline, |
| 1588 | bool isImplicitlyDeclared, bool isConstexpr) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1589 | assert(NameInfo.getName().getNameKind() |
| 1590 | == DeclarationName::CXXConstructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1591 | "Name must refer to a constructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1592 | return new (C) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1593 | isExplicit, isInline, isImplicitlyDeclared, |
| 1594 | isConstexpr); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1597 | CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { |
| 1598 | assert(isDelegatingConstructor() && "Not a delegating constructor!"); |
| 1599 | Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); |
| 1600 | if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E)) |
| 1601 | return Construct->getConstructor(); |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1606 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 1607 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1608 | // A default constructor for a class X is a constructor of class |
| 1609 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1610 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 1611 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1614 | bool |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1615 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1616 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1617 | getParamDecl(0)->getType()->isLValueReferenceType(); |
| 1618 | } |
| 1619 | |
| 1620 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { |
| 1621 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1622 | getParamDecl(0)->getType()->isRValueReferenceType(); |
| 1623 | } |
| 1624 | |
| 1625 | /// \brief Determine whether this is a copy or move constructor. |
| 1626 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1627 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1628 | // A non-template constructor for class X is a copy constructor |
| 1629 | // if its first parameter is of type X&, const X&, volatile X& or |
| 1630 | // const volatile X&, and either there are no other parameters |
| 1631 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1632 | // C++0x [class.copy]p3: |
| 1633 | // A non-template constructor for class X is a move constructor if its |
| 1634 | // first parameter is of type X&&, const X&&, volatile X&&, or |
| 1635 | // const volatile X&&, and either there are no other parameters or else |
| 1636 | // all other parameters have default arguments. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1637 | if ((getNumParams() < 1) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1638 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1639 | (getPrimaryTemplate() != 0) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1640 | (getDescribedFunctionTemplate() != 0)) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1641 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1642 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1643 | const ParmVarDecl *Param = getParamDecl(0); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1644 | |
| 1645 | // Do we have a reference type? |
| 1646 | const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1647 | if (!ParamRefType) |
| 1648 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1649 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1650 | // Is it a reference to our class type? |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1651 | ASTContext &Context = getASTContext(); |
| 1652 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1653 | CanQualType PointeeType |
| 1654 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Douglas Gregor | 14e0b3d | 2009-09-15 20:50:23 +0000 | [diff] [blame] | 1655 | CanQualType ClassTy |
| 1656 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1657 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 1658 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1659 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1660 | // FIXME: other qualifiers? |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1661 | |
| 1662 | // We have a copy or move constructor. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1663 | TypeQuals = PointeeType.getCVRQualifiers(); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1664 | return true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1667 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1668 | // C++ [class.conv.ctor]p1: |
| 1669 | // A constructor declared without the function-specifier explicit |
| 1670 | // that can be called with a single parameter specifies a |
| 1671 | // conversion from the type of its first parameter to the type of |
| 1672 | // its class. Such a constructor is called a converting |
| 1673 | // constructor. |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1674 | if (isExplicit() && !AllowExplicit) |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1675 | return false; |
| 1676 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | return (getNumParams() == 0 && |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1678 | getType()->getAs<FunctionProtoType>()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1679 | (getNumParams() == 1) || |
Douglas Gregor | 113c444 | 2012-06-05 23:44:51 +0000 | [diff] [blame] | 1680 | (getNumParams() > 1 && |
| 1681 | (getParamDecl(1)->hasDefaultArg() || |
| 1682 | getParamDecl(1)->isParameterPack())); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1683 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1684 | |
Douglas Gregor | 6493cc5 | 2010-11-08 17:16:59 +0000 | [diff] [blame] | 1685 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1686 | if ((getNumParams() < 1) || |
| 1687 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
| 1688 | (getPrimaryTemplate() == 0) || |
| 1689 | (getDescribedFunctionTemplate() != 0)) |
| 1690 | return false; |
| 1691 | |
| 1692 | const ParmVarDecl *Param = getParamDecl(0); |
| 1693 | |
| 1694 | ASTContext &Context = getASTContext(); |
| 1695 | CanQualType ParamType = Context.getCanonicalType(Param->getType()); |
| 1696 | |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1697 | // Is it the same as our our class type? |
| 1698 | CanQualType ClassTy |
| 1699 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
| 1700 | if (ParamType.getUnqualifiedType() != ClassTy) |
| 1701 | return false; |
| 1702 | |
| 1703 | return true; |
| 1704 | } |
| 1705 | |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1706 | const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { |
| 1707 | // Hack: we store the inherited constructor in the overridden method table |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1708 | method_iterator It = getASTContext().overridden_methods_begin(this); |
| 1709 | if (It == getASTContext().overridden_methods_end(this)) |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1710 | return 0; |
| 1711 | |
| 1712 | return cast<CXXConstructorDecl>(*It); |
| 1713 | } |
| 1714 | |
| 1715 | void |
| 1716 | CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ |
| 1717 | // Hack: we store the inherited constructor in the overridden method table |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1718 | assert(getASTContext().overridden_methods_size(this) == 0 && |
| 1719 | "Base ctor already set."); |
| 1720 | getASTContext().addOverriddenMethod(this, BaseCtor); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1723 | void CXXDestructorDecl::anchor() { } |
| 1724 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1725 | CXXDestructorDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1726 | CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1727 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXDestructorDecl)); |
| 1728 | return new (Mem) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1729 | QualType(), 0, false, false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | CXXDestructorDecl * |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1733 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1734 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1735 | const DeclarationNameInfo &NameInfo, |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1736 | QualType T, TypeSourceInfo *TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1737 | bool isInline, bool isImplicitlyDeclared) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1738 | assert(NameInfo.getName().getNameKind() |
| 1739 | == DeclarationName::CXXDestructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1740 | "Name must refer to a destructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1741 | return new (C) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, isInline, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1742 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1745 | void CXXConversionDecl::anchor() { } |
| 1746 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1747 | CXXConversionDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1748 | CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1749 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConversionDecl)); |
| 1750 | return new (Mem) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), |
| 1751 | QualType(), 0, false, false, false, |
| 1752 | SourceLocation()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | CXXConversionDecl * |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1756 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1757 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1758 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1759 | QualType T, TypeSourceInfo *TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1760 | bool isInline, bool isExplicit, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1761 | bool isConstexpr, SourceLocation EndLocation) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1762 | assert(NameInfo.getName().getNameKind() |
| 1763 | == DeclarationName::CXXConversionFunctionName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1764 | "Name must refer to a conversion function"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1765 | return new (C) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1766 | isInline, isExplicit, isConstexpr, |
| 1767 | EndLocation); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
Douglas Gregor | f6e2e02 | 2012-02-16 01:06:16 +0000 | [diff] [blame] | 1770 | bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { |
| 1771 | return isImplicit() && getParent()->isLambda() && |
| 1772 | getConversionType()->isBlockPointerType(); |
| 1773 | } |
| 1774 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1775 | void LinkageSpecDecl::anchor() { } |
| 1776 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 1777 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1779 | SourceLocation ExternLoc, |
| 1780 | SourceLocation LangLoc, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1781 | LanguageIDs Lang, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1782 | SourceLocation RBraceLoc) { |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1783 | return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 1784 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1785 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1786 | LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1787 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LinkageSpecDecl)); |
| 1788 | return new (Mem) LinkageSpecDecl(0, SourceLocation(), SourceLocation(), |
| 1789 | lang_c, SourceLocation()); |
| 1790 | } |
| 1791 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1792 | void UsingDirectiveDecl::anchor() { } |
| 1793 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1794 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 1795 | SourceLocation L, |
| 1796 | SourceLocation NamespaceLoc, |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1797 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1798 | SourceLocation IdentLoc, |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1799 | NamedDecl *Used, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1800 | DeclContext *CommonAncestor) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1801 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) |
| 1802 | Used = NS->getOriginalNamespace(); |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1803 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, |
| 1804 | IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1807 | UsingDirectiveDecl * |
| 1808 | UsingDirectiveDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1809 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDirectiveDecl)); |
| 1810 | return new (Mem) UsingDirectiveDecl(0, SourceLocation(), SourceLocation(), |
| 1811 | NestedNameSpecifierLoc(), |
| 1812 | SourceLocation(), 0, 0); |
| 1813 | } |
| 1814 | |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1815 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { |
| 1816 | if (NamespaceAliasDecl *NA = |
| 1817 | dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) |
| 1818 | return NA->getNamespace(); |
| 1819 | return cast_or_null<NamespaceDecl>(NominatedNamespace); |
| 1820 | } |
| 1821 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1822 | void NamespaceDecl::anchor() { } |
| 1823 | |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1824 | NamespaceDecl::NamespaceDecl(DeclContext *DC, bool Inline, |
| 1825 | SourceLocation StartLoc, |
| 1826 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1827 | NamespaceDecl *PrevDecl) |
| 1828 | : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), |
| 1829 | LocStart(StartLoc), RBraceLoc(), AnonOrFirstNamespaceAndInline(0, Inline) |
| 1830 | { |
| 1831 | setPreviousDeclaration(PrevDecl); |
| 1832 | |
| 1833 | if (PrevDecl) |
| 1834 | AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); |
| 1835 | } |
| 1836 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1837 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1838 | bool Inline, SourceLocation StartLoc, |
| 1839 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1840 | NamespaceDecl *PrevDecl) { |
| 1841 | return new (C) NamespaceDecl(DC, Inline, StartLoc, IdLoc, Id, PrevDecl); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1845 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceDecl)); |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1846 | return new (Mem) NamespaceDecl(0, false, SourceLocation(), SourceLocation(), |
| 1847 | 0, 0); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1850 | void NamespaceAliasDecl::anchor() { } |
| 1851 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 1853 | SourceLocation UsingLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | SourceLocation AliasLoc, |
| 1855 | IdentifierInfo *Alias, |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1856 | NestedNameSpecifierLoc QualifierLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | SourceLocation IdentLoc, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1858 | NamedDecl *Namespace) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1859 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) |
| 1860 | Namespace = NS->getOriginalNamespace(); |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1861 | return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, |
| 1862 | QualifierLoc, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1865 | NamespaceAliasDecl * |
| 1866 | NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1867 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceAliasDecl)); |
| 1868 | return new (Mem) NamespaceAliasDecl(0, SourceLocation(), SourceLocation(), 0, |
| 1869 | NestedNameSpecifierLoc(), |
| 1870 | SourceLocation(), 0); |
| 1871 | } |
| 1872 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1873 | void UsingShadowDecl::anchor() { } |
| 1874 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1875 | UsingShadowDecl * |
| 1876 | UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1877 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingShadowDecl)); |
| 1878 | return new (Mem) UsingShadowDecl(0, SourceLocation(), 0, 0); |
| 1879 | } |
| 1880 | |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1881 | UsingDecl *UsingShadowDecl::getUsingDecl() const { |
| 1882 | const UsingShadowDecl *Shadow = this; |
| 1883 | while (const UsingShadowDecl *NextShadow = |
| 1884 | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) |
| 1885 | Shadow = NextShadow; |
| 1886 | return cast<UsingDecl>(Shadow->UsingOrNextShadow); |
| 1887 | } |
| 1888 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1889 | void UsingDecl::anchor() { } |
| 1890 | |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1891 | void UsingDecl::addShadowDecl(UsingShadowDecl *S) { |
| 1892 | assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && |
| 1893 | "declaration already in set"); |
| 1894 | assert(S->getUsingDecl() == this); |
| 1895 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1896 | if (FirstUsingShadow.getPointer()) |
| 1897 | S->UsingOrNextShadow = FirstUsingShadow.getPointer(); |
| 1898 | FirstUsingShadow.setPointer(S); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { |
| 1902 | assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && |
| 1903 | "declaration not in set"); |
| 1904 | assert(S->getUsingDecl() == this); |
| 1905 | |
| 1906 | // Remove S from the shadow decl chain. This is O(n) but hopefully rare. |
| 1907 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1908 | if (FirstUsingShadow.getPointer() == S) { |
| 1909 | FirstUsingShadow.setPointer( |
| 1910 | dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1911 | S->UsingOrNextShadow = this; |
| 1912 | return; |
| 1913 | } |
| 1914 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1915 | UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1916 | while (Prev->UsingOrNextShadow != S) |
| 1917 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); |
| 1918 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; |
| 1919 | S->UsingOrNextShadow = this; |
| 1920 | } |
| 1921 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1922 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, |
| 1923 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1924 | const DeclarationNameInfo &NameInfo, |
| 1925 | bool IsTypeNameArg) { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1926 | return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1929 | UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1930 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDecl)); |
| 1931 | return new (Mem) UsingDecl(0, SourceLocation(), NestedNameSpecifierLoc(), |
| 1932 | DeclarationNameInfo(), false); |
| 1933 | } |
| 1934 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1935 | void UnresolvedUsingValueDecl::anchor() { } |
| 1936 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1937 | UnresolvedUsingValueDecl * |
| 1938 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, |
| 1939 | SourceLocation UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1940 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1941 | const DeclarationNameInfo &NameInfo) { |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1942 | return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1943 | QualifierLoc, NameInfo); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1946 | UnresolvedUsingValueDecl * |
| 1947 | UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1948 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UnresolvedUsingValueDecl)); |
| 1949 | return new (Mem) UnresolvedUsingValueDecl(0, QualType(), SourceLocation(), |
| 1950 | NestedNameSpecifierLoc(), |
| 1951 | DeclarationNameInfo()); |
| 1952 | } |
| 1953 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1954 | void UnresolvedUsingTypenameDecl::anchor() { } |
| 1955 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1956 | UnresolvedUsingTypenameDecl * |
| 1957 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, |
| 1958 | SourceLocation UsingLoc, |
| 1959 | SourceLocation TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1960 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1961 | SourceLocation TargetNameLoc, |
| 1962 | DeclarationName TargetName) { |
| 1963 | return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1964 | QualifierLoc, TargetNameLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1965 | TargetName.getAsIdentifierInfo()); |
Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1968 | UnresolvedUsingTypenameDecl * |
| 1969 | UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1970 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 1971 | sizeof(UnresolvedUsingTypenameDecl)); |
| 1972 | return new (Mem) UnresolvedUsingTypenameDecl(0, SourceLocation(), |
| 1973 | SourceLocation(), |
| 1974 | NestedNameSpecifierLoc(), |
| 1975 | SourceLocation(), |
| 1976 | 0); |
| 1977 | } |
| 1978 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1979 | void StaticAssertDecl::anchor() { } |
| 1980 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1981 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1982 | SourceLocation StaticAssertLoc, |
| 1983 | Expr *AssertExpr, |
| 1984 | StringLiteral *Message, |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 1985 | SourceLocation RParenLoc, |
| 1986 | bool Failed) { |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1987 | return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 1988 | RParenLoc, Failed); |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1991 | StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, |
| 1992 | unsigned ID) { |
| 1993 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(StaticAssertDecl)); |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 1994 | return new (Mem) StaticAssertDecl(0, SourceLocation(), 0, 0, |
| 1995 | SourceLocation(), false); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 1998 | static const char *getAccessName(AccessSpecifier AS) { |
| 1999 | switch (AS) { |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2000 | case AS_none: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2001 | llvm_unreachable("Invalid access specifier!"); |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2002 | case AS_public: |
| 2003 | return "public"; |
| 2004 | case AS_private: |
| 2005 | return "private"; |
| 2006 | case AS_protected: |
| 2007 | return "protected"; |
| 2008 | } |
David Blaikie | 561d3ab | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 2009 | llvm_unreachable("Invalid access specifier!"); |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 2013 | AccessSpecifier AS) { |
| 2014 | return DB << getAccessName(AS); |
| 2015 | } |
Richard Smith | f15fda0 | 2012-02-02 01:16:57 +0000 | [diff] [blame] | 2016 | |
| 2017 | const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB, |
| 2018 | AccessSpecifier AS) { |
| 2019 | return DB << getAccessName(AS); |
| 2020 | } |