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 | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 20 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 21 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Fariborz Jahanian | faebcbb | 2009-09-12 19:52:10 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallPtrSet.h" |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // Decl Allocation/Deallocation Method Implementations |
| 28 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 29 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 30 | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) |
| 31 | : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 32 | UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false), |
Eli Friedman | 97c134e | 2009-08-15 22:23:00 +0000 | [diff] [blame] | 33 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
| 34 | Abstract(false), HasTrivialConstructor(true), |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 35 | HasTrivialCopyConstructor(true), HasTrivialMoveConstructor(true), |
| 36 | HasTrivialCopyAssignment(true), HasTrivialMoveAssignment(true), |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 37 | HasTrivialDestructor(true), ComputedVisibleConversions(false), |
Douglas Gregor | 1827403 | 2010-07-03 00:47:00 +0000 | [diff] [blame] | 38 | DeclaredDefaultConstructor(false), DeclaredCopyConstructor(false), |
Douglas Gregor | a376d10 | 2010-07-02 21:50:04 +0000 | [diff] [blame] | 39 | DeclaredCopyAssignment(false), DeclaredDestructor(false), |
Anders Carlsson | cb88a1f | 2011-01-24 16:26:15 +0000 | [diff] [blame] | 40 | NumBases(0), NumVBases(0), Bases(), VBases(), |
| 41 | Definition(D), FirstFriend(0) { |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 45 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 46 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl) |
| 47 | : RecordDecl(K, TK, DC, StartLoc, IdLoc, Id, PrevDecl), |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 48 | DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 49 | TemplateOrInstantiation() { } |
Douglas Gregor | 7d7e672 | 2008-11-12 23:21:09 +0000 | [diff] [blame] | 50 | |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 51 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 52 | DeclContext *DC, SourceLocation StartLoc, |
| 53 | SourceLocation IdLoc, IdentifierInfo *Id, |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 54 | CXXRecordDecl* PrevDecl, |
| 55 | bool DelayTypeCreation) { |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 56 | CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, StartLoc, IdLoc, |
| 57 | Id, PrevDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 8e9e9ef | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 59 | // FIXME: DelayTypeCreation seems like such a hack |
Douglas Gregor | aafc0cc | 2009-05-15 19:11:46 +0000 | [diff] [blame] | 60 | if (!DelayTypeCreation) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 61 | C.getTypeDeclType(R, PrevDecl); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 62 | return R; |
| 63 | } |
| 64 | |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 65 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, EmptyShell Empty) { |
Abramo Bagnara | ba877ad | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 66 | return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), |
| 67 | SourceLocation(), 0, 0); |
Argyrios Kyrtzidis | b8b03e6 | 2010-07-02 11:54:55 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | void |
Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 71 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 72 | unsigned NumBases) { |
Douglas Gregor | 2d5b703 | 2010-02-11 01:30:34 +0000 | [diff] [blame] | 73 | ASTContext &C = getASTContext(); |
| 74 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 75 | // C++ [dcl.init.aggr]p1: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 76 | // An aggregate is an array or a class (clause 9) with [...] |
| 77 | // no base classes [...]. |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 78 | data().Aggregate = false; |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 79 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 80 | if (!data().Bases.isOffset() && data().NumBases > 0) |
| 81 | C.Deallocate(data().getBases()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 82 | |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 83 | // The set of seen virtual base types. |
Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 84 | llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 85 | |
| 86 | // The virtual bases of this class. |
| 87 | llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 89 | data().Bases = new(C) CXXBaseSpecifier [NumBases]; |
| 90 | data().NumBases = NumBases; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 91 | for (unsigned i = 0; i < NumBases; ++i) { |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 92 | data().getBases()[i] = *Bases[i]; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 93 | // Keep track of inherited vbases for this base class. |
| 94 | const CXXBaseSpecifier *Base = Bases[i]; |
| 95 | QualType BaseType = Base->getType(); |
Douglas Gregor | 5fe8c04 | 2010-02-27 00:25:28 +0000 | [diff] [blame] | 96 | // Skip dependent types; we can't do any checking on them now. |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 97 | if (BaseType->isDependentType()) |
| 98 | continue; |
| 99 | CXXRecordDecl *BaseClassDecl |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 100 | = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 110 | // A class with a non-empty base class is not empty. |
| 111 | // FIXME: Standard ref? |
| 112 | if (!BaseClassDecl->isEmpty()) |
| 113 | data().Empty = false; |
| 114 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 115 | // C++ [class.virtual]p1: |
| 116 | // A class that declares or inherits a virtual function is called a |
| 117 | // polymorphic class. |
| 118 | if (BaseClassDecl->isPolymorphic()) |
| 119 | data().Polymorphic = true; |
| 120 | |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 121 | // Now go through all virtual bases of this base and add them. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | for (CXXRecordDecl::base_class_iterator VBase = |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 123 | BaseClassDecl->vbases_begin(), |
| 124 | E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 125 | // Add this base if it's not already in the list. |
Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 126 | if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType()))) |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 127 | VBases.push_back(VBase); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 128 | } |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 129 | |
| 130 | if (Base->isVirtual()) { |
| 131 | // Add this base if it's not already in the list. |
Anders Carlsson | 1c36393 | 2010-03-29 19:49:09 +0000 | [diff] [blame] | 132 | if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType))) |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 133 | VBases.push_back(Base); |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 134 | |
| 135 | // C++0x [meta.unary.prop] is_empty: |
| 136 | // T is a class type, but not a union type, with ... no virtual base |
| 137 | // classes |
| 138 | data().Empty = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 139 | |
| 140 | // C++ [class.ctor]p5: |
| 141 | // A constructor is trivial if its class has no virtual base classes. |
| 142 | data().HasTrivialConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 143 | |
| 144 | // C++0x [class.copy]p13: |
| 145 | // A copy/move constructor for class X is trivial if it is neither |
| 146 | // user-provided nor deleted and if |
| 147 | // -- class X has no virtual functions and no virtual base classes, and |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 148 | data().HasTrivialCopyConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 149 | data().HasTrivialMoveConstructor = false; |
| 150 | |
| 151 | // C++0x [class.copy]p27: |
| 152 | // A copy/move assignment operator for class X is trivial if it is |
| 153 | // neither user-provided nor deleted and if |
| 154 | // -- class X has no virtual functions and no virtual base classes, and |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 155 | data().HasTrivialCopyAssignment = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 156 | data().HasTrivialMoveAssignment = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 157 | } else { |
| 158 | // C++ [class.ctor]p5: |
| 159 | // A constructor is trivial if all the direct base classes of its |
| 160 | // class have trivial constructors. |
| 161 | if (!BaseClassDecl->hasTrivialConstructor()) |
| 162 | data().HasTrivialConstructor = false; |
| 163 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 164 | // C++0x [class.copy]p13: |
| 165 | // A copy/move constructor for class X is trivial if [...] |
| 166 | // [...] |
| 167 | // -- the constructor selected to copy/move each direct base class |
| 168 | // subobject is trivial, and |
| 169 | // FIXME: C++0x: We need to only consider the selected constructor |
| 170 | // instead of all of them. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 171 | if (!BaseClassDecl->hasTrivialCopyConstructor()) |
| 172 | data().HasTrivialCopyConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 173 | if (!BaseClassDecl->hasTrivialMoveConstructor()) |
| 174 | data().HasTrivialMoveConstructor = false; |
| 175 | |
| 176 | // C++0x [class.copy]p27: |
| 177 | // A copy/move assignment operator for class X is trivial if [...] |
| 178 | // [...] |
| 179 | // -- the assignment operator selected to copy/move each direct base |
| 180 | // class subobject is trivial, and |
| 181 | // FIXME: C++0x: We need to only consider the selected operator instead |
| 182 | // of all of them. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 183 | if (!BaseClassDecl->hasTrivialCopyAssignment()) |
| 184 | data().HasTrivialCopyAssignment = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 185 | if (!BaseClassDecl->hasTrivialMoveAssignment()) |
| 186 | data().HasTrivialMoveAssignment = false; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 187 | } |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 188 | |
| 189 | // C++ [class.ctor]p3: |
| 190 | // A destructor is trivial if all the direct base classes of its class |
| 191 | // have trivial destructors. |
| 192 | if (!BaseClassDecl->hasTrivialDestructor()) |
| 193 | data().HasTrivialDestructor = false; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 194 | } |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 195 | |
| 196 | if (VBases.empty()) |
| 197 | return; |
| 198 | |
| 199 | // Create base specifier for any direct or indirect virtual bases. |
| 200 | data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; |
| 201 | data().NumVBases = VBases.size(); |
| 202 | for (int I = 0, E = VBases.size(); I != E; ++I) { |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 203 | TypeSourceInfo *VBaseTypeInfo = VBases[I]->getTypeSourceInfo(); |
| 204 | |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 205 | // Skip dependent types; we can't do any checking on them now. |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 206 | if (VBaseTypeInfo->getType()->isDependentType()) |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 207 | continue; |
| 208 | |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 209 | CXXRecordDecl *VBaseClassDecl = cast<CXXRecordDecl>( |
| 210 | VBaseTypeInfo->getType()->getAs<RecordType>()->getDecl()); |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 211 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 212 | data().getVBases()[I] = |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 213 | CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true, |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 214 | VBaseClassDecl->getTagKind() == TTK_Class, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 215 | VBases[I]->getAccessSpecifier(), VBaseTypeInfo, |
| 216 | SourceLocation()); |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 217 | } |
Douglas Gregor | 57c856b | 2008-10-23 18:13:27 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Douglas Gregor | 9edad9b | 2010-01-14 17:47:39 +0000 | [diff] [blame] | 220 | /// Callback function for CXXRecordDecl::forallBases that acknowledges |
| 221 | /// that it saw a base class. |
| 222 | static bool SawBase(const CXXRecordDecl *, void *) { |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | bool CXXRecordDecl::hasAnyDependentBases() const { |
| 227 | if (!isDependentContext()) |
| 228 | return false; |
| 229 | |
| 230 | return !forallBases(SawBase, 0); |
| 231 | } |
| 232 | |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 233 | bool CXXRecordDecl::hasConstCopyConstructor(const ASTContext &Context) const { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 234 | return getCopyConstructor(Context, Qualifiers::Const) != 0; |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 237 | bool CXXRecordDecl::isTriviallyCopyable() const { |
| 238 | // C++0x [class]p5: |
| 239 | // A trivially copyable class is a class that: |
| 240 | // -- has no non-trivial copy constructors, |
| 241 | if (!hasTrivialCopyConstructor()) return false; |
| 242 | // -- has no non-trivial move constructors, |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 243 | if (!hasTrivialMoveConstructor()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 244 | // -- has no non-trivial copy assignment operators, |
| 245 | if (!hasTrivialCopyAssignment()) return false; |
| 246 | // -- has no non-trivial move assignment operators, and |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 247 | if (!hasTrivialMoveAssignment()) return false; |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 248 | // -- has a trivial destructor. |
| 249 | if (!hasTrivialDestructor()) return false; |
| 250 | |
| 251 | return true; |
| 252 | } |
| 253 | |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 254 | /// \brief Perform a simplistic form of overload resolution that only considers |
| 255 | /// cv-qualifiers on a single parameter, and return the best overload candidate |
| 256 | /// (if there is one). |
| 257 | static CXXMethodDecl * |
| 258 | GetBestOverloadCandidateSimple( |
| 259 | const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) { |
| 260 | if (Cands.empty()) |
| 261 | return 0; |
| 262 | if (Cands.size() == 1) |
| 263 | return Cands[0].first; |
| 264 | |
| 265 | unsigned Best = 0, N = Cands.size(); |
| 266 | for (unsigned I = 1; I != N; ++I) |
| 267 | if (Cands[Best].second.isSupersetOf(Cands[I].second)) |
| 268 | Best = I; |
| 269 | |
| 270 | for (unsigned I = 1; I != N; ++I) |
| 271 | if (Cands[Best].second.isSupersetOf(Cands[I].second)) |
| 272 | return 0; |
| 273 | |
| 274 | return Cands[Best].first; |
| 275 | } |
| 276 | |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 277 | CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(const ASTContext &Context, |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 278 | unsigned TypeQuals) const{ |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 279 | QualType ClassType |
| 280 | = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | DeclarationName ConstructorName |
Douglas Gregor | 9e7d9de | 2008-12-15 21:24:18 +0000 | [diff] [blame] | 282 | = Context.DeclarationNames.getCXXConstructorName( |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 283 | Context.getCanonicalType(ClassType)); |
| 284 | unsigned FoundTQs; |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 285 | llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 286 | DeclContext::lookup_const_iterator Con, ConEnd; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 287 | for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); |
Douglas Gregor | fdfab6b | 2008-12-23 21:31:30 +0000 | [diff] [blame] | 288 | Con != ConEnd; ++Con) { |
Douglas Gregor | d93bacf | 2009-09-04 14:46:39 +0000 | [diff] [blame] | 289 | // C++ [class.copy]p2: |
| 290 | // A non-template constructor for class X is a copy constructor if [...] |
| 291 | if (isa<FunctionTemplateDecl>(*Con)) |
| 292 | continue; |
| 293 | |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 294 | CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); |
| 295 | if (Constructor->isCopyConstructor(FoundTQs)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 296 | if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) || |
| 297 | (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const))) |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 298 | Found.push_back(std::make_pair( |
| 299 | const_cast<CXXConstructorDecl *>(Constructor), |
| 300 | Qualifiers::fromCVRMask(FoundTQs))); |
Fariborz Jahanian | 485f087 | 2009-06-22 23:34:40 +0000 | [diff] [blame] | 301 | } |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 302 | } |
Douglas Gregor | 0d405db | 2010-07-01 20:59:04 +0000 | [diff] [blame] | 303 | |
| 304 | return cast_or_null<CXXConstructorDecl>( |
| 305 | GetBestOverloadCandidateSimple(Found)); |
Douglas Gregor | 396b7cd | 2008-11-03 17:51:48 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Douglas Gregor | b87786f | 2010-07-01 17:48:08 +0000 | [diff] [blame] | 308 | CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const { |
| 309 | ASTContext &Context = getASTContext(); |
| 310 | QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this)); |
| 311 | DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal); |
| 312 | |
| 313 | llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; |
| 314 | DeclContext::lookup_const_iterator Op, OpEnd; |
| 315 | for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) { |
| 316 | // C++ [class.copy]p9: |
| 317 | // A user-declared copy assignment operator is a non-static non-template |
| 318 | // member function of class X with exactly one parameter of type X, X&, |
| 319 | // const X&, volatile X& or const volatile X&. |
| 320 | const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op); |
| 321 | if (!Method || Method->isStatic() || Method->getPrimaryTemplate()) |
| 322 | continue; |
| 323 | |
| 324 | const FunctionProtoType *FnType |
| 325 | = Method->getType()->getAs<FunctionProtoType>(); |
| 326 | assert(FnType && "Overloaded operator has no prototype."); |
| 327 | // Don't assert on this; an invalid decl might have been left in the AST. |
| 328 | if (FnType->getNumArgs() != 1 || FnType->isVariadic()) |
| 329 | continue; |
| 330 | |
| 331 | QualType ArgType = FnType->getArgType(0); |
| 332 | Qualifiers Quals; |
| 333 | if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { |
| 334 | ArgType = Ref->getPointeeType(); |
| 335 | // If we have a const argument and we have a reference to a non-const, |
| 336 | // this function does not match. |
| 337 | if (ArgIsConst && !ArgType.isConstQualified()) |
| 338 | continue; |
| 339 | |
| 340 | Quals = ArgType.getQualifiers(); |
| 341 | } else { |
| 342 | // By-value copy-assignment operators are treated like const X& |
| 343 | // copy-assignment operators. |
| 344 | Quals = Qualifiers::fromCVRMask(Qualifiers::Const); |
| 345 | } |
| 346 | |
| 347 | if (!Context.hasSameUnqualifiedType(ArgType, Class)) |
| 348 | continue; |
| 349 | |
| 350 | // Save this copy-assignment operator. It might be "the one". |
| 351 | Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals)); |
| 352 | } |
| 353 | |
| 354 | // Use a simplistic form of overload resolution to find the candidate. |
| 355 | return GetBestOverloadCandidateSimple(Found); |
| 356 | } |
| 357 | |
Douglas Gregor | 2138664 | 2010-09-28 21:55:22 +0000 | [diff] [blame] | 358 | void CXXRecordDecl::markedVirtualFunctionPure() { |
| 359 | // C++ [class.abstract]p2: |
| 360 | // A class is abstract if it has at least one pure virtual function. |
| 361 | data().Abstract = true; |
| 362 | } |
| 363 | |
| 364 | void CXXRecordDecl::addedMember(Decl *D) { |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 365 | // Ignore friends and invalid declarations. |
| 366 | if (D->getFriendObjectKind() || D->isInvalidDecl()) |
Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 367 | return; |
| 368 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 369 | FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); |
| 370 | if (FunTmpl) |
| 371 | D = FunTmpl->getTemplatedDecl(); |
| 372 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 373 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 374 | if (Method->isVirtual()) { |
| 375 | // C++ [dcl.init.aggr]p1: |
| 376 | // An aggregate is an array or a class with [...] no virtual functions. |
| 377 | data().Aggregate = false; |
| 378 | |
| 379 | // C++ [class]p4: |
| 380 | // A POD-struct is an aggregate class... |
| 381 | data().PlainOldData = false; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 382 | |
| 383 | // Virtual functions make the class non-empty. |
| 384 | // FIXME: Standard ref? |
| 385 | data().Empty = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 386 | |
| 387 | // C++ [class.virtual]p1: |
| 388 | // A class that declares or inherits a virtual function is called a |
| 389 | // polymorphic class. |
| 390 | data().Polymorphic = true; |
| 391 | |
| 392 | // None of the special member functions are trivial. |
| 393 | data().HasTrivialConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 394 | |
| 395 | // C++0x [class.copy]p13: |
| 396 | // A copy/move constructor for class X is trivial if [...] |
| 397 | // -- class X has no virtual functions [...] |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 398 | data().HasTrivialCopyConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 399 | data().HasTrivialMoveConstructor = false; |
| 400 | |
| 401 | // C++0x [class.copy]p27: |
| 402 | // A copy/move assignment operator for class X is trivial if [...] |
| 403 | // -- class X has no virtual functions [...] |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 404 | data().HasTrivialCopyAssignment = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 405 | data().HasTrivialMoveAssignment = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 406 | // FIXME: Destructor? |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 410 | if (D->isImplicit()) { |
Argyrios Kyrtzidis | b6cc0e1 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 411 | // Notify that an implicit member was added after the definition |
| 412 | // was completed. |
| 413 | if (!isBeingDefined()) |
| 414 | if (ASTMutationListener *L = getASTMutationListener()) |
| 415 | L->AddedCXXImplicitMember(data().Definition, D); |
Argyrios Kyrtzidis | 046c03b | 2010-10-20 23:48:42 +0000 | [diff] [blame] | 416 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 417 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 418 | // If this is the implicit default constructor, note that we have now |
| 419 | // declared it. |
| 420 | if (Constructor->isDefaultConstructor()) |
| 421 | data().DeclaredDefaultConstructor = true; |
| 422 | // If this is the implicit copy constructor, note that we have now |
| 423 | // declared it. |
| 424 | else if (Constructor->isCopyConstructor()) |
| 425 | data().DeclaredCopyConstructor = true; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 426 | return; |
| 427 | } |
| 428 | |
| 429 | if (isa<CXXDestructorDecl>(D)) { |
Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 430 | data().DeclaredDestructor = true; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
| 434 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 435 | // If this is the implicit copy constructor, note that we have now |
| 436 | // declared it. |
| 437 | // FIXME: Move constructors |
Douglas Gregor | 3e9438b | 2010-09-27 22:37:28 +0000 | [diff] [blame] | 438 | if (Method->getOverloadedOperator() == OO_Equal) |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 439 | data().DeclaredCopyAssignment = true; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 440 | return; |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 441 | } |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 442 | |
| 443 | // Any other implicit declarations are handled like normal declarations. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | // Handle (user-declared) constructors. |
| 447 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 448 | // Note that we have a user-declared constructor. |
| 449 | data().UserDeclaredConstructor = true; |
| 450 | |
| 451 | // Note that we have no need of an implicitly-declared default constructor. |
| 452 | data().DeclaredDefaultConstructor = true; |
| 453 | |
| 454 | // C++ [dcl.init.aggr]p1: |
| 455 | // An aggregate is an array or a class (clause 9) with no |
| 456 | // user-declared constructors (12.1) [...]. |
| 457 | data().Aggregate = false; |
| 458 | |
| 459 | // C++ [class]p4: |
| 460 | // A POD-struct is an aggregate class [...] |
| 461 | data().PlainOldData = false; |
| 462 | |
| 463 | // C++ [class.ctor]p5: |
| 464 | // A constructor is trivial if it is an implicitly-declared default |
| 465 | // constructor. |
| 466 | // FIXME: C++0x: don't do this for "= default" default constructors. |
| 467 | data().HasTrivialConstructor = false; |
| 468 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 469 | // Note when we have a user-declared copy or move constructor, which will |
| 470 | // suppress the implicit declaration of those constructors. |
| 471 | if (!FunTmpl) { |
| 472 | if (Constructor->isCopyConstructor()) { |
| 473 | data().UserDeclaredCopyConstructor = true; |
| 474 | data().DeclaredCopyConstructor = true; |
| 475 | |
| 476 | // C++0x [class.copy]p13: |
| 477 | // A copy/move constructor for class X is trivial if it is neither |
| 478 | // user-provided nor deleted |
| 479 | // FIXME: C++0x: don't do this for "= default" copy constructors. |
| 480 | data().HasTrivialCopyConstructor = false; |
| 481 | } else if (Constructor->isMoveConstructor()) { |
| 482 | // C++0x [class.copy]p13: |
| 483 | // A copy/move constructor for class X is trivial if it is neither |
| 484 | // user-provided nor deleted |
| 485 | // FIXME: C++0x: don't do this for "= default" move constructors. |
| 486 | data().HasTrivialMoveConstructor = false; |
| 487 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 488 | } |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 489 | |
Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 490 | return; |
| 491 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 492 | |
Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 493 | // Handle (user-declared) destructors. |
| 494 | if (isa<CXXDestructorDecl>(D)) { |
| 495 | data().DeclaredDestructor = true; |
| 496 | data().UserDeclaredDestructor = true; |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 497 | |
| 498 | // C++ [class]p4: |
| 499 | // A POD-struct is an aggregate class that has [...] no user-defined |
| 500 | // destructor. |
| 501 | data().PlainOldData = false; |
| 502 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 503 | // C++ [class.dtor]p3: |
| 504 | // A destructor is trivial if it is an implicitly-declared destructor and |
| 505 | // [...]. |
| 506 | // |
| 507 | // FIXME: C++0x: don't do this for "= default" destructors |
| 508 | data().HasTrivialDestructor = false; |
| 509 | |
Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 510 | return; |
| 511 | } |
Douglas Gregor | 5c0646b | 2010-09-27 21:17:54 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | 0ed2e08 | 2010-09-27 22:48:58 +0000 | [diff] [blame] | 513 | // Handle (user-declared) member functions. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 514 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
| 515 | if (Method->getOverloadedOperator() == OO_Equal) { |
| 516 | // We're interested specifically in copy assignment operators. |
| 517 | const FunctionProtoType *FnType |
| 518 | = Method->getType()->getAs<FunctionProtoType>(); |
| 519 | assert(FnType && "Overloaded operator has no proto function type."); |
| 520 | assert(FnType->getNumArgs() == 1 && !FnType->isVariadic()); |
| 521 | |
| 522 | // Copy assignment operators must be non-templates. |
| 523 | if (Method->getPrimaryTemplate() || FunTmpl) |
| 524 | return; |
| 525 | |
| 526 | ASTContext &Context = getASTContext(); |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 527 | QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType( |
| 528 | const_cast<CXXRecordDecl*>(this))); |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 529 | |
| 530 | bool isRValueRefArg = false; |
| 531 | QualType ArgType = FnType->getArgType(0); |
| 532 | if (const LValueReferenceType *Ref = |
| 533 | ArgType->getAs<LValueReferenceType>()) { |
| 534 | ArgType = Ref->getPointeeType(); |
| 535 | } else if (const RValueReferenceType *Ref = |
| 536 | ArgType->getAs<RValueReferenceType>()) { |
| 537 | ArgType = Ref->getPointeeType(); |
| 538 | isRValueRefArg = true; |
| 539 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 540 | if (!Context.hasSameUnqualifiedType(ClassType, ArgType)) |
| 541 | return; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 542 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 543 | // C++ [class]p4: |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 544 | // A POD-struct is an aggregate class that [...] has no user-defined |
| 545 | // copy assignment operator [...]. |
| 546 | // FIXME: This should be probably determined dynamically in terms of |
| 547 | // other more precise attributes to correctly model how it is specified |
| 548 | // in C++0x. Setting it here happens to do the right thing. |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 549 | data().PlainOldData = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 550 | |
| 551 | if (!isRValueRefArg) { |
| 552 | // This is a copy assignment operator. |
| 553 | |
| 554 | // Suppress the implicit declaration of a copy constructor. |
| 555 | data().UserDeclaredCopyAssignment = true; |
| 556 | data().DeclaredCopyAssignment = true; |
| 557 | |
| 558 | // C++0x [class.copy]p27: |
| 559 | // A copy/move assignment operator for class X is trivial if it is |
| 560 | // neither user-provided nor deleted [...] |
| 561 | // FIXME: C++0x: don't do this for "= default" copy operators. |
| 562 | data().HasTrivialCopyAssignment = false; |
| 563 | } else { |
| 564 | // This is a move assignment operator. |
| 565 | |
| 566 | // C++0x [class.copy]p27: |
| 567 | // A copy/move assignment operator for class X is trivial if it is |
| 568 | // neither user-provided nor deleted [...] |
| 569 | // FIXME: C++0x: don't do this for "= default" copy operators. |
| 570 | data().HasTrivialMoveAssignment = false; |
| 571 | } |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 572 | } |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 573 | |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 574 | // Keep the list of conversion functions up-to-date. |
| 575 | if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
| 576 | // We don't record specializations. |
| 577 | if (Conversion->getPrimaryTemplate()) |
| 578 | return; |
| 579 | |
| 580 | // FIXME: We intentionally don't use the decl's access here because it |
| 581 | // hasn't been set yet. That's really just a misdesign in Sema. |
| 582 | |
| 583 | if (FunTmpl) { |
| 584 | if (FunTmpl->getPreviousDeclaration()) |
| 585 | data().Conversions.replace(FunTmpl->getPreviousDeclaration(), |
| 586 | FunTmpl); |
| 587 | else |
| 588 | data().Conversions.addDecl(FunTmpl); |
| 589 | } else { |
| 590 | if (Conversion->getPreviousDeclaration()) |
| 591 | data().Conversions.replace(Conversion->getPreviousDeclaration(), |
| 592 | Conversion); |
| 593 | else |
| 594 | data().Conversions.addDecl(Conversion); |
| 595 | } |
| 596 | } |
| 597 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 598 | return; |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 599 | } |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 600 | |
| 601 | // Handle non-static data members. |
| 602 | if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { |
| 603 | // C++ [dcl.init.aggr]p1: |
| 604 | // An aggregate is an array or a class (clause 9) with [...] no |
| 605 | // private or protected non-static data members (clause 11). |
| 606 | // |
| 607 | // A POD must be an aggregate. |
| 608 | if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { |
| 609 | data().Aggregate = false; |
| 610 | data().PlainOldData = false; |
| 611 | } |
| 612 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 613 | // C++0x [class]p9: |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 614 | // A POD struct is a class that is both a trivial class and a |
| 615 | // standard-layout class, and has no non-static data members of type |
| 616 | // non-POD struct, non-POD union (or array of such types). |
| 617 | ASTContext &Context = getASTContext(); |
| 618 | QualType T = Context.getBaseElementType(Field->getType()); |
| 619 | if (!T->isPODType()) |
| 620 | data().PlainOldData = false; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 621 | if (T->isReferenceType()) |
| 622 | data().HasTrivialConstructor = false; |
| 623 | |
| 624 | if (const RecordType *RecordTy = T->getAs<RecordType>()) { |
| 625 | CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); |
| 626 | if (FieldRec->getDefinition()) { |
| 627 | if (!FieldRec->hasTrivialConstructor()) |
| 628 | data().HasTrivialConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 629 | |
| 630 | // C++0x [class.copy]p13: |
| 631 | // A copy/move constructor for class X is trivial if [...] |
| 632 | // [...] |
| 633 | // -- for each non-static data member of X that is of class type (or |
| 634 | // an array thereof), the constructor selected to copy/move that |
| 635 | // member is trivial; |
| 636 | // FIXME: C++0x: We don't correctly model 'selected' constructors. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 637 | if (!FieldRec->hasTrivialCopyConstructor()) |
| 638 | data().HasTrivialCopyConstructor = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 639 | if (!FieldRec->hasTrivialMoveConstructor()) |
| 640 | data().HasTrivialMoveConstructor = false; |
| 641 | |
| 642 | // C++0x [class.copy]p27: |
| 643 | // A copy/move assignment operator for class X is trivial if [...] |
| 644 | // [...] |
| 645 | // -- for each non-static data member of X that is of class type (or |
| 646 | // an array thereof), the assignment operator selected to |
| 647 | // copy/move that member is trivial; |
| 648 | // FIXME: C++0x: We don't correctly model 'selected' operators. |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 649 | if (!FieldRec->hasTrivialCopyAssignment()) |
| 650 | data().HasTrivialCopyAssignment = false; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame^] | 651 | if (!FieldRec->hasTrivialMoveAssignment()) |
| 652 | data().HasTrivialMoveAssignment = false; |
| 653 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 654 | if (!FieldRec->hasTrivialDestructor()) |
| 655 | data().HasTrivialDestructor = false; |
| 656 | } |
| 657 | } |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 658 | |
| 659 | // If this is not a zero-length bit-field, then the class is not empty. |
| 660 | if (data().Empty) { |
| 661 | if (!Field->getBitWidth()) |
| 662 | data().Empty = false; |
| 663 | else if (!Field->getBitWidth()->isTypeDependent() && |
| 664 | !Field->getBitWidth()->isValueDependent()) { |
| 665 | llvm::APSInt Bits; |
| 666 | if (Field->getBitWidth()->isIntegerConstantExpr(Bits, Context)) |
| 667 | if (!!Bits) |
| 668 | data().Empty = false; |
| 669 | } |
| 670 | } |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 671 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 672 | |
| 673 | // Handle using declarations of conversion functions. |
| 674 | if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) |
| 675 | if (Shadow->getDeclName().getNameKind() |
| 676 | == DeclarationName::CXXConversionFunctionName) |
| 677 | data().Conversions.addDecl(Shadow, Shadow->getAccess()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 678 | } |
| 679 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 680 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { |
| 681 | QualType T; |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 682 | if (isa<UsingShadowDecl>(Conv)) |
| 683 | Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl(); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 684 | if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv)) |
| 685 | T = ConvTemp->getTemplatedDecl()->getResultType(); |
| 686 | else |
| 687 | T = cast<CXXConversionDecl>(Conv)->getConversionType(); |
| 688 | return Context.getCanonicalType(T); |
Fariborz Jahanian | 0351a1e | 2009-10-07 20:43:36 +0000 | [diff] [blame] | 689 | } |
| 690 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 691 | /// Collect the visible conversions of a base class. |
| 692 | /// |
| 693 | /// \param Base a base class of the class we're considering |
| 694 | /// \param InVirtual whether this base class is a virtual base (or a base |
| 695 | /// of a virtual base) |
| 696 | /// \param Access the access along the inheritance path to this base |
| 697 | /// \param ParentHiddenTypes the conversions provided by the inheritors |
| 698 | /// of this base |
| 699 | /// \param Output the set to which to add conversions from non-virtual bases |
| 700 | /// \param VOutput the set to which to add conversions from virtual bases |
| 701 | /// \param HiddenVBaseCs the set of conversions which were hidden in a |
| 702 | /// virtual base along some inheritance path |
| 703 | static void CollectVisibleConversions(ASTContext &Context, |
| 704 | CXXRecordDecl *Record, |
| 705 | bool InVirtual, |
| 706 | AccessSpecifier Access, |
| 707 | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, |
| 708 | UnresolvedSetImpl &Output, |
| 709 | UnresolvedSetImpl &VOutput, |
| 710 | llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { |
| 711 | // The set of types which have conversions in this class or its |
| 712 | // subclasses. As an optimization, we don't copy the derived set |
| 713 | // unless it might change. |
| 714 | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; |
| 715 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; |
| 716 | |
| 717 | // Collect the direct conversions and figure out which conversions |
| 718 | // will be hidden in the subclasses. |
| 719 | UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); |
| 720 | if (!Cs.empty()) { |
| 721 | HiddenTypesBuffer = ParentHiddenTypes; |
| 722 | HiddenTypes = &HiddenTypesBuffer; |
| 723 | |
| 724 | for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) { |
| 725 | bool Hidden = |
| 726 | !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl())); |
| 727 | |
| 728 | // If this conversion is hidden and we're in a virtual base, |
| 729 | // remember that it's hidden along some inheritance path. |
| 730 | if (Hidden && InVirtual) |
| 731 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); |
| 732 | |
| 733 | // If this conversion isn't hidden, add it to the appropriate output. |
| 734 | else if (!Hidden) { |
| 735 | AccessSpecifier IAccess |
| 736 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); |
| 737 | |
| 738 | if (InVirtual) |
| 739 | VOutput.addDecl(I.getDecl(), IAccess); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 740 | else |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 741 | Output.addDecl(I.getDecl(), IAccess); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 745 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 746 | // Collect information recursively from any base classes. |
| 747 | for (CXXRecordDecl::base_class_iterator |
| 748 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 749 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 750 | if (!RT) continue; |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 751 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 752 | AccessSpecifier BaseAccess |
| 753 | = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier()); |
| 754 | bool BaseInVirtual = InVirtual || I->isVirtual(); |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 755 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 756 | CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); |
| 757 | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, |
| 758 | *HiddenTypes, Output, VOutput, HiddenVBaseCs); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 759 | } |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 760 | } |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 761 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 762 | /// Collect the visible conversions of a class. |
| 763 | /// |
| 764 | /// This would be extremely straightforward if it weren't for virtual |
| 765 | /// bases. It might be worth special-casing that, really. |
| 766 | static void CollectVisibleConversions(ASTContext &Context, |
| 767 | CXXRecordDecl *Record, |
| 768 | UnresolvedSetImpl &Output) { |
| 769 | // The collection of all conversions in virtual bases that we've |
| 770 | // found. These will be added to the output as long as they don't |
| 771 | // appear in the hidden-conversions set. |
| 772 | UnresolvedSet<8> VBaseCs; |
| 773 | |
| 774 | // The set of conversions in virtual bases that we've determined to |
| 775 | // be hidden. |
| 776 | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; |
| 777 | |
| 778 | // The set of types hidden by classes derived from this one. |
| 779 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; |
| 780 | |
| 781 | // Go ahead and collect the direct conversions and add them to the |
| 782 | // hidden-types set. |
| 783 | UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); |
| 784 | Output.append(Cs.begin(), Cs.end()); |
| 785 | for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) |
| 786 | HiddenTypes.insert(GetConversionType(Context, I.getDecl())); |
| 787 | |
| 788 | // Recursively collect conversions from base classes. |
| 789 | for (CXXRecordDecl::base_class_iterator |
| 790 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 791 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 792 | if (!RT) continue; |
| 793 | |
| 794 | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), |
| 795 | I->isVirtual(), I->getAccessSpecifier(), |
| 796 | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); |
| 797 | } |
| 798 | |
| 799 | // Add any unhidden conversions provided by virtual bases. |
| 800 | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); |
| 801 | I != E; ++I) { |
| 802 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) |
| 803 | Output.addDecl(I.getDecl(), I.getAccess()); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 804 | } |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /// getVisibleConversionFunctions - get all conversion functions visible |
| 808 | /// in current class; including conversion function templates. |
John McCall | eec51cf | 2010-01-20 00:46:10 +0000 | [diff] [blame] | 809 | const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() { |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 810 | // If root class, all conversions are visible. |
| 811 | if (bases_begin() == bases_end()) |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 812 | return &data().Conversions; |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 813 | // If visible conversion list is already evaluated, return it. |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 814 | if (data().ComputedVisibleConversions) |
| 815 | return &data().VisibleConversions; |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 816 | CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 817 | data().ComputedVisibleConversions = true; |
| 818 | return &data().VisibleConversions; |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 819 | } |
| 820 | |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 821 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { |
| 822 | // This operation is O(N) but extremely rare. Sema only uses it to |
| 823 | // remove UsingShadowDecls in a class that were followed by a direct |
| 824 | // declaration, e.g.: |
| 825 | // class A : B { |
| 826 | // using B::operator int; |
| 827 | // operator int(); |
| 828 | // }; |
| 829 | // This is uncommon by itself and even more uncommon in conjunction |
| 830 | // with sufficiently large numbers of directly-declared conversions |
| 831 | // that asymptotic behavior matters. |
| 832 | |
| 833 | UnresolvedSetImpl &Convs = *getConversionFunctions(); |
| 834 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { |
| 835 | if (Convs[I].getDecl() == ConvDecl) { |
| 836 | Convs.erase(I); |
| 837 | assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() |
| 838 | && "conversion was found multiple times in unresolved set"); |
| 839 | return; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | llvm_unreachable("conversion not found in set!"); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 844 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 845 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 846 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 847 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 848 | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 853 | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { |
| 854 | return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); |
| 855 | } |
| 856 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 857 | void |
| 858 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, |
| 859 | TemplateSpecializationKind TSK) { |
| 860 | assert(TemplateOrInstantiation.isNull() && |
| 861 | "Previous template or instantiation?"); |
| 862 | assert(!isa<ClassTemplateSpecializationDecl>(this)); |
| 863 | TemplateOrInstantiation |
| 864 | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); |
| 865 | } |
| 866 | |
Anders Carlsson | b13e357 | 2009-12-07 06:33:48 +0000 | [diff] [blame] | 867 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ |
| 868 | if (const ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 869 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) |
| 870 | return Spec->getSpecializationKind(); |
| 871 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 872 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 873 | return MSInfo->getTemplateSpecializationKind(); |
| 874 | |
| 875 | return TSK_Undeclared; |
| 876 | } |
| 877 | |
| 878 | void |
| 879 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
| 880 | if (ClassTemplateSpecializationDecl *Spec |
| 881 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
| 882 | Spec->setSpecializationKind(TSK); |
| 883 | return; |
| 884 | } |
| 885 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 886 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 887 | MSInfo->setTemplateSpecializationKind(TSK); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | assert(false && "Not a class template or member class specialization"); |
| 892 | } |
| 893 | |
Douglas Gregor | 1d110e0 | 2010-07-01 14:13:13 +0000 | [diff] [blame] | 894 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { |
| 895 | ASTContext &Context = getASTContext(); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 896 | QualType ClassType = Context.getTypeDeclType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | |
| 898 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 899 | = Context.DeclarationNames.getCXXDestructorName( |
| 900 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 901 | |
John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 902 | DeclContext::lookup_const_iterator I, E; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | llvm::tie(I, E) = lookup(Name); |
Sebastian Redl | d4b25cb | 2010-09-02 23:19:42 +0000 | [diff] [blame] | 904 | if (I == E) |
| 905 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 906 | |
Anders Carlsson | 5ec02ae | 2009-12-02 17:15:43 +0000 | [diff] [blame] | 907 | CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 908 | return Dtor; |
| 909 | } |
| 910 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 911 | void CXXRecordDecl::completeDefinition() { |
| 912 | completeDefinition(0); |
| 913 | } |
| 914 | |
| 915 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { |
| 916 | RecordDecl::completeDefinition(); |
| 917 | |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 918 | // If the class may be abstract (but hasn't been marked as such), check for |
| 919 | // any pure final overriders. |
| 920 | if (mayBeAbstract()) { |
| 921 | CXXFinalOverriderMap MyFinalOverriders; |
| 922 | if (!FinalOverriders) { |
| 923 | getFinalOverriders(MyFinalOverriders); |
| 924 | FinalOverriders = &MyFinalOverriders; |
| 925 | } |
| 926 | |
| 927 | bool Done = false; |
| 928 | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), |
| 929 | MEnd = FinalOverriders->end(); |
| 930 | M != MEnd && !Done; ++M) { |
| 931 | for (OverridingMethods::iterator SO = M->second.begin(), |
| 932 | SOEnd = M->second.end(); |
| 933 | SO != SOEnd && !Done; ++SO) { |
| 934 | assert(SO->second.size() > 0 && |
| 935 | "All virtual functions have overridding virtual functions"); |
| 936 | |
| 937 | // C++ [class.abstract]p4: |
| 938 | // A class is abstract if it contains or inherits at least one |
| 939 | // pure virtual function for which the final overrider is pure |
| 940 | // virtual. |
| 941 | if (SO->second.front().Method->isPure()) { |
| 942 | data().Abstract = true; |
| 943 | Done = true; |
| 944 | break; |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 949 | |
| 950 | // Set access bits correctly on the directly-declared conversions. |
| 951 | for (UnresolvedSetIterator I = data().Conversions.begin(), |
| 952 | E = data().Conversions.end(); |
| 953 | I != E; ++I) |
| 954 | data().Conversions.setAccess(I, (*I)->getAccess()); |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | bool CXXRecordDecl::mayBeAbstract() const { |
| 958 | if (data().Abstract || isInvalidDecl() || !data().Polymorphic || |
| 959 | isDependentContext()) |
| 960 | return false; |
| 961 | |
| 962 | for (CXXRecordDecl::base_class_const_iterator B = bases_begin(), |
| 963 | BEnd = bases_end(); |
| 964 | B != BEnd; ++B) { |
| 965 | CXXRecordDecl *BaseDecl |
| 966 | = cast<CXXRecordDecl>(B->getType()->getAs<RecordType>()->getDecl()); |
| 967 | if (BaseDecl->isAbstract()) |
| 968 | return true; |
| 969 | } |
| 970 | |
| 971 | return false; |
| 972 | } |
| 973 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 974 | CXXMethodDecl * |
| 975 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 976 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 977 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 978 | QualType T, TypeSourceInfo *TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 979 | bool isStatic, StorageClass SCAsWritten, bool isInline, |
| 980 | SourceLocation EndLocation) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 981 | return new (C) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 982 | isStatic, SCAsWritten, isInline, EndLocation); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 985 | bool CXXMethodDecl::isUsualDeallocationFunction() const { |
| 986 | if (getOverloadedOperator() != OO_Delete && |
| 987 | getOverloadedOperator() != OO_Array_Delete) |
| 988 | return false; |
Douglas Gregor | 6d90870 | 2010-02-26 05:06:18 +0000 | [diff] [blame] | 989 | |
| 990 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 991 | // A template instance is never a usual deallocation function, |
| 992 | // regardless of its signature. |
| 993 | if (getPrimaryTemplate()) |
| 994 | return false; |
| 995 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 996 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 997 | // If a class T has a member deallocation function named operator delete |
| 998 | // with exactly one parameter, then that function is a usual (non-placement) |
| 999 | // deallocation function. [...] |
| 1000 | if (getNumParams() == 1) |
| 1001 | return true; |
| 1002 | |
| 1003 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1004 | // [...] If class T does not declare such an operator delete but does |
| 1005 | // declare a member deallocation function named operator delete with |
| 1006 | // exactly two parameters, the second of which has type std::size_t (18.1), |
| 1007 | // then this function is a usual deallocation function. |
| 1008 | ASTContext &Context = getASTContext(); |
| 1009 | if (getNumParams() != 2 || |
Chandler Carruth | e228ba9 | 2010-02-08 18:54:05 +0000 | [diff] [blame] | 1010 | !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), |
| 1011 | Context.getSizeType())) |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1012 | return false; |
| 1013 | |
| 1014 | // This function is a usual deallocation function if there are no |
| 1015 | // single-parameter deallocation functions of the same kind. |
| 1016 | for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName()); |
| 1017 | R.first != R.second; ++R.first) { |
| 1018 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first)) |
| 1019 | if (FD->getNumParams() == 1) |
| 1020 | return false; |
| 1021 | } |
| 1022 | |
| 1023 | return true; |
| 1024 | } |
| 1025 | |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1026 | bool CXXMethodDecl::isCopyAssignmentOperator() const { |
| 1027 | // C++0x [class.copy]p19: |
| 1028 | // A user-declared copy assignment operator X::operator= is a non-static |
| 1029 | // non-template member function of class X with exactly one parameter of |
| 1030 | // type X, X&, const X&, volatile X& or const volatile X&. |
| 1031 | if (/*operator=*/getOverloadedOperator() != OO_Equal || |
| 1032 | /*non-static*/ isStatic() || |
| 1033 | /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() || |
| 1034 | /*exactly one parameter*/getNumParams() != 1) |
| 1035 | return false; |
| 1036 | |
| 1037 | QualType ParamType = getParamDecl(0)->getType(); |
| 1038 | if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) |
| 1039 | ParamType = Ref->getPointeeType(); |
| 1040 | |
| 1041 | ASTContext &Context = getASTContext(); |
| 1042 | QualType ClassType |
| 1043 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
| 1044 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
| 1045 | } |
| 1046 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1047 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 1048 | assert(MD->isCanonicalDecl() && "Method is not canonical!"); |
Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 1049 | assert(!MD->getParent()->isDependentContext() && |
| 1050 | "Can't add an overridden method to a class template!"); |
| 1051 | |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1052 | getASTContext().addOverriddenMethod(this, MD); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1056 | return getASTContext().overridden_methods_begin(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1060 | return getASTContext().overridden_methods_end(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1063 | unsigned CXXMethodDecl::size_overridden_methods() const { |
| 1064 | return getASTContext().overridden_methods_size(this); |
| 1065 | } |
| 1066 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1067 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 1068 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 1069 | // If the member function is declared const, the type of this is const X*, |
| 1070 | // if the member function is declared volatile, the type of this is |
| 1071 | // volatile X*, and if the member function is declared const volatile, |
| 1072 | // the type of this is const volatile X*. |
| 1073 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1074 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 1075 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 1076 | QualType ClassTy = C.getTypeDeclType(getParent()); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1077 | ClassTy = C.getQualifiedType(ClassTy, |
| 1078 | Qualifiers::fromCVRMask(getTypeQualifiers())); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 1079 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1082 | bool CXXMethodDecl::hasInlineBody() const { |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 1083 | // If this function is a template instantiation, look at the template from |
| 1084 | // which it was instantiated. |
| 1085 | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); |
| 1086 | if (!CheckFn) |
| 1087 | CheckFn = this; |
| 1088 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1089 | const FunctionDecl *fn; |
Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1090 | return CheckFn->hasBody(fn) && !fn->isOutOfLine(); |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1093 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1094 | TypeSourceInfo *TInfo, bool IsVirtual, |
| 1095 | SourceLocation L, Expr *Init, |
| 1096 | SourceLocation R, |
| 1097 | SourceLocation EllipsisLoc) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1098 | : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1099 | LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false), |
| 1100 | SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1101 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1104 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1105 | FieldDecl *Member, |
| 1106 | SourceLocation MemberLoc, |
| 1107 | SourceLocation L, Expr *Init, |
| 1108 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1109 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1110 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
| 1111 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1112 | { |
| 1113 | } |
| 1114 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1115 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1116 | IndirectFieldDecl *Member, |
| 1117 | SourceLocation MemberLoc, |
| 1118 | SourceLocation L, Expr *Init, |
| 1119 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1120 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1121 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1122 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1123 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1126 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1127 | SourceLocation D, SourceLocation L, |
| 1128 | CXXConstructorDecl *Target, Expr *Init, |
| 1129 | SourceLocation R) |
| 1130 | : Initializee(Target), MemberOrEllipsisLocation(D), Init(Init), |
| 1131 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
| 1132 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1133 | { |
| 1134 | } |
| 1135 | |
| 1136 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1137 | FieldDecl *Member, |
| 1138 | SourceLocation MemberLoc, |
| 1139 | SourceLocation L, Expr *Init, |
| 1140 | SourceLocation R, |
| 1141 | VarDecl **Indices, |
| 1142 | unsigned NumIndices) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1143 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1144 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1145 | IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1146 | { |
| 1147 | VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1); |
| 1148 | memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *)); |
| 1149 | } |
| 1150 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1151 | CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, |
| 1152 | FieldDecl *Member, |
| 1153 | SourceLocation MemberLoc, |
| 1154 | SourceLocation L, Expr *Init, |
| 1155 | SourceLocation R, |
| 1156 | VarDecl **Indices, |
| 1157 | unsigned NumIndices) { |
| 1158 | void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) + |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1159 | sizeof(VarDecl *) * NumIndices, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1160 | llvm::alignOf<CXXCtorInitializer>()); |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1161 | return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, |
| 1162 | Indices, NumIndices); |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1165 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1166 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1167 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1168 | else |
| 1169 | return TypeLoc(); |
| 1170 | } |
| 1171 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1172 | const Type *CXXCtorInitializer::getBaseClass() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1173 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1174 | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1175 | else |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1179 | SourceLocation CXXCtorInitializer::getSourceLocation() const { |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1180 | if (isAnyMemberInitializer() || isDelegatingInitializer()) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1181 | return getMemberLocation(); |
| 1182 | |
Abramo Bagnara | bd054db | 2010-05-20 10:00:11 +0000 | [diff] [blame] | 1183 | return getBaseClassLoc().getLocalSourceRange().getBegin(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1186 | SourceRange CXXCtorInitializer::getSourceRange() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1187 | return SourceRange(getSourceLocation(), getRParenLoc()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1190 | CXXConstructorDecl * |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1191 | CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1192 | return new (C) CXXConstructorDecl(0, SourceLocation(), DeclarationNameInfo(), |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1193 | QualType(), 0, false, false, false); |
| 1194 | } |
| 1195 | |
| 1196 | CXXConstructorDecl * |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1197 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1198 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1199 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1200 | QualType T, TypeSourceInfo *TInfo, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1201 | bool isExplicit, |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 1202 | bool isInline, |
| 1203 | bool isImplicitlyDeclared) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1204 | assert(NameInfo.getName().getNameKind() |
| 1205 | == DeclarationName::CXXConstructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1206 | "Name must refer to a constructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1207 | return new (C) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo, |
| 1208 | isExplicit, isInline, isImplicitlyDeclared); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1211 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 1212 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1213 | // A default constructor for a class X is a constructor of class |
| 1214 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1215 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 1216 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | bool |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1220 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1221 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1222 | getParamDecl(0)->getType()->isLValueReferenceType(); |
| 1223 | } |
| 1224 | |
| 1225 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { |
| 1226 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1227 | getParamDecl(0)->getType()->isRValueReferenceType(); |
| 1228 | } |
| 1229 | |
| 1230 | /// \brief Determine whether this is a copy or move constructor. |
| 1231 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1232 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1233 | // A non-template constructor for class X is a copy constructor |
| 1234 | // if its first parameter is of type X&, const X&, volatile X& or |
| 1235 | // const volatile X&, and either there are no other parameters |
| 1236 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1237 | // C++0x [class.copy]p3: |
| 1238 | // A non-template constructor for class X is a move constructor if its |
| 1239 | // first parameter is of type X&&, const X&&, volatile X&&, or |
| 1240 | // const volatile X&&, and either there are no other parameters or else |
| 1241 | // all other parameters have default arguments. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1242 | if ((getNumParams() < 1) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1243 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1244 | (getPrimaryTemplate() != 0) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1245 | (getDescribedFunctionTemplate() != 0)) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1246 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1248 | const ParmVarDecl *Param = getParamDecl(0); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1249 | |
| 1250 | // Do we have a reference type? |
| 1251 | const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1252 | if (!ParamRefType) |
| 1253 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1255 | // Is it a reference to our class type? |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1256 | ASTContext &Context = getASTContext(); |
| 1257 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1258 | CanQualType PointeeType |
| 1259 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Douglas Gregor | 14e0b3d | 2009-09-15 20:50:23 +0000 | [diff] [blame] | 1260 | CanQualType ClassTy |
| 1261 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1262 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 1263 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1264 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1265 | // FIXME: other qualifiers? |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1266 | |
| 1267 | // We have a copy or move constructor. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1268 | TypeQuals = PointeeType.getCVRQualifiers(); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1269 | return true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1272 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1273 | // C++ [class.conv.ctor]p1: |
| 1274 | // A constructor declared without the function-specifier explicit |
| 1275 | // that can be called with a single parameter specifies a |
| 1276 | // conversion from the type of its first parameter to the type of |
| 1277 | // its class. Such a constructor is called a converting |
| 1278 | // constructor. |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1279 | if (isExplicit() && !AllowExplicit) |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1280 | return false; |
| 1281 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | return (getNumParams() == 0 && |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1283 | getType()->getAs<FunctionProtoType>()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1284 | (getNumParams() == 1) || |
Anders Carlsson | ae0b4e7 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 1285 | (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1286 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1287 | |
Douglas Gregor | 6493cc5 | 2010-11-08 17:16:59 +0000 | [diff] [blame] | 1288 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1289 | if ((getNumParams() < 1) || |
| 1290 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
| 1291 | (getPrimaryTemplate() == 0) || |
| 1292 | (getDescribedFunctionTemplate() != 0)) |
| 1293 | return false; |
| 1294 | |
| 1295 | const ParmVarDecl *Param = getParamDecl(0); |
| 1296 | |
| 1297 | ASTContext &Context = getASTContext(); |
| 1298 | CanQualType ParamType = Context.getCanonicalType(Param->getType()); |
| 1299 | |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1300 | // Is it the same as our our class type? |
| 1301 | CanQualType ClassTy |
| 1302 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
| 1303 | if (ParamType.getUnqualifiedType() != ClassTy) |
| 1304 | return false; |
| 1305 | |
| 1306 | return true; |
| 1307 | } |
| 1308 | |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1309 | const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { |
| 1310 | // Hack: we store the inherited constructor in the overridden method table |
| 1311 | method_iterator It = begin_overridden_methods(); |
| 1312 | if (It == end_overridden_methods()) |
| 1313 | return 0; |
| 1314 | |
| 1315 | return cast<CXXConstructorDecl>(*It); |
| 1316 | } |
| 1317 | |
| 1318 | void |
| 1319 | CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ |
| 1320 | // Hack: we store the inherited constructor in the overridden method table |
| 1321 | assert(size_overridden_methods() == 0 && "Base ctor already set."); |
| 1322 | addOverriddenMethod(BaseCtor); |
| 1323 | } |
| 1324 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1325 | CXXDestructorDecl * |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1326 | CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1327 | return new (C) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1328 | QualType(), 0, false, false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | CXXDestructorDecl * |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1332 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1333 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1334 | const DeclarationNameInfo &NameInfo, |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1335 | QualType T, TypeSourceInfo *TInfo, |
| 1336 | bool isInline, |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1337 | bool isImplicitlyDeclared) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1338 | assert(NameInfo.getName().getNameKind() |
| 1339 | == DeclarationName::CXXDestructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1340 | "Name must refer to a destructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1341 | return new (C) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, isInline, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1342 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1345 | CXXConversionDecl * |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1346 | CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1347 | return new (C) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1348 | QualType(), 0, false, false, |
| 1349 | SourceLocation()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | CXXConversionDecl * |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1353 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1354 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1355 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1356 | QualType T, TypeSourceInfo *TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1357 | bool isInline, bool isExplicit, |
| 1358 | SourceLocation EndLocation) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1359 | assert(NameInfo.getName().getNameKind() |
| 1360 | == DeclarationName::CXXConversionFunctionName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1361 | "Name must refer to a conversion function"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1362 | return new (C) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1363 | isInline, isExplicit, EndLocation); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 1366 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1368 | SourceLocation ExternLoc, |
| 1369 | SourceLocation LangLoc, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1370 | LanguageIDs Lang, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1371 | SourceLocation RBraceLoc) { |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1372 | return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 1373 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1374 | |
| 1375 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 1376 | SourceLocation L, |
| 1377 | SourceLocation NamespaceLoc, |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1378 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1379 | SourceLocation IdentLoc, |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1380 | NamedDecl *Used, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1381 | DeclContext *CommonAncestor) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1382 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) |
| 1383 | Used = NS->getOriginalNamespace(); |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1384 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, |
| 1385 | IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1388 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { |
| 1389 | if (NamespaceAliasDecl *NA = |
| 1390 | dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) |
| 1391 | return NA->getNamespace(); |
| 1392 | return cast_or_null<NamespaceDecl>(NominatedNamespace); |
| 1393 | } |
| 1394 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 1396 | SourceLocation UsingLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | SourceLocation AliasLoc, |
| 1398 | IdentifierInfo *Alias, |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1399 | NestedNameSpecifierLoc QualifierLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1400 | SourceLocation IdentLoc, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1401 | NamedDecl *Namespace) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1402 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) |
| 1403 | Namespace = NS->getOriginalNamespace(); |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1404 | return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, |
| 1405 | QualifierLoc, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1408 | UsingDecl *UsingShadowDecl::getUsingDecl() const { |
| 1409 | const UsingShadowDecl *Shadow = this; |
| 1410 | while (const UsingShadowDecl *NextShadow = |
| 1411 | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) |
| 1412 | Shadow = NextShadow; |
| 1413 | return cast<UsingDecl>(Shadow->UsingOrNextShadow); |
| 1414 | } |
| 1415 | |
| 1416 | void UsingDecl::addShadowDecl(UsingShadowDecl *S) { |
| 1417 | assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && |
| 1418 | "declaration already in set"); |
| 1419 | assert(S->getUsingDecl() == this); |
| 1420 | |
| 1421 | if (FirstUsingShadow) |
| 1422 | S->UsingOrNextShadow = FirstUsingShadow; |
| 1423 | FirstUsingShadow = S; |
| 1424 | } |
| 1425 | |
| 1426 | void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { |
| 1427 | assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && |
| 1428 | "declaration not in set"); |
| 1429 | assert(S->getUsingDecl() == this); |
| 1430 | |
| 1431 | // Remove S from the shadow decl chain. This is O(n) but hopefully rare. |
| 1432 | |
| 1433 | if (FirstUsingShadow == S) { |
| 1434 | FirstUsingShadow = dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow); |
| 1435 | S->UsingOrNextShadow = this; |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | UsingShadowDecl *Prev = FirstUsingShadow; |
| 1440 | while (Prev->UsingOrNextShadow != S) |
| 1441 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); |
| 1442 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; |
| 1443 | S->UsingOrNextShadow = this; |
| 1444 | } |
| 1445 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1446 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, |
| 1447 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1448 | const DeclarationNameInfo &NameInfo, |
| 1449 | bool IsTypeNameArg) { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1450 | return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1453 | UnresolvedUsingValueDecl * |
| 1454 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, |
| 1455 | SourceLocation UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1456 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1457 | const DeclarationNameInfo &NameInfo) { |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1458 | return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1459 | QualifierLoc, NameInfo); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | UnresolvedUsingTypenameDecl * |
| 1463 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, |
| 1464 | SourceLocation UsingLoc, |
| 1465 | SourceLocation TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1466 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1467 | SourceLocation TargetNameLoc, |
| 1468 | DeclarationName TargetName) { |
| 1469 | return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1470 | QualifierLoc, TargetNameLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1471 | TargetName.getAsIdentifierInfo()); |
Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1474 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1475 | SourceLocation StaticAssertLoc, |
| 1476 | Expr *AssertExpr, |
| 1477 | StringLiteral *Message, |
| 1478 | SourceLocation RParenLoc) { |
| 1479 | return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, |
| 1480 | RParenLoc); |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 1483 | static const char *getAccessName(AccessSpecifier AS) { |
| 1484 | switch (AS) { |
| 1485 | default: |
| 1486 | case AS_none: |
| 1487 | assert("Invalid access specifier!"); |
| 1488 | return 0; |
| 1489 | case AS_public: |
| 1490 | return "public"; |
| 1491 | case AS_private: |
| 1492 | return "private"; |
| 1493 | case AS_protected: |
| 1494 | return "protected"; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 1499 | AccessSpecifier AS) { |
| 1500 | return DB << getAccessName(AS); |
| 1501 | } |