clang 17.0.0git
ExprCXX.cpp
Go to the documentation of this file.
1//===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Expr class declared in ExprCXX.h
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/ExprCXX.h"
15#include "clang/AST/Attr.h"
17#include "clang/AST/Decl.h"
19#include "clang/AST/DeclBase.h"
20#include "clang/AST/DeclCXX.h"
24#include "clang/AST/Expr.h"
28#include "clang/AST/Type.h"
29#include "clang/AST/TypeLoc.h"
30#include "clang/Basic/LLVM.h"
34#include "llvm/ADT/ArrayRef.h"
35#include "llvm/Support/Casting.h"
36#include "llvm/Support/ErrorHandling.h"
37#include <cassert>
38#include <cstddef>
39#include <cstring>
40#include <memory>
41#include <optional>
42
43using namespace clang;
44
45//===----------------------------------------------------------------------===//
46// Child Iterators for iterating over subexpressions/substatements
47//===----------------------------------------------------------------------===//
48
50 // An infix binary operator is any operator with two arguments other than
51 // operator() and operator[]. Note that none of these operators can have
52 // default arguments, so it suffices to check the number of argument
53 // expressions.
54 if (getNumArgs() != 2)
55 return false;
56
57 switch (getOperator()) {
58 case OO_Call: case OO_Subscript:
59 return false;
60 default:
61 return true;
62 }
63}
64
68 const Expr *E = getSemanticForm()->IgnoreImplicit();
69
70 // Remove an outer '!' if it exists (only happens for a '!=' rewrite).
71 bool SkippedNot = false;
72 if (auto *NotEq = dyn_cast<UnaryOperator>(E)) {
73 assert(NotEq->getOpcode() == UO_LNot);
74 E = NotEq->getSubExpr()->IgnoreImplicit();
75 SkippedNot = true;
76 }
77
78 // Decompose the outer binary operator.
79 if (auto *BO = dyn_cast<BinaryOperator>(E)) {
80 assert(!SkippedNot || BO->getOpcode() == BO_EQ);
81 Result.Opcode = SkippedNot ? BO_NE : BO->getOpcode();
82 Result.LHS = BO->getLHS();
83 Result.RHS = BO->getRHS();
84 Result.InnerBinOp = BO;
85 } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
86 assert(!SkippedNot || BO->getOperator() == OO_EqualEqual);
87 assert(BO->isInfixBinaryOp());
88 switch (BO->getOperator()) {
89 case OO_Less: Result.Opcode = BO_LT; break;
90 case OO_LessEqual: Result.Opcode = BO_LE; break;
91 case OO_Greater: Result.Opcode = BO_GT; break;
92 case OO_GreaterEqual: Result.Opcode = BO_GE; break;
93 case OO_Spaceship: Result.Opcode = BO_Cmp; break;
94 case OO_EqualEqual: Result.Opcode = SkippedNot ? BO_NE : BO_EQ; break;
95 default: llvm_unreachable("unexpected binop in rewritten operator expr");
96 }
97 Result.LHS = BO->getArg(0);
98 Result.RHS = BO->getArg(1);
99 Result.InnerBinOp = BO;
100 } else {
101 llvm_unreachable("unexpected rewritten operator form");
102 }
103
104 // Put the operands in the right order for == and !=, and canonicalize the
105 // <=> subexpression onto the LHS for all other forms.
106 if (isReversed())
107 std::swap(Result.LHS, Result.RHS);
108
109 // If this isn't a spaceship rewrite, we're done.
110 if (Result.Opcode == BO_EQ || Result.Opcode == BO_NE)
111 return Result;
112
113 // Otherwise, we expect a <=> to now be on the LHS.
114 E = Result.LHS->IgnoreImplicitAsWritten();
115 if (auto *BO = dyn_cast<BinaryOperator>(E)) {
116 assert(BO->getOpcode() == BO_Cmp);
117 Result.LHS = BO->getLHS();
118 Result.RHS = BO->getRHS();
119 Result.InnerBinOp = BO;
120 } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
121 assert(BO->getOperator() == OO_Spaceship);
122 Result.LHS = BO->getArg(0);
123 Result.RHS = BO->getArg(1);
124 Result.InnerBinOp = BO;
125 } else {
126 llvm_unreachable("unexpected rewritten operator form");
127 }
128
129 // Put the comparison operands in the right order.
130 if (isReversed())
131 std::swap(Result.LHS, Result.RHS);
132 return Result;
133}
134
136 if (isTypeOperand())
137 return false;
138
139 // C++11 [expr.typeid]p3:
140 // When typeid is applied to an expression other than a glvalue of
141 // polymorphic class type, [...] the expression is an unevaluated operand.
142 const Expr *E = getExprOperand();
143 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
144 if (RD->isPolymorphic() && E->isGLValue())
145 return true;
146
147 return false;
148}
149
151 assert(!isTypeOperand() && "Cannot call isMostDerived for typeid(type)");
152 const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Context);
153 if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
154 QualType Ty = DRE->getDecl()->getType();
155 if (!Ty->isPointerType() && !Ty->isReferenceType())
156 return true;
157 }
158
159 return false;
160}
161
163 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
164 Qualifiers Quals;
165 return Context.getUnqualifiedArrayType(
166 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
167}
168
170 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
171 Qualifiers Quals;
172 return Context.getUnqualifiedArrayType(
173 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
174}
175
176// CXXScalarValueInitExpr
178 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
179}
180
181// CXXNewExpr
182CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
183 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
184 bool UsualArrayDeleteWantsSize,
185 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
186 std::optional<Expr *> ArraySize,
187 InitializationStyle InitializationStyle,
189 TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
190 SourceRange DirectInitRange)
191 : Expr(CXXNewExprClass, Ty, VK_PRValue, OK_Ordinary),
192 OperatorNew(OperatorNew), OperatorDelete(OperatorDelete),
193 AllocatedTypeInfo(AllocatedTypeInfo), Range(Range),
194 DirectInitRange(DirectInitRange) {
195
196 assert((Initializer != nullptr || InitializationStyle == NoInit) &&
197 "Only NoInit can have no initializer!");
198
199 CXXNewExprBits.IsGlobalNew = IsGlobalNew;
200 CXXNewExprBits.IsArray = ArraySize.has_value();
201 CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment;
202 CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
203 CXXNewExprBits.StoredInitializationStyle =
204 Initializer ? InitializationStyle + 1 : 0;
205 bool IsParenTypeId = TypeIdParens.isValid();
206 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
207 CXXNewExprBits.NumPlacementArgs = PlacementArgs.size();
208
209 if (ArraySize)
210 getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
211 if (Initializer)
212 getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
213 for (unsigned I = 0; I != PlacementArgs.size(); ++I)
214 getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
215 PlacementArgs[I];
216 if (IsParenTypeId)
217 getTrailingObjects<SourceRange>()[0] = TypeIdParens;
218
219 switch (getInitializationStyle()) {
220 case CallInit:
221 this->Range.setEnd(DirectInitRange.getEnd());
222 break;
223 case ListInit:
224 this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
225 break;
226 default:
227 if (IsParenTypeId)
228 this->Range.setEnd(TypeIdParens.getEnd());
229 break;
230 }
231
233}
234
235CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
236 unsigned NumPlacementArgs, bool IsParenTypeId)
237 : Expr(CXXNewExprClass, Empty) {
238 CXXNewExprBits.IsArray = IsArray;
239 CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
240 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
241}
242
244CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
245 FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
246 bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
247 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
248 std::optional<Expr *> ArraySize,
250 QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
251 SourceRange Range, SourceRange DirectInitRange) {
252 bool IsArray = ArraySize.has_value();
253 bool HasInit = Initializer != nullptr;
254 unsigned NumPlacementArgs = PlacementArgs.size();
255 bool IsParenTypeId = TypeIdParens.isValid();
256 void *Mem =
257 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
258 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
259 alignof(CXXNewExpr));
260 return new (Mem)
261 CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
262 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
263 ArraySize, InitializationStyle, Initializer, Ty,
264 AllocatedTypeInfo, Range, DirectInitRange);
265}
266
268 bool HasInit, unsigned NumPlacementArgs,
269 bool IsParenTypeId) {
270 void *Mem =
271 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
272 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
273 alignof(CXXNewExpr));
274 return new (Mem)
275 CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
276}
277
279 return !getOperatorNew()->hasAttr<ReturnsNonNullAttr>() &&
281 ->getType()
283 ->isNothrow() &&
285}
286
287// CXXDeleteExpr
289 const Expr *Arg = getArgument();
290
291 // For a destroying operator delete, we may have implicitly converted the
292 // pointer type to the type of the parameter of the 'operator delete'
293 // function.
294 while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
295 if (ICE->getCastKind() == CK_DerivedToBase ||
296 ICE->getCastKind() == CK_UncheckedDerivedToBase ||
297 ICE->getCastKind() == CK_NoOp) {
298 assert((ICE->getCastKind() == CK_NoOp ||
299 getOperatorDelete()->isDestroyingOperatorDelete()) &&
300 "only a destroying operator delete can have a converted arg");
301 Arg = ICE->getSubExpr();
302 } else
303 break;
304 }
305
306 // The type-to-delete may not be a pointer if it's a dependent type.
307 const QualType ArgType = Arg->getType();
308
309 if (ArgType->isDependentType() && !ArgType->isPointerType())
310 return QualType();
311
312 return ArgType->castAs<PointerType>()->getPointeeType();
313}
314
315// CXXPseudoDestructorExpr
317 : Type(Info) {
318 Location = Info->getTypeLoc().getBeginLoc();
319}
320
322 const ASTContext &Context, Expr *Base, bool isArrow,
323 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
324 TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc,
325 SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
326 : Expr(CXXPseudoDestructorExprClass, Context.BoundMemberTy, VK_PRValue,
328 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
329 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
330 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
331 DestroyedType(DestroyedType) {
333}
334
336 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
337 return TInfo->getType();
338
339 return QualType();
340}
341
343 SourceLocation End = DestroyedType.getLocation();
344 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
345 End = TInfo->getTypeLoc().getSourceRange().getEnd();
346 return End;
347}
348
349// UnresolvedLookupExpr
350UnresolvedLookupExpr::UnresolvedLookupExpr(
351 const ASTContext &Context, CXXRecordDecl *NamingClass,
352 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
353 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
356 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
357 TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
358 false, false),
359 NamingClass(NamingClass) {
360 UnresolvedLookupExprBits.RequiresADL = RequiresADL;
361 UnresolvedLookupExprBits.Overloaded = Overloaded;
362}
363
364UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
365 unsigned NumResults,
366 bool HasTemplateKWAndArgsInfo)
367 : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
368 HasTemplateKWAndArgsInfo) {}
369
371 const ASTContext &Context, CXXRecordDecl *NamingClass,
372 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
373 bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
375 unsigned NumResults = End - Begin;
376 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
377 TemplateArgumentLoc>(NumResults, 0, 0);
378 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
379 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
380 SourceLocation(), NameInfo, RequiresADL,
381 Overloaded, nullptr, Begin, End);
382}
383
385 const ASTContext &Context, CXXRecordDecl *NamingClass,
386 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
387 const DeclarationNameInfo &NameInfo, bool RequiresADL,
390 assert(Args || TemplateKWLoc.isValid());
391 unsigned NumResults = End - Begin;
392 unsigned NumTemplateArgs = Args ? Args->size() : 0;
393 unsigned Size =
395 TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
396 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
397 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
398 TemplateKWLoc, NameInfo, RequiresADL,
399 /*Overloaded*/ true, Args, Begin, End);
400}
401
403 const ASTContext &Context, unsigned NumResults,
404 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
405 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
406 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
408 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
409 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
410 return new (Mem)
411 UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
412}
413
415 NestedNameSpecifierLoc QualifierLoc,
416 SourceLocation TemplateKWLoc,
417 const DeclarationNameInfo &NameInfo,
418 const TemplateArgumentListInfo *TemplateArgs,
420 UnresolvedSetIterator End, bool KnownDependent,
421 bool KnownInstantiationDependent,
422 bool KnownContainsUnexpandedParameterPack)
423 : Expr(SC, Context.OverloadTy, VK_LValue, OK_Ordinary), NameInfo(NameInfo),
424 QualifierLoc(QualifierLoc) {
425 unsigned NumResults = End - Begin;
426 OverloadExprBits.NumResults = NumResults;
427 OverloadExprBits.HasTemplateKWAndArgsInfo =
428 (TemplateArgs != nullptr ) || TemplateKWLoc.isValid();
429
430 if (NumResults) {
431 // Copy the results to the trailing array past UnresolvedLookupExpr
432 // or UnresolvedMemberExpr.
434 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
435 }
436
437 if (TemplateArgs) {
438 auto Deps = TemplateArgumentDependence::None;
440 TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), Deps);
441 } else if (TemplateKWLoc.isValid()) {
443 }
444
445 setDependence(computeDependence(this, KnownDependent,
446 KnownInstantiationDependent,
447 KnownContainsUnexpandedParameterPack));
448 if (isTypeDependent())
449 setType(Context.DependentTy);
450}
451
452OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
453 bool HasTemplateKWAndArgsInfo)
454 : Expr(SC, Empty) {
455 OverloadExprBits.NumResults = NumResults;
456 OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
457}
458
459// DependentScopeDeclRefExpr
460DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
461 QualType Ty, NestedNameSpecifierLoc QualifierLoc,
462 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
463 const TemplateArgumentListInfo *Args)
464 : Expr(DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary),
465 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
466 DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
467 (Args != nullptr) || TemplateKWLoc.isValid();
468 if (Args) {
469 auto Deps = TemplateArgumentDependence::None;
470 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
471 TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), Deps);
472 } else if (TemplateKWLoc.isValid()) {
473 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
474 TemplateKWLoc);
475 }
477}
478
480 const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
481 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
482 const TemplateArgumentListInfo *Args) {
483 assert(QualifierLoc && "should be created for dependent qualifiers");
484 bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
485 std::size_t Size =
486 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
487 HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
488 void *Mem = Context.Allocate(Size);
489 return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
490 TemplateKWLoc, NameInfo, Args);
491}
492
495 bool HasTemplateKWAndArgsInfo,
496 unsigned NumTemplateArgs) {
497 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
498 std::size_t Size =
499 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
500 HasTemplateKWAndArgsInfo, NumTemplateArgs);
501 void *Mem = Context.Allocate(Size);
502 auto *E = new (Mem) DependentScopeDeclRefExpr(
504 DeclarationNameInfo(), nullptr);
505 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
506 HasTemplateKWAndArgsInfo;
507 return E;
508}
509
511 if (isa<CXXTemporaryObjectExpr>(this))
512 return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
513 return getLocation();
514}
515
517 if (isa<CXXTemporaryObjectExpr>(this))
518 return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
519
520 if (ParenOrBraceRange.isValid())
521 return ParenOrBraceRange.getEnd();
522
524 for (unsigned I = getNumArgs(); I > 0; --I) {
525 const Expr *Arg = getArg(I-1);
526 if (!Arg->isDefaultArgument()) {
527 SourceLocation NewEnd = Arg->getEndLoc();
528 if (NewEnd.isValid()) {
529 End = NewEnd;
530 break;
531 }
532 }
533 }
534
535 return End;
536}
537
538CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
539 Expr *Fn, ArrayRef<Expr *> Args,
540 QualType Ty, ExprValueKind VK,
541 SourceLocation OperatorLoc,
542 FPOptionsOverride FPFeatures,
543 ADLCallKind UsesADL)
544 : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
545 OperatorLoc, FPFeatures, /*MinNumArgs=*/0, UsesADL) {
546 CXXOperatorCallExprBits.OperatorKind = OpKind;
547 assert(
548 (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
549 "OperatorKind overflow!");
550 Range = getSourceRangeImpl();
551}
552
553CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures,
554 EmptyShell Empty)
555 : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs,
556 HasFPFeatures, Empty) {}
557
560 OverloadedOperatorKind OpKind, Expr *Fn,
561 ArrayRef<Expr *> Args, QualType Ty,
562 ExprValueKind VK, SourceLocation OperatorLoc,
563 FPOptionsOverride FPFeatures, ADLCallKind UsesADL) {
564 // Allocate storage for the trailing objects of CallExpr.
565 unsigned NumArgs = Args.size();
566 unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
567 /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
568 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
569 alignof(CXXOperatorCallExpr));
570 return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
571 FPFeatures, UsesADL);
572}
573
575 unsigned NumArgs,
576 bool HasFPFeatures,
577 EmptyShell Empty) {
578 // Allocate storage for the trailing objects of CallExpr.
579 unsigned SizeOfTrailingObjects =
580 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
581 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
582 alignof(CXXOperatorCallExpr));
583 return new (Mem) CXXOperatorCallExpr(NumArgs, HasFPFeatures, Empty);
584}
585
586SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
588 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
589 if (getNumArgs() == 1)
590 // Prefix operator
592 else
593 // Postfix operator
595 } else if (Kind == OO_Arrow) {
597 } else if (Kind == OO_Call) {
599 } else if (Kind == OO_Subscript) {
601 } else if (getNumArgs() == 1) {
603 } else if (getNumArgs() == 2) {
604 return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
605 } else {
606 return getOperatorLoc();
607 }
608}
609
610CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
611 QualType Ty, ExprValueKind VK,
614 unsigned MinNumArgs)
615 : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
616 FPOptions, MinNumArgs, NotADL) {}
617
618CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures,
619 EmptyShell Empty)
620 : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures,
621 Empty) {}
622
624 ArrayRef<Expr *> Args, QualType Ty,
625 ExprValueKind VK,
627 FPOptionsOverride FPFeatures,
628 unsigned MinNumArgs) {
629 // Allocate storage for the trailing objects of CallExpr.
630 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
631 unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
632 /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
633 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
634 alignof(CXXMemberCallExpr));
635 return new (Mem)
636 CXXMemberCallExpr(Fn, Args, Ty, VK, RP, FPFeatures, MinNumArgs);
637}
638
640 unsigned NumArgs,
641 bool HasFPFeatures,
642 EmptyShell Empty) {
643 // Allocate storage for the trailing objects of CallExpr.
644 unsigned SizeOfTrailingObjects =
645 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
646 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
647 alignof(CXXMemberCallExpr));
648 return new (Mem) CXXMemberCallExpr(NumArgs, HasFPFeatures, Empty);
649}
650
652 const Expr *Callee = getCallee()->IgnoreParens();
653 if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
654 return MemExpr->getBase();
655 if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
656 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
657 return BO->getLHS();
658
659 // FIXME: Will eventually need to cope with member pointers.
660 return nullptr;
661}
662
665 if (Ty->isPointerType())
666 Ty = Ty->getPointeeType();
667 return Ty;
668}
669
671 if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
672 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
673
674 // FIXME: Will eventually need to cope with member pointers.
675 // NOTE: Update makeTailCallIfSwiftAsync on fixing this.
676 return nullptr;
677}
678
680 Expr* ThisArg = getImplicitObjectArgument();
681 if (!ThisArg)
682 return nullptr;
683
684 if (ThisArg->getType()->isAnyPointerType())
685 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
686
687 return ThisArg->getType()->getAsCXXRecordDecl();
688}
689
690//===----------------------------------------------------------------------===//
691// Named casts
692//===----------------------------------------------------------------------===//
693
694/// getCastName - Get the name of the C++ cast being used, e.g.,
695/// "static_cast", "dynamic_cast", "reinterpret_cast", or
696/// "const_cast". The returned pointer must not be freed.
697const char *CXXNamedCastExpr::getCastName() const {
698 switch (getStmtClass()) {
699 case CXXStaticCastExprClass: return "static_cast";
700 case CXXDynamicCastExprClass: return "dynamic_cast";
701 case CXXReinterpretCastExprClass: return "reinterpret_cast";
702 case CXXConstCastExprClass: return "const_cast";
703 case CXXAddrspaceCastExprClass: return "addrspace_cast";
704 default: return "<invalid cast>";
705 }
706}
707
710 CastKind K, Expr *Op, const CXXCastPath *BasePath,
711 TypeSourceInfo *WrittenTy, FPOptionsOverride FPO,
712 SourceLocation L, SourceLocation RParenLoc,
713 SourceRange AngleBrackets) {
714 unsigned PathSize = (BasePath ? BasePath->size() : 0);
715 void *Buffer =
716 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
717 PathSize, FPO.requiresTrailingStorage()));
718 auto *E = new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy,
719 FPO, L, RParenLoc, AngleBrackets);
720 if (PathSize)
721 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
722 E->getTrailingObjects<CXXBaseSpecifier *>());
723 return E;
724}
725
727 unsigned PathSize,
728 bool HasFPFeatures) {
729 void *Buffer =
730 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
731 PathSize, HasFPFeatures));
732 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize, HasFPFeatures);
733}
734
736 ExprValueKind VK,
737 CastKind K, Expr *Op,
738 const CXXCastPath *BasePath,
739 TypeSourceInfo *WrittenTy,
741 SourceLocation RParenLoc,
742 SourceRange AngleBrackets) {
743 unsigned PathSize = (BasePath ? BasePath->size() : 0);
744 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
745 auto *E =
746 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
747 RParenLoc, AngleBrackets);
748 if (PathSize)
749 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
750 E->getTrailingObjects<CXXBaseSpecifier *>());
751 return E;
752}
753
755 unsigned PathSize) {
756 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
757 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
758}
759
760/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
761/// to always be null. For example:
762///
763/// struct A { };
764/// struct B final : A { };
765/// struct C { };
766///
767/// C *f(B* b) { return dynamic_cast<C*>(b); }
769{
770 QualType SrcType = getSubExpr()->getType();
771 QualType DestType = getType();
772
773 if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
774 SrcType = SrcPTy->getPointeeType();
775 DestType = DestType->castAs<PointerType>()->getPointeeType();
776 }
777
778 if (DestType->isVoidType())
779 return false;
780
781 const auto *SrcRD =
782 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
783
784 if (!SrcRD->hasAttr<FinalAttr>())
785 return false;
786
787 const auto *DestRD =
788 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
789
790 return !DestRD->isDerivedFrom(SrcRD);
791}
792
795 ExprValueKind VK, CastKind K, Expr *Op,
796 const CXXCastPath *BasePath,
797 TypeSourceInfo *WrittenTy, SourceLocation L,
798 SourceLocation RParenLoc,
799 SourceRange AngleBrackets) {
800 unsigned PathSize = (BasePath ? BasePath->size() : 0);
801 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
802 auto *E =
803 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
804 RParenLoc, AngleBrackets);
805 if (PathSize)
806 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
807 E->getTrailingObjects<CXXBaseSpecifier *>());
808 return E;
809}
810
813 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
814 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
815}
816
818 ExprValueKind VK, Expr *Op,
819 TypeSourceInfo *WrittenTy,
821 SourceLocation RParenLoc,
822 SourceRange AngleBrackets) {
823 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
824}
825
827 return new (C) CXXConstCastExpr(EmptyShell());
828}
829
832 CastKind K, Expr *Op, TypeSourceInfo *WrittenTy,
833 SourceLocation L, SourceLocation RParenLoc,
834 SourceRange AngleBrackets) {
835 return new (C) CXXAddrspaceCastExpr(T, VK, K, Op, WrittenTy, L, RParenLoc,
836 AngleBrackets);
837}
838
840 return new (C) CXXAddrspaceCastExpr(EmptyShell());
841}
842
844 const ASTContext &C, QualType T, ExprValueKind VK, TypeSourceInfo *Written,
845 CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
847 unsigned PathSize = (BasePath ? BasePath->size() : 0);
848 void *Buffer =
849 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
850 PathSize, FPO.requiresTrailingStorage()));
851 auto *E = new (Buffer)
852 CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, FPO, L, R);
853 if (PathSize)
854 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
855 E->getTrailingObjects<CXXBaseSpecifier *>());
856 return E;
857}
858
860 unsigned PathSize,
861 bool HasFPFeatures) {
862 void *Buffer =
863 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
864 PathSize, HasFPFeatures));
865 return new (Buffer)
866 CXXFunctionalCastExpr(EmptyShell(), PathSize, HasFPFeatures);
867}
868
871}
872
874 return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc();
875}
876
877UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args,
878 QualType Ty, ExprValueKind VK,
879 SourceLocation LitEndLoc,
880 SourceLocation SuffixLoc,
881 FPOptionsOverride FPFeatures)
882 : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
883 LitEndLoc, FPFeatures, /*MinNumArgs=*/0, NotADL),
884 UDSuffixLoc(SuffixLoc) {}
885
886UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures,
887 EmptyShell Empty)
888 : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs,
889 HasFPFeatures, Empty) {}
890
892 ArrayRef<Expr *> Args,
893 QualType Ty, ExprValueKind VK,
894 SourceLocation LitEndLoc,
895 SourceLocation SuffixLoc,
896 FPOptionsOverride FPFeatures) {
897 // Allocate storage for the trailing objects of CallExpr.
898 unsigned NumArgs = Args.size();
899 unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
900 /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
901 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
902 alignof(UserDefinedLiteral));
903 return new (Mem)
904 UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc, FPFeatures);
905}
906
908 unsigned NumArgs,
909 bool HasFPOptions,
910 EmptyShell Empty) {
911 // Allocate storage for the trailing objects of CallExpr.
912 unsigned SizeOfTrailingObjects =
913 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPOptions);
914 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
915 alignof(UserDefinedLiteral));
916 return new (Mem) UserDefinedLiteral(NumArgs, HasFPOptions, Empty);
917}
918
921 if (getNumArgs() == 0)
922 return LOK_Template;
923 if (getNumArgs() == 2)
924 return LOK_String;
925
926 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
927 QualType ParamTy =
928 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
929 if (ParamTy->isPointerType())
930 return LOK_Raw;
931 if (ParamTy->isAnyCharacterType())
932 return LOK_Character;
933 if (ParamTy->isIntegerType())
934 return LOK_Integer;
935 if (ParamTy->isFloatingType())
936 return LOK_Floating;
937
938 llvm_unreachable("unknown kind of literal operator");
939}
940
942#ifndef NDEBUG
944 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
945#endif
946 return getArg(0);
947}
948
950 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
951}
952
954 bool HasRewrittenInit) {
955 size_t Size = totalSizeToAlloc<Expr *>(HasRewrittenInit);
956 auto *Mem = C.Allocate(Size, alignof(CXXDefaultArgExpr));
957 return new (Mem) CXXDefaultArgExpr(EmptyShell(), HasRewrittenInit);
958}
959
961 SourceLocation Loc,
962 ParmVarDecl *Param,
963 Expr *RewrittenExpr,
964 DeclContext *UsedContext) {
965 size_t Size = totalSizeToAlloc<Expr *>(RewrittenExpr != nullptr);
966 auto *Mem = C.Allocate(Size, alignof(CXXDefaultArgExpr));
967 return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
968 RewrittenExpr, UsedContext);
969}
970
972 return CXXDefaultArgExprBits.HasRewrittenInit ? getAdjustedRewrittenExpr()
973 : getParam()->getDefaultArg();
974}
975
977 assert(hasRewrittenInit() &&
978 "expected this CXXDefaultArgExpr to have a rewritten init.");
979 Expr *Init = getRewrittenExpr();
980 if (auto *E = dyn_cast_if_present<FullExpr>(Init))
981 if (!isa<ConstantExpr>(E))
982 return E->getSubExpr();
983 return Init;
984}
985
986CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx,
987 SourceLocation Loc, FieldDecl *Field,
988 QualType Ty, DeclContext *UsedContext,
989 Expr *RewrittenInitExpr)
990 : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
991 Ty->isLValueReferenceType() ? VK_LValue
992 : Ty->isRValueReferenceType() ? VK_XValue
993 : VK_PRValue,
994 /*FIXME*/ OK_Ordinary),
995 Field(Field), UsedContext(UsedContext) {
996 CXXDefaultInitExprBits.Loc = Loc;
997 CXXDefaultInitExprBits.HasRewrittenInit = RewrittenInitExpr != nullptr;
998
999 if (CXXDefaultInitExprBits.HasRewrittenInit)
1000 *getTrailingObjects<Expr *>() = RewrittenInitExpr;
1001
1002 assert(Field->hasInClassInitializer());
1003
1005}
1006
1008 bool HasRewrittenInit) {
1009 size_t Size = totalSizeToAlloc<Expr *>(HasRewrittenInit);
1010 auto *Mem = C.Allocate(Size, alignof(CXXDefaultInitExpr));
1011 return new (Mem) CXXDefaultInitExpr(EmptyShell(), HasRewrittenInit);
1012}
1013
1015 SourceLocation Loc,
1016 FieldDecl *Field,
1017 DeclContext *UsedContext,
1018 Expr *RewrittenInitExpr) {
1019
1020 size_t Size = totalSizeToAlloc<Expr *>(RewrittenInitExpr != nullptr);
1021 auto *Mem = Ctx.Allocate(Size, alignof(CXXDefaultInitExpr));
1022 return new (Mem) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(),
1023 UsedContext, RewrittenInitExpr);
1024}
1025
1027 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1028 if (hasRewrittenInit())
1029 return getRewrittenExpr();
1030
1031 return Field->getInClassInitializer();
1032}
1033
1035 const CXXDestructorDecl *Destructor) {
1036 return new (C) CXXTemporary(Destructor);
1037}
1038
1040 CXXTemporary *Temp,
1041 Expr* SubExpr) {
1042 assert((SubExpr->getType()->isRecordType() ||
1043 SubExpr->getType()->isArrayType()) &&
1044 "Expression bound to a temporary must have record or array type!");
1045
1046 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
1047}
1048
1049CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
1051 ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
1052 bool HadMultipleCandidates, bool ListInitialization,
1053 bool StdInitListInitialization, bool ZeroInitialization)
1055 CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
1056 Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
1057 ListInitialization, StdInitListInitialization, ZeroInitialization,
1058 CXXConstructExpr::CK_Complete, ParenOrBraceRange),
1059 TSI(TSI) {
1061}
1062
1063CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
1064 unsigned NumArgs)
1065 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
1066
1068 const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
1069 TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
1070 bool HadMultipleCandidates, bool ListInitialization,
1071 bool StdInitListInitialization, bool ZeroInitialization) {
1072 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1073 void *Mem =
1074 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1075 alignof(CXXTemporaryObjectExpr));
1076 return new (Mem) CXXTemporaryObjectExpr(
1077 Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
1078 ListInitialization, StdInitListInitialization, ZeroInitialization);
1079}
1080
1083 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1084 void *Mem =
1085 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1086 alignof(CXXTemporaryObjectExpr));
1087 return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
1088}
1089
1092}
1093
1096 if (Loc.isInvalid() && getNumArgs())
1097 Loc = getArg(getNumArgs() - 1)->getEndLoc();
1098 return Loc;
1099}
1100
1102 const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1103 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1104 bool HadMultipleCandidates, bool ListInitialization,
1105 bool StdInitListInitialization, bool ZeroInitialization,
1106 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1107 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1108 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1109 alignof(CXXConstructExpr));
1110 return new (Mem) CXXConstructExpr(
1111 CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1112 HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1113 ZeroInitialization, ConstructKind, ParenOrBraceRange);
1114}
1115
1117 unsigned NumArgs) {
1118 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1119 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1120 alignof(CXXConstructExpr));
1121 return new (Mem)
1122 CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1123}
1124
1127 bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1128 bool ListInitialization, bool StdInitListInitialization,
1129 bool ZeroInitialization, ConstructionKind ConstructKind,
1130 SourceRange ParenOrBraceRange)
1131 : Expr(SC, Ty, VK_PRValue, OK_Ordinary), Constructor(Ctor),
1132 ParenOrBraceRange(ParenOrBraceRange), NumArgs(Args.size()) {
1133 CXXConstructExprBits.Elidable = Elidable;
1134 CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1135 CXXConstructExprBits.ListInitialization = ListInitialization;
1136 CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1137 CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1138 CXXConstructExprBits.ConstructionKind = ConstructKind;
1139 CXXConstructExprBits.Loc = Loc;
1140
1141 Stmt **TrailingArgs = getTrailingArgs();
1142 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1143 assert(Args[I] && "NULL argument in CXXConstructExpr!");
1144 TrailingArgs[I] = Args[I];
1145 }
1146
1147 // CXXTemporaryObjectExpr does this itself after setting its TypeSourceInfo.
1148 if (SC == CXXConstructExprClass)
1150}
1151
1153 unsigned NumArgs)
1154 : Expr(SC, Empty), NumArgs(NumArgs) {}
1155
1157 LambdaCaptureKind Kind, ValueDecl *Var,
1158 SourceLocation EllipsisLoc)
1159 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
1160 unsigned Bits = 0;
1161 if (Implicit)
1162 Bits |= Capture_Implicit;
1163
1164 switch (Kind) {
1165 case LCK_StarThis:
1166 Bits |= Capture_ByCopy;
1167 [[fallthrough]];
1168 case LCK_This:
1169 assert(!Var && "'this' capture cannot have a variable!");
1170 Bits |= Capture_This;
1171 break;
1172
1173 case LCK_ByCopy:
1174 Bits |= Capture_ByCopy;
1175 [[fallthrough]];
1176 case LCK_ByRef:
1177 assert(Var && "capture must have a variable!");
1178 break;
1179 case LCK_VLAType:
1180 assert(!Var && "VLA type capture cannot have a variable!");
1181 break;
1182 }
1183 DeclAndBits.setInt(Bits);
1184}
1185
1187 if (capturesVLAType())
1188 return LCK_VLAType;
1189 bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1190 if (capturesThis())
1191 return CapByCopy ? LCK_StarThis : LCK_This;
1192 return CapByCopy ? LCK_ByCopy : LCK_ByRef;
1193}
1194
1195LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
1196 LambdaCaptureDefault CaptureDefault,
1197 SourceLocation CaptureDefaultLoc, bool ExplicitParams,
1198 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1199 SourceLocation ClosingBrace,
1200 bool ContainsUnexpandedParameterPack)
1201 : Expr(LambdaExprClass, T, VK_PRValue, OK_Ordinary),
1202 IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1203 ClosingBrace(ClosingBrace) {
1204 LambdaExprBits.NumCaptures = CaptureInits.size();
1205 LambdaExprBits.CaptureDefault = CaptureDefault;
1206 LambdaExprBits.ExplicitParams = ExplicitParams;
1207 LambdaExprBits.ExplicitResultType = ExplicitResultType;
1208
1209 CXXRecordDecl *Class = getLambdaClass();
1210 (void)Class;
1211 assert(capture_size() == Class->capture_size() && "Wrong number of captures");
1212 assert(getCaptureDefault() == Class->getLambdaCaptureDefault());
1213
1214 // Copy initialization expressions for the non-static data members.
1215 Stmt **Stored = getStoredStmts();
1216 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
1217 *Stored++ = CaptureInits[I];
1218
1219 // Copy the body of the lambda.
1220 *Stored++ = getCallOperator()->getBody();
1221
1222 setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
1223}
1224
1225LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1226 : Expr(LambdaExprClass, Empty) {
1227 LambdaExprBits.NumCaptures = NumCaptures;
1228
1229 // Initially don't initialize the body of the LambdaExpr. The body will
1230 // be lazily deserialized when needed.
1231 getStoredStmts()[NumCaptures] = nullptr; // Not one past the end.
1232}
1233
1235 SourceRange IntroducerRange,
1236 LambdaCaptureDefault CaptureDefault,
1237 SourceLocation CaptureDefaultLoc,
1238 bool ExplicitParams, bool ExplicitResultType,
1239 ArrayRef<Expr *> CaptureInits,
1240 SourceLocation ClosingBrace,
1241 bool ContainsUnexpandedParameterPack) {
1242 // Determine the type of the expression (i.e., the type of the
1243 // function object we're creating).
1244 QualType T = Context.getTypeDeclType(Class);
1245
1246 unsigned Size = totalSizeToAlloc<Stmt *>(CaptureInits.size() + 1);
1247 void *Mem = Context.Allocate(Size);
1248 return new (Mem)
1249 LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1250 ExplicitParams, ExplicitResultType, CaptureInits, ClosingBrace,
1251 ContainsUnexpandedParameterPack);
1252}
1253
1255 unsigned NumCaptures) {
1256 unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
1257 void *Mem = C.Allocate(Size);
1258 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
1259}
1260
1261void LambdaExpr::initBodyIfNeeded() const {
1262 if (!getStoredStmts()[capture_size()]) {
1263 auto *This = const_cast<LambdaExpr *>(this);
1264 This->getStoredStmts()[capture_size()] = getCallOperator()->getBody();
1265 }
1266}
1267
1269 initBodyIfNeeded();
1270 return getStoredStmts()[capture_size()];
1271}
1272
1274 Stmt *Body = getBody();
1275 if (const auto *CoroBody = dyn_cast<CoroutineBodyStmt>(Body))
1276 return cast<CompoundStmt>(CoroBody->getBody());
1277 return cast<CompoundStmt>(Body);
1278}
1279
1281 return C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1282 getCallOperator() == C->getCapturedVar()->getDeclContext();
1283}
1284
1286 return getLambdaClass()->captures_begin();
1287}
1288
1290 return getLambdaClass()->captures_end();
1291}
1292
1295}
1296
1298 return capture_begin();
1299}
1300
1302 return capture_begin() +
1303 getLambdaClass()->getLambdaData().NumExplicitCaptures;
1304}
1305
1308}
1309
1311 return explicit_capture_end();
1312}
1313
1315 return capture_end();
1316}
1317
1320}
1321
1323 return getType()->getAsCXXRecordDecl();
1324}
1325
1327 CXXRecordDecl *Record = getLambdaClass();
1328 return Record->getLambdaCallOperator();
1329}
1330
1332 CXXRecordDecl *Record = getLambdaClass();
1333 return Record->getDependentLambdaCallOperator();
1334}
1335
1337 CXXRecordDecl *Record = getLambdaClass();
1338 return Record->getGenericLambdaTemplateParameterList();
1339}
1340
1342 const CXXRecordDecl *Record = getLambdaClass();
1343 return Record->getLambdaExplicitTemplateParameters();
1344}
1345
1348}
1349
1350bool LambdaExpr::isMutable() const { return !getCallOperator()->isConst(); }
1351
1353 initBodyIfNeeded();
1354 return child_range(getStoredStmts(), getStoredStmts() + capture_size() + 1);
1355}
1356
1358 initBodyIfNeeded();
1359 return const_child_range(getStoredStmts(),
1360 getStoredStmts() + capture_size() + 1);
1361}
1362
1363ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1364 bool CleanupsHaveSideEffects,
1366 : FullExpr(ExprWithCleanupsClass, subexpr) {
1367 ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
1368 ExprWithCleanupsBits.NumObjects = objects.size();
1369 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1370 getTrailingObjects<CleanupObject>()[i] = objects[i];
1371}
1372
1374 bool CleanupsHaveSideEffects,
1375 ArrayRef<CleanupObject> objects) {
1376 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1377 alignof(ExprWithCleanups));
1378 return new (buffer)
1379 ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
1380}
1381
1382ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1383 : FullExpr(ExprWithCleanupsClass, empty) {
1384 ExprWithCleanupsBits.NumObjects = numObjects;
1385}
1386
1388 EmptyShell empty,
1389 unsigned numObjects) {
1390 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1391 alignof(ExprWithCleanups));
1392 return new (buffer) ExprWithCleanups(empty, numObjects);
1393}
1394
1395CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(
1396 QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1397 ArrayRef<Expr *> Args, SourceLocation RParenLoc, bool IsListInit)
1398 : Expr(CXXUnresolvedConstructExprClass, T,
1399 (TSI->getType()->isLValueReferenceType() ? VK_LValue
1400 : TSI->getType()->isRValueReferenceType() ? VK_XValue
1401 : VK_PRValue),
1402 OK_Ordinary),
1403 TypeAndInitForm(TSI, IsListInit), LParenLoc(LParenLoc),
1404 RParenLoc(RParenLoc) {
1405 CXXUnresolvedConstructExprBits.NumArgs = Args.size();
1406 auto **StoredArgs = getTrailingObjects<Expr *>();
1407 for (unsigned I = 0; I != Args.size(); ++I)
1408 StoredArgs[I] = Args[I];
1410}
1411
1413 const ASTContext &Context, QualType T, TypeSourceInfo *TSI,
1414 SourceLocation LParenLoc, ArrayRef<Expr *> Args, SourceLocation RParenLoc,
1415 bool IsListInit) {
1416 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1417 return new (Mem) CXXUnresolvedConstructExpr(T, TSI, LParenLoc, Args,
1418 RParenLoc, IsListInit);
1419}
1420
1423 unsigned NumArgs) {
1424 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1425 return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
1426}
1427
1429 return TypeAndInitForm.getPointer()->getTypeLoc().getBeginLoc();
1430}
1431
1432CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1433 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1434 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1435 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1436 DeclarationNameInfo MemberNameInfo,
1437 const TemplateArgumentListInfo *TemplateArgs)
1438 : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
1439 OK_Ordinary),
1440 Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
1441 MemberNameInfo(MemberNameInfo) {
1442 CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1443 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1444 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1445 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1446 FirstQualifierFoundInScope != nullptr;
1447 CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1448
1449 if (TemplateArgs) {
1450 auto Deps = TemplateArgumentDependence::None;
1451 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1452 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1453 Deps);
1454 } else if (TemplateKWLoc.isValid()) {
1455 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1456 TemplateKWLoc);
1457 }
1458
1459 if (hasFirstQualifierFoundInScope())
1460 *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
1462}
1463
1464CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1465 EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
1466 bool HasFirstQualifierFoundInScope)
1467 : Expr(CXXDependentScopeMemberExprClass, Empty) {
1468 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1469 HasTemplateKWAndArgsInfo;
1470 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1471 HasFirstQualifierFoundInScope;
1472}
1473
1475 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1476 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1477 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1478 DeclarationNameInfo MemberNameInfo,
1479 const TemplateArgumentListInfo *TemplateArgs) {
1480 bool HasTemplateKWAndArgsInfo =
1481 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1482 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1483 bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr;
1484
1485 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1487 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1488
1489 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1490 return new (Mem) CXXDependentScopeMemberExpr(
1491 Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
1492 FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs);
1493}
1494
1496 const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
1497 unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) {
1498 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1499
1500 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1502 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1503
1504 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1505 return new (Mem) CXXDependentScopeMemberExpr(
1506 EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope);
1507}
1508
1511 do {
1512 NamedDecl *decl = *begin;
1513 if (isa<UnresolvedUsingValueDecl>(decl))
1514 return false;
1515
1516 // Unresolved member expressions should only contain methods and
1517 // method templates.
1518 if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1519 ->isStatic())
1520 return false;
1521 } while (++begin != end);
1522
1523 return true;
1524}
1525
1526UnresolvedMemberExpr::UnresolvedMemberExpr(
1527 const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1528 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1529 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1530 const DeclarationNameInfo &MemberNameInfo,
1533 : OverloadExpr(
1534 UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc,
1535 MemberNameInfo, TemplateArgs, Begin, End,
1536 // Dependent
1537 ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1538 ((Base && Base->isInstantiationDependent()) ||
1539 BaseType->isInstantiationDependentType()),
1540 // Contains unexpanded parameter pack
1541 ((Base && Base->containsUnexpandedParameterPack()) ||
1542 BaseType->containsUnexpandedParameterPack())),
1543 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1544 UnresolvedMemberExprBits.IsArrow = IsArrow;
1545 UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing;
1546
1547 // Check whether all of the members are non-static member functions,
1548 // and if so, mark give this bound-member type instead of overload type.
1550 setType(Context.BoundMemberTy);
1551}
1552
1553UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty,
1554 unsigned NumResults,
1555 bool HasTemplateKWAndArgsInfo)
1556 : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults,
1557 HasTemplateKWAndArgsInfo) {}
1558
1560 if (!Base)
1561 return true;
1562
1563 return cast<Expr>(Base)->isImplicitCXXThis();
1564}
1565
1567 const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1568 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1569 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1570 const DeclarationNameInfo &MemberNameInfo,
1573 unsigned NumResults = End - Begin;
1574 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1575 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1576 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1578 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1579 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1580 return new (Mem) UnresolvedMemberExpr(
1581 Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc,
1582 QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
1583}
1584
1586 const ASTContext &Context, unsigned NumResults,
1587 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
1588 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1589 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1591 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1592 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1593 return new (Mem)
1594 UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
1595}
1596
1598 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1599
1600 // If there was a nested name specifier, it names the naming class.
1601 // It can't be dependent: after all, we were actually able to do the
1602 // lookup.
1603 CXXRecordDecl *Record = nullptr;
1604 auto *NNS = getQualifier();
1605 if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
1606 const Type *T = getQualifier()->getAsType();
1607 assert(T && "qualifier in member expression does not name type");
1608 Record = T->getAsCXXRecordDecl();
1609 assert(Record && "qualifier in member expression does not name record");
1610 }
1611 // Otherwise the naming class must have been the base class.
1612 else {
1614 if (isArrow())
1615 BaseType = BaseType->castAs<PointerType>()->getPointeeType();
1616
1617 Record = BaseType->getAsCXXRecordDecl();
1618 assert(Record && "base of member expression does not name record");
1619 }
1620
1621 return Record;
1622}
1623
1625 SourceLocation OperatorLoc,
1626 NamedDecl *Pack, SourceLocation PackLoc,
1627 SourceLocation RParenLoc,
1628 std::optional<unsigned> Length,
1629 ArrayRef<TemplateArgument> PartialArgs) {
1630 void *Storage =
1631 Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1632 return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1633 PackLoc, RParenLoc, Length, PartialArgs);
1634}
1635
1637 unsigned NumPartialArgs) {
1638 void *Storage =
1639 Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1640 return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1641}
1642
1644 return cast<NonTypeTemplateParmDecl>(
1646}
1647
1649 const ASTContext &Context) const {
1650 // Note that, for a class type NTTP, we will have an lvalue of type 'const
1651 // T', so we can't just compute this from the type and value category.
1653 return Context.getLValueReferenceType(getType());
1654 return getType().getUnqualifiedType();
1655}
1656
1657SubstNonTypeTemplateParmPackExpr::SubstNonTypeTemplateParmPackExpr(
1658 QualType T, ExprValueKind ValueKind, SourceLocation NameLoc,
1659 const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index)
1660 : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary),
1661 AssociatedDecl(AssociatedDecl), Arguments(ArgPack.pack_begin()),
1662 NumArguments(ArgPack.pack_size()), Index(Index), NameLoc(NameLoc) {
1663 assert(AssociatedDecl != nullptr);
1664 setDependence(ExprDependence::TypeValueInstantiation |
1665 ExprDependence::UnexpandedPack);
1666}
1667
1670 return cast<NonTypeTemplateParmDecl>(
1672}
1673
1675 return TemplateArgument(llvm::ArrayRef(Arguments, NumArguments));
1676}
1677
1678FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
1679 SourceLocation NameLoc,
1680 unsigned NumParams,
1681 VarDecl *const *Params)
1682 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary),
1683 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1684 if (Params)
1685 std::uninitialized_copy(Params, Params + NumParams,
1686 getTrailingObjects<VarDecl *>());
1687 setDependence(ExprDependence::TypeValueInstantiation |
1688 ExprDependence::UnexpandedPack);
1689}
1690
1693 VarDecl *ParamPack, SourceLocation NameLoc,
1694 ArrayRef<VarDecl *> Params) {
1695 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
1696 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1697}
1698
1701 unsigned NumParams) {
1702 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
1703 FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1704}
1705
1707 QualType T, Expr *Temporary, bool BoundToLvalueReference,
1709 : Expr(MaterializeTemporaryExprClass, T,
1710 BoundToLvalueReference ? VK_LValue : VK_XValue, OK_Ordinary) {
1711 if (MTD) {
1712 State = MTD;
1713 MTD->ExprWithTemporary = Temporary;
1714 return;
1715 }
1716 State = Temporary;
1718}
1719
1721 unsigned ManglingNumber) {
1722 // We only need extra state if we have to remember more than just the Stmt.
1723 if (!ExtendedBy)
1724 return;
1725
1726 // We may need to allocate extra storage for the mangling number and the
1727 // extended-by ValueDecl.
1728 if (!State.is<LifetimeExtendedTemporaryDecl *>())
1730 cast<Expr>(State.get<Stmt *>()), ExtendedBy, ManglingNumber);
1731
1732 auto ES = State.get<LifetimeExtendedTemporaryDecl *>();
1733 ES->ExtendingDecl = ExtendedBy;
1734 ES->ManglingNumber = ManglingNumber;
1735}
1736
1738 const ASTContext &Context) const {
1739 // C++20 [expr.const]p4:
1740 // An object or reference is usable in constant expressions if it is [...]
1741 // a temporary object of non-volatile const-qualified literal type
1742 // whose lifetime is extended to that of a variable that is usable
1743 // in constant expressions
1744 auto *VD = dyn_cast_or_null<VarDecl>(getExtendingDecl());
1745 return VD && getType().isConstant(Context) &&
1747 getType()->isLiteralType(Context) &&
1748 VD->isUsableInConstantExpressions(Context);
1749}
1750
1751TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1753 SourceLocation RParenLoc, bool Value)
1754 : Expr(TypeTraitExprClass, T, VK_PRValue, OK_Ordinary), Loc(Loc),
1755 RParenLoc(RParenLoc) {
1756 assert(Kind <= TT_Last && "invalid enum value!");
1757 TypeTraitExprBits.Kind = Kind;
1758 assert(static_cast<unsigned>(Kind) == TypeTraitExprBits.Kind &&
1759 "TypeTraitExprBits.Kind overflow!");
1760 TypeTraitExprBits.Value = Value;
1761 TypeTraitExprBits.NumArgs = Args.size();
1762 assert(Args.size() == TypeTraitExprBits.NumArgs &&
1763 "TypeTraitExprBits.NumArgs overflow!");
1764
1765 auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1766 for (unsigned I = 0, N = Args.size(); I != N; ++I)
1767 ToArgs[I] = Args[I];
1768
1770}
1771
1773 SourceLocation Loc,
1774 TypeTrait Kind,
1776 SourceLocation RParenLoc,
1777 bool Value) {
1778 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1779 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1780}
1781
1783 unsigned NumArgs) {
1784 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1785 return new (Mem) TypeTraitExpr(EmptyShell());
1786}
1787
1788CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1789 ArrayRef<Expr *> Args, QualType Ty,
1791 FPOptionsOverride FPFeatures,
1792 unsigned MinNumArgs)
1793 : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1794 RP, FPFeatures, MinNumArgs, NotADL) {}
1795
1796CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures,
1797 EmptyShell Empty)
1798 : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1799 HasFPFeatures, Empty) {}
1800
1804 SourceLocation RP, FPOptionsOverride FPFeatures,
1805 unsigned MinNumArgs) {
1806 // Allocate storage for the trailing objects of CallExpr.
1807 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1808 unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1809 /*NumPreArgs=*/END_PREARG, NumArgs, FPFeatures.requiresTrailingStorage());
1810 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1811 alignof(CUDAKernelCallExpr));
1812 return new (Mem)
1813 CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, FPFeatures, MinNumArgs);
1814}
1815
1817 unsigned NumArgs,
1818 bool HasFPFeatures,
1819 EmptyShell Empty) {
1820 // Allocate storage for the trailing objects of CallExpr.
1821 unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1822 /*NumPreArgs=*/END_PREARG, NumArgs, HasFPFeatures);
1823 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1824 alignof(CUDAKernelCallExpr));
1825 return new (Mem) CUDAKernelCallExpr(NumArgs, HasFPFeatures, Empty);
1826}
1827
1830 unsigned NumUserSpecifiedExprs,
1831 SourceLocation InitLoc, SourceLocation LParenLoc,
1832 SourceLocation RParenLoc) {
1833 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1834 return new (Mem) CXXParenListInitExpr(Args, T, NumUserSpecifiedExprs, InitLoc,
1835 LParenLoc, RParenLoc);
1836}
1837
1839 unsigned NumExprs,
1840 EmptyShell Empty) {
1841 void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumExprs),
1842 alignof(CXXParenListInitExpr));
1843 return new (Mem) CXXParenListInitExpr(Empty, NumExprs);
1844}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin, UnresolvedSetIterator end)
Definition: ExprCXX.cpp:1509
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines an enumeration for C++ overloaded operators.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
SourceLocation Begin
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
CanQualType DependentTy
Definition: ASTContext.h:1105
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1561
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CanQualType BoundMemberTy
Definition: ASTContext.h:1105
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:704
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:231
static CUDAKernelCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Definition: ExprCXX.cpp:1816
static CUDAKernelCallExpr * Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:1802
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition: ExprCXX.h:601
static CXXAddrspaceCastExpr * CreateEmpty(const ASTContext &Context)
Definition: ExprCXX.cpp:839
static CXXAddrspaceCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:831
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1470
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1039
A C++ const_cast expression (C++ [expr.const.cast]).
Definition: ExprCXX.h:563
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:817
static CXXConstCastExpr * CreateEmpty(const ASTContext &Context)
Definition: ExprCXX.cpp:826
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1518
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1686
CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Build a C++ construction expression.
Definition: ExprCXX.cpp:1125
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, ConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:1101
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1669
SourceLocation getLocation() const
Definition: ExprCXX.h:1592
static unsigned sizeOfTrailingObjects(unsigned NumArgs)
Return the size in bytes of the trailing objects.
Definition: ExprCXX.h:1573
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:516
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:510
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1666
static CXXConstructExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs)
Create an empty C++ construction expression.
Definition: ExprCXX.cpp:1116
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2491
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1249
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1291
Expr * getAdjustedRewrittenExpr()
Definition: ExprCXX.cpp:976
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:960
static CXXDefaultArgExpr * CreateEmpty(const ASTContext &C, bool HasRewrittenInit)
Definition: ExprCXX.cpp:953
bool hasRewrittenInit() const
Definition: ExprCXX.h:1294
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1356
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.cpp:1014
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition: ExprCXX.h:1401
bool hasRewrittenInit() const
Definition: ExprCXX.h:1385
Expr * getExpr()
Get the initialization expression that will be used.
Definition: ExprCXX.cpp:1026
static CXXDefaultInitExpr * CreateEmpty(const ASTContext &C, bool HasRewrittenInit)
Definition: ExprCXX.cpp:1007
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2512
Expr * getArgument()
Definition: ExprCXX.h:2514
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:288
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3629
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1474
static CXXDependentScopeMemberExpr * CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope)
Definition: ExprCXX.cpp:1495
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2755
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:478
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:735
static CXXDynamicCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:754
bool isAlwaysNull() const
isAlwaysNull - Return whether the result of the dynamic_cast is proven to always be null.
Definition: ExprCXX.cpp:768
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition: ExprCXX.h:1787
static CXXFunctionalCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition: ExprCXX.cpp:859
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:869
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:873
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:843
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Definition: ExprCXX.cpp:670
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition: ExprCXX.cpp:651
static CXXMemberCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Definition: ExprCXX.cpp:639
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:623
QualType getObjectType() const
Retrieve the type of the object argument.
Definition: ExprCXX.cpp:663
CXXRecordDecl * getRecordDecl() const
Retrieve the CXXRecordDecl for the underlying type of the implicit object argument.
Definition: ExprCXX.cpp:679
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2035
bool isConst() const
Definition: DeclCXX.h:2076
const char * getCastName() const
getCastName - Get the name of the C++ cast being used, e.g., "static_cast", "dynamic_cast",...
Definition: ExprCXX.cpp:697
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2199
static CXXNewExpr * CreateEmpty(const ASTContext &Ctx, bool IsArray, bool HasInit, unsigned NumPlacementArgs, bool IsParenTypeId)
Create an empty c++ new expression.
Definition: ExprCXX.cpp:267
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
Definition: ExprCXX.cpp:278
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:244
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2315
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
bool isInfixBinaryOp() const
Is this written as an infix binary operator?
Definition: ExprCXX.cpp:49
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
Definition: ExprCXX.h:149
SourceLocation getEndLoc() const
Definition: ExprCXX.h:160
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:111
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:559
static CXXOperatorCallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Definition: ExprCXX.cpp:574
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:159
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4798
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition: ExprCXX.cpp:1829
static CXXParenListInitExpr * CreateEmpty(ASTContext &C, unsigned numExprs, EmptyShell Empty)
Definition: ExprCXX.cpp:1838
CXXPseudoDestructorExpr(const ASTContext &Context, Expr *Base, bool isArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
Definition: ExprCXX.cpp:321
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:342
QualType getDestroyedType() const
Retrieve the type being destroyed.
Definition: ExprCXX.cpp:335
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
capture_const_iterator captures_end() const
Definition: DeclCXX.h:1092
capture_const_iterator captures_begin() const
Definition: DeclCXX.h:1086
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition: ExprCXX.h:523
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:794
static CXXReinterpretCastExpr * CreateEmpty(const ASTContext &Context, unsigned pathSize)
Definition: ExprCXX.cpp:812
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:301
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition: ExprCXX.h:319
DecomposedForm getDecomposedForm() const LLVM_READONLY
Decompose this operator into its syntactic form.
Definition: ExprCXX.cpp:66
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:177
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:2174
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:433
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:709
static CXXStaticCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool hasFPFeatures)
Definition: ExprCXX.cpp:726
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1855
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:1067
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1884
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1094
static CXXTemporaryObjectExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs)
Definition: ExprCXX.cpp:1082
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1090
Represents a C++ temporary.
Definition: ExprCXX.h:1438
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1034
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Definition: ExprCXX.cpp:162
bool isTypeOperand() const
Definition: ExprCXX.h:881
Expr * getExprOperand() const
Definition: ExprCXX.h:892
bool isMostDerived(ASTContext &Context) const
Best-effort check if the expression operand refers to a most derived object.
Definition: ExprCXX.cpp:150
bool isPotentiallyEvaluated() const
Determine whether this typeid has a type operand which is potentially evaluated, per C++11 [expr....
Definition: ExprCXX.cpp:135
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3503
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1412
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:1428
static CXXUnresolvedConstructExpr * CreateEmpty(const ASTContext &Context, unsigned NumArgs)
Definition: ExprCXX.cpp:1422
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
Definition: ExprCXX.cpp:169
bool isTypeOperand() const
Definition: ExprCXX.h:1092
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2817
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:3008
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:2891
Expr * getCallee()
Definition: Expr.h:2967
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2995
SourceLocation getRParenLoc() const
Definition: Expr.h:3127
static constexpr ADLCallKind UsesADL
Definition: Expr.h:2875
Decl * getCalleeDecl()
Definition: Expr.h:2981
Expr * getSubExpr()
Definition: Expr.h:3537
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1424
A POD class for pairing a NamedDecl* with an access specifier.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1402
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
bool hasAttr() const
Definition: DeclBase.h:560
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:841
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3269
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:479
static DependentScopeDeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:494
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3731
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3420
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1387
This represents one expression.
Definition: Expr.h:110
bool isGLValue() const
Definition: Expr.h:274
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Definition: Expr.cpp:3082
void setType(QualType t)
Definition: Expr.h:143
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:186
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3043
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3051
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:3150
QualType getType() const
Definition: Expr.h:142
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Definition: Expr.h:135
Represents difference between two FPOptions values.
Definition: LangOptions.h:806
bool requiresTrailingStorage() const
Definition: LangOptions.h:832
Represents a member of a struct/union/class.
Definition: Decl.h:2945
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1014
Represents a function declaration or definition.
Definition: Decl.h:1917
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3138
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:3205
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4484
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl * > Params)
Definition: ExprCXX.cpp:1692
static FunctionParmPackExpr * CreateEmpty(const ASTContext &Context, unsigned NumParams)
Definition: ExprCXX.cpp:1700
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4056
Declaration of a template function.
One of these records is kept for each identifier that is lexed.
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
bool capturesVLAType() const
Determine whether this captures a variable length array bound expression.
Definition: LambdaCapture.h:94
LambdaCapture(SourceLocation Loc, bool Implicit, LambdaCaptureKind Kind, ValueDecl *Var=nullptr, SourceLocation EllipsisLoc=SourceLocation())
Create a new capture of a variable or of this.
Definition: ExprCXX.cpp:1156
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1186
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
Definition: LambdaCapture.h:82
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1924
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition: ExprCXX.cpp:1285
static LambdaExpr * CreateDeserialized(const ASTContext &C, unsigned NumCaptures)
Construct a new lambda expression that will be deserialized from an external source.
Definition: ExprCXX.cpp:1254
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1234
Stmt * getBody() const
Retrieve the body of the lambda.
Definition: ExprCXX.cpp:1268
bool isMutable() const
Determine whether the lambda is mutable, meaning that any captures values can be modified.
Definition: ExprCXX.cpp:1350
capture_iterator implicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of implicit lambda captures.
Definition: ExprCXX.cpp:1314
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition: ExprCXX.h:2005
capture_range explicit_captures() const
Retrieve this lambda's explicit captures.
Definition: ExprCXX.cpp:1306
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition: ExprCXX.cpp:1280
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1326
const CompoundStmt * getCompoundStmtBody() const
Retrieve the CompoundStmt representing the body of the lambda.
Definition: ExprCXX.cpp:1273
capture_range implicit_captures() const
Retrieve this lambda's implicit captures.
Definition: ExprCXX.cpp:1318
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it,...
Definition: ExprCXX.cpp:1336
ArrayRef< NamedDecl * > getExplicitTemplateParameters() const
Get the template parameters were explicitly specified (as opposed to being invented by use of an auto...
Definition: ExprCXX.cpp:1341
capture_iterator implicit_capture_begin() const
Retrieve an iterator pointing to the first implicit lambda capture.
Definition: ExprCXX.cpp:1310
capture_iterator explicit_capture_end() const
Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.
Definition: ExprCXX.cpp:1301
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition: ExprCXX.cpp:1289
llvm::iterator_range< capture_iterator > capture_range
An iterator over a range of lambda captures.
Definition: ExprCXX.h:1992
Expr * getTrailingRequiresClause() const
Get the trailing requires clause, if any.
Definition: ExprCXX.cpp:1346
capture_iterator explicit_capture_begin() const
Retrieve an iterator pointing to the first explicit lambda capture.
Definition: ExprCXX.cpp:1297
child_range children()
Includes the captures and the body of the lambda.
Definition: ExprCXX.cpp:1352
FunctionTemplateDecl * getDependentCallOperator() const
Retrieve the function template call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1331
capture_range captures() const
Retrieve this lambda's captures.
Definition: ExprCXX.cpp:1293
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1322
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3183
static LifetimeExtendedTemporaryDecl * Create(Expr *Temp, ValueDecl *EDec, unsigned Mangling)
Definition: DeclCXX.h:3208
MaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference, LifetimeExtendedTemporaryDecl *MTD=nullptr)
Definition: ExprCXX.cpp:1706
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
Definition: ExprCXX.h:4614
bool isUsableInConstantExpressions(const ASTContext &Context) const
Determine whether this temporary object is usable in constant expressions, as specified in C++20 [exp...
Definition: ExprCXX.cpp:1737
void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber)
Definition: ExprCXX.cpp:1720
This represents a decl that may have a name.
Definition: Decl.h:247
A C++ nested-name-specifier augmented with source location information.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2954
NestedNameSpecifier * getQualifier() const
Fetches the nested-name qualifier, if one was given.
Definition: ExprCXX.h:3069
ASTTemplateKWAndArgsInfo * getTrailingASTTemplateKWAndArgsInfo()
Return the optional template keyword and arguments info.
Definition: ExprCXX.h:4045
TemplateArgumentLoc * getTrailingTemplateArgumentLoc()
Return the optional template arguments.
Definition: ExprCXX.h:4055
DeclAccessPair * getTrailingResults()
Return the results. Defined after UnresolvedMemberExpr.
Definition: ExprCXX.h:4039
OverloadExpr(StmtClass SC, const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent, bool KnownContainsUnexpandedParameterPack)
Definition: ExprCXX.cpp:414
Represents a parameter to a function.
Definition: Decl.h:1722
Expr * getDefaultArg()
Definition: Decl.cpp:2907
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2800
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2541
SourceLocation getLocation() const
Definition: ExprCXX.h:2565
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2557
A (possibly-)qualified type.
Definition: Type.h:736
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6747
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:876
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6864
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6757
The collection of all-type qualifiers we support.
Definition: Type.h:146
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4850
RecordDecl * getDecl() const
Definition: Type.h:4860
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4204
static SizeOfPackExpr * CreateDeserialized(ASTContext &Context, unsigned NumPartialArgs)
Definition: ExprCXX.cpp:1636
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs=std::nullopt)
Definition: ExprCXX.cpp:1624
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
bool isValid() const
void setEnd(SourceLocation e)
Stmt - This represents one statement.
Definition: Stmt.h:72
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:349
StmtClass
Definition: Stmt.h:74
CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits
Definition: Stmt.h:1079
UnresolvedLookupExprBitfields UnresolvedLookupExprBits
Definition: Stmt.h:1082
ExprWithCleanupsBitfields ExprWithCleanupsBits
Definition: Stmt.h:1078
StmtClass getStmtClass() const
Definition: Stmt.h:1181
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:325
OverloadExprBitfields OverloadExprBits
Definition: Stmt.h:1081
CXXConstructExprBitfields CXXConstructExprBits
Definition: Stmt.h:1077
CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits
Definition: Stmt.h:1080
TypeTraitExprBitfields TypeTraitExprBits
Definition: Stmt.h:1075
CXXNewExprBitfields CXXNewExprBits
Definition: Stmt.h:1073
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1270
CXXDefaultInitExprBitfields CXXDefaultInitExprBits
Definition: Stmt.h:1071
DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits
Definition: Stmt.h:1076
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1271
CXXDefaultArgExprBitfields CXXDefaultArgExprBits
Definition: Stmt.h:1070
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4362
QualType getParameterType(const ASTContext &Ctx) const
Determine the substituted type of the template parameter.
Definition: ExprCXX.cpp:1648
NonTypeTemplateParmDecl * getParameter() const
Definition: ExprCXX.cpp:1643
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition: ExprCXX.cpp:1674
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Definition: ExprCXX.cpp:1669
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4435
A convenient class for passing around template argument information.
Definition: TemplateBase.h:590
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:484
Represents a template argument.
Definition: TemplateBase.h:60
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:191
A container of type source information.
Definition: Type.h:6635
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:249
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6646
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2742
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition: ExprCXX.cpp:1772
static TypeTraitExpr * CreateDeserialized(const ASTContext &C, unsigned NumArgs)
Definition: ExprCXX.cpp:1782
The base class of the type hierarchy.
Definition: Type.h:1568
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1799
bool isVoidType() const
Definition: Type.h:7224
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2751
bool isArrayType() const
Definition: Type.h:6982
bool isPointerType() const
Definition: Type.h:6916
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7256
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7497
bool isReferenceType() const
Definition: Type.h:6928
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:631
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2042
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2329
bool isFloatingType() const
Definition: Type.cpp:2166
bool isAnyPointerType() const
Definition: Type.h:6920
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7430
bool isRecordType() const
Definition: Type.h:7006
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3151
static UnresolvedLookupExpr * CreateEmpty(const ASTContext &Context, unsigned NumResults, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:402
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:370
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3889
QualType getBaseType() const
Definition: ExprCXX.h:3971
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:3981
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1566
CXXRecordDecl * getNamingClass()
Retrieve the naming class of this lookup.
Definition: ExprCXX.cpp:1597
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition: ExprCXX.cpp:1559
static UnresolvedMemberExpr * CreateEmpty(const ASTContext &Context, unsigned NumResults, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: ExprCXX.cpp:1585
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:35
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition: ExprCXX.h:637
LiteralOperatorKind getLiteralOperatorKind() const
Returns the kind of literal operator invocation which this expression represents.
Definition: ExprCXX.cpp:920
const IdentifierInfo * getUDSuffix() const
Returns the ud-suffix specified for this literal.
Definition: ExprCXX.cpp:949
static UserDefinedLiteral * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation LitEndLoc, SourceLocation SuffixLoc, FPOptionsOverride FPFeatures)
Definition: ExprCXX.cpp:891
static UserDefinedLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPOptions, EmptyShell Empty)
Definition: ExprCXX.cpp:907
Expr * getCookedLiteral()
If this is not a raw user-defined literal, get the underlying cooked literal (representing the litera...
Definition: ExprCXX.cpp:941
LiteralOperatorKind
The kind of literal operator which is invoked.
Definition: ExprCXX.h:665
@ LOK_String
operator "" X (const CharT *, size_t)
Definition: ExprCXX.h:679
@ LOK_Raw
Raw form: operator "" X (const char *)
Definition: ExprCXX.h:667
@ LOK_Floating
operator "" X (long double)
Definition: ExprCXX.h:676
@ LOK_Integer
operator "" X (unsigned long long)
Definition: ExprCXX.h:673
@ LOK_Template
Raw form: operator "" X<cs...> ()
Definition: ExprCXX.h:670
@ LOK_Character
operator "" X (CharT)
Definition: ExprCXX.h:682
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
QualType getType() const
Definition: Decl.h:712
Represents a variable declaration or definition.
Definition: Decl.h:913
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:142
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_VLAType
Capturing variable-length array type.
Definition: Lambda.h:38
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
ExprDependence computeDependence(FullExpr *E)
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
TemplateParameterList * getReplacedTemplateParameterList(Decl *D)
Internal helper used by Subst* nodes to retrieve the parameter list for their AssociatedDecl.
CastKind
CastKind - The kind of operation required for a conversion.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:123
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:126
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition: Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:130
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ TT_Last
Definition: TypeTraits.h:36
#define false
Definition: stdbool.h:22
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:693
void initializeFrom(SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &List, TemplateArgumentLoc *OutArgArray)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition: Stmt.h:1121