blob: e8f97a383d02f6f41e1f2fcda7535608a516c84d [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 Gregor7d7e6722008-11-12 23:21:09 +000018#include "clang/Basic/IdentifierTable.h"
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000019#include "llvm/ADT/STLExtras.h"
Ted Kremenek4b7c9832008-09-05 17:16:31 +000020using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// Decl Allocation/Deallocation Method Implementations
24//===----------------------------------------------------------------------===//
Douglas Gregor72c3f312008-12-05 18:15:24 +000025
Douglas Gregor3e00bad2009-02-17 01:05:43 +000026CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
Douglas Gregor741dd9a2009-07-21 14:46:17 +000027 SourceLocation L, IdentifierInfo *Id,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000028 CXXRecordDecl *PrevDecl,
Mike Stump1eb44332009-09-09 15:08:12 +000029 SourceLocation TKL)
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000030 : RecordDecl(K, TK, DC, L, Id, PrevDecl, TKL),
Douglas Gregor7d7e6722008-11-12 23:21:09 +000031 UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
Sebastian Redl64b45f72009-01-05 20:52:13 +000032 UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
Eli Friedman97c134e2009-08-15 22:23:00 +000033 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
34 Abstract(false), HasTrivialConstructor(true),
35 HasTrivialCopyConstructor(true), HasTrivialCopyAssignment(true),
36 HasTrivialDestructor(true), Bases(0), NumBases(0), VBases(0), NumVBases(0),
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000037 Conversions(DC, DeclarationName()),
Douglas Gregord475b8d2009-03-25 21:17:03 +000038 TemplateOrInstantiation() { }
Douglas Gregor7d7e6722008-11-12 23:21:09 +000039
Ted Kremenek4b7c9832008-09-05 17:16:31 +000040CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
41 SourceLocation L, IdentifierInfo *Id,
Douglas Gregor741dd9a2009-07-21 14:46:17 +000042 SourceLocation TKL,
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000043 CXXRecordDecl* PrevDecl,
44 bool DelayTypeCreation) {
Mike Stump1eb44332009-09-09 15:08:12 +000045 CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000046 PrevDecl, TKL);
Mike Stump1eb44332009-09-09 15:08:12 +000047
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +000048 // FIXME: DelayTypeCreation seems like such a hack
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000049 if (!DelayTypeCreation)
Mike Stump1eb44332009-09-09 15:08:12 +000050 C.getTypeDeclType(R, PrevDecl);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000051 return R;
52}
53
Douglas Gregorf8268ae2008-10-22 17:49:05 +000054CXXRecordDecl::~CXXRecordDecl() {
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000055}
56
57void CXXRecordDecl::Destroy(ASTContext &C) {
58 C.Deallocate(Bases);
Fariborz Jahanian71c6e712009-07-22 17:41:53 +000059 C.Deallocate(VBases);
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000060 this->RecordDecl::Destroy(C);
Douglas Gregorf8268ae2008-10-22 17:49:05 +000061}
62
Mike Stump1eb44332009-09-09 15:08:12 +000063void
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000064CXXRecordDecl::setBases(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +000065 CXXBaseSpecifier const * const *Bases,
Douglas Gregor57c856b2008-10-23 18:13:27 +000066 unsigned NumBases) {
Mike Stump1eb44332009-09-09 15:08:12 +000067 // C++ [dcl.init.aggr]p1:
Douglas Gregor64bffa92008-11-05 16:20:31 +000068 // An aggregate is an array or a class (clause 9) with [...]
69 // no base classes [...].
70 Aggregate = false;
71
Douglas Gregor57c856b2008-10-23 18:13:27 +000072 if (this->Bases)
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000073 C.Deallocate(this->Bases);
Mike Stump1eb44332009-09-09 15:08:12 +000074
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000075 int vbaseCount = 0;
76 llvm::SmallVector<const CXXBaseSpecifier*, 8> UniqueVbases;
77 bool hasDirectVirtualBase = false;
Mike Stump1eb44332009-09-09 15:08:12 +000078
Fariborz Jahanian5ffcd7b2009-07-02 18:26:15 +000079 this->Bases = new(C) CXXBaseSpecifier [NumBases];
Douglas Gregor57c856b2008-10-23 18:13:27 +000080 this->NumBases = NumBases;
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000081 for (unsigned i = 0; i < NumBases; ++i) {
Douglas Gregor57c856b2008-10-23 18:13:27 +000082 this->Bases[i] = *Bases[i];
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000083 // Keep track of inherited vbases for this base class.
84 const CXXBaseSpecifier *Base = Bases[i];
85 QualType BaseType = Base->getType();
Mike Stump1eb44332009-09-09 15:08:12 +000086 // Skip template types.
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000087 // FIXME. This means that this list must be rebuilt during template
88 // instantiation.
89 if (BaseType->isDependentType())
90 continue;
91 CXXRecordDecl *BaseClassDecl
Ted Kremenek6217b802009-07-29 21:53:49 +000092 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000093 if (Base->isVirtual())
94 hasDirectVirtualBase = true;
Mike Stump1eb44332009-09-09 15:08:12 +000095 for (CXXRecordDecl::base_class_iterator VBase =
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000096 BaseClassDecl->vbases_begin(),
97 E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) {
Mike Stump1eb44332009-09-09 15:08:12 +000098 // Add this vbase to the array of vbases for current class if it is
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000099 // not already in the list.
100 // FIXME. Note that we do a linear search as number of such classes are
101 // very few.
102 int i;
103 for (i = 0; i < vbaseCount; ++i)
104 if (UniqueVbases[i]->getType() == VBase->getType())
105 break;
106 if (i == vbaseCount) {
107 UniqueVbases.push_back(VBase);
108 ++vbaseCount;
109 }
110 }
111 }
112 if (hasDirectVirtualBase) {
113 // Iterate one more time through the direct bases and add the virtual
114 // base to the list of vritual bases for current class.
115 for (unsigned i = 0; i < NumBases; ++i) {
116 const CXXBaseSpecifier *VBase = Bases[i];
117 if (!VBase->isVirtual())
118 continue;
Alisdair Meredith002b91f2009-07-11 14:32:10 +0000119 int j;
120 for (j = 0; j < vbaseCount; ++j)
121 if (UniqueVbases[j]->getType() == VBase->getType())
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000122 break;
Alisdair Meredith002b91f2009-07-11 14:32:10 +0000123 if (j == vbaseCount) {
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000124 UniqueVbases.push_back(VBase);
125 ++vbaseCount;
126 }
127 }
128 }
129 if (vbaseCount > 0) {
130 // build AST for inhireted, direct or indirect, virtual bases.
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000131 this->VBases = new (C) CXXBaseSpecifier [vbaseCount];
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000132 this->NumVBases = vbaseCount;
133 for (int i = 0; i < vbaseCount; i++) {
134 QualType QT = UniqueVbases[i]->getType();
135 CXXRecordDecl *VBaseClassDecl
Ted Kremenek6217b802009-07-29 21:53:49 +0000136 = cast<CXXRecordDecl>(QT->getAs<RecordType>()->getDecl());
Mike Stump1eb44332009-09-09 15:08:12 +0000137 this->VBases[i] =
Douglas Gregor2aef06d2009-07-22 20:55:49 +0000138 CXXBaseSpecifier(VBaseClassDecl->getSourceRange(), true,
139 VBaseClassDecl->getTagKind() == RecordDecl::TK_class,
140 UniqueVbases[i]->getAccessSpecifier(), QT);
Fariborz Jahanian40c072f2009-07-10 20:13:23 +0000141 }
142 }
Douglas Gregor57c856b2008-10-23 18:13:27 +0000143}
144
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000145bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const {
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000146 return getCopyConstructor(Context, QualType::Const) != 0;
147}
148
Mike Stump1eb44332009-09-09 15:08:12 +0000149CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000150 unsigned TypeQuals) const{
Sebastian Redl64b45f72009-01-05 20:52:13 +0000151 QualType ClassType
152 = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this));
Mike Stump1eb44332009-09-09 15:08:12 +0000153 DeclarationName ConstructorName
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000154 = Context.DeclarationNames.getCXXConstructorName(
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000155 Context.getCanonicalType(ClassType));
156 unsigned FoundTQs;
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000157 DeclContext::lookup_const_iterator Con, ConEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000158 for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName);
Douglas Gregorfdfab6b2008-12-23 21:31:30 +0000159 Con != ConEnd; ++Con) {
Douglas Gregord93bacf2009-09-04 14:46:39 +0000160 // C++ [class.copy]p2:
161 // A non-template constructor for class X is a copy constructor if [...]
162 if (isa<FunctionTemplateDecl>(*Con))
163 continue;
164
Mike Stump1eb44332009-09-09 15:08:12 +0000165 if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context,
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000166 FoundTQs)) {
167 if (((TypeQuals & QualType::Const) == (FoundTQs & QualType::Const)) ||
168 (!(TypeQuals & QualType::Const) && (FoundTQs & QualType::Const)))
169 return cast<CXXConstructorDecl>(*Con);
Mike Stump1eb44332009-09-09 15:08:12 +0000170
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000171 }
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000172 }
Fariborz Jahanian485f0872009-06-22 23:34:40 +0000173 return 0;
Douglas Gregor396b7cd2008-11-03 17:51:48 +0000174}
175
Fariborz Jahanian0270b8a2009-08-12 23:34:46 +0000176bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context,
177 const CXXMethodDecl *& MD) const {
Sebastian Redl64b45f72009-01-05 20:52:13 +0000178 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
179 const_cast<CXXRecordDecl*>(this)));
180 DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal);
181
182 DeclContext::lookup_const_iterator Op, OpEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000183 for (llvm::tie(Op, OpEnd) = this->lookup(OpName);
Sebastian Redl64b45f72009-01-05 20:52:13 +0000184 Op != OpEnd; ++Op) {
185 // C++ [class.copy]p9:
186 // A user-declared copy assignment operator is a non-static non-template
187 // member function of class X with exactly one parameter of type X, X&,
188 // const X&, volatile X& or const volatile X&.
189 const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op);
190 if (Method->isStatic())
191 continue;
192 // TODO: Skip templates? Or is this implicitly done due to parameter types?
Douglas Gregor72564e72009-02-26 23:50:07 +0000193 const FunctionProtoType *FnType =
194 Method->getType()->getAsFunctionProtoType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000195 assert(FnType && "Overloaded operator has no prototype.");
196 // Don't assert on this; an invalid decl might have been left in the AST.
197 if (FnType->getNumArgs() != 1 || FnType->isVariadic())
198 continue;
199 bool AcceptsConst = true;
200 QualType ArgType = FnType->getArgType(0);
Ted Kremenek6217b802009-07-29 21:53:49 +0000201 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) {
Sebastian Redl64b45f72009-01-05 20:52:13 +0000202 ArgType = Ref->getPointeeType();
Douglas Gregor2ff44782009-03-20 20:21:37 +0000203 // Is it a non-const lvalue reference?
Sebastian Redl64b45f72009-01-05 20:52:13 +0000204 if (!ArgType.isConstQualified())
205 AcceptsConst = false;
206 }
207 if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType)
208 continue;
Fariborz Jahanian0270b8a2009-08-12 23:34:46 +0000209 MD = Method;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000210 // We have a single argument of type cv X or cv X&, i.e. we've found the
211 // copy assignment operator. Return whether it accepts const arguments.
212 return AcceptsConst;
213 }
214 assert(isInvalidDecl() &&
215 "No copy assignment operator declared in valid code.");
216 return false;
217}
218
219void
Mike Stump1eb44332009-09-09 15:08:12 +0000220CXXRecordDecl::addedConstructor(ASTContext &Context,
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000221 CXXConstructorDecl *ConDecl) {
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000222 assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl");
223 // Note that we have a user-declared constructor.
224 UserDeclaredConstructor = true;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000225
Mike Stump1eb44332009-09-09 15:08:12 +0000226 // C++ [dcl.init.aggr]p1:
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000227 // An aggregate is an array or a class (clause 9) with no
228 // user-declared constructors (12.1) [...].
229 Aggregate = false;
Douglas Gregor64bffa92008-11-05 16:20:31 +0000230
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000231 // C++ [class]p4:
232 // A POD-struct is an aggregate class [...]
233 PlainOldData = false;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000234
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000235 // C++ [class.ctor]p5:
236 // A constructor is trivial if it is an implicitly-declared default
237 // constructor.
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000238 // FIXME: C++0x: don't do this for "= default" default constructors.
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000239 HasTrivialConstructor = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000240
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000241 // Note when we have a user-declared copy constructor, which will
242 // suppress the implicit declaration of a copy constructor.
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000243 if (ConDecl->isCopyConstructor(Context)) {
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000244 UserDeclaredCopyConstructor = true;
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000245
246 // C++ [class.copy]p6:
247 // A copy constructor is trivial if it is implicitly declared.
248 // FIXME: C++0x: don't do this for "= default" copy constructors.
249 HasTrivialCopyConstructor = false;
250 }
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000251}
252
Sebastian Redl64b45f72009-01-05 20:52:13 +0000253void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context,
254 CXXMethodDecl *OpDecl) {
255 // We're interested specifically in copy assignment operators.
Douglas Gregor72564e72009-02-26 23:50:07 +0000256 const FunctionProtoType *FnType = OpDecl->getType()->getAsFunctionProtoType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000257 assert(FnType && "Overloaded operator has no proto function type.");
258 assert(FnType->getNumArgs() == 1 && !FnType->isVariadic());
259 QualType ArgType = FnType->getArgType(0);
Ted Kremenek6217b802009-07-29 21:53:49 +0000260 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>())
Sebastian Redl64b45f72009-01-05 20:52:13 +0000261 ArgType = Ref->getPointeeType();
262
263 ArgType = ArgType.getUnqualifiedType();
264 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
265 const_cast<CXXRecordDecl*>(this)));
266
267 if (ClassType != Context.getCanonicalType(ArgType))
268 return;
269
270 // This is a copy assignment operator.
271 // Suppress the implicit declaration of a copy constructor.
272 UserDeclaredCopyAssignment = true;
273
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000274 // C++ [class.copy]p11:
275 // A copy assignment operator is trivial if it is implicitly declared.
276 // FIXME: C++0x: don't do this for "= default" copy operators.
277 HasTrivialCopyAssignment = false;
278
Sebastian Redl64b45f72009-01-05 20:52:13 +0000279 // C++ [class]p4:
280 // A POD-struct is an aggregate class that [...] has no user-defined copy
281 // assignment operator [...].
282 PlainOldData = false;
283}
284
Mike Stump1eb44332009-09-09 15:08:12 +0000285void CXXRecordDecl::addConversionFunction(ASTContext &Context,
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000286 CXXConversionDecl *ConvDecl) {
Douglas Gregor65ec1fd2009-08-21 23:19:43 +0000287 assert(!ConvDecl->getDescribedFunctionTemplate() &&
288 "Conversion function templates should cast to FunctionTemplateDecl.");
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000289 Conversions.addOverload(ConvDecl);
290}
291
Mike Stump1eb44332009-09-09 15:08:12 +0000292void CXXRecordDecl::addConversionFunction(ASTContext &Context,
Douglas Gregor65ec1fd2009-08-21 23:19:43 +0000293 FunctionTemplateDecl *ConvDecl) {
294 assert(isa<CXXConversionDecl>(ConvDecl->getTemplatedDecl()) &&
295 "Function template is not a conversion function template");
296 Conversions.addOverload(ConvDecl);
297}
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000298
299CXXConstructorDecl *
300CXXRecordDecl::getDefaultConstructor(ASTContext &Context) {
301 QualType ClassType = Context.getTypeDeclType(this);
302 DeclarationName ConstructorName
303 = Context.DeclarationNames.getCXXConstructorName(
304 Context.getCanonicalType(ClassType.getUnqualifiedType()));
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000306 DeclContext::lookup_const_iterator Con, ConEnd;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000307 for (llvm::tie(Con, ConEnd) = lookup(ConstructorName);
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000308 Con != ConEnd; ++Con) {
Douglas Gregord93bacf2009-09-04 14:46:39 +0000309 // FIXME: In C++0x, a constructor template can be a default constructor.
310 if (isa<FunctionTemplateDecl>(*Con))
311 continue;
312
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000313 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
314 if (Constructor->isDefaultConstructor())
315 return Constructor;
316 }
317 return 0;
318}
319
Anders Carlsson7267c162009-05-29 21:03:38 +0000320const CXXDestructorDecl *
321CXXRecordDecl::getDestructor(ASTContext &Context) {
322 QualType ClassType = Context.getTypeDeclType(this);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
324 DeclarationName Name
Douglas Gregor50d62d12009-08-05 05:36:45 +0000325 = Context.DeclarationNames.getCXXDestructorName(
326 Context.getCanonicalType(ClassType));
Anders Carlsson7267c162009-05-29 21:03:38 +0000327
328 DeclContext::lookup_iterator I, E;
Mike Stump1eb44332009-09-09 15:08:12 +0000329 llvm::tie(I, E) = lookup(Name);
Anders Carlsson7267c162009-05-29 21:03:38 +0000330 assert(I != E && "Did not find a destructor!");
Mike Stump1eb44332009-09-09 15:08:12 +0000331
Anders Carlsson7267c162009-05-29 21:03:38 +0000332 const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I);
333 assert(++I == E && "Found more than one destructor!");
Mike Stump1eb44332009-09-09 15:08:12 +0000334
Anders Carlsson7267c162009-05-29 21:03:38 +0000335 return Dtor;
336}
337
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000338CXXMethodDecl *
339CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor10bd3682008-11-17 22:58:34 +0000340 SourceLocation L, DeclarationName N,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000341 QualType T, DeclaratorInfo *DInfo,
342 bool isStatic, bool isInline) {
343 return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, DInfo,
344 isStatic, isInline);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000345}
346
Anders Carlsson05eb2442009-05-16 23:58:37 +0000347
Mike Stump1eb44332009-09-09 15:08:12 +0000348typedef llvm::DenseMap<const CXXMethodDecl*,
349 std::vector<const CXXMethodDecl *> *>
Anders Carlsson05eb2442009-05-16 23:58:37 +0000350 OverriddenMethodsMapTy;
351
Mike Stumpb9871a22009-08-21 01:45:00 +0000352// FIXME: We hate static data. This doesn't survive PCH saving/loading, and
353// the vtable building code uses it at CG time.
Anders Carlsson05eb2442009-05-16 23:58:37 +0000354static OverriddenMethodsMapTy *OverriddenMethods = 0;
355
356void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
357 // FIXME: The CXXMethodDecl dtor needs to remove and free the entry.
Mike Stump1eb44332009-09-09 15:08:12 +0000358
Anders Carlsson05eb2442009-05-16 23:58:37 +0000359 if (!OverriddenMethods)
360 OverriddenMethods = new OverriddenMethodsMapTy();
Mike Stump1eb44332009-09-09 15:08:12 +0000361
Anders Carlsson05eb2442009-05-16 23:58:37 +0000362 std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this];
363 if (!Methods)
364 Methods = new std::vector<const CXXMethodDecl *>;
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Anders Carlsson05eb2442009-05-16 23:58:37 +0000366 Methods->push_back(MD);
367}
368
369CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
370 if (!OverriddenMethods)
371 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000372
Anders Carlsson05eb2442009-05-16 23:58:37 +0000373 OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
Daniel Dunbar0908c332009-08-01 23:40:20 +0000374 if (it == OverriddenMethods->end() || it->second->empty())
Anders Carlsson05eb2442009-05-16 23:58:37 +0000375 return 0;
Daniel Dunbar0908c332009-08-01 23:40:20 +0000376
Anders Carlsson05eb2442009-05-16 23:58:37 +0000377 return &(*it->second)[0];
378}
379
380CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
381 if (!OverriddenMethods)
382 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000383
Anders Carlsson05eb2442009-05-16 23:58:37 +0000384 OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
Daniel Dunbar0908c332009-08-01 23:40:20 +0000385 if (it == OverriddenMethods->end() || it->second->empty())
Anders Carlsson05eb2442009-05-16 23:58:37 +0000386 return 0;
387
Daniel Dunbar637ec322009-08-02 01:48:29 +0000388 return &(*it->second)[0] + it->second->size();
Anders Carlsson05eb2442009-05-16 23:58:37 +0000389}
390
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000391QualType CXXMethodDecl::getThisType(ASTContext &C) const {
Argyrios Kyrtzidisb0d178d2008-10-24 22:28:18 +0000392 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
393 // If the member function is declared const, the type of this is const X*,
394 // if the member function is declared volatile, the type of this is
395 // volatile X*, and if the member function is declared const volatile,
396 // the type of this is const volatile X*.
397
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000398 assert(isInstance() && "No 'this' for static methods!");
Anders Carlsson31a08752009-06-13 02:59:33 +0000399
400 QualType ClassTy;
401 if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate())
402 ClassTy = TD->getInjectedClassNameType(C);
403 else
Mike Stumpe607ed02009-08-07 18:05:12 +0000404 ClassTy = C.getTagDeclType(getParent());
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000405 ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers());
Anders Carlsson4e579922009-07-10 21:35:09 +0000406 return C.getPointerType(ClassTy);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000407}
408
Douglas Gregor7ad83902008-11-05 04:29:56 +0000409CXXBaseOrMemberInitializer::
Fariborz Jahanian47deacf2009-06-30 00:02:17 +0000410CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs,
Fariborz Jahaniand7b27e12009-07-23 00:42:24 +0000411 CXXConstructorDecl *C,
Mike Stump1eb44332009-09-09 15:08:12 +0000412 SourceLocation L, SourceLocation R)
Douglas Gregor72f6d672009-09-01 21:04:42 +0000413 : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) {
Douglas Gregor7ad83902008-11-05 04:29:56 +0000414 BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr());
415 assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer");
416 BaseOrMember |= 0x01;
Mike Stump1eb44332009-09-09 15:08:12 +0000417
Douglas Gregor7ad83902008-11-05 04:29:56 +0000418 if (NumArgs > 0) {
419 this->NumArgs = NumArgs;
Fariborz Jahanian50b8eea2009-07-24 17:57:02 +0000420 // FIXME. Allocation via Context
421 this->Args = new Stmt*[NumArgs];
Douglas Gregor7ad83902008-11-05 04:29:56 +0000422 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
423 this->Args[Idx] = Args[Idx];
424 }
Douglas Gregor72f6d672009-09-01 21:04:42 +0000425 CtorOrAnonUnion = C;
Douglas Gregor7ad83902008-11-05 04:29:56 +0000426}
427
428CXXBaseOrMemberInitializer::
Fariborz Jahanian47deacf2009-06-30 00:02:17 +0000429CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs,
Fariborz Jahaniand7b27e12009-07-23 00:42:24 +0000430 CXXConstructorDecl *C,
Anders Carlsson8c57a662009-08-29 01:31:33 +0000431 SourceLocation L, SourceLocation R)
Douglas Gregor72f6d672009-09-01 21:04:42 +0000432 : Args(0), NumArgs(0), CtorOrAnonUnion(), IdLoc(L), RParenLoc(R) {
Douglas Gregor7ad83902008-11-05 04:29:56 +0000433 BaseOrMember = reinterpret_cast<uintptr_t>(Member);
Mike Stump1eb44332009-09-09 15:08:12 +0000434 assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer");
Douglas Gregor7ad83902008-11-05 04:29:56 +0000435
436 if (NumArgs > 0) {
437 this->NumArgs = NumArgs;
Fariborz Jahanian50b8eea2009-07-24 17:57:02 +0000438 this->Args = new Stmt*[NumArgs];
Douglas Gregor7ad83902008-11-05 04:29:56 +0000439 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
440 this->Args[Idx] = Args[Idx];
441 }
Douglas Gregor72f6d672009-09-01 21:04:42 +0000442 CtorOrAnonUnion = C;
Douglas Gregor7ad83902008-11-05 04:29:56 +0000443}
444
445CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() {
446 delete [] Args;
447}
448
Douglas Gregorb48fe382008-10-31 09:07:45 +0000449CXXConstructorDecl *
450CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000451 SourceLocation L, DeclarationName N,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000452 QualType T, DeclaratorInfo *DInfo,
453 bool isExplicit,
Douglas Gregorb48fe382008-10-31 09:07:45 +0000454 bool isInline, bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000455 assert(N.getNameKind() == DeclarationName::CXXConstructorName &&
456 "Name must refer to a constructor");
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000457 return new (C) CXXConstructorDecl(RD, L, N, T, DInfo, isExplicit, isInline,
Douglas Gregorb48fe382008-10-31 09:07:45 +0000458 isImplicitlyDeclared);
459}
460
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000461bool CXXConstructorDecl::isDefaultConstructor() const {
462 // C++ [class.ctor]p5:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000463 // A default constructor for a class X is a constructor of class
464 // X that can be called without an argument.
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000465 return (getNumParams() == 0) ||
Anders Carlssonda3f4e22009-08-25 05:12:04 +0000466 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg());
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000467}
468
Mike Stump1eb44332009-09-09 15:08:12 +0000469bool
470CXXConstructorDecl::isCopyConstructor(ASTContext &Context,
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000471 unsigned &TypeQuals) const {
472 // C++ [class.copy]p2:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000473 // A non-template constructor for class X is a copy constructor
474 // if its first parameter is of type X&, const X&, volatile X& or
475 // const volatile X&, and either there are no other parameters
476 // or else all other parameters have default arguments (8.3.6).
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000477 if ((getNumParams() < 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +0000478 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()))
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000479 return false;
480
481 const ParmVarDecl *Param = getParamDecl(0);
482
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000483 // Do we have a reference type? Rvalue references don't count.
484 const LValueReferenceType *ParamRefType =
Ted Kremenek6217b802009-07-29 21:53:49 +0000485 Param->getType()->getAs<LValueReferenceType>();
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000486 if (!ParamRefType)
487 return false;
488
489 // Is it a reference to our class type?
Mike Stumpe607ed02009-08-07 18:05:12 +0000490 QualType PointeeType
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000491 = Context.getCanonicalType(ParamRefType->getPointeeType());
Mike Stumpe607ed02009-08-07 18:05:12 +0000492 QualType ClassTy = Context.getTagDeclType(getParent());
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000493 if (PointeeType.getUnqualifiedType() != ClassTy)
494 return false;
495
496 // We have a copy constructor.
497 TypeQuals = PointeeType.getCVRQualifiers();
498 return true;
499}
500
Anders Carlssonfaccd722009-08-28 16:57:08 +0000501bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
Douglas Gregor60d62c22008-10-31 16:23:19 +0000502 // C++ [class.conv.ctor]p1:
503 // A constructor declared without the function-specifier explicit
504 // that can be called with a single parameter specifies a
505 // conversion from the type of its first parameter to the type of
506 // its class. Such a constructor is called a converting
507 // constructor.
Anders Carlssonfaccd722009-08-28 16:57:08 +0000508 if (isExplicit() && !AllowExplicit)
Douglas Gregor60d62c22008-10-31 16:23:19 +0000509 return false;
510
Mike Stump1eb44332009-09-09 15:08:12 +0000511 return (getNumParams() == 0 &&
Douglas Gregor72564e72009-02-26 23:50:07 +0000512 getType()->getAsFunctionProtoType()->isVariadic()) ||
Douglas Gregor60d62c22008-10-31 16:23:19 +0000513 (getNumParams() == 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +0000514 (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
Douglas Gregor60d62c22008-10-31 16:23:19 +0000515}
Douglas Gregorb48fe382008-10-31 09:07:45 +0000516
Douglas Gregor42a552f2008-11-05 20:51:48 +0000517CXXDestructorDecl *
518CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000519 SourceLocation L, DeclarationName N,
Mike Stump1eb44332009-09-09 15:08:12 +0000520 QualType T, bool isInline,
Douglas Gregor42a552f2008-11-05 20:51:48 +0000521 bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000522 assert(N.getNameKind() == DeclarationName::CXXDestructorName &&
523 "Name must refer to a destructor");
Mike Stump1eb44332009-09-09 15:08:12 +0000524 return new (C) CXXDestructorDecl(RD, L, N, T, isInline,
Steve Naroff3e970492009-01-27 21:25:57 +0000525 isImplicitlyDeclared);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000526}
527
Fariborz Jahaniand45c3632009-07-01 21:05:43 +0000528void
Fariborz Jahanian393612e2009-07-21 22:36:06 +0000529CXXDestructorDecl::Destroy(ASTContext& C) {
530 C.Deallocate(BaseOrMemberDestructions);
531 CXXMethodDecl::Destroy(C);
532}
533
534void
Fariborz Jahanian73b85f32009-07-01 23:35:25 +0000535CXXConstructorDecl::Destroy(ASTContext& C) {
536 C.Deallocate(BaseOrMemberInitializers);
Fariborz Jahanian0d3c26c2009-07-07 16:24:08 +0000537 CXXMethodDecl::Destroy(C);
Fariborz Jahanian73b85f32009-07-01 23:35:25 +0000538}
539
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000540CXXConversionDecl *
541CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000542 SourceLocation L, DeclarationName N,
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000543 QualType T, DeclaratorInfo *DInfo,
544 bool isInline, bool isExplicit) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000545 assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName &&
546 "Name must refer to a conversion function");
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000547 return new (C) CXXConversionDecl(RD, L, N, T, DInfo, isInline, isExplicit);
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000548}
549
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000550OverloadedFunctionDecl *
551OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000552 DeclarationName N) {
Steve Naroff3e970492009-01-27 21:25:57 +0000553 return new (C) OverloadedFunctionDecl(DC, N);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000554}
Chris Lattner21ef7ae2008-11-04 16:51:42 +0000555
Douglas Gregordec06662009-08-21 18:42:58 +0000556OverloadIterator::OverloadIterator(NamedDecl *ND) : D(0) {
557 if (!ND)
558 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000559
Douglas Gregordec06662009-08-21 18:42:58 +0000560 if (isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND))
561 D = ND;
562 else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(ND)) {
Douglas Gregor8f1d89e2009-09-01 16:58:52 +0000563 if (Ovl->size() != 0) {
564 D = ND;
565 Iter = Ovl->function_begin();
566 }
Douglas Gregordec06662009-08-21 18:42:58 +0000567 }
568}
569
Douglas Gregor364e0212009-06-27 21:05:07 +0000570void OverloadedFunctionDecl::addOverload(AnyFunctionDecl F) {
571 Functions.push_back(F);
572 this->setLocation(F.get()->getLocation());
Douglas Gregore53060f2009-06-25 22:08:12 +0000573}
574
Douglas Gregordaa439a2009-07-08 10:57:20 +0000575OverloadIterator::reference OverloadIterator::operator*() const {
576 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
577 return FD;
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregordaa439a2009-07-08 10:57:20 +0000579 if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D))
580 return FTD;
Mike Stump1eb44332009-09-09 15:08:12 +0000581
Douglas Gregordaa439a2009-07-08 10:57:20 +0000582 assert(isa<OverloadedFunctionDecl>(D));
583 return *Iter;
584}
585
586OverloadIterator &OverloadIterator::operator++() {
587 if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) {
588 D = 0;
589 return *this;
590 }
Mike Stump1eb44332009-09-09 15:08:12 +0000591
Douglas Gregordaa439a2009-07-08 10:57:20 +0000592 if (++Iter == cast<OverloadedFunctionDecl>(D)->function_end())
593 D = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000594
Douglas Gregordaa439a2009-07-08 10:57:20 +0000595 return *this;
596}
597
598bool OverloadIterator::Equals(const OverloadIterator &Other) const {
599 if (!D || !Other.D)
600 return D == Other.D;
Mike Stump1eb44332009-09-09 15:08:12 +0000601
Douglas Gregordaa439a2009-07-08 10:57:20 +0000602 if (D != Other.D)
603 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Douglas Gregordaa439a2009-07-08 10:57:20 +0000605 return !isa<OverloadedFunctionDecl>(D) || Iter == Other.Iter;
606}
607
John McCall02cace72009-08-28 07:59:38 +0000608FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
609 SourceLocation L,
610 FriendUnion Friend,
611 SourceLocation FriendL) {
Daniel Dunbare32ecce2009-08-31 19:16:38 +0000612#ifndef NDEBUG
John McCall02cace72009-08-28 07:59:38 +0000613 if (Friend.is<NamedDecl*>()) {
614 NamedDecl *D = Friend.get<NamedDecl*>();
615 assert(isa<FunctionDecl>(D) ||
616 isa<CXXRecordDecl>(D) ||
617 isa<FunctionTemplateDecl>(D) ||
618 isa<ClassTemplateDecl>(D));
619 assert(D->getFriendObjectKind());
620 }
Daniel Dunbare32ecce2009-08-31 19:16:38 +0000621#endif
John McCallc48fbdf2009-08-11 21:13:21 +0000622
John McCall02cace72009-08-28 07:59:38 +0000623 return new (C) FriendDecl(DC, L, Friend, FriendL);
Mike Stump1eb44332009-09-09 15:08:12 +0000624}
John McCall3f9a8a62009-08-11 06:59:38 +0000625
Chris Lattner21ef7ae2008-11-04 16:51:42 +0000626LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
Mike Stump1eb44332009-09-09 15:08:12 +0000627 DeclContext *DC,
Chris Lattner21ef7ae2008-11-04 16:51:42 +0000628 SourceLocation L,
Douglas Gregor074149e2009-01-05 19:45:36 +0000629 LanguageIDs Lang, bool Braces) {
Steve Naroff3e970492009-01-27 21:25:57 +0000630 return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
Douglas Gregorf44515a2008-12-16 22:23:02 +0000631}
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000632
633UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
634 SourceLocation L,
635 SourceLocation NamespaceLoc,
Douglas Gregor8419fa32009-05-30 06:31:56 +0000636 SourceRange QualifierRange,
637 NestedNameSpecifier *Qualifier,
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000638 SourceLocation IdentLoc,
639 NamespaceDecl *Used,
640 DeclContext *CommonAncestor) {
Mike Stump1eb44332009-09-09 15:08:12 +0000641 return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange,
Douglas Gregor8419fa32009-05-30 06:31:56 +0000642 Qualifier, IdentLoc, Used, CommonAncestor);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000643}
644
Mike Stump1eb44332009-09-09 15:08:12 +0000645NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
646 SourceLocation L,
647 SourceLocation AliasLoc,
648 IdentifierInfo *Alias,
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000649 SourceRange QualifierRange,
650 NestedNameSpecifier *Qualifier,
Mike Stump1eb44332009-09-09 15:08:12 +0000651 SourceLocation IdentLoc,
Anders Carlsson68771c72009-03-28 22:58:02 +0000652 NamedDecl *Namespace) {
Mike Stump1eb44332009-09-09 15:08:12 +0000653 return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange,
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000654 Qualifier, IdentLoc, Namespace);
Anders Carlsson68771c72009-03-28 22:58:02 +0000655}
656
Douglas Gregor9cfbe482009-06-20 00:51:54 +0000657UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC,
658 SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
659 SourceLocation UL, NamedDecl* Target,
660 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) {
661 return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target,
662 TargetNNS, IsTypeNameArg);
663}
664
Anders Carlsson665b49c2009-08-28 05:30:28 +0000665UnresolvedUsingDecl *UnresolvedUsingDecl::Create(ASTContext &C, DeclContext *DC,
666 SourceLocation UsingLoc,
667 SourceRange TargetNNR,
668 NestedNameSpecifier *TargetNNS,
669 SourceLocation TargetNameLoc,
670 DeclarationName TargetName,
671 bool IsTypeNameArg) {
672 return new (C) UnresolvedUsingDecl(DC, UsingLoc, TargetNNR, TargetNNS,
673 TargetNameLoc, TargetName, IsTypeNameArg);
674}
675
Anders Carlssonfb311762009-03-14 00:25:26 +0000676StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
677 SourceLocation L, Expr *AssertExpr,
678 StringLiteral *Message) {
679 return new (C) StaticAssertDecl(DC, L, AssertExpr, Message);
680}
681
682void StaticAssertDecl::Destroy(ASTContext& C) {
683 AssertExpr->Destroy(C);
684 Message->Destroy(C);
685 this->~StaticAssertDecl();
686 C.Deallocate((void *)this);
687}
688
689StaticAssertDecl::~StaticAssertDecl() {
690}
691
Anders Carlsson05bf2c72009-03-26 23:46:50 +0000692static const char *getAccessName(AccessSpecifier AS) {
693 switch (AS) {
694 default:
695 case AS_none:
696 assert("Invalid access specifier!");
697 return 0;
698 case AS_public:
699 return "public";
700 case AS_private:
701 return "private";
702 case AS_protected:
703 return "protected";
704 }
705}
706
707const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
708 AccessSpecifier AS) {
709 return DB << getAccessName(AS);
710}
711
712