blob: 55bd1990f605c42cf51f08f6520c15ce490bb53c [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
857LambdaExpr::LambdaExpr(QualType T,
858 SourceRange IntroducerRange,
859 LambdaCaptureDefault CaptureDefault,
860 ArrayRef<Capture> Captures,
861 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000862 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000863 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000864 ArrayRef<VarDecl *> ArrayIndexVars,
865 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000866 SourceLocation ClosingBrace,
867 bool ContainsUnexpandedParameterPack)
Douglas Gregor01d08012012-02-07 10:09:13 +0000868 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary,
869 T->isDependentType(), T->isDependentType(), T->isDependentType(),
Richard Smith612409e2012-07-25 03:56:55 +0000870 ContainsUnexpandedParameterPack),
Douglas Gregor01d08012012-02-07 10:09:13 +0000871 IntroducerRange(IntroducerRange),
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000872 NumCaptures(Captures.size()),
Douglas Gregor01d08012012-02-07 10:09:13 +0000873 CaptureDefault(CaptureDefault),
874 ExplicitParams(ExplicitParams),
Douglas Gregordfca6f52012-02-13 22:00:16 +0000875 ExplicitResultType(ExplicitResultType),
Douglas Gregor01d08012012-02-07 10:09:13 +0000876 ClosingBrace(ClosingBrace)
877{
878 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorda8962a2012-02-13 15:44:47 +0000879 CXXRecordDecl *Class = getLambdaClass();
880 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorda8962a2012-02-13 15:44:47 +0000881
882 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000883
884 // Copy captures.
885 ASTContext &Context = Class->getASTContext();
886 Data.NumCaptures = NumCaptures;
887 Data.NumExplicitCaptures = 0;
888 Data.Captures = (Capture *)Context.Allocate(sizeof(Capture) * NumCaptures);
889 Capture *ToCapture = Data.Captures;
890 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
891 if (Captures[I].isExplicit())
892 ++Data.NumExplicitCaptures;
893
894 *ToCapture++ = Captures[I];
895 }
896
897 // Copy initialization expressions for the non-static data members.
898 Stmt **Stored = getStoredStmts();
899 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
900 *Stored++ = CaptureInits[I];
901
902 // Copy the body of the lambda.
903 *Stored++ = getCallOperator()->getBody();
904
905 // Copy the array index variables, if any.
906 HasArrayIndexVars = !ArrayIndexVars.empty();
907 if (HasArrayIndexVars) {
908 assert(ArrayIndexStarts.size() == NumCaptures);
909 memcpy(getArrayIndexVars(), ArrayIndexVars.data(),
910 sizeof(VarDecl *) * ArrayIndexVars.size());
911 memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(),
912 sizeof(unsigned) * Captures.size());
913 getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size();
Douglas Gregor5878cbc2012-02-21 04:17:39 +0000914 }
Douglas Gregor01d08012012-02-07 10:09:13 +0000915}
916
917LambdaExpr *LambdaExpr::Create(ASTContext &Context,
918 CXXRecordDecl *Class,
919 SourceRange IntroducerRange,
920 LambdaCaptureDefault CaptureDefault,
921 ArrayRef<Capture> Captures,
922 bool ExplicitParams,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000923 bool ExplicitResultType,
Douglas Gregor01d08012012-02-07 10:09:13 +0000924 ArrayRef<Expr *> CaptureInits,
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000925 ArrayRef<VarDecl *> ArrayIndexVars,
926 ArrayRef<unsigned> ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000927 SourceLocation ClosingBrace,
928 bool ContainsUnexpandedParameterPack) {
Douglas Gregor01d08012012-02-07 10:09:13 +0000929 // Determine the type of the expression (i.e., the type of the
930 // function object we're creating).
931 QualType T = Context.getTypeDeclType(Class);
Douglas Gregor01d08012012-02-07 10:09:13 +0000932
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000933 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (Captures.size() + 1);
Richard Smith88d2f672012-08-21 05:42:49 +0000934 if (!ArrayIndexVars.empty()) {
935 Size += sizeof(unsigned) * (Captures.size() + 1);
936 // Realign for following VarDecl array.
Richard Smitha796b6c2012-08-21 18:18:06 +0000937 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
Richard Smith88d2f672012-08-21 05:42:49 +0000938 Size += sizeof(VarDecl *) * ArrayIndexVars.size();
939 }
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000940 void *Mem = Context.Allocate(Size);
941 return new (Mem) LambdaExpr(T, IntroducerRange, CaptureDefault,
Douglas Gregordfca6f52012-02-13 22:00:16 +0000942 Captures, ExplicitParams, ExplicitResultType,
943 CaptureInits, ArrayIndexVars, ArrayIndexStarts,
Richard Smith612409e2012-07-25 03:56:55 +0000944 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregor01d08012012-02-07 10:09:13 +0000945}
946
Douglas Gregor9d36f5d2012-02-14 17:54:36 +0000947LambdaExpr *LambdaExpr::CreateDeserialized(ASTContext &C, unsigned NumCaptures,
948 unsigned NumArrayIndexVars) {
949 unsigned Size = sizeof(LambdaExpr) + sizeof(Stmt *) * (NumCaptures + 1);
950 if (NumArrayIndexVars)
951 Size += sizeof(VarDecl) * NumArrayIndexVars
952 + sizeof(unsigned) * (NumCaptures + 1);
953 void *Mem = C.Allocate(Size);
954 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures, NumArrayIndexVars > 0);
955}
956
Douglas Gregorda8962a2012-02-13 15:44:47 +0000957LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000958 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000959}
960
961LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000962 return capture_begin() + NumCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000963}
964
965LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
966 return capture_begin();
967}
968
969LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
970 struct CXXRecordDecl::LambdaDefinitionData &Data
971 = getLambdaClass()->getLambdaData();
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000972 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorda8962a2012-02-13 15:44:47 +0000973}
974
975LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
976 return explicit_capture_end();
977}
978
979LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
980 return capture_end();
981}
982
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000983ArrayRef<VarDecl *>
984LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const {
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000985 assert(HasArrayIndexVars && "No array index-var data?");
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000986
987 unsigned Index = Iter - capture_init_begin();
Matt Beaumont-Gay43a1b002012-02-13 19:29:45 +0000988 assert(Index < getLambdaClass()->getLambdaData().NumCaptures &&
989 "Capture index out-of-range");
Douglas Gregor7ae282f2012-02-13 17:20:40 +0000990 VarDecl **IndexVars = getArrayIndexVars();
991 unsigned *IndexStarts = getArrayIndexStarts();
Douglas Gregor9daa7bf2012-02-13 16:35:30 +0000992 return ArrayRef<VarDecl *>(IndexVars + IndexStarts[Index],
993 IndexVars + IndexStarts[Index + 1]);
994}
995
Douglas Gregor01d08012012-02-07 10:09:13 +0000996CXXRecordDecl *LambdaExpr::getLambdaClass() const {
997 return getType()->getAsCXXRecordDecl();
998}
999
1000CXXMethodDecl *LambdaExpr::getCallOperator() const {
1001 CXXRecordDecl *Record = getLambdaClass();
1002 DeclarationName Name
1003 = Record->getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
1004 DeclContext::lookup_result Calls = Record->lookup(Name);
David Blaikie3bc93e32012-12-19 00:45:41 +00001005 assert(!Calls.empty() && "Missing lambda call operator!");
1006 assert(Calls.size() == 1 && "More than one lambda call operator!");
1007 CXXMethodDecl *Result = cast<CXXMethodDecl>(Calls.front());
Douglas Gregor01d08012012-02-07 10:09:13 +00001008 return Result;
1009}
1010
Douglas Gregor9d36f5d2012-02-14 17:54:36 +00001011CompoundStmt *LambdaExpr::getBody() const {
1012 if (!getStoredStmts()[NumCaptures])
1013 getStoredStmts()[NumCaptures] = getCallOperator()->getBody();
1014
1015 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1016}
1017
Douglas Gregor01d08012012-02-07 10:09:13 +00001018bool LambdaExpr::isMutable() const {
David Blaikie4ef832f2012-08-10 00:55:35 +00001019 return !getCallOperator()->isConst();
Douglas Gregor01d08012012-02-07 10:09:13 +00001020}
1021
John McCall80ee6e82011-11-10 05:35:25 +00001022ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1023 ArrayRef<CleanupObject> objects)
John McCall4765fa02010-12-06 08:20:24 +00001024 : Expr(ExprWithCleanupsClass, subexpr->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00001025 subexpr->getValueKind(), subexpr->getObjectKind(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001026 subexpr->isTypeDependent(), subexpr->isValueDependent(),
Douglas Gregor561f8122011-07-01 01:22:09 +00001027 subexpr->isInstantiationDependent(),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001028 subexpr->containsUnexpandedParameterPack()),
John McCall80ee6e82011-11-10 05:35:25 +00001029 SubExpr(subexpr) {
1030 ExprWithCleanupsBits.NumObjects = objects.size();
1031 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1032 getObjectsBuffer()[i] = objects[i];
Anders Carlsson02bbfa32009-04-24 22:47:04 +00001033}
1034
John McCall80ee6e82011-11-10 05:35:25 +00001035ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, Expr *subexpr,
1036 ArrayRef<CleanupObject> objects) {
1037 size_t size = sizeof(ExprWithCleanups)
1038 + objects.size() * sizeof(CleanupObject);
1039 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1040 return new (buffer) ExprWithCleanups(subexpr, objects);
Chris Lattnerd2598362010-05-10 00:25:06 +00001041}
1042
John McCall80ee6e82011-11-10 05:35:25 +00001043ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1044 : Expr(ExprWithCleanupsClass, empty) {
1045 ExprWithCleanupsBits.NumObjects = numObjects;
1046}
Chris Lattnerd2598362010-05-10 00:25:06 +00001047
John McCall80ee6e82011-11-10 05:35:25 +00001048ExprWithCleanups *ExprWithCleanups::Create(ASTContext &C, EmptyShell empty,
1049 unsigned numObjects) {
1050 size_t size = sizeof(ExprWithCleanups) + numObjects * sizeof(CleanupObject);
1051 void *buffer = C.Allocate(size, llvm::alignOf<ExprWithCleanups>());
1052 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson88eaf072009-05-30 22:38:53 +00001053}
1054
Douglas Gregorab6677e2010-09-08 00:15:04 +00001055CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001056 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001057 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001058 SourceLocation RParenLoc)
Douglas Gregorab6677e2010-09-08 00:15:04 +00001059 : Expr(CXXUnresolvedConstructExprClass,
1060 Type->getType().getNonReferenceType(),
Douglas Gregor032c8692011-07-08 15:50:43 +00001061 (Type->getType()->isLValueReferenceType() ? VK_LValue
1062 :Type->getType()->isRValueReferenceType()? VK_XValue
1063 :VK_RValue),
1064 OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001065 Type->getType()->isDependentType(), true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001066 Type->getType()->containsUnexpandedParameterPack()),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001067 Type(Type),
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001068 LParenLoc(LParenLoc),
1069 RParenLoc(RParenLoc),
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001070 NumArgs(Args.size()) {
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001071 Stmt **StoredArgs = reinterpret_cast<Stmt **>(this + 1);
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001072 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001073 if (Args[I]->containsUnexpandedParameterPack())
1074 ExprBits.ContainsUnexpandedParameterPack = true;
1075
1076 StoredArgs[I] = Args[I];
1077 }
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001078}
1079
1080CXXUnresolvedConstructExpr *
Mike Stump1eb44332009-09-09 15:08:12 +00001081CXXUnresolvedConstructExpr::Create(ASTContext &C,
Douglas Gregorab6677e2010-09-08 00:15:04 +00001082 TypeSourceInfo *Type,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001083 SourceLocation LParenLoc,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001084 ArrayRef<Expr*> Args,
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001085 SourceLocation RParenLoc) {
1086 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00001087 sizeof(Expr *) * Args.size());
1088 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregord81e6ca2009-05-20 18:46:25 +00001089}
1090
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001091CXXUnresolvedConstructExpr *
1092CXXUnresolvedConstructExpr::CreateEmpty(ASTContext &C, unsigned NumArgs) {
1093 Stmt::EmptyShell Empty;
1094 void *Mem = C.Allocate(sizeof(CXXUnresolvedConstructExpr) +
1095 sizeof(Expr *) * NumArgs);
1096 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1097}
1098
Erik Verbruggen65d78312012-12-25 14:51:39 +00001099SourceLocation CXXUnresolvedConstructExpr::getLocStart() const {
1100 return Type->getTypeLoc().getBeginLoc();
Douglas Gregorab6677e2010-09-08 00:15:04 +00001101}
1102
John McCall865d4472009-11-19 22:55:06 +00001103CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001104 Expr *Base, QualType BaseType,
1105 bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001106 SourceLocation OperatorLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001107 NestedNameSpecifierLoc QualifierLoc,
1108 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001109 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001110 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001111 const TemplateArgumentListInfo *TemplateArgs)
John McCallf89e55a2010-11-18 06:31:45 +00001112 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001113 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001114 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001115 (QualifierLoc &&
1116 QualifierLoc.getNestedNameSpecifier()
1117 ->containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001118 MemberNameInfo.containsUnexpandedParameterPack())),
John McCallaa81e162009-12-01 22:10:20 +00001119 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001120 HasTemplateKWAndArgsInfo(TemplateArgs != 0 || TemplateKWLoc.isValid()),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001121 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001122 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Abramo Bagnara25777432010-08-11 22:01:17 +00001123 MemberNameInfo(MemberNameInfo) {
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001124 if (TemplateArgs) {
1125 bool Dependent = true;
Douglas Gregor561f8122011-07-01 01:22:09 +00001126 bool InstantiationDependent = true;
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001127 bool ContainsUnexpandedParameterPack = false;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001128 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc, *TemplateArgs,
1129 Dependent,
1130 InstantiationDependent,
1131 ContainsUnexpandedParameterPack);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001132 if (ContainsUnexpandedParameterPack)
1133 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001134 } else if (TemplateKWLoc.isValid()) {
1135 getTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001136 }
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001137}
1138
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001139CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
1140 Expr *Base, QualType BaseType,
1141 bool IsArrow,
1142 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001143 NestedNameSpecifierLoc QualifierLoc,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001144 NamedDecl *FirstQualifierFoundInScope,
1145 DeclarationNameInfo MemberNameInfo)
1146 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy,
Douglas Gregor561f8122011-07-01 01:22:09 +00001147 VK_LValue, OK_Ordinary, true, true, true,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001148 ((Base && Base->containsUnexpandedParameterPack()) ||
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001149 (QualifierLoc &&
1150 QualifierLoc.getNestedNameSpecifier()->
1151 containsUnexpandedParameterPack()) ||
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001152 MemberNameInfo.containsUnexpandedParameterPack())),
1153 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001154 HasTemplateKWAndArgsInfo(false),
1155 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001156 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1157 MemberNameInfo(MemberNameInfo) { }
1158
John McCall865d4472009-11-19 22:55:06 +00001159CXXDependentScopeMemberExpr *
1160CXXDependentScopeMemberExpr::Create(ASTContext &C,
John McCallaa81e162009-12-01 22:10:20 +00001161 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001162 SourceLocation OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001163 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001164 SourceLocation TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001165 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001166 DeclarationNameInfo MemberNameInfo,
John McCalld5532b62009-11-23 01:53:49 +00001167 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001168 if (!TemplateArgs && !TemplateKWLoc.isValid())
John McCallaa81e162009-12-01 22:10:20 +00001169 return new (C) CXXDependentScopeMemberExpr(C, Base, BaseType,
1170 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001171 QualifierLoc,
John McCallaa81e162009-12-01 22:10:20 +00001172 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001173 MemberNameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +00001174
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001175 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1176 std::size_t size = sizeof(CXXDependentScopeMemberExpr)
1177 + ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
John McCalld5532b62009-11-23 01:53:49 +00001178
Chris Lattner32488542010-10-30 05:14:06 +00001179 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
John McCallaa81e162009-12-01 22:10:20 +00001180 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1181 IsArrow, OperatorLoc,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001182 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001183 TemplateKWLoc,
John McCallaa81e162009-12-01 22:10:20 +00001184 FirstQualifierFoundInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001185 MemberNameInfo, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001186}
1187
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001188CXXDependentScopeMemberExpr *
1189CXXDependentScopeMemberExpr::CreateEmpty(ASTContext &C,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001190 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001191 unsigned NumTemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001192 if (!HasTemplateKWAndArgsInfo)
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001193 return new (C) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001194 0, SourceLocation(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00001195 NestedNameSpecifierLoc(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001196 DeclarationNameInfo());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001197
1198 std::size_t size = sizeof(CXXDependentScopeMemberExpr) +
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001199 ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Chris Lattner32488542010-10-30 05:14:06 +00001200 void *Mem = C.Allocate(size, llvm::alignOf<CXXDependentScopeMemberExpr>());
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001201 CXXDependentScopeMemberExpr *E
1202 = new (Mem) CXXDependentScopeMemberExpr(C, 0, QualType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001203 0, SourceLocation(),
1204 NestedNameSpecifierLoc(),
1205 SourceLocation(), 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001206 DeclarationNameInfo(), 0);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001207 E->HasTemplateKWAndArgsInfo = true;
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +00001208 return E;
1209}
1210
Douglas Gregor4c9be892011-02-28 20:01:57 +00001211bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
1212 if (Base == 0)
1213 return true;
1214
Douglas Gregor75e85042011-03-02 21:06:53 +00001215 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001216}
1217
John McCall864c0412011-04-26 20:42:42 +00001218static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1219 UnresolvedSetIterator end) {
1220 do {
1221 NamedDecl *decl = *begin;
1222 if (isa<UnresolvedUsingValueDecl>(decl))
1223 return false;
1224 if (isa<UsingShadowDecl>(decl))
1225 decl = cast<UsingShadowDecl>(decl)->getUnderlyingDecl();
1226
1227 // Unresolved member expressions should only contain methods and
1228 // method templates.
1229 assert(isa<CXXMethodDecl>(decl) || isa<FunctionTemplateDecl>(decl));
1230
1231 if (isa<FunctionTemplateDecl>(decl))
1232 decl = cast<FunctionTemplateDecl>(decl)->getTemplatedDecl();
1233 if (cast<CXXMethodDecl>(decl)->isStatic())
1234 return false;
1235 } while (++begin != end);
1236
1237 return true;
1238}
1239
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001240UnresolvedMemberExpr::UnresolvedMemberExpr(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001241 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001242 Expr *Base, QualType BaseType,
1243 bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001244 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001245 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001246 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001247 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001248 const TemplateArgumentListInfo *TemplateArgs,
1249 UnresolvedSetIterator Begin,
1250 UnresolvedSetIterator End)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001251 : OverloadExpr(UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1252 MemberNameInfo, TemplateArgs, Begin, End,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001253 // Dependent
1254 ((Base && Base->isTypeDependent()) ||
1255 BaseType->isDependentType()),
Douglas Gregor561f8122011-07-01 01:22:09 +00001256 ((Base && Base->isInstantiationDependent()) ||
1257 BaseType->isInstantiationDependentType()),
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001258 // Contains unexpanded parameter pack
1259 ((Base && Base->containsUnexpandedParameterPack()) ||
1260 BaseType->containsUnexpandedParameterPack())),
John McCall7bb12da2010-02-02 06:20:04 +00001261 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing),
1262 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall864c0412011-04-26 20:42:42 +00001263
1264 // Check whether all of the members are non-static member functions,
1265 // and if so, mark give this bound-member type instead of overload type.
1266 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1267 setType(C.BoundMemberTy);
John McCall129e2df2009-11-30 22:42:35 +00001268}
1269
Douglas Gregor4c9be892011-02-28 20:01:57 +00001270bool UnresolvedMemberExpr::isImplicitAccess() const {
1271 if (Base == 0)
1272 return true;
1273
Douglas Gregor75e85042011-03-02 21:06:53 +00001274 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor4c9be892011-02-28 20:01:57 +00001275}
1276
John McCall129e2df2009-11-30 22:42:35 +00001277UnresolvedMemberExpr *
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001278UnresolvedMemberExpr::Create(ASTContext &C,
John McCall129e2df2009-11-30 22:42:35 +00001279 bool HasUnresolvedUsing,
John McCallaa81e162009-12-01 22:10:20 +00001280 Expr *Base, QualType BaseType, bool IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001281 SourceLocation OperatorLoc,
Douglas Gregor4c9be892011-02-28 20:01:57 +00001282 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001283 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001284 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor5a84dec2010-05-23 18:57:34 +00001285 const TemplateArgumentListInfo *TemplateArgs,
1286 UnresolvedSetIterator Begin,
1287 UnresolvedSetIterator End) {
John McCall129e2df2009-11-30 22:42:35 +00001288 std::size_t size = sizeof(UnresolvedMemberExpr);
1289 if (TemplateArgs)
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001290 size += ASTTemplateKWAndArgsInfo::sizeFor(TemplateArgs->size());
1291 else if (TemplateKWLoc.isValid())
1292 size += ASTTemplateKWAndArgsInfo::sizeFor(0);
John McCall129e2df2009-11-30 22:42:35 +00001293
Chris Lattner32488542010-10-30 05:14:06 +00001294 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Douglas Gregor928e6fc2010-05-23 19:36:40 +00001295 return new (Mem) UnresolvedMemberExpr(C,
Douglas Gregorbebbe0d2010-12-15 01:34:56 +00001296 HasUnresolvedUsing, Base, BaseType,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001297 IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001298 MemberNameInfo, TemplateArgs, Begin, End);
John McCall129e2df2009-11-30 22:42:35 +00001299}
1300
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001301UnresolvedMemberExpr *
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001302UnresolvedMemberExpr::CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
Douglas Gregordef03542011-02-04 12:01:24 +00001303 unsigned NumTemplateArgs) {
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001304 std::size_t size = sizeof(UnresolvedMemberExpr);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001305 if (HasTemplateKWAndArgsInfo)
1306 size += ASTTemplateKWAndArgsInfo::sizeFor(NumTemplateArgs);
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001307
Chris Lattner32488542010-10-30 05:14:06 +00001308 void *Mem = C.Allocate(size, llvm::alignOf<UnresolvedMemberExpr>());
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001309 UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001310 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisa77eb082010-06-25 09:03:26 +00001311 return E;
1312}
1313
John McCallc373d482010-01-27 01:50:18 +00001314CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1315 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1316
1317 // If there was a nested name specifier, it names the naming class.
1318 // It can't be dependent: after all, we were actually able to do the
1319 // lookup.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001320 CXXRecordDecl *Record = 0;
John McCall7bb12da2010-02-02 06:20:04 +00001321 if (getQualifier()) {
John McCallf4c73712011-01-19 06:33:43 +00001322 const Type *T = getQualifier()->getAsType();
John McCallc373d482010-01-27 01:50:18 +00001323 assert(T && "qualifier in member expression does not name type");
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001324 Record = T->getAsCXXRecordDecl();
1325 assert(Record && "qualifier in member expression does not name record");
1326 }
John McCallc373d482010-01-27 01:50:18 +00001327 // Otherwise the naming class must have been the base class.
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001328 else {
John McCallc373d482010-01-27 01:50:18 +00001329 QualType BaseType = getBaseType().getNonReferenceType();
1330 if (isArrow()) {
1331 const PointerType *PT = BaseType->getAs<PointerType>();
1332 assert(PT && "base of arrow member access is not pointer");
1333 BaseType = PT->getPointeeType();
1334 }
1335
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001336 Record = BaseType->getAsCXXRecordDecl();
1337 assert(Record && "base of member expression does not name record");
John McCallc373d482010-01-27 01:50:18 +00001338 }
1339
Douglas Gregorc96be1e2010-04-27 18:19:34 +00001340 return Record;
John McCallc373d482010-01-27 01:50:18 +00001341}
1342
Douglas Gregorc7793c72011-01-15 01:15:58 +00001343SubstNonTypeTemplateParmPackExpr::
1344SubstNonTypeTemplateParmPackExpr(QualType T,
1345 NonTypeTemplateParmDecl *Param,
1346 SourceLocation NameLoc,
1347 const TemplateArgument &ArgPack)
1348 : Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
Douglas Gregor561f8122011-07-01 01:22:09 +00001349 true, true, true, true),
Douglas Gregorc7793c72011-01-15 01:15:58 +00001350 Param(Param), Arguments(ArgPack.pack_begin()),
1351 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
1352
1353TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1354 return TemplateArgument(Arguments, NumArguments);
1355}
1356
Richard Smith9a4db032012-09-12 00:56:43 +00001357FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1358 SourceLocation NameLoc,
1359 unsigned NumParams,
1360 Decl * const *Params)
1361 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary,
1362 true, true, true, true),
1363 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1364 if (Params)
1365 std::uninitialized_copy(Params, Params + NumParams,
1366 reinterpret_cast<Decl**>(this+1));
1367}
1368
1369FunctionParmPackExpr *
1370FunctionParmPackExpr::Create(ASTContext &Context, QualType T,
1371 ParmVarDecl *ParamPack, SourceLocation NameLoc,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001372 ArrayRef<Decl *> Params) {
Richard Smith9a4db032012-09-12 00:56:43 +00001373 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1374 sizeof(ParmVarDecl*) * Params.size()))
1375 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1376}
1377
1378FunctionParmPackExpr *
1379FunctionParmPackExpr::CreateEmpty(ASTContext &Context, unsigned NumParams) {
1380 return new (Context.Allocate(sizeof(FunctionParmPackExpr) +
1381 sizeof(ParmVarDecl*) * NumParams))
1382 FunctionParmPackExpr(QualType(), 0, SourceLocation(), 0, 0);
1383}
1384
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00001385TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1386 ArrayRef<TypeSourceInfo *> Args,
1387 SourceLocation RParenLoc,
1388 bool Value)
1389 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1390 /*TypeDependent=*/false,
1391 /*ValueDependent=*/false,
1392 /*InstantiationDependent=*/false,
1393 /*ContainsUnexpandedParameterPack=*/false),
1394 Loc(Loc), RParenLoc(RParenLoc)
1395{
1396 TypeTraitExprBits.Kind = Kind;
1397 TypeTraitExprBits.Value = Value;
1398 TypeTraitExprBits.NumArgs = Args.size();
1399
1400 TypeSourceInfo **ToArgs = getTypeSourceInfos();
1401
1402 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1403 if (Args[I]->getType()->isDependentType())
1404 setValueDependent(true);
1405 if (Args[I]->getType()->isInstantiationDependentType())
1406 setInstantiationDependent(true);
1407 if (Args[I]->getType()->containsUnexpandedParameterPack())
1408 setContainsUnexpandedParameterPack(true);
1409
1410 ToArgs[I] = Args[I];
1411 }
1412}
1413
1414TypeTraitExpr *TypeTraitExpr::Create(ASTContext &C, QualType T,
1415 SourceLocation Loc,
1416 TypeTrait Kind,
1417 ArrayRef<TypeSourceInfo *> Args,
1418 SourceLocation RParenLoc,
1419 bool Value) {
1420 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * Args.size();
1421 void *Mem = C.Allocate(Size);
1422 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1423}
1424
1425TypeTraitExpr *TypeTraitExpr::CreateDeserialized(ASTContext &C,
1426 unsigned NumArgs) {
1427 unsigned Size = sizeof(TypeTraitExpr) + sizeof(TypeSourceInfo*) * NumArgs;
1428 void *Mem = C.Allocate(Size);
1429 return new (Mem) TypeTraitExpr(EmptyShell());
1430}
1431
David Blaikie99ba9e32011-12-20 02:48:34 +00001432void ArrayTypeTraitExpr::anchor() { }