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