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