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