blob: 7a930d78c12365f333dd17b9867b3e2070b11847 [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 Gregor7d7e6722008-11-12 23:21:09 +000027 SourceLocation L, IdentifierInfo *Id)
Douglas Gregor3e00bad2009-02-17 01:05:43 +000028 : RecordDecl(K, TK, DC, L, Id),
Douglas Gregor7d7e6722008-11-12 23:21:09 +000029 UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
Sebastian Redl64b45f72009-01-05 20:52:13 +000030 UserDeclaredCopyAssignment(false), UserDeclaredDestructor(false),
Anders Carlsson67e4dd22009-03-22 01:52:17 +000031 Aggregate(true), PlainOldData(true), Polymorphic(false), Abstract(false),
Anders Carlsson072abef2009-04-17 02:34:54 +000032 HasTrivialConstructor(true), HasTrivialDestructor(true),
Douglas Gregord475b8d2009-03-25 21:17:03 +000033 Bases(0), NumBases(0), Conversions(DC, DeclarationName()),
34 TemplateOrInstantiation() { }
Douglas Gregor7d7e6722008-11-12 23:21:09 +000035
Ted Kremenek4b7c9832008-09-05 17:16:31 +000036CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
37 SourceLocation L, IdentifierInfo *Id,
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000038 CXXRecordDecl* PrevDecl,
39 bool DelayTypeCreation) {
Douglas Gregor3e00bad2009-02-17 01:05:43 +000040 CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, L, Id);
Douglas Gregoraafc0cc2009-05-15 19:11:46 +000041 if (!DelayTypeCreation)
42 C.getTypeDeclType(R, PrevDecl);
Ted Kremenek4b7c9832008-09-05 17:16:31 +000043 return R;
44}
45
Douglas Gregorf8268ae2008-10-22 17:49:05 +000046CXXRecordDecl::~CXXRecordDecl() {
Douglas Gregorf8268ae2008-10-22 17:49:05 +000047 delete [] Bases;
48}
49
Douglas Gregor57c856b2008-10-23 18:13:27 +000050void
51CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
52 unsigned NumBases) {
Douglas Gregor64bffa92008-11-05 16:20:31 +000053 // C++ [dcl.init.aggr]p1:
54 // An aggregate is an array or a class (clause 9) with [...]
55 // no base classes [...].
56 Aggregate = false;
57
Douglas Gregor57c856b2008-10-23 18:13:27 +000058 if (this->Bases)
59 delete [] this->Bases;
60
Douglas Gregor2943aed2009-03-03 04:44:36 +000061 // FIXME: allocate using the ASTContext
Douglas Gregor57c856b2008-10-23 18:13:27 +000062 this->Bases = new CXXBaseSpecifier[NumBases];
63 this->NumBases = NumBases;
64 for (unsigned i = 0; i < NumBases; ++i)
65 this->Bases[i] = *Bases[i];
66}
67
Douglas Gregor396b7cd2008-11-03 17:51:48 +000068bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const {
Sebastian Redl64b45f72009-01-05 20:52:13 +000069 QualType ClassType
70 = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this));
Douglas Gregor9e7d9de2008-12-15 21:24:18 +000071 DeclarationName ConstructorName
72 = Context.DeclarationNames.getCXXConstructorName(
73 Context.getCanonicalType(ClassType));
74 unsigned TypeQuals;
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000075 DeclContext::lookup_const_iterator Con, ConEnd;
Douglas Gregor6ab35242009-04-09 21:40:53 +000076 for (llvm::tie(Con, ConEnd) = this->lookup(Context, ConstructorName);
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000077 Con != ConEnd; ++Con) {
Douglas Gregor396b7cd2008-11-03 17:51:48 +000078 if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(Context, TypeQuals) &&
Eli Friedmane8e32052008-12-16 20:06:41 +000079 (TypeQuals & QualType::Const) != 0)
Douglas Gregor396b7cd2008-11-03 17:51:48 +000080 return true;
81 }
Douglas Gregorfdfab6b2008-12-23 21:31:30 +000082
Douglas Gregor396b7cd2008-11-03 17:51:48 +000083 return false;
84}
85
Sebastian Redl64b45f72009-01-05 20:52:13 +000086bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context) const {
87 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
88 const_cast<CXXRecordDecl*>(this)));
89 DeclarationName OpName =Context.DeclarationNames.getCXXOperatorName(OO_Equal);
90
91 DeclContext::lookup_const_iterator Op, OpEnd;
Douglas Gregor6ab35242009-04-09 21:40:53 +000092 for (llvm::tie(Op, OpEnd) = this->lookup(Context, OpName);
Sebastian Redl64b45f72009-01-05 20:52:13 +000093 Op != OpEnd; ++Op) {
94 // C++ [class.copy]p9:
95 // A user-declared copy assignment operator is a non-static non-template
96 // member function of class X with exactly one parameter of type X, X&,
97 // const X&, volatile X& or const volatile X&.
98 const CXXMethodDecl* Method = cast<CXXMethodDecl>(*Op);
99 if (Method->isStatic())
100 continue;
101 // TODO: Skip templates? Or is this implicitly done due to parameter types?
Douglas Gregor72564e72009-02-26 23:50:07 +0000102 const FunctionProtoType *FnType =
103 Method->getType()->getAsFunctionProtoType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000104 assert(FnType && "Overloaded operator has no prototype.");
105 // Don't assert on this; an invalid decl might have been left in the AST.
106 if (FnType->getNumArgs() != 1 || FnType->isVariadic())
107 continue;
108 bool AcceptsConst = true;
109 QualType ArgType = FnType->getArgType(0);
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000110 if (const LValueReferenceType *Ref = ArgType->getAsLValueReferenceType()) {
Sebastian Redl64b45f72009-01-05 20:52:13 +0000111 ArgType = Ref->getPointeeType();
Douglas Gregor2ff44782009-03-20 20:21:37 +0000112 // Is it a non-const lvalue reference?
Sebastian Redl64b45f72009-01-05 20:52:13 +0000113 if (!ArgType.isConstQualified())
114 AcceptsConst = false;
115 }
116 if (Context.getCanonicalType(ArgType).getUnqualifiedType() != ClassType)
117 continue;
118
119 // We have a single argument of type cv X or cv X&, i.e. we've found the
120 // copy assignment operator. Return whether it accepts const arguments.
121 return AcceptsConst;
122 }
123 assert(isInvalidDecl() &&
124 "No copy assignment operator declared in valid code.");
125 return false;
126}
127
128void
Douglas Gregor9e7d9de2008-12-15 21:24:18 +0000129CXXRecordDecl::addedConstructor(ASTContext &Context,
130 CXXConstructorDecl *ConDecl) {
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000131 assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl");
132 // Note that we have a user-declared constructor.
133 UserDeclaredConstructor = true;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000134
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000135 // C++ [dcl.init.aggr]p1:
136 // An aggregate is an array or a class (clause 9) with no
137 // user-declared constructors (12.1) [...].
138 Aggregate = false;
Douglas Gregor64bffa92008-11-05 16:20:31 +0000139
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000140 // C++ [class]p4:
141 // A POD-struct is an aggregate class [...]
142 PlainOldData = false;
Sebastian Redl64b45f72009-01-05 20:52:13 +0000143
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000144 // C++ [class.ctor]p5:
145 // A constructor is trivial if it is an implicitly-declared default
146 // constructor.
147 HasTrivialConstructor = false;
Anders Carlsson347ba892009-04-16 00:08:20 +0000148
Fariborz Jahanian8bc3fa42009-06-17 22:44:31 +0000149 // Note when we have a user-declared copy constructor, which will
150 // suppress the implicit declaration of a copy constructor.
151 if (ConDecl->isCopyConstructor(Context))
152 UserDeclaredCopyConstructor = true;
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000153}
154
Sebastian Redl64b45f72009-01-05 20:52:13 +0000155void CXXRecordDecl::addedAssignmentOperator(ASTContext &Context,
156 CXXMethodDecl *OpDecl) {
157 // We're interested specifically in copy assignment operators.
Douglas Gregor72564e72009-02-26 23:50:07 +0000158 const FunctionProtoType *FnType = OpDecl->getType()->getAsFunctionProtoType();
Sebastian Redl64b45f72009-01-05 20:52:13 +0000159 assert(FnType && "Overloaded operator has no proto function type.");
160 assert(FnType->getNumArgs() == 1 && !FnType->isVariadic());
161 QualType ArgType = FnType->getArgType(0);
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000162 if (const LValueReferenceType *Ref = ArgType->getAsLValueReferenceType())
Sebastian Redl64b45f72009-01-05 20:52:13 +0000163 ArgType = Ref->getPointeeType();
164
165 ArgType = ArgType.getUnqualifiedType();
166 QualType ClassType = Context.getCanonicalType(Context.getTypeDeclType(
167 const_cast<CXXRecordDecl*>(this)));
168
169 if (ClassType != Context.getCanonicalType(ArgType))
170 return;
171
172 // This is a copy assignment operator.
173 // Suppress the implicit declaration of a copy constructor.
174 UserDeclaredCopyAssignment = true;
175
176 // C++ [class]p4:
177 // A POD-struct is an aggregate class that [...] has no user-defined copy
178 // assignment operator [...].
179 PlainOldData = false;
180}
181
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000182void CXXRecordDecl::addConversionFunction(ASTContext &Context,
183 CXXConversionDecl *ConvDecl) {
184 Conversions.addOverload(ConvDecl);
185}
186
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000187
188CXXConstructorDecl *
189CXXRecordDecl::getDefaultConstructor(ASTContext &Context) {
190 QualType ClassType = Context.getTypeDeclType(this);
191 DeclarationName ConstructorName
192 = Context.DeclarationNames.getCXXConstructorName(
193 Context.getCanonicalType(ClassType.getUnqualifiedType()));
194
195 DeclContext::lookup_const_iterator Con, ConEnd;
196 for (llvm::tie(Con, ConEnd) = lookup(Context, ConstructorName);
197 Con != ConEnd; ++Con) {
198 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
199 if (Constructor->isDefaultConstructor())
200 return Constructor;
201 }
202 return 0;
203}
204
Anders Carlsson7267c162009-05-29 21:03:38 +0000205const CXXDestructorDecl *
206CXXRecordDecl::getDestructor(ASTContext &Context) {
207 QualType ClassType = Context.getTypeDeclType(this);
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +0000208
Anders Carlsson7267c162009-05-29 21:03:38 +0000209 DeclarationName Name
210 = Context.DeclarationNames.getCXXDestructorName(ClassType);
211
212 DeclContext::lookup_iterator I, E;
213 llvm::tie(I, E) = lookup(Context, Name);
214 assert(I != E && "Did not find a destructor!");
215
216 const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I);
217 assert(++I == E && "Found more than one destructor!");
218
219 return Dtor;
220}
221
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000222CXXMethodDecl *
223CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor10bd3682008-11-17 22:58:34 +0000224 SourceLocation L, DeclarationName N,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000225 QualType T, bool isStatic, bool isInline) {
Steve Naroff3e970492009-01-27 21:25:57 +0000226 return new (C) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000227}
228
Anders Carlsson05eb2442009-05-16 23:58:37 +0000229
230typedef llvm::DenseMap<const CXXMethodDecl*,
231 std::vector<const CXXMethodDecl *> *>
232 OverriddenMethodsMapTy;
233
234static OverriddenMethodsMapTy *OverriddenMethods = 0;
235
236void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
237 // FIXME: The CXXMethodDecl dtor needs to remove and free the entry.
238
239 if (!OverriddenMethods)
240 OverriddenMethods = new OverriddenMethodsMapTy();
241
242 std::vector<const CXXMethodDecl *> *&Methods = (*OverriddenMethods)[this];
243 if (!Methods)
244 Methods = new std::vector<const CXXMethodDecl *>;
245
246 Methods->push_back(MD);
247}
248
249CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
250 if (!OverriddenMethods)
251 return 0;
252
253 OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
254 if (it == OverriddenMethods->end())
255 return 0;
256 return &(*it->second)[0];
257}
258
259CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
260 if (!OverriddenMethods)
261 return 0;
262
263 OverriddenMethodsMapTy::iterator it = OverriddenMethods->find(this);
264 if (it == OverriddenMethods->end())
265 return 0;
266
267 return &(*it->second)[it->second->size()];
268}
269
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000270QualType CXXMethodDecl::getThisType(ASTContext &C) const {
Argyrios Kyrtzidisb0d178d2008-10-24 22:28:18 +0000271 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
272 // If the member function is declared const, the type of this is const X*,
273 // if the member function is declared volatile, the type of this is
274 // volatile X*, and if the member function is declared const volatile,
275 // the type of this is const volatile X*.
276
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000277 assert(isInstance() && "No 'this' for static methods!");
Anders Carlsson31a08752009-06-13 02:59:33 +0000278
279 QualType ClassTy;
280 if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate())
281 ClassTy = TD->getInjectedClassNameType(C);
282 else
283 ClassTy = C.getTagDeclType(const_cast<CXXRecordDecl*>(getParent()));
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +0000284 ClassTy = ClassTy.getWithAdditionalQualifiers(getTypeQualifiers());
285 return C.getPointerType(ClassTy).withConst();
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000286}
287
Douglas Gregor7ad83902008-11-05 04:29:56 +0000288CXXBaseOrMemberInitializer::
289CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs)
290 : Args(0), NumArgs(0) {
291 BaseOrMember = reinterpret_cast<uintptr_t>(BaseType.getTypePtr());
292 assert((BaseOrMember & 0x01) == 0 && "Invalid base class type pointer");
293 BaseOrMember |= 0x01;
294
295 if (NumArgs > 0) {
296 this->NumArgs = NumArgs;
297 this->Args = new Expr*[NumArgs];
298 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
299 this->Args[Idx] = Args[Idx];
300 }
301}
302
303CXXBaseOrMemberInitializer::
Douglas Gregor44b43212008-12-11 16:49:14 +0000304CXXBaseOrMemberInitializer(FieldDecl *Member, Expr **Args, unsigned NumArgs)
Douglas Gregor7ad83902008-11-05 04:29:56 +0000305 : Args(0), NumArgs(0) {
306 BaseOrMember = reinterpret_cast<uintptr_t>(Member);
307 assert((BaseOrMember & 0x01) == 0 && "Invalid member pointer");
308
309 if (NumArgs > 0) {
310 this->NumArgs = NumArgs;
311 this->Args = new Expr*[NumArgs];
312 for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
313 this->Args[Idx] = Args[Idx];
314 }
315}
316
317CXXBaseOrMemberInitializer::~CXXBaseOrMemberInitializer() {
318 delete [] Args;
319}
320
Douglas Gregorb48fe382008-10-31 09:07:45 +0000321CXXConstructorDecl *
322CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000323 SourceLocation L, DeclarationName N,
Douglas Gregorb48fe382008-10-31 09:07:45 +0000324 QualType T, bool isExplicit,
325 bool isInline, bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000326 assert(N.getNameKind() == DeclarationName::CXXConstructorName &&
327 "Name must refer to a constructor");
Steve Naroff3e970492009-01-27 21:25:57 +0000328 return new (C) CXXConstructorDecl(RD, L, N, T, isExplicit, isInline,
Douglas Gregorb48fe382008-10-31 09:07:45 +0000329 isImplicitlyDeclared);
330}
331
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000332bool CXXConstructorDecl::isDefaultConstructor() const {
333 // C++ [class.ctor]p5:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000334 // A default constructor for a class X is a constructor of class
335 // X that can be called without an argument.
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000336 return (getNumParams() == 0) ||
Douglas Gregorf03d7c72008-11-05 15:29:30 +0000337 (getNumParams() > 0 && getParamDecl(0)->getDefaultArg() != 0);
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000338}
339
340bool
341CXXConstructorDecl::isCopyConstructor(ASTContext &Context,
342 unsigned &TypeQuals) const {
343 // C++ [class.copy]p2:
Douglas Gregor64bffa92008-11-05 16:20:31 +0000344 // A non-template constructor for class X is a copy constructor
345 // if its first parameter is of type X&, const X&, volatile X& or
346 // const volatile X&, and either there are no other parameters
347 // or else all other parameters have default arguments (8.3.6).
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000348 if ((getNumParams() < 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +0000349 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()))
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000350 return false;
351
352 const ParmVarDecl *Param = getParamDecl(0);
353
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000354 // Do we have a reference type? Rvalue references don't count.
355 const LValueReferenceType *ParamRefType =
356 Param->getType()->getAsLValueReferenceType();
Douglas Gregor030ff0c2008-10-31 20:25:05 +0000357 if (!ParamRefType)
358 return false;
359
360 // Is it a reference to our class type?
361 QualType PointeeType
362 = Context.getCanonicalType(ParamRefType->getPointeeType());
363 QualType ClassTy
364 = Context.getTagDeclType(const_cast<CXXRecordDecl*>(getParent()));
365 if (PointeeType.getUnqualifiedType() != ClassTy)
366 return false;
367
368 // We have a copy constructor.
369 TypeQuals = PointeeType.getCVRQualifiers();
370 return true;
371}
372
Douglas Gregor60d62c22008-10-31 16:23:19 +0000373bool CXXConstructorDecl::isConvertingConstructor() const {
374 // C++ [class.conv.ctor]p1:
375 // A constructor declared without the function-specifier explicit
376 // that can be called with a single parameter specifies a
377 // conversion from the type of its first parameter to the type of
378 // its class. Such a constructor is called a converting
379 // constructor.
380 if (isExplicit())
381 return false;
382
383 return (getNumParams() == 0 &&
Douglas Gregor72564e72009-02-26 23:50:07 +0000384 getType()->getAsFunctionProtoType()->isVariadic()) ||
Douglas Gregor60d62c22008-10-31 16:23:19 +0000385 (getNumParams() == 1) ||
Anders Carlssonae0b4e72009-06-06 04:14:07 +0000386 (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
Douglas Gregor60d62c22008-10-31 16:23:19 +0000387}
Douglas Gregorb48fe382008-10-31 09:07:45 +0000388
Douglas Gregor42a552f2008-11-05 20:51:48 +0000389CXXDestructorDecl *
390CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000391 SourceLocation L, DeclarationName N,
Douglas Gregor42a552f2008-11-05 20:51:48 +0000392 QualType T, bool isInline,
393 bool isImplicitlyDeclared) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000394 assert(N.getNameKind() == DeclarationName::CXXDestructorName &&
395 "Name must refer to a destructor");
Steve Naroff3e970492009-01-27 21:25:57 +0000396 return new (C) CXXDestructorDecl(RD, L, N, T, isInline,
397 isImplicitlyDeclared);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000398}
399
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000400CXXConversionDecl *
401CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000402 SourceLocation L, DeclarationName N,
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000403 QualType T, bool isInline, bool isExplicit) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000404 assert(N.getNameKind() == DeclarationName::CXXConversionFunctionName &&
405 "Name must refer to a conversion function");
Steve Naroff3e970492009-01-27 21:25:57 +0000406 return new (C) CXXConversionDecl(RD, L, N, T, isInline, isExplicit);
Douglas Gregor2f1bc522008-11-07 20:08:42 +0000407}
408
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000409OverloadedFunctionDecl *
410OverloadedFunctionDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000411 DeclarationName N) {
Steve Naroff3e970492009-01-27 21:25:57 +0000412 return new (C) OverloadedFunctionDecl(DC, N);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000413}
Chris Lattner21ef7ae2008-11-04 16:51:42 +0000414
415LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
Douglas Gregor074149e2009-01-05 19:45:36 +0000416 DeclContext *DC,
Chris Lattner21ef7ae2008-11-04 16:51:42 +0000417 SourceLocation L,
Douglas Gregor074149e2009-01-05 19:45:36 +0000418 LanguageIDs Lang, bool Braces) {
Steve Naroff3e970492009-01-27 21:25:57 +0000419 return new (C) LinkageSpecDecl(DC, L, Lang, Braces);
Douglas Gregorf44515a2008-12-16 22:23:02 +0000420}
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000421
422UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
423 SourceLocation L,
424 SourceLocation NamespaceLoc,
Douglas Gregor8419fa32009-05-30 06:31:56 +0000425 SourceRange QualifierRange,
426 NestedNameSpecifier *Qualifier,
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000427 SourceLocation IdentLoc,
428 NamespaceDecl *Used,
429 DeclContext *CommonAncestor) {
Douglas Gregor8419fa32009-05-30 06:31:56 +0000430 return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange,
431 Qualifier, IdentLoc, Used, CommonAncestor);
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000432}
433
Anders Carlsson68771c72009-03-28 22:58:02 +0000434NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
435 SourceLocation L,
436 SourceLocation AliasLoc,
437 IdentifierInfo *Alias,
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000438 SourceRange QualifierRange,
439 NestedNameSpecifier *Qualifier,
Anders Carlsson68771c72009-03-28 22:58:02 +0000440 SourceLocation IdentLoc,
441 NamedDecl *Namespace) {
Douglas Gregor6c9c9402009-05-30 06:48:27 +0000442 return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange,
443 Qualifier, IdentLoc, Namespace);
Anders Carlsson68771c72009-03-28 22:58:02 +0000444}
445
Douglas Gregor9cfbe482009-06-20 00:51:54 +0000446UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC,
447 SourceLocation L, SourceRange NNR, SourceLocation TargetNL,
448 SourceLocation UL, NamedDecl* Target,
449 NestedNameSpecifier* TargetNNS, bool IsTypeNameArg) {
450 return new (C) UsingDecl(DC, L, NNR, TargetNL, UL, Target,
451 TargetNNS, IsTypeNameArg);
452}
453
Anders Carlssonfb311762009-03-14 00:25:26 +0000454StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
455 SourceLocation L, Expr *AssertExpr,
456 StringLiteral *Message) {
457 return new (C) StaticAssertDecl(DC, L, AssertExpr, Message);
458}
459
460void StaticAssertDecl::Destroy(ASTContext& C) {
461 AssertExpr->Destroy(C);
462 Message->Destroy(C);
463 this->~StaticAssertDecl();
464 C.Deallocate((void *)this);
465}
466
467StaticAssertDecl::~StaticAssertDecl() {
468}
469
Anders Carlsson05bf2c72009-03-26 23:46:50 +0000470static const char *getAccessName(AccessSpecifier AS) {
471 switch (AS) {
472 default:
473 case AS_none:
474 assert("Invalid access specifier!");
475 return 0;
476 case AS_public:
477 return "public";
478 case AS_private:
479 return "private";
480 case AS_protected:
481 return "protected";
482 }
483}
484
485const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
486 AccessSpecifier AS) {
487 return DB << getAccessName(AS);
488}
489
490