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