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