blob: 496697fc55b933c56ce29b11d04e02b78d10be4f [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;
Eli Friedman6e40c952013-06-17 22:35:10 +0000137 default:
138 if (TypeIdParens.isValid())
139 this->Range.setEnd(TypeIdParens.getEnd());
140 break;
David Blaikiec2fc67e2012-11-08 22:53:48 +0000141 }
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000142}
143
Chris Lattner59218632010-05-10 01:22:27 +0000144void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000145 unsigned numPlaceArgs, bool hasInitializer){
Chris Lattner59218632010-05-10 01:22:27 +0000146 assert(SubExprs == 0 && "SubExprs already allocated");
147 Array = isArray;
148 NumPlacementArgs = numPlaceArgs;
Sebastian Redl2aed8b82012-02-16 12:22:20 +0000149
150 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattner59218632010-05-10 01:22:27 +0000151 SubExprs = new (C) Stmt*[TotalSize];
152}
153
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000154bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
John McCallc2f3e7f2011-03-07 03:12:35 +0000155 return getOperatorNew()->getType()->
Sebastian Redl8026f6d2011-03-13 17:09:40 +0000156 castAs<FunctionProtoType>()->isNothrow(Ctx);
John McCallc2f3e7f2011-03-07 03:12:35 +0000157}
Chris Lattner59218632010-05-10 01:22:27 +0000158
Sebastian Redl4c5d3202008-11-21 19:14:01 +0000159// CXXDeleteExpr
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000160QualType CXXDeleteExpr::getDestroyedType() const {
161 const Expr *Arg = getArgument();
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000162 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silversteinc87fa062010-10-20 00:56:01 +0000163 const QualType ArgType = Arg->getType();
Craig Silversteina437ad32010-11-16 07:16:25 +0000164
165 if (ArgType->isDependentType() && !ArgType->isPointerType())
166 return QualType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000167
Craig Silverstein0fa0b782010-10-20 00:38:15 +0000168 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor5833b0b2010-09-14 22:55:20 +0000169}
170
Douglas Gregora71d8192009-09-04 17:36:40 +0000171// CXXPseudoDestructorExpr
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000172PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
173 : Type(Info)
174{
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000175 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000176}
177
John McCalle23cf432010-12-14 08:05:40 +0000178CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(ASTContext &Context,
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000179 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
180 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
181 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
182 PseudoDestructorTypeStorage DestroyedType)
John McCalle23cf432010-12-14 08:05:40 +0000183 : Expr(CXXPseudoDestructorExprClass,
Dmitri Gribenko55431692013-05-05 00:41:58 +0000184 Context.getPointerType(Context.getFunctionType(Context.VoidTy, None,
John McCalle23cf432010-12-14 08:05:40 +0000185 FunctionProtoType::ExtProtoInfo())),
186 VK_RValue, OK_Ordinary,
187 /*isTypeDependent=*/(Base->isTypeDependent() ||
188 (DestroyedType.getTypeSourceInfo() &&
189 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000190 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000191 (Base->isInstantiationDependent() ||
192 (QualifierLoc &&
193 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
194 (ScopeType &&
195 ScopeType->getType()->isInstantiationDependentType()) ||
196 (DestroyedType.getTypeSourceInfo() &&
197 DestroyedType.getTypeSourceInfo()->getType()
198 ->isInstantiationDependentType())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000199 // ContainsUnexpandedParameterPack
200 (Base->containsUnexpandedParameterPack() ||
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000201 (QualifierLoc &&
202 QualifierLoc.getNestedNameSpecifier()
203 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000204 (ScopeType &&
205 ScopeType->getType()->containsUnexpandedParameterPack()) ||
206 (DestroyedType.getTypeSourceInfo() &&
207 DestroyedType.getTypeSourceInfo()->getType()
208 ->containsUnexpandedParameterPack()))),
John McCalle23cf432010-12-14 08:05:40 +0000209 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregorf3db29f2011-02-25 18:19:59 +0000210 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalle23cf432010-12-14 08:05:40 +0000211 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
212 DestroyedType(DestroyedType) { }
213
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000214QualType CXXPseudoDestructorExpr::getDestroyedType() const {
215 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
216 return TInfo->getType();
217
218 return QualType();
219}
220
Erik Verbruggen65d78312012-12-25 14:51:39 +0000221SourceLocation CXXPseudoDestructorExpr::getLocEnd() const {
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000222 SourceLocation End = DestroyedType.getLocation();
223 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnarabd054db2010-05-20 10:00:11 +0000224 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Erik Verbruggen65d78312012-12-25 14:51:39 +0000225 return End;
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000226}
227
John McCallba135432009-11-21 08:51:07 +0000228// UnresolvedLookupExpr
John McCallf7a1a742009-11-24 19:00:30 +0000229UnresolvedLookupExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000230UnresolvedLookupExpr::Create(ASTContext &C,
John McCallc373d482010-01-27 01:50:18 +0000231 CXXRecordDecl *NamingClass,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000232 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000233 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000234 const DeclarationNameInfo &NameInfo,
235 bool ADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000236 const TemplateArgumentListInfo *Args,
237 UnresolvedSetIterator Begin,
238 UnresolvedSetIterator End)
John McCallf7a1a742009-11-24 19:00:30 +0000239{
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000240 assert(Args || TemplateKWLoc.isValid());
241 unsigned num_args = Args ? Args->size() : 0;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000242 void *Mem = C.Allocate(sizeof(UnresolvedLookupExpr) +
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000243 ASTTemplateKWAndArgsInfo::sizeFor(num_args));
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000244 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
245 TemplateKWLoc, NameInfo,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +0000246 ADL, /*Overload*/ true, Args,
Richard Smithb1502bc2012-10-18 17:56:02 +0000247 Begin, End);
John McCallf7a1a742009-11-24 19:00:30 +0000248}
249
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000250UnresolvedLookupExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000251UnresolvedLookupExpr::CreateEmpty(ASTContext &C,
252 bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +0000253 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000254 std::size_t size = sizeof(UnresolvedLookupExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000255 if (HasTemplateKWAndArgsInfo)
256 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000257
Chris Lattner32488542010-10-30 05:14:06 +0000258 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedLookupExpr>());
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000259 UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000260 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisbd65bb52010-06-25 09:03:34 +0000261 return E;
262}
263
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000264OverloadExpr::OverloadExpr(StmtClass K, ASTContext &C,
Douglas Gregor4c9be892011-02-28 20:01:57 +0000265 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000266 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000267 const DeclarationNameInfo &NameInfo,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000268 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000269 UnresolvedSetIterator Begin,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000270 UnresolvedSetIterator End,
271 bool KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000272 bool KnownInstantiationDependent,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000273 bool KnownContainsUnexpandedParameterPack)
274 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
275 KnownDependent,
Douglas Gregor561f8122011-07-01 01:22:09 +0000276 (KnownInstantiationDependent ||
277 NameInfo.isInstantiationDependent() ||
278 (QualifierLoc &&
279 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000280 (KnownContainsUnexpandedParameterPack ||
281 NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor4c9be892011-02-28 20:01:57 +0000282 (QualifierLoc &&
283 QualifierLoc.getNestedNameSpecifier()
284 ->containsUnexpandedParameterPack()))),
Benjamin Kramerd162cf12012-02-26 20:37:14 +0000285 NameInfo(NameInfo), QualifierLoc(QualifierLoc),
286 Results(0), NumResults(End - Begin),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000287 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid())
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000288{
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000289 NumResults = End - Begin;
290 if (NumResults) {
291 // Determine whether this expression is type-dependent.
292 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
293 if ((*I)->getDeclContext()->isDependentContext() ||
294 isa<UnresolvedUsingValueDecl>(*I)) {
295 ExprBits.TypeDependent = true;
296 ExprBits.ValueDependent = true;
Richard Smith7657fd72012-08-13 21:29:18 +0000297 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000298 }
299 }
300
301 Results = static_cast<DeclAccessPair *>(
302 C.Allocate(sizeof(DeclAccessPair) * NumResults,
303 llvm::alignOf<DeclAccessPair>()));
304 memcpy(Results, &*Begin.getIterator(),
305 NumResults * sizeof(DeclAccessPair));
306 }
307
308 // If we have explicit template arguments, check for dependent
309 // template arguments and whether they contain any unexpanded pack
310 // expansions.
311 if (TemplateArgs) {
312 bool Dependent = false;
Douglas Gregor561f8122011-07-01 01:22:09 +0000313 bool InstantiationDependent = false;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000314 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000315 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
316 Dependent,
317 InstantiationDependent,
318 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000319
320 if (Dependent) {
Douglas Gregor561f8122011-07-01 01:22:09 +0000321 ExprBits.TypeDependent = true;
322 ExprBits.ValueDependent = true;
323 }
324 if (InstantiationDependent)
325 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000326 if (ContainsUnexpandedParameterPack)
327 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000328 } else if (TemplateKWLoc.isValid()) {
329 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000330 }
331
332 if (isTypeDependent())
333 setType(C.DependentTy);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +0000334}
335
336void OverloadExpr::initializeResults(ASTContext &C,
337 UnresolvedSetIterator Begin,
338 UnresolvedSetIterator End) {
339 assert(Results == 0 && "Results already initialized!");
340 NumResults = End - Begin;
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000341 if (NumResults) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000342 Results = static_cast<DeclAccessPair *>(
343 C.Allocate(sizeof(DeclAccessPair) * NumResults,
344
345 llvm::alignOf<DeclAccessPair>()));
346 memcpy(Results, &*Begin.getIterator(),
347 NumResults * sizeof(DeclAccessPair));
Douglas Gregor928e6fc2010-05-23 19:36:40 +0000348 }
349}
350
John McCalle9ee23e2010-04-22 18:44:12 +0000351CXXRecordDecl *OverloadExpr::getNamingClass() const {
352 if (isa<UnresolvedLookupExpr>(this))
353 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
354 else
355 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
356}
357
John McCall865d4472009-11-19 22:55:06 +0000358// DependentScopeDeclRefExpr
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000359DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000360 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000361 SourceLocation TemplateKWLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000362 const DeclarationNameInfo &NameInfo,
363 const TemplateArgumentListInfo *Args)
364 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
365 true, true,
Douglas Gregor561f8122011-07-01 01:22:09 +0000366 (NameInfo.isInstantiationDependent() ||
367 (QualifierLoc &&
368 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000369 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000370 (QualifierLoc &&
371 QualifierLoc.getNestedNameSpecifier()
372 ->containsUnexpandedParameterPack()))),
373 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000374 HasTemplateKWAndArgsInfo(Args != 0 || TemplateKWLoc.isValid())
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000375{
376 if (Args) {
377 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000378 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000379 bool ContainsUnexpandedParameterPack
380 = ExprBits.ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000381 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *Args,
382 Dependent,
383 InstantiationDependent,
384 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000385 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000386 } else if (TemplateKWLoc.isValid()) {
387 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000388 }
389}
390
John McCallf7a1a742009-11-24 19:00:30 +0000391DependentScopeDeclRefExpr *
392DependentScopeDeclRefExpr::Create(ASTContext &C,
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000393 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000394 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +0000395 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +0000396 const TemplateArgumentListInfo *Args) {
397 std::size_t size = sizeof(DependentScopeDeclRefExpr);
John McCallf7a1a742009-11-24 19:00:30 +0000398 if (Args)
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000399 size += ASTTemplateKWAndArgsInfo::sizeFor(Args->size());
400 else if (TemplateKWLoc.isValid())
401 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000402 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000403 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
404 TemplateKWLoc, NameInfo, Args);
John McCallf7a1a742009-11-24 19:00:30 +0000405}
406
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000407DependentScopeDeclRefExpr *
408DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000409 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000410 unsigned NumTemplateArgs) {
411 std::size_t size = sizeof(DependentScopeDeclRefExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000412 if (HasTemplateKWAndArgsInfo)
413 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000414 void *Mem = C.Allocate(size);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000415 DependentScopeDeclRefExpr *E
Douglas Gregor00cf3cc2011-02-25 20:49:16 +0000416 = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000417 SourceLocation(),
Douglas Gregordef03542011-02-04 12:01:24 +0000418 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000419 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregordef03542011-02-04 12:01:24 +0000420 return E;
Argyrios Kyrtzidis12dffcd2010-06-28 09:31:56 +0000421}
422
Erik Verbruggen65d78312012-12-25 14:51:39 +0000423SourceLocation CXXConstructExpr::getLocStart() const {
John McCall2882eca2011-02-21 06:23:05 +0000424 if (isa<CXXTemporaryObjectExpr>(this))
Erik Verbruggen65d78312012-12-25 14:51:39 +0000425 return cast<CXXTemporaryObjectExpr>(this)->getLocStart();
426 return Loc;
427}
428
429SourceLocation CXXConstructExpr::getLocEnd() const {
430 if (isa<CXXTemporaryObjectExpr>(this))
431 return cast<CXXTemporaryObjectExpr>(this)->getLocEnd();
John McCall2882eca2011-02-21 06:23:05 +0000432
Douglas Gregor40749ee2010-11-03 00:35:38 +0000433 if (ParenRange.isValid())
Erik Verbruggen65d78312012-12-25 14:51:39 +0000434 return ParenRange.getEnd();
Douglas Gregor40749ee2010-11-03 00:35:38 +0000435
436 SourceLocation End = Loc;
437 for (unsigned I = getNumArgs(); I > 0; --I) {
438 const Expr *Arg = getArg(I-1);
439 if (!Arg->isDefaultArgument()) {
440 SourceLocation NewEnd = Arg->getLocEnd();
441 if (NewEnd.isValid()) {
442 End = NewEnd;
443 break;
444 }
445 }
446 }
447
Erik Verbruggen65d78312012-12-25 14:51:39 +0000448 return End;
Ted Kremeneke3837682009-12-23 04:00:48 +0000449}
450
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000451SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregorb4609802008-11-14 16:09:21 +0000452 OverloadedOperatorKind Kind = getOperator();
453 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
454 if (getNumArgs() == 1)
455 // Prefix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000456 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000457 else
458 // Postfix operator
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000459 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthd7650612011-04-02 09:47:38 +0000460 } else if (Kind == OO_Arrow) {
461 return getArg(0)->getSourceRange();
Douglas Gregorb4609802008-11-14 16:09:21 +0000462 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000463 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000464 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000465 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregorb4609802008-11-14 16:09:21 +0000466 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000467 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000468 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis3539b0c2012-05-01 22:19:11 +0000469 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregorb4609802008-11-14 16:09:21 +0000470 } else {
Argyrios Kyrtzidis4548ca22012-04-30 22:12:22 +0000471 return getOperatorLoc();
Douglas Gregorb4609802008-11-14 16:09:21 +0000472 }
473}
474
Ted Kremenekb2771592011-03-30 17:41:19 +0000475Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose51e87c52012-08-03 23:08:39 +0000476 const Expr *Callee = getCallee()->IgnoreParens();
477 if (const MemberExpr *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor88a35142008-12-22 05:46:06 +0000478 return MemExpr->getBase();
Jordan Rose51e87c52012-08-03 23:08:39 +0000479 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(Callee))
480 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
481 return BO->getLHS();
Douglas Gregor88a35142008-12-22 05:46:06 +0000482
483 // FIXME: Will eventually need to cope with member pointers.
484 return 0;
485}
486
Ted Kremenekb2771592011-03-30 17:41:19 +0000487CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
488 if (const MemberExpr *MemExpr =
489 dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
490 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
491
492 // FIXME: Will eventually need to cope with member pointers.
493 return 0;
494}
495
496
David Blaikie0cf3c0e2012-05-03 16:25:49 +0000497CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth007a9b12010-10-27 06:55:41 +0000498 Expr* ThisArg = getImplicitObjectArgument();
499 if (!ThisArg)
500 return 0;
501
502 if (ThisArg->getType()->isAnyPointerType())
503 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
504
505 return ThisArg->getType()->getAsCXXRecordDecl();
506}
507
Douglas Gregor00b98c22009-11-12 15:31:47 +0000508
Douglas Gregor49badde2008-10-27 19:41:14 +0000509//===----------------------------------------------------------------------===//
510// Named casts
511//===----------------------------------------------------------------------===//
512
513/// getCastName - Get the name of the C++ cast being used, e.g.,
514/// "static_cast", "dynamic_cast", "reinterpret_cast", or
515/// "const_cast". The returned pointer must not be freed.
516const char *CXXNamedCastExpr::getCastName() const {
517 switch (getStmtClass()) {
518 case CXXStaticCastExprClass: return "static_cast";
519 case CXXDynamicCastExprClass: return "dynamic_cast";
520 case CXXReinterpretCastExprClass: return "reinterpret_cast";
521 case CXXConstCastExprClass: return "const_cast";
522 default: return "<invalid cast>";
523 }
524}
Douglas Gregor506ae412009-01-16 18:33:17 +0000525
John McCallf871d0c2010-08-07 06:22:56 +0000526CXXStaticCastExpr *CXXStaticCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000527 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000528 CastKind K, Expr *Op,
529 const CXXCastPath *BasePath,
530 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000531 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000532 SourceLocation RParenLoc,
533 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000534 unsigned PathSize = (BasePath ? BasePath->size() : 0);
535 void *Buffer = C.Allocate(sizeof(CXXStaticCastExpr)
536 + PathSize * sizeof(CXXBaseSpecifier*));
537 CXXStaticCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000538 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000539 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000540 if (PathSize) E->setCastPath(*BasePath);
541 return E;
542}
543
544CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(ASTContext &C,
545 unsigned PathSize) {
546 void *Buffer =
547 C.Allocate(sizeof(CXXStaticCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
548 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
549}
550
551CXXDynamicCastExpr *CXXDynamicCastExpr::Create(ASTContext &C, QualType T,
John McCallf89e55a2010-11-18 06:31:45 +0000552 ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000553 CastKind K, Expr *Op,
554 const CXXCastPath *BasePath,
555 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000556 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000557 SourceLocation RParenLoc,
558 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000559 unsigned PathSize = (BasePath ? BasePath->size() : 0);
560 void *Buffer = C.Allocate(sizeof(CXXDynamicCastExpr)
561 + PathSize * sizeof(CXXBaseSpecifier*));
562 CXXDynamicCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000563 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000564 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000565 if (PathSize) E->setCastPath(*BasePath);
566 return E;
567}
568
569CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(ASTContext &C,
570 unsigned PathSize) {
571 void *Buffer =
572 C.Allocate(sizeof(CXXDynamicCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
573 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
574}
575
Anders Carlsson0fee3302011-04-11 01:43:55 +0000576/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
577/// to always be null. For example:
578///
579/// struct A { };
580/// struct B final : A { };
581/// struct C { };
582///
583/// C *f(B* b) { return dynamic_cast<C*>(b); }
584bool CXXDynamicCastExpr::isAlwaysNull() const
585{
586 QualType SrcType = getSubExpr()->getType();
587 QualType DestType = getType();
588
589 if (const PointerType *SrcPTy = SrcType->getAs<PointerType>()) {
590 SrcType = SrcPTy->getPointeeType();
591 DestType = DestType->castAs<PointerType>()->getPointeeType();
592 }
593
Sean Hunt5ca86392012-06-19 23:44:55 +0000594 if (DestType->isVoidType())
595 return false;
596
Anders Carlsson0fee3302011-04-11 01:43:55 +0000597 const CXXRecordDecl *SrcRD =
598 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
599
Jakob Stoklund Olesen35329362012-06-19 21:48:43 +0000600 if (!SrcRD->hasAttr<FinalAttr>())
601 return false;
602
Anders Carlsson0fee3302011-04-11 01:43:55 +0000603 const CXXRecordDecl *DestRD =
604 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
605
606 return !DestRD->isDerivedFrom(SrcRD);
607}
608
John McCallf871d0c2010-08-07 06:22:56 +0000609CXXReinterpretCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000610CXXReinterpretCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
611 CastKind K, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000612 const CXXCastPath *BasePath,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000613 TypeSourceInfo *WrittenTy, SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000614 SourceLocation RParenLoc,
615 SourceRange AngleBrackets) {
John McCallf871d0c2010-08-07 06:22:56 +0000616 unsigned PathSize = (BasePath ? BasePath->size() : 0);
617 void *Buffer =
618 C.Allocate(sizeof(CXXReinterpretCastExpr) + PathSize * sizeof(CXXBaseSpecifier*));
619 CXXReinterpretCastExpr *E =
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000620 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000621 RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000622 if (PathSize) E->setCastPath(*BasePath);
623 return E;
624}
625
626CXXReinterpretCastExpr *
627CXXReinterpretCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
628 void *Buffer = C.Allocate(sizeof(CXXReinterpretCastExpr)
629 + PathSize * sizeof(CXXBaseSpecifier*));
630 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
631}
632
John McCallf89e55a2010-11-18 06:31:45 +0000633CXXConstCastExpr *CXXConstCastExpr::Create(ASTContext &C, QualType T,
634 ExprValueKind VK, Expr *Op,
John McCallf871d0c2010-08-07 06:22:56 +0000635 TypeSourceInfo *WrittenTy,
Douglas Gregor1d5d0b92011-01-12 22:41:29 +0000636 SourceLocation L,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +0000637 SourceLocation RParenLoc,
638 SourceRange AngleBrackets) {
639 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
John McCallf871d0c2010-08-07 06:22:56 +0000640}
641
642CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(ASTContext &C) {
643 return new (C) CXXConstCastExpr(EmptyShell());
644}
645
646CXXFunctionalCastExpr *
John McCallf89e55a2010-11-18 06:31:45 +0000647CXXFunctionalCastExpr::Create(ASTContext &C, QualType T, ExprValueKind VK,
John McCallf871d0c2010-08-07 06:22:56 +0000648 TypeSourceInfo *Written, SourceLocation L,
649 CastKind K, Expr *Op, const CXXCastPath *BasePath,
650 SourceLocation R) {
651 unsigned PathSize = (BasePath ? BasePath->size() : 0);
652 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
653 + PathSize * sizeof(CXXBaseSpecifier*));
654 CXXFunctionalCastExpr *E =
John McCallf89e55a2010-11-18 06:31:45 +0000655 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, L, K, Op, PathSize, R);
John McCallf871d0c2010-08-07 06:22:56 +0000656 if (PathSize) E->setCastPath(*BasePath);
657 return E;
658}
659
660CXXFunctionalCastExpr *
661CXXFunctionalCastExpr::CreateEmpty(ASTContext &C, unsigned PathSize) {
662 void *Buffer = C.Allocate(sizeof(CXXFunctionalCastExpr)
663 + PathSize * sizeof(CXXBaseSpecifier*));
664 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
665}
666
Richard Smith9fcce652012-03-07 08:35:16 +0000667UserDefinedLiteral::LiteralOperatorKind
668UserDefinedLiteral::getLiteralOperatorKind() const {
669 if (getNumArgs() == 0)
670 return LOK_Template;
671 if (getNumArgs() == 2)
672 return LOK_String;
673
674 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
675 QualType ParamTy =
676 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
677 if (ParamTy->isPointerType())
678 return LOK_Raw;
679 if (ParamTy->isAnyCharacterType())
680 return LOK_Character;
681 if (ParamTy->isIntegerType())
682 return LOK_Integer;
683 if (ParamTy->isFloatingType())
684 return LOK_Floating;
685
686 llvm_unreachable("unknown kind of literal operator");
687}
688
689Expr *UserDefinedLiteral::getCookedLiteral() {
690#ifndef NDEBUG
691 LiteralOperatorKind LOK = getLiteralOperatorKind();
692 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
693#endif
694 return getArg(0);
695}
696
697const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
698 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
699}
John McCallf871d0c2010-08-07 06:22:56 +0000700
Douglas Gregor65222e82009-12-23 18:19:08 +0000701CXXDefaultArgExpr *
Douglas Gregor036aed12009-12-23 23:03:06 +0000702CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
703 ParmVarDecl *Param, Expr *SubExpr) {
Douglas Gregor65222e82009-12-23 18:19:08 +0000704 void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
Douglas Gregor036aed12009-12-23 23:03:06 +0000705 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
706 SubExpr);
Douglas Gregor65222e82009-12-23 18:19:08 +0000707}
708
Richard Smithc3bf52c2013-04-20 22:23:05 +0000709CXXDefaultInitExpr::CXXDefaultInitExpr(ASTContext &C, SourceLocation Loc,
710 FieldDecl *Field, QualType T)
711 : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C),
712 T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType()
713 ? VK_XValue
714 : VK_RValue,
715 /*FIXME*/ OK_Ordinary, false, false, false, false),
716 Field(Field), Loc(Loc) {
717 assert(Field->hasInClassInitializer());
718}
719
Mike Stump1eb44332009-09-09 15:08:12 +0000720CXXTemporary *CXXTemporary::Create(ASTContext &C,
Anders Carlssonb859f352009-05-30 20:34:37 +0000721 const CXXDestructorDecl *Destructor) {
Anders Carlsson88eaf072009-05-30 22:38:53 +0000722 return new (C) CXXTemporary(Destructor);
723}
724
Mike Stump1eb44332009-09-09 15:08:12 +0000725CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(ASTContext &C,
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000726 CXXTemporary *Temp,
727 Expr* SubExpr) {
Peter Collingbournebceb7552011-11-27 22:09:28 +0000728 assert((SubExpr->getType()->isRecordType() ||
729 SubExpr->getType()->isArrayType()) &&
730 "Expression bound to a temporary must have record or array type!");
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000731
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000732 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlssonfceb0a82009-05-30 20:03:25 +0000733}
734
Anders Carlsson8e587a12009-05-30 20:56:46 +0000735CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(ASTContext &C,
Anders Carlsson26de5492009-04-24 05:23:13 +0000736 CXXConstructorDecl *Cons,
Douglas Gregorab6677e2010-09-08 00:15:04 +0000737 TypeSourceInfo *Type,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000738 ArrayRef<Expr*> Args,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000739 SourceRange parenRange,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000740 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +0000741 bool ListInitialization,
Douglas Gregor1c63b9c2010-04-27 20:36:09 +0000742 bool ZeroInitialization)
Douglas Gregorab6677e2010-09-08 00:15:04 +0000743 : CXXConstructExpr(C, CXXTemporaryObjectExprClass,
744 Type->getType().getNonReferenceType(),
745 Type->getTypeLoc().getBeginLoc(),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000746 Cons, false, Args,
Richard Smithc83c2302012-12-19 01:39:02 +0000747 HadMultipleCandidates,
748 ListInitialization, ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000749 CXXConstructExpr::CK_Complete, parenRange),
750 Type(Type) {
Douglas Gregorab6677e2010-09-08 00:15:04 +0000751}
752
Erik Verbruggen65d78312012-12-25 14:51:39 +0000753SourceLocation CXXTemporaryObjectExpr::getLocStart() const {
754 return Type->getTypeLoc().getBeginLoc();
755}
756
757SourceLocation CXXTemporaryObjectExpr::getLocEnd() const {
758 return getParenRange().getEnd();
Douglas Gregor506ae412009-01-16 18:33:17 +0000759}
Anders Carlsson19d28a62009-04-21 02:22:11 +0000760
Mike Stump1eb44332009-09-09 15:08:12 +0000761CXXConstructExpr *CXXConstructExpr::Create(ASTContext &C, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000762 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000763 CXXConstructorDecl *D, bool Elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000764 ArrayRef<Expr*> Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000765 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000766 bool ListInitialization,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +0000767 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000768 ConstructionKind ConstructKind,
769 SourceRange ParenRange) {
Douglas Gregor99a2e602009-12-16 01:38:02 +0000770 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc, D,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000771 Elidable, Args,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000772 HadMultipleCandidates, ListInitialization,
773 ZeroInitialization, ConstructKind,
774 ParenRange);
Anders Carlssone349bea2009-04-23 02:32:43 +0000775}
776
Mike Stump1eb44332009-09-09 15:08:12 +0000777CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
Douglas Gregor99a2e602009-12-16 01:38:02 +0000778 SourceLocation Loc,
Anders Carlsson8e587a12009-05-30 20:56:46 +0000779 CXXConstructorDecl *D, bool elidable,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000780 ArrayRef<Expr*> args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000781 bool HadMultipleCandidates,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000782 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000783 bool ZeroInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +0000784 ConstructionKind ConstructKind,
785 SourceRange ParenRange)
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000786 : Expr(SC, T, VK_RValue, OK_Ordinary,
787 T->isDependentType(), T->isDependentType(),
Douglas Gregor561f8122011-07-01 01:22:09 +0000788 T->isInstantiationDependentType(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000789 T->containsUnexpandedParameterPack()),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000790 Constructor(D), Loc(Loc), ParenRange(ParenRange), NumArgs(args.size()),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000791 Elidable(elidable), HadMultipleCandidates(HadMultipleCandidates),
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +0000792 ListInitialization(ListInitialization),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +0000793 ZeroInitialization(ZeroInitialization),
Douglas Gregora48e6762011-09-26 14:47:03 +0000794 ConstructKind(ConstructKind), Args(0)
Douglas Gregor16006c92009-12-16 18:50:27 +0000795{
796 if (NumArgs) {
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000797 Args = new (C) Stmt*[args.size()];
Douglas Gregor16006c92009-12-16 18:50:27 +0000798
Benjamin Kramer3b6bef92012-08-24 11:54:20 +0000799 for (unsigned i = 0; i != args.size(); ++i) {
Douglas Gregor16006c92009-12-16 18:50:27 +0000800 assert(args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000801
802 if (args[i]->isValueDependent())
803 ExprBits.ValueDependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +0000804 if (args[i]->isInstantiationDependent())
805 ExprBits.InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +0000806 if (args[i]->containsUnexpandedParameterPack())
807 ExprBits.ContainsUnexpandedParameterPack = true;
808
Douglas Gregor16006c92009-12-16 18:50:27 +0000809 Args[i] = args[i];
Anders Carlssone349bea2009-04-23 02:32:43 +0000810 }
Douglas Gregor16006c92009-12-16 18:50:27 +0000811 }
Anders Carlssone349bea2009-04-23 02:32:43 +0000812}
813
Douglas Gregor01d08012012-02-07 10:09:13 +0000814LambdaExpr::Capture::Capture(SourceLocation Loc, bool Implicit,
815 LambdaCaptureKind Kind, VarDecl *Var,
816 SourceLocation EllipsisLoc)
Richard Smith0d8e9642013-05-16 06:20:58 +0000817 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
Douglas Gregor01d08012012-02-07 10:09:13 +0000818{
819 unsigned Bits = 0;
820 if (Implicit)
821 Bits |= Capture_Implicit;
822
823 switch (Kind) {
824 case LCK_This:
825 assert(Var == 0 && "'this' capture cannot have a variable!");
826 break;
827
828 case LCK_ByCopy:
829 Bits |= Capture_ByCopy;
830 // Fall through
831 case LCK_ByRef:
832 assert(Var && "capture must have a variable!");
833 break;
Richard Smith0d8e9642013-05-16 06:20:58 +0000834
835 case LCK_Init:
836 llvm_unreachable("don't use this constructor for an init-capture");
Douglas Gregor01d08012012-02-07 10:09:13 +0000837 }
Richard Smith0d8e9642013-05-16 06:20:58 +0000838 DeclAndBits.setInt(Bits);
Douglas Gregor01d08012012-02-07 10:09:13 +0000839}
840
Richard Smith0d8e9642013-05-16 06:20:58 +0000841LambdaExpr::Capture::Capture(FieldDecl *Field)
842 : DeclAndBits(Field,
843 Field->getType()->isReferenceType() ? 0 : Capture_ByCopy),
844 Loc(Field->getLocation()), EllipsisLoc() {}
845
Douglas Gregor01d08012012-02-07 10:09:13 +0000846LambdaCaptureKind LambdaExpr::Capture::getCaptureKind() const {
Richard Smith0d8e9642013-05-16 06:20:58 +0000847 Decl *D = DeclAndBits.getPointer();
848 if (!D)
Douglas Gregor01d08012012-02-07 10:09:13 +0000849 return LCK_This;
850
Richard Smith0d8e9642013-05-16 06:20:58 +0000851 if (isa<FieldDecl>(D))
852 return LCK_Init;
853
854 return (DeclAndBits.getInt() & Capture_ByCopy) ? LCK_ByCopy : LCK_ByRef;
Douglas Gregor01d08012012-02-07 10:09:13 +0000855}
856
James Dennettf68af642013-08-09 23:08:25 +0000857LambdaExpr::LambdaExpr(QualType T,
Douglas Gregor01d08012012-02-07 10:09:13 +0000858 SourceRange IntroducerRange,
859 LambdaCaptureDefault CaptureDefault,
James Dennettf68af642013-08-09 23:08:25 +0000860 SourceLocation CaptureDefaultLoc,
861 ArrayRef<Capture> Captures,
Douglas Gregor01d08012012-02-07 10:09:13 +0000862 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000863 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000864 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000865 ArrayRef<VarDecl *> ArrayIndexVars,
866 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000867 SourceLocation ClosingBrace,
868 bool ContainsUnexpandedParameterPack)
Douglas Gregor01d08012012-02-07 10:09:13 +0000869 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
870 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith612409e2012-07-25 03:56:55 +0000871 ContainsUnexpandedParameterPack),
Douglas Gregor01d08012012-02-07 10:09:13 +0000872 IntroducerRange(IntroducerRange),
James Dennettf68af642013-08-09 23:08:25 +0000873 CaptureDefaultLoc(CaptureDefaultLoc),
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000874 NumCaptures(Captures.size()),
Douglas Gregor01d08012012-02-07 10:09:13 +0000875 CaptureDefault(CaptureDefault),
876 ExplicitParams(ExplicitParams),
Douglas Gregordfca6f52012-02-13 22:00:16 +0000877 ExplicitResultType(ExplicitResultType),
Douglas Gregor01d08012012-02-07 10:09:13 +0000878 ClosingBrace(ClosingBrace)
879{
880 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorda8962a2012-02-13 15:44:47 +0000881 CXXRecordDecl *Class = getLambdaClass();
882 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorda8962a2012-02-13 15:44:47 +0000883
884 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000885
886 // Copy captures.
887 ASTContext &Context = Class->getASTContext();
888 Data.NumCaptures = NumCaptures;
889 Data.NumExplicitCaptures = 0;
890 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
891 Capture *ToCapture = Data.Captures;
892 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
893 if (Captures[I].isExplicit())
894 ++Data.NumExplicitCaptures;
895
896 *ToCapture++ = Captures[I];
897 }
898
899 // Copy initialization expressions for the non-static data members.
900 Stmt **Stored = getStoredStmts();
901 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
902 *Stored++ = CaptureInits[I];
903
904 // Copy the body of the lambda.
905 *Stored++ = getCallOperator()->getBody();
906
907 // Copy the array index variables, if any.
908 HasArrayIndexVars = !ArrayIndexVars.empty();
909 if (HasArrayIndexVars) {
910 assert(ArrayIndexStarts.size() == NumCaptures);
911 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
912 sizeof(VarDecl *) * ArrayIndexVars.size());
913 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
914 sizeof(unsigned) * Captures.size());
915 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor5878cbc2012-02-21 04:17:39 +0000916 }
Douglas Gregor01d08012012-02-07 10:09:13 +0000917}
918
James Dennettf68af642013-08-09 23:08:25 +0000919LambdaExpr *LambdaExpr::Create(ASTContext &Context,
Douglas Gregor01d08012012-02-07 10:09:13 +0000920 CXXRecordDecl *Class,
921 SourceRange IntroducerRange,
922 LambdaCaptureDefault CaptureDefault,
James Dennettf68af642013-08-09 23:08:25 +0000923 SourceLocation CaptureDefaultLoc,
924 ArrayRef<Capture> Captures,
Douglas Gregor01d08012012-02-07 10:09:13 +0000925 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000926 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000927 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000928 ArrayRef<VarDecl *> ArrayIndexVars,
929 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000930 SourceLocation ClosingBrace,
931 bool ContainsUnexpandedParameterPack) {
Douglas Gregor01d08012012-02-07 10:09:13 +0000932 // Determine the type of the expression (i.e., the type of the
933 // function object we're creating).
934 QualType T = Context.getTypeDeclType(Class);
Douglas Gregor01d08012012-02-07 10:09:13 +0000935
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000936 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smith88d2f672012-08-21 05:42:49 +0000937 if (!ArrayIndexVars.empty()) {
938 Size += sizeof(unsigned) * (Captures.size() + 1);
939 // Realign for following VarDecl array.
Richard Smitha796b6c2012-08-21 18:18:06 +0000940 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smith88d2f672012-08-21 05:42:49 +0000941 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
942 }
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000943 void *Mem = Context.Allocate(Size);
James Dennettf68af642013-08-09 23:08:25 +0000944 return new (Mem) LambdaExpr(T, IntroducerRange,
945 CaptureDefault, CaptureDefaultLoc, Captures,
946 ExplicitParams, ExplicitResultType,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000947 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000948 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregor01d08012012-02-07 10:09:13 +0000949}
950
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000951LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
952 unsigned NumArrayIndexVars) {
953 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
954 if (NumArrayIndexVars)
955 Size += sizeof(VarDecl) * NumArrayIndexVars
956 + sizeof(unsigned) * (NumCaptures + 1);
957 void *Mem = C.Allocate(Size);
958 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
959}
960
Douglas Gregorda8962a2012-02-13 15:44:47 +0000961LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000962 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000963}
964
965LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000966 return capture_begin() + NumCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000967}
968
969LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
970 return capture_begin();
971}
972
973LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
974 struct CXXRecordDecl::LambdaDefinitionData &Data
975 = getLambdaClass()->getLambdaData();
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000976 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000977}
978
979LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
980 return explicit_capture_end();
981}
982
983LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
984 return capture_end();
985}
986
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000987ArrayRef<VarDecl *>
988LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000989 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000990
991 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gay43a1b002012-02-13 19:29:45 +0000992 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
993 "Capture index out-of-range");
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000994 VarDecl **IndexVars = getArrayIndexVars();
995 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000996 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
997 IndexVars + IndexStarts[Index + 1]);
998}
999
Douglas Gregor01d08012012-02-07 10:09:13 +00001000CXXRecordDecl *LambdaExpr::getLambdaClass() const {
1001 return getType()->getAsCXXRecordDecl();
1002}
1003
1004CXXMethodDecl *LambdaExpr::getCallOperator() const {
1005 CXXRecordDecl *Record = getLambdaClass();
1006 DeclarationName Name
1007 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
1008 DeclContext::lookup_result Calls = Record->lookup(Name);
David Blaikie3bc93e32012-12-19 00:45:41 +00001009 assert(!Calls.empty() && "Missing lambda call operator!");
1010 assert(Calls.size() == 1 && "More than one lambda call operator!");
1011 CXXMethodDecl *Result = cast<CXXMethodDecl>(Calls.front());
Douglas Gregor01d08012012-02-07 10:09:13 +00001012 return Result;
1013}
1014
Douglas Gregor9d36f5d2012-02-14 17:54:36 +00001015CompoundStmt *LambdaExpr::getBody() const {
1016 if (!getStoredStmts()[NumCaptures])
1017 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
1018
1019 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1020}
1021
Douglas Gregor01d08012012-02-07 10:09:13 +00001022bool LambdaExpr::isMutable() const {
David Blaikie4ef832f2012-08-10 00:55:35 +00001023 return !getCallOperator()->isConst();
Douglas Gregor01d08012012-02-07 10:09:13 +00001024}
1025
John McCall80ee6e82011-11-10 05:35:25 +00001026ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1027 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +00001028 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001029 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001030 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +00001031 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001032 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +00001033 SubExpr(subexpr) {
1034 ExprWithCleanupsBits.NumObjects = objects.size();
1035 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1036 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +00001037}
1038
John McCall80ee6e82011-11-10 05:35:25 +00001039ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
1040 ArrayRef<CleanupObject> objects) {
1041 size_t size = sizeof(ExprWithCleanups)
1042 + objects.size() * sizeof(CleanupObject);
1043 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1044 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +00001045}
1046
John McCall80ee6e82011-11-10 05:35:25 +00001047ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1048 : Expr(ExprWithCleanupsClass, empty) {
1049 ExprWithCleanupsBits.NumObjects = numObjects;
1050}
Chris Lattnerd2598362010-05-10 00:25:06 +00001051
John McCall80ee6e82011-11-10 05:35:25 +00001052ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1053 unsigned numObjects) {
1054 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1055 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1056 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +00001057}
1058
Douglas Gregorab6677e2010-09-08 00:15:04 +00001059CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001060 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001061 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001062 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +00001063 : Expr(CXXUnresolvedConstructExprClass,
1064 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +00001065 (Type->getType()->isLValueReferenceType() ? VK_LValue
1066 :Type->getType()->isRValueReferenceType()? VK_XValue
1067 :VK_RValue),
1068 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001069 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001070 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001071 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001072 LParenLoc(LParenLoc),
1073 RParenLoc(RParenLoc),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001074 NumArgs(Args.size()) {
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001075 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001076 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001077 if (Args[I]->containsUnexpandedParameterPack())
1078 ExprBits.ContainsUnexpandedParameterPack = true;
1079
1080 StoredArgs[I] = Args[I];
1081 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001082}
1083
1084CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +00001085CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +00001086 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001087 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001088 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001089 SourceLocation RParenLoc) {
1090 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001091 sizeof(Expr *) * Args.size());
1092 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001093}
1094
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001095CXXUnresolvedConstructExpr *
1096CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1097 Stmt::EmptyShell Empty;
1098 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1099 sizeof(Expr *) * NumArgs);
1100 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1101}
1102
Erik Verbruggen65d78312012-12-25 14:51:39 +00001103SourceLocation CXXUnresolvedConstructExpr::getLocStart() const {
1104 return Type->getTypeLoc().getBeginLoc();
Douglas Gregorab6677e2010-09-08 00:15:04 +00001105}
1106
John McCall865d4472009-11-19 22:55:06 +00001107CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001108 Expr *Base, QualType BaseType,
1109 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001110 SourceLocation OperatorLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001111 NestedNameSpecifierLoc QualifierLoc,
1112 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001113 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001114 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001115 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +00001116 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001117 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001118 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001119 (QualifierLoc &&
1120 QualifierLoc.getNestedNameSpecifier()
1121 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001122 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +00001123 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001124 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001125 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001126 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +00001127 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001128 if (TemplateArgs) {
1129 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +00001130 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001131 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001132 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1133 Dependent,
1134 InstantiationDependent,
1135 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001136 if (ContainsUnexpandedParameterPack)
1137 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001138 } else if (TemplateKWLoc.isValid()) {
1139 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001140 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001141}
1142
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001143CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1144 Expr *Base, QualType BaseType,
1145 bool IsArrow,
1146 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001147 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001148 NamedDecl *FirstQualifierFoundInScope,
1149 DeclarationNameInfo MemberNameInfo)
1150 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001151 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001152 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001153 (QualifierLoc &&
1154 QualifierLoc.getNestedNameSpecifier()->
1155 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001156 MemberNameInfo.containsUnexpandedParameterPack())),
1157 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001158 HasTemplateKWAndArgsInfo(false),
1159 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001160 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1161 MemberNameInfo(MemberNameInfo) { }
1162
John McCall865d4472009-11-19 22:55:06 +00001163CXXDependentScopeMemberExpr *
1164CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001165 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001166 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001167 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001168 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001169 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001170 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001171 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001172 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCallaa81e162009-12-01 22:10:20 +00001173 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1174 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001175 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +00001176 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001177 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +00001178
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001179 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1180 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1181 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +00001182
Chris Lattner32488542010-10-30 05:14:06 +00001183 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +00001184 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1185 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001186 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001187 TemplateKWLoc,
John McCallaa81e162009-12-01 22:10:20 +00001188 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001189 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001190}
1191
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001192CXXDependentScopeMemberExpr *
1193CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001194 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001195 unsigned NumTemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001196 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001197 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001198 0, SourceLocation(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001199 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001200 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001201
1202 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001203 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +00001204 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001205 CXXDependentScopeMemberExpr *E
1206 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001207 0, SourceLocation(),
1208 NestedNameSpecifierLoc(),
1209 SourceLocation(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001210 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001211 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001212 return E;
1213}
1214
Douglas Gregor4c9be892011-02-28 20:01:57 +00001215bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1216 if (Base == 0)
1217 return true;
1218
Douglas Gregor75e85042011-03-02 21:06:53 +00001219 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001220}
1221
John McCall864c0412011-04-26 20:42:42 +00001222static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1223 UnresolvedSetIterator end) {
1224 do {
1225 NamedDecl *decl = *begin;
1226 if (isa<UnresolvedUsingValueDecl>(decl))
1227 return false;
1228 if (isa<UsingShadowDecl>(decl))
1229 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1230
1231 // Unresolved member expressions should only contain methods and
1232 // method templates.
1233 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1234
1235 if (isa<FunctionTemplateDecl>(decl))
1236 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1237 if (cast<CXXMethodDecl>(decl)->isStatic())
1238 return false;
1239 } while (++begin != end);
1240
1241 return true;
1242}
1243
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001244UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001245 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001246 Expr *Base, QualType BaseType,
1247 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001248 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001249 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001250 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001251 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001252 const TemplateArgumentListInfo *TemplateArgs,
1253 UnresolvedSetIterator Begin,
1254 UnresolvedSetIterator End)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001255 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1256 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001257 // Dependent
1258 ((Base && Base->isTypeDependent()) ||
1259 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +00001260 ((Base && Base->isInstantiationDependent()) ||
1261 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001262 // Contains unexpanded parameter pack
1263 ((Base && Base->containsUnexpandedParameterPack()) ||
1264 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +00001265 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1266 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +00001267
1268 // Check whether all of the members are non-static member functions,
1269 // and if so, mark give this bound-member type instead of overload type.
1270 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1271 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +00001272}
1273
Douglas Gregor4c9be892011-02-28 20:01:57 +00001274bool UnresolvedMemberExpr::isImplicitAccess() const {
1275 if (Base == 0)
1276 return true;
1277
Douglas Gregor75e85042011-03-02 21:06:53 +00001278 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001279}
1280
John McCall129e2df2009-11-30 22:42:35 +00001281UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001282UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001283 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001284 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001285 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001286 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001287 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001288 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001289 const TemplateArgumentListInfo *TemplateArgs,
1290 UnresolvedSetIterator Begin,
1291 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +00001292 std::size_t size = sizeof(UnresolvedMemberExpr);
1293 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001294 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1295 else if (TemplateKWLoc.isValid())
1296 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall129e2df2009-11-30 22:42:35 +00001297
Chris Lattner32488542010-10-30 05:14:06 +00001298 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +00001299 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001300 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001301 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001302 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +00001303}
1304
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001305UnresolvedMemberExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001306UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001307 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001308 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001309 if (HasTemplateKWAndArgsInfo)
1310 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001311
Chris Lattner32488542010-10-30 05:14:06 +00001312 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001313 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001314 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001315 return E;
1316}
1317
John McCallc373d482010-01-27 01:50:18 +00001318CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1319 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1320
1321 // If there was a nested name specifier, it names the naming class.
1322 // It can't be dependent: after all, we were actually able to do the
1323 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001324 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +00001325 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +00001326 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +00001327 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001328 Record = T->getAsCXXRecordDecl();
1329 assert(Record && "qualifier in member expression does not name record");
1330 }
John McCallc373d482010-01-27 01:50:18 +00001331 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001332 else {
John McCallc373d482010-01-27 01:50:18 +00001333 QualType BaseType = getBaseType().getNonReferenceType();
1334 if (isArrow()) {
1335 const PointerType *PT = BaseType->getAs<PointerType>();
1336 assert(PT && "base of arrow member access is not pointer");
1337 BaseType = PT->getPointeeType();
1338 }
1339
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001340 Record = BaseType->getAsCXXRecordDecl();
1341 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001342 }
1343
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001344 return Record;
John McCallc373d482010-01-27 01:50:18 +00001345}
1346
Douglas Gregorc7793c72011-01-15 01:15:58 +00001347SubstNonTypeTemplateParmPackExpr::
1348SubstNonTypeTemplateParmPackExpr(QualType T,
1349 NonTypeTemplateParmDecl *Param,
1350 SourceLocation NameLoc,
1351 const TemplateArgument &ArgPack)
1352 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001353 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001354 Param(Param), Arguments(ArgPack.pack_begin()),
1355 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1356
1357TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1358 return TemplateArgument(Arguments, NumArguments);
1359}
1360
Richard Smith9a4db032012-09-12 00:56:43 +00001361FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1362 SourceLocation NameLoc,
1363 unsigned NumParams,
1364 Decl * const *Params)
1365 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1366 true, true, true, true),
1367 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1368 if (Params)
1369 std::uninitialized_copy(Params, Params + NumParams,
1370 reinterpret_cast<Decl**>(this+1));
1371}
1372
1373FunctionParmPackExpr *
1374FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1375 ParmVarDecl *ParamPack, SourceLocation NameLoc,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001376 ArrayRef<Decl *> Params) {
Richard Smith9a4db032012-09-12 00:56:43 +00001377 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1378 sizeof(ParmVarDecl*) * Params.size()))
1379 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1380}
1381
1382FunctionParmPackExpr *
1383FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1384 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1385 sizeof(ParmVarDecl*) * NumParams))
1386 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1387}
1388
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001389TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1390 ArrayRef<TypeSourceInfo *> Args,
1391 SourceLocation RParenLoc,
1392 bool Value)
1393 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1394 /*TypeDependent=*/false,
1395 /*ValueDependent=*/false,
1396 /*InstantiationDependent=*/false,
1397 /*ContainsUnexpandedParameterPack=*/false),
1398 Loc(Loc), RParenLoc(RParenLoc)
1399{
1400 TypeTraitExprBits.Kind = Kind;
1401 TypeTraitExprBits.Value = Value;
1402 TypeTraitExprBits.NumArgs = Args.size();
1403
1404 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1405
1406 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1407 if (Args[I]->getType()->isDependentType())
1408 setValueDependent(true);
1409 if (Args[I]->getType()->isInstantiationDependentType())
1410 setInstantiationDependent(true);
1411 if (Args[I]->getType()->containsUnexpandedParameterPack())
1412 setContainsUnexpandedParameterPack(true);
1413
1414 ToArgs[I] = Args[I];
1415 }
1416}
1417
1418TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1419 SourceLocation Loc,
1420 TypeTrait Kind,
1421 ArrayRef<TypeSourceInfo *> Args,
1422 SourceLocation RParenLoc,
1423 bool Value) {
1424 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1425 void *Mem = C.Allocate(Size);
1426 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1427}
1428
1429TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1430 unsigned NumArgs) {
1431 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1432 void *Mem = C.Allocate(Size);
1433 return new (Mem) TypeTraitExpr(EmptyShell());
1434}
1435
David Blaikie99ba9e32011-12-20 02:48:34 +00001436void ArrayTypeTraitExpr::anchor() { }