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