blob: 3a204c244f683f1038e10b822b3802e8497ba70c [file] [log] [blame]
Eugene Zelenko821f6982017-11-18 01:47:41 +00001//===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===//
Ted Kremeneke3a0c142007-08-24 20:21:10 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-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 Kremeneke3a0c142007-08-24 20:21:10 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the subclesses of Expr class declared in ExprCXX.h
11//
12//===----------------------------------------------------------------------===//
13
Eugene Zelenko821f6982017-11-18 01:47:41 +000014#include "clang/AST/ExprCXX.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000015#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000016#include "clang/AST/Attr.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000017#include "clang/AST/Decl.h"
18#include "clang/AST/DeclAccessPair.h"
19#include "clang/AST/DeclBase.h"
Douglas Gregor993603d2008-11-14 16:09:21 +000020#include "clang/AST/DeclCXX.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000021#include "clang/AST/DeclarationName.h"
22#include "clang/AST/Expr.h"
23#include "clang/AST/LambdaCapture.h"
24#include "clang/AST/NestedNameSpecifier.h"
25#include "clang/AST/TemplateBase.h"
26#include "clang/AST/Type.h"
Douglas Gregor651fe5e2010-02-24 23:40:28 +000027#include "clang/AST/TypeLoc.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000028#include "clang/Basic/LLVM.h"
29#include "clang/Basic/OperatorKinds.h"
30#include "clang/Basic/SourceLocation.h"
31#include "clang/Basic/Specifiers.h"
32#include "llvm/ADT/ArrayRef.h"
33#include "llvm/Support/Casting.h"
34#include "llvm/Support/ErrorHandling.h"
35#include <cassert>
36#include <cstddef>
37#include <cstring>
38#include <memory>
Ted Kremeneke3a0c142007-08-24 20:21:10 +000039
Eugene Zelenko821f6982017-11-18 01:47:41 +000040using namespace clang;
Douglas Gregor9da64192010-04-26 22:37:10 +000041
Ted Kremeneke3a0c142007-08-24 20:21:10 +000042//===----------------------------------------------------------------------===//
43// Child Iterators for iterating over subexpressions/substatements
44//===----------------------------------------------------------------------===//
45
Richard Smith66094432016-10-20 00:55:15 +000046bool CXXOperatorCallExpr::isInfixBinaryOp() const {
47 // An infix binary operator is any operator with two arguments other than
48 // operator() and operator[]. Note that none of these operators can have
49 // default arguments, so it suffices to check the number of argument
50 // expressions.
51 if (getNumArgs() != 2)
52 return false;
53
54 switch (getOperator()) {
55 case OO_Call: case OO_Subscript:
56 return false;
57 default:
58 return true;
59 }
60}
61
Richard Smithef8bf432012-08-13 20:08:14 +000062bool CXXTypeidExpr::isPotentiallyEvaluated() const {
63 if (isTypeOperand())
64 return false;
65
66 // C++11 [expr.typeid]p3:
67 // When typeid is applied to an expression other than a glvalue of
68 // polymorphic class type, [...] the expression is an unevaluated operand.
69 const Expr *E = getExprOperand();
70 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
71 if (RD->isPolymorphic() && E->isGLValue())
72 return true;
73
74 return false;
75}
76
David Majnemer143c55e2013-09-27 07:04:31 +000077QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
Douglas Gregor9da64192010-04-26 22:37:10 +000078 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
David Majnemer143c55e2013-09-27 07:04:31 +000079 Qualifiers Quals;
80 return Context.getUnqualifiedArrayType(
81 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
Douglas Gregor9da64192010-04-26 22:37:10 +000082}
83
David Majnemer143c55e2013-09-27 07:04:31 +000084QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const {
Francois Pichet9f4f2072010-09-08 12:20:18 +000085 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
David Majnemer143c55e2013-09-27 07:04:31 +000086 Qualifiers Quals;
87 return Context.getUnqualifiedArrayType(
88 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
Francois Pichet9f4f2072010-09-08 12:20:18 +000089}
90
Douglas Gregor747eb782010-07-08 06:14:04 +000091// CXXScalarValueInitExpr
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +000092SourceLocation CXXScalarValueInitExpr::getLocStart() const {
93 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc;
Douglas Gregor2b88c112010-09-08 00:15:04 +000094}
95
Sebastian Redlbd150f42008-11-21 19:14:01 +000096// CXXNewExpr
Craig Toppera31a8822013-08-22 07:09:37 +000097CXXNewExpr::CXXNewExpr(const ASTContext &C, bool globalNew,
98 FunctionDecl *operatorNew, FunctionDecl *operatorDelete,
Richard Smithb2f0f052016-10-10 18:54:32 +000099 bool PassAlignment, bool usualArrayDeleteWantsSize,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000100 ArrayRef<Expr*> placementArgs,
Sebastian Redl6047f072012-02-16 12:22:20 +0000101 SourceRange typeIdParens, Expr *arraySize,
102 InitializationStyle initializationStyle,
103 Expr *initializer, QualType ty,
104 TypeSourceInfo *allocatedTypeInfo,
David Blaikie7b97aef2012-11-07 00:12:38 +0000105 SourceRange Range, SourceRange directInitRange)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000106 : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, ty->isDependentType(),
107 ty->isDependentType(), ty->isInstantiationDependentType(),
108 ty->containsUnexpandedParameterPack()),
109 OperatorNew(operatorNew), OperatorDelete(operatorDelete),
110 AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
111 Range(Range), DirectInitRange(directInitRange), GlobalNew(globalNew),
112 PassAlignment(PassAlignment),
113 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
Craig Topper36250ad2014-05-12 05:36:57 +0000114 assert((initializer != nullptr || initializationStyle == NoInit) &&
Sebastian Redl6047f072012-02-16 12:22:20 +0000115 "Only NoInit can have no initializer.");
116 StoredInitializationStyle = initializer ? initializationStyle + 1 : 0;
Craig Topper36250ad2014-05-12 05:36:57 +0000117 AllocateArgsArray(C, arraySize != nullptr, placementArgs.size(),
118 initializer != nullptr);
Sebastian Redlbd150f42008-11-21 19:14:01 +0000119 unsigned i = 0;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000120 if (Array) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000121 if (arraySize->isInstantiationDependent())
122 ExprBits.InstantiationDependent = true;
123
Douglas Gregora6e053e2010-12-15 01:34:56 +0000124 if (arraySize->containsUnexpandedParameterPack())
125 ExprBits.ContainsUnexpandedParameterPack = true;
126
Sebastian Redl351bb782008-12-02 14:43:59 +0000127 SubExprs[i++] = arraySize;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000128 }
129
Sebastian Redl6047f072012-02-16 12:22:20 +0000130 if (initializer) {
131 if (initializer->isInstantiationDependent())
132 ExprBits.InstantiationDependent = true;
133
134 if (initializer->containsUnexpandedParameterPack())
135 ExprBits.ContainsUnexpandedParameterPack = true;
136
137 SubExprs[i++] = initializer;
138 }
139
Benjamin Kramerc215e762012-08-24 11:54:20 +0000140 for (unsigned j = 0; j != placementArgs.size(); ++j) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000141 if (placementArgs[j]->isInstantiationDependent())
142 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000143 if (placementArgs[j]->containsUnexpandedParameterPack())
144 ExprBits.ContainsUnexpandedParameterPack = true;
145
Sebastian Redlbd150f42008-11-21 19:14:01 +0000146 SubExprs[i++] = placementArgs[j];
Douglas Gregora6e053e2010-12-15 01:34:56 +0000147 }
David Blaikie3a0de212012-11-08 22:53:48 +0000148
149 switch (getInitializationStyle()) {
150 case CallInit:
151 this->Range.setEnd(DirectInitRange.getEnd()); break;
152 case ListInit:
153 this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
Eli Friedman2dcbdc02013-06-17 22:35:10 +0000154 default:
155 if (TypeIdParens.isValid())
156 this->Range.setEnd(TypeIdParens.getEnd());
157 break;
David Blaikie3a0de212012-11-08 22:53:48 +0000158 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000159}
160
Craig Toppera31a8822013-08-22 07:09:37 +0000161void CXXNewExpr::AllocateArgsArray(const ASTContext &C, bool isArray,
Sebastian Redl6047f072012-02-16 12:22:20 +0000162 unsigned numPlaceArgs, bool hasInitializer){
Craig Topper36250ad2014-05-12 05:36:57 +0000163 assert(SubExprs == nullptr && "SubExprs already allocated");
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000164 Array = isArray;
165 NumPlacementArgs = numPlaceArgs;
Sebastian Redl6047f072012-02-16 12:22:20 +0000166
167 unsigned TotalSize = Array + hasInitializer + NumPlacementArgs;
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000168 SubExprs = new (C) Stmt*[TotalSize];
169}
170
Craig Toppera31a8822013-08-22 07:09:37 +0000171bool CXXNewExpr::shouldNullCheckAllocation(const ASTContext &Ctx) const {
Richard Smitheaf11ad2018-05-03 03:58:32 +0000172 return getOperatorNew()->getType()->castAs<FunctionProtoType>()
173 ->isNothrow() &&
Richard Smith902a0232015-02-14 01:52:20 +0000174 !getOperatorNew()->isReservedGlobalPlacementOperator();
John McCall75f94982011-03-07 03:12:35 +0000175}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000176
Sebastian Redlbd150f42008-11-21 19:14:01 +0000177// CXXDeleteExpr
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000178QualType CXXDeleteExpr::getDestroyedType() const {
179 const Expr *Arg = getArgument();
Richard Smith5b349582017-10-13 01:55:36 +0000180
181 // For a destroying operator delete, we may have implicitly converted the
182 // pointer type to the type of the parameter of the 'operator delete'
183 // function.
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000184 while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
Richard Smith5b349582017-10-13 01:55:36 +0000185 if (ICE->getCastKind() == CK_DerivedToBase ||
186 ICE->getCastKind() == CK_UncheckedDerivedToBase ||
187 ICE->getCastKind() == CK_NoOp) {
188 assert((ICE->getCastKind() == CK_NoOp ||
189 getOperatorDelete()->isDestroyingOperatorDelete()) &&
190 "only a destroying operator delete can have a converted arg");
191 Arg = ICE->getSubExpr();
192 } else
193 break;
194 }
195
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000196 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000197 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000198
199 if (ArgType->isDependentType() && !ArgType->isPointerType())
200 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000201
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000202 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000203}
204
Douglas Gregorad8a3362009-09-04 17:36:40 +0000205// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000206PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000207 : Type(Info) {
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000208 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000209}
210
Craig Toppera31a8822013-08-22 07:09:37 +0000211CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000212 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
213 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
214 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
215 PseudoDestructorTypeStorage DestroyedType)
John McCalldb40c7f2010-12-14 08:05:40 +0000216 : Expr(CXXPseudoDestructorExprClass,
David Majnemerced8bdf2015-02-25 17:36:15 +0000217 Context.BoundMemberTy,
John McCalldb40c7f2010-12-14 08:05:40 +0000218 VK_RValue, OK_Ordinary,
219 /*isTypeDependent=*/(Base->isTypeDependent() ||
220 (DestroyedType.getTypeSourceInfo() &&
221 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000222 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000223 (Base->isInstantiationDependent() ||
224 (QualifierLoc &&
225 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
226 (ScopeType &&
227 ScopeType->getType()->isInstantiationDependentType()) ||
228 (DestroyedType.getTypeSourceInfo() &&
229 DestroyedType.getTypeSourceInfo()->getType()
230 ->isInstantiationDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000231 // ContainsUnexpandedParameterPack
232 (Base->containsUnexpandedParameterPack() ||
Douglas Gregora6ce6082011-02-25 18:19:59 +0000233 (QualifierLoc &&
234 QualifierLoc.getNestedNameSpecifier()
235 ->containsUnexpandedParameterPack()) ||
Douglas Gregora6e053e2010-12-15 01:34:56 +0000236 (ScopeType &&
237 ScopeType->getType()->containsUnexpandedParameterPack()) ||
238 (DestroyedType.getTypeSourceInfo() &&
239 DestroyedType.getTypeSourceInfo()->getType()
240 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000241 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000242 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000243 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
Eugene Zelenko821f6982017-11-18 01:47:41 +0000244 DestroyedType(DestroyedType) {}
John McCalldb40c7f2010-12-14 08:05:40 +0000245
Douglas Gregor678f90d2010-02-25 01:56:36 +0000246QualType CXXPseudoDestructorExpr::getDestroyedType() const {
247 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
248 return TInfo->getType();
249
250 return QualType();
251}
252
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000253SourceLocation CXXPseudoDestructorExpr::getLocEnd() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000254 SourceLocation End = DestroyedType.getLocation();
255 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000256 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000257 return End;
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000258}
259
John McCalld14a8642009-11-21 08:51:07 +0000260// UnresolvedLookupExpr
John McCalle66edc12009-11-24 19:00:30 +0000261UnresolvedLookupExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000262UnresolvedLookupExpr::Create(const ASTContext &C,
John McCall58cc69d2010-01-27 01:50:18 +0000263 CXXRecordDecl *NamingClass,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000264 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000265 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000266 const DeclarationNameInfo &NameInfo,
267 bool ADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000268 const TemplateArgumentListInfo *Args,
269 UnresolvedSetIterator Begin,
Eugene Zelenko821f6982017-11-18 01:47:41 +0000270 UnresolvedSetIterator End) {
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000271 assert(Args || TemplateKWLoc.isValid());
272 unsigned num_args = Args ? Args->size() : 0;
James Y Knighte7d82282015-12-29 18:15:14 +0000273
274 std::size_t Size =
275 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(1,
276 num_args);
Benjamin Kramerc3f89252016-10-20 14:27:22 +0000277 void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr));
Abramo Bagnara7945c982012-01-27 09:46:47 +0000278 return new (Mem) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
279 TemplateKWLoc, NameInfo,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000280 ADL, /*Overload*/ true, Args,
Richard Smithb6626742012-10-18 17:56:02 +0000281 Begin, End);
John McCalle66edc12009-11-24 19:00:30 +0000282}
283
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000284UnresolvedLookupExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000285UnresolvedLookupExpr::CreateEmpty(const ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000286 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +0000287 unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +0000288 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
289 std::size_t Size =
290 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
291 HasTemplateKWAndArgsInfo, NumTemplateArgs);
Benjamin Kramerc3f89252016-10-20 14:27:22 +0000292 void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000293 auto *E = new (Mem) UnresolvedLookupExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +0000294 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000295 return E;
296}
297
Craig Toppera31a8822013-08-22 07:09:37 +0000298OverloadExpr::OverloadExpr(StmtClass K, const ASTContext &C,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000299 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000300 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000301 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000302 const TemplateArgumentListInfo *TemplateArgs,
Douglas Gregorc69978f2010-05-23 19:36:40 +0000303 UnresolvedSetIterator Begin,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000304 UnresolvedSetIterator End,
305 bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000306 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000307 bool KnownContainsUnexpandedParameterPack)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000308 : Expr(K, C.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
309 KnownDependent,
310 (KnownInstantiationDependent ||
311 NameInfo.isInstantiationDependent() ||
312 (QualifierLoc &&
313 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
314 (KnownContainsUnexpandedParameterPack ||
315 NameInfo.containsUnexpandedParameterPack() ||
316 (QualifierLoc &&
317 QualifierLoc.getNestedNameSpecifier()
318 ->containsUnexpandedParameterPack()))),
319 NameInfo(NameInfo), QualifierLoc(QualifierLoc), NumResults(End - Begin),
320 HasTemplateKWAndArgsInfo(TemplateArgs != nullptr ||
321 TemplateKWLoc.isValid()) {
Douglas Gregora6e053e2010-12-15 01:34:56 +0000322 NumResults = End - Begin;
323 if (NumResults) {
324 // Determine whether this expression is type-dependent.
325 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
326 if ((*I)->getDeclContext()->isDependentContext() ||
327 isa<UnresolvedUsingValueDecl>(*I)) {
328 ExprBits.TypeDependent = true;
329 ExprBits.ValueDependent = true;
Richard Smith47726b22012-08-13 21:29:18 +0000330 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000331 }
332 }
333
Benjamin Kramerc3f89252016-10-20 14:27:22 +0000334 Results = static_cast<DeclAccessPair *>(C.Allocate(
335 sizeof(DeclAccessPair) * NumResults, alignof(DeclAccessPair)));
Benjamin Kramer04ec7e32015-02-01 20:31:36 +0000336 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
Douglas Gregora6e053e2010-12-15 01:34:56 +0000337 }
338
339 // If we have explicit template arguments, check for dependent
340 // template arguments and whether they contain any unexpanded pack
341 // expansions.
342 if (TemplateArgs) {
343 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000344 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000345 bool ContainsUnexpandedParameterPack = false;
James Y Knighte7d82282015-12-29 18:15:14 +0000346 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
347 TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(),
348 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000349
350 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000351 ExprBits.TypeDependent = true;
352 ExprBits.ValueDependent = true;
353 }
354 if (InstantiationDependent)
355 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000356 if (ContainsUnexpandedParameterPack)
357 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000358 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +0000359 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000360 }
361
362 if (isTypeDependent())
363 setType(C.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000364}
365
Craig Toppera31a8822013-08-22 07:09:37 +0000366void OverloadExpr::initializeResults(const ASTContext &C,
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000367 UnresolvedSetIterator Begin,
368 UnresolvedSetIterator End) {
Craig Topper36250ad2014-05-12 05:36:57 +0000369 assert(!Results && "Results already initialized!");
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000370 NumResults = End - Begin;
Douglas Gregorc69978f2010-05-23 19:36:40 +0000371 if (NumResults) {
Benjamin Kramerc3f89252016-10-20 14:27:22 +0000372 Results = static_cast<DeclAccessPair *>(
373 C.Allocate(sizeof(DeclAccessPair) * NumResults,
374
375 alignof(DeclAccessPair)));
376 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
Douglas Gregorc69978f2010-05-23 19:36:40 +0000377 }
378}
379
John McCall8c12dc42010-04-22 18:44:12 +0000380CXXRecordDecl *OverloadExpr::getNamingClass() const {
381 if (isa<UnresolvedLookupExpr>(this))
382 return cast<UnresolvedLookupExpr>(this)->getNamingClass();
383 else
384 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
385}
386
John McCall8cd78132009-11-19 22:55:06 +0000387// DependentScopeDeclRefExpr
Douglas Gregora6e053e2010-12-15 01:34:56 +0000388DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000389 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000390 SourceLocation TemplateKWLoc,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000391 const DeclarationNameInfo &NameInfo,
392 const TemplateArgumentListInfo *Args)
393 : Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
394 true, true,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000395 (NameInfo.isInstantiationDependent() ||
396 (QualifierLoc &&
397 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000398 (NameInfo.containsUnexpandedParameterPack() ||
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000399 (QualifierLoc &&
400 QualifierLoc.getNestedNameSpecifier()
401 ->containsUnexpandedParameterPack()))),
402 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
Craig Topper36250ad2014-05-12 05:36:57 +0000403 HasTemplateKWAndArgsInfo(Args != nullptr || TemplateKWLoc.isValid())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000404{
405 if (Args) {
406 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000407 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000408 bool ContainsUnexpandedParameterPack
409 = ExprBits.ContainsUnexpandedParameterPack;
James Y Knighte7d82282015-12-29 18:15:14 +0000410 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
411 TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(),
412 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000413 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000414 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +0000415 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
416 TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000417 }
418}
419
John McCalle66edc12009-11-24 19:00:30 +0000420DependentScopeDeclRefExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000421DependentScopeDeclRefExpr::Create(const ASTContext &C,
Douglas Gregor3a43fd62011-02-25 20:49:16 +0000422 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000423 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000424 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +0000425 const TemplateArgumentListInfo *Args) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +0000426 assert(QualifierLoc && "should be created for dependent qualifiers");
James Y Knighte7d82282015-12-29 18:15:14 +0000427 bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
428 std::size_t Size =
429 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
430 HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
431 void *Mem = C.Allocate(Size);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000432 return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
433 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000434}
435
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000436DependentScopeDeclRefExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000437DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000438 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000439 unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +0000440 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
441 std::size_t Size =
442 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
443 HasTemplateKWAndArgsInfo, NumTemplateArgs);
444 void *Mem = C.Allocate(Size);
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000445 auto *E =
446 new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
Abramo Bagnara7945c982012-01-27 09:46:47 +0000447 SourceLocation(),
Craig Topper36250ad2014-05-12 05:36:57 +0000448 DeclarationNameInfo(), nullptr);
Abramo Bagnara7945c982012-01-27 09:46:47 +0000449 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000450 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000451}
452
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000453SourceLocation CXXConstructExpr::getLocStart() const {
John McCall701417a2011-02-21 06:23:05 +0000454 if (isa<CXXTemporaryObjectExpr>(this))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000455 return cast<CXXTemporaryObjectExpr>(this)->getLocStart();
456 return Loc;
457}
458
459SourceLocation CXXConstructExpr::getLocEnd() const {
460 if (isa<CXXTemporaryObjectExpr>(this))
461 return cast<CXXTemporaryObjectExpr>(this)->getLocEnd();
John McCall701417a2011-02-21 06:23:05 +0000462
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000463 if (ParenOrBraceRange.isValid())
464 return ParenOrBraceRange.getEnd();
Douglas Gregor15417cf2010-11-03 00:35:38 +0000465
466 SourceLocation End = Loc;
467 for (unsigned I = getNumArgs(); I > 0; --I) {
468 const Expr *Arg = getArg(I-1);
469 if (!Arg->isDefaultArgument()) {
470 SourceLocation NewEnd = Arg->getLocEnd();
471 if (NewEnd.isValid()) {
472 End = NewEnd;
473 break;
474 }
475 }
476 }
477
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000478 return End;
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000479}
480
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000481SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregor993603d2008-11-14 16:09:21 +0000482 OverloadedOperatorKind Kind = getOperator();
483 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
484 if (getNumArgs() == 1)
485 // Prefix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000486 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000487 else
488 // Postfix operator
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000489 return SourceRange(getArg(0)->getLocStart(), getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000490 } else if (Kind == OO_Arrow) {
491 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000492 } else if (Kind == OO_Call) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000493 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000494 } else if (Kind == OO_Subscript) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000495 return SourceRange(getArg(0)->getLocStart(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000496 } else if (getNumArgs() == 1) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000497 return SourceRange(getOperatorLoc(), getArg(0)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000498 } else if (getNumArgs() == 2) {
Argyrios Kyrtzidis5f20a7e2012-05-01 22:19:11 +0000499 return SourceRange(getArg(0)->getLocStart(), getArg(1)->getLocEnd());
Douglas Gregor993603d2008-11-14 16:09:21 +0000500 } else {
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000501 return getOperatorLoc();
Douglas Gregor993603d2008-11-14 16:09:21 +0000502 }
503}
504
Ted Kremenek98a24e32011-03-30 17:41:19 +0000505Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose16fe35e2012-08-03 23:08:39 +0000506 const Expr *Callee = getCallee()->IgnoreParens();
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000507 if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000508 return MemExpr->getBase();
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000509 if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
Jordan Rose16fe35e2012-08-03 23:08:39 +0000510 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
511 return BO->getLHS();
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000512
513 // FIXME: Will eventually need to cope with member pointers.
Craig Topper36250ad2014-05-12 05:36:57 +0000514 return nullptr;
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000515}
516
Ted Kremenek98a24e32011-03-30 17:41:19 +0000517CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000518 if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Ted Kremenek98a24e32011-03-30 17:41:19 +0000519 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
520
521 // FIXME: Will eventually need to cope with member pointers.
Craig Topper36250ad2014-05-12 05:36:57 +0000522 return nullptr;
Ted Kremenek98a24e32011-03-30 17:41:19 +0000523}
524
David Blaikiec0f58662012-05-03 16:25:49 +0000525CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth00426b42010-10-27 06:55:41 +0000526 Expr* ThisArg = getImplicitObjectArgument();
527 if (!ThisArg)
Craig Topper36250ad2014-05-12 05:36:57 +0000528 return nullptr;
Chandler Carruth00426b42010-10-27 06:55:41 +0000529
530 if (ThisArg->getType()->isAnyPointerType())
531 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
532
533 return ThisArg->getType()->getAsCXXRecordDecl();
534}
535
Douglas Gregore200adc2008-10-27 19:41:14 +0000536//===----------------------------------------------------------------------===//
537// Named casts
538//===----------------------------------------------------------------------===//
539
540/// getCastName - Get the name of the C++ cast being used, e.g.,
541/// "static_cast", "dynamic_cast", "reinterpret_cast", or
542/// "const_cast". The returned pointer must not be freed.
543const char *CXXNamedCastExpr::getCastName() const {
544 switch (getStmtClass()) {
545 case CXXStaticCastExprClass: return "static_cast";
546 case CXXDynamicCastExprClass: return "dynamic_cast";
547 case CXXReinterpretCastExprClass: return "reinterpret_cast";
548 case CXXConstCastExprClass: return "const_cast";
549 default: return "<invalid cast>";
550 }
551}
Douglas Gregordd04d332009-01-16 18:33:17 +0000552
Craig Toppera31a8822013-08-22 07:09:37 +0000553CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000554 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000555 CastKind K, Expr *Op,
556 const CXXCastPath *BasePath,
557 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000558 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000559 SourceLocation RParenLoc,
560 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000561 unsigned PathSize = (BasePath ? BasePath->size() : 0);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000562 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000563 auto *E =
564 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
565 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000566 if (PathSize)
567 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
568 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000569 return E;
570}
571
Craig Toppera31a8822013-08-22 07:09:37 +0000572CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C,
John McCallcf142162010-08-07 06:22:56 +0000573 unsigned PathSize) {
James Y Knight1d75c5e2015-12-30 02:27:28 +0000574 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000575 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
576}
577
Craig Toppera31a8822013-08-22 07:09:37 +0000578CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000579 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000580 CastKind K, Expr *Op,
581 const CXXCastPath *BasePath,
582 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000583 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000584 SourceLocation RParenLoc,
585 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000586 unsigned PathSize = (BasePath ? BasePath->size() : 0);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000587 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000588 auto *E =
589 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
590 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000591 if (PathSize)
592 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
593 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000594 return E;
595}
596
Craig Toppera31a8822013-08-22 07:09:37 +0000597CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C,
John McCallcf142162010-08-07 06:22:56 +0000598 unsigned PathSize) {
James Y Knight1d75c5e2015-12-30 02:27:28 +0000599 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000600 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
601}
602
Anders Carlsson267c0c92011-04-11 01:43:55 +0000603/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
604/// to always be null. For example:
605///
606/// struct A { };
607/// struct B final : A { };
608/// struct C { };
609///
610/// C *f(B* b) { return dynamic_cast<C*>(b); }
611bool CXXDynamicCastExpr::isAlwaysNull() const
612{
613 QualType SrcType = getSubExpr()->getType();
614 QualType DestType = getType();
615
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000616 if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
Anders Carlsson267c0c92011-04-11 01:43:55 +0000617 SrcType = SrcPTy->getPointeeType();
618 DestType = DestType->castAs<PointerType>()->getPointeeType();
619 }
620
Alexis Hunt78e2b912012-06-19 23:44:55 +0000621 if (DestType->isVoidType())
622 return false;
623
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000624 const auto *SrcRD =
625 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
Anders Carlsson267c0c92011-04-11 01:43:55 +0000626
Jakob Stoklund Olesene1c0ae62012-06-19 21:48:43 +0000627 if (!SrcRD->hasAttr<FinalAttr>())
628 return false;
629
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000630 const auto *DestRD =
631 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
Anders Carlsson267c0c92011-04-11 01:43:55 +0000632
633 return !DestRD->isDerivedFrom(SrcRD);
634}
635
John McCallcf142162010-08-07 06:22:56 +0000636CXXReinterpretCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000637CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
638 ExprValueKind VK, CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000639 const CXXCastPath *BasePath,
Douglas Gregor4478f852011-01-12 22:41:29 +0000640 TypeSourceInfo *WrittenTy, SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000641 SourceLocation RParenLoc,
642 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000643 unsigned PathSize = (BasePath ? BasePath->size() : 0);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000644 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000645 auto *E =
646 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
647 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000648 if (PathSize)
649 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
650 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000651 return E;
652}
653
654CXXReinterpretCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000655CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
James Y Knight1d75c5e2015-12-30 02:27:28 +0000656 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000657 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
658}
659
Craig Toppera31a8822013-08-22 07:09:37 +0000660CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000661 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000662 TypeSourceInfo *WrittenTy,
Douglas Gregor4478f852011-01-12 22:41:29 +0000663 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000664 SourceLocation RParenLoc,
665 SourceRange AngleBrackets) {
666 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
John McCallcf142162010-08-07 06:22:56 +0000667}
668
Craig Toppera31a8822013-08-22 07:09:37 +0000669CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) {
John McCallcf142162010-08-07 06:22:56 +0000670 return new (C) CXXConstCastExpr(EmptyShell());
671}
672
673CXXFunctionalCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000674CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
Eli Friedman89fe0d52013-08-15 22:02:56 +0000675 TypeSourceInfo *Written, CastKind K, Expr *Op,
676 const CXXCastPath *BasePath,
677 SourceLocation L, SourceLocation R) {
John McCallcf142162010-08-07 06:22:56 +0000678 unsigned PathSize = (BasePath ? BasePath->size() : 0);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000679 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000680 auto *E =
681 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000682 if (PathSize)
683 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
684 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000685 return E;
686}
687
688CXXFunctionalCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000689CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
James Y Knight1d75c5e2015-12-30 02:27:28 +0000690 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000691 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
692}
693
Eli Friedman89fe0d52013-08-15 22:02:56 +0000694SourceLocation CXXFunctionalCastExpr::getLocStart() const {
695 return getTypeInfoAsWritten()->getTypeLoc().getLocStart();
696}
697
698SourceLocation CXXFunctionalCastExpr::getLocEnd() const {
699 return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd();
700}
701
Richard Smithc67fdd42012-03-07 08:35:16 +0000702UserDefinedLiteral::LiteralOperatorKind
703UserDefinedLiteral::getLiteralOperatorKind() const {
704 if (getNumArgs() == 0)
705 return LOK_Template;
706 if (getNumArgs() == 2)
707 return LOK_String;
708
709 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
710 QualType ParamTy =
711 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
712 if (ParamTy->isPointerType())
713 return LOK_Raw;
714 if (ParamTy->isAnyCharacterType())
715 return LOK_Character;
716 if (ParamTy->isIntegerType())
717 return LOK_Integer;
718 if (ParamTy->isFloatingType())
719 return LOK_Floating;
720
721 llvm_unreachable("unknown kind of literal operator");
722}
723
724Expr *UserDefinedLiteral::getCookedLiteral() {
725#ifndef NDEBUG
726 LiteralOperatorKind LOK = getLiteralOperatorKind();
727 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
728#endif
729 return getArg(0);
730}
731
732const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
733 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
734}
John McCallcf142162010-08-07 06:22:56 +0000735
Craig Toppera31a8822013-08-22 07:09:37 +0000736CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc,
Richard Smith852c9db2013-04-20 22:23:05 +0000737 FieldDecl *Field, QualType T)
738 : Expr(CXXDefaultInitExprClass, T.getNonLValueExprType(C),
739 T->isLValueReferenceType() ? VK_LValue : T->isRValueReferenceType()
740 ? VK_XValue
741 : VK_RValue,
742 /*FIXME*/ OK_Ordinary, false, false, false, false),
743 Field(Field), Loc(Loc) {
744 assert(Field->hasInClassInitializer());
745}
746
Craig Toppera31a8822013-08-22 07:09:37 +0000747CXXTemporary *CXXTemporary::Create(const ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000748 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000749 return new (C) CXXTemporary(Destructor);
750}
751
Craig Toppera31a8822013-08-22 07:09:37 +0000752CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000753 CXXTemporary *Temp,
754 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000755 assert((SubExpr->getType()->isRecordType() ||
756 SubExpr->getType()->isArrayType()) &&
757 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000758
Douglas Gregora6e053e2010-12-15 01:34:56 +0000759 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000760}
761
Craig Toppera31a8822013-08-22 07:09:37 +0000762CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(const ASTContext &C,
Anders Carlsson56c5bd82009-04-24 05:23:13 +0000763 CXXConstructorDecl *Cons,
Richard Smith60437622017-02-09 19:17:44 +0000764 QualType Type,
765 TypeSourceInfo *TSI,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000766 ArrayRef<Expr*> Args,
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000767 SourceRange ParenOrBraceRange,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000768 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +0000769 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +0000770 bool StdInitListInitialization,
Douglas Gregor199db362010-04-27 20:36:09 +0000771 bool ZeroInitialization)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000772 : CXXConstructExpr(C, CXXTemporaryObjectExprClass, Type,
773 TSI->getTypeLoc().getBeginLoc(), Cons, false, Args,
774 HadMultipleCandidates, ListInitialization,
775 StdInitListInitialization, ZeroInitialization,
776 CXXConstructExpr::CK_Complete, ParenOrBraceRange),
777 Type(TSI) {}
Douglas Gregor2b88c112010-09-08 00:15:04 +0000778
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000779SourceLocation CXXTemporaryObjectExpr::getLocStart() const {
780 return Type->getTypeLoc().getBeginLoc();
781}
782
783SourceLocation CXXTemporaryObjectExpr::getLocEnd() const {
Argyrios Kyrtzidis623ecfd2013-09-11 23:23:27 +0000784 SourceLocation Loc = getParenOrBraceRange().getEnd();
785 if (Loc.isInvalid() && getNumArgs())
786 Loc = getArg(getNumArgs()-1)->getLocEnd();
787 return Loc;
Douglas Gregordd04d332009-01-16 18:33:17 +0000788}
Anders Carlsson6f287832009-04-21 02:22:11 +0000789
Craig Toppera31a8822013-08-22 07:09:37 +0000790CXXConstructExpr *CXXConstructExpr::Create(const ASTContext &C, QualType T,
Douglas Gregor85dabae2009-12-16 01:38:02 +0000791 SourceLocation Loc,
Richard Smithc2bebe92016-05-11 20:37:46 +0000792 CXXConstructorDecl *Ctor,
793 bool Elidable,
Benjamin Kramerc215e762012-08-24 11:54:20 +0000794 ArrayRef<Expr*> Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000795 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000796 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +0000797 bool StdInitListInitialization,
Douglas Gregor7ae2d772010-01-31 09:12:51 +0000798 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000799 ConstructionKind ConstructKind,
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000800 SourceRange ParenOrBraceRange) {
Richard Smithc2bebe92016-05-11 20:37:46 +0000801 return new (C) CXXConstructExpr(C, CXXConstructExprClass, T, Loc,
Richard Smithc83bf822016-06-10 00:58:19 +0000802 Ctor, Elidable, Args,
Sebastian Redla9351792012-02-11 23:51:47 +0000803 HadMultipleCandidates, ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +0000804 StdInitListInitialization,
Sebastian Redla9351792012-02-11 23:51:47 +0000805 ZeroInitialization, ConstructKind,
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000806 ParenOrBraceRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +0000807}
808
Craig Toppera31a8822013-08-22 07:09:37 +0000809CXXConstructExpr::CXXConstructExpr(const ASTContext &C, StmtClass SC,
810 QualType T, SourceLocation Loc,
Richard Smithc83bf822016-06-10 00:58:19 +0000811 CXXConstructorDecl *Ctor,
Richard Smithc2bebe92016-05-11 20:37:46 +0000812 bool Elidable,
813 ArrayRef<Expr*> Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000814 bool HadMultipleCandidates,
Sebastian Redla9351792012-02-11 23:51:47 +0000815 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +0000816 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +0000817 bool ZeroInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +0000818 ConstructionKind ConstructKind,
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000819 SourceRange ParenOrBraceRange)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000820 : Expr(SC, T, VK_RValue, OK_Ordinary,
821 T->isDependentType(), T->isDependentType(),
822 T->isInstantiationDependentType(),
823 T->containsUnexpandedParameterPack()),
824 Constructor(Ctor), Loc(Loc), ParenOrBraceRange(ParenOrBraceRange),
825 NumArgs(Args.size()), Elidable(Elidable),
826 HadMultipleCandidates(HadMultipleCandidates),
827 ListInitialization(ListInitialization),
828 StdInitListInitialization(StdInitListInitialization),
829 ZeroInitialization(ZeroInitialization), ConstructKind(ConstructKind) {
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000830 if (NumArgs) {
Richard Smithc2bebe92016-05-11 20:37:46 +0000831 this->Args = new (C) Stmt*[Args.size()];
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000832
Richard Smithc2bebe92016-05-11 20:37:46 +0000833 for (unsigned i = 0; i != Args.size(); ++i) {
834 assert(Args[i] && "NULL argument in CXXConstructExpr");
Douglas Gregora6e053e2010-12-15 01:34:56 +0000835
Richard Smithc2bebe92016-05-11 20:37:46 +0000836 if (Args[i]->isValueDependent())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000837 ExprBits.ValueDependent = true;
Richard Smithc2bebe92016-05-11 20:37:46 +0000838 if (Args[i]->isInstantiationDependent())
Douglas Gregor678d76c2011-07-01 01:22:09 +0000839 ExprBits.InstantiationDependent = true;
Richard Smithc2bebe92016-05-11 20:37:46 +0000840 if (Args[i]->containsUnexpandedParameterPack())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000841 ExprBits.ContainsUnexpandedParameterPack = true;
842
Richard Smithc2bebe92016-05-11 20:37:46 +0000843 this->Args[i] = Args[i];
Anders Carlsson0781ce72009-04-23 02:32:43 +0000844 }
Douglas Gregor4f4b1862009-12-16 18:50:27 +0000845 }
Anders Carlsson0781ce72009-04-23 02:32:43 +0000846}
847
Benjamin Kramerf3ca26982014-05-10 16:31:55 +0000848LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
Douglas Gregore31e6062012-02-07 10:09:13 +0000849 LambdaCaptureKind Kind, VarDecl *Var,
850 SourceLocation EllipsisLoc)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000851 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000852 unsigned Bits = 0;
853 if (Implicit)
854 Bits |= Capture_Implicit;
855
856 switch (Kind) {
Faisal Validc6b5962016-03-21 09:25:37 +0000857 case LCK_StarThis:
858 Bits |= Capture_ByCopy;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +0000859 LLVM_FALLTHROUGH;
Craig Topper36250ad2014-05-12 05:36:57 +0000860 case LCK_This:
861 assert(!Var && "'this' capture cannot have a variable!");
John Brawn771721c2016-06-15 14:14:51 +0000862 Bits |= Capture_This;
Douglas Gregore31e6062012-02-07 10:09:13 +0000863 break;
864
865 case LCK_ByCopy:
866 Bits |= Capture_ByCopy;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +0000867 LLVM_FALLTHROUGH;
Douglas Gregore31e6062012-02-07 10:09:13 +0000868 case LCK_ByRef:
869 assert(Var && "capture must have a variable!");
870 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +0000871 case LCK_VLAType:
872 assert(!Var && "VLA type capture cannot have a variable!");
Alexey Bataev39c81e22014-08-28 04:28:19 +0000873 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000874 }
John Brawn771721c2016-06-15 14:14:51 +0000875 DeclAndBits.setInt(Bits);
Douglas Gregore31e6062012-02-07 10:09:13 +0000876}
877
Benjamin Kramerf3ca26982014-05-10 16:31:55 +0000878LambdaCaptureKind LambdaCapture::getCaptureKind() const {
John Brawn771721c2016-06-15 14:14:51 +0000879 if (capturesVLAType())
Faisal Validc6b5962016-03-21 09:25:37 +0000880 return LCK_VLAType;
John Brawn771721c2016-06-15 14:14:51 +0000881 bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
882 if (capturesThis())
Faisal Validc6b5962016-03-21 09:25:37 +0000883 return CapByCopy ? LCK_StarThis : LCK_This;
Alexey Bataev39c81e22014-08-28 04:28:19 +0000884 return CapByCopy ? LCK_ByCopy : LCK_ByRef;
Douglas Gregore31e6062012-02-07 10:09:13 +0000885}
886
James Y Knighte00a67e2015-12-31 04:18:25 +0000887LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
Douglas Gregore31e6062012-02-07 10:09:13 +0000888 LambdaCaptureDefault CaptureDefault,
James Dennettddd36ff2013-08-09 23:08:25 +0000889 SourceLocation CaptureDefaultLoc,
James Y Knighte00a67e2015-12-31 04:18:25 +0000890 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
891 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
Richard Smith2589b9802012-07-25 03:56:55 +0000892 SourceLocation ClosingBrace,
893 bool ContainsUnexpandedParameterPack)
James Y Knighte00a67e2015-12-31 04:18:25 +0000894 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(),
895 T->isDependentType(), T->isDependentType(),
896 ContainsUnexpandedParameterPack),
897 IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
898 NumCaptures(Captures.size()), CaptureDefault(CaptureDefault),
899 ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType),
900 ClosingBrace(ClosingBrace) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000901 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorc8a73492012-02-13 15:44:47 +0000902 CXXRecordDecl *Class = getLambdaClass();
903 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Douglas Gregorc8a73492012-02-13 15:44:47 +0000904
905 // FIXME: Propagate "has unexpanded parameter pack" bit.
Douglas Gregore5561632012-02-13 17:20:40 +0000906
907 // Copy captures.
Craig Toppera31a8822013-08-22 07:09:37 +0000908 const ASTContext &Context = Class->getASTContext();
Douglas Gregore5561632012-02-13 17:20:40 +0000909 Data.NumCaptures = NumCaptures;
910 Data.NumExplicitCaptures = 0;
James Y Knighte00a67e2015-12-31 04:18:25 +0000911 Data.Captures =
912 (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures);
913 LambdaCapture *ToCapture = Data.Captures;
Douglas Gregore5561632012-02-13 17:20:40 +0000914 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
915 if (Captures[I].isExplicit())
916 ++Data.NumExplicitCaptures;
917
918 *ToCapture++ = Captures[I];
919 }
920
921 // Copy initialization expressions for the non-static data members.
922 Stmt **Stored = getStoredStmts();
923 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
924 *Stored++ = CaptureInits[I];
925
926 // Copy the body of the lambda.
927 *Stored++ = getCallOperator()->getBody();
Douglas Gregore31e6062012-02-07 10:09:13 +0000928}
929
James Y Knighte00a67e2015-12-31 04:18:25 +0000930LambdaExpr *LambdaExpr::Create(
931 const ASTContext &Context, CXXRecordDecl *Class,
932 SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault,
933 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
934 bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
James Y Knighte00a67e2015-12-31 04:18:25 +0000935 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) {
Douglas Gregore31e6062012-02-07 10:09:13 +0000936 // Determine the type of the expression (i.e., the type of the
937 // function object we're creating).
938 QualType T = Context.getTypeDeclType(Class);
Douglas Gregore31e6062012-02-07 10:09:13 +0000939
Richard Smith30e304e2016-12-14 00:03:17 +0000940 unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1);
Douglas Gregore5561632012-02-13 17:20:40 +0000941 void *Mem = Context.Allocate(Size);
Richard Smith30e304e2016-12-14 00:03:17 +0000942 return new (Mem)
943 LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
944 Captures, ExplicitParams, ExplicitResultType, CaptureInits,
945 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregore31e6062012-02-07 10:09:13 +0000946}
947
Craig Toppera31a8822013-08-22 07:09:37 +0000948LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C,
Richard Smith30e304e2016-12-14 00:03:17 +0000949 unsigned NumCaptures) {
950 unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
Douglas Gregor99ae8062012-02-14 17:54:36 +0000951 void *Mem = C.Allocate(Size);
Richard Smith30e304e2016-12-14 00:03:17 +0000952 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
Douglas Gregor99ae8062012-02-14 17:54:36 +0000953}
954
James Dennettdd2ffea22015-05-07 18:48:18 +0000955bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
956 return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
957 (getCallOperator() == C->getCapturedVar()->getDeclContext()));
958}
959
Douglas Gregorc8a73492012-02-13 15:44:47 +0000960LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000961 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000962}
963
964LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregore5561632012-02-13 17:20:40 +0000965 return capture_begin() + NumCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000966}
967
James Dennett1575cb42014-05-27 19:13:04 +0000968LambdaExpr::capture_range LambdaExpr::captures() const {
969 return capture_range(capture_begin(), capture_end());
970}
971
Douglas Gregorc8a73492012-02-13 15:44:47 +0000972LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
973 return capture_begin();
974}
975
976LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
977 struct CXXRecordDecl::LambdaDefinitionData &Data
978 = getLambdaClass()->getLambdaData();
Douglas Gregore5561632012-02-13 17:20:40 +0000979 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +0000980}
981
James Dennett1575cb42014-05-27 19:13:04 +0000982LambdaExpr::capture_range LambdaExpr::explicit_captures() const {
983 return capture_range(explicit_capture_begin(), explicit_capture_end());
984}
985
Douglas Gregorc8a73492012-02-13 15:44:47 +0000986LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
987 return explicit_capture_end();
988}
989
990LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
991 return capture_end();
992}
993
James Dennett1575cb42014-05-27 19:13:04 +0000994LambdaExpr::capture_range LambdaExpr::implicit_captures() const {
995 return capture_range(implicit_capture_begin(), implicit_capture_end());
996}
997
Douglas Gregore31e6062012-02-07 10:09:13 +0000998CXXRecordDecl *LambdaExpr::getLambdaClass() const {
999 return getType()->getAsCXXRecordDecl();
1000}
1001
1002CXXMethodDecl *LambdaExpr::getCallOperator() const {
1003 CXXRecordDecl *Record = getLambdaClass();
Faisal Vali2b391ab2013-09-26 19:54:12 +00001004 return Record->getLambdaCallOperator();
1005}
1006
1007TemplateParameterList *LambdaExpr::getTemplateParameterList() const {
1008 CXXRecordDecl *Record = getLambdaClass();
1009 return Record->getGenericLambdaTemplateParameterList();
1010
Douglas Gregore31e6062012-02-07 10:09:13 +00001011}
1012
Douglas Gregor99ae8062012-02-14 17:54:36 +00001013CompoundStmt *LambdaExpr::getBody() const {
James Y Knight53c76162015-07-17 18:21:37 +00001014 // FIXME: this mutation in getBody is bogus. It should be
1015 // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
1016 // don't understand, that doesn't work.
Douglas Gregor99ae8062012-02-14 17:54:36 +00001017 if (!getStoredStmts()[NumCaptures])
Eugene Zelenko821f6982017-11-18 01:47:41 +00001018 *const_cast<Stmt **>(&getStoredStmts()[NumCaptures]) =
James Y Knight53c76162015-07-17 18:21:37 +00001019 getCallOperator()->getBody();
1020
James Y Knighte00a67e2015-12-31 04:18:25 +00001021 return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001022}
1023
Douglas Gregore31e6062012-02-07 10:09:13 +00001024bool LambdaExpr::isMutable() const {
David Blaikief5697e52012-08-10 00:55:35 +00001025 return !getCallOperator()->isConst();
Douglas Gregore31e6062012-02-07 10:09:13 +00001026}
1027
John McCall28fc7092011-11-10 05:35:25 +00001028ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
Tim Shen4a05bb82016-06-21 20:29:17 +00001029 bool CleanupsHaveSideEffects,
John McCall28fc7092011-11-10 05:35:25 +00001030 ArrayRef<CleanupObject> objects)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001031 : Expr(ExprWithCleanupsClass, subexpr->getType(),
1032 subexpr->getValueKind(), subexpr->getObjectKind(),
1033 subexpr->isTypeDependent(), subexpr->isValueDependent(),
1034 subexpr->isInstantiationDependent(),
1035 subexpr->containsUnexpandedParameterPack()),
1036 SubExpr(subexpr) {
Tim Shen4a05bb82016-06-21 20:29:17 +00001037 ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
John McCall28fc7092011-11-10 05:35:25 +00001038 ExprWithCleanupsBits.NumObjects = objects.size();
1039 for (unsigned i = 0, e = objects.size(); i != e; ++i)
James Y Knighte00a67e2015-12-31 04:18:25 +00001040 getTrailingObjects<CleanupObject>()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +00001041}
1042
Craig Toppera31a8822013-08-22 07:09:37 +00001043ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr,
Tim Shen4a05bb82016-06-21 20:29:17 +00001044 bool CleanupsHaveSideEffects,
John McCall28fc7092011-11-10 05:35:25 +00001045 ArrayRef<CleanupObject> objects) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001046 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001047 alignof(ExprWithCleanups));
Tim Shen4a05bb82016-06-21 20:29:17 +00001048 return new (buffer)
1049 ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
Chris Lattnercba86142010-05-10 00:25:06 +00001050}
1051
John McCall28fc7092011-11-10 05:35:25 +00001052ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001053 : Expr(ExprWithCleanupsClass, empty) {
John McCall28fc7092011-11-10 05:35:25 +00001054 ExprWithCleanupsBits.NumObjects = numObjects;
1055}
Chris Lattnercba86142010-05-10 00:25:06 +00001056
Craig Toppera31a8822013-08-22 07:09:37 +00001057ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C,
1058 EmptyShell empty,
John McCall28fc7092011-11-10 05:35:25 +00001059 unsigned numObjects) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001060 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001061 alignof(ExprWithCleanups));
John McCall28fc7092011-11-10 05:35:25 +00001062 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +00001063}
1064
Douglas Gregor2b88c112010-09-08 00:15:04 +00001065CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001066 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001067 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001068 SourceLocation RParenLoc)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001069 : Expr(CXXUnresolvedConstructExprClass,
1070 Type->getType().getNonReferenceType(),
1071 (Type->getType()->isLValueReferenceType()
1072 ? VK_LValue
1073 : Type->getType()->isRValueReferenceType() ? VK_XValue
1074 : VK_RValue),
1075 OK_Ordinary,
1076 Type->getType()->isDependentType() ||
1077 Type->getType()->getContainedDeducedType(),
1078 true, true, Type->getType()->containsUnexpandedParameterPack()),
1079 Type(Type), LParenLoc(LParenLoc), RParenLoc(RParenLoc),
1080 NumArgs(Args.size()) {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001081 auto **StoredArgs = getTrailingObjects<Expr *>();
Benjamin Kramerc215e762012-08-24 11:54:20 +00001082 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001083 if (Args[I]->containsUnexpandedParameterPack())
1084 ExprBits.ContainsUnexpandedParameterPack = true;
1085
1086 StoredArgs[I] = Args[I];
1087 }
Douglas Gregorce934142009-05-20 18:46:25 +00001088}
1089
1090CXXUnresolvedConstructExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001091CXXUnresolvedConstructExpr::Create(const ASTContext &C,
Douglas Gregor2b88c112010-09-08 00:15:04 +00001092 TypeSourceInfo *Type,
Douglas Gregorce934142009-05-20 18:46:25 +00001093 SourceLocation LParenLoc,
Benjamin Kramerc215e762012-08-24 11:54:20 +00001094 ArrayRef<Expr*> Args,
Douglas Gregorce934142009-05-20 18:46:25 +00001095 SourceLocation RParenLoc) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001096 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
Benjamin Kramerc215e762012-08-24 11:54:20 +00001097 return new (Mem) CXXUnresolvedConstructExpr(Type, LParenLoc, Args, RParenLoc);
Douglas Gregorce934142009-05-20 18:46:25 +00001098}
1099
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001100CXXUnresolvedConstructExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001101CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &C, unsigned NumArgs) {
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001102 Stmt::EmptyShell Empty;
James Y Knighte00a67e2015-12-31 04:18:25 +00001103 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001104 return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
1105}
1106
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +00001107SourceLocation CXXUnresolvedConstructExpr::getLocStart() const {
1108 return Type->getTypeLoc().getBeginLoc();
Douglas Gregor2b88c112010-09-08 00:15:04 +00001109}
1110
James Y Knighte7d82282015-12-29 18:15:14 +00001111CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1112 const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
1113 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1114 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1115 DeclarationNameInfo MemberNameInfo,
1116 const TemplateArgumentListInfo *TemplateArgs)
1117 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, VK_LValue,
1118 OK_Ordinary, true, true, true,
1119 ((Base && Base->containsUnexpandedParameterPack()) ||
1120 (QualifierLoc &&
1121 QualifierLoc.getNestedNameSpecifier()
1122 ->containsUnexpandedParameterPack()) ||
1123 MemberNameInfo.containsUnexpandedParameterPack())),
1124 Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1125 HasTemplateKWAndArgsInfo(TemplateArgs != nullptr ||
1126 TemplateKWLoc.isValid()),
1127 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
1128 FirstQualifierFoundInScope(FirstQualifierFoundInScope),
1129 MemberNameInfo(MemberNameInfo) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001130 if (TemplateArgs) {
1131 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +00001132 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001133 bool ContainsUnexpandedParameterPack = false;
James Y Knighte7d82282015-12-29 18:15:14 +00001134 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1135 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1136 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001137 if (ContainsUnexpandedParameterPack)
1138 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001139 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001140 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1141 TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001142 }
Douglas Gregor308047d2009-09-09 00:23:06 +00001143}
1144
John McCall8cd78132009-11-19 22:55:06 +00001145CXXDependentScopeMemberExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001146CXXDependentScopeMemberExpr::Create(const ASTContext &C,
John McCall2d74de92009-12-01 22:10:20 +00001147 Expr *Base, QualType BaseType, bool IsArrow,
Douglas Gregor308047d2009-09-09 00:23:06 +00001148 SourceLocation OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001149 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001150 SourceLocation TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00001151 NamedDecl *FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001152 DeclarationNameInfo MemberNameInfo,
John McCall6b51f282009-11-23 01:53:49 +00001153 const TemplateArgumentListInfo *TemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +00001154 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
Abramo Bagnara7945c982012-01-27 09:46:47 +00001155 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
James Y Knighte7d82282015-12-29 18:15:14 +00001156 std::size_t Size =
1157 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1158 HasTemplateKWAndArgsInfo, NumTemplateArgs);
John McCall6b51f282009-11-23 01:53:49 +00001159
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001160 void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
John McCall2d74de92009-12-01 22:10:20 +00001161 return new (Mem) CXXDependentScopeMemberExpr(C, Base, BaseType,
1162 IsArrow, OperatorLoc,
Douglas Gregore16af532011-02-28 18:50:33 +00001163 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001164 TemplateKWLoc,
John McCall2d74de92009-12-01 22:10:20 +00001165 FirstQualifierFoundInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001166 MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001167}
1168
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001169CXXDependentScopeMemberExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001170CXXDependentScopeMemberExpr::CreateEmpty(const ASTContext &C,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001171 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001172 unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +00001173 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1174 std::size_t Size =
1175 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1176 HasTemplateKWAndArgsInfo, NumTemplateArgs);
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001177 void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001178 auto *E =
1179 new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(),
1180 false, SourceLocation(),
1181 NestedNameSpecifierLoc(),
1182 SourceLocation(), nullptr,
1183 DeclarationNameInfo(), nullptr);
James Y Knighte7d82282015-12-29 18:15:14 +00001184 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001185 return E;
1186}
1187
Douglas Gregor0da1d432011-02-28 20:01:57 +00001188bool CXXDependentScopeMemberExpr::isImplicitAccess() const {
Craig Topper36250ad2014-05-12 05:36:57 +00001189 if (!Base)
Douglas Gregor0da1d432011-02-28 20:01:57 +00001190 return true;
1191
Douglas Gregor25b7e052011-03-02 21:06:53 +00001192 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001193}
1194
John McCall0009fcc2011-04-26 20:42:42 +00001195static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1196 UnresolvedSetIterator end) {
1197 do {
1198 NamedDecl *decl = *begin;
1199 if (isa<UnresolvedUsingValueDecl>(decl))
1200 return false;
John McCall0009fcc2011-04-26 20:42:42 +00001201
1202 // Unresolved member expressions should only contain methods and
1203 // method templates.
Alp Tokera2794f92014-01-22 07:29:52 +00001204 if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1205 ->isStatic())
John McCall0009fcc2011-04-26 20:42:42 +00001206 return false;
1207 } while (++begin != end);
1208
1209 return true;
1210}
1211
Craig Toppera31a8822013-08-22 07:09:37 +00001212UnresolvedMemberExpr::UnresolvedMemberExpr(const ASTContext &C,
John McCall10eae182009-11-30 22:42:35 +00001213 bool HasUnresolvedUsing,
John McCall2d74de92009-12-01 22:10:20 +00001214 Expr *Base, QualType BaseType,
1215 bool IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001216 SourceLocation OperatorLoc,
Douglas Gregor0da1d432011-02-28 20:01:57 +00001217 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001218 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001219 const DeclarationNameInfo &MemberNameInfo,
Douglas Gregor30a4f4c2010-05-23 18:57:34 +00001220 const TemplateArgumentListInfo *TemplateArgs,
1221 UnresolvedSetIterator Begin,
1222 UnresolvedSetIterator End)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001223 : OverloadExpr(
1224 UnresolvedMemberExprClass, C, QualifierLoc, TemplateKWLoc,
1225 MemberNameInfo, TemplateArgs, Begin, End,
1226 // Dependent
1227 ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1228 ((Base && Base->isInstantiationDependent()) ||
1229 BaseType->isInstantiationDependentType()),
1230 // Contains unexpanded parameter pack
1231 ((Base && Base->containsUnexpandedParameterPack()) ||
1232 BaseType->containsUnexpandedParameterPack())),
1233 IsArrow(IsArrow), HasUnresolvedUsing(HasUnresolvedUsing), Base(Base),
1234 BaseType(BaseType), OperatorLoc(OperatorLoc) {
John McCall0009fcc2011-04-26 20:42:42 +00001235 // Check whether all of the members are non-static member functions,
1236 // and if so, mark give this bound-member type instead of overload type.
1237 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1238 setType(C.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +00001239}
1240
Douglas Gregor0da1d432011-02-28 20:01:57 +00001241bool UnresolvedMemberExpr::isImplicitAccess() const {
Craig Topper36250ad2014-05-12 05:36:57 +00001242 if (!Base)
Douglas Gregor0da1d432011-02-28 20:01:57 +00001243 return true;
1244
Douglas Gregor25b7e052011-03-02 21:06:53 +00001245 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001246}
1247
James Y Knighte7d82282015-12-29 18:15:14 +00001248UnresolvedMemberExpr *UnresolvedMemberExpr::Create(
1249 const ASTContext &C, bool HasUnresolvedUsing, Expr *Base, QualType BaseType,
1250 bool IsArrow, SourceLocation OperatorLoc,
1251 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1252 const DeclarationNameInfo &MemberNameInfo,
1253 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1254 UnresolvedSetIterator End) {
1255 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1256 std::size_t Size =
1257 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1258 HasTemplateKWAndArgsInfo, TemplateArgs ? TemplateArgs->size() : 0);
John McCall10eae182009-11-30 22:42:35 +00001259
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001260 void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr));
James Y Knighte7d82282015-12-29 18:15:14 +00001261 return new (Mem) UnresolvedMemberExpr(
1262 C, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc,
1263 TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +00001264}
1265
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001266UnresolvedMemberExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001267UnresolvedMemberExpr::CreateEmpty(const ASTContext &C,
1268 bool HasTemplateKWAndArgsInfo,
Douglas Gregor87866ce2011-02-04 12:01:24 +00001269 unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +00001270 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1271 std::size_t Size =
1272 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
1273 HasTemplateKWAndArgsInfo, NumTemplateArgs);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001274
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001275 void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001276 auto *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
Abramo Bagnara7945c982012-01-27 09:46:47 +00001277 E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001278 return E;
1279}
1280
John McCall58cc69d2010-01-27 01:50:18 +00001281CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
1282 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1283
1284 // If there was a nested name specifier, it names the naming class.
1285 // It can't be dependent: after all, we were actually able to do the
1286 // lookup.
Craig Topper36250ad2014-05-12 05:36:57 +00001287 CXXRecordDecl *Record = nullptr;
Nikola Smiljanic67860242014-09-26 00:28:20 +00001288 auto *NNS = getQualifier();
1289 if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
John McCall424cec92011-01-19 06:33:43 +00001290 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001291 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001292 Record = T->getAsCXXRecordDecl();
1293 assert(Record && "qualifier in member expression does not name record");
1294 }
John McCall58cc69d2010-01-27 01:50:18 +00001295 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001296 else {
John McCall58cc69d2010-01-27 01:50:18 +00001297 QualType BaseType = getBaseType().getNonReferenceType();
1298 if (isArrow()) {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001299 const auto *PT = BaseType->getAs<PointerType>();
John McCall58cc69d2010-01-27 01:50:18 +00001300 assert(PT && "base of arrow member access is not pointer");
1301 BaseType = PT->getPointeeType();
1302 }
1303
Douglas Gregor9262f472010-04-27 18:19:34 +00001304 Record = BaseType->getAsCXXRecordDecl();
1305 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001306 }
1307
Douglas Gregor9262f472010-04-27 18:19:34 +00001308 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001309}
1310
Richard Smithd784e682015-09-23 21:41:42 +00001311SizeOfPackExpr *
1312SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc,
1313 NamedDecl *Pack, SourceLocation PackLoc,
1314 SourceLocation RParenLoc,
1315 Optional<unsigned> Length,
1316 ArrayRef<TemplateArgument> PartialArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001317 void *Storage =
1318 Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
Richard Smithd784e682015-09-23 21:41:42 +00001319 return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1320 PackLoc, RParenLoc, Length, PartialArgs);
1321}
1322
1323SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
1324 unsigned NumPartialArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001325 void *Storage =
1326 Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
Richard Smithd784e682015-09-23 21:41:42 +00001327 return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1328}
1329
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001330SubstNonTypeTemplateParmPackExpr::
1331SubstNonTypeTemplateParmPackExpr(QualType T,
Richard Smithf1f20e62018-02-14 02:07:53 +00001332 ExprValueKind ValueKind,
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001333 NonTypeTemplateParmDecl *Param,
1334 SourceLocation NameLoc,
1335 const TemplateArgument &ArgPack)
Richard Smithf1f20e62018-02-14 02:07:53 +00001336 : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary,
Eugene Zelenko821f6982017-11-18 01:47:41 +00001337 true, true, true, true),
1338 Param(Param), Arguments(ArgPack.pack_begin()),
1339 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {}
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001340
1341TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
Benjamin Kramercce63472015-08-05 09:40:22 +00001342 return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001343}
1344
Richard Smithb15fe3a2012-09-12 00:56:43 +00001345FunctionParmPackExpr::FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
1346 SourceLocation NameLoc,
1347 unsigned NumParams,
James Y Knight48fefa32015-09-30 14:04:23 +00001348 ParmVarDecl *const *Params)
1349 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
1350 true, true),
1351 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
Richard Smithb15fe3a2012-09-12 00:56:43 +00001352 if (Params)
1353 std::uninitialized_copy(Params, Params + NumParams,
James Y Knighte00a67e2015-12-31 04:18:25 +00001354 getTrailingObjects<ParmVarDecl *>());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001355}
1356
1357FunctionParmPackExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001358FunctionParmPackExpr::Create(const ASTContext &Context, QualType T,
Richard Smithb15fe3a2012-09-12 00:56:43 +00001359 ParmVarDecl *ParamPack, SourceLocation NameLoc,
James Y Knight48fefa32015-09-30 14:04:23 +00001360 ArrayRef<ParmVarDecl *> Params) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001361 return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(Params.size())))
1362 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001363}
1364
1365FunctionParmPackExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001366FunctionParmPackExpr::CreateEmpty(const ASTContext &Context,
1367 unsigned NumParams) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001368 return new (Context.Allocate(totalSizeToAlloc<ParmVarDecl *>(NumParams)))
1369 FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001370}
1371
David Majnemerdaff3702014-05-01 17:50:17 +00001372void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy,
1373 unsigned ManglingNumber) {
1374 // We only need extra state if we have to remember more than just the Stmt.
1375 if (!ExtendedBy)
1376 return;
1377
1378 // We may need to allocate extra storage for the mangling number and the
1379 // extended-by ValueDecl.
1380 if (!State.is<ExtraState *>()) {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001381 auto *ES = new (ExtendedBy->getASTContext()) ExtraState;
David Majnemerdaff3702014-05-01 17:50:17 +00001382 ES->Temporary = State.get<Stmt *>();
1383 State = ES;
1384 }
1385
1386 auto ES = State.get<ExtraState *>();
1387 ES->ExtendingDecl = ExtendedBy;
1388 ES->ManglingNumber = ManglingNumber;
1389}
1390
Douglas Gregor29c42f22012-02-24 07:38:34 +00001391TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1392 ArrayRef<TypeSourceInfo *> Args,
1393 SourceLocation RParenLoc,
1394 bool Value)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001395 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1396 /*TypeDependent=*/false,
1397 /*ValueDependent=*/false,
1398 /*InstantiationDependent=*/false,
1399 /*ContainsUnexpandedParameterPack=*/false),
1400 Loc(Loc), RParenLoc(RParenLoc) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00001401 TypeTraitExprBits.Kind = Kind;
1402 TypeTraitExprBits.Value = Value;
1403 TypeTraitExprBits.NumArgs = Args.size();
1404
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001405 auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
James Y Knighte00a67e2015-12-31 04:18:25 +00001406
Douglas Gregor29c42f22012-02-24 07:38:34 +00001407 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1408 if (Args[I]->getType()->isDependentType())
1409 setValueDependent(true);
1410 if (Args[I]->getType()->isInstantiationDependentType())
1411 setInstantiationDependent(true);
1412 if (Args[I]->getType()->containsUnexpandedParameterPack())
1413 setContainsUnexpandedParameterPack(true);
1414
1415 ToArgs[I] = Args[I];
1416 }
1417}
1418
Craig Toppera31a8822013-08-22 07:09:37 +00001419TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
Douglas Gregor29c42f22012-02-24 07:38:34 +00001420 SourceLocation Loc,
1421 TypeTrait Kind,
1422 ArrayRef<TypeSourceInfo *> Args,
1423 SourceLocation RParenLoc,
1424 bool Value) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001425 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001426 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1427}
1428
Craig Toppera31a8822013-08-22 07:09:37 +00001429TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
Douglas Gregor29c42f22012-02-24 07:38:34 +00001430 unsigned NumArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001431 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001432 return new (Mem) TypeTraitExpr(EmptyShell());
1433}
1434
Eugene Zelenko821f6982017-11-18 01:47:41 +00001435void ArrayTypeTraitExpr::anchor() {}