blob: 402d7b532b2193899be9635b2b28b66e10711bed [file] [log] [blame]
Ted Kremeneka758d092007-08-24 20:21:10 +00001//===--- ExprCXX.cpp - (C++) Expression AST Node Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremeneka758d092007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer471c8b42012-07-04 20:19:54 +000014#include "clang/AST/ASTContext.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000015#include "clang/AST/Attr.h"
Douglas Gregorb4609802008-11-14 16:09:21 +000016#include "clang/AST/DeclCXX.h"
Douglas Gregoredce4dd2009-06-30 22:34:41 +000017#include "clang/AST/DeclTemplate.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000018#include "clang/AST/ExprCXX.h"
Douglas Gregor26d4ac92010-02-24 23:40:28 +000019#include "clang/AST/TypeLoc.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000020#include "clang/Basic/IdentifierTable.h"
Ted Kremeneka758d092007-08-24 20:21:10 +000021using namespace clang;
22
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000023
Ted Kremeneka758d092007-08-24 20:21:10 +000024//===----------------------------------------------------------------------===//
25// Child Iterators for iterating over subexpressions/substatements
26//===----------------------------------------------------------------------===//
27
Richard Smith0d729102012-08-13 20:08:14 +000028bool CXXTypeidExpr::isPotentiallyEvaluated() const {
29 if (isTypeOperand())
30 return false;
31
32 // C++11 [expr.typeid]p3:
33 // When typeid is applied to an expression other than a glvalue of
34 // polymorphic class type, [...] the expression is an unevaluated operand.
35 const Expr *E = getExprOperand();
36 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
37 if (RD->isPolymorphic() && E->isGLValue())
38 return true;
39
40 return false;
41}
42
Douglas Gregor57fdc8a2010-04-26 22:37:10 +000043QualType CXXTypeidExpr::getTypeOperand() const {
44 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
45 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
46 .getUnqualifiedType();
47}
48
Francois Pichet01b7c302010-09-08 12:20:18 +000049QualType CXXUuidofExpr::getTypeOperand() const {
50 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
51 return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType()
52 .getUnqualifiedType();
53}
54
Nico Weberc5f80462012-10-11 10:13:44 +000055// static
56UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT) {
57 // Optionally remove one level of pointer, reference or array indirection.
58 const Type *Ty = QT.getTypePtr();
59 if (QT->isPointerType() || QT->isReferenceType())
60 Ty = QT->getPointeeType().getTypePtr();
61 else if (QT->isArrayType())
62 Ty = cast<ArrayType>(QT)->getElementType().getTypePtr();
63
64 // Loop all record redeclaration looking for an uuid attribute.
65 CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
66 for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(),
67 E = RD->redecls_end(); I != E; ++I) {
68 if (UuidAttr *Uuid = I->getAttr<UuidAttr>())
69 return Uuid;
70 }
71
72 return 0;
73}
74
Douglas Gregored8abf12010-07-08 06:14:04 +000075// CXXScalarValueInitExpr
Erik Verbruggen65d78312012-12-25 14:51:39 +000076SourceLocation CXXScalarValueInitExpr::getLocStart() const {
77 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc;
Douglas Gregorab6677e2010-09-08 00:15:04 +000078}
79
Sebastian Redl4c5d3202008-11-21 19:14:01 +000080// CXXNewExpr
Ted Kremenekad7fe862010-02-11 22:51:03 +000081CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
Sebastian Redl1548d142012-02-16 11:35:52 +000082 FunctionDecl *operatorDelete,
Sebastian Redl2aed8b82012-02-16 12:22:20 +000083 bool usualArrayDeleteWantsSize,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +000084 ArrayRef<Expr*> placementArgs,
Sebastian Redl2aed8b82012-02-16 12:22:20 +000085 SourceRange typeIdParens, Expr *arraySize,
86 InitializationStyle initializationStyle,
87 Expr *initializer, QualType ty,
88 TypeSourceInfo *allocatedTypeInfo,
David Blaikie53056412012-11-07 00:12:38 +000089 SourceRange Range, SourceRange directInitRange)
John McCallf89e55a2010-11-18 06:31:45 +000090 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000091 ty->isDependentType(), ty->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +000092 ty->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +000093 ty->containsUnexpandedParameterPack()),
Sebastian Redl2aed8b82012-02-16 12:22:20 +000094 SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
95 AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
David Blaikie53056412012-11-07 00:12:38 +000096 Range(Range), DirectInitRange(directInitRange),
Benjamin Kramerd162cf12012-02-26 20:37:14 +000097 GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
Sebastian Redl2aed8b82012-02-16 12:22:20 +000098 assert((initializer != 0 || initializationStyle == NoInit) &&
99 "Only NoInit can have no initializer.");
100 StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000101 AllocateArgsArray(C, arraySize != 0, placementArgs.size(), initializer != 0);
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000102 unsigned i = 0;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000103 if (Array) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000104 if (arraySize->isInstantiationDependent())
105 ExprBits.InstantiationDependent = true;
106
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000107 if (arraySize->containsUnexpandedParameterPack())
108 ExprBits.ContainsUnexpandedParameterPack = true;
109
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000110 SubExprs[i++] = arraySize;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000111 }
112
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000113 if (initializer) {
114 if (initializer->isInstantiationDependent())
115 ExprBits.InstantiationDependent = true;
116
117 if (initializer->containsUnexpandedParameterPack())
118 ExprBits.ContainsUnexpandedParameterPack = true;
119
120 SubExprs[i++] = initializer;
121 }
122
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000123 for (unsigned j = 0; j != placementArgs.size(); ++j) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000124 if (placementArgs[j]->isInstantiationDependent())
125 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000126 if (placementArgs[j]->containsUnexpandedParameterPack())
127 ExprBits.ContainsUnexpandedParameterPack = true;
128
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000129 SubExprs[i++] = placementArgs[j];
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000130 }
David Blaikiec2fc67e2012-11-08 22:53:48 +0000131
132 switch (getInitializationStyle()) {
133 case CallInit:
134 this->Range.setEnd(DirectInitRange.getEnd()); break;
135 case ListInit:
136 this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
137 default: break;
138 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000139}
140
Chris Lattner59218632010-05-10 01:22:27 +0000141void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000142 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattner59218632010-05-10 01:22:27 +0000143 assert(SubExprs == 0 && "SubExprs already allocated");
144 Array = isArray;
145 NumPlacementArgs = numPlaceArgs;
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000146
147 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattner59218632010-05-10 01:22:27 +0000148 SubExprs = new (C) Stmt*[TotalSize];
149}
150
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000151bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCallc2f3e7f2011-03-07 03:12:35 +0000152 return getOperatorNew()->getType()->
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000153 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCallc2f3e7f2011-03-07 03:12:35 +0000154}
Chris Lattner59218632010-05-10 01:22:27 +0000155
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000156// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000157QualType CXXDeleteExpr::getDestroyedType() const {
158 const Expr *Arg = getArgument();
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000159 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000160 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000161
162 if (ArgType->isDependentType() && !ArgType->isPointerType())
163 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000164
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000165 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000166}
167
Douglas Gregora71d8192009-09-04 17:36:40 +0000168// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000169PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
170 : Type(Info)
171{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000172 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000173}
174
John McCalle23cf432010-12-14 08:05:40 +0000175CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000176 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
177 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
178 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
179 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000180 : Expr(CXXPseudoDestructorExprClass,
Dmitri Gribenko55431692013-05-05 00:41:58 +0000181 Context.getPointerType(Context.getFunctionType(Context.VoidTy, None,
John McCalle23cf432010-12-14 08:05:40 +0000182 FunctionProtoType::ExtProtoInfo())),
183 VK_RValue, OK_Ordinary,
184 /*isTypeDependent=*/(Base->isTypeDependent() ||
185 (DestroyedType.getTypeSourceInfo() &&
186 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000187 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000188 (Base->isInstantiationDependent() ||
189 (QualifierLoc &&
190 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
191 (ScopeType &&
192 ScopeType->getType()->isInstantiationDependentType()) ||
193 (DestroyedType.getTypeSourceInfo() &&
194 DestroyedType.getTypeSourceInfo()->getType()
195 ->isInstantiationDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000196 // ContainsUnexpandedParameterPack
197 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000198 (QualifierLoc &&
199 QualifierLoc.getNestedNameSpecifier()
200 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000201 (ScopeType &&
202 ScopeType->getType()->containsUnexpandedParameterPack()) ||
203 (DestroyedType.getTypeSourceInfo() &&
204 DestroyedType.getTypeSourceInfo()->getType()
205 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000206 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000207 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000208 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
209 DestroyedType(DestroyedType) { }
210
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000211QualType CXXPseudoDestructorExpr::getDestroyedType() const {
212 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
213 return TInfo->getType();
214
215 return QualType();
216}
217
Erik Verbruggen65d78312012-12-25 14:51:39 +0000218SourceLocation CXXPseudoDestructorExpr::getLocEnd() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000219 SourceLocation End = DestroyedType.getLocation();
220 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000221 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Erik Verbruggen65d78312012-12-25 14:51:39 +0000222 return End;
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000223}
224
John McCallba135432009-11-21 08:51:07 +0000225// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000226UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000227UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000228 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000229 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000230 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000231 const DeclarationNameInfo &NameInfo,
232 bool ADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000233 const TemplateArgumentListInfo *Args,
234 UnresolvedSetIterator Begin,
235 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000236{
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000237 assert(Args || TemplateKWLoc.isValid());
238 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000239 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000240 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000241 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
242 TemplateKWLoc, NameInfo,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000243 ADL, /*Overload*/ true, Args,
Richard Smithb1502bc2012-10-18 17:56:02 +0000244 Begin, End);
John McCallf7a1a742009-11-24 19:00:30 +0000245}
246
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000247UnresolvedLookupExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000248UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
249 bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +0000250 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000251 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000252 if (HasTemplateKWAndArgsInfo)
253 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000254
Chris Lattner32488542010-10-30 05:14:06 +0000255 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000256 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000257 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000258 return E;
259}
260
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000261OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000262 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000263 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000264 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000265 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000266 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000267 UnresolvedSetIterator End,
268 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000269 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000270 bool KnownContainsUnexpandedParameterPack)
271 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
272 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000273 (KnownInstantiationDependent ||
274 NameInfo.isInstantiationDependent() ||
275 (QualifierLoc &&
276 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000277 (KnownContainsUnexpandedParameterPack ||
278 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000279 (QualifierLoc &&
280 QualifierLoc.getNestedNameSpecifier()
281 ->containsUnexpandedParameterPack()))),
Benjamin Kramerd162cf12012-02-26 20:37:14 +0000282 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
283 Results(0), NumResults(End - Begin),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000284 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000285{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000286 NumResults = End - Begin;
287 if (NumResults) {
288 // Determine whether this expression is type-dependent.
289 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
290 if ((*I)->getDeclContext()->isDependentContext() ||
291 isa<UnresolvedUsingValueDecl>(*I)) {
292 ExprBits.TypeDependent = true;
293 ExprBits.ValueDependent = true;
Richard Smith7657fd72012-08-13 21:29:18 +0000294 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000295 }
296 }
297
298 Results = static_cast<DeclAccessPair *>(
299 C.Allocate(sizeof(DeclAccessPair) * NumResults,
300 llvm::alignOf<DeclAccessPair>()));
301 memcpy(Results, &*Begin.getIterator(),
302 NumResults * sizeof(DeclAccessPair));
303 }
304
305 // If we have explicit template arguments, check for dependent
306 // template arguments and whether they contain any unexpanded pack
307 // expansions.
308 if (TemplateArgs) {
309 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000310 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000311 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000312 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
313 Dependent,
314 InstantiationDependent,
315 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000316
317 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000318 ExprBits.TypeDependent = true;
319 ExprBits.ValueDependent = true;
320 }
321 if (InstantiationDependent)
322 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000323 if (ContainsUnexpandedParameterPack)
324 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000325 } else if (TemplateKWLoc.isValid()) {
326 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000327 }
328
329 if (isTypeDependent())
330 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000331}
332
333void OverloadExpr::initializeResults(ASTContext &C,
334 UnresolvedSetIterator Begin,
335 UnresolvedSetIterator End) {
336 assert(Results == 0 && "Results already initialized!");
337 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000338 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000339 Results = static_cast<DeclAccessPair *>(
340 C.Allocate(sizeof(DeclAccessPair) * NumResults,
341
342 llvm::alignOf<DeclAccessPair>()));
343 memcpy(Results, &*Begin.getIterator(),
344 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000345 }
346}
347
John McCalle9ee23e2010-04-22 18:44:12 +0000348CXXRecordDecl *OverloadExpr::getNamingClass() const {
349 if (isa<UnresolvedLookupExpr>(this))
350 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
351 else
352 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
353}
354
John McCall865d4472009-11-19 22:55:06 +0000355// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000356DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000357 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000358 SourceLocation TemplateKWLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000359 const DeclarationNameInfo &NameInfo,
360 const TemplateArgumentListInfo *Args)
361 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
362 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000363 (NameInfo.isInstantiationDependent() ||
364 (QualifierLoc &&
365 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000366 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000367 (QualifierLoc &&
368 QualifierLoc.getNestedNameSpecifier()
369 ->containsUnexpandedParameterPack()))),
370 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000371 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000372{
373 if (Args) {
374 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000375 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000376 bool ContainsUnexpandedParameterPack
377 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000378 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
379 Dependent,
380 InstantiationDependent,
381 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000382 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000383 } else if (TemplateKWLoc.isValid()) {
384 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000385 }
386}
387
John McCallf7a1a742009-11-24 19:00:30 +0000388DependentScopeDeclRefExpr *
389DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000390 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000391 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000392 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000393 const TemplateArgumentListInfo *Args) {
394 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000395 if (Args)
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000396 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
397 else if (TemplateKWLoc.isValid())
398 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000399 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000400 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
401 TemplateKWLoc, NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000402}
403
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000404DependentScopeDeclRefExpr *
405DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000406 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000407 unsigned NumTemplateArgs) {
408 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000409 if (HasTemplateKWAndArgsInfo)
410 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000411 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000412 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000413 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000414 SourceLocation(),
Douglas Gregordef03542011-02-04 12:01:24 +0000415 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000416 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregordef03542011-02-04 12:01:24 +0000417 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000418}
419
Erik Verbruggen65d78312012-12-25 14:51:39 +0000420SourceLocation CXXConstructExpr::getLocStart() const {
John McCall2882eca2011-02-21 06:23:05 +0000421 if (isa<CXXTemporaryObjectExpr>(this))
Erik Verbruggen65d78312012-12-25 14:51:39 +0000422 return cast<CXXTemporaryObjectExpr>(this)->getLocStart();
423 return Loc;
424}
425
426SourceLocation CXXConstructExpr::getLocEnd() const {
427 if (isa<CXXTemporaryObjectExpr>(this))
428 return cast<CXXTemporaryObjectExpr>(this)->getLocEnd();
John McCall2882eca2011-02-21 06:23:05 +0000429
Douglas Gregor40749ee2010-11-03 00:35:38 +0000430 if (ParenRange.isValid())
Erik Verbruggen65d78312012-12-25 14:51:39 +0000431 return ParenRange.getEnd();
Douglas Gregor40749ee2010-11-03 00:35:38 +0000432
433 SourceLocation End = Loc;
434 for (unsigned I = getNumArgs(); I > 0; --I) {
435 const Expr *Arg = getArg(I-1);
436 if (!Arg->isDefaultArgument()) {
437 SourceLocation NewEnd = Arg->getLocEnd();
438 if (NewEnd.isValid()) {
439 End = NewEnd;
440 break;
441 }
442 }
443 }
444
Erik Verbruggen65d78312012-12-25 14:51:39 +0000445 return End;
Ted Kremeneke3837682009-12-23 04:00:48 +0000446}
447
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000448SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregorb4609802008-11-14 16:09:21 +0000449 OverloadedOperatorKind Kind = getOperator();
450 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
451 if (getNumArgs() == 1)
452 // Prefix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000453 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000454 else
455 // Postfix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000456 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000457 } else if (Kind == OO_Arrow) {
458 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000459 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000460 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000461 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000462 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000463 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000464 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000465 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000466 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000467 } else {
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000468 return getOperatorLoc();
Douglas Gregorb4609802008-11-14 16:09:21 +0000469 }
470}
471
Ted Kremenekb2771592011-03-30 17:41:19 +0000472Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose51e87c52012-08-03 23:08:39 +0000473 const Expr *Callee = getCallee()->IgnoreParens();
474 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor88a35142008-12-22 05:46:06 +0000475 return MemExpr->getBase();
Jordan Rose51e87c52012-08-03 23:08:39 +0000476 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
477 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
478 return BO->getLHS();
Douglas Gregor88a35142008-12-22 05:46:06 +0000479
480 // FIXME: Will eventually need to cope with member pointers.
481 return 0;
482}
483
Ted Kremenekb2771592011-03-30 17:41:19 +0000484CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
485 if (const MemberExpr *MemExpr =
486 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
487 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
488
489 // FIXME: Will eventually need to cope with member pointers.
490 return 0;
491}
492
493
David Blaikie0cf3c0e2012-05-03 16:25:49 +0000494CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth007a9b12010-10-27 06:55:41 +0000495 Expr* ThisArg = getImplicitObjectArgument();
496 if (!ThisArg)
497 return 0;
498
499 if (ThisArg->getType()->isAnyPointerType())
500 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
501
502 return ThisArg->getType()->getAsCXXRecordDecl();
503}
504
Douglas Gregor00b98c22009-11-12 15:31:47 +0000505
Douglas Gregor49badde2008-10-27 19:41:14 +0000506//===----------------------------------------------------------------------===//
507// Named casts
508//===----------------------------------------------------------------------===//
509
510/// getCastName - Get the name of the C++ cast being used, e.g.,
511/// "static_cast", "dynamic_cast", "reinterpret_cast", or
512/// "const_cast". The returned pointer must not be freed.
513const char *CXXNamedCastExpr::getCastName() const {
514 switch (getStmtClass()) {
515 case CXXStaticCastExprClass: return "static_cast";
516 case CXXDynamicCastExprClass: return "dynamic_cast";
517 case CXXReinterpretCastExprClass: return "reinterpret_cast";
518 case CXXConstCastExprClass: return "const_cast";
519 default: return "<invalid cast>";
520 }
521}
Douglas Gregor506ae412009-01-16 18:33:17 +0000522
John McCallf871d0c2010-08-07 06:22:56 +0000523CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000524 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000525 CastKind K, Expr *Op,
526 const CXXCastPath *BasePath,
527 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000528 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000529 SourceLocation RParenLoc,
530 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000531 unsigned PathSize = (BasePath ? BasePath->size() : 0);
532 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
533 + PathSize * sizeof(CXXBaseSpecifier*));
534 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000535 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000536 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000537 if (PathSize) E->setCastPath(*BasePath);
538 return E;
539}
540
541CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
542 unsigned PathSize) {
543 void *Buffer =
544 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
545 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
546}
547
548CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000549 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000550 CastKind K, Expr *Op,
551 const CXXCastPath *BasePath,
552 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000553 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000554 SourceLocation RParenLoc,
555 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000556 unsigned PathSize = (BasePath ? BasePath->size() : 0);
557 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
558 + PathSize * sizeof(CXXBaseSpecifier*));
559 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000560 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000561 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000562 if (PathSize) E->setCastPath(*BasePath);
563 return E;
564}
565
566CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
567 unsigned PathSize) {
568 void *Buffer =
569 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
570 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
571}
572
Anders Carlsson0fee3302011-04-11 01:43:55 +0000573/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
574/// to always be null. For example:
575///
576/// struct A { };
577/// struct B final : A { };
578/// struct C { };
579///
580/// C *f(B* b) { return dynamic_cast<C*>(b); }
581bool CXXDynamicCastExpr::isAlwaysNull() const
582{
583 QualType SrcType = getSubExpr()->getType();
584 QualType DestType = getType();
585
586 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
587 SrcType = SrcPTy->getPointeeType();
588 DestType = DestType->castAs<PointerType>()->getPointeeType();
589 }
590
Sean Hunt5ca86392012-06-19 23:44:55 +0000591 if (DestType->isVoidType())
592 return false;
593
Anders Carlsson0fee3302011-04-11 01:43:55 +0000594 const CXXRecordDecl *SrcRD =
595 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
596
Jakob Stoklund Olesen35329362012-06-19 21:48:43 +0000597 if (!SrcRD->hasAttr<FinalAttr>())
598 return false;
599
Anders Carlsson0fee3302011-04-11 01:43:55 +0000600 const CXXRecordDecl *DestRD =
601 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
602
603 return !DestRD->isDerivedFrom(SrcRD);
604}
605
John McCallf871d0c2010-08-07 06:22:56 +0000606CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000607CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
608 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000609 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000610 TypeSourceInfo *WrittenTy, SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000611 SourceLocation RParenLoc,
612 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000613 unsigned PathSize = (BasePath ? BasePath->size() : 0);
614 void *Buffer =
615 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
616 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000617 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000618 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000619 if (PathSize) E->setCastPath(*BasePath);
620 return E;
621}
622
623CXXReinterpretCastExpr *
624CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
625 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
626 + PathSize * sizeof(CXXBaseSpecifier*));
627 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
628}
629
John McCallf89e55a2010-11-18 06:31:45 +0000630CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
631 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000632 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000633 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000634 SourceLocation RParenLoc,
635 SourceRange AngleBrackets) {
636 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000637}
638
639CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
640 return new (C) CXXConstCastExpr(EmptyShell());
641}
642
643CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000644CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000645 TypeSourceInfo *Written, SourceLocation L,
646 CastKind K, Expr *Op, const CXXCastPath *BasePath,
647 SourceLocation R) {
648 unsigned PathSize = (BasePath ? BasePath->size() : 0);
649 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
650 + PathSize * sizeof(CXXBaseSpecifier*));
651 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000652 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000653 if (PathSize) E->setCastPath(*BasePath);
654 return E;
655}
656
657CXXFunctionalCastExpr *
658CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
659 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
660 + PathSize * sizeof(CXXBaseSpecifier*));
661 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
662}
663
Richard Smith9fcce652012-03-07 08:35:16 +0000664UserDefinedLiteral::LiteralOperatorKind
665UserDefinedLiteral::getLiteralOperatorKind() const {
666 if (getNumArgs() == 0)
667 return LOK_Template;
668 if (getNumArgs() == 2)
669 return LOK_String;
670
671 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
672 QualType ParamTy =
673 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
674 if (ParamTy->isPointerType())
675 return LOK_Raw;
676 if (ParamTy->isAnyCharacterType())
677 return LOK_Character;
678 if (ParamTy->isIntegerType())
679 return LOK_Integer;
680 if (ParamTy->isFloatingType())
681 return LOK_Floating;
682
683 llvm_unreachable("unknown kind of literal operator");
684}
685
686Expr *UserDefinedLiteral::getCookedLiteral() {
687#ifndef NDEBUG
688 LiteralOperatorKind LOK = getLiteralOperatorKind();
689 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
690#endif
691 return getArg(0);
692}
693
694const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
695 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
696}
John McCallf871d0c2010-08-07 06:22:56 +0000697
Douglas Gregor65222e82009-12-23 18:19:08 +0000698CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000699CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
700 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000701 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000702 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
703 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000704}
705
Richard Smithc3bf52c2013-04-20 22:23:05 +0000706CXXDefaultInitExpr::CXXDefaultInitExpr(ASTContext &C, SourceLocation Loc,
707 FieldDecl *Field, QualType T)
708 : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C),
709 T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType()
710 ? VK_XValue
711 : VK_RValue,
712 /*FIXME*/ OK_Ordinary, false, false, false, false),
713 Field(Field), Loc(Loc) {
714 assert(Field->hasInClassInitializer());
715}
716
Mike Stump1eb44332009-09-09 15:08:12 +0000717CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000718 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000719 return new (C) CXXTemporary(Destructor);
720}
721
Mike Stump1eb44332009-09-09 15:08:12 +0000722CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000723 CXXTemporary *Temp,
724 Expr* SubExpr) {
Peter Collingbournebceb7552011-11-27 22:09:28 +0000725 assert((SubExpr->getType()->isRecordType() ||
726 SubExpr->getType()->isArrayType()) &&
727 "Expression bound to a temporary must have record or array type!");
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000728
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000729 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000730}
731
Anders Carlsson8e587a12009-05-30 20:56:46 +0000732CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000733 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000734 TypeSourceInfo *Type,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000735 ArrayRef<Expr*> Args,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000736 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000737 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +0000738 bool ListInitialization,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000739 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000740 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
741 Type->getType().getNonReferenceType(),
742 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000743 Cons, false, Args,
Richard Smithc83c2302012-12-19 01:39:02 +0000744 HadMultipleCandidates,
745 ListInitialization, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000746 CXXConstructExpr::CK_Complete, parenRange),
747 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000748}
749
Erik Verbruggen65d78312012-12-25 14:51:39 +0000750SourceLocation CXXTemporaryObjectExpr::getLocStart() const {
751 return Type->getTypeLoc().getBeginLoc();
752}
753
754SourceLocation CXXTemporaryObjectExpr::getLocEnd() const {
755 return getParenRange().getEnd();
Douglas Gregor506ae412009-01-16 18:33:17 +0000756}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000757
Mike Stump1eb44332009-09-09 15:08:12 +0000758CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000759 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000760 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000761 ArrayRef<Expr*> Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000762 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000763 bool ListInitialization,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000764 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000765 ConstructionKind ConstructKind,
766 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000767 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000768 Elidable, Args,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000769 HadMultipleCandidates, ListInitialization,
770 ZeroInitialization, ConstructKind,
771 ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000772}
773
Mike Stump1eb44332009-09-09 15:08:12 +0000774CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000775 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000776 CXXConstructorDecl *D, bool elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000777 ArrayRef<Expr*> args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000778 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000779 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000780 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000781 ConstructionKind ConstructKind,
782 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000783 : Expr(SC, T, VK_RValue, OK_Ordinary,
784 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000785 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000786 T->containsUnexpandedParameterPack()),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000787 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000788 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000789 ListInitialization(ListInitialization),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000790 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000791 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000792{
793 if (NumArgs) {
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000794 Args = new (C) Stmt*[args.size()];
Douglas Gregor16006c92009-12-16 18:50:27 +0000795
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000796 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor16006c92009-12-16 18:50:27 +0000797 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000798
799 if (args[i]->isValueDependent())
800 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000801 if (args[i]->isInstantiationDependent())
802 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000803 if (args[i]->containsUnexpandedParameterPack())
804 ExprBits.ContainsUnexpandedParameterPack = true;
805
Douglas Gregor16006c92009-12-16 18:50:27 +0000806 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000807 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000808 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000809}
810
Douglas Gregor01d08012012-02-07 10:09:13 +0000811LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
812 LambdaCaptureKind Kind, VarDecl *Var,
813 SourceLocation EllipsisLoc)
814 : VarAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
815{
816 unsigned Bits = 0;
817 if (Implicit)
818 Bits |= Capture_Implicit;
819
820 switch (Kind) {
821 case LCK_This:
822 assert(Var == 0 && "'this' capture cannot have a variable!");
823 break;
824
825 case LCK_ByCopy:
826 Bits |= Capture_ByCopy;
827 // Fall through
828 case LCK_ByRef:
829 assert(Var && "capture must have a variable!");
830 break;
831 }
832 VarAndBits.setInt(Bits);
833}
834
835LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
836 if (capturesThis())
837 return LCK_This;
838
839 return (VarAndBits.getInt() & Capture_ByCopy)? LCK_ByCopy : LCK_ByRef;
840}
841
842LambdaExpr::LambdaExpr(QualType T,
843 SourceRange IntroducerRange,
844 LambdaCaptureDefault CaptureDefault,
845 ArrayRef<Capture> Captures,
846 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000847 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000848 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000849 ArrayRef<VarDecl *> ArrayIndexVars,
850 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000851 SourceLocation ClosingBrace,
852 bool ContainsUnexpandedParameterPack)
Douglas Gregor01d08012012-02-07 10:09:13 +0000853 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
854 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith612409e2012-07-25 03:56:55 +0000855 ContainsUnexpandedParameterPack),
Douglas Gregor01d08012012-02-07 10:09:13 +0000856 IntroducerRange(IntroducerRange),
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000857 NumCaptures(Captures.size()),
Douglas Gregor01d08012012-02-07 10:09:13 +0000858 CaptureDefault(CaptureDefault),
859 ExplicitParams(ExplicitParams),
Douglas Gregordfca6f52012-02-13 22:00:16 +0000860 ExplicitResultType(ExplicitResultType),
Douglas Gregor01d08012012-02-07 10:09:13 +0000861 ClosingBrace(ClosingBrace)
862{
863 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorda8962a2012-02-13 15:44:47 +0000864 CXXRecordDecl *Class = getLambdaClass();
865 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorda8962a2012-02-13 15:44:47 +0000866
867 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000868
869 // Copy captures.
870 ASTContext &Context = Class->getASTContext();
871 Data.NumCaptures = NumCaptures;
872 Data.NumExplicitCaptures = 0;
873 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
874 Capture *ToCapture = Data.Captures;
875 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
876 if (Captures[I].isExplicit())
877 ++Data.NumExplicitCaptures;
878
879 *ToCapture++ = Captures[I];
880 }
881
882 // Copy initialization expressions for the non-static data members.
883 Stmt **Stored = getStoredStmts();
884 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
885 *Stored++ = CaptureInits[I];
886
887 // Copy the body of the lambda.
888 *Stored++ = getCallOperator()->getBody();
889
890 // Copy the array index variables, if any.
891 HasArrayIndexVars = !ArrayIndexVars.empty();
892 if (HasArrayIndexVars) {
893 assert(ArrayIndexStarts.size() == NumCaptures);
894 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
895 sizeof(VarDecl *) * ArrayIndexVars.size());
896 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
897 sizeof(unsigned) * Captures.size());
898 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor5878cbc2012-02-21 04:17:39 +0000899 }
Douglas Gregor01d08012012-02-07 10:09:13 +0000900}
901
902LambdaExpr *LambdaExpr::Create(ASTContext &Context,
903 CXXRecordDecl *Class,
904 SourceRange IntroducerRange,
905 LambdaCaptureDefault CaptureDefault,
906 ArrayRef<Capture> Captures,
907 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000908 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000909 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000910 ArrayRef<VarDecl *> ArrayIndexVars,
911 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000912 SourceLocation ClosingBrace,
913 bool ContainsUnexpandedParameterPack) {
Douglas Gregor01d08012012-02-07 10:09:13 +0000914 // Determine the type of the expression (i.e., the type of the
915 // function object we're creating).
916 QualType T = Context.getTypeDeclType(Class);
Douglas Gregor01d08012012-02-07 10:09:13 +0000917
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000918 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smith88d2f672012-08-21 05:42:49 +0000919 if (!ArrayIndexVars.empty()) {
920 Size += sizeof(unsigned) * (Captures.size() + 1);
921 // Realign for following VarDecl array.
Richard Smitha796b6c2012-08-21 18:18:06 +0000922 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smith88d2f672012-08-21 05:42:49 +0000923 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
924 }
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000925 void *Mem = Context.Allocate(Size);
926 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000927 Captures, ExplicitParams, ExplicitResultType,
928 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000929 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregor01d08012012-02-07 10:09:13 +0000930}
931
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000932LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
933 unsigned NumArrayIndexVars) {
934 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
935 if (NumArrayIndexVars)
936 Size += sizeof(VarDecl) * NumArrayIndexVars
937 + sizeof(unsigned) * (NumCaptures + 1);
938 void *Mem = C.Allocate(Size);
939 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
940}
941
Douglas Gregorda8962a2012-02-13 15:44:47 +0000942LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000943 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000944}
945
946LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000947 return capture_begin() + NumCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000948}
949
950LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
951 return capture_begin();
952}
953
954LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
955 struct CXXRecordDecl::LambdaDefinitionData &Data
956 = getLambdaClass()->getLambdaData();
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000957 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000958}
959
960LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
961 return explicit_capture_end();
962}
963
964LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
965 return capture_end();
966}
967
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000968ArrayRef<VarDecl *>
969LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000970 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000971
972 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gay43a1b002012-02-13 19:29:45 +0000973 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
974 "Capture index out-of-range");
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000975 VarDecl **IndexVars = getArrayIndexVars();
976 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000977 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
978 IndexVars + IndexStarts[Index + 1]);
979}
980
Douglas Gregor01d08012012-02-07 10:09:13 +0000981CXXRecordDecl *LambdaExpr::getLambdaClass() const {
982 return getType()->getAsCXXRecordDecl();
983}
984
985CXXMethodDecl *LambdaExpr::getCallOperator() const {
986 CXXRecordDecl *Record = getLambdaClass();
987 DeclarationName Name
988 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
989 DeclContext::lookup_result Calls = Record->lookup(Name);
David Blaikie3bc93e32012-12-19 00:45:41 +0000990 assert(!Calls.empty() && "Missing lambda call operator!");
991 assert(Calls.size() == 1 && "More than one lambda call operator!");
992 CXXMethodDecl *Result = cast<CXXMethodDecl>(Calls.front());
Douglas Gregor01d08012012-02-07 10:09:13 +0000993 return Result;
994}
995
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000996CompoundStmt *LambdaExpr::getBody() const {
997 if (!getStoredStmts()[NumCaptures])
998 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
999
1000 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1001}
1002
Douglas Gregor01d08012012-02-07 10:09:13 +00001003bool LambdaExpr::isMutable() const {
David Blaikie4ef832f2012-08-10 00:55:35 +00001004 return !getCallOperator()->isConst();
Douglas Gregor01d08012012-02-07 10:09:13 +00001005}
1006
John McCall80ee6e82011-11-10 05:35:25 +00001007ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1008 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +00001009 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001010 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001011 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +00001012 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001013 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +00001014 SubExpr(subexpr) {
1015 ExprWithCleanupsBits.NumObjects = objects.size();
1016 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1017 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +00001018}
1019
John McCall80ee6e82011-11-10 05:35:25 +00001020ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
1021 ArrayRef<CleanupObject> objects) {
1022 size_t size = sizeof(ExprWithCleanups)
1023 + objects.size() * sizeof(CleanupObject);
1024 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1025 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +00001026}
1027
John McCall80ee6e82011-11-10 05:35:25 +00001028ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1029 : Expr(ExprWithCleanupsClass, empty) {
1030 ExprWithCleanupsBits.NumObjects = numObjects;
1031}
Chris Lattnerd2598362010-05-10 00:25:06 +00001032
John McCall80ee6e82011-11-10 05:35:25 +00001033ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1034 unsigned numObjects) {
1035 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1036 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1037 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +00001038}
1039
Douglas Gregorab6677e2010-09-08 00:15:04 +00001040CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001041 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001042 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001043 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +00001044 : Expr(CXXUnresolvedConstructExprClass,
1045 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +00001046 (Type->getType()->isLValueReferenceType() ? VK_LValue
1047 :Type->getType()->isRValueReferenceType()? VK_XValue
1048 :VK_RValue),
1049 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001050 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001051 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001052 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001053 LParenLoc(LParenLoc),
1054 RParenLoc(RParenLoc),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001055 NumArgs(Args.size()) {
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001056 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001057 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001058 if (Args[I]->containsUnexpandedParameterPack())
1059 ExprBits.ContainsUnexpandedParameterPack = true;
1060
1061 StoredArgs[I] = Args[I];
1062 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001063}
1064
1065CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +00001066CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +00001067 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001068 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001069 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001070 SourceLocation RParenLoc) {
1071 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001072 sizeof(Expr *) * Args.size());
1073 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001074}
1075
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001076CXXUnresolvedConstructExpr *
1077CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1078 Stmt::EmptyShell Empty;
1079 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1080 sizeof(Expr *) * NumArgs);
1081 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1082}
1083
Erik Verbruggen65d78312012-12-25 14:51:39 +00001084SourceLocation CXXUnresolvedConstructExpr::getLocStart() const {
1085 return Type->getTypeLoc().getBeginLoc();
Douglas Gregorab6677e2010-09-08 00:15:04 +00001086}
1087
John McCall865d4472009-11-19 22:55:06 +00001088CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001089 Expr *Base, QualType BaseType,
1090 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001091 SourceLocation OperatorLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001092 NestedNameSpecifierLoc QualifierLoc,
1093 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001094 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001095 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001096 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +00001097 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001098 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001099 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001100 (QualifierLoc &&
1101 QualifierLoc.getNestedNameSpecifier()
1102 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001103 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +00001104 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001105 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001106 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001107 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +00001108 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001109 if (TemplateArgs) {
1110 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +00001111 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001112 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001113 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1114 Dependent,
1115 InstantiationDependent,
1116 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001117 if (ContainsUnexpandedParameterPack)
1118 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001119 } else if (TemplateKWLoc.isValid()) {
1120 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001121 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001122}
1123
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001124CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1125 Expr *Base, QualType BaseType,
1126 bool IsArrow,
1127 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001128 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001129 NamedDecl *FirstQualifierFoundInScope,
1130 DeclarationNameInfo MemberNameInfo)
1131 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001132 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001133 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001134 (QualifierLoc &&
1135 QualifierLoc.getNestedNameSpecifier()->
1136 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001137 MemberNameInfo.containsUnexpandedParameterPack())),
1138 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001139 HasTemplateKWAndArgsInfo(false),
1140 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001141 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1142 MemberNameInfo(MemberNameInfo) { }
1143
John McCall865d4472009-11-19 22:55:06 +00001144CXXDependentScopeMemberExpr *
1145CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001146 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001147 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001148 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001149 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001150 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001151 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001152 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001153 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCallaa81e162009-12-01 22:10:20 +00001154 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1155 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001156 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +00001157 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001158 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001160 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1161 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1162 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +00001163
Chris Lattner32488542010-10-30 05:14:06 +00001164 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +00001165 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1166 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001167 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001168 TemplateKWLoc,
John McCallaa81e162009-12-01 22:10:20 +00001169 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001170 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001171}
1172
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001173CXXDependentScopeMemberExpr *
1174CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001175 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001176 unsigned NumTemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001177 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001178 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001179 0, SourceLocation(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001180 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001181 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001182
1183 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001184 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +00001185 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001186 CXXDependentScopeMemberExpr *E
1187 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001188 0, SourceLocation(),
1189 NestedNameSpecifierLoc(),
1190 SourceLocation(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001191 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001192 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001193 return E;
1194}
1195
Douglas Gregor4c9be892011-02-28 20:01:57 +00001196bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1197 if (Base == 0)
1198 return true;
1199
Douglas Gregor75e85042011-03-02 21:06:53 +00001200 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001201}
1202
John McCall864c0412011-04-26 20:42:42 +00001203static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1204 UnresolvedSetIterator end) {
1205 do {
1206 NamedDecl *decl = *begin;
1207 if (isa<UnresolvedUsingValueDecl>(decl))
1208 return false;
1209 if (isa<UsingShadowDecl>(decl))
1210 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1211
1212 // Unresolved member expressions should only contain methods and
1213 // method templates.
1214 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1215
1216 if (isa<FunctionTemplateDecl>(decl))
1217 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1218 if (cast<CXXMethodDecl>(decl)->isStatic())
1219 return false;
1220 } while (++begin != end);
1221
1222 return true;
1223}
1224
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001225UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001226 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001227 Expr *Base, QualType BaseType,
1228 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001229 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001230 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001231 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001232 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001233 const TemplateArgumentListInfo *TemplateArgs,
1234 UnresolvedSetIterator Begin,
1235 UnresolvedSetIterator End)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001236 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1237 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001238 // Dependent
1239 ((Base && Base->isTypeDependent()) ||
1240 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +00001241 ((Base && Base->isInstantiationDependent()) ||
1242 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001243 // Contains unexpanded parameter pack
1244 ((Base && Base->containsUnexpandedParameterPack()) ||
1245 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +00001246 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1247 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +00001248
1249 // Check whether all of the members are non-static member functions,
1250 // and if so, mark give this bound-member type instead of overload type.
1251 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1252 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +00001253}
1254
Douglas Gregor4c9be892011-02-28 20:01:57 +00001255bool UnresolvedMemberExpr::isImplicitAccess() const {
1256 if (Base == 0)
1257 return true;
1258
Douglas Gregor75e85042011-03-02 21:06:53 +00001259 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001260}
1261
John McCall129e2df2009-11-30 22:42:35 +00001262UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001263UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001264 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001265 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001266 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001267 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001268 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001269 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001270 const TemplateArgumentListInfo *TemplateArgs,
1271 UnresolvedSetIterator Begin,
1272 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +00001273 std::size_t size = sizeof(UnresolvedMemberExpr);
1274 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001275 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1276 else if (TemplateKWLoc.isValid())
1277 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall129e2df2009-11-30 22:42:35 +00001278
Chris Lattner32488542010-10-30 05:14:06 +00001279 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +00001280 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001281 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001282 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001283 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +00001284}
1285
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001286UnresolvedMemberExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001287UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001288 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001289 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001290 if (HasTemplateKWAndArgsInfo)
1291 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001292
Chris Lattner32488542010-10-30 05:14:06 +00001293 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001294 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001295 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001296 return E;
1297}
1298
John McCallc373d482010-01-27 01:50:18 +00001299CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1300 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1301
1302 // If there was a nested name specifier, it names the naming class.
1303 // It can't be dependent: after all, we were actually able to do the
1304 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001305 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +00001306 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +00001307 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +00001308 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001309 Record = T->getAsCXXRecordDecl();
1310 assert(Record && "qualifier in member expression does not name record");
1311 }
John McCallc373d482010-01-27 01:50:18 +00001312 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001313 else {
John McCallc373d482010-01-27 01:50:18 +00001314 QualType BaseType = getBaseType().getNonReferenceType();
1315 if (isArrow()) {
1316 const PointerType *PT = BaseType->getAs<PointerType>();
1317 assert(PT && "base of arrow member access is not pointer");
1318 BaseType = PT->getPointeeType();
1319 }
1320
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001321 Record = BaseType->getAsCXXRecordDecl();
1322 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001323 }
1324
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001325 return Record;
John McCallc373d482010-01-27 01:50:18 +00001326}
1327
Douglas Gregorc7793c72011-01-15 01:15:58 +00001328SubstNonTypeTemplateParmPackExpr::
1329SubstNonTypeTemplateParmPackExpr(QualType T,
1330 NonTypeTemplateParmDecl *Param,
1331 SourceLocation NameLoc,
1332 const TemplateArgument &ArgPack)
1333 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001334 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001335 Param(Param), Arguments(ArgPack.pack_begin()),
1336 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1337
1338TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1339 return TemplateArgument(Arguments, NumArguments);
1340}
1341
Richard Smith9a4db032012-09-12 00:56:43 +00001342FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1343 SourceLocation NameLoc,
1344 unsigned NumParams,
1345 Decl * const *Params)
1346 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1347 true, true, true, true),
1348 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1349 if (Params)
1350 std::uninitialized_copy(Params, Params + NumParams,
1351 reinterpret_cast<Decl**>(this+1));
1352}
1353
1354FunctionParmPackExpr *
1355FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1356 ParmVarDecl *ParamPack, SourceLocation NameLoc,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001357 ArrayRef<Decl *> Params) {
Richard Smith9a4db032012-09-12 00:56:43 +00001358 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1359 sizeof(ParmVarDecl*) * Params.size()))
1360 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1361}
1362
1363FunctionParmPackExpr *
1364FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1365 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1366 sizeof(ParmVarDecl*) * NumParams))
1367 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1368}
1369
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001370TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1371 ArrayRef<TypeSourceInfo *> Args,
1372 SourceLocation RParenLoc,
1373 bool Value)
1374 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1375 /*TypeDependent=*/false,
1376 /*ValueDependent=*/false,
1377 /*InstantiationDependent=*/false,
1378 /*ContainsUnexpandedParameterPack=*/false),
1379 Loc(Loc), RParenLoc(RParenLoc)
1380{
1381 TypeTraitExprBits.Kind = Kind;
1382 TypeTraitExprBits.Value = Value;
1383 TypeTraitExprBits.NumArgs = Args.size();
1384
1385 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1386
1387 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1388 if (Args[I]->getType()->isDependentType())
1389 setValueDependent(true);
1390 if (Args[I]->getType()->isInstantiationDependentType())
1391 setInstantiationDependent(true);
1392 if (Args[I]->getType()->containsUnexpandedParameterPack())
1393 setContainsUnexpandedParameterPack(true);
1394
1395 ToArgs[I] = Args[I];
1396 }
1397}
1398
1399TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1400 SourceLocation Loc,
1401 TypeTrait Kind,
1402 ArrayRef<TypeSourceInfo *> Args,
1403 SourceLocation RParenLoc,
1404 bool Value) {
1405 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1406 void *Mem = C.Allocate(Size);
1407 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1408}
1409
1410TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1411 unsigned NumArgs) {
1412 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1413 void *Mem = C.Allocate(Size);
1414 return new (Mem) TypeTraitExpr(EmptyShell());
1415}
1416
David Blaikie99ba9e32011-12-20 02:48:34 +00001417void ArrayTypeTraitExpr::anchor() { }