blob: a77c1c8ed526d99a29a729e463ef8d024134929b [file] [log] [blame]
Ted Kremenek4b7c9832008-09-05 17:16:31 +00001//===--- 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 Gregord475b8d2009-03-25 21:17:03 +000015#include "clang/AST/DeclTemplate.h"
Ted Kremenek4b7c9832008-09-05 17:16:31 +000016#include "clang/AST/ASTContext.h"
Anders Carlssonfb311762009-03-14 00:25:26 +000017#include "clang/AST/Expr.h"
Douglas Gregor802ab452009-12-02 22:36:29 +000018#include "clang/AST/TypeLoc.h"
Douglas Gregor7d7e6722008-11-12 23:21:09 +000019#include "clang/Basic/IdentifierTable.h"
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000020#include "llvm/ADT/STLExtras.h"
Fariborz Jahanianfaebcbb2009-09-12 19:52:10 +000021#include "llvm/ADT/SmallPtrSet.h"
Ted Kremenek4b7c9832008-09-05 17:16:31 +000022using namespace clang;
23
24//===----------------------------------------------------------------------===//
25// Decl Allocation/Deallocation Method Implementations
26//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +000027
John McCall86ff3082010-02-04 22:26:26 +000028CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
29 : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
Sebastian Redl64b45f72009-01-05 20:52:13 +000030 UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
Eli Friedman97c134e2009-08-15 22:23:00 +000031 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
32 Abstract(false), HasTrivialConstructor(true),
33 HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true),
Fariborz Jahanian62509212009-09-12 18:26:03 +000034 HasTrivialDestructor(true), ComputedVisibleConversions(false),
35 Bases(0), NumBases(0), VBases(0), NumVBases(0),
John McCalld60e22e2010-03-12 01:19:31 +000036 Definition(D), FirstFriend(0) {
John McCall86ff3082010-02-04 22:26:26 +000037}
38
39CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
40 SourceLocation L, IdentifierInfo *Id,
41 CXXRecordDecl *PrevDecl,
42 SourceLocation TKL)
43 : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL),
44 DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0),
Douglas Gregord475b8d2009-03-25 21:17:03 +000045 TemplateOrInstantiation() { }
Douglas Gregor7d7e6722008-11-12 23:21:09 +000046
Ted Kremenek4b7c9832008-09-05 17:16:31 +000047CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
48 SourceLocation L, IdentifierInfo *Id,
Douglas Gregor741dd9a2009-07-21 14:46:17 +000049 SourceLocation TKL,
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000050 CXXRecordDecl* PrevDecl,
51 bool DelayTypeCreation) {
Mike Stump1eb44332009-09-09 15:08:12 +000052 CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000053 PrevDecl, TKL);
Mike Stump1eb44332009-09-09 15:08:12 +000054
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000055 // FIXME: DelayTypeCreation seems like such a hack
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000056 if (!DelayTypeCreation)
Mike Stump1eb44332009-09-09 15:08:12 +000057 C.getTypeDeclType(R, PrevDecl);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000058 return R;
59}
60
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +000061CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, EmptyShell Empty) {
62 return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), 0, 0,
63 SourceLocation());
64}
65
Douglas Gregorf8268ae2008-10-22 17:49:05 +000066CXXRecordDecl::~CXXRecordDecl() {
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000067}
68
69void CXXRecordDecl::Destroy(ASTContext &C) {
John McCall86ff3082010-02-04 22:26:26 +000070 if (data().Definition == this) {
71 C.Deallocate(data().Bases);
72 C.Deallocate(data().VBases);
73 C.Deallocate(&data());
74 }
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000075 this->RecordDecl::Destroy(C);
Douglas Gregorf8268ae2008-10-22 17:49:05 +000076}
77
Mike Stump1eb44332009-09-09 15:08:12 +000078void
Douglas Gregor2d5b7032010-02-11 01:30:34 +000079CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
Douglas Gregor57c856b2008-10-23 18:13:27 +000080 unsigned NumBases) {
Douglas Gregor2d5b7032010-02-11 01:30:34 +000081 ASTContext &C = getASTContext();
82
Mike Stump1eb44332009-09-09 15:08:12 +000083 // C++ [dcl.init.aggr]p1:
Douglas Gregor64bffa92008-11-05 16:20:31 +000084 // An aggregate is an array or a class (clause 9) with [...]
85 // no base classes [...].
John McCall86ff3082010-02-04 22:26:26 +000086 data().Aggregate = false;
Douglas Gregor64bffa92008-11-05 16:20:31 +000087
John McCall86ff3082010-02-04 22:26:26 +000088 if (data().Bases)
89 C.Deallocate(data().Bases);
Mike Stump1eb44332009-09-09 15:08:12 +000090
Anders Carlsson6f6de732010-03-29 05:13:12 +000091 // The set of seen virtual base types.
Anders Carlsson1c363932010-03-29 19:49:09 +000092 llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
Anders Carlsson6f6de732010-03-29 05:13:12 +000093
94 // The virtual bases of this class.
95 llvm::SmallVector<const CXXBaseSpecifier *, 8> VBases;
Mike Stump1eb44332009-09-09 15:08:12 +000096
John McCall86ff3082010-02-04 22:26:26 +000097 data().Bases = new(C) CXXBaseSpecifier [NumBases];
98 data().NumBases = NumBases;
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000099 for (unsigned i = 0; i < NumBases; ++i) {
John McCall86ff3082010-02-04 22:26:26 +0000100 data().Bases[i] = *Bases[i];
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000101 // Keep track of inherited vbases for this base class.
102 const CXXBaseSpecifier *Base = Bases[i];
103 QualType BaseType = Base->getType();
Douglas Gregor5fe8c042010-02-27 00:25:28 +0000104 // Skip dependent types; we can't do any checking on them now.
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000105 if (BaseType->isDependentType())
106 continue;
107 CXXRecordDecl *BaseClassDecl
Ted Kremenek6217b802009-07-29 21:53:49 +0000108 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
Anders Carlsson6f6de732010-03-29 05:13:12 +0000109
110 // Now go through all virtual bases of this base and add them.
Mike Stump1eb44332009-09-09 15:08:12 +0000111 for (CXXRecordDecl::base_class_iterator VBase =
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000112 BaseClassDecl->vbases_begin(),
113 E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) {
Anders Carlsson6f6de732010-03-29 05:13:12 +0000114 // Add this base if it's not already in the list.
Anders Carlsson1c363932010-03-29 19:49:09 +0000115 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType())))
Anders Carlsson6f6de732010-03-29 05:13:12 +0000116 VBases.push_back(VBase);
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000117 }
Anders Carlsson6f6de732010-03-29 05:13:12 +0000118
119 if (Base->isVirtual()) {
120 // Add this base if it's not already in the list.
Anders Carlsson1c363932010-03-29 19:49:09 +0000121 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)))
Anders Carlsson6f6de732010-03-29 05:13:12 +0000122 VBases.push_back(Base);
123 }
124
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000125 }
Anders Carlsson6f6de732010-03-29 05:13:12 +0000126
127 if (VBases.empty())
128 return;
129
130 // Create base specifier for any direct or indirect virtual bases.
131 data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
132 data().NumVBases = VBases.size();
133 for (int I = 0, E = VBases.size(); I != E; ++I) {
134 QualType VBaseType = VBases[I]->getType();
135
136 // Skip dependent types; we can't do any checking on them now.
137 if (VBaseType->isDependentType())
138 continue;
139
140 CXXRecordDecl *VBaseClassDecl
141 = cast<CXXRecordDecl>(VBaseType->getAs<RecordType>()->getDecl());
142
143 data().VBases[I] =
144 CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000145 VBaseClassDecl->getTagKind() == TTK_Class,
Anders Carlsson6f6de732010-03-29 05:13:12 +0000146 VBases[I]->getAccessSpecifier(), VBaseType);
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000147 }
Douglas Gregor57c856b2008-10-23 18:13:27 +0000148}
149
Douglas Gregor9edad9b2010-01-14 17:47:39 +0000150/// Callback function for CXXRecordDecl::forallBases that acknowledges
151/// that it saw a base class.
152static bool SawBase(const CXXRecordDecl *, void *) {
153 return true;
154}
155
156bool CXXRecordDecl::hasAnyDependentBases() const {
157 if (!isDependentContext())
158 return false;
159
160 return !forallBases(SawBase, 0);
161}
162
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000163bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const {
John McCall0953e762009-09-24 19:53:00 +0000164 return getCopyConstructor(Context, Qualifiers::Const) != 0;
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000165}
166
Douglas Gregor0d405db2010-07-01 20:59:04 +0000167/// \brief Perform a simplistic form of overload resolution that only considers
168/// cv-qualifiers on a single parameter, and return the best overload candidate
169/// (if there is one).
170static CXXMethodDecl *
171GetBestOverloadCandidateSimple(
172 const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) {
173 if (Cands.empty())
174 return 0;
175 if (Cands.size() == 1)
176 return Cands[0].first;
177
178 unsigned Best = 0, N = Cands.size();
179 for (unsigned I = 1; I != N; ++I)
180 if (Cands[Best].second.isSupersetOf(Cands[I].second))
181 Best = I;
182
183 for (unsigned I = 1; I != N; ++I)
184 if (Cands[Best].second.isSupersetOf(Cands[I].second))
185 return 0;
186
187 return Cands[Best].first;
188}
189
Mike Stump1eb44332009-09-09 15:08:12 +0000190CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000191 unsigned TypeQuals) const{
Sebastian Redl64b45f72009-01-05 20:52:13 +0000192 QualType ClassType
193 = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this));
Mike Stump1eb44332009-09-09 15:08:12 +0000194 DeclarationName ConstructorName
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000195 = Context.DeclarationNames.getCXXConstructorName(
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000196 Context.getCanonicalType(ClassType));
197 unsigned FoundTQs;
Douglas Gregor0d405db2010-07-01 20:59:04 +0000198 llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found;
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000199 DeclContext::lookup_const_iterator Con, ConEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000200 for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName);
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000201 Con != ConEnd; ++Con) {
Douglas Gregord93bacf2009-09-04 14:46:39 +0000202 // C++ [class.copy]p2:
203 // A non-template constructor for class X is a copy constructor if [...]
204 if (isa<FunctionTemplateDecl>(*Con))
205 continue;
206
Douglas Gregor0d405db2010-07-01 20:59:04 +0000207 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
208 if (Constructor->isCopyConstructor(FoundTQs)) {
John McCall0953e762009-09-24 19:53:00 +0000209 if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) ||
210 (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const)))
Douglas Gregor0d405db2010-07-01 20:59:04 +0000211 Found.push_back(std::make_pair(
212 const_cast<CXXConstructorDecl *>(Constructor),
213 Qualifiers::fromCVRMask(FoundTQs)));
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000214 }
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000215 }
Douglas Gregor0d405db2010-07-01 20:59:04 +0000216
217 return cast_or_null<CXXConstructorDecl>(
218 GetBestOverloadCandidateSimple(Found));
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000219}
220
Fariborz Jahanian0270b8a2009-08-12 23:34:46 +0000221bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context,
222 const CXXMethodDecl *& MD) const {
Sebastian Redl64b45f72009-01-05 20:52:13 +0000223 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
224 const_cast<CXXRecordDecl*>(this)));
225 DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal);
226
227 DeclContext::lookup_const_iterator Op, OpEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000228 for (llvm::tie(Op, OpEnd) = this->lookup(OpName);
Sebastian Redl64b45f72009-01-05 20:52:13 +0000229 Op != OpEnd; ++Op) {
230 // C++ [class.copy]p9:
231 // A user-declared copy assignment operator is a non-static non-template
232 // member function of class X with exactly one parameter of type X, X&,
233 // const X&, volatile X& or const volatile X&.
Douglas Gregor682054c2009-10-30 22:48:49 +0000234 const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op);
235 if (!Method)
236 continue;
237
Sebastian Redl64b45f72009-01-05 20:52:13 +0000238 if (Method->isStatic())
239 continue;
Douglas Gregor77da3f42009-10-13 23:45:19 +0000240 if (Method->getPrimaryTemplate())
241 continue;
Douglas Gregor72564e72009-02-26 23:50:07 +0000242 const FunctionProtoType *FnType =
John McCall183700f2009-09-21 23:43:11 +0000243 Method->getType()->getAs<FunctionProtoType>();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000244 assert(FnType && "Overloaded operator has no prototype.");
245 // Don't assert on this; an invalid decl might have been left in the AST.
246 if (FnType->getNumArgs() != 1 || FnType->isVariadic())
247 continue;
248 bool AcceptsConst = true;
249 QualType ArgType = FnType->getArgType(0);
Ted Kremenek6217b802009-07-29 21:53:49 +0000250 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) {
Sebastian Redl64b45f72009-01-05 20:52:13 +0000251 ArgType = Ref->getPointeeType();
Douglas Gregor2ff44782009-03-20 20:21:37 +0000252 // Is it a non-const lvalue reference?
Sebastian Redl64b45f72009-01-05 20:52:13 +0000253 if (!ArgType.isConstQualified())
254 AcceptsConst = false;
255 }
Douglas Gregora4923eb2009-11-16 21:35:15 +0000256 if (!Context.hasSameUnqualifiedType(ArgType, ClassType))
Sebastian Redl64b45f72009-01-05 20:52:13 +0000257 continue;
Fariborz Jahanian0270b8a2009-08-12 23:34:46 +0000258 MD = Method;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000259 // We have a single argument of type cv X or cv X&, i.e. we've found the
260 // copy assignment operator. Return whether it accepts const arguments.
261 return AcceptsConst;
262 }
263 assert(isInvalidDecl() &&
264 "No copy assignment operator declared in valid code.");
265 return false;
266}
267
Douglas Gregorb87786f2010-07-01 17:48:08 +0000268CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const {
269 ASTContext &Context = getASTContext();
270 QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this));
271 DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal);
272
273 llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found;
274 DeclContext::lookup_const_iterator Op, OpEnd;
275 for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) {
276 // C++ [class.copy]p9:
277 // A user-declared copy assignment operator is a non-static non-template
278 // member function of class X with exactly one parameter of type X, X&,
279 // const X&, volatile X& or const volatile X&.
280 const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op);
281 if (!Method || Method->isStatic() || Method->getPrimaryTemplate())
282 continue;
283
284 const FunctionProtoType *FnType
285 = Method->getType()->getAs<FunctionProtoType>();
286 assert(FnType && "Overloaded operator has no prototype.");
287 // Don't assert on this; an invalid decl might have been left in the AST.
288 if (FnType->getNumArgs() != 1 || FnType->isVariadic())
289 continue;
290
291 QualType ArgType = FnType->getArgType(0);
292 Qualifiers Quals;
293 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) {
294 ArgType = Ref->getPointeeType();
295 // If we have a const argument and we have a reference to a non-const,
296 // this function does not match.
297 if (ArgIsConst && !ArgType.isConstQualified())
298 continue;
299
300 Quals = ArgType.getQualifiers();
301 } else {
302 // By-value copy-assignment operators are treated like const X&
303 // copy-assignment operators.
304 Quals = Qualifiers::fromCVRMask(Qualifiers::Const);
305 }
306
307 if (!Context.hasSameUnqualifiedType(ArgType, Class))
308 continue;
309
310 // Save this copy-assignment operator. It might be "the one".
311 Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals));
312 }
313
314 // Use a simplistic form of overload resolution to find the candidate.
315 return GetBestOverloadCandidateSimple(Found);
316}
317
Sebastian Redl64b45f72009-01-05 20:52:13 +0000318void
Mike Stump1eb44332009-09-09 15:08:12 +0000319CXXRecordDecl::addedConstructor(ASTContext &Context,
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000320 CXXConstructorDecl *ConDecl) {
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000321 assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl");
322 // Note that we have a user-declared constructor.
John McCall86ff3082010-02-04 22:26:26 +0000323 data().UserDeclaredConstructor = true;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000324
Mike Stump1eb44332009-09-09 15:08:12 +0000325 // C++ [dcl.init.aggr]p1:
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000326 // An aggregate is an array or a class (clause 9) with no
327 // user-declared constructors (12.1) [...].
John McCall86ff3082010-02-04 22:26:26 +0000328 data().Aggregate = false;
Douglas Gregor64bffa92008-11-05 16:20:31 +0000329
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000330 // C++ [class]p4:
331 // A POD-struct is an aggregate class [...]
John McCall86ff3082010-02-04 22:26:26 +0000332 data().PlainOldData = false;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000333
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000334 // C++ [class.ctor]p5:
335 // A constructor is trivial if it is an implicitly-declared default
336 // constructor.
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000337 // FIXME: C++0x: don't do this for "= default" default constructors.
John McCall86ff3082010-02-04 22:26:26 +0000338 data().HasTrivialConstructor = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000339
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000340 // Note when we have a user-declared copy constructor, which will
341 // suppress the implicit declaration of a copy constructor.
Douglas Gregor9e9199d2009-12-22 00:34:07 +0000342 if (ConDecl->isCopyConstructor()) {
John McCall86ff3082010-02-04 22:26:26 +0000343 data().UserDeclaredCopyConstructor = true;
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000344
345 // C++ [class.copy]p6:
346 // A copy constructor is trivial if it is implicitly declared.
347 // FIXME: C++0x: don't do this for "= default" copy constructors.
John McCall86ff3082010-02-04 22:26:26 +0000348 data().HasTrivialCopyConstructor = false;
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000349 }
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000350}
351
Sebastian Redl64b45f72009-01-05 20:52:13 +0000352void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context,
353 CXXMethodDecl *OpDecl) {
354 // We're interested specifically in copy assignment operators.
John McCall183700f2009-09-21 23:43:11 +0000355 const FunctionProtoType *FnType = OpDecl->getType()->getAs<FunctionProtoType>();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000356 assert(FnType && "Overloaded operator has no proto function type.");
357 assert(FnType->getNumArgs() == 1 && !FnType->isVariadic());
Douglas Gregor77da3f42009-10-13 23:45:19 +0000358
359 // Copy assignment operators must be non-templates.
360 if (OpDecl->getPrimaryTemplate() || OpDecl->getDescribedFunctionTemplate())
361 return;
362
Sebastian Redl64b45f72009-01-05 20:52:13 +0000363 QualType ArgType = FnType->getArgType(0);
Ted Kremenek6217b802009-07-29 21:53:49 +0000364 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>())
Sebastian Redl64b45f72009-01-05 20:52:13 +0000365 ArgType = Ref->getPointeeType();
366
367 ArgType = ArgType.getUnqualifiedType();
368 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
369 const_cast<CXXRecordDecl*>(this)));
370
Douglas Gregora4923eb2009-11-16 21:35:15 +0000371 if (!Context.hasSameUnqualifiedType(ClassType, ArgType))
Sebastian Redl64b45f72009-01-05 20:52:13 +0000372 return;
373
374 // This is a copy assignment operator.
Eli Friedman88fad632009-11-07 00:02:45 +0000375 // Note on the decl that it is a copy assignment operator.
376 OpDecl->setCopyAssignment(true);
377
Sebastian Redl64b45f72009-01-05 20:52:13 +0000378 // Suppress the implicit declaration of a copy constructor.
John McCall86ff3082010-02-04 22:26:26 +0000379 data().UserDeclaredCopyAssignment = true;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000380
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000381 // C++ [class.copy]p11:
382 // A copy assignment operator is trivial if it is implicitly declared.
383 // FIXME: C++0x: don't do this for "= default" copy operators.
John McCall86ff3082010-02-04 22:26:26 +0000384 data().HasTrivialCopyAssignment = false;
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000385
Sebastian Redl64b45f72009-01-05 20:52:13 +0000386 // C++ [class]p4:
387 // A POD-struct is an aggregate class that [...] has no user-defined copy
388 // assignment operator [...].
John McCall86ff3082010-02-04 22:26:26 +0000389 data().PlainOldData = false;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000390}
391
John McCallb05b5f32010-03-15 09:07:48 +0000392static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
393 QualType T;
John McCall32daa422010-03-31 01:36:47 +0000394 if (isa<UsingShadowDecl>(Conv))
395 Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl();
John McCallb05b5f32010-03-15 09:07:48 +0000396 if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv))
397 T = ConvTemp->getTemplatedDecl()->getResultType();
398 else
399 T = cast<CXXConversionDecl>(Conv)->getConversionType();
400 return Context.getCanonicalType(T);
Fariborz Jahanian0351a1e2009-10-07 20:43:36 +0000401}
402
John McCallb05b5f32010-03-15 09:07:48 +0000403/// Collect the visible conversions of a base class.
404///
405/// \param Base a base class of the class we're considering
406/// \param InVirtual whether this base class is a virtual base (or a base
407/// of a virtual base)
408/// \param Access the access along the inheritance path to this base
409/// \param ParentHiddenTypes the conversions provided by the inheritors
410/// of this base
411/// \param Output the set to which to add conversions from non-virtual bases
412/// \param VOutput the set to which to add conversions from virtual bases
413/// \param HiddenVBaseCs the set of conversions which were hidden in a
414/// virtual base along some inheritance path
415static void CollectVisibleConversions(ASTContext &Context,
416 CXXRecordDecl *Record,
417 bool InVirtual,
418 AccessSpecifier Access,
419 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
420 UnresolvedSetImpl &Output,
421 UnresolvedSetImpl &VOutput,
422 llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
423 // The set of types which have conversions in this class or its
424 // subclasses. As an optimization, we don't copy the derived set
425 // unless it might change.
426 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
427 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
428
429 // Collect the direct conversions and figure out which conversions
430 // will be hidden in the subclasses.
431 UnresolvedSetImpl &Cs = *Record->getConversionFunctions();
432 if (!Cs.empty()) {
433 HiddenTypesBuffer = ParentHiddenTypes;
434 HiddenTypes = &HiddenTypesBuffer;
435
436 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) {
437 bool Hidden =
438 !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl()));
439
440 // If this conversion is hidden and we're in a virtual base,
441 // remember that it's hidden along some inheritance path.
442 if (Hidden && InVirtual)
443 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
444
445 // If this conversion isn't hidden, add it to the appropriate output.
446 else if (!Hidden) {
447 AccessSpecifier IAccess
448 = CXXRecordDecl::MergeAccess(Access, I.getAccess());
449
450 if (InVirtual)
451 VOutput.addDecl(I.getDecl(), IAccess);
Fariborz Jahanian62509212009-09-12 18:26:03 +0000452 else
John McCallb05b5f32010-03-15 09:07:48 +0000453 Output.addDecl(I.getDecl(), IAccess);
Fariborz Jahanian53462782009-09-11 21:44:33 +0000454 }
455 }
456 }
Sebastian Redl9994a342009-10-25 17:03:50 +0000457
John McCallb05b5f32010-03-15 09:07:48 +0000458 // Collect information recursively from any base classes.
459 for (CXXRecordDecl::base_class_iterator
460 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) {
461 const RecordType *RT = I->getType()->getAs<RecordType>();
462 if (!RT) continue;
Sebastian Redl9994a342009-10-25 17:03:50 +0000463
John McCallb05b5f32010-03-15 09:07:48 +0000464 AccessSpecifier BaseAccess
465 = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier());
466 bool BaseInVirtual = InVirtual || I->isVirtual();
Sebastian Redl9994a342009-10-25 17:03:50 +0000467
John McCallb05b5f32010-03-15 09:07:48 +0000468 CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
469 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
470 *HiddenTypes, Output, VOutput, HiddenVBaseCs);
Fariborz Jahanian53462782009-09-11 21:44:33 +0000471 }
John McCallb05b5f32010-03-15 09:07:48 +0000472}
Sebastian Redl9994a342009-10-25 17:03:50 +0000473
John McCallb05b5f32010-03-15 09:07:48 +0000474/// Collect the visible conversions of a class.
475///
476/// This would be extremely straightforward if it weren't for virtual
477/// bases. It might be worth special-casing that, really.
478static void CollectVisibleConversions(ASTContext &Context,
479 CXXRecordDecl *Record,
480 UnresolvedSetImpl &Output) {
481 // The collection of all conversions in virtual bases that we've
482 // found. These will be added to the output as long as they don't
483 // appear in the hidden-conversions set.
484 UnresolvedSet<8> VBaseCs;
485
486 // The set of conversions in virtual bases that we've determined to
487 // be hidden.
488 llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs;
489
490 // The set of types hidden by classes derived from this one.
491 llvm::SmallPtrSet<CanQualType, 8> HiddenTypes;
492
493 // Go ahead and collect the direct conversions and add them to the
494 // hidden-types set.
495 UnresolvedSetImpl &Cs = *Record->getConversionFunctions();
496 Output.append(Cs.begin(), Cs.end());
497 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I)
498 HiddenTypes.insert(GetConversionType(Context, I.getDecl()));
499
500 // Recursively collect conversions from base classes.
501 for (CXXRecordDecl::base_class_iterator
502 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) {
503 const RecordType *RT = I->getType()->getAs<RecordType>();
504 if (!RT) continue;
505
506 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
507 I->isVirtual(), I->getAccessSpecifier(),
508 HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
509 }
510
511 // Add any unhidden conversions provided by virtual bases.
512 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
513 I != E; ++I) {
514 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
515 Output.addDecl(I.getDecl(), I.getAccess());
Fariborz Jahanian53462782009-09-11 21:44:33 +0000516 }
Fariborz Jahanian62509212009-09-12 18:26:03 +0000517}
518
519/// getVisibleConversionFunctions - get all conversion functions visible
520/// in current class; including conversion function templates.
John McCalleec51cf2010-01-20 00:46:10 +0000521const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() {
Fariborz Jahanian62509212009-09-12 18:26:03 +0000522 // If root class, all conversions are visible.
523 if (bases_begin() == bases_end())
John McCall86ff3082010-02-04 22:26:26 +0000524 return &data().Conversions;
Fariborz Jahanian62509212009-09-12 18:26:03 +0000525 // If visible conversion list is already evaluated, return it.
John McCall86ff3082010-02-04 22:26:26 +0000526 if (data().ComputedVisibleConversions)
527 return &data().VisibleConversions;
John McCallb05b5f32010-03-15 09:07:48 +0000528 CollectVisibleConversions(getASTContext(), this, data().VisibleConversions);
John McCall86ff3082010-02-04 22:26:26 +0000529 data().ComputedVisibleConversions = true;
530 return &data().VisibleConversions;
Fariborz Jahanian53462782009-09-11 21:44:33 +0000531}
532
John McCall32daa422010-03-31 01:36:47 +0000533#ifndef NDEBUG
534void CXXRecordDecl::CheckConversionFunction(NamedDecl *ConvDecl) {
John McCallb05b5f32010-03-15 09:07:48 +0000535 assert(ConvDecl->getDeclContext() == this &&
536 "conversion function does not belong to this record");
537
John McCall32daa422010-03-31 01:36:47 +0000538 ConvDecl = ConvDecl->getUnderlyingDecl();
539 if (FunctionTemplateDecl *Temp = dyn_cast<FunctionTemplateDecl>(ConvDecl)) {
540 assert(isa<CXXConversionDecl>(Temp->getTemplatedDecl()));
541 } else {
542 assert(isa<CXXConversionDecl>(ConvDecl));
543 }
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000544}
John McCall32daa422010-03-31 01:36:47 +0000545#endif
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000546
John McCall32daa422010-03-31 01:36:47 +0000547void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) {
548 // This operation is O(N) but extremely rare. Sema only uses it to
549 // remove UsingShadowDecls in a class that were followed by a direct
550 // declaration, e.g.:
551 // class A : B {
552 // using B::operator int;
553 // operator int();
554 // };
555 // This is uncommon by itself and even more uncommon in conjunction
556 // with sufficiently large numbers of directly-declared conversions
557 // that asymptotic behavior matters.
558
559 UnresolvedSetImpl &Convs = *getConversionFunctions();
560 for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
561 if (Convs[I].getDecl() == ConvDecl) {
562 Convs.erase(I);
563 assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end()
564 && "conversion was found multiple times in unresolved set");
565 return;
566 }
567 }
568
569 llvm_unreachable("conversion not found in set!");
Douglas Gregor65ec1fd2009-08-21 23:19:43 +0000570}
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000571
Fariborz Jahaniane7184df2009-12-03 18:44:40 +0000572void CXXRecordDecl::setMethodAsVirtual(FunctionDecl *Method) {
573 Method->setVirtualAsWritten(true);
574 setAggregate(false);
575 setPOD(false);
576 setEmpty(false);
577 setPolymorphic(true);
578 setHasTrivialConstructor(false);
579 setHasTrivialCopyConstructor(false);
580 setHasTrivialCopyAssignment(false);
581}
582
Douglas Gregorf6b11852009-10-08 15:14:33 +0000583CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000584 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
Douglas Gregorf6b11852009-10-08 15:14:33 +0000585 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
586
587 return 0;
588}
589
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000590MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const {
591 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
592}
593
Douglas Gregorf6b11852009-10-08 15:14:33 +0000594void
595CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
596 TemplateSpecializationKind TSK) {
597 assert(TemplateOrInstantiation.isNull() &&
598 "Previous template or instantiation?");
599 assert(!isa<ClassTemplateSpecializationDecl>(this));
600 TemplateOrInstantiation
601 = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
602}
603
Anders Carlssonb13e3572009-12-07 06:33:48 +0000604TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{
605 if (const ClassTemplateSpecializationDecl *Spec
Douglas Gregorf6b11852009-10-08 15:14:33 +0000606 = dyn_cast<ClassTemplateSpecializationDecl>(this))
607 return Spec->getSpecializationKind();
608
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000609 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
Douglas Gregorf6b11852009-10-08 15:14:33 +0000610 return MSInfo->getTemplateSpecializationKind();
611
612 return TSK_Undeclared;
613}
614
615void
616CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
617 if (ClassTemplateSpecializationDecl *Spec
618 = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
619 Spec->setSpecializationKind(TSK);
620 return;
621 }
622
Douglas Gregorb3ae4fc2009-10-12 20:18:28 +0000623 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
Douglas Gregorf6b11852009-10-08 15:14:33 +0000624 MSInfo->setTemplateSpecializationKind(TSK);
625 return;
626 }
627
628 assert(false && "Not a class template or member class specialization");
629}
630
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000631CXXConstructorDecl *
Douglas Gregoreb8c6702010-07-01 22:31:05 +0000632CXXRecordDecl::getDefaultConstructor() {
633 ASTContext &Context = getASTContext();
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000634 QualType ClassType = Context.getTypeDeclType(this);
635 DeclarationName ConstructorName
636 = Context.DeclarationNames.getCXXConstructorName(
637 Context.getCanonicalType(ClassType.getUnqualifiedType()));
Mike Stump1eb44332009-09-09 15:08:12 +0000638
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000639 DeclContext::lookup_const_iterator Con, ConEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000640 for (llvm::tie(Con, ConEnd) = lookup(ConstructorName);
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000641 Con != ConEnd; ++Con) {
Douglas Gregord93bacf2009-09-04 14:46:39 +0000642 // FIXME: In C++0x, a constructor template can be a default constructor.
643 if (isa<FunctionTemplateDecl>(*Con))
644 continue;
645
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000646 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
647 if (Constructor->isDefaultConstructor())
648 return Constructor;
649 }
650 return 0;
651}
652
Douglas Gregor1d110e02010-07-01 14:13:13 +0000653CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
654 ASTContext &Context = getASTContext();
Anders Carlsson7267c162009-05-29 21:03:38 +0000655 QualType ClassType = Context.getTypeDeclType(this);
Mike Stump1eb44332009-09-09 15:08:12 +0000656
657 DeclarationName Name
Douglas Gregor50d62d12009-08-05 05:36:45 +0000658 = Context.DeclarationNames.getCXXDestructorName(
659 Context.getCanonicalType(ClassType));
Anders Carlsson7267c162009-05-29 21:03:38 +0000660
John McCallc0bf4622010-02-23 00:48:20 +0000661 DeclContext::lookup_const_iterator I, E;
Mike Stump1eb44332009-09-09 15:08:12 +0000662 llvm::tie(I, E) = lookup(Name);
Anders Carlsson7267c162009-05-29 21:03:38 +0000663 assert(I != E && "Did not find a destructor!");
Mike Stump1eb44332009-09-09 15:08:12 +0000664
Anders Carlsson5ec02ae2009-12-02 17:15:43 +0000665 CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I);
Anders Carlsson7267c162009-05-29 21:03:38 +0000666 assert(++I == E && "Found more than one destructor!");
Mike Stump1eb44332009-09-09 15:08:12 +0000667
Anders Carlsson7267c162009-05-29 21:03:38 +0000668 return Dtor;
669}
670
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000671CXXMethodDecl *
672CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor10bd3682008-11-17 22:58:34 +0000673 SourceLocation L, DeclarationName N,
John McCalla93c9342009-12-07 02:54:59 +0000674 QualType T, TypeSourceInfo *TInfo,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000675 bool isStatic, StorageClass SCAsWritten, bool isInline) {
John McCalla93c9342009-12-07 02:54:59 +0000676 return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, TInfo,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000677 isStatic, SCAsWritten, isInline);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000678}
679
Douglas Gregor90916562009-09-29 18:16:17 +0000680bool CXXMethodDecl::isUsualDeallocationFunction() const {
681 if (getOverloadedOperator() != OO_Delete &&
682 getOverloadedOperator() != OO_Array_Delete)
683 return false;
Douglas Gregor6d908702010-02-26 05:06:18 +0000684
685 // C++ [basic.stc.dynamic.deallocation]p2:
686 // A template instance is never a usual deallocation function,
687 // regardless of its signature.
688 if (getPrimaryTemplate())
689 return false;
690
Douglas Gregor90916562009-09-29 18:16:17 +0000691 // C++ [basic.stc.dynamic.deallocation]p2:
692 // If a class T has a member deallocation function named operator delete
693 // with exactly one parameter, then that function is a usual (non-placement)
694 // deallocation function. [...]
695 if (getNumParams() == 1)
696 return true;
697
698 // C++ [basic.stc.dynamic.deallocation]p2:
699 // [...] If class T does not declare such an operator delete but does
700 // declare a member deallocation function named operator delete with
701 // exactly two parameters, the second of which has type std::size_t (18.1),
702 // then this function is a usual deallocation function.
703 ASTContext &Context = getASTContext();
704 if (getNumParams() != 2 ||
Chandler Carruthe228ba92010-02-08 18:54:05 +0000705 !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(),
706 Context.getSizeType()))
Douglas Gregor90916562009-09-29 18:16:17 +0000707 return false;
708
709 // This function is a usual deallocation function if there are no
710 // single-parameter deallocation functions of the same kind.
711 for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName());
712 R.first != R.second; ++R.first) {
713 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first))
714 if (FD->getNumParams() == 1)
715 return false;
716 }
717
718 return true;
719}
720
Douglas Gregor06a9f362010-05-01 20:49:11 +0000721bool CXXMethodDecl::isCopyAssignmentOperator() const {
722 // C++0x [class.copy]p19:
723 // A user-declared copy assignment operator X::operator= is a non-static
724 // non-template member function of class X with exactly one parameter of
725 // type X, X&, const X&, volatile X& or const volatile X&.
726 if (/*operator=*/getOverloadedOperator() != OO_Equal ||
727 /*non-static*/ isStatic() ||
728 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() ||
729 /*exactly one parameter*/getNumParams() != 1)
730 return false;
731
732 QualType ParamType = getParamDecl(0)->getType();
733 if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>())
734 ParamType = Ref->getPointeeType();
735
736 ASTContext &Context = getASTContext();
737 QualType ClassType
738 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
739 return Context.hasSameUnqualifiedType(ClassType, ParamType);
740}
741
Anders Carlsson05eb2442009-05-16 23:58:37 +0000742void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
Anders Carlsson3aaf4862009-12-04 05:51:56 +0000743 assert(MD->isCanonicalDecl() && "Method is not canonical!");
Anders Carlssonc076c452010-01-30 17:42:34 +0000744 assert(!MD->getParent()->isDependentContext() &&
745 "Can't add an overridden method to a class template!");
746
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000747 getASTContext().addOverriddenMethod(this, MD);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000748}
749
750CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000751 return getASTContext().overridden_methods_begin(this);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000752}
753
754CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
Douglas Gregor7d10b7e2010-03-02 23:58:15 +0000755 return getASTContext().overridden_methods_end(this);
Anders Carlsson05eb2442009-05-16 23:58:37 +0000756}
757
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000758QualType CXXMethodDecl::getThisType(ASTContext &C) const {
Argyrios Kyrtzidisb0d178d2008-10-24 22:28:18 +0000759 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
760 // If the member function is declared const, the type of this is const X*,
761 // if the member function is declared volatile, the type of this is
762 // volatile X*, and if the member function is declared const volatile,
763 // the type of this is const volatile X*.
764
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000765 assert(isInstance() && "No 'this' for static methods!");
Anders Carlsson31a08752009-06-13 02:59:33 +0000766
John McCall3cb0ebd2010-03-10 03:28:59 +0000767 QualType ClassTy = C.getTypeDeclType(getParent());
John McCall0953e762009-09-24 19:53:00 +0000768 ClassTy = C.getQualifiedType(ClassTy,
769 Qualifiers::fromCVRMask(getTypeQualifiers()));
Anders Carlsson4e579922009-07-10 21:35:09 +0000770 return C.getPointerType(ClassTy);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000771}
772
Eli Friedmand7d7f672009-12-06 20:50:05 +0000773bool CXXMethodDecl::hasInlineBody() const {
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000774 // If this function is a template instantiation, look at the template from
775 // which it was instantiated.
776 const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
777 if (!CheckFn)
778 CheckFn = this;
779
Eli Friedmand7d7f672009-12-06 20:50:05 +0000780 const FunctionDecl *fn;
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000781 return CheckFn->getBody(fn) && !fn->isOutOfLine();
Eli Friedmand7d7f672009-12-06 20:50:05 +0000782}
783
Douglas Gregor7ad83902008-11-05 04:29:56 +0000784CXXBaseOrMemberInitializer::
Douglas Gregor802ab452009-12-02 22:36:29 +0000785CXXBaseOrMemberInitializer(ASTContext &Context,
Anders Carlsson80638c52010-04-12 00:51:03 +0000786 TypeSourceInfo *TInfo, bool IsVirtual,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000787 SourceLocation L, Expr *Init, SourceLocation R)
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000788 : BaseOrMember(TInfo), Init(Init), AnonUnionMember(0),
789 LParenLoc(L), RParenLoc(R), IsVirtual(IsVirtual), IsWritten(false),
790 SourceOrderOrNumArrayIndices(0)
Douglas Gregor802ab452009-12-02 22:36:29 +0000791{
Douglas Gregor7ad83902008-11-05 04:29:56 +0000792}
793
794CXXBaseOrMemberInitializer::
Douglas Gregor802ab452009-12-02 22:36:29 +0000795CXXBaseOrMemberInitializer(ASTContext &Context,
796 FieldDecl *Member, SourceLocation MemberLoc,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000797 SourceLocation L, Expr *Init, SourceLocation R)
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000798 : BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
799 AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
800 IsWritten(false), SourceOrderOrNumArrayIndices(0)
Douglas Gregor802ab452009-12-02 22:36:29 +0000801{
Douglas Gregor7ad83902008-11-05 04:29:56 +0000802}
803
Douglas Gregorfb8cc252010-05-05 05:51:00 +0000804CXXBaseOrMemberInitializer::
805CXXBaseOrMemberInitializer(ASTContext &Context,
806 FieldDecl *Member, SourceLocation MemberLoc,
807 SourceLocation L, Expr *Init, SourceLocation R,
808 VarDecl **Indices,
809 unsigned NumIndices)
810 : BaseOrMember(Member), MemberLocation(MemberLoc), Init(Init),
Abramo Bagnaraa0af3b42010-05-26 18:09:23 +0000811 AnonUnionMember(0), LParenLoc(L), RParenLoc(R), IsVirtual(false),
812 IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices)
Douglas Gregorfb8cc252010-05-05 05:51:00 +0000813{
814 VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1);
815 memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *));
816}
817
818CXXBaseOrMemberInitializer *
819CXXBaseOrMemberInitializer::Create(ASTContext &Context,
820 FieldDecl *Member,
821 SourceLocation MemberLoc,
822 SourceLocation L,
823 Expr *Init,
824 SourceLocation R,
825 VarDecl **Indices,
826 unsigned NumIndices) {
827 void *Mem = Context.Allocate(sizeof(CXXBaseOrMemberInitializer) +
828 sizeof(VarDecl *) * NumIndices,
829 llvm::alignof<CXXBaseOrMemberInitializer>());
830 return new (Mem) CXXBaseOrMemberInitializer(Context, Member, MemberLoc,
831 L, Init, R, Indices, NumIndices);
832}
833
Douglas Gregor802ab452009-12-02 22:36:29 +0000834void CXXBaseOrMemberInitializer::Destroy(ASTContext &Context) {
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000835 if (Init)
836 Init->Destroy(Context);
Douglas Gregorfb8cc252010-05-05 05:51:00 +0000837 // FIXME: Destroy indices
Douglas Gregor802ab452009-12-02 22:36:29 +0000838 this->~CXXBaseOrMemberInitializer();
839}
840
841TypeLoc CXXBaseOrMemberInitializer::getBaseClassLoc() const {
842 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000843 return BaseOrMember.get<TypeSourceInfo*>()->getTypeLoc();
Douglas Gregor802ab452009-12-02 22:36:29 +0000844 else
845 return TypeLoc();
846}
847
848Type *CXXBaseOrMemberInitializer::getBaseClass() {
849 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000850 return BaseOrMember.get<TypeSourceInfo*>()->getType().getTypePtr();
Douglas Gregor802ab452009-12-02 22:36:29 +0000851 else
852 return 0;
853}
854
855const Type *CXXBaseOrMemberInitializer::getBaseClass() const {
856 if (isBaseInitializer())
John McCalla93c9342009-12-07 02:54:59 +0000857 return BaseOrMember.get<TypeSourceInfo*>()->getType().getTypePtr();
Douglas Gregor802ab452009-12-02 22:36:29 +0000858 else
859 return 0;
860}
861
862SourceLocation CXXBaseOrMemberInitializer::getSourceLocation() const {
863 if (isMemberInitializer())
864 return getMemberLocation();
865
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000866 return getBaseClassLoc().getLocalSourceRange().getBegin();
Douglas Gregor802ab452009-12-02 22:36:29 +0000867}
868
869SourceRange CXXBaseOrMemberInitializer::getSourceRange() const {
870 return SourceRange(getSourceLocation(), getRParenLoc());
Douglas Gregor7ad83902008-11-05 04:29:56 +0000871}
872
Douglas Gregorb48fe382008-10-31 09:07:45 +0000873CXXConstructorDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000874CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) {
875 return new (C) CXXConstructorDecl(0, SourceLocation(), DeclarationName(),
876 QualType(), 0, false, false, false);
877}
878
879CXXConstructorDecl *
Douglas Gregorb48fe382008-10-31 09:07:45 +0000880CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000881 SourceLocation L, DeclarationName N,
John McCalla93c9342009-12-07 02:54:59 +0000882 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000883 bool isExplicit,
Douglas Gregor16573fa2010-04-19 22:54:31 +0000884 bool isInline,
885 bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000886 assert(N.getNameKind() == DeclarationName::CXXConstructorName &&
887 "Name must refer to a constructor");
Douglas Gregor16573fa2010-04-19 22:54:31 +0000888 return new (C) CXXConstructorDecl(RD, L, N, T, TInfo, isExplicit,
889 isInline, isImplicitlyDeclared);
Douglas Gregorb48fe382008-10-31 09:07:45 +0000890}
891
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000892bool CXXConstructorDecl::isDefaultConstructor() const {
893 // C++ [class.ctor]p5:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000894 // A default constructor for a class X is a constructor of class
895 // X that can be called without an argument.
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000896 return (getNumParams() == 0) ||
Anders Carlssonda3f4e22009-08-25 05:12:04 +0000897 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg());
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000898}
899
Mike Stump1eb44332009-09-09 15:08:12 +0000900bool
Douglas Gregor9e9199d2009-12-22 00:34:07 +0000901CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000902 // C++ [class.copy]p2:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000903 // A non-template constructor for class X is a copy constructor
904 // if its first parameter is of type X&, const X&, volatile X& or
905 // const volatile X&, and either there are no other parameters
906 // or else all other parameters have default arguments (8.3.6).
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000907 if ((getNumParams() < 1) ||
Douglas Gregor77da3f42009-10-13 23:45:19 +0000908 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
Douglas Gregorfd476482009-11-13 23:59:09 +0000909 (getPrimaryTemplate() != 0) ||
Douglas Gregor77da3f42009-10-13 23:45:19 +0000910 (getDescribedFunctionTemplate() != 0))
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000911 return false;
912
913 const ParmVarDecl *Param = getParamDecl(0);
914
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000915 // Do we have a reference type? Rvalue references don't count.
Douglas Gregorfd476482009-11-13 23:59:09 +0000916 const LValueReferenceType *ParamRefType =
917 Param->getType()->getAs<LValueReferenceType>();
918 if (!ParamRefType)
919 return false;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000920
Douglas Gregorfd476482009-11-13 23:59:09 +0000921 // Is it a reference to our class type?
Douglas Gregor9e9199d2009-12-22 00:34:07 +0000922 ASTContext &Context = getASTContext();
923
Douglas Gregorfd476482009-11-13 23:59:09 +0000924 CanQualType PointeeType
925 = Context.getCanonicalType(ParamRefType->getPointeeType());
Douglas Gregor14e0b3d2009-09-15 20:50:23 +0000926 CanQualType ClassTy
927 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000928 if (PointeeType.getUnqualifiedType() != ClassTy)
929 return false;
930
John McCall0953e762009-09-24 19:53:00 +0000931 // FIXME: other qualifiers?
932
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000933 // We have a copy constructor.
934 TypeQuals = PointeeType.getCVRQualifiers();
935 return true;
936}
937
Anders Carlssonfaccd722009-08-28 16:57:08 +0000938bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
Douglas Gregor60d62c22008-10-31 16:23:19 +0000939 // C++ [class.conv.ctor]p1:
940 // A constructor declared without the function-specifier explicit
941 // that can be called with a single parameter specifies a
942 // conversion from the type of its first parameter to the type of
943 // its class. Such a constructor is called a converting
944 // constructor.
Anders Carlssonfaccd722009-08-28 16:57:08 +0000945 if (isExplicit() && !AllowExplicit)
Douglas Gregor60d62c22008-10-31 16:23:19 +0000946 return false;
947
Mike Stump1eb44332009-09-09 15:08:12 +0000948 return (getNumParams() == 0 &&
John McCall183700f2009-09-21 23:43:11 +0000949 getType()->getAs<FunctionProtoType>()->isVariadic()) ||
Douglas Gregor60d62c22008-10-31 16:23:19 +0000950 (getNumParams() == 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +0000951 (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
Douglas Gregor60d62c22008-10-31 16:23:19 +0000952}
Douglas Gregorb48fe382008-10-31 09:07:45 +0000953
Douglas Gregor66724ea2009-11-14 01:20:54 +0000954bool CXXConstructorDecl::isCopyConstructorLikeSpecialization() const {
955 if ((getNumParams() < 1) ||
956 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
957 (getPrimaryTemplate() == 0) ||
958 (getDescribedFunctionTemplate() != 0))
959 return false;
960
961 const ParmVarDecl *Param = getParamDecl(0);
962
963 ASTContext &Context = getASTContext();
964 CanQualType ParamType = Context.getCanonicalType(Param->getType());
965
966 // Strip off the lvalue reference, if any.
967 if (CanQual<LValueReferenceType> ParamRefType
968 = ParamType->getAs<LValueReferenceType>())
969 ParamType = ParamRefType->getPointeeType();
970
971
972 // Is it the same as our our class type?
973 CanQualType ClassTy
974 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
975 if (ParamType.getUnqualifiedType() != ClassTy)
976 return false;
977
978 return true;
979}
980
Douglas Gregor42a552f2008-11-05 20:51:48 +0000981CXXDestructorDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000982CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) {
983 return new (C) CXXDestructorDecl(0, SourceLocation(), DeclarationName(),
984 QualType(), false, false);
985}
986
987CXXDestructorDecl *
Douglas Gregor42a552f2008-11-05 20:51:48 +0000988CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000989 SourceLocation L, DeclarationName N,
Mike Stump1eb44332009-09-09 15:08:12 +0000990 QualType T, bool isInline,
Douglas Gregor42a552f2008-11-05 20:51:48 +0000991 bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000992 assert(N.getNameKind() == DeclarationName::CXXDestructorName &&
993 "Name must refer to a destructor");
Douglas Gregor16573fa2010-04-19 22:54:31 +0000994 return new (C) CXXDestructorDecl(RD, L, N, T, isInline, isImplicitlyDeclared);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000995}
996
Fariborz Jahaniand45c3632009-07-01 21:05:43 +0000997void
Fariborz Jahanian73b85f32009-07-01 23:35:25 +0000998CXXConstructorDecl::Destroy(ASTContext& C) {
999 C.Deallocate(BaseOrMemberInitializers);
Fariborz Jahanian0d3c26c2009-07-07 16:24:08 +00001000 CXXMethodDecl::Destroy(C);
Fariborz Jahanian73b85f32009-07-01 23:35:25 +00001001}
1002
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001003CXXConversionDecl *
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001004CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) {
1005 return new (C) CXXConversionDecl(0, SourceLocation(), DeclarationName(),
1006 QualType(), 0, false, false);
1007}
1008
1009CXXConversionDecl *
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001010CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +00001011 SourceLocation L, DeclarationName N,
John McCalla93c9342009-12-07 02:54:59 +00001012 QualType T, TypeSourceInfo *TInfo,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001013 bool isInline, bool isExplicit) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +00001014 assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName &&
1015 "Name must refer to a conversion function");
John McCalla93c9342009-12-07 02:54:59 +00001016 return new (C) CXXConversionDecl(RD, L, N, T, TInfo, isInline, isExplicit);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001017}
1018
Chris Lattner21ef7ae2008-11-04 16:51:42 +00001019LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +00001020 DeclContext *DC,
Chris Lattner21ef7ae2008-11-04 16:51:42 +00001021 SourceLocation L,
Douglas Gregor074149e2009-01-05 19:45:36 +00001022 LanguageIDs Lang, bool Braces) {
Steve Naroff3e970492009-01-27 21:25:57 +00001023 return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
Douglas Gregorf44515a2008-12-16 22:23:02 +00001024}
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001025
1026UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
1027 SourceLocation L,
1028 SourceLocation NamespaceLoc,
Douglas Gregor8419fa32009-05-30 06:31:56 +00001029 SourceRange QualifierRange,
1030 NestedNameSpecifier *Qualifier,
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001031 SourceLocation IdentLoc,
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001032 NamedDecl *Used,
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001033 DeclContext *CommonAncestor) {
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001034 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
1035 Used = NS->getOriginalNamespace();
Mike Stump1eb44332009-09-09 15:08:12 +00001036 return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange,
Douglas Gregor8419fa32009-05-30 06:31:56 +00001037 Qualifier, IdentLoc, Used, CommonAncestor);
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001038}
1039
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001040NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
1041 if (NamespaceAliasDecl *NA =
1042 dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
1043 return NA->getNamespace();
1044 return cast_or_null<NamespaceDecl>(NominatedNamespace);
1045}
1046
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001047void UsingDirectiveDecl::setNominatedNamespace(NamedDecl* ND) {
1048 assert((isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) &&
1049 "expected a NamespaceDecl or NamespaceAliasDecl");
1050 NominatedNamespace = ND;
1051}
1052
Mike Stump1eb44332009-09-09 15:08:12 +00001053NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
1054 SourceLocation L,
1055 SourceLocation AliasLoc,
1056 IdentifierInfo *Alias,
Douglas Gregor6c9c9402009-05-30 06:48:27 +00001057 SourceRange QualifierRange,
1058 NestedNameSpecifier *Qualifier,
Mike Stump1eb44332009-09-09 15:08:12 +00001059 SourceLocation IdentLoc,
Anders Carlsson68771c72009-03-28 22:58:02 +00001060 NamedDecl *Namespace) {
Sebastian Redleb0d8c92009-11-23 15:34:23 +00001061 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
1062 Namespace = NS->getOriginalNamespace();
Mike Stump1eb44332009-09-09 15:08:12 +00001063 return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange,
Douglas Gregor6c9c9402009-05-30 06:48:27 +00001064 Qualifier, IdentLoc, Namespace);
Anders Carlsson68771c72009-03-28 22:58:02 +00001065}
1066
Douglas Gregor9cfbe482009-06-20 00:51:54 +00001067UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC,
John McCall9488ea12009-11-17 05:59:44 +00001068 SourceLocation L, SourceRange NNR, SourceLocation UL,
1069 NestedNameSpecifier* TargetNNS, DeclarationName Name,
1070 bool IsTypeNameArg) {
1071 return new (C) UsingDecl(DC, L, NNR, UL, TargetNNS, Name, IsTypeNameArg);
Douglas Gregor9cfbe482009-06-20 00:51:54 +00001072}
1073
John McCall7ba107a2009-11-18 02:36:19 +00001074UnresolvedUsingValueDecl *
1075UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
1076 SourceLocation UsingLoc,
1077 SourceRange TargetNNR,
1078 NestedNameSpecifier *TargetNNS,
1079 SourceLocation TargetNameLoc,
1080 DeclarationName TargetName) {
1081 return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
1082 TargetNNR, TargetNNS,
1083 TargetNameLoc, TargetName);
1084}
1085
1086UnresolvedUsingTypenameDecl *
1087UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
1088 SourceLocation UsingLoc,
1089 SourceLocation TypenameLoc,
1090 SourceRange TargetNNR,
1091 NestedNameSpecifier *TargetNNS,
1092 SourceLocation TargetNameLoc,
1093 DeclarationName TargetName) {
1094 return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc,
1095 TargetNNR, TargetNNS,
1096 TargetNameLoc,
1097 TargetName.getAsIdentifierInfo());
Anders Carlsson665b49c2009-08-28 05:30:28 +00001098}
1099
Anders Carlssonfb311762009-03-14 00:25:26 +00001100StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
1101 SourceLocation L, Expr *AssertExpr,
1102 StringLiteral *Message) {
1103 return new (C) StaticAssertDecl(DC, L, AssertExpr, Message);
1104}
1105
1106void StaticAssertDecl::Destroy(ASTContext& C) {
1107 AssertExpr->Destroy(C);
1108 Message->Destroy(C);
John McCallb6217662010-03-15 10:12:16 +00001109 Decl::Destroy(C);
Anders Carlssonfb311762009-03-14 00:25:26 +00001110}
1111
1112StaticAssertDecl::~StaticAssertDecl() {
1113}
1114
Anders Carlsson05bf2c72009-03-26 23:46:50 +00001115static const char *getAccessName(AccessSpecifier AS) {
1116 switch (AS) {
1117 default:
1118 case AS_none:
1119 assert("Invalid access specifier!");
1120 return 0;
1121 case AS_public:
1122 return "public";
1123 case AS_private:
1124 return "private";
1125 case AS_protected:
1126 return "protected";
1127 }
1128}
1129
1130const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
1131 AccessSpecifier AS) {
1132 return DB << getAccessName(AS);
1133}
1134
1135