1 //===- ExprCXX.h - Classes for representing expressions ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Defines the clang::Expr interface and subclasses for C++ expressions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/NestedNameSpecifier.h"
23 #include "clang/AST/OperationKinds.h"
24 #include "clang/AST/Stmt.h"
25 #include "clang/AST/TemplateBase.h"
26 #include "clang/AST/Type.h"
27 #include "clang/AST/UnresolvedSet.h"
28 #include "clang/Basic/ExceptionSpecificationType.h"
29 #include "clang/Basic/ExpressionTraits.h"
30 #include "clang/Basic/LLVM.h"
31 #include "clang/Basic/Lambda.h"
32 #include "clang/Basic/LangOptions.h"
33 #include "clang/Basic/OperatorKinds.h"
34 #include "clang/Basic/SourceLocation.h"
35 #include "clang/Basic/Specifiers.h"
36 #include "clang/Basic/TypeTraits.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/None.h"
39 #include "llvm/ADT/Optional.h"
40 #include "llvm/ADT/PointerUnion.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/iterator_range.h"
43 #include "llvm/Support/Casting.h"
44 #include "llvm/Support/Compiler.h"
45 #include "llvm/Support/TrailingObjects.h"
57 class NonTypeTemplateParmDecl;
58 class TemplateParameterList;
60 //===--------------------------------------------------------------------===//
62 //===--------------------------------------------------------------------===//
64 /// A call to an overloaded operator written using operator
67 /// Represents a call to an overloaded operator written using operator
68 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
69 /// normal call, this AST node provides better information about the
70 /// syntactic representation of the call.
72 /// In a C++ template, this expression node kind will be used whenever
73 /// any of the arguments are type-dependent. In this case, the
74 /// function itself will be a (possibly empty) set of functions and
75 /// function templates that were found by name lookup at template
77 class CXXOperatorCallExpr final : public CallExpr {
78 friend class ASTStmtReader;
79 friend class ASTStmtWriter;
83 // CXXOperatorCallExpr has some trailing objects belonging
84 // to CallExpr. See CallExpr for the details.
86 SourceRange getSourceRangeImpl() const LLVM_READONLY;
88 CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn,
89 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
90 SourceLocation OperatorLoc, FPOptions FPFeatures,
93 CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty);
96 static CXXOperatorCallExpr *
97 Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
98 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
99 SourceLocation OperatorLoc, FPOptions FPFeatures,
100 ADLCallKind UsesADL = NotADL);
102 static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx,
103 unsigned NumArgs, EmptyShell Empty);
105 /// Returns the kind of overloaded operator that this expression refers to.
106 OverloadedOperatorKind getOperator() const {
107 return static_cast<OverloadedOperatorKind>(
108 CXXOperatorCallExprBits.OperatorKind);
111 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
112 return Opc == OO_Equal || Opc == OO_StarEqual || Opc == OO_SlashEqual ||
113 Opc == OO_PercentEqual || Opc == OO_PlusEqual ||
114 Opc == OO_MinusEqual || Opc == OO_LessLessEqual ||
115 Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
116 Opc == OO_CaretEqual || Opc == OO_PipeEqual;
118 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
120 /// Is this written as an infix binary operator?
121 bool isInfixBinaryOp() const;
123 /// Returns the location of the operator symbol in the expression.
125 /// When \c getOperator()==OO_Call, this is the location of the right
126 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
127 /// of the right bracket.
128 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
130 SourceLocation getExprLoc() const LLVM_READONLY {
131 OverloadedOperatorKind Operator = getOperator();
132 return (Operator < OO_Plus || Operator >= OO_Arrow ||
133 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
138 SourceLocation getBeginLoc() const { return Range.getBegin(); }
139 SourceLocation getEndLoc() const { return Range.getEnd(); }
140 SourceRange getSourceRange() const { return Range; }
142 static bool classof(const Stmt *T) {
143 return T->getStmtClass() == CXXOperatorCallExprClass;
146 // Set the FP contractability status of this operator. Only meaningful for
147 // operations on floating point types.
148 void setFPFeatures(FPOptions F) {
149 CXXOperatorCallExprBits.FPFeatures = F.getInt();
151 FPOptions getFPFeatures() const {
152 return FPOptions(CXXOperatorCallExprBits.FPFeatures);
155 // Get the FP contractability status of this operator. Only meaningful for
156 // operations on floating point types.
157 bool isFPContractableWithinStatement() const {
158 return getFPFeatures().allowFPContractWithinStatement();
162 /// Represents a call to a member function that
163 /// may be written either with member call syntax (e.g., "obj.func()"
164 /// or "objptr->func()") or with normal function-call syntax
165 /// ("func()") within a member function that ends up calling a member
166 /// function. The callee in either case is a MemberExpr that contains
167 /// both the object argument and the member function, while the
168 /// arguments are the arguments within the parentheses (not including
169 /// the object argument).
170 class CXXMemberCallExpr final : public CallExpr {
171 // CXXMemberCallExpr has some trailing objects belonging
172 // to CallExpr. See CallExpr for the details.
174 CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
175 ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs);
177 CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty);
180 static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
181 ArrayRef<Expr *> Args, QualType Ty,
182 ExprValueKind VK, SourceLocation RP,
183 unsigned MinNumArgs = 0);
185 static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
188 /// Retrieve the implicit object argument for the member call.
190 /// For example, in "x.f(5)", this returns the sub-expression "x".
191 Expr *getImplicitObjectArgument() const;
193 /// Retrieve the type of the object argument.
195 /// Note that this always returns a non-pointer type.
196 QualType getObjectType() const;
198 /// Retrieve the declaration of the called method.
199 CXXMethodDecl *getMethodDecl() const;
201 /// Retrieve the CXXRecordDecl for the underlying type of
202 /// the implicit object argument.
204 /// Note that this is may not be the same declaration as that of the class
205 /// context of the CXXMethodDecl which this function is calling.
206 /// FIXME: Returns 0 for member pointer call exprs.
207 CXXRecordDecl *getRecordDecl() const;
209 SourceLocation getExprLoc() const LLVM_READONLY {
210 SourceLocation CLoc = getCallee()->getExprLoc();
214 return getBeginLoc();
217 static bool classof(const Stmt *T) {
218 return T->getStmtClass() == CXXMemberCallExprClass;
222 /// Represents a call to a CUDA kernel function.
223 class CUDAKernelCallExpr final : public CallExpr {
224 friend class ASTStmtReader;
226 enum { CONFIG, END_PREARG };
228 // CUDAKernelCallExpr has some trailing objects belonging
229 // to CallExpr. See CallExpr for the details.
231 CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args,
232 QualType Ty, ExprValueKind VK, SourceLocation RP,
233 unsigned MinNumArgs);
235 CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty);
238 static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
239 CallExpr *Config, ArrayRef<Expr *> Args,
240 QualType Ty, ExprValueKind VK,
241 SourceLocation RP, unsigned MinNumArgs = 0);
243 static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx,
244 unsigned NumArgs, EmptyShell Empty);
246 const CallExpr *getConfig() const {
247 return cast_or_null<CallExpr>(getPreArg(CONFIG));
249 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
251 static bool classof(const Stmt *T) {
252 return T->getStmtClass() == CUDAKernelCallExprClass;
256 /// Abstract class common to all of the C++ "named"/"keyword" casts.
258 /// This abstract class is inherited by all of the classes
259 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
260 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
261 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
262 class CXXNamedCastExpr : public ExplicitCastExpr {
264 // the location of the casting op
267 // the location of the right parenthesis
268 SourceLocation RParenLoc;
271 SourceRange AngleBrackets;
274 friend class ASTStmtReader;
276 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
277 CastKind kind, Expr *op, unsigned PathSize,
278 TypeSourceInfo *writtenTy, SourceLocation l,
279 SourceLocation RParenLoc,
280 SourceRange AngleBrackets)
281 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
282 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
284 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
285 : ExplicitCastExpr(SC, Shell, PathSize) {}
288 const char *getCastName() const;
290 /// Retrieve the location of the cast operator keyword, e.g.,
292 SourceLocation getOperatorLoc() const { return Loc; }
294 /// Retrieve the location of the closing parenthesis.
295 SourceLocation getRParenLoc() const { return RParenLoc; }
297 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
298 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
299 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
301 static bool classof(const Stmt *T) {
302 switch (T->getStmtClass()) {
303 case CXXStaticCastExprClass:
304 case CXXDynamicCastExprClass:
305 case CXXReinterpretCastExprClass:
306 case CXXConstCastExprClass:
314 /// A C++ \c static_cast expression (C++ [expr.static.cast]).
316 /// This expression node represents a C++ static cast, e.g.,
317 /// \c static_cast<int>(1.0).
318 class CXXStaticCastExpr final
319 : public CXXNamedCastExpr,
320 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
321 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
322 unsigned pathSize, TypeSourceInfo *writtenTy,
323 SourceLocation l, SourceLocation RParenLoc,
324 SourceRange AngleBrackets)
325 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
326 writtenTy, l, RParenLoc, AngleBrackets) {}
328 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
329 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) {}
332 friend class CastExpr;
333 friend TrailingObjects;
335 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
336 ExprValueKind VK, CastKind K, Expr *Op,
337 const CXXCastPath *Path,
338 TypeSourceInfo *Written, SourceLocation L,
339 SourceLocation RParenLoc,
340 SourceRange AngleBrackets);
341 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
344 static bool classof(const Stmt *T) {
345 return T->getStmtClass() == CXXStaticCastExprClass;
349 /// A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
351 /// This expression node represents a dynamic cast, e.g.,
352 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
353 /// check to determine how to perform the type conversion.
354 class CXXDynamicCastExpr final
355 : public CXXNamedCastExpr,
356 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
357 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
358 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
359 SourceLocation l, SourceLocation RParenLoc,
360 SourceRange AngleBrackets)
361 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
362 writtenTy, l, RParenLoc, AngleBrackets) {}
364 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
365 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) {}
368 friend class CastExpr;
369 friend TrailingObjects;
371 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
372 ExprValueKind VK, CastKind Kind, Expr *Op,
373 const CXXCastPath *Path,
374 TypeSourceInfo *Written, SourceLocation L,
375 SourceLocation RParenLoc,
376 SourceRange AngleBrackets);
378 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
381 bool isAlwaysNull() const;
383 static bool classof(const Stmt *T) {
384 return T->getStmtClass() == CXXDynamicCastExprClass;
388 /// A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
390 /// This expression node represents a reinterpret cast, e.g.,
391 /// @c reinterpret_cast<int>(VoidPtr).
393 /// A reinterpret_cast provides a differently-typed view of a value but
394 /// (in Clang, as in most C++ implementations) performs no actual work at
396 class CXXReinterpretCastExpr final
397 : public CXXNamedCastExpr,
398 private llvm::TrailingObjects<CXXReinterpretCastExpr,
399 CXXBaseSpecifier *> {
400 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
401 Expr *op, unsigned pathSize,
402 TypeSourceInfo *writtenTy, SourceLocation l,
403 SourceLocation RParenLoc,
404 SourceRange AngleBrackets)
405 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
406 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
408 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
409 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) {}
412 friend class CastExpr;
413 friend TrailingObjects;
415 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
416 ExprValueKind VK, CastKind Kind,
417 Expr *Op, const CXXCastPath *Path,
418 TypeSourceInfo *WrittenTy, SourceLocation L,
419 SourceLocation RParenLoc,
420 SourceRange AngleBrackets);
421 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
424 static bool classof(const Stmt *T) {
425 return T->getStmtClass() == CXXReinterpretCastExprClass;
429 /// A C++ \c const_cast expression (C++ [expr.const.cast]).
431 /// This expression node represents a const cast, e.g.,
432 /// \c const_cast<char*>(PtrToConstChar).
434 /// A const_cast can remove type qualifiers but does not change the underlying
436 class CXXConstCastExpr final
437 : public CXXNamedCastExpr,
438 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
439 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
440 TypeSourceInfo *writtenTy, SourceLocation l,
441 SourceLocation RParenLoc, SourceRange AngleBrackets)
442 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
443 0, writtenTy, l, RParenLoc, AngleBrackets) {}
445 explicit CXXConstCastExpr(EmptyShell Empty)
446 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) {}
449 friend class CastExpr;
450 friend TrailingObjects;
452 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
453 ExprValueKind VK, Expr *Op,
454 TypeSourceInfo *WrittenTy, SourceLocation L,
455 SourceLocation RParenLoc,
456 SourceRange AngleBrackets);
457 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
459 static bool classof(const Stmt *T) {
460 return T->getStmtClass() == CXXConstCastExprClass;
464 /// A call to a literal operator (C++11 [over.literal])
465 /// written as a user-defined literal (C++11 [lit.ext]).
467 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
468 /// is semantically equivalent to a normal call, this AST node provides better
469 /// information about the syntactic representation of the literal.
471 /// Since literal operators are never found by ADL and can only be declared at
472 /// namespace scope, a user-defined literal is never dependent.
473 class UserDefinedLiteral final : public CallExpr {
474 friend class ASTStmtReader;
475 friend class ASTStmtWriter;
477 /// The location of a ud-suffix within the literal.
478 SourceLocation UDSuffixLoc;
480 // UserDefinedLiteral has some trailing objects belonging
481 // to CallExpr. See CallExpr for the details.
483 UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
484 ExprValueKind VK, SourceLocation LitEndLoc,
485 SourceLocation SuffixLoc);
487 UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty);
490 static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn,
491 ArrayRef<Expr *> Args, QualType Ty,
492 ExprValueKind VK, SourceLocation LitEndLoc,
493 SourceLocation SuffixLoc);
495 static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx,
496 unsigned NumArgs, EmptyShell Empty);
498 /// The kind of literal operator which is invoked.
499 enum LiteralOperatorKind {
500 /// Raw form: operator "" X (const char *)
503 /// Raw form: operator "" X<cs...> ()
506 /// operator "" X (unsigned long long)
509 /// operator "" X (long double)
512 /// operator "" X (const CharT *, size_t)
515 /// operator "" X (CharT)
519 /// Returns the kind of literal operator invocation
520 /// which this expression represents.
521 LiteralOperatorKind getLiteralOperatorKind() const;
523 /// If this is not a raw user-defined literal, get the
524 /// underlying cooked literal (representing the literal with the suffix
526 Expr *getCookedLiteral();
527 const Expr *getCookedLiteral() const {
528 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
531 SourceLocation getBeginLoc() const {
532 if (getLiteralOperatorKind() == LOK_Template)
533 return getRParenLoc();
534 return getArg(0)->getBeginLoc();
537 SourceLocation getEndLoc() const { return getRParenLoc(); }
539 /// Returns the location of a ud-suffix in the expression.
541 /// For a string literal, there may be multiple identical suffixes. This
542 /// returns the first.
543 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
545 /// Returns the ud-suffix specified for this literal.
546 const IdentifierInfo *getUDSuffix() const;
548 static bool classof(const Stmt *S) {
549 return S->getStmtClass() == UserDefinedLiteralClass;
553 /// A boolean literal, per ([C++ lex.bool] Boolean literals).
554 class CXXBoolLiteralExpr : public Expr {
556 CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc)
557 : Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
559 CXXBoolLiteralExprBits.Value = Val;
560 CXXBoolLiteralExprBits.Loc = Loc;
563 explicit CXXBoolLiteralExpr(EmptyShell Empty)
564 : Expr(CXXBoolLiteralExprClass, Empty) {}
566 bool getValue() const { return CXXBoolLiteralExprBits.Value; }
567 void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; }
569 SourceLocation getBeginLoc() const { return getLocation(); }
570 SourceLocation getEndLoc() const { return getLocation(); }
572 SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; }
573 void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; }
575 static bool classof(const Stmt *T) {
576 return T->getStmtClass() == CXXBoolLiteralExprClass;
580 child_range children() {
581 return child_range(child_iterator(), child_iterator());
584 const_child_range children() const {
585 return const_child_range(const_child_iterator(), const_child_iterator());
589 /// The null pointer literal (C++11 [lex.nullptr])
591 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
592 class CXXNullPtrLiteralExpr : public Expr {
594 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc)
595 : Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false,
596 false, false, false) {
597 CXXNullPtrLiteralExprBits.Loc = Loc;
600 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
601 : Expr(CXXNullPtrLiteralExprClass, Empty) {}
603 SourceLocation getBeginLoc() const { return getLocation(); }
604 SourceLocation getEndLoc() const { return getLocation(); }
606 SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; }
607 void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; }
609 static bool classof(const Stmt *T) {
610 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
613 child_range children() {
614 return child_range(child_iterator(), child_iterator());
617 const_child_range children() const {
618 return const_child_range(const_child_iterator(), const_child_iterator());
622 /// Implicit construction of a std::initializer_list<T> object from an
623 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
624 class CXXStdInitializerListExpr : public Expr {
625 Stmt *SubExpr = nullptr;
627 CXXStdInitializerListExpr(EmptyShell Empty)
628 : Expr(CXXStdInitializerListExprClass, Empty) {}
631 friend class ASTReader;
632 friend class ASTStmtReader;
634 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
635 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
636 Ty->isDependentType(), SubExpr->isValueDependent(),
637 SubExpr->isInstantiationDependent(),
638 SubExpr->containsUnexpandedParameterPack()),
641 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
642 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
644 SourceLocation getBeginLoc() const LLVM_READONLY {
645 return SubExpr->getBeginLoc();
648 SourceLocation getEndLoc() const LLVM_READONLY {
649 return SubExpr->getEndLoc();
652 /// Retrieve the source range of the expression.
653 SourceRange getSourceRange() const LLVM_READONLY {
654 return SubExpr->getSourceRange();
657 static bool classof(const Stmt *S) {
658 return S->getStmtClass() == CXXStdInitializerListExprClass;
661 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
663 const_child_range children() const {
664 return const_child_range(&SubExpr, &SubExpr + 1);
668 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
669 /// the \c type_info that corresponds to the supplied type, or the (possibly
670 /// dynamic) type of the supplied expression.
672 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
673 class CXXTypeidExpr : public Expr {
675 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
679 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
680 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
681 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
683 // typeid is value-dependent if the type or expression are
685 Operand->getType()->isDependentType(),
686 Operand->getType()->isInstantiationDependentType(),
687 Operand->getType()->containsUnexpandedParameterPack()),
688 Operand(Operand), Range(R) {}
690 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
691 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
692 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
694 // typeid is value-dependent if the type or expression are
696 Operand->isTypeDependent() || Operand->isValueDependent(),
697 Operand->isInstantiationDependent(),
698 Operand->containsUnexpandedParameterPack()),
699 Operand(Operand), Range(R) {}
701 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
702 : Expr(CXXTypeidExprClass, Empty) {
704 Operand = (Expr*)nullptr;
706 Operand = (TypeSourceInfo*)nullptr;
709 /// Determine whether this typeid has a type operand which is potentially
710 /// evaluated, per C++11 [expr.typeid]p3.
711 bool isPotentiallyEvaluated() const;
713 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
715 /// Retrieves the type operand of this typeid() expression after
716 /// various required adjustments (removing reference types, cv-qualifiers).
717 QualType getTypeOperand(ASTContext &Context) const;
719 /// Retrieve source information for the type operand.
720 TypeSourceInfo *getTypeOperandSourceInfo() const {
721 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
722 return Operand.get<TypeSourceInfo *>();
725 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
726 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
730 Expr *getExprOperand() const {
731 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
732 return static_cast<Expr*>(Operand.get<Stmt *>());
735 void setExprOperand(Expr *E) {
736 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
740 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
741 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
742 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
743 void setSourceRange(SourceRange R) { Range = R; }
745 static bool classof(const Stmt *T) {
746 return T->getStmtClass() == CXXTypeidExprClass;
750 child_range children() {
752 return child_range(child_iterator(), child_iterator());
753 auto **begin = reinterpret_cast<Stmt **>(&Operand);
754 return child_range(begin, begin + 1);
757 const_child_range children() const {
759 return const_child_range(const_child_iterator(), const_child_iterator());
762 reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand);
763 return const_child_range(begin, begin + 1);
767 /// A member reference to an MSPropertyDecl.
769 /// This expression always has pseudo-object type, and therefore it is
770 /// typically not encountered in a fully-typechecked expression except
771 /// within the syntactic form of a PseudoObjectExpr.
772 class MSPropertyRefExpr : public Expr {
774 MSPropertyDecl *TheDecl;
775 SourceLocation MemberLoc;
777 NestedNameSpecifierLoc QualifierLoc;
780 friend class ASTStmtReader;
782 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
783 QualType ty, ExprValueKind VK,
784 NestedNameSpecifierLoc qualifierLoc,
785 SourceLocation nameLoc)
786 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
787 /*type-dependent*/ false, baseExpr->isValueDependent(),
788 baseExpr->isInstantiationDependent(),
789 baseExpr->containsUnexpandedParameterPack()),
790 BaseExpr(baseExpr), TheDecl(decl),
791 MemberLoc(nameLoc), IsArrow(isArrow),
792 QualifierLoc(qualifierLoc) {}
794 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
796 SourceRange getSourceRange() const LLVM_READONLY {
797 return SourceRange(getBeginLoc(), getEndLoc());
800 bool isImplicitAccess() const {
801 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
804 SourceLocation getBeginLoc() const {
805 if (!isImplicitAccess())
806 return BaseExpr->getBeginLoc();
807 else if (QualifierLoc)
808 return QualifierLoc.getBeginLoc();
813 SourceLocation getEndLoc() const { return getMemberLoc(); }
815 child_range children() {
816 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
819 const_child_range children() const {
820 auto Children = const_cast<MSPropertyRefExpr *>(this)->children();
821 return const_child_range(Children.begin(), Children.end());
824 static bool classof(const Stmt *T) {
825 return T->getStmtClass() == MSPropertyRefExprClass;
828 Expr *getBaseExpr() const { return BaseExpr; }
829 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
830 bool isArrow() const { return IsArrow; }
831 SourceLocation getMemberLoc() const { return MemberLoc; }
832 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
835 /// MS property subscript expression.
836 /// MSVC supports 'property' attribute and allows to apply it to the
837 /// declaration of an empty array in a class or structure definition.
840 /// __declspec(property(get=GetX, put=PutX)) int x[];
842 /// The above statement indicates that x[] can be used with one or more array
843 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
844 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
845 /// This is a syntactic pseudo-object expression.
846 class MSPropertySubscriptExpr : public Expr {
847 friend class ASTStmtReader;
849 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
851 Stmt *SubExprs[NUM_SUBEXPRS];
852 SourceLocation RBracketLoc;
854 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
855 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
858 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
859 ExprObjectKind OK, SourceLocation RBracketLoc)
860 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
861 Idx->isValueDependent(), Idx->isInstantiationDependent(),
862 Idx->containsUnexpandedParameterPack()),
863 RBracketLoc(RBracketLoc) {
864 SubExprs[BASE_EXPR] = Base;
865 SubExprs[IDX_EXPR] = Idx;
868 /// Create an empty array subscript expression.
869 explicit MSPropertySubscriptExpr(EmptyShell Shell)
870 : Expr(MSPropertySubscriptExprClass, Shell) {}
872 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
873 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
875 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
876 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
878 SourceLocation getBeginLoc() const LLVM_READONLY {
879 return getBase()->getBeginLoc();
882 SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
884 SourceLocation getRBracketLoc() const { return RBracketLoc; }
885 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
887 SourceLocation getExprLoc() const LLVM_READONLY {
888 return getBase()->getExprLoc();
891 static bool classof(const Stmt *T) {
892 return T->getStmtClass() == MSPropertySubscriptExprClass;
896 child_range children() {
897 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
900 const_child_range children() const {
901 return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
905 /// A Microsoft C++ @c __uuidof expression, which gets
906 /// the _GUID that corresponds to the supplied type or expression.
908 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
909 class CXXUuidofExpr : public Expr {
911 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
916 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
918 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
919 Operand->getType()->isDependentType(),
920 Operand->getType()->isInstantiationDependentType(),
921 Operand->getType()->containsUnexpandedParameterPack()),
922 Operand(Operand), UuidStr(UuidStr), Range(R) {}
924 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
925 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
926 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
927 Operand->containsUnexpandedParameterPack()),
928 Operand(Operand), UuidStr(UuidStr), Range(R) {}
930 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
931 : Expr(CXXUuidofExprClass, Empty) {
933 Operand = (Expr*)nullptr;
935 Operand = (TypeSourceInfo*)nullptr;
938 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
940 /// Retrieves the type operand of this __uuidof() expression after
941 /// various required adjustments (removing reference types, cv-qualifiers).
942 QualType getTypeOperand(ASTContext &Context) const;
944 /// Retrieve source information for the type operand.
945 TypeSourceInfo *getTypeOperandSourceInfo() const {
946 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
947 return Operand.get<TypeSourceInfo *>();
950 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
951 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
955 Expr *getExprOperand() const {
956 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
957 return static_cast<Expr*>(Operand.get<Stmt *>());
960 void setExprOperand(Expr *E) {
961 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
965 void setUuidStr(StringRef US) { UuidStr = US; }
966 StringRef getUuidStr() const { return UuidStr; }
968 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
969 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
970 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
971 void setSourceRange(SourceRange R) { Range = R; }
973 static bool classof(const Stmt *T) {
974 return T->getStmtClass() == CXXUuidofExprClass;
978 child_range children() {
980 return child_range(child_iterator(), child_iterator());
981 auto **begin = reinterpret_cast<Stmt **>(&Operand);
982 return child_range(begin, begin + 1);
985 const_child_range children() const {
987 return const_child_range(const_child_iterator(), const_child_iterator());
989 reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand);
990 return const_child_range(begin, begin + 1);
994 /// Represents the \c this expression in C++.
996 /// This is a pointer to the object on which the current member function is
997 /// executing (C++ [expr.prim]p3). Example:
1003 /// void test() { this->bar(); }
1006 class CXXThisExpr : public Expr {
1008 CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit)
1009 : Expr(CXXThisExprClass, Ty, VK_RValue, OK_Ordinary,
1010 // 'this' is type-dependent if the class type of the enclosing
1011 // member function is dependent (C++ [temp.dep.expr]p2)
1012 Ty->isDependentType(), Ty->isDependentType(),
1013 Ty->isInstantiationDependentType(),
1014 /*ContainsUnexpandedParameterPack=*/false) {
1015 CXXThisExprBits.IsImplicit = IsImplicit;
1016 CXXThisExprBits.Loc = L;
1019 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
1021 SourceLocation getLocation() const { return CXXThisExprBits.Loc; }
1022 void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; }
1024 SourceLocation getBeginLoc() const { return getLocation(); }
1025 SourceLocation getEndLoc() const { return getLocation(); }
1027 bool isImplicit() const { return CXXThisExprBits.IsImplicit; }
1028 void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; }
1030 static bool classof(const Stmt *T) {
1031 return T->getStmtClass() == CXXThisExprClass;
1035 child_range children() {
1036 return child_range(child_iterator(), child_iterator());
1039 const_child_range children() const {
1040 return const_child_range(const_child_iterator(), const_child_iterator());
1044 /// A C++ throw-expression (C++ [except.throw]).
1046 /// This handles 'throw' (for re-throwing the current exception) and
1047 /// 'throw' assignment-expression. When assignment-expression isn't
1048 /// present, Op will be null.
1049 class CXXThrowExpr : public Expr {
1050 friend class ASTStmtReader;
1052 /// The optional expression in the throw statement.
1056 // \p Ty is the void type which is used as the result type of the
1057 // expression. The \p Loc is the location of the throw keyword.
1058 // \p Operand is the expression in the throw statement, and can be
1059 // null if not present.
1060 CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc,
1061 bool IsThrownVariableInScope)
1062 : Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
1063 Operand && Operand->isInstantiationDependent(),
1064 Operand && Operand->containsUnexpandedParameterPack()),
1066 CXXThrowExprBits.ThrowLoc = Loc;
1067 CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope;
1069 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
1071 const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); }
1072 Expr *getSubExpr() { return cast_or_null<Expr>(Operand); }
1074 SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; }
1076 /// Determines whether the variable thrown by this expression (if any!)
1077 /// is within the innermost try block.
1079 /// This information is required to determine whether the NRVO can apply to
1081 bool isThrownVariableInScope() const {
1082 return CXXThrowExprBits.IsThrownVariableInScope;
1085 SourceLocation getBeginLoc() const { return getThrowLoc(); }
1086 SourceLocation getEndLoc() const LLVM_READONLY {
1088 return getThrowLoc();
1089 return getSubExpr()->getEndLoc();
1092 static bool classof(const Stmt *T) {
1093 return T->getStmtClass() == CXXThrowExprClass;
1097 child_range children() {
1098 return child_range(&Operand, Operand ? &Operand + 1 : &Operand);
1101 const_child_range children() const {
1102 return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand);
1106 /// A default argument (C++ [dcl.fct.default]).
1108 /// This wraps up a function call argument that was created from the
1109 /// corresponding parameter's default argument, when the call did not
1110 /// explicitly supply arguments for all of the parameters.
1111 class CXXDefaultArgExpr final : public Expr {
1112 friend class ASTStmtReader;
1114 /// The parameter whose default is being used.
1117 /// The context where the default argument expression was used.
1118 DeclContext *UsedContext;
1120 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
1121 DeclContext *UsedContext)
1123 Param->hasUnparsedDefaultArg()
1124 ? Param->getType().getNonReferenceType()
1125 : Param->getDefaultArg()->getType(),
1126 Param->getDefaultArg()->getValueKind(),
1127 Param->getDefaultArg()->getObjectKind(), false, false, false,
1129 Param(Param), UsedContext(UsedContext) {
1130 CXXDefaultArgExprBits.Loc = Loc;
1134 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
1136 // \p Param is the parameter whose default argument is used by this
1138 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1140 DeclContext *UsedContext) {
1142 CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext);
1145 // Retrieve the parameter that the argument was created from.
1146 const ParmVarDecl *getParam() const { return Param; }
1147 ParmVarDecl *getParam() { return Param; }
1149 // Retrieve the actual argument to the function call.
1150 const Expr *getExpr() const { return getParam()->getDefaultArg(); }
1151 Expr *getExpr() { return getParam()->getDefaultArg(); }
1153 const DeclContext *getUsedContext() const { return UsedContext; }
1154 DeclContext *getUsedContext() { return UsedContext; }
1156 /// Retrieve the location where this default argument was actually used.
1157 SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; }
1159 /// Default argument expressions have no representation in the
1160 /// source, so they have an empty source range.
1161 SourceLocation getBeginLoc() const { return SourceLocation(); }
1162 SourceLocation getEndLoc() const { return SourceLocation(); }
1164 SourceLocation getExprLoc() const { return getUsedLocation(); }
1166 static bool classof(const Stmt *T) {
1167 return T->getStmtClass() == CXXDefaultArgExprClass;
1171 child_range children() {
1172 return child_range(child_iterator(), child_iterator());
1175 const_child_range children() const {
1176 return const_child_range(const_child_iterator(), const_child_iterator());
1180 /// A use of a default initializer in a constructor or in aggregate
1183 /// This wraps a use of a C++ default initializer (technically,
1184 /// a brace-or-equal-initializer for a non-static data member) when it
1185 /// is implicitly used in a mem-initializer-list in a constructor
1186 /// (C++11 [class.base.init]p8) or in aggregate initialization
1187 /// (C++1y [dcl.init.aggr]p7).
1188 class CXXDefaultInitExpr : public Expr {
1189 friend class ASTReader;
1190 friend class ASTStmtReader;
1192 /// The field whose default is being used.
1195 /// The context where the default initializer expression was used.
1196 DeclContext *UsedContext;
1198 CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
1199 FieldDecl *Field, QualType Ty, DeclContext *UsedContext);
1201 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1204 /// \p Field is the non-static data member whose default initializer is used
1205 /// by this expression.
1206 static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc,
1207 FieldDecl *Field, DeclContext *UsedContext) {
1208 return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext);
1211 /// Get the field whose initializer will be used.
1212 FieldDecl *getField() { return Field; }
1213 const FieldDecl *getField() const { return Field; }
1215 /// Get the initialization expression that will be used.
1216 const Expr *getExpr() const {
1217 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1218 return Field->getInClassInitializer();
1221 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1222 return Field->getInClassInitializer();
1225 const DeclContext *getUsedContext() const { return UsedContext; }
1226 DeclContext *getUsedContext() { return UsedContext; }
1228 /// Retrieve the location where this default initializer expression was
1230 SourceLocation getUsedLocation() const { return getBeginLoc(); }
1232 SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; }
1233 SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; }
1235 static bool classof(const Stmt *T) {
1236 return T->getStmtClass() == CXXDefaultInitExprClass;
1240 child_range children() {
1241 return child_range(child_iterator(), child_iterator());
1244 const_child_range children() const {
1245 return const_child_range(const_child_iterator(), const_child_iterator());
1249 /// Represents a C++ temporary.
1250 class CXXTemporary {
1251 /// The destructor that needs to be called.
1252 const CXXDestructorDecl *Destructor;
1254 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1255 : Destructor(destructor) {}
1258 static CXXTemporary *Create(const ASTContext &C,
1259 const CXXDestructorDecl *Destructor);
1261 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1263 void setDestructor(const CXXDestructorDecl *Dtor) {
1268 /// Represents binding an expression to a temporary.
1270 /// This ensures the destructor is called for the temporary. It should only be
1271 /// needed for non-POD, non-trivially destructable class types. For example:
1275 /// S() { } // User defined constructor makes S non-POD.
1276 /// ~S() { } // User defined destructor makes it non-trivial.
1279 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1282 class CXXBindTemporaryExpr : public Expr {
1283 CXXTemporary *Temp = nullptr;
1284 Stmt *SubExpr = nullptr;
1286 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1287 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1288 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1289 SubExpr->isValueDependent(),
1290 SubExpr->isInstantiationDependent(),
1291 SubExpr->containsUnexpandedParameterPack()),
1292 Temp(temp), SubExpr(SubExpr) {}
1295 CXXBindTemporaryExpr(EmptyShell Empty)
1296 : Expr(CXXBindTemporaryExprClass, Empty) {}
1298 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1301 CXXTemporary *getTemporary() { return Temp; }
1302 const CXXTemporary *getTemporary() const { return Temp; }
1303 void setTemporary(CXXTemporary *T) { Temp = T; }
1305 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1306 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1307 void setSubExpr(Expr *E) { SubExpr = E; }
1309 SourceLocation getBeginLoc() const LLVM_READONLY {
1310 return SubExpr->getBeginLoc();
1313 SourceLocation getEndLoc() const LLVM_READONLY {
1314 return SubExpr->getEndLoc();
1317 // Implement isa/cast/dyncast/etc.
1318 static bool classof(const Stmt *T) {
1319 return T->getStmtClass() == CXXBindTemporaryExprClass;
1323 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1325 const_child_range children() const {
1326 return const_child_range(&SubExpr, &SubExpr + 1);
1330 /// Represents a call to a C++ constructor.
1331 class CXXConstructExpr : public Expr {
1332 friend class ASTStmtReader;
1335 enum ConstructionKind {
1343 /// A pointer to the constructor which will be ultimately called.
1344 CXXConstructorDecl *Constructor;
1346 SourceRange ParenOrBraceRange;
1348 /// The number of arguments.
1351 // We would like to stash the arguments of the constructor call after
1352 // CXXConstructExpr. However CXXConstructExpr is used as a base class of
1353 // CXXTemporaryObjectExpr which makes the use of llvm::TrailingObjects
1356 // Instead we manually stash the trailing object after the full object
1357 // containing CXXConstructExpr (that is either CXXConstructExpr or
1358 // CXXTemporaryObjectExpr).
1360 // The trailing objects are:
1362 // * An array of getNumArgs() "Stmt *" for the arguments of the
1363 // constructor call.
1365 /// Return a pointer to the start of the trailing arguments.
1366 /// Defined just after CXXTemporaryObjectExpr.
1367 inline Stmt **getTrailingArgs();
1368 const Stmt *const *getTrailingArgs() const {
1369 return const_cast<CXXConstructExpr *>(this)->getTrailingArgs();
1373 /// Build a C++ construction expression.
1374 CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc,
1375 CXXConstructorDecl *Ctor, bool Elidable,
1376 ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1377 bool ListInitialization, bool StdInitListInitialization,
1378 bool ZeroInitialization, ConstructionKind ConstructKind,
1379 SourceRange ParenOrBraceRange);
1381 /// Build an empty C++ construction expression.
1382 CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs);
1384 /// Return the size in bytes of the trailing objects. Used by
1385 /// CXXTemporaryObjectExpr to allocate the right amount of storage.
1386 static unsigned sizeOfTrailingObjects(unsigned NumArgs) {
1387 return NumArgs * sizeof(Stmt *);
1391 /// Create a C++ construction expression.
1392 static CXXConstructExpr *
1393 Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1394 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1395 bool HadMultipleCandidates, bool ListInitialization,
1396 bool StdInitListInitialization, bool ZeroInitialization,
1397 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange);
1399 /// Create an empty C++ construction expression.
1400 static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs);
1402 /// Get the constructor that this expression will (ultimately) call.
1403 CXXConstructorDecl *getConstructor() const { return Constructor; }
1405 SourceLocation getLocation() const { return CXXConstructExprBits.Loc; }
1406 void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; }
1408 /// Whether this construction is elidable.
1409 bool isElidable() const { return CXXConstructExprBits.Elidable; }
1410 void setElidable(bool E) { CXXConstructExprBits.Elidable = E; }
1412 /// Whether the referred constructor was resolved from
1413 /// an overloaded set having size greater than 1.
1414 bool hadMultipleCandidates() const {
1415 return CXXConstructExprBits.HadMultipleCandidates;
1417 void setHadMultipleCandidates(bool V) {
1418 CXXConstructExprBits.HadMultipleCandidates = V;
1421 /// Whether this constructor call was written as list-initialization.
1422 bool isListInitialization() const {
1423 return CXXConstructExprBits.ListInitialization;
1425 void setListInitialization(bool V) {
1426 CXXConstructExprBits.ListInitialization = V;
1429 /// Whether this constructor call was written as list-initialization,
1430 /// but was interpreted as forming a std::initializer_list<T> from the list
1431 /// and passing that as a single constructor argument.
1432 /// See C++11 [over.match.list]p1 bullet 1.
1433 bool isStdInitListInitialization() const {
1434 return CXXConstructExprBits.StdInitListInitialization;
1436 void setStdInitListInitialization(bool V) {
1437 CXXConstructExprBits.StdInitListInitialization = V;
1440 /// Whether this construction first requires
1441 /// zero-initialization before the initializer is called.
1442 bool requiresZeroInitialization() const {
1443 return CXXConstructExprBits.ZeroInitialization;
1445 void setRequiresZeroInitialization(bool ZeroInit) {
1446 CXXConstructExprBits.ZeroInitialization = ZeroInit;
1449 /// Determine whether this constructor is actually constructing
1450 /// a base class (rather than a complete object).
1451 ConstructionKind getConstructionKind() const {
1452 return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind);
1454 void setConstructionKind(ConstructionKind CK) {
1455 CXXConstructExprBits.ConstructionKind = CK;
1458 using arg_iterator = ExprIterator;
1459 using const_arg_iterator = ConstExprIterator;
1460 using arg_range = llvm::iterator_range<arg_iterator>;
1461 using const_arg_range = llvm::iterator_range<const_arg_iterator>;
1463 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1464 const_arg_range arguments() const {
1465 return const_arg_range(arg_begin(), arg_end());
1468 arg_iterator arg_begin() { return getTrailingArgs(); }
1469 arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
1470 const_arg_iterator arg_begin() const { return getTrailingArgs(); }
1471 const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
1473 Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); }
1474 const Expr *const *getArgs() const {
1475 return reinterpret_cast<const Expr *const *>(getTrailingArgs());
1478 /// Return the number of arguments to the constructor call.
1479 unsigned getNumArgs() const { return NumArgs; }
1481 /// Return the specified argument.
1482 Expr *getArg(unsigned Arg) {
1483 assert(Arg < getNumArgs() && "Arg access out of range!");
1484 return getArgs()[Arg];
1486 const Expr *getArg(unsigned Arg) const {
1487 assert(Arg < getNumArgs() && "Arg access out of range!");
1488 return getArgs()[Arg];
1491 /// Set the specified argument.
1492 void setArg(unsigned Arg, Expr *ArgExpr) {
1493 assert(Arg < getNumArgs() && "Arg access out of range!");
1494 getArgs()[Arg] = ArgExpr;
1497 SourceLocation getBeginLoc() const LLVM_READONLY;
1498 SourceLocation getEndLoc() const LLVM_READONLY;
1499 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1500 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1502 static bool classof(const Stmt *T) {
1503 return T->getStmtClass() == CXXConstructExprClass ||
1504 T->getStmtClass() == CXXTemporaryObjectExprClass;
1508 child_range children() {
1509 return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs());
1512 const_child_range children() const {
1513 auto Children = const_cast<CXXConstructExpr *>(this)->children();
1514 return const_child_range(Children.begin(), Children.end());
1518 /// Represents a call to an inherited base class constructor from an
1519 /// inheriting constructor. This call implicitly forwards the arguments from
1520 /// the enclosing context (an inheriting constructor) to the specified inherited
1521 /// base class constructor.
1522 class CXXInheritedCtorInitExpr : public Expr {
1524 CXXConstructorDecl *Constructor = nullptr;
1526 /// The location of the using declaration.
1529 /// Whether this is the construction of a virtual base.
1530 unsigned ConstructsVirtualBase : 1;
1532 /// Whether the constructor is inherited from a virtual base class of the
1533 /// class that we construct.
1534 unsigned InheritedFromVirtualBase : 1;
1537 friend class ASTStmtReader;
1539 /// Construct a C++ inheriting construction expression.
1540 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1541 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1542 bool InheritedFromVirtualBase)
1543 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1544 false, false, false),
1545 Constructor(Ctor), Loc(Loc),
1546 ConstructsVirtualBase(ConstructsVirtualBase),
1547 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1548 assert(!T->isDependentType());
1551 /// Construct an empty C++ inheriting construction expression.
1552 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1553 : Expr(CXXInheritedCtorInitExprClass, Empty),
1554 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1556 /// Get the constructor that this expression will call.
1557 CXXConstructorDecl *getConstructor() const { return Constructor; }
1559 /// Determine whether this constructor is actually constructing
1560 /// a base class (rather than a complete object).
1561 bool constructsVBase() const { return ConstructsVirtualBase; }
1562 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1563 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1564 : CXXConstructExpr::CK_NonVirtualBase;
1567 /// Determine whether the inherited constructor is inherited from a
1568 /// virtual base of the object we construct. If so, we are not responsible
1569 /// for calling the inherited constructor (the complete object constructor
1570 /// does that), and so we don't need to pass any arguments.
1571 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1573 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1574 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1575 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1577 static bool classof(const Stmt *T) {
1578 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1581 child_range children() {
1582 return child_range(child_iterator(), child_iterator());
1585 const_child_range children() const {
1586 return const_child_range(const_child_iterator(), const_child_iterator());
1590 /// Represents an explicit C++ type conversion that uses "functional"
1591 /// notation (C++ [expr.type.conv]).
1597 class CXXFunctionalCastExpr final
1598 : public ExplicitCastExpr,
1599 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1600 SourceLocation LParenLoc;
1601 SourceLocation RParenLoc;
1603 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1604 TypeSourceInfo *writtenTy,
1605 CastKind kind, Expr *castExpr, unsigned pathSize,
1606 SourceLocation lParenLoc, SourceLocation rParenLoc)
1607 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1608 castExpr, pathSize, writtenTy),
1609 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1611 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1612 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) {}
1615 friend class CastExpr;
1616 friend TrailingObjects;
1618 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1620 TypeSourceInfo *Written,
1621 CastKind Kind, Expr *Op,
1622 const CXXCastPath *Path,
1623 SourceLocation LPLoc,
1624 SourceLocation RPLoc);
1625 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1628 SourceLocation getLParenLoc() const { return LParenLoc; }
1629 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1630 SourceLocation getRParenLoc() const { return RParenLoc; }
1631 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1633 /// Determine whether this expression models list-initialization.
1634 bool isListInitialization() const { return LParenLoc.isInvalid(); }
1636 SourceLocation getBeginLoc() const LLVM_READONLY;
1637 SourceLocation getEndLoc() const LLVM_READONLY;
1639 static bool classof(const Stmt *T) {
1640 return T->getStmtClass() == CXXFunctionalCastExprClass;
1644 /// Represents a C++ functional cast expression that builds a
1645 /// temporary object.
1647 /// This expression type represents a C++ "functional" cast
1648 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1649 /// constructor to build a temporary object. With N == 1 arguments the
1650 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1653 /// struct X { X(int, float); }
1656 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1659 class CXXTemporaryObjectExpr final : public CXXConstructExpr {
1660 friend class ASTStmtReader;
1662 // CXXTemporaryObjectExpr has some trailing objects belonging
1663 // to CXXConstructExpr. See the comment inside CXXConstructExpr
1664 // for more details.
1666 TypeSourceInfo *TSI;
1668 CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty,
1669 TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
1670 SourceRange ParenOrBraceRange,
1671 bool HadMultipleCandidates, bool ListInitialization,
1672 bool StdInitListInitialization,
1673 bool ZeroInitialization);
1675 CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs);
1678 static CXXTemporaryObjectExpr *
1679 Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
1680 TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
1681 SourceRange ParenOrBraceRange, bool HadMultipleCandidates,
1682 bool ListInitialization, bool StdInitListInitialization,
1683 bool ZeroInitialization);
1685 static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx,
1688 TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
1690 SourceLocation getBeginLoc() const LLVM_READONLY;
1691 SourceLocation getEndLoc() const LLVM_READONLY;
1693 static bool classof(const Stmt *T) {
1694 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1698 Stmt **CXXConstructExpr::getTrailingArgs() {
1699 if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this))
1700 return reinterpret_cast<Stmt **>(E + 1);
1701 assert((getStmtClass() == CXXConstructExprClass) &&
1702 "Unexpected class deriving from CXXConstructExpr!");
1703 return reinterpret_cast<Stmt **>(this + 1);
1706 /// A C++ lambda expression, which produces a function object
1707 /// (of unspecified type) that can be invoked later.
1711 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1712 /// values.erase(std::remove_if(values.begin(), values.end(),
1713 /// [=](double value) { return value > cutoff; });
1717 /// C++11 lambda expressions can capture local variables, either by copying
1718 /// the values of those local variables at the time the function
1719 /// object is constructed (not when it is called!) or by holding a
1720 /// reference to the local variable. These captures can occur either
1721 /// implicitly or can be written explicitly between the square
1722 /// brackets ([...]) that start the lambda expression.
1724 /// C++1y introduces a new form of "capture" called an init-capture that
1725 /// includes an initializing expression (rather than capturing a variable),
1726 /// and which can never occur implicitly.
1727 class LambdaExpr final : public Expr,
1728 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1729 /// The source range that covers the lambda introducer ([...]).
1730 SourceRange IntroducerRange;
1732 /// The source location of this lambda's capture-default ('=' or '&').
1733 SourceLocation CaptureDefaultLoc;
1735 /// The number of captures.
1736 unsigned NumCaptures : 16;
1738 /// The default capture kind, which is a value of type
1739 /// LambdaCaptureDefault.
1740 unsigned CaptureDefault : 2;
1742 /// Whether this lambda had an explicit parameter list vs. an
1743 /// implicit (and empty) parameter list.
1744 unsigned ExplicitParams : 1;
1746 /// Whether this lambda had the result type explicitly specified.
1747 unsigned ExplicitResultType : 1;
1749 /// The location of the closing brace ('}') that completes
1752 /// The location of the brace is also available by looking up the
1753 /// function call operator in the lambda class. However, it is
1754 /// stored here to improve the performance of getSourceRange(), and
1755 /// to avoid having to deserialize the function call operator from a
1756 /// module file just to determine the source range.
1757 SourceLocation ClosingBrace;
1759 /// Construct a lambda expression.
1760 LambdaExpr(QualType T, SourceRange IntroducerRange,
1761 LambdaCaptureDefault CaptureDefault,
1762 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1763 bool ExplicitParams, bool ExplicitResultType,
1764 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1765 bool ContainsUnexpandedParameterPack);
1767 /// Construct an empty lambda expression.
1768 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1769 : Expr(LambdaExprClass, Empty), NumCaptures(NumCaptures),
1770 CaptureDefault(LCD_None), ExplicitParams(false),
1771 ExplicitResultType(false) {
1772 getStoredStmts()[NumCaptures] = nullptr;
1775 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1777 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1780 friend class ASTStmtReader;
1781 friend class ASTStmtWriter;
1782 friend TrailingObjects;
1784 /// Construct a new lambda expression.
1786 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1787 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1788 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1789 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1790 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1792 /// Construct a new lambda expression that will be deserialized from
1793 /// an external source.
1794 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1795 unsigned NumCaptures);
1797 /// Determine the default capture kind for this lambda.
1798 LambdaCaptureDefault getCaptureDefault() const {
1799 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1802 /// Retrieve the location of this lambda's capture-default, if any.
1803 SourceLocation getCaptureDefaultLoc() const {
1804 return CaptureDefaultLoc;
1807 /// Determine whether one of this lambda's captures is an init-capture.
1808 bool isInitCapture(const LambdaCapture *Capture) const;
1810 /// An iterator that walks over the captures of the lambda,
1811 /// both implicit and explicit.
1812 using capture_iterator = const LambdaCapture *;
1814 /// An iterator over a range of lambda captures.
1815 using capture_range = llvm::iterator_range<capture_iterator>;
1817 /// Retrieve this lambda's captures.
1818 capture_range captures() const;
1820 /// Retrieve an iterator pointing to the first lambda capture.
1821 capture_iterator capture_begin() const;
1823 /// Retrieve an iterator pointing past the end of the
1824 /// sequence of lambda captures.
1825 capture_iterator capture_end() const;
1827 /// Determine the number of captures in this lambda.
1828 unsigned capture_size() const { return NumCaptures; }
1830 /// Retrieve this lambda's explicit captures.
1831 capture_range explicit_captures() const;
1833 /// Retrieve an iterator pointing to the first explicit
1835 capture_iterator explicit_capture_begin() const;
1837 /// Retrieve an iterator pointing past the end of the sequence of
1838 /// explicit lambda captures.
1839 capture_iterator explicit_capture_end() const;
1841 /// Retrieve this lambda's implicit captures.
1842 capture_range implicit_captures() const;
1844 /// Retrieve an iterator pointing to the first implicit
1846 capture_iterator implicit_capture_begin() const;
1848 /// Retrieve an iterator pointing past the end of the sequence of
1849 /// implicit lambda captures.
1850 capture_iterator implicit_capture_end() const;
1852 /// Iterator that walks over the capture initialization
1854 using capture_init_iterator = Expr **;
1856 /// Const iterator that walks over the capture initialization
1858 using const_capture_init_iterator = Expr *const *;
1860 /// Retrieve the initialization expressions for this lambda's captures.
1861 llvm::iterator_range<capture_init_iterator> capture_inits() {
1862 return llvm::make_range(capture_init_begin(), capture_init_end());
1865 /// Retrieve the initialization expressions for this lambda's captures.
1866 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1867 return llvm::make_range(capture_init_begin(), capture_init_end());
1870 /// Retrieve the first initialization argument for this
1871 /// lambda expression (which initializes the first capture field).
1872 capture_init_iterator capture_init_begin() {
1873 return reinterpret_cast<Expr **>(getStoredStmts());
1876 /// Retrieve the first initialization argument for this
1877 /// lambda expression (which initializes the first capture field).
1878 const_capture_init_iterator capture_init_begin() const {
1879 return reinterpret_cast<Expr *const *>(getStoredStmts());
1882 /// Retrieve the iterator pointing one past the last
1883 /// initialization argument for this lambda expression.
1884 capture_init_iterator capture_init_end() {
1885 return capture_init_begin() + NumCaptures;
1888 /// Retrieve the iterator pointing one past the last
1889 /// initialization argument for this lambda expression.
1890 const_capture_init_iterator capture_init_end() const {
1891 return capture_init_begin() + NumCaptures;
1894 /// Retrieve the source range covering the lambda introducer,
1895 /// which contains the explicit capture list surrounded by square
1896 /// brackets ([...]).
1897 SourceRange getIntroducerRange() const { return IntroducerRange; }
1899 /// Retrieve the class that corresponds to the lambda.
1901 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1902 /// captures in its fields and provides the various operations permitted
1903 /// on a lambda (copying, calling).
1904 CXXRecordDecl *getLambdaClass() const;
1906 /// Retrieve the function call operator associated with this
1907 /// lambda expression.
1908 CXXMethodDecl *getCallOperator() const;
1910 /// If this is a generic lambda expression, retrieve the template
1911 /// parameter list associated with it, or else return null.
1912 TemplateParameterList *getTemplateParameterList() const;
1914 /// Get the template parameters were explicitly specified (as opposed to being
1915 /// invented by use of an auto parameter).
1916 ArrayRef<NamedDecl *> getExplicitTemplateParameters() const;
1918 /// Whether this is a generic lambda.
1919 bool isGenericLambda() const { return getTemplateParameterList(); }
1921 /// Retrieve the body of the lambda.
1922 CompoundStmt *getBody() const;
1924 /// Determine whether the lambda is mutable, meaning that any
1925 /// captures values can be modified.
1926 bool isMutable() const;
1928 /// Determine whether this lambda has an explicit parameter
1929 /// list vs. an implicit (empty) parameter list.
1930 bool hasExplicitParameters() const { return ExplicitParams; }
1932 /// Whether this lambda had its result type explicitly specified.
1933 bool hasExplicitResultType() const { return ExplicitResultType; }
1935 static bool classof(const Stmt *T) {
1936 return T->getStmtClass() == LambdaExprClass;
1939 SourceLocation getBeginLoc() const LLVM_READONLY {
1940 return IntroducerRange.getBegin();
1943 SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; }
1945 child_range children() {
1946 // Includes initialization exprs plus body stmt
1947 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1950 const_child_range children() const {
1951 return const_child_range(getStoredStmts(),
1952 getStoredStmts() + NumCaptures + 1);
1956 /// An expression "T()" which creates a value-initialized rvalue of type
1957 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
1958 class CXXScalarValueInitExpr : public Expr {
1959 friend class ASTStmtReader;
1961 TypeSourceInfo *TypeInfo;
1964 /// Create an explicitly-written scalar-value initialization
1966 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1967 SourceLocation RParenLoc)
1968 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, false,
1969 false, Type->isInstantiationDependentType(),
1970 Type->containsUnexpandedParameterPack()),
1971 TypeInfo(TypeInfo) {
1972 CXXScalarValueInitExprBits.RParenLoc = RParenLoc;
1975 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1976 : Expr(CXXScalarValueInitExprClass, Shell) {}
1978 TypeSourceInfo *getTypeSourceInfo() const {
1982 SourceLocation getRParenLoc() const {
1983 return CXXScalarValueInitExprBits.RParenLoc;
1986 SourceLocation getBeginLoc() const LLVM_READONLY;
1987 SourceLocation getEndLoc() const { return getRParenLoc(); }
1989 static bool classof(const Stmt *T) {
1990 return T->getStmtClass() == CXXScalarValueInitExprClass;
1994 child_range children() {
1995 return child_range(child_iterator(), child_iterator());
1998 const_child_range children() const {
1999 return const_child_range(const_child_iterator(), const_child_iterator());
2003 /// Represents a new-expression for memory allocation and constructor
2004 /// calls, e.g: "new CXXNewExpr(foo)".
2005 class CXXNewExpr final
2007 private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> {
2008 friend class ASTStmtReader;
2009 friend class ASTStmtWriter;
2010 friend TrailingObjects;
2012 /// Points to the allocation function used.
2013 FunctionDecl *OperatorNew;
2015 /// Points to the deallocation function used in case of error. May be null.
2016 FunctionDecl *OperatorDelete;
2018 /// The allocated type-source information, as written in the source.
2019 TypeSourceInfo *AllocatedTypeInfo;
2021 /// Range of the entire new expression.
2024 /// Source-range of a paren-delimited initializer.
2025 SourceRange DirectInitRange;
2027 // CXXNewExpr is followed by several optional trailing objects.
2028 // They are in order:
2030 // * An optional "Stmt *" for the array size expression.
2031 // Present if and ony if isArray().
2033 // * An optional "Stmt *" for the init expression.
2034 // Present if and only if hasInitializer().
2036 // * An array of getNumPlacementArgs() "Stmt *" for the placement new
2037 // arguments, if any.
2039 // * An optional SourceRange for the range covering the parenthesized type-id
2040 // if the allocated type was expressed as a parenthesized type-id.
2041 // Present if and only if isParenTypeId().
2042 unsigned arraySizeOffset() const { return 0; }
2043 unsigned initExprOffset() const { return arraySizeOffset() + isArray(); }
2044 unsigned placementNewArgsOffset() const {
2045 return initExprOffset() + hasInitializer();
2048 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2049 return isArray() + hasInitializer() + getNumPlacementArgs();
2052 unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
2053 return isParenTypeId();
2057 enum InitializationStyle {
2058 /// New-expression has no initializer as written.
2061 /// New-expression has a C++98 paren-delimited initializer.
2064 /// New-expression has a C++11 list-initializer.
2069 /// Build a c++ new expression.
2070 CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
2071 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2072 bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2073 SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2074 InitializationStyle InitializationStyle, Expr *Initializer,
2075 QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2076 SourceRange DirectInitRange);
2078 /// Build an empty c++ new expression.
2079 CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
2080 bool IsParenTypeId);
2083 /// Create a c++ new expression.
2085 Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew,
2086 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2087 bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2088 SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2089 InitializationStyle InitializationStyle, Expr *Initializer,
2090 QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2091 SourceRange DirectInitRange);
2093 /// Create an empty c++ new expression.
2094 static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
2095 bool HasInit, unsigned NumPlacementArgs,
2096 bool IsParenTypeId);
2098 QualType getAllocatedType() const {
2099 assert(getType()->isPointerType());
2100 return getType()->getAs<PointerType>()->getPointeeType();
2103 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
2104 return AllocatedTypeInfo;
2107 /// True if the allocation result needs to be null-checked.
2109 /// C++11 [expr.new]p13:
2110 /// If the allocation function returns null, initialization shall
2111 /// not be done, the deallocation function shall not be called,
2112 /// and the value of the new-expression shall be null.
2115 /// If the allocation function is a reserved placement allocation
2116 /// function that returns null, the behavior is undefined.
2118 /// An allocation function is not allowed to return null unless it
2119 /// has a non-throwing exception-specification. The '03 rule is
2120 /// identical except that the definition of a non-throwing
2121 /// exception specification is just "is it throw()?".
2122 bool shouldNullCheckAllocation() const;
2124 FunctionDecl *getOperatorNew() const { return OperatorNew; }
2125 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
2126 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2127 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
2129 bool isArray() const { return CXXNewExprBits.IsArray; }
2131 Optional<Expr *> getArraySize() {
2134 return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2136 Optional<const Expr *> getArraySize() const {
2139 return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2142 unsigned getNumPlacementArgs() const {
2143 return CXXNewExprBits.NumPlacementArgs;
2146 Expr **getPlacementArgs() {
2147 return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() +
2148 placementNewArgsOffset());
2151 Expr *getPlacementArg(unsigned I) {
2152 assert((I < getNumPlacementArgs()) && "Index out of range!");
2153 return getPlacementArgs()[I];
2155 const Expr *getPlacementArg(unsigned I) const {
2156 return const_cast<CXXNewExpr *>(this)->getPlacementArg(I);
2159 bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; }
2160 SourceRange getTypeIdParens() const {
2161 return isParenTypeId() ? getTrailingObjects<SourceRange>()[0]
2165 bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
2167 /// Whether this new-expression has any initializer at all.
2168 bool hasInitializer() const {
2169 return CXXNewExprBits.StoredInitializationStyle > 0;
2172 /// The kind of initializer this new-expression has.
2173 InitializationStyle getInitializationStyle() const {
2174 if (CXXNewExprBits.StoredInitializationStyle == 0)
2176 return static_cast<InitializationStyle>(
2177 CXXNewExprBits.StoredInitializationStyle - 1);
2180 /// The initializer of this new-expression.
2181 Expr *getInitializer() {
2182 return hasInitializer()
2183 ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2186 const Expr *getInitializer() const {
2187 return hasInitializer()
2188 ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2192 /// Returns the CXXConstructExpr from this new-expression, or null.
2193 const CXXConstructExpr *getConstructExpr() const {
2194 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
2197 /// Indicates whether the required alignment should be implicitly passed to
2198 /// the allocation function.
2199 bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; }
2201 /// Answers whether the usual array deallocation function for the
2202 /// allocated type expects the size of the allocation as a
2204 bool doesUsualArrayDeleteWantSize() const {
2205 return CXXNewExprBits.UsualArrayDeleteWantsSize;
2208 using arg_iterator = ExprIterator;
2209 using const_arg_iterator = ConstExprIterator;
2211 llvm::iterator_range<arg_iterator> placement_arguments() {
2212 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2215 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
2216 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2219 arg_iterator placement_arg_begin() {
2220 return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2222 arg_iterator placement_arg_end() {
2223 return placement_arg_begin() + getNumPlacementArgs();
2225 const_arg_iterator placement_arg_begin() const {
2226 return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2228 const_arg_iterator placement_arg_end() const {
2229 return placement_arg_begin() + getNumPlacementArgs();
2232 using raw_arg_iterator = Stmt **;
2234 raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); }
2235 raw_arg_iterator raw_arg_end() {
2236 return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2238 const_arg_iterator raw_arg_begin() const {
2239 return getTrailingObjects<Stmt *>();
2241 const_arg_iterator raw_arg_end() const {
2242 return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2245 SourceLocation getBeginLoc() const { return Range.getBegin(); }
2246 SourceLocation getEndLoc() const { return Range.getEnd(); }
2248 SourceRange getDirectInitRange() const { return DirectInitRange; }
2249 SourceRange getSourceRange() const { return Range; }
2251 static bool classof(const Stmt *T) {
2252 return T->getStmtClass() == CXXNewExprClass;
2256 child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); }
2258 const_child_range children() const {
2259 return const_child_range(const_cast<CXXNewExpr *>(this)->children());
2263 /// Represents a \c delete expression for memory deallocation and
2264 /// destructor calls, e.g. "delete[] pArray".
2265 class CXXDeleteExpr : public Expr {
2266 friend class ASTStmtReader;
2268 /// Points to the operator delete overload that is used. Could be a member.
2269 FunctionDecl *OperatorDelete = nullptr;
2271 /// The pointer expression to be deleted.
2272 Stmt *Argument = nullptr;
2275 CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm,
2276 bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize,
2277 FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc)
2278 : Expr(CXXDeleteExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
2279 Arg->isInstantiationDependent(),
2280 Arg->containsUnexpandedParameterPack()),
2281 OperatorDelete(OperatorDelete), Argument(Arg) {
2282 CXXDeleteExprBits.GlobalDelete = GlobalDelete;
2283 CXXDeleteExprBits.ArrayForm = ArrayForm;
2284 CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten;
2285 CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
2286 CXXDeleteExprBits.Loc = Loc;
2289 explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {}
2291 bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; }
2292 bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; }
2293 bool isArrayFormAsWritten() const {
2294 return CXXDeleteExprBits.ArrayFormAsWritten;
2297 /// Answers whether the usual array deallocation function for the
2298 /// allocated type expects the size of the allocation as a
2299 /// parameter. This can be true even if the actual deallocation
2300 /// function that we're using doesn't want a size.
2301 bool doesUsualArrayDeleteWantSize() const {
2302 return CXXDeleteExprBits.UsualArrayDeleteWantsSize;
2305 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2307 Expr *getArgument() { return cast<Expr>(Argument); }
2308 const Expr *getArgument() const { return cast<Expr>(Argument); }
2310 /// Retrieve the type being destroyed.
2312 /// If the type being destroyed is a dependent type which may or may not
2313 /// be a pointer, return an invalid type.
2314 QualType getDestroyedType() const;
2316 SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; }
2317 SourceLocation getEndLoc() const LLVM_READONLY {
2318 return Argument->getEndLoc();
2321 static bool classof(const Stmt *T) {
2322 return T->getStmtClass() == CXXDeleteExprClass;
2326 child_range children() { return child_range(&Argument, &Argument + 1); }
2328 const_child_range children() const {
2329 return const_child_range(&Argument, &Argument + 1);
2333 /// Stores the type being destroyed by a pseudo-destructor expression.
2334 class PseudoDestructorTypeStorage {
2335 /// Either the type source information or the name of the type, if
2336 /// it couldn't be resolved due to type-dependence.
2337 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2339 /// The starting source location of the pseudo-destructor type.
2340 SourceLocation Location;
2343 PseudoDestructorTypeStorage() = default;
2345 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2346 : Type(II), Location(Loc) {}
2348 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2350 TypeSourceInfo *getTypeSourceInfo() const {
2351 return Type.dyn_cast<TypeSourceInfo *>();
2354 IdentifierInfo *getIdentifier() const {
2355 return Type.dyn_cast<IdentifierInfo *>();
2358 SourceLocation getLocation() const { return Location; }
2361 /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2363 /// A pseudo-destructor is an expression that looks like a member access to a
2364 /// destructor of a scalar type, except that scalar types don't have
2365 /// destructors. For example:
2369 /// void f(int *p) {
2374 /// Pseudo-destructors typically occur when instantiating templates such as:
2377 /// template<typename T>
2378 /// void destroy(T* ptr) {
2383 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2384 /// beyond evaluating the base expression.
2385 class CXXPseudoDestructorExpr : public Expr {
2386 friend class ASTStmtReader;
2388 /// The base expression (that is being destroyed).
2389 Stmt *Base = nullptr;
2391 /// Whether the operator was an arrow ('->'); otherwise, it was a
2395 /// The location of the '.' or '->' operator.
2396 SourceLocation OperatorLoc;
2398 /// The nested-name-specifier that follows the operator, if present.
2399 NestedNameSpecifierLoc QualifierLoc;
2401 /// The type that precedes the '::' in a qualified pseudo-destructor
2403 TypeSourceInfo *ScopeType = nullptr;
2405 /// The location of the '::' in a qualified pseudo-destructor
2407 SourceLocation ColonColonLoc;
2409 /// The location of the '~'.
2410 SourceLocation TildeLoc;
2412 /// The type being destroyed, or its name if we were unable to
2413 /// resolve the name.
2414 PseudoDestructorTypeStorage DestroyedType;
2417 CXXPseudoDestructorExpr(const ASTContext &Context,
2418 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2419 NestedNameSpecifierLoc QualifierLoc,
2420 TypeSourceInfo *ScopeType,
2421 SourceLocation ColonColonLoc,
2422 SourceLocation TildeLoc,
2423 PseudoDestructorTypeStorage DestroyedType);
2425 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2426 : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {}
2428 Expr *getBase() const { return cast<Expr>(Base); }
2430 /// Determines whether this member expression actually had
2431 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2433 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2435 /// Retrieves the nested-name-specifier that qualifies the type name,
2436 /// with source-location information.
2437 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2439 /// If the member name was qualified, retrieves the
2440 /// nested-name-specifier that precedes the member name. Otherwise, returns
2442 NestedNameSpecifier *getQualifier() const {
2443 return QualifierLoc.getNestedNameSpecifier();
2446 /// Determine whether this pseudo-destructor expression was written
2447 /// using an '->' (otherwise, it used a '.').
2448 bool isArrow() const { return IsArrow; }
2450 /// Retrieve the location of the '.' or '->' operator.
2451 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2453 /// Retrieve the scope type in a qualified pseudo-destructor
2456 /// Pseudo-destructor expressions can have extra qualification within them
2457 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2458 /// Here, if the object type of the expression is (or may be) a scalar type,
2459 /// \p T may also be a scalar type and, therefore, cannot be part of a
2460 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2461 /// destructor expression.
2462 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2464 /// Retrieve the location of the '::' in a qualified pseudo-destructor
2466 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2468 /// Retrieve the location of the '~'.
2469 SourceLocation getTildeLoc() const { return TildeLoc; }
2471 /// Retrieve the source location information for the type
2472 /// being destroyed.
2474 /// This type-source information is available for non-dependent
2475 /// pseudo-destructor expressions and some dependent pseudo-destructor
2476 /// expressions. Returns null if we only have the identifier for a
2477 /// dependent pseudo-destructor expression.
2478 TypeSourceInfo *getDestroyedTypeInfo() const {
2479 return DestroyedType.getTypeSourceInfo();
2482 /// In a dependent pseudo-destructor expression for which we do not
2483 /// have full type information on the destroyed type, provides the name
2484 /// of the destroyed type.
2485 IdentifierInfo *getDestroyedTypeIdentifier() const {
2486 return DestroyedType.getIdentifier();
2489 /// Retrieve the type being destroyed.
2490 QualType getDestroyedType() const;
2492 /// Retrieve the starting location of the type being destroyed.
2493 SourceLocation getDestroyedTypeLoc() const {
2494 return DestroyedType.getLocation();
2497 /// Set the name of destroyed type for a dependent pseudo-destructor
2499 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2500 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2503 /// Set the destroyed type.
2504 void setDestroyedType(TypeSourceInfo *Info) {
2505 DestroyedType = PseudoDestructorTypeStorage(Info);
2508 SourceLocation getBeginLoc() const LLVM_READONLY {
2509 return Base->getBeginLoc();
2511 SourceLocation getEndLoc() const LLVM_READONLY;
2513 static bool classof(const Stmt *T) {
2514 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2518 child_range children() { return child_range(&Base, &Base + 1); }
2520 const_child_range children() const {
2521 return const_child_range(&Base, &Base + 1);
2525 /// A type trait used in the implementation of various C++11 and
2526 /// Library TR1 trait templates.
2529 /// __is_pod(int) == true
2530 /// __is_enum(std::string) == false
2531 /// __is_trivially_constructible(vector<int>, int*, int*)
2533 class TypeTraitExpr final
2535 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2536 /// The location of the type trait keyword.
2539 /// The location of the closing parenthesis.
2540 SourceLocation RParenLoc;
2542 // Note: The TypeSourceInfos for the arguments are allocated after the
2545 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2546 ArrayRef<TypeSourceInfo *> Args,
2547 SourceLocation RParenLoc,
2550 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
2552 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2553 return getNumArgs();
2557 friend class ASTStmtReader;
2558 friend class ASTStmtWriter;
2559 friend TrailingObjects;
2561 /// Create a new type trait expression.
2562 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2563 SourceLocation Loc, TypeTrait Kind,
2564 ArrayRef<TypeSourceInfo *> Args,
2565 SourceLocation RParenLoc,
2568 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2571 /// Determine which type trait this expression uses.
2572 TypeTrait getTrait() const {
2573 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2576 bool getValue() const {
2577 assert(!isValueDependent());
2578 return TypeTraitExprBits.Value;
2581 /// Determine the number of arguments to this type trait.
2582 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2584 /// Retrieve the Ith argument.
2585 TypeSourceInfo *getArg(unsigned I) const {
2586 assert(I < getNumArgs() && "Argument out-of-range");
2587 return getArgs()[I];
2590 /// Retrieve the argument types.
2591 ArrayRef<TypeSourceInfo *> getArgs() const {
2592 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2596 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2597 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2599 static bool classof(const Stmt *T) {
2600 return T->getStmtClass() == TypeTraitExprClass;
2604 child_range children() {
2605 return child_range(child_iterator(), child_iterator());
2608 const_child_range children() const {
2609 return const_child_range(const_child_iterator(), const_child_iterator());
2613 /// An Embarcadero array type trait, as used in the implementation of
2614 /// __array_rank and __array_extent.
2618 /// __array_rank(int[10][20]) == 2
2619 /// __array_extent(int, 1) == 20
2621 class ArrayTypeTraitExpr : public Expr {
2622 /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2625 /// The value of the type trait. Unspecified if dependent.
2628 /// The array dimension being queried, or -1 if not used.
2631 /// The location of the type trait keyword.
2634 /// The location of the closing paren.
2635 SourceLocation RParen;
2637 /// The type being queried.
2638 TypeSourceInfo *QueriedType = nullptr;
2641 friend class ASTStmtReader;
2643 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2644 TypeSourceInfo *queried, uint64_t value,
2645 Expr *dimension, SourceLocation rparen, QualType ty)
2646 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2647 false, queried->getType()->isDependentType(),
2648 (queried->getType()->isInstantiationDependentType() ||
2649 (dimension && dimension->isInstantiationDependent())),
2650 queried->getType()->containsUnexpandedParameterPack()),
2651 ATT(att), Value(value), Dimension(dimension),
2652 Loc(loc), RParen(rparen), QueriedType(queried) {}
2654 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2655 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
2657 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2658 SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2660 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2662 QualType getQueriedType() const { return QueriedType->getType(); }
2664 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2666 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2668 Expr *getDimensionExpression() const { return Dimension; }
2670 static bool classof(const Stmt *T) {
2671 return T->getStmtClass() == ArrayTypeTraitExprClass;
2675 child_range children() {
2676 return child_range(child_iterator(), child_iterator());
2679 const_child_range children() const {
2680 return const_child_range(const_child_iterator(), const_child_iterator());
2684 /// An expression trait intrinsic.
2688 /// __is_lvalue_expr(std::cout) == true
2689 /// __is_lvalue_expr(1) == false
2691 class ExpressionTraitExpr : public Expr {
2692 /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2695 /// The value of the type trait. Unspecified if dependent.
2698 /// The location of the type trait keyword.
2701 /// The location of the closing paren.
2702 SourceLocation RParen;
2704 /// The expression being queried.
2705 Expr* QueriedExpression = nullptr;
2708 friend class ASTStmtReader;
2710 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2711 Expr *queried, bool value,
2712 SourceLocation rparen, QualType resultType)
2713 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2714 false, // Not type-dependent
2715 // Value-dependent if the argument is type-dependent.
2716 queried->isTypeDependent(),
2717 queried->isInstantiationDependent(),
2718 queried->containsUnexpandedParameterPack()),
2719 ET(et), Value(value), Loc(loc), RParen(rparen),
2720 QueriedExpression(queried) {}
2722 explicit ExpressionTraitExpr(EmptyShell Empty)
2723 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {}
2725 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2726 SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2728 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2730 Expr *getQueriedExpression() const { return QueriedExpression; }
2732 bool getValue() const { return Value; }
2734 static bool classof(const Stmt *T) {
2735 return T->getStmtClass() == ExpressionTraitExprClass;
2739 child_range children() {
2740 return child_range(child_iterator(), child_iterator());
2743 const_child_range children() const {
2744 return const_child_range(const_child_iterator(), const_child_iterator());
2748 /// A reference to an overloaded function set, either an
2749 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2750 class OverloadExpr : public Expr {
2751 friend class ASTStmtReader;
2752 friend class ASTStmtWriter;
2754 /// The common name of these declarations.
2755 DeclarationNameInfo NameInfo;
2757 /// The nested-name-specifier that qualifies the name, if any.
2758 NestedNameSpecifierLoc QualifierLoc;
2761 OverloadExpr(StmtClass SC, const ASTContext &Context,
2762 NestedNameSpecifierLoc QualifierLoc,
2763 SourceLocation TemplateKWLoc,
2764 const DeclarationNameInfo &NameInfo,
2765 const TemplateArgumentListInfo *TemplateArgs,
2766 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2767 bool KnownDependent, bool KnownInstantiationDependent,
2768 bool KnownContainsUnexpandedParameterPack);
2770 OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
2771 bool HasTemplateKWAndArgsInfo);
2773 /// Return the results. Defined after UnresolvedMemberExpr.
2774 inline DeclAccessPair *getTrailingResults();
2775 const DeclAccessPair *getTrailingResults() const {
2776 return const_cast<OverloadExpr *>(this)->getTrailingResults();
2779 /// Return the optional template keyword and arguments info.
2780 /// Defined after UnresolvedMemberExpr.
2781 inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo();
2782 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2783 return const_cast<OverloadExpr *>(this)
2784 ->getTrailingASTTemplateKWAndArgsInfo();
2787 /// Return the optional template arguments. Defined after
2788 /// UnresolvedMemberExpr.
2789 inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc();
2790 const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const {
2791 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2794 bool hasTemplateKWAndArgsInfo() const {
2795 return OverloadExprBits.HasTemplateKWAndArgsInfo;
2800 OverloadExpr *Expression;
2801 bool IsAddressOfOperand;
2802 bool HasFormOfMemberPointer;
2805 /// Finds the overloaded expression in the given expression \p E of
2808 /// \return the expression (which must be there) and true if it has
2809 /// the particular form of a member pointer expression
2810 static FindResult find(Expr *E) {
2811 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2815 E = E->IgnoreParens();
2816 if (isa<UnaryOperator>(E)) {
2817 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2818 E = cast<UnaryOperator>(E)->getSubExpr();
2819 auto *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2821 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2822 Result.IsAddressOfOperand = true;
2823 Result.Expression = Ovl;
2825 Result.HasFormOfMemberPointer = false;
2826 Result.IsAddressOfOperand = false;
2827 Result.Expression = cast<OverloadExpr>(E);
2833 /// Gets the naming class of this lookup, if any.
2834 /// Defined after UnresolvedMemberExpr.
2835 inline CXXRecordDecl *getNamingClass();
2836 const CXXRecordDecl *getNamingClass() const {
2837 return const_cast<OverloadExpr *>(this)->getNamingClass();
2840 using decls_iterator = UnresolvedSetImpl::iterator;
2842 decls_iterator decls_begin() const {
2843 return UnresolvedSetIterator(getTrailingResults());
2845 decls_iterator decls_end() const {
2846 return UnresolvedSetIterator(getTrailingResults() + getNumDecls());
2848 llvm::iterator_range<decls_iterator> decls() const {
2849 return llvm::make_range(decls_begin(), decls_end());
2852 /// Gets the number of declarations in the unresolved set.
2853 unsigned getNumDecls() const { return OverloadExprBits.NumResults; }
2855 /// Gets the full name info.
2856 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2858 /// Gets the name looked up.
2859 DeclarationName getName() const { return NameInfo.getName(); }
2861 /// Gets the location of the name.
2862 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2864 /// Fetches the nested-name qualifier, if one was given.
2865 NestedNameSpecifier *getQualifier() const {
2866 return QualifierLoc.getNestedNameSpecifier();
2869 /// Fetches the nested-name qualifier with source-location
2870 /// information, if one was given.
2871 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2873 /// Retrieve the location of the template keyword preceding
2874 /// this name, if any.
2875 SourceLocation getTemplateKeywordLoc() const {
2876 if (!hasTemplateKWAndArgsInfo())
2877 return SourceLocation();
2878 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2881 /// Retrieve the location of the left angle bracket starting the
2882 /// explicit template argument list following the name, if any.
2883 SourceLocation getLAngleLoc() const {
2884 if (!hasTemplateKWAndArgsInfo())
2885 return SourceLocation();
2886 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2889 /// Retrieve the location of the right angle bracket ending the
2890 /// explicit template argument list following the name, if any.
2891 SourceLocation getRAngleLoc() const {
2892 if (!hasTemplateKWAndArgsInfo())
2893 return SourceLocation();
2894 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2897 /// Determines whether the name was preceded by the template keyword.
2898 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2900 /// Determines whether this expression had explicit template arguments.
2901 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2903 TemplateArgumentLoc const *getTemplateArgs() const {
2904 if (!hasExplicitTemplateArgs())
2906 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2909 unsigned getNumTemplateArgs() const {
2910 if (!hasExplicitTemplateArgs())
2913 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
2916 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2917 return {getTemplateArgs(), getNumTemplateArgs()};
2920 /// Copies the template arguments into the given structure.
2921 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2922 if (hasExplicitTemplateArgs())
2923 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
2926 static bool classof(const Stmt *T) {
2927 return T->getStmtClass() == UnresolvedLookupExprClass ||
2928 T->getStmtClass() == UnresolvedMemberExprClass;
2932 /// A reference to a name which we were able to look up during
2933 /// parsing but could not resolve to a specific declaration.
2935 /// This arises in several ways:
2936 /// * we might be waiting for argument-dependent lookup;
2937 /// * the name might resolve to an overloaded function;
2939 /// * the lookup might have included a function template.
2941 /// These never include UnresolvedUsingValueDecls, which are always class
2942 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2943 class UnresolvedLookupExpr final
2944 : public OverloadExpr,
2945 private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair,
2946 ASTTemplateKWAndArgsInfo,
2947 TemplateArgumentLoc> {
2948 friend class ASTStmtReader;
2949 friend class OverloadExpr;
2950 friend TrailingObjects;
2952 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2953 /// any. This can generally be recalculated from the context chain,
2954 /// but that can be fairly expensive for unqualified lookups.
2955 CXXRecordDecl *NamingClass;
2957 // UnresolvedLookupExpr is followed by several trailing objects.
2958 // They are in order:
2960 // * An array of getNumResults() DeclAccessPair for the results. These are
2961 // undesugared, which is to say, they may include UsingShadowDecls.
2962 // Access is relative to the naming class.
2964 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
2965 // template keyword and arguments. Present if and only if
2966 // hasTemplateKWAndArgsInfo().
2968 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
2969 // location information for the explicitly specified template arguments.
2971 UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass,
2972 NestedNameSpecifierLoc QualifierLoc,
2973 SourceLocation TemplateKWLoc,
2974 const DeclarationNameInfo &NameInfo, bool RequiresADL,
2976 const TemplateArgumentListInfo *TemplateArgs,
2977 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2979 UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
2980 bool HasTemplateKWAndArgsInfo);
2982 unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
2983 return getNumDecls();
2986 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2987 return hasTemplateKWAndArgsInfo();
2991 static UnresolvedLookupExpr *
2992 Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
2993 NestedNameSpecifierLoc QualifierLoc,
2994 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
2995 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2997 static UnresolvedLookupExpr *
2998 Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
2999 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3000 const DeclarationNameInfo &NameInfo, bool RequiresADL,
3001 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
3002 UnresolvedSetIterator End);
3004 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
3005 unsigned NumResults,
3006 bool HasTemplateKWAndArgsInfo,
3007 unsigned NumTemplateArgs);
3009 /// True if this declaration should be extended by
3010 /// argument-dependent lookup.
3011 bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; }
3013 /// True if this lookup is overloaded.
3014 bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; }
3016 /// Gets the 'naming class' (in the sense of C++0x
3017 /// [class.access.base]p5) of the lookup. This is the scope
3018 /// that was looked in to find these results.
3019 CXXRecordDecl *getNamingClass() { return NamingClass; }
3020 const CXXRecordDecl *getNamingClass() const { return NamingClass; }
3022 SourceLocation getBeginLoc() const LLVM_READONLY {
3023 if (NestedNameSpecifierLoc l = getQualifierLoc())
3024 return l.getBeginLoc();
3025 return getNameInfo().getBeginLoc();
3028 SourceLocation getEndLoc() const LLVM_READONLY {
3029 if (hasExplicitTemplateArgs())
3030 return getRAngleLoc();
3031 return getNameInfo().getEndLoc();
3034 child_range children() {
3035 return child_range(child_iterator(), child_iterator());
3038 const_child_range children() const {
3039 return const_child_range(const_child_iterator(), const_child_iterator());
3042 static bool classof(const Stmt *T) {
3043 return T->getStmtClass() == UnresolvedLookupExprClass;
3047 /// A qualified reference to a name whose declaration cannot
3048 /// yet be resolved.
3050 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
3051 /// it expresses a reference to a declaration such as
3052 /// X<T>::value. The difference, however, is that an
3053 /// DependentScopeDeclRefExpr node is used only within C++ templates when
3054 /// the qualification (e.g., X<T>::) refers to a dependent type. In
3055 /// this case, X<T>::value cannot resolve to a declaration because the
3056 /// declaration will differ from one instantiation of X<T> to the
3057 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
3058 /// qualifier (X<T>::) and the name of the entity being referenced
3059 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
3060 /// declaration can be found.
3061 class DependentScopeDeclRefExpr final
3063 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
3064 ASTTemplateKWAndArgsInfo,
3065 TemplateArgumentLoc> {
3066 friend class ASTStmtReader;
3067 friend class ASTStmtWriter;
3068 friend TrailingObjects;
3070 /// The nested-name-specifier that qualifies this unresolved
3071 /// declaration name.
3072 NestedNameSpecifierLoc QualifierLoc;
3074 /// The name of the entity we will be referencing.
3075 DeclarationNameInfo NameInfo;
3077 DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc,
3078 SourceLocation TemplateKWLoc,
3079 const DeclarationNameInfo &NameInfo,
3080 const TemplateArgumentListInfo *Args);
3082 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3083 return hasTemplateKWAndArgsInfo();
3086 bool hasTemplateKWAndArgsInfo() const {
3087 return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo;
3091 static DependentScopeDeclRefExpr *
3092 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
3093 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
3094 const TemplateArgumentListInfo *TemplateArgs);
3096 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context,
3097 bool HasTemplateKWAndArgsInfo,
3098 unsigned NumTemplateArgs);
3100 /// Retrieve the name that this expression refers to.
3101 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3103 /// Retrieve the name that this expression refers to.
3104 DeclarationName getDeclName() const { return NameInfo.getName(); }
3106 /// Retrieve the location of the name within the expression.
3108 /// For example, in "X<T>::value" this is the location of "value".
3109 SourceLocation getLocation() const { return NameInfo.getLoc(); }
3111 /// Retrieve the nested-name-specifier that qualifies the
3112 /// name, with source location information.
3113 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3115 /// Retrieve the nested-name-specifier that qualifies this
3117 NestedNameSpecifier *getQualifier() const {
3118 return QualifierLoc.getNestedNameSpecifier();
3121 /// Retrieve the location of the template keyword preceding
3122 /// this name, if any.
3123 SourceLocation getTemplateKeywordLoc() const {
3124 if (!hasTemplateKWAndArgsInfo())
3125 return SourceLocation();
3126 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3129 /// Retrieve the location of the left angle bracket starting the
3130 /// explicit template argument list following the name, if any.
3131 SourceLocation getLAngleLoc() const {
3132 if (!hasTemplateKWAndArgsInfo())
3133 return SourceLocation();
3134 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3137 /// Retrieve the location of the right angle bracket ending the
3138 /// explicit template argument list following the name, if any.
3139 SourceLocation getRAngleLoc() const {
3140 if (!hasTemplateKWAndArgsInfo())
3141 return SourceLocation();
3142 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3145 /// Determines whether the name was preceded by the template keyword.
3146 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3148 /// Determines whether this lookup had explicit template arguments.
3149 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3151 /// Copies the template arguments (if present) into the given
3153 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3154 if (hasExplicitTemplateArgs())
3155 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3156 getTrailingObjects<TemplateArgumentLoc>(), List);
3159 TemplateArgumentLoc const *getTemplateArgs() const {
3160 if (!hasExplicitTemplateArgs())
3163 return getTrailingObjects<TemplateArgumentLoc>();
3166 unsigned getNumTemplateArgs() const {
3167 if (!hasExplicitTemplateArgs())
3170 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3173 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3174 return {getTemplateArgs(), getNumTemplateArgs()};
3177 /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr,
3178 /// and differs from getLocation().getStart().
3179 SourceLocation getBeginLoc() const LLVM_READONLY {
3180 return QualifierLoc.getBeginLoc();
3183 SourceLocation getEndLoc() const LLVM_READONLY {
3184 if (hasExplicitTemplateArgs())
3185 return getRAngleLoc();
3186 return getLocation();
3189 static bool classof(const Stmt *T) {
3190 return T->getStmtClass() == DependentScopeDeclRefExprClass;
3193 child_range children() {
3194 return child_range(child_iterator(), child_iterator());
3197 const_child_range children() const {
3198 return const_child_range(const_child_iterator(), const_child_iterator());
3202 /// Represents an expression -- generally a full-expression -- that
3203 /// introduces cleanups to be run at the end of the sub-expression's
3204 /// evaluation. The most common source of expression-introduced
3205 /// cleanups is temporary objects in C++, but several other kinds of
3206 /// expressions can create cleanups, including basically every
3207 /// call in ARC that returns an Objective-C pointer.
3209 /// This expression also tracks whether the sub-expression contains a
3210 /// potentially-evaluated block literal. The lifetime of a block
3211 /// literal is the extent of the enclosing scope.
3212 class ExprWithCleanups final
3214 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
3216 /// The type of objects that are kept in the cleanup.
3217 /// It's useful to remember the set of blocks; we could also
3218 /// remember the set of temporaries, but there's currently
3220 using CleanupObject = BlockDecl *;
3223 friend class ASTStmtReader;
3224 friend TrailingObjects;
3226 ExprWithCleanups(EmptyShell, unsigned NumObjects);
3227 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
3228 ArrayRef<CleanupObject> Objects);
3231 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
3232 unsigned numObjects);
3234 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
3235 bool CleanupsHaveSideEffects,
3236 ArrayRef<CleanupObject> objects);
3238 ArrayRef<CleanupObject> getObjects() const {
3239 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
3243 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
3245 CleanupObject getObject(unsigned i) const {
3246 assert(i < getNumObjects() && "Index out of range");
3247 return getObjects()[i];
3250 bool cleanupsHaveSideEffects() const {
3251 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
3254 SourceLocation getBeginLoc() const LLVM_READONLY {
3255 return SubExpr->getBeginLoc();
3258 SourceLocation getEndLoc() const LLVM_READONLY {
3259 return SubExpr->getEndLoc();
3262 // Implement isa/cast/dyncast/etc.
3263 static bool classof(const Stmt *T) {
3264 return T->getStmtClass() == ExprWithCleanupsClass;
3268 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
3270 const_child_range children() const {
3271 return const_child_range(&SubExpr, &SubExpr + 1);
3275 /// Describes an explicit type conversion that uses functional
3276 /// notion but could not be resolved because one or more arguments are
3279 /// The explicit type conversions expressed by
3280 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
3281 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
3282 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
3283 /// type-dependent. For example, this would occur in a template such
3287 /// template<typename T, typename A1>
3288 /// inline T make_a(const A1& a1) {
3293 /// When the returned expression is instantiated, it may resolve to a
3294 /// constructor call, conversion function call, or some kind of type
3296 class CXXUnresolvedConstructExpr final
3298 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3299 friend class ASTStmtReader;
3300 friend TrailingObjects;
3302 /// The type being constructed.
3303 TypeSourceInfo *TSI;
3305 /// The location of the left parentheses ('(').
3306 SourceLocation LParenLoc;
3308 /// The location of the right parentheses (')').
3309 SourceLocation RParenLoc;
3311 CXXUnresolvedConstructExpr(TypeSourceInfo *TSI, SourceLocation LParenLoc,
3312 ArrayRef<Expr *> Args, SourceLocation RParenLoc);
3314 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3315 : Expr(CXXUnresolvedConstructExprClass, Empty) {
3316 CXXUnresolvedConstructExprBits.NumArgs = NumArgs;
3320 static CXXUnresolvedConstructExpr *Create(const ASTContext &Context,
3321 TypeSourceInfo *Type,
3322 SourceLocation LParenLoc,
3323 ArrayRef<Expr *> Args,
3324 SourceLocation RParenLoc);
3326 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context,
3329 /// Retrieve the type that is being constructed, as specified
3330 /// in the source code.
3331 QualType getTypeAsWritten() const { return TSI->getType(); }
3333 /// Retrieve the type source information for the type being
3335 TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
3337 /// Retrieve the location of the left parentheses ('(') that
3338 /// precedes the argument list.
3339 SourceLocation getLParenLoc() const { return LParenLoc; }
3340 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3342 /// Retrieve the location of the right parentheses (')') that
3343 /// follows the argument list.
3344 SourceLocation getRParenLoc() const { return RParenLoc; }
3345 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3347 /// Determine whether this expression models list-initialization.
3348 /// If so, there will be exactly one subexpression, which will be
3349 /// an InitListExpr.
3350 bool isListInitialization() const { return LParenLoc.isInvalid(); }
3352 /// Retrieve the number of arguments.
3353 unsigned arg_size() const { return CXXUnresolvedConstructExprBits.NumArgs; }
3355 using arg_iterator = Expr **;
3356 using arg_range = llvm::iterator_range<arg_iterator>;
3358 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3359 arg_iterator arg_end() { return arg_begin() + arg_size(); }
3360 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
3362 using const_arg_iterator = const Expr* const *;
3363 using const_arg_range = llvm::iterator_range<const_arg_iterator>;
3365 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3366 const_arg_iterator arg_end() const { return arg_begin() + arg_size(); }
3367 const_arg_range arguments() const {
3368 return const_arg_range(arg_begin(), arg_end());
3371 Expr *getArg(unsigned I) {
3372 assert(I < arg_size() && "Argument index out-of-range");
3373 return arg_begin()[I];
3376 const Expr *getArg(unsigned I) const {
3377 assert(I < arg_size() && "Argument index out-of-range");
3378 return arg_begin()[I];
3381 void setArg(unsigned I, Expr *E) {
3382 assert(I < arg_size() && "Argument index out-of-range");
3386 SourceLocation getBeginLoc() const LLVM_READONLY;
3387 SourceLocation getEndLoc() const LLVM_READONLY {
3388 if (!RParenLoc.isValid() && arg_size() > 0)
3389 return getArg(arg_size() - 1)->getEndLoc();
3393 static bool classof(const Stmt *T) {
3394 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3398 child_range children() {
3399 auto **begin = reinterpret_cast<Stmt **>(arg_begin());
3400 return child_range(begin, begin + arg_size());
3403 const_child_range children() const {
3404 auto **begin = reinterpret_cast<Stmt **>(
3405 const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin());
3406 return const_child_range(begin, begin + arg_size());
3410 /// Represents a C++ member access expression where the actual
3411 /// member referenced could not be resolved because the base
3412 /// expression or the member name was dependent.
3414 /// Like UnresolvedMemberExprs, these can be either implicit or
3415 /// explicit accesses. It is only possible to get one of these with
3416 /// an implicit access if a qualifier is provided.
3417 class CXXDependentScopeMemberExpr final
3419 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3420 ASTTemplateKWAndArgsInfo,
3421 TemplateArgumentLoc, NamedDecl *> {
3422 friend class ASTStmtReader;
3423 friend class ASTStmtWriter;
3424 friend TrailingObjects;
3426 /// The expression for the base pointer or class reference,
3427 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3430 /// The type of the base expression. Never null, even for
3431 /// implicit accesses.
3434 /// The nested-name-specifier that precedes the member name, if any.
3435 /// FIXME: This could be in principle store as a trailing object.
3436 /// However the performance impact of doing so should be investigated first.
3437 NestedNameSpecifierLoc QualifierLoc;
3439 /// The member to which this member expression refers, which
3440 /// can be name, overloaded operator, or destructor.
3442 /// FIXME: could also be a template-id
3443 DeclarationNameInfo MemberNameInfo;
3445 // CXXDependentScopeMemberExpr is followed by several trailing objects,
3446 // some of which optional. They are in order:
3448 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3449 // template keyword and arguments. Present if and only if
3450 // hasTemplateKWAndArgsInfo().
3452 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location
3453 // information for the explicitly specified template arguments.
3455 // * An optional NamedDecl *. In a qualified member access expression such
3456 // as t->Base::f, this member stores the resolves of name lookup in the
3457 // context of the member access expression, to be used at instantiation
3458 // time. Present if and only if hasFirstQualifierFoundInScope().
3460 bool hasTemplateKWAndArgsInfo() const {
3461 return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
3464 bool hasFirstQualifierFoundInScope() const {
3465 return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
3468 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3469 return hasTemplateKWAndArgsInfo();
3472 unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const {
3473 return getNumTemplateArgs();
3476 unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const {
3477 return hasFirstQualifierFoundInScope();
3480 CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base,
3481 QualType BaseType, bool IsArrow,
3482 SourceLocation OperatorLoc,
3483 NestedNameSpecifierLoc QualifierLoc,
3484 SourceLocation TemplateKWLoc,
3485 NamedDecl *FirstQualifierFoundInScope,
3486 DeclarationNameInfo MemberNameInfo,
3487 const TemplateArgumentListInfo *TemplateArgs);
3489 CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
3490 bool HasFirstQualifierFoundInScope);
3493 static CXXDependentScopeMemberExpr *
3494 Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
3495 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3496 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3497 DeclarationNameInfo MemberNameInfo,
3498 const TemplateArgumentListInfo *TemplateArgs);
3500 static CXXDependentScopeMemberExpr *
3501 CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
3502 unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope);
3504 /// True if this is an implicit access, i.e. one in which the
3505 /// member being accessed was not written in the source. The source
3506 /// location of the operator is invalid in this case.
3507 bool isImplicitAccess() const {
3510 return cast<Expr>(Base)->isImplicitCXXThis();
3513 /// Retrieve the base object of this member expressions,
3514 /// e.g., the \c x in \c x.m.
3515 Expr *getBase() const {
3516 assert(!isImplicitAccess());
3517 return cast<Expr>(Base);
3520 QualType getBaseType() const { return BaseType; }
3522 /// Determine whether this member expression used the '->'
3523 /// operator; otherwise, it used the '.' operator.
3524 bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; }
3526 /// Retrieve the location of the '->' or '.' operator.
3527 SourceLocation getOperatorLoc() const {
3528 return CXXDependentScopeMemberExprBits.OperatorLoc;
3531 /// Retrieve the nested-name-specifier that qualifies the member name.
3532 NestedNameSpecifier *getQualifier() const {
3533 return QualifierLoc.getNestedNameSpecifier();
3536 /// Retrieve the nested-name-specifier that qualifies the member
3537 /// name, with source location information.
3538 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3540 /// Retrieve the first part of the nested-name-specifier that was
3541 /// found in the scope of the member access expression when the member access
3542 /// was initially parsed.
3544 /// This function only returns a useful result when member access expression
3545 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3546 /// returned by this function describes what was found by unqualified name
3547 /// lookup for the identifier "Base" within the scope of the member access
3548 /// expression itself. At template instantiation time, this information is
3549 /// combined with the results of name lookup into the type of the object
3550 /// expression itself (the class type of x).
3551 NamedDecl *getFirstQualifierFoundInScope() const {
3552 if (!hasFirstQualifierFoundInScope())
3554 return *getTrailingObjects<NamedDecl *>();
3557 /// Retrieve the name of the member that this expression refers to.
3558 const DeclarationNameInfo &getMemberNameInfo() const {
3559 return MemberNameInfo;
3562 /// Retrieve the name of the member that this expression refers to.
3563 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3565 // Retrieve the location of the name of the member that this
3566 // expression refers to.
3567 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3569 /// Retrieve the location of the template keyword preceding the
3570 /// member name, if any.
3571 SourceLocation getTemplateKeywordLoc() const {
3572 if (!hasTemplateKWAndArgsInfo())
3573 return SourceLocation();
3574 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3577 /// Retrieve the location of the left angle bracket starting the
3578 /// explicit template argument list following the member name, if any.
3579 SourceLocation getLAngleLoc() const {
3580 if (!hasTemplateKWAndArgsInfo())
3581 return SourceLocation();
3582 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3585 /// Retrieve the location of the right angle bracket ending the
3586 /// explicit template argument list following the member name, if any.
3587 SourceLocation getRAngleLoc() const {
3588 if (!hasTemplateKWAndArgsInfo())
3589 return SourceLocation();
3590 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3593 /// Determines whether the member name was preceded by the template keyword.
3594 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3596 /// Determines whether this member expression actually had a C++
3597 /// template argument list explicitly specified, e.g., x.f<int>.
3598 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3600 /// Copies the template arguments (if present) into the given
3602 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3603 if (hasExplicitTemplateArgs())
3604 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3605 getTrailingObjects<TemplateArgumentLoc>(), List);
3608 /// Retrieve the template arguments provided as part of this
3610 const TemplateArgumentLoc *getTemplateArgs() const {
3611 if (!hasExplicitTemplateArgs())
3614 return getTrailingObjects<TemplateArgumentLoc>();
3617 /// Retrieve the number of template arguments provided as part of this
3619 unsigned getNumTemplateArgs() const {
3620 if (!hasExplicitTemplateArgs())
3623 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3626 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3627 return {getTemplateArgs(), getNumTemplateArgs()};
3630 SourceLocation getBeginLoc() const LLVM_READONLY {
3631 if (!isImplicitAccess())
3632 return Base->getBeginLoc();
3634 return getQualifierLoc().getBeginLoc();
3635 return MemberNameInfo.getBeginLoc();
3638 SourceLocation getEndLoc() const LLVM_READONLY {
3639 if (hasExplicitTemplateArgs())
3640 return getRAngleLoc();
3641 return MemberNameInfo.getEndLoc();
3644 static bool classof(const Stmt *T) {
3645 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3649 child_range children() {
3650 if (isImplicitAccess())
3651 return child_range(child_iterator(), child_iterator());
3652 return child_range(&Base, &Base + 1);
3655 const_child_range children() const {
3656 if (isImplicitAccess())
3657 return const_child_range(const_child_iterator(), const_child_iterator());
3658 return const_child_range(&Base, &Base + 1);
3662 /// Represents a C++ member access expression for which lookup
3663 /// produced a set of overloaded functions.
3665 /// The member access may be explicit or implicit:
3669 /// int explicitAccess() { return this->a + this->A::b; }
3670 /// int implicitAccess() { return a + A::b; }
3674 /// In the final AST, an explicit access always becomes a MemberExpr.
3675 /// An implicit access may become either a MemberExpr or a
3676 /// DeclRefExpr, depending on whether the member is static.
3677 class UnresolvedMemberExpr final
3678 : public OverloadExpr,
3679 private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair,
3680 ASTTemplateKWAndArgsInfo,
3681 TemplateArgumentLoc> {
3682 friend class ASTStmtReader;
3683 friend class OverloadExpr;
3684 friend TrailingObjects;
3686 /// The expression for the base pointer or class reference,
3687 /// e.g., the \c x in x.f.
3689 /// This can be null if this is an 'unbased' member expression.
3692 /// The type of the base expression; never null.
3695 /// The location of the '->' or '.' operator.
3696 SourceLocation OperatorLoc;
3698 // UnresolvedMemberExpr is followed by several trailing objects.
3699 // They are in order:
3701 // * An array of getNumResults() DeclAccessPair for the results. These are
3702 // undesugared, which is to say, they may include UsingShadowDecls.
3703 // Access is relative to the naming class.
3705 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3706 // template keyword and arguments. Present if and only if
3707 // hasTemplateKWAndArgsInfo().
3709 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
3710 // location information for the explicitly specified template arguments.
3712 UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing,
3713 Expr *Base, QualType BaseType, bool IsArrow,
3714 SourceLocation OperatorLoc,
3715 NestedNameSpecifierLoc QualifierLoc,
3716 SourceLocation TemplateKWLoc,
3717 const DeclarationNameInfo &MemberNameInfo,
3718 const TemplateArgumentListInfo *TemplateArgs,
3719 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3721 UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults,
3722 bool HasTemplateKWAndArgsInfo);
3724 unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3725 return getNumDecls();
3728 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3729 return hasTemplateKWAndArgsInfo();
3733 static UnresolvedMemberExpr *
3734 Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
3735 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
3736 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3737 const DeclarationNameInfo &MemberNameInfo,
3738 const TemplateArgumentListInfo *TemplateArgs,
3739 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3741 static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context,
3742 unsigned NumResults,
3743 bool HasTemplateKWAndArgsInfo,
3744 unsigned NumTemplateArgs);
3746 /// True if this is an implicit access, i.e., one in which the
3747 /// member being accessed was not written in the source.
3749 /// The source location of the operator is invalid in this case.
3750 bool isImplicitAccess() const;
3752 /// Retrieve the base object of this member expressions,
3753 /// e.g., the \c x in \c x.m.
3755 assert(!isImplicitAccess());
3756 return cast<Expr>(Base);
3758 const Expr *getBase() const {
3759 assert(!isImplicitAccess());
3760 return cast<Expr>(Base);
3763 QualType getBaseType() const { return BaseType; }
3765 /// Determine whether the lookup results contain an unresolved using
3767 bool hasUnresolvedUsing() const {
3768 return UnresolvedMemberExprBits.HasUnresolvedUsing;
3771 /// Determine whether this member expression used the '->'
3772 /// operator; otherwise, it used the '.' operator.
3773 bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; }
3775 /// Retrieve the location of the '->' or '.' operator.
3776 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3778 /// Retrieve the naming class of this lookup.
3779 CXXRecordDecl *getNamingClass();
3780 const CXXRecordDecl *getNamingClass() const {
3781 return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass();
3784 /// Retrieve the full name info for the member that this expression
3786 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3788 /// Retrieve the name of the member that this expression refers to.
3789 DeclarationName getMemberName() const { return getName(); }
3791 /// Retrieve the location of the name of the member that this
3792 /// expression refers to.
3793 SourceLocation getMemberLoc() const { return getNameLoc(); }
3795 /// Return the preferred location (the member name) for the arrow when
3796 /// diagnosing a problem with this expression.
3797 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3799 SourceLocation getBeginLoc() const LLVM_READONLY {
3800 if (!isImplicitAccess())
3801 return Base->getBeginLoc();
3802 if (NestedNameSpecifierLoc l = getQualifierLoc())
3803 return l.getBeginLoc();
3804 return getMemberNameInfo().getBeginLoc();
3807 SourceLocation getEndLoc() const LLVM_READONLY {
3808 if (hasExplicitTemplateArgs())
3809 return getRAngleLoc();
3810 return getMemberNameInfo().getEndLoc();
3813 static bool classof(const Stmt *T) {
3814 return T->getStmtClass() == UnresolvedMemberExprClass;
3818 child_range children() {
3819 if (isImplicitAccess())
3820 return child_range(child_iterator(), child_iterator());
3821 return child_range(&Base, &Base + 1);
3824 const_child_range children() const {
3825 if (isImplicitAccess())
3826 return const_child_range(const_child_iterator(), const_child_iterator());
3827 return const_child_range(&Base, &Base + 1);
3831 DeclAccessPair *OverloadExpr::getTrailingResults() {
3832 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3833 return ULE->getTrailingObjects<DeclAccessPair>();
3834 return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>();
3837 ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3838 if (!hasTemplateKWAndArgsInfo())
3841 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3842 return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3843 return cast<UnresolvedMemberExpr>(this)
3844 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3847 TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3848 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3849 return ULE->getTrailingObjects<TemplateArgumentLoc>();
3850 return cast<UnresolvedMemberExpr>(this)
3851 ->getTrailingObjects<TemplateArgumentLoc>();
3854 CXXRecordDecl *OverloadExpr::getNamingClass() {
3855 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3856 return ULE->getNamingClass();
3857 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
3860 /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3862 /// The noexcept expression tests whether a given expression might throw. Its
3863 /// result is a boolean constant.
3864 class CXXNoexceptExpr : public Expr {
3865 friend class ASTStmtReader;
3871 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3872 SourceLocation Keyword, SourceLocation RParen)
3873 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3874 /*TypeDependent*/ false,
3875 /*ValueDependent*/ Val == CT_Dependent,
3876 Val == CT_Dependent || Operand->isInstantiationDependent(),
3877 Operand->containsUnexpandedParameterPack()),
3878 Operand(Operand), Range(Keyword, RParen) {
3879 CXXNoexceptExprBits.Value = Val == CT_Cannot;
3882 CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
3884 Expr *getOperand() const { return static_cast<Expr *>(Operand); }
3886 SourceLocation getBeginLoc() const { return Range.getBegin(); }
3887 SourceLocation getEndLoc() const { return Range.getEnd(); }
3888 SourceRange getSourceRange() const { return Range; }
3890 bool getValue() const { return CXXNoexceptExprBits.Value; }
3892 static bool classof(const Stmt *T) {
3893 return T->getStmtClass() == CXXNoexceptExprClass;
3897 child_range children() { return child_range(&Operand, &Operand + 1); }
3899 const_child_range children() const {
3900 return const_child_range(&Operand, &Operand + 1);
3904 /// Represents a C++11 pack expansion that produces a sequence of
3907 /// A pack expansion expression contains a pattern (which itself is an
3908 /// expression) followed by an ellipsis. For example:
3911 /// template<typename F, typename ...Types>
3912 /// void forward(F f, Types &&...args) {
3913 /// f(static_cast<Types&&>(args)...);
3917 /// Here, the argument to the function object \c f is a pack expansion whose
3918 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3919 /// template is instantiated, the pack expansion will instantiate to zero or
3920 /// or more function arguments to the function object \c f.
3921 class PackExpansionExpr : public Expr {
3922 friend class ASTStmtReader;
3923 friend class ASTStmtWriter;
3925 SourceLocation EllipsisLoc;
3927 /// The number of expansions that will be produced by this pack
3928 /// expansion expression, if known.
3930 /// When zero, the number of expansions is not known. Otherwise, this value
3931 /// is the number of expansions + 1.
3932 unsigned NumExpansions;
3937 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3938 Optional<unsigned> NumExpansions)
3939 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3940 Pattern->getObjectKind(), /*TypeDependent=*/true,
3941 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3942 /*ContainsUnexpandedParameterPack=*/false),
3943 EllipsisLoc(EllipsisLoc),
3944 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
3947 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {}
3949 /// Retrieve the pattern of the pack expansion.
3950 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3952 /// Retrieve the pattern of the pack expansion.
3953 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3955 /// Retrieve the location of the ellipsis that describes this pack
3957 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3959 /// Determine the number of expansions that will be produced when
3960 /// this pack expansion is instantiated, if already known.
3961 Optional<unsigned> getNumExpansions() const {
3963 return NumExpansions - 1;
3968 SourceLocation getBeginLoc() const LLVM_READONLY {
3969 return Pattern->getBeginLoc();
3972 SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; }
3974 static bool classof(const Stmt *T) {
3975 return T->getStmtClass() == PackExpansionExprClass;
3979 child_range children() {
3980 return child_range(&Pattern, &Pattern + 1);
3983 const_child_range children() const {
3984 return const_child_range(&Pattern, &Pattern + 1);
3988 /// Represents an expression that computes the length of a parameter
3992 /// template<typename ...Types>
3994 /// static const unsigned value = sizeof...(Types);
3997 class SizeOfPackExpr final
3999 private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
4000 friend class ASTStmtReader;
4001 friend class ASTStmtWriter;
4002 friend TrailingObjects;
4004 /// The location of the \c sizeof keyword.
4005 SourceLocation OperatorLoc;
4007 /// The location of the name of the parameter pack.
4008 SourceLocation PackLoc;
4010 /// The location of the closing parenthesis.
4011 SourceLocation RParenLoc;
4013 /// The length of the parameter pack, if known.
4015 /// When this expression is not value-dependent, this is the length of
4016 /// the pack. When the expression was parsed rather than instantiated
4017 /// (and thus is value-dependent), this is zero.
4019 /// After partial substitution into a sizeof...(X) expression (for instance,
4020 /// within an alias template or during function template argument deduction),
4021 /// we store a trailing array of partially-substituted TemplateArguments,
4022 /// and this is the length of that array.
4025 /// The parameter pack.
4026 NamedDecl *Pack = nullptr;
4028 /// Create an expression that computes the length of
4029 /// the given parameter pack.
4030 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
4031 SourceLocation PackLoc, SourceLocation RParenLoc,
4032 Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
4033 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
4034 /*TypeDependent=*/false, /*ValueDependent=*/!Length,
4035 /*InstantiationDependent=*/!Length,
4036 /*ContainsUnexpandedParameterPack=*/false),
4037 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
4038 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
4039 assert((!Length || PartialArgs.empty()) &&
4040 "have partial args for non-dependent sizeof... expression");
4041 auto *Args = getTrailingObjects<TemplateArgument>();
4042 std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
4045 /// Create an empty expression.
4046 SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
4047 : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
4050 static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
4051 NamedDecl *Pack, SourceLocation PackLoc,
4052 SourceLocation RParenLoc,
4053 Optional<unsigned> Length = None,
4054 ArrayRef<TemplateArgument> PartialArgs = None);
4055 static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
4056 unsigned NumPartialArgs);
4058 /// Determine the location of the 'sizeof' keyword.
4059 SourceLocation getOperatorLoc() const { return OperatorLoc; }
4061 /// Determine the location of the parameter pack.
4062 SourceLocation getPackLoc() const { return PackLoc; }
4064 /// Determine the location of the right parenthesis.
4065 SourceLocation getRParenLoc() const { return RParenLoc; }
4067 /// Retrieve the parameter pack.
4068 NamedDecl *getPack() const { return Pack; }
4070 /// Retrieve the length of the parameter pack.
4072 /// This routine may only be invoked when the expression is not
4073 /// value-dependent.
4074 unsigned getPackLength() const {
4075 assert(!isValueDependent() &&
4076 "Cannot get the length of a value-dependent pack size expression");
4080 /// Determine whether this represents a partially-substituted sizeof...
4081 /// expression, such as is produced for:
4083 /// template<typename ...Ts> using X = int[sizeof...(Ts)];
4084 /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
4085 bool isPartiallySubstituted() const {
4086 return isValueDependent() && Length;
4090 ArrayRef<TemplateArgument> getPartialArguments() const {
4091 assert(isPartiallySubstituted());
4092 const auto *Args = getTrailingObjects<TemplateArgument>();
4093 return llvm::makeArrayRef(Args, Args + Length);
4096 SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
4097 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4099 static bool classof(const Stmt *T) {
4100 return T->getStmtClass() == SizeOfPackExprClass;
4104 child_range children() {
4105 return child_range(child_iterator(), child_iterator());
4108 const_child_range children() const {
4109 return const_child_range(const_child_iterator(), const_child_iterator());
4113 /// Represents a reference to a non-type template parameter
4114 /// that has been substituted with a template argument.
4115 class SubstNonTypeTemplateParmExpr : public Expr {
4116 friend class ASTReader;
4117 friend class ASTStmtReader;
4119 /// The replaced parameter.
4120 NonTypeTemplateParmDecl *Param;
4122 /// The replacement expression.
4125 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
4126 : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
4129 SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
4131 NonTypeTemplateParmDecl *Param,
4133 : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary,
4134 Replacement->isTypeDependent(), Replacement->isValueDependent(),
4135 Replacement->isInstantiationDependent(),
4136 Replacement->containsUnexpandedParameterPack()),
4137 Param(Param), Replacement(Replacement) {
4138 SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
4141 SourceLocation getNameLoc() const {
4142 return SubstNonTypeTemplateParmExprBits.NameLoc;
4144 SourceLocation getBeginLoc() const { return getNameLoc(); }
4145 SourceLocation getEndLoc() const { return getNameLoc(); }
4147 Expr *getReplacement() const { return cast<Expr>(Replacement); }
4149 NonTypeTemplateParmDecl *getParameter() const { return Param; }
4151 static bool classof(const Stmt *s) {
4152 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
4156 child_range children() { return child_range(&Replacement, &Replacement + 1); }
4158 const_child_range children() const {
4159 return const_child_range(&Replacement, &Replacement + 1);
4163 /// Represents a reference to a non-type template parameter pack that
4164 /// has been substituted with a non-template argument pack.
4166 /// When a pack expansion in the source code contains multiple parameter packs
4167 /// and those parameter packs correspond to different levels of template
4168 /// parameter lists, this node is used to represent a non-type template
4169 /// parameter pack from an outer level, which has already had its argument pack
4170 /// substituted but that still lives within a pack expansion that itself
4171 /// could not be instantiated. When actually performing a substitution into
4172 /// that pack expansion (e.g., when all template parameters have corresponding
4173 /// arguments), this type will be replaced with the appropriate underlying
4174 /// expression at the current pack substitution index.
4175 class SubstNonTypeTemplateParmPackExpr : public Expr {
4176 friend class ASTReader;
4177 friend class ASTStmtReader;
4179 /// The non-type template parameter pack itself.
4180 NonTypeTemplateParmDecl *Param;
4182 /// A pointer to the set of template arguments that this
4183 /// parameter pack is instantiated with.
4184 const TemplateArgument *Arguments;
4186 /// The number of template arguments in \c Arguments.
4187 unsigned NumArguments;
4189 /// The location of the non-type template parameter pack reference.
4190 SourceLocation NameLoc;
4192 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
4193 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {}
4196 SubstNonTypeTemplateParmPackExpr(QualType T,
4197 ExprValueKind ValueKind,
4198 NonTypeTemplateParmDecl *Param,
4199 SourceLocation NameLoc,
4200 const TemplateArgument &ArgPack);
4202 /// Retrieve the non-type template parameter pack being substituted.
4203 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
4205 /// Retrieve the location of the parameter pack name.
4206 SourceLocation getParameterPackLocation() const { return NameLoc; }
4208 /// Retrieve the template argument pack containing the substituted
4209 /// template arguments.
4210 TemplateArgument getArgumentPack() const;
4212 SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
4213 SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4215 static bool classof(const Stmt *T) {
4216 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
4220 child_range children() {
4221 return child_range(child_iterator(), child_iterator());
4224 const_child_range children() const {
4225 return const_child_range(const_child_iterator(), const_child_iterator());
4229 /// Represents a reference to a function parameter pack or init-capture pack
4230 /// that has been substituted but not yet expanded.
4232 /// When a pack expansion contains multiple parameter packs at different levels,
4233 /// this node is used to represent a function parameter pack at an outer level
4234 /// which we have already substituted to refer to expanded parameters, but where
4235 /// the containing pack expansion cannot yet be expanded.
4238 /// template<typename...Ts> struct S {
4239 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
4241 /// template struct S<int, int>;
4243 class FunctionParmPackExpr final
4245 private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> {
4246 friend class ASTReader;
4247 friend class ASTStmtReader;
4248 friend TrailingObjects;
4250 /// The function parameter pack which was referenced.
4253 /// The location of the function parameter pack reference.
4254 SourceLocation NameLoc;
4256 /// The number of expansions of this pack.
4257 unsigned NumParameters;
4259 FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
4260 SourceLocation NameLoc, unsigned NumParams,
4261 VarDecl *const *Params);
4264 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
4266 SourceLocation NameLoc,
4267 ArrayRef<VarDecl *> Params);
4268 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
4269 unsigned NumParams);
4271 /// Get the parameter pack which this expression refers to.
4272 VarDecl *getParameterPack() const { return ParamPack; }
4274 /// Get the location of the parameter pack.
4275 SourceLocation getParameterPackLocation() const { return NameLoc; }
4277 /// Iterators over the parameters which the parameter pack expanded
4279 using iterator = VarDecl * const *;
4280 iterator begin() const { return getTrailingObjects<VarDecl *>(); }
4281 iterator end() const { return begin() + NumParameters; }
4283 /// Get the number of parameters in this parameter pack.
4284 unsigned getNumExpansions() const { return NumParameters; }
4286 /// Get an expansion of the parameter pack by index.
4287 VarDecl *getExpansion(unsigned I) const { return begin()[I]; }
4289 SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
4290 SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4292 static bool classof(const Stmt *T) {
4293 return T->getStmtClass() == FunctionParmPackExprClass;
4296 child_range children() {
4297 return child_range(child_iterator(), child_iterator());
4300 const_child_range children() const {
4301 return const_child_range(const_child_iterator(), const_child_iterator());
4305 /// Represents a prvalue temporary that is written into memory so that
4306 /// a reference can bind to it.
4308 /// Prvalue expressions are materialized when they need to have an address
4309 /// in memory for a reference to bind to. This happens when binding a
4310 /// reference to the result of a conversion, e.g.,
4313 /// const int &r = 1.0;
4316 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
4317 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
4318 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
4319 /// (either an lvalue or an xvalue, depending on the kind of reference binding
4320 /// to it), maintaining the invariant that references always bind to glvalues.
4322 /// Reference binding and copy-elision can both extend the lifetime of a
4323 /// temporary. When either happens, the expression will also track the
4324 /// declaration which is responsible for the lifetime extension.
4325 class MaterializeTemporaryExpr : public Expr {
4327 friend class ASTStmtReader;
4328 friend class ASTStmtWriter;
4331 /// The temporary-generating expression whose value will be
4335 /// The declaration which lifetime-extended this reference, if any.
4336 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
4337 const ValueDecl *ExtendingDecl;
4339 unsigned ManglingNumber;
4341 llvm::PointerUnion<Stmt *, ExtraState *> State;
4343 void initializeExtraState(const ValueDecl *ExtendedBy,
4344 unsigned ManglingNumber);
4347 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
4348 bool BoundToLvalueReference)
4349 : Expr(MaterializeTemporaryExprClass, T,
4350 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
4351 Temporary->isTypeDependent(), Temporary->isValueDependent(),
4352 Temporary->isInstantiationDependent(),
4353 Temporary->containsUnexpandedParameterPack()),
4356 MaterializeTemporaryExpr(EmptyShell Empty)
4357 : Expr(MaterializeTemporaryExprClass, Empty) {}
4359 Stmt *getTemporary() const {
4360 return State.is<Stmt *>() ? State.get<Stmt *>()
4361 : State.get<ExtraState *>()->Temporary;
4364 /// Retrieve the temporary-generating subexpression whose value will
4365 /// be materialized into a glvalue.
4366 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
4368 /// Retrieve the storage duration for the materialized temporary.
4369 StorageDuration getStorageDuration() const {
4370 const ValueDecl *ExtendingDecl = getExtendingDecl();
4372 return SD_FullExpression;
4373 // FIXME: This is not necessarily correct for a temporary materialized
4374 // within a default initializer.
4375 if (isa<FieldDecl>(ExtendingDecl))
4376 return SD_Automatic;
4377 // FIXME: This only works because storage class specifiers are not allowed
4378 // on decomposition declarations.
4379 if (isa<BindingDecl>(ExtendingDecl))
4380 return ExtendingDecl->getDeclContext()->isFunctionOrMethod()
4383 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
4386 /// Get the declaration which triggered the lifetime-extension of this
4387 /// temporary, if any.
4388 const ValueDecl *getExtendingDecl() const {
4389 return State.is<Stmt *>() ? nullptr
4390 : State.get<ExtraState *>()->ExtendingDecl;
4393 void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
4395 unsigned getManglingNumber() const {
4396 return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
4399 /// Determine whether this materialized temporary is bound to an
4400 /// lvalue reference; otherwise, it's bound to an rvalue reference.
4401 bool isBoundToLvalueReference() const {
4402 return getValueKind() == VK_LValue;
4405 SourceLocation getBeginLoc() const LLVM_READONLY {
4406 return getTemporary()->getBeginLoc();
4409 SourceLocation getEndLoc() const LLVM_READONLY {
4410 return getTemporary()->getEndLoc();
4413 static bool classof(const Stmt *T) {
4414 return T->getStmtClass() == MaterializeTemporaryExprClass;
4418 child_range children() {
4419 if (State.is<Stmt *>())
4420 return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
4422 auto ES = State.get<ExtraState *>();
4423 return child_range(&ES->Temporary, &ES->Temporary + 1);
4426 const_child_range children() const {
4427 if (State.is<Stmt *>())
4428 return const_child_range(State.getAddrOfPtr1(),
4429 State.getAddrOfPtr1() + 1);
4431 auto ES = State.get<ExtraState *>();
4432 return const_child_range(&ES->Temporary, &ES->Temporary + 1);
4436 /// Represents a folding of a pack over an operator.
4438 /// This expression is always dependent and represents a pack expansion of the
4443 /// ( expr op ... op expr )
4444 class CXXFoldExpr : public Expr {
4445 friend class ASTStmtReader;
4446 friend class ASTStmtWriter;
4448 SourceLocation LParenLoc;
4449 SourceLocation EllipsisLoc;
4450 SourceLocation RParenLoc;
4451 // When 0, the number of expansions is not known. Otherwise, this is one more
4452 // than the number of expansions.
4453 unsigned NumExpansions;
4455 BinaryOperatorKind Opcode;
4458 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
4459 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
4460 SourceLocation RParenLoc, Optional<unsigned> NumExpansions)
4461 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
4462 /*Dependent*/ true, true, true,
4463 /*ContainsUnexpandedParameterPack*/ false),
4464 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4465 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) {
4470 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4472 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
4473 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
4475 /// Does this produce a right-associated sequence of operators?
4476 bool isRightFold() const {
4477 return getLHS() && getLHS()->containsUnexpandedParameterPack();
4480 /// Does this produce a left-associated sequence of operators?
4481 bool isLeftFold() const { return !isRightFold(); }
4483 /// Get the pattern, that is, the operand that contains an unexpanded pack.
4484 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4486 /// Get the operand that doesn't contain a pack, for a binary fold.
4487 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4489 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4490 BinaryOperatorKind getOperator() const { return Opcode; }
4492 Optional<unsigned> getNumExpansions() const {
4494 return NumExpansions - 1;
4498 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4500 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4502 static bool classof(const Stmt *T) {
4503 return T->getStmtClass() == CXXFoldExprClass;
4507 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4509 const_child_range children() const {
4510 return const_child_range(SubExprs, SubExprs + 2);
4514 /// Represents an expression that might suspend coroutine execution;
4515 /// either a co_await or co_yield expression.
4517 /// Evaluation of this expression first evaluates its 'ready' expression. If
4518 /// that returns 'false':
4519 /// -- execution of the coroutine is suspended
4520 /// -- the 'suspend' expression is evaluated
4521 /// -- if the 'suspend' expression returns 'false', the coroutine is
4523 /// -- otherwise, control passes back to the resumer.
4524 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4525 /// expression is evaluated, and its result is the result of the overall
4527 class CoroutineSuspendExpr : public Expr {
4528 friend class ASTStmtReader;
4530 SourceLocation KeywordLoc;
4532 enum SubExpr { Common, Ready, Suspend, Resume, Count };
4534 Stmt *SubExprs[SubExpr::Count];
4535 OpaqueValueExpr *OpaqueValue = nullptr;
4538 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4539 Expr *Ready, Expr *Suspend, Expr *Resume,
4540 OpaqueValueExpr *OpaqueValue)
4541 : Expr(SC, Resume->getType(), Resume->getValueKind(),
4542 Resume->getObjectKind(), Resume->isTypeDependent(),
4543 Resume->isValueDependent(), Common->isInstantiationDependent(),
4544 Common->containsUnexpandedParameterPack()),
4545 KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
4546 SubExprs[SubExpr::Common] = Common;
4547 SubExprs[SubExpr::Ready] = Ready;
4548 SubExprs[SubExpr::Suspend] = Suspend;
4549 SubExprs[SubExpr::Resume] = Resume;
4552 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4554 : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
4555 Common->containsUnexpandedParameterPack()),
4556 KeywordLoc(KeywordLoc) {
4557 assert(Common->isTypeDependent() && Ty->isDependentType() &&
4558 "wrong constructor for non-dependent co_await/co_yield expression");
4559 SubExprs[SubExpr::Common] = Common;
4560 SubExprs[SubExpr::Ready] = nullptr;
4561 SubExprs[SubExpr::Suspend] = nullptr;
4562 SubExprs[SubExpr::Resume] = nullptr;
4565 CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4566 SubExprs[SubExpr::Common] = nullptr;
4567 SubExprs[SubExpr::Ready] = nullptr;
4568 SubExprs[SubExpr::Suspend] = nullptr;
4569 SubExprs[SubExpr::Resume] = nullptr;
4572 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4574 Expr *getCommonExpr() const {
4575 return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4578 /// getOpaqueValue - Return the opaque value placeholder.
4579 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4581 Expr *getReadyExpr() const {
4582 return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4585 Expr *getSuspendExpr() const {
4586 return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4589 Expr *getResumeExpr() const {
4590 return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4593 SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4595 SourceLocation getEndLoc() const LLVM_READONLY {
4596 return getCommonExpr()->getEndLoc();
4599 child_range children() {
4600 return child_range(SubExprs, SubExprs + SubExpr::Count);
4603 const_child_range children() const {
4604 return const_child_range(SubExprs, SubExprs + SubExpr::Count);
4607 static bool classof(const Stmt *T) {
4608 return T->getStmtClass() == CoawaitExprClass ||
4609 T->getStmtClass() == CoyieldExprClass;
4613 /// Represents a 'co_await' expression.
4614 class CoawaitExpr : public CoroutineSuspendExpr {
4615 friend class ASTStmtReader;
4618 CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4619 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
4620 bool IsImplicit = false)
4621 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4622 Suspend, Resume, OpaqueValue) {
4623 CoawaitBits.IsImplicit = IsImplicit;
4626 CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
4627 bool IsImplicit = false)
4628 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
4629 CoawaitBits.IsImplicit = IsImplicit;
4632 CoawaitExpr(EmptyShell Empty)
4633 : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4635 Expr *getOperand() const {
4636 // FIXME: Dig out the actual operand or store it.
4637 return getCommonExpr();
4640 bool isImplicit() const { return CoawaitBits.IsImplicit; }
4641 void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
4643 static bool classof(const Stmt *T) {
4644 return T->getStmtClass() == CoawaitExprClass;
4648 /// Represents a 'co_await' expression while the type of the promise
4650 class DependentCoawaitExpr : public Expr {
4651 friend class ASTStmtReader;
4653 SourceLocation KeywordLoc;
4657 DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
4658 UnresolvedLookupExpr *OpCoawait)
4659 : Expr(DependentCoawaitExprClass, Ty, VK_RValue, OK_Ordinary,
4660 /*TypeDependent*/ true, /*ValueDependent*/ true,
4661 /*InstantiationDependent*/ true,
4662 Op->containsUnexpandedParameterPack()),
4663 KeywordLoc(KeywordLoc) {
4664 // NOTE: A co_await expression is dependent on the coroutines promise
4665 // type and may be dependent even when the `Op` expression is not.
4666 assert(Ty->isDependentType() &&
4667 "wrong constructor for non-dependent co_await/co_yield expression");
4669 SubExprs[1] = OpCoawait;
4672 DependentCoawaitExpr(EmptyShell Empty)
4673 : Expr(DependentCoawaitExprClass, Empty) {}
4675 Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
4677 UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
4678 return cast<UnresolvedLookupExpr>(SubExprs[1]);
4681 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4683 SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4685 SourceLocation getEndLoc() const LLVM_READONLY {
4686 return getOperand()->getEndLoc();
4689 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4691 const_child_range children() const {
4692 return const_child_range(SubExprs, SubExprs + 2);
4695 static bool classof(const Stmt *T) {
4696 return T->getStmtClass() == DependentCoawaitExprClass;
4700 /// Represents a 'co_yield' expression.
4701 class CoyieldExpr : public CoroutineSuspendExpr {
4702 friend class ASTStmtReader;
4705 CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4706 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
4707 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4708 Suspend, Resume, OpaqueValue) {}
4709 CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4710 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
4711 CoyieldExpr(EmptyShell Empty)
4712 : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4714 Expr *getOperand() const {
4715 // FIXME: Dig out the actual operand or store it.
4716 return getCommonExpr();
4719 static bool classof(const Stmt *T) {
4720 return T->getStmtClass() == CoyieldExprClass;
4724 /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement
4725 /// std::bit_cast. These can sometimes be evaluated as part of a constant
4726 /// expression, but otherwise CodeGen to a simple memcpy in general.
4727 class BuiltinBitCastExpr final
4728 : public ExplicitCastExpr,
4729 private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> {
4730 friend class ASTStmtReader;
4731 friend class CastExpr;
4732 friend class TrailingObjects;
4734 SourceLocation KWLoc;
4735 SourceLocation RParenLoc;
4738 BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
4739 TypeSourceInfo *DstType, SourceLocation KWLoc,
4740 SourceLocation RParenLoc)
4741 : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0,
4743 KWLoc(KWLoc), RParenLoc(RParenLoc) {}
4745 SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; }
4746 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4748 static bool classof(const Stmt *T) {
4749 return T->getStmtClass() == BuiltinBitCastExprClass;
4753 } // namespace clang
4755 #endif // LLVM_CLANG_AST_EXPRCXX_H