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