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/DeclTemplate.h"
21 #include "clang/AST/DeclarationName.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/NestedNameSpecifier.h"
24 #include "clang/AST/OperationKinds.h"
25 #include "clang/AST/Stmt.h"
26 #include "clang/AST/TemplateBase.h"
27 #include "clang/AST/Type.h"
28 #include "clang/AST/UnresolvedSet.h"
29 #include "clang/Basic/ExceptionSpecificationType.h"
30 #include "clang/Basic/ExpressionTraits.h"
31 #include "clang/Basic/LLVM.h"
32 #include "clang/Basic/Lambda.h"
33 #include "clang/Basic/LangOptions.h"
34 #include "clang/Basic/OperatorKinds.h"
35 #include "clang/Basic/SourceLocation.h"
36 #include "clang/Basic/Specifiers.h"
37 #include "clang/Basic/TypeTraits.h"
38 #include "llvm/ADT/ArrayRef.h"
39 #include "llvm/ADT/None.h"
40 #include "llvm/ADT/Optional.h"
41 #include "llvm/ADT/PointerUnion.h"
42 #include "llvm/ADT/StringRef.h"
43 #include "llvm/ADT/iterator_range.h"
44 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/Compiler.h"
46 #include "llvm/Support/TrailingObjects.h"
58 class NonTypeTemplateParmDecl;
59 class TemplateParameterList;
61 //===--------------------------------------------------------------------===//
63 //===--------------------------------------------------------------------===//
65 /// A call to an overloaded operator written using operator
68 /// Represents a call to an overloaded operator written using operator
69 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
70 /// normal call, this AST node provides better information about the
71 /// syntactic representation of the call.
73 /// In a C++ template, this expression node kind will be used whenever
74 /// any of the arguments are type-dependent. In this case, the
75 /// function itself will be a (possibly empty) set of functions and
76 /// function templates that were found by name lookup at template
78 class CXXOperatorCallExpr final : public CallExpr {
79 friend class ASTStmtReader;
80 friend class ASTStmtWriter;
84 // CXXOperatorCallExpr has some trailing objects belonging
85 // to CallExpr. See CallExpr for the details.
87 SourceRange getSourceRangeImpl() const LLVM_READONLY;
89 CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn,
90 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
91 SourceLocation OperatorLoc, FPOptions FPFeatures,
94 CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty);
97 static CXXOperatorCallExpr *
98 Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
99 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
100 SourceLocation OperatorLoc, FPOptions FPFeatures,
101 ADLCallKind UsesADL = NotADL);
103 static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx,
104 unsigned NumArgs, EmptyShell Empty);
106 /// Returns the kind of overloaded operator that this expression refers to.
107 OverloadedOperatorKind getOperator() const {
108 return static_cast<OverloadedOperatorKind>(
109 CXXOperatorCallExprBits.OperatorKind);
112 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
113 return Opc == OO_Equal || Opc == OO_StarEqual || Opc == OO_SlashEqual ||
114 Opc == OO_PercentEqual || Opc == OO_PlusEqual ||
115 Opc == OO_MinusEqual || Opc == OO_LessLessEqual ||
116 Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual ||
117 Opc == OO_CaretEqual || Opc == OO_PipeEqual;
119 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
121 /// Is this written as an infix binary operator?
122 bool isInfixBinaryOp() const;
124 /// Returns the location of the operator symbol in the expression.
126 /// When \c getOperator()==OO_Call, this is the location of the right
127 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
128 /// of the right bracket.
129 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
131 SourceLocation getExprLoc() const LLVM_READONLY {
132 OverloadedOperatorKind Operator = getOperator();
133 return (Operator < OO_Plus || Operator >= OO_Arrow ||
134 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
139 SourceLocation getBeginLoc() const { return Range.getBegin(); }
140 SourceLocation getEndLoc() const { return Range.getEnd(); }
141 SourceRange getSourceRange() const { return Range; }
143 static bool classof(const Stmt *T) {
144 return T->getStmtClass() == CXXOperatorCallExprClass;
147 // Set the FP contractability status of this operator. Only meaningful for
148 // operations on floating point types.
149 void setFPFeatures(FPOptions F) {
150 CXXOperatorCallExprBits.FPFeatures = F.getInt();
152 FPOptions getFPFeatures() const {
153 return FPOptions(CXXOperatorCallExprBits.FPFeatures);
156 // Get the FP contractability status of this operator. Only meaningful for
157 // operations on floating point types.
158 bool isFPContractableWithinStatement() const {
159 return getFPFeatures().allowFPContractWithinStatement();
163 /// Represents a call to a member function that
164 /// may be written either with member call syntax (e.g., "obj.func()"
165 /// or "objptr->func()") or with normal function-call syntax
166 /// ("func()") within a member function that ends up calling a member
167 /// function. The callee in either case is a MemberExpr that contains
168 /// both the object argument and the member function, while the
169 /// arguments are the arguments within the parentheses (not including
170 /// the object argument).
171 class CXXMemberCallExpr final : public CallExpr {
172 // CXXMemberCallExpr has some trailing objects belonging
173 // to CallExpr. See CallExpr for the details.
175 CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
176 ExprValueKind VK, SourceLocation RP, unsigned MinNumArgs);
178 CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty);
181 static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
182 ArrayRef<Expr *> Args, QualType Ty,
183 ExprValueKind VK, SourceLocation RP,
184 unsigned MinNumArgs = 0);
186 static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
189 /// Retrieve the implicit object argument for the member call.
191 /// For example, in "x.f(5)", this returns the sub-expression "x".
192 Expr *getImplicitObjectArgument() const;
194 /// Retrieve the type of the object argument.
196 /// Note that this always returns a non-pointer type.
197 QualType getObjectType() const;
199 /// Retrieve the declaration of the called method.
200 CXXMethodDecl *getMethodDecl() const;
202 /// Retrieve the CXXRecordDecl for the underlying type of
203 /// the implicit object argument.
205 /// Note that this is may not be the same declaration as that of the class
206 /// context of the CXXMethodDecl which this function is calling.
207 /// FIXME: Returns 0 for member pointer call exprs.
208 CXXRecordDecl *getRecordDecl() const;
210 SourceLocation getExprLoc() const LLVM_READONLY {
211 SourceLocation CLoc = getCallee()->getExprLoc();
215 return getBeginLoc();
218 static bool classof(const Stmt *T) {
219 return T->getStmtClass() == CXXMemberCallExprClass;
223 /// Represents a call to a CUDA kernel function.
224 class CUDAKernelCallExpr final : public CallExpr {
225 friend class ASTStmtReader;
227 enum { CONFIG, END_PREARG };
229 // CUDAKernelCallExpr has some trailing objects belonging
230 // to CallExpr. See CallExpr for the details.
232 CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args,
233 QualType Ty, ExprValueKind VK, SourceLocation RP,
234 unsigned MinNumArgs);
236 CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty);
239 static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn,
240 CallExpr *Config, ArrayRef<Expr *> Args,
241 QualType Ty, ExprValueKind VK,
242 SourceLocation RP, unsigned MinNumArgs = 0);
244 static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx,
245 unsigned NumArgs, EmptyShell Empty);
247 const CallExpr *getConfig() const {
248 return cast_or_null<CallExpr>(getPreArg(CONFIG));
250 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
252 static bool classof(const Stmt *T) {
253 return T->getStmtClass() == CUDAKernelCallExprClass;
257 /// A rewritten comparison expression that was originally written using
260 /// In C++20, the following rewrites are performed:
261 /// - <tt>a == b</tt> -> <tt>b == a</tt>
262 /// - <tt>a != b</tt> -> <tt>!(a == b)</tt>
263 /// - <tt>a != b</tt> -> <tt>!(b == a)</tt>
264 /// - For \c \@ in \c <, \c <=, \c >, \c >=, \c <=>:
265 /// - <tt>a @ b</tt> -> <tt>(a <=> b) @ 0</tt>
266 /// - <tt>a @ b</tt> -> <tt>0 @ (b <=> a)</tt>
268 /// This expression provides access to both the original syntax and the
269 /// rewritten expression.
271 /// Note that the rewritten calls to \c ==, \c <=>, and \c \@ are typically
272 /// \c CXXOperatorCallExprs, but could theoretically be \c BinaryOperators.
273 class CXXRewrittenBinaryOperator : public Expr {
274 friend class ASTStmtReader;
276 /// The rewritten semantic form.
280 CXXRewrittenBinaryOperator(Expr *SemanticForm, bool IsReversed)
281 : Expr(CXXRewrittenBinaryOperatorClass, SemanticForm->getType(),
282 SemanticForm->getValueKind(), SemanticForm->getObjectKind(),
283 SemanticForm->isTypeDependent(), SemanticForm->isValueDependent(),
284 SemanticForm->isInstantiationDependent(),
285 SemanticForm->containsUnexpandedParameterPack()),
286 SemanticForm(SemanticForm) {
287 CXXRewrittenBinaryOperatorBits.IsReversed = IsReversed;
289 CXXRewrittenBinaryOperator(EmptyShell Empty)
290 : Expr(CXXRewrittenBinaryOperatorClass, Empty), SemanticForm() {}
292 /// Get an equivalent semantic form for this expression.
293 Expr *getSemanticForm() { return cast<Expr>(SemanticForm); }
294 const Expr *getSemanticForm() const { return cast<Expr>(SemanticForm); }
296 struct DecomposedForm {
297 /// The original opcode, prior to rewriting.
298 BinaryOperatorKind Opcode;
299 /// The original left-hand side.
301 /// The original right-hand side.
303 /// The inner \c == or \c <=> operator expression.
304 const Expr *InnerBinOp;
307 /// Decompose this operator into its syntactic form.
308 DecomposedForm getDecomposedForm() const LLVM_READONLY;
310 /// Determine whether this expression was rewritten in reverse form.
311 bool isReversed() const { return CXXRewrittenBinaryOperatorBits.IsReversed; }
313 BinaryOperatorKind getOperator() const { return getDecomposedForm().Opcode; }
314 const Expr *getLHS() const { return getDecomposedForm().LHS; }
315 const Expr *getRHS() const { return getDecomposedForm().RHS; }
317 SourceLocation getOperatorLoc() const LLVM_READONLY {
318 return getDecomposedForm().InnerBinOp->getExprLoc();
320 SourceLocation getExprLoc() const LLVM_READONLY { return getOperatorLoc(); }
322 /// Compute the begin and end locations from the decomposed form.
323 /// The locations of the semantic form are not reliable if this is
324 /// a reversed expression.
326 SourceLocation getBeginLoc() const LLVM_READONLY {
327 return getDecomposedForm().LHS->getBeginLoc();
329 SourceLocation getEndLoc() const LLVM_READONLY {
330 return getDecomposedForm().RHS->getEndLoc();
332 SourceRange getSourceRange() const LLVM_READONLY {
333 DecomposedForm DF = getDecomposedForm();
334 return SourceRange(DF.LHS->getBeginLoc(), DF.RHS->getEndLoc());
338 child_range children() {
339 return child_range(&SemanticForm, &SemanticForm + 1);
342 static bool classof(const Stmt *T) {
343 return T->getStmtClass() == CXXRewrittenBinaryOperatorClass;
347 /// Abstract class common to all of the C++ "named"/"keyword" casts.
349 /// This abstract class is inherited by all of the classes
350 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
351 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
352 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
353 class CXXNamedCastExpr : public ExplicitCastExpr {
355 // the location of the casting op
358 // the location of the right parenthesis
359 SourceLocation RParenLoc;
362 SourceRange AngleBrackets;
365 friend class ASTStmtReader;
367 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
368 CastKind kind, Expr *op, unsigned PathSize,
369 TypeSourceInfo *writtenTy, SourceLocation l,
370 SourceLocation RParenLoc,
371 SourceRange AngleBrackets)
372 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
373 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
375 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
376 : ExplicitCastExpr(SC, Shell, PathSize) {}
379 const char *getCastName() const;
381 /// Retrieve the location of the cast operator keyword, e.g.,
383 SourceLocation getOperatorLoc() const { return Loc; }
385 /// Retrieve the location of the closing parenthesis.
386 SourceLocation getRParenLoc() const { return RParenLoc; }
388 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
389 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
390 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
392 static bool classof(const Stmt *T) {
393 switch (T->getStmtClass()) {
394 case CXXStaticCastExprClass:
395 case CXXDynamicCastExprClass:
396 case CXXReinterpretCastExprClass:
397 case CXXConstCastExprClass:
405 /// A C++ \c static_cast expression (C++ [expr.static.cast]).
407 /// This expression node represents a C++ static cast, e.g.,
408 /// \c static_cast<int>(1.0).
409 class CXXStaticCastExpr final
410 : public CXXNamedCastExpr,
411 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
412 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
413 unsigned pathSize, TypeSourceInfo *writtenTy,
414 SourceLocation l, SourceLocation RParenLoc,
415 SourceRange AngleBrackets)
416 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
417 writtenTy, l, RParenLoc, AngleBrackets) {}
419 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
420 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) {}
423 friend class CastExpr;
424 friend TrailingObjects;
426 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
427 ExprValueKind VK, CastKind K, Expr *Op,
428 const CXXCastPath *Path,
429 TypeSourceInfo *Written, SourceLocation L,
430 SourceLocation RParenLoc,
431 SourceRange AngleBrackets);
432 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
435 static bool classof(const Stmt *T) {
436 return T->getStmtClass() == CXXStaticCastExprClass;
440 /// A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
442 /// This expression node represents a dynamic cast, e.g.,
443 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
444 /// check to determine how to perform the type conversion.
445 class CXXDynamicCastExpr final
446 : public CXXNamedCastExpr,
447 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
448 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
449 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
450 SourceLocation l, SourceLocation RParenLoc,
451 SourceRange AngleBrackets)
452 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
453 writtenTy, l, RParenLoc, AngleBrackets) {}
455 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
456 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) {}
459 friend class CastExpr;
460 friend TrailingObjects;
462 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
463 ExprValueKind VK, CastKind Kind, Expr *Op,
464 const CXXCastPath *Path,
465 TypeSourceInfo *Written, SourceLocation L,
466 SourceLocation RParenLoc,
467 SourceRange AngleBrackets);
469 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
472 bool isAlwaysNull() const;
474 static bool classof(const Stmt *T) {
475 return T->getStmtClass() == CXXDynamicCastExprClass;
479 /// A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
481 /// This expression node represents a reinterpret cast, e.g.,
482 /// @c reinterpret_cast<int>(VoidPtr).
484 /// A reinterpret_cast provides a differently-typed view of a value but
485 /// (in Clang, as in most C++ implementations) performs no actual work at
487 class CXXReinterpretCastExpr final
488 : public CXXNamedCastExpr,
489 private llvm::TrailingObjects<CXXReinterpretCastExpr,
490 CXXBaseSpecifier *> {
491 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
492 Expr *op, unsigned pathSize,
493 TypeSourceInfo *writtenTy, SourceLocation l,
494 SourceLocation RParenLoc,
495 SourceRange AngleBrackets)
496 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
497 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
499 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
500 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) {}
503 friend class CastExpr;
504 friend TrailingObjects;
506 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
507 ExprValueKind VK, CastKind Kind,
508 Expr *Op, const CXXCastPath *Path,
509 TypeSourceInfo *WrittenTy, SourceLocation L,
510 SourceLocation RParenLoc,
511 SourceRange AngleBrackets);
512 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
515 static bool classof(const Stmt *T) {
516 return T->getStmtClass() == CXXReinterpretCastExprClass;
520 /// A C++ \c const_cast expression (C++ [expr.const.cast]).
522 /// This expression node represents a const cast, e.g.,
523 /// \c const_cast<char*>(PtrToConstChar).
525 /// A const_cast can remove type qualifiers but does not change the underlying
527 class CXXConstCastExpr final
528 : public CXXNamedCastExpr,
529 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
530 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
531 TypeSourceInfo *writtenTy, SourceLocation l,
532 SourceLocation RParenLoc, SourceRange AngleBrackets)
533 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
534 0, writtenTy, l, RParenLoc, AngleBrackets) {}
536 explicit CXXConstCastExpr(EmptyShell Empty)
537 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) {}
540 friend class CastExpr;
541 friend TrailingObjects;
543 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
544 ExprValueKind VK, Expr *Op,
545 TypeSourceInfo *WrittenTy, SourceLocation L,
546 SourceLocation RParenLoc,
547 SourceRange AngleBrackets);
548 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
550 static bool classof(const Stmt *T) {
551 return T->getStmtClass() == CXXConstCastExprClass;
555 /// A call to a literal operator (C++11 [over.literal])
556 /// written as a user-defined literal (C++11 [lit.ext]).
558 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
559 /// is semantically equivalent to a normal call, this AST node provides better
560 /// information about the syntactic representation of the literal.
562 /// Since literal operators are never found by ADL and can only be declared at
563 /// namespace scope, a user-defined literal is never dependent.
564 class UserDefinedLiteral final : public CallExpr {
565 friend class ASTStmtReader;
566 friend class ASTStmtWriter;
568 /// The location of a ud-suffix within the literal.
569 SourceLocation UDSuffixLoc;
571 // UserDefinedLiteral has some trailing objects belonging
572 // to CallExpr. See CallExpr for the details.
574 UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty,
575 ExprValueKind VK, SourceLocation LitEndLoc,
576 SourceLocation SuffixLoc);
578 UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty);
581 static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn,
582 ArrayRef<Expr *> Args, QualType Ty,
583 ExprValueKind VK, SourceLocation LitEndLoc,
584 SourceLocation SuffixLoc);
586 static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx,
587 unsigned NumArgs, EmptyShell Empty);
589 /// The kind of literal operator which is invoked.
590 enum LiteralOperatorKind {
591 /// Raw form: operator "" X (const char *)
594 /// Raw form: operator "" X<cs...> ()
597 /// operator "" X (unsigned long long)
600 /// operator "" X (long double)
603 /// operator "" X (const CharT *, size_t)
606 /// operator "" X (CharT)
610 /// Returns the kind of literal operator invocation
611 /// which this expression represents.
612 LiteralOperatorKind getLiteralOperatorKind() const;
614 /// If this is not a raw user-defined literal, get the
615 /// underlying cooked literal (representing the literal with the suffix
617 Expr *getCookedLiteral();
618 const Expr *getCookedLiteral() const {
619 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
622 SourceLocation getBeginLoc() const {
623 if (getLiteralOperatorKind() == LOK_Template)
624 return getRParenLoc();
625 return getArg(0)->getBeginLoc();
628 SourceLocation getEndLoc() const { return getRParenLoc(); }
630 /// Returns the location of a ud-suffix in the expression.
632 /// For a string literal, there may be multiple identical suffixes. This
633 /// returns the first.
634 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
636 /// Returns the ud-suffix specified for this literal.
637 const IdentifierInfo *getUDSuffix() const;
639 static bool classof(const Stmt *S) {
640 return S->getStmtClass() == UserDefinedLiteralClass;
644 /// A boolean literal, per ([C++ lex.bool] Boolean literals).
645 class CXXBoolLiteralExpr : public Expr {
647 CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc)
648 : Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
650 CXXBoolLiteralExprBits.Value = Val;
651 CXXBoolLiteralExprBits.Loc = Loc;
654 explicit CXXBoolLiteralExpr(EmptyShell Empty)
655 : Expr(CXXBoolLiteralExprClass, Empty) {}
657 bool getValue() const { return CXXBoolLiteralExprBits.Value; }
658 void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; }
660 SourceLocation getBeginLoc() const { return getLocation(); }
661 SourceLocation getEndLoc() const { return getLocation(); }
663 SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; }
664 void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; }
666 static bool classof(const Stmt *T) {
667 return T->getStmtClass() == CXXBoolLiteralExprClass;
671 child_range children() {
672 return child_range(child_iterator(), child_iterator());
675 const_child_range children() const {
676 return const_child_range(const_child_iterator(), const_child_iterator());
680 /// The null pointer literal (C++11 [lex.nullptr])
682 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
683 class CXXNullPtrLiteralExpr : public Expr {
685 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc)
686 : Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false,
687 false, false, false) {
688 CXXNullPtrLiteralExprBits.Loc = Loc;
691 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
692 : Expr(CXXNullPtrLiteralExprClass, Empty) {}
694 SourceLocation getBeginLoc() const { return getLocation(); }
695 SourceLocation getEndLoc() const { return getLocation(); }
697 SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; }
698 void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; }
700 static bool classof(const Stmt *T) {
701 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
704 child_range children() {
705 return child_range(child_iterator(), child_iterator());
708 const_child_range children() const {
709 return const_child_range(const_child_iterator(), const_child_iterator());
713 /// Implicit construction of a std::initializer_list<T> object from an
714 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
715 class CXXStdInitializerListExpr : public Expr {
716 Stmt *SubExpr = nullptr;
718 CXXStdInitializerListExpr(EmptyShell Empty)
719 : Expr(CXXStdInitializerListExprClass, Empty) {}
722 friend class ASTReader;
723 friend class ASTStmtReader;
725 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
726 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
727 Ty->isDependentType(), SubExpr->isValueDependent(),
728 SubExpr->isInstantiationDependent(),
729 SubExpr->containsUnexpandedParameterPack()),
732 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
733 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
735 SourceLocation getBeginLoc() const LLVM_READONLY {
736 return SubExpr->getBeginLoc();
739 SourceLocation getEndLoc() const LLVM_READONLY {
740 return SubExpr->getEndLoc();
743 /// Retrieve the source range of the expression.
744 SourceRange getSourceRange() const LLVM_READONLY {
745 return SubExpr->getSourceRange();
748 static bool classof(const Stmt *S) {
749 return S->getStmtClass() == CXXStdInitializerListExprClass;
752 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
754 const_child_range children() const {
755 return const_child_range(&SubExpr, &SubExpr + 1);
759 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
760 /// the \c type_info that corresponds to the supplied type, or the (possibly
761 /// dynamic) type of the supplied expression.
763 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
764 class CXXTypeidExpr : public Expr {
766 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
770 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
771 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
772 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
774 // typeid is value-dependent if the type or expression are
776 Operand->getType()->isDependentType(),
777 Operand->getType()->isInstantiationDependentType(),
778 Operand->getType()->containsUnexpandedParameterPack()),
779 Operand(Operand), Range(R) {}
781 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
782 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
783 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
785 // typeid is value-dependent if the type or expression are
787 Operand->isTypeDependent() || Operand->isValueDependent(),
788 Operand->isInstantiationDependent(),
789 Operand->containsUnexpandedParameterPack()),
790 Operand(Operand), Range(R) {}
792 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
793 : Expr(CXXTypeidExprClass, Empty) {
795 Operand = (Expr*)nullptr;
797 Operand = (TypeSourceInfo*)nullptr;
800 /// Determine whether this typeid has a type operand which is potentially
801 /// evaluated, per C++11 [expr.typeid]p3.
802 bool isPotentiallyEvaluated() const;
804 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
806 /// Retrieves the type operand of this typeid() expression after
807 /// various required adjustments (removing reference types, cv-qualifiers).
808 QualType getTypeOperand(ASTContext &Context) const;
810 /// Retrieve source information for the type operand.
811 TypeSourceInfo *getTypeOperandSourceInfo() const {
812 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
813 return Operand.get<TypeSourceInfo *>();
816 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
817 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
821 Expr *getExprOperand() const {
822 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
823 return static_cast<Expr*>(Operand.get<Stmt *>());
826 void setExprOperand(Expr *E) {
827 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
831 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
832 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
833 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
834 void setSourceRange(SourceRange R) { Range = R; }
836 static bool classof(const Stmt *T) {
837 return T->getStmtClass() == CXXTypeidExprClass;
841 child_range children() {
843 return child_range(child_iterator(), child_iterator());
844 auto **begin = reinterpret_cast<Stmt **>(&Operand);
845 return child_range(begin, begin + 1);
848 const_child_range children() const {
850 return const_child_range(const_child_iterator(), const_child_iterator());
853 reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand);
854 return const_child_range(begin, begin + 1);
858 /// A member reference to an MSPropertyDecl.
860 /// This expression always has pseudo-object type, and therefore it is
861 /// typically not encountered in a fully-typechecked expression except
862 /// within the syntactic form of a PseudoObjectExpr.
863 class MSPropertyRefExpr : public Expr {
865 MSPropertyDecl *TheDecl;
866 SourceLocation MemberLoc;
868 NestedNameSpecifierLoc QualifierLoc;
871 friend class ASTStmtReader;
873 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
874 QualType ty, ExprValueKind VK,
875 NestedNameSpecifierLoc qualifierLoc,
876 SourceLocation nameLoc)
877 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
878 /*type-dependent*/ false, baseExpr->isValueDependent(),
879 baseExpr->isInstantiationDependent(),
880 baseExpr->containsUnexpandedParameterPack()),
881 BaseExpr(baseExpr), TheDecl(decl),
882 MemberLoc(nameLoc), IsArrow(isArrow),
883 QualifierLoc(qualifierLoc) {}
885 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
887 SourceRange getSourceRange() const LLVM_READONLY {
888 return SourceRange(getBeginLoc(), getEndLoc());
891 bool isImplicitAccess() const {
892 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
895 SourceLocation getBeginLoc() const {
896 if (!isImplicitAccess())
897 return BaseExpr->getBeginLoc();
898 else if (QualifierLoc)
899 return QualifierLoc.getBeginLoc();
904 SourceLocation getEndLoc() const { return getMemberLoc(); }
906 child_range children() {
907 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
910 const_child_range children() const {
911 auto Children = const_cast<MSPropertyRefExpr *>(this)->children();
912 return const_child_range(Children.begin(), Children.end());
915 static bool classof(const Stmt *T) {
916 return T->getStmtClass() == MSPropertyRefExprClass;
919 Expr *getBaseExpr() const { return BaseExpr; }
920 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
921 bool isArrow() const { return IsArrow; }
922 SourceLocation getMemberLoc() const { return MemberLoc; }
923 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
926 /// MS property subscript expression.
927 /// MSVC supports 'property' attribute and allows to apply it to the
928 /// declaration of an empty array in a class or structure definition.
931 /// __declspec(property(get=GetX, put=PutX)) int x[];
933 /// The above statement indicates that x[] can be used with one or more array
934 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
935 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
936 /// This is a syntactic pseudo-object expression.
937 class MSPropertySubscriptExpr : public Expr {
938 friend class ASTStmtReader;
940 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
942 Stmt *SubExprs[NUM_SUBEXPRS];
943 SourceLocation RBracketLoc;
945 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
946 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
949 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
950 ExprObjectKind OK, SourceLocation RBracketLoc)
951 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
952 Idx->isValueDependent(), Idx->isInstantiationDependent(),
953 Idx->containsUnexpandedParameterPack()),
954 RBracketLoc(RBracketLoc) {
955 SubExprs[BASE_EXPR] = Base;
956 SubExprs[IDX_EXPR] = Idx;
959 /// Create an empty array subscript expression.
960 explicit MSPropertySubscriptExpr(EmptyShell Shell)
961 : Expr(MSPropertySubscriptExprClass, Shell) {}
963 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
964 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
966 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
967 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
969 SourceLocation getBeginLoc() const LLVM_READONLY {
970 return getBase()->getBeginLoc();
973 SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
975 SourceLocation getRBracketLoc() const { return RBracketLoc; }
976 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
978 SourceLocation getExprLoc() const LLVM_READONLY {
979 return getBase()->getExprLoc();
982 static bool classof(const Stmt *T) {
983 return T->getStmtClass() == MSPropertySubscriptExprClass;
987 child_range children() {
988 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
991 const_child_range children() const {
992 return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
996 /// A Microsoft C++ @c __uuidof expression, which gets
997 /// the _GUID that corresponds to the supplied type or expression.
999 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
1000 class CXXUuidofExpr : public Expr {
1002 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
1007 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
1009 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
1010 Operand->getType()->isDependentType(),
1011 Operand->getType()->isInstantiationDependentType(),
1012 Operand->getType()->containsUnexpandedParameterPack()),
1013 Operand(Operand), UuidStr(UuidStr), Range(R) {}
1015 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
1016 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
1017 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
1018 Operand->containsUnexpandedParameterPack()),
1019 Operand(Operand), UuidStr(UuidStr), Range(R) {}
1021 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
1022 : Expr(CXXUuidofExprClass, Empty) {
1024 Operand = (Expr*)nullptr;
1026 Operand = (TypeSourceInfo*)nullptr;
1029 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
1031 /// Retrieves the type operand of this __uuidof() expression after
1032 /// various required adjustments (removing reference types, cv-qualifiers).
1033 QualType getTypeOperand(ASTContext &Context) const;
1035 /// Retrieve source information for the type operand.
1036 TypeSourceInfo *getTypeOperandSourceInfo() const {
1037 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
1038 return Operand.get<TypeSourceInfo *>();
1041 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
1042 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
1046 Expr *getExprOperand() const {
1047 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
1048 return static_cast<Expr*>(Operand.get<Stmt *>());
1051 void setExprOperand(Expr *E) {
1052 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
1056 void setUuidStr(StringRef US) { UuidStr = US; }
1057 StringRef getUuidStr() const { return UuidStr; }
1059 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
1060 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
1061 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
1062 void setSourceRange(SourceRange R) { Range = R; }
1064 static bool classof(const Stmt *T) {
1065 return T->getStmtClass() == CXXUuidofExprClass;
1069 child_range children() {
1070 if (isTypeOperand())
1071 return child_range(child_iterator(), child_iterator());
1072 auto **begin = reinterpret_cast<Stmt **>(&Operand);
1073 return child_range(begin, begin + 1);
1076 const_child_range children() const {
1077 if (isTypeOperand())
1078 return const_child_range(const_child_iterator(), const_child_iterator());
1080 reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand);
1081 return const_child_range(begin, begin + 1);
1085 /// Represents the \c this expression in C++.
1087 /// This is a pointer to the object on which the current member function is
1088 /// executing (C++ [expr.prim]p3). Example:
1094 /// void test() { this->bar(); }
1097 class CXXThisExpr : public Expr {
1099 CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit)
1100 : Expr(CXXThisExprClass, Ty, VK_RValue, OK_Ordinary,
1101 // 'this' is type-dependent if the class type of the enclosing
1102 // member function is dependent (C++ [temp.dep.expr]p2)
1103 Ty->isDependentType(), Ty->isDependentType(),
1104 Ty->isInstantiationDependentType(),
1105 /*ContainsUnexpandedParameterPack=*/false) {
1106 CXXThisExprBits.IsImplicit = IsImplicit;
1107 CXXThisExprBits.Loc = L;
1110 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
1112 SourceLocation getLocation() const { return CXXThisExprBits.Loc; }
1113 void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; }
1115 SourceLocation getBeginLoc() const { return getLocation(); }
1116 SourceLocation getEndLoc() const { return getLocation(); }
1118 bool isImplicit() const { return CXXThisExprBits.IsImplicit; }
1119 void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; }
1121 static bool classof(const Stmt *T) {
1122 return T->getStmtClass() == CXXThisExprClass;
1126 child_range children() {
1127 return child_range(child_iterator(), child_iterator());
1130 const_child_range children() const {
1131 return const_child_range(const_child_iterator(), const_child_iterator());
1135 /// A C++ throw-expression (C++ [except.throw]).
1137 /// This handles 'throw' (for re-throwing the current exception) and
1138 /// 'throw' assignment-expression. When assignment-expression isn't
1139 /// present, Op will be null.
1140 class CXXThrowExpr : public Expr {
1141 friend class ASTStmtReader;
1143 /// The optional expression in the throw statement.
1147 // \p Ty is the void type which is used as the result type of the
1148 // expression. The \p Loc is the location of the throw keyword.
1149 // \p Operand is the expression in the throw statement, and can be
1150 // null if not present.
1151 CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc,
1152 bool IsThrownVariableInScope)
1153 : Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
1154 Operand && Operand->isInstantiationDependent(),
1155 Operand && Operand->containsUnexpandedParameterPack()),
1157 CXXThrowExprBits.ThrowLoc = Loc;
1158 CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope;
1160 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
1162 const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); }
1163 Expr *getSubExpr() { return cast_or_null<Expr>(Operand); }
1165 SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; }
1167 /// Determines whether the variable thrown by this expression (if any!)
1168 /// is within the innermost try block.
1170 /// This information is required to determine whether the NRVO can apply to
1172 bool isThrownVariableInScope() const {
1173 return CXXThrowExprBits.IsThrownVariableInScope;
1176 SourceLocation getBeginLoc() const { return getThrowLoc(); }
1177 SourceLocation getEndLoc() const LLVM_READONLY {
1179 return getThrowLoc();
1180 return getSubExpr()->getEndLoc();
1183 static bool classof(const Stmt *T) {
1184 return T->getStmtClass() == CXXThrowExprClass;
1188 child_range children() {
1189 return child_range(&Operand, Operand ? &Operand + 1 : &Operand);
1192 const_child_range children() const {
1193 return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand);
1197 /// A default argument (C++ [dcl.fct.default]).
1199 /// This wraps up a function call argument that was created from the
1200 /// corresponding parameter's default argument, when the call did not
1201 /// explicitly supply arguments for all of the parameters.
1202 class CXXDefaultArgExpr final : public Expr {
1203 friend class ASTStmtReader;
1205 /// The parameter whose default is being used.
1208 /// The context where the default argument expression was used.
1209 DeclContext *UsedContext;
1211 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
1212 DeclContext *UsedContext)
1214 Param->hasUnparsedDefaultArg()
1215 ? Param->getType().getNonReferenceType()
1216 : Param->getDefaultArg()->getType(),
1217 Param->getDefaultArg()->getValueKind(),
1218 Param->getDefaultArg()->getObjectKind(), false, false, false,
1220 Param(Param), UsedContext(UsedContext) {
1221 CXXDefaultArgExprBits.Loc = Loc;
1225 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
1227 // \p Param is the parameter whose default argument is used by this
1229 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1231 DeclContext *UsedContext) {
1233 CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext);
1236 // Retrieve the parameter that the argument was created from.
1237 const ParmVarDecl *getParam() const { return Param; }
1238 ParmVarDecl *getParam() { return Param; }
1240 // Retrieve the actual argument to the function call.
1241 const Expr *getExpr() const { return getParam()->getDefaultArg(); }
1242 Expr *getExpr() { return getParam()->getDefaultArg(); }
1244 const DeclContext *getUsedContext() const { return UsedContext; }
1245 DeclContext *getUsedContext() { return UsedContext; }
1247 /// Retrieve the location where this default argument was actually used.
1248 SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; }
1250 /// Default argument expressions have no representation in the
1251 /// source, so they have an empty source range.
1252 SourceLocation getBeginLoc() const { return SourceLocation(); }
1253 SourceLocation getEndLoc() const { return SourceLocation(); }
1255 SourceLocation getExprLoc() const { return getUsedLocation(); }
1257 static bool classof(const Stmt *T) {
1258 return T->getStmtClass() == CXXDefaultArgExprClass;
1262 child_range children() {
1263 return child_range(child_iterator(), child_iterator());
1266 const_child_range children() const {
1267 return const_child_range(const_child_iterator(), const_child_iterator());
1271 /// A use of a default initializer in a constructor or in aggregate
1274 /// This wraps a use of a C++ default initializer (technically,
1275 /// a brace-or-equal-initializer for a non-static data member) when it
1276 /// is implicitly used in a mem-initializer-list in a constructor
1277 /// (C++11 [class.base.init]p8) or in aggregate initialization
1278 /// (C++1y [dcl.init.aggr]p7).
1279 class CXXDefaultInitExpr : public Expr {
1280 friend class ASTReader;
1281 friend class ASTStmtReader;
1283 /// The field whose default is being used.
1286 /// The context where the default initializer expression was used.
1287 DeclContext *UsedContext;
1289 CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
1290 FieldDecl *Field, QualType Ty, DeclContext *UsedContext);
1292 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1295 /// \p Field is the non-static data member whose default initializer is used
1296 /// by this expression.
1297 static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc,
1298 FieldDecl *Field, DeclContext *UsedContext) {
1299 return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext);
1302 /// Get the field whose initializer will be used.
1303 FieldDecl *getField() { return Field; }
1304 const FieldDecl *getField() const { return Field; }
1306 /// Get the initialization expression that will be used.
1307 const Expr *getExpr() const {
1308 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1309 return Field->getInClassInitializer();
1312 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1313 return Field->getInClassInitializer();
1316 const DeclContext *getUsedContext() const { return UsedContext; }
1317 DeclContext *getUsedContext() { return UsedContext; }
1319 /// Retrieve the location where this default initializer expression was
1321 SourceLocation getUsedLocation() const { return getBeginLoc(); }
1323 SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; }
1324 SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; }
1326 static bool classof(const Stmt *T) {
1327 return T->getStmtClass() == CXXDefaultInitExprClass;
1331 child_range children() {
1332 return child_range(child_iterator(), child_iterator());
1335 const_child_range children() const {
1336 return const_child_range(const_child_iterator(), const_child_iterator());
1340 /// Represents a C++ temporary.
1341 class CXXTemporary {
1342 /// The destructor that needs to be called.
1343 const CXXDestructorDecl *Destructor;
1345 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1346 : Destructor(destructor) {}
1349 static CXXTemporary *Create(const ASTContext &C,
1350 const CXXDestructorDecl *Destructor);
1352 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1354 void setDestructor(const CXXDestructorDecl *Dtor) {
1359 /// Represents binding an expression to a temporary.
1361 /// This ensures the destructor is called for the temporary. It should only be
1362 /// needed for non-POD, non-trivially destructable class types. For example:
1366 /// S() { } // User defined constructor makes S non-POD.
1367 /// ~S() { } // User defined destructor makes it non-trivial.
1370 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1373 class CXXBindTemporaryExpr : public Expr {
1374 CXXTemporary *Temp = nullptr;
1375 Stmt *SubExpr = nullptr;
1377 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1378 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1379 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1380 SubExpr->isValueDependent(),
1381 SubExpr->isInstantiationDependent(),
1382 SubExpr->containsUnexpandedParameterPack()),
1383 Temp(temp), SubExpr(SubExpr) {}
1386 CXXBindTemporaryExpr(EmptyShell Empty)
1387 : Expr(CXXBindTemporaryExprClass, Empty) {}
1389 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1392 CXXTemporary *getTemporary() { return Temp; }
1393 const CXXTemporary *getTemporary() const { return Temp; }
1394 void setTemporary(CXXTemporary *T) { Temp = T; }
1396 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1397 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1398 void setSubExpr(Expr *E) { SubExpr = E; }
1400 SourceLocation getBeginLoc() const LLVM_READONLY {
1401 return SubExpr->getBeginLoc();
1404 SourceLocation getEndLoc() const LLVM_READONLY {
1405 return SubExpr->getEndLoc();
1408 // Implement isa/cast/dyncast/etc.
1409 static bool classof(const Stmt *T) {
1410 return T->getStmtClass() == CXXBindTemporaryExprClass;
1414 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1416 const_child_range children() const {
1417 return const_child_range(&SubExpr, &SubExpr + 1);
1421 /// Represents a call to a C++ constructor.
1422 class CXXConstructExpr : public Expr {
1423 friend class ASTStmtReader;
1426 enum ConstructionKind {
1434 /// A pointer to the constructor which will be ultimately called.
1435 CXXConstructorDecl *Constructor;
1437 SourceRange ParenOrBraceRange;
1439 /// The number of arguments.
1442 // We would like to stash the arguments of the constructor call after
1443 // CXXConstructExpr. However CXXConstructExpr is used as a base class of
1444 // CXXTemporaryObjectExpr which makes the use of llvm::TrailingObjects
1447 // Instead we manually stash the trailing object after the full object
1448 // containing CXXConstructExpr (that is either CXXConstructExpr or
1449 // CXXTemporaryObjectExpr).
1451 // The trailing objects are:
1453 // * An array of getNumArgs() "Stmt *" for the arguments of the
1454 // constructor call.
1456 /// Return a pointer to the start of the trailing arguments.
1457 /// Defined just after CXXTemporaryObjectExpr.
1458 inline Stmt **getTrailingArgs();
1459 const Stmt *const *getTrailingArgs() const {
1460 return const_cast<CXXConstructExpr *>(this)->getTrailingArgs();
1464 /// Build a C++ construction expression.
1465 CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc,
1466 CXXConstructorDecl *Ctor, bool Elidable,
1467 ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1468 bool ListInitialization, bool StdInitListInitialization,
1469 bool ZeroInitialization, ConstructionKind ConstructKind,
1470 SourceRange ParenOrBraceRange);
1472 /// Build an empty C++ construction expression.
1473 CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs);
1475 /// Return the size in bytes of the trailing objects. Used by
1476 /// CXXTemporaryObjectExpr to allocate the right amount of storage.
1477 static unsigned sizeOfTrailingObjects(unsigned NumArgs) {
1478 return NumArgs * sizeof(Stmt *);
1482 /// Create a C++ construction expression.
1483 static CXXConstructExpr *
1484 Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1485 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1486 bool HadMultipleCandidates, bool ListInitialization,
1487 bool StdInitListInitialization, bool ZeroInitialization,
1488 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange);
1490 /// Create an empty C++ construction expression.
1491 static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs);
1493 /// Get the constructor that this expression will (ultimately) call.
1494 CXXConstructorDecl *getConstructor() const { return Constructor; }
1496 SourceLocation getLocation() const { return CXXConstructExprBits.Loc; }
1497 void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; }
1499 /// Whether this construction is elidable.
1500 bool isElidable() const { return CXXConstructExprBits.Elidable; }
1501 void setElidable(bool E) { CXXConstructExprBits.Elidable = E; }
1503 /// Whether the referred constructor was resolved from
1504 /// an overloaded set having size greater than 1.
1505 bool hadMultipleCandidates() const {
1506 return CXXConstructExprBits.HadMultipleCandidates;
1508 void setHadMultipleCandidates(bool V) {
1509 CXXConstructExprBits.HadMultipleCandidates = V;
1512 /// Whether this constructor call was written as list-initialization.
1513 bool isListInitialization() const {
1514 return CXXConstructExprBits.ListInitialization;
1516 void setListInitialization(bool V) {
1517 CXXConstructExprBits.ListInitialization = V;
1520 /// Whether this constructor call was written as list-initialization,
1521 /// but was interpreted as forming a std::initializer_list<T> from the list
1522 /// and passing that as a single constructor argument.
1523 /// See C++11 [over.match.list]p1 bullet 1.
1524 bool isStdInitListInitialization() const {
1525 return CXXConstructExprBits.StdInitListInitialization;
1527 void setStdInitListInitialization(bool V) {
1528 CXXConstructExprBits.StdInitListInitialization = V;
1531 /// Whether this construction first requires
1532 /// zero-initialization before the initializer is called.
1533 bool requiresZeroInitialization() const {
1534 return CXXConstructExprBits.ZeroInitialization;
1536 void setRequiresZeroInitialization(bool ZeroInit) {
1537 CXXConstructExprBits.ZeroInitialization = ZeroInit;
1540 /// Determine whether this constructor is actually constructing
1541 /// a base class (rather than a complete object).
1542 ConstructionKind getConstructionKind() const {
1543 return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind);
1545 void setConstructionKind(ConstructionKind CK) {
1546 CXXConstructExprBits.ConstructionKind = CK;
1549 using arg_iterator = ExprIterator;
1550 using const_arg_iterator = ConstExprIterator;
1551 using arg_range = llvm::iterator_range<arg_iterator>;
1552 using const_arg_range = llvm::iterator_range<const_arg_iterator>;
1554 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1555 const_arg_range arguments() const {
1556 return const_arg_range(arg_begin(), arg_end());
1559 arg_iterator arg_begin() { return getTrailingArgs(); }
1560 arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
1561 const_arg_iterator arg_begin() const { return getTrailingArgs(); }
1562 const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
1564 Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); }
1565 const Expr *const *getArgs() const {
1566 return reinterpret_cast<const Expr *const *>(getTrailingArgs());
1569 /// Return the number of arguments to the constructor call.
1570 unsigned getNumArgs() const { return NumArgs; }
1572 /// Return the specified argument.
1573 Expr *getArg(unsigned Arg) {
1574 assert(Arg < getNumArgs() && "Arg access out of range!");
1575 return getArgs()[Arg];
1577 const Expr *getArg(unsigned Arg) const {
1578 assert(Arg < getNumArgs() && "Arg access out of range!");
1579 return getArgs()[Arg];
1582 /// Set the specified argument.
1583 void setArg(unsigned Arg, Expr *ArgExpr) {
1584 assert(Arg < getNumArgs() && "Arg access out of range!");
1585 getArgs()[Arg] = ArgExpr;
1588 SourceLocation getBeginLoc() const LLVM_READONLY;
1589 SourceLocation getEndLoc() const LLVM_READONLY;
1590 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1591 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1593 static bool classof(const Stmt *T) {
1594 return T->getStmtClass() == CXXConstructExprClass ||
1595 T->getStmtClass() == CXXTemporaryObjectExprClass;
1599 child_range children() {
1600 return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs());
1603 const_child_range children() const {
1604 auto Children = const_cast<CXXConstructExpr *>(this)->children();
1605 return const_child_range(Children.begin(), Children.end());
1609 /// Represents a call to an inherited base class constructor from an
1610 /// inheriting constructor. This call implicitly forwards the arguments from
1611 /// the enclosing context (an inheriting constructor) to the specified inherited
1612 /// base class constructor.
1613 class CXXInheritedCtorInitExpr : public Expr {
1615 CXXConstructorDecl *Constructor = nullptr;
1617 /// The location of the using declaration.
1620 /// Whether this is the construction of a virtual base.
1621 unsigned ConstructsVirtualBase : 1;
1623 /// Whether the constructor is inherited from a virtual base class of the
1624 /// class that we construct.
1625 unsigned InheritedFromVirtualBase : 1;
1628 friend class ASTStmtReader;
1630 /// Construct a C++ inheriting construction expression.
1631 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1632 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1633 bool InheritedFromVirtualBase)
1634 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1635 false, false, false),
1636 Constructor(Ctor), Loc(Loc),
1637 ConstructsVirtualBase(ConstructsVirtualBase),
1638 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1639 assert(!T->isDependentType());
1642 /// Construct an empty C++ inheriting construction expression.
1643 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1644 : Expr(CXXInheritedCtorInitExprClass, Empty),
1645 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1647 /// Get the constructor that this expression will call.
1648 CXXConstructorDecl *getConstructor() const { return Constructor; }
1650 /// Determine whether this constructor is actually constructing
1651 /// a base class (rather than a complete object).
1652 bool constructsVBase() const { return ConstructsVirtualBase; }
1653 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1654 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1655 : CXXConstructExpr::CK_NonVirtualBase;
1658 /// Determine whether the inherited constructor is inherited from a
1659 /// virtual base of the object we construct. If so, we are not responsible
1660 /// for calling the inherited constructor (the complete object constructor
1661 /// does that), and so we don't need to pass any arguments.
1662 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1664 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1665 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1666 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1668 static bool classof(const Stmt *T) {
1669 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1672 child_range children() {
1673 return child_range(child_iterator(), child_iterator());
1676 const_child_range children() const {
1677 return const_child_range(const_child_iterator(), const_child_iterator());
1681 /// Represents an explicit C++ type conversion that uses "functional"
1682 /// notation (C++ [expr.type.conv]).
1688 class CXXFunctionalCastExpr final
1689 : public ExplicitCastExpr,
1690 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1691 SourceLocation LParenLoc;
1692 SourceLocation RParenLoc;
1694 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1695 TypeSourceInfo *writtenTy,
1696 CastKind kind, Expr *castExpr, unsigned pathSize,
1697 SourceLocation lParenLoc, SourceLocation rParenLoc)
1698 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1699 castExpr, pathSize, writtenTy),
1700 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1702 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1703 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) {}
1706 friend class CastExpr;
1707 friend TrailingObjects;
1709 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1711 TypeSourceInfo *Written,
1712 CastKind Kind, Expr *Op,
1713 const CXXCastPath *Path,
1714 SourceLocation LPLoc,
1715 SourceLocation RPLoc);
1716 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1719 SourceLocation getLParenLoc() const { return LParenLoc; }
1720 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1721 SourceLocation getRParenLoc() const { return RParenLoc; }
1722 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1724 /// Determine whether this expression models list-initialization.
1725 bool isListInitialization() const { return LParenLoc.isInvalid(); }
1727 SourceLocation getBeginLoc() const LLVM_READONLY;
1728 SourceLocation getEndLoc() const LLVM_READONLY;
1730 static bool classof(const Stmt *T) {
1731 return T->getStmtClass() == CXXFunctionalCastExprClass;
1735 /// Represents a C++ functional cast expression that builds a
1736 /// temporary object.
1738 /// This expression type represents a C++ "functional" cast
1739 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1740 /// constructor to build a temporary object. With N == 1 arguments the
1741 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1744 /// struct X { X(int, float); }
1747 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1750 class CXXTemporaryObjectExpr final : public CXXConstructExpr {
1751 friend class ASTStmtReader;
1753 // CXXTemporaryObjectExpr has some trailing objects belonging
1754 // to CXXConstructExpr. See the comment inside CXXConstructExpr
1755 // for more details.
1757 TypeSourceInfo *TSI;
1759 CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty,
1760 TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
1761 SourceRange ParenOrBraceRange,
1762 bool HadMultipleCandidates, bool ListInitialization,
1763 bool StdInitListInitialization,
1764 bool ZeroInitialization);
1766 CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs);
1769 static CXXTemporaryObjectExpr *
1770 Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
1771 TypeSourceInfo *TSI, ArrayRef<Expr *> Args,
1772 SourceRange ParenOrBraceRange, bool HadMultipleCandidates,
1773 bool ListInitialization, bool StdInitListInitialization,
1774 bool ZeroInitialization);
1776 static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx,
1779 TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
1781 SourceLocation getBeginLoc() const LLVM_READONLY;
1782 SourceLocation getEndLoc() const LLVM_READONLY;
1784 static bool classof(const Stmt *T) {
1785 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1789 Stmt **CXXConstructExpr::getTrailingArgs() {
1790 if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this))
1791 return reinterpret_cast<Stmt **>(E + 1);
1792 assert((getStmtClass() == CXXConstructExprClass) &&
1793 "Unexpected class deriving from CXXConstructExpr!");
1794 return reinterpret_cast<Stmt **>(this + 1);
1797 /// A C++ lambda expression, which produces a function object
1798 /// (of unspecified type) that can be invoked later.
1802 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1803 /// values.erase(std::remove_if(values.begin(), values.end(),
1804 /// [=](double value) { return value > cutoff; });
1808 /// C++11 lambda expressions can capture local variables, either by copying
1809 /// the values of those local variables at the time the function
1810 /// object is constructed (not when it is called!) or by holding a
1811 /// reference to the local variable. These captures can occur either
1812 /// implicitly or can be written explicitly between the square
1813 /// brackets ([...]) that start the lambda expression.
1815 /// C++1y introduces a new form of "capture" called an init-capture that
1816 /// includes an initializing expression (rather than capturing a variable),
1817 /// and which can never occur implicitly.
1818 class LambdaExpr final : public Expr,
1819 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1820 /// The source range that covers the lambda introducer ([...]).
1821 SourceRange IntroducerRange;
1823 /// The source location of this lambda's capture-default ('=' or '&').
1824 SourceLocation CaptureDefaultLoc;
1826 /// The number of captures.
1827 unsigned NumCaptures : 16;
1829 /// The default capture kind, which is a value of type
1830 /// LambdaCaptureDefault.
1831 unsigned CaptureDefault : 2;
1833 /// Whether this lambda had an explicit parameter list vs. an
1834 /// implicit (and empty) parameter list.
1835 unsigned ExplicitParams : 1;
1837 /// Whether this lambda had the result type explicitly specified.
1838 unsigned ExplicitResultType : 1;
1840 /// The location of the closing brace ('}') that completes
1843 /// The location of the brace is also available by looking up the
1844 /// function call operator in the lambda class. However, it is
1845 /// stored here to improve the performance of getSourceRange(), and
1846 /// to avoid having to deserialize the function call operator from a
1847 /// module file just to determine the source range.
1848 SourceLocation ClosingBrace;
1850 /// Construct a lambda expression.
1851 LambdaExpr(QualType T, SourceRange IntroducerRange,
1852 LambdaCaptureDefault CaptureDefault,
1853 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1854 bool ExplicitParams, bool ExplicitResultType,
1855 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1856 bool ContainsUnexpandedParameterPack);
1858 /// Construct an empty lambda expression.
1859 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1860 : Expr(LambdaExprClass, Empty), NumCaptures(NumCaptures),
1861 CaptureDefault(LCD_None), ExplicitParams(false),
1862 ExplicitResultType(false) {
1863 getStoredStmts()[NumCaptures] = nullptr;
1866 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1868 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1871 friend class ASTStmtReader;
1872 friend class ASTStmtWriter;
1873 friend TrailingObjects;
1875 /// Construct a new lambda expression.
1877 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1878 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1879 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1880 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1881 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1883 /// Construct a new lambda expression that will be deserialized from
1884 /// an external source.
1885 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1886 unsigned NumCaptures);
1888 /// Determine the default capture kind for this lambda.
1889 LambdaCaptureDefault getCaptureDefault() const {
1890 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1893 /// Retrieve the location of this lambda's capture-default, if any.
1894 SourceLocation getCaptureDefaultLoc() const {
1895 return CaptureDefaultLoc;
1898 /// Determine whether one of this lambda's captures is an init-capture.
1899 bool isInitCapture(const LambdaCapture *Capture) const;
1901 /// An iterator that walks over the captures of the lambda,
1902 /// both implicit and explicit.
1903 using capture_iterator = const LambdaCapture *;
1905 /// An iterator over a range of lambda captures.
1906 using capture_range = llvm::iterator_range<capture_iterator>;
1908 /// Retrieve this lambda's captures.
1909 capture_range captures() const;
1911 /// Retrieve an iterator pointing to the first lambda capture.
1912 capture_iterator capture_begin() const;
1914 /// Retrieve an iterator pointing past the end of the
1915 /// sequence of lambda captures.
1916 capture_iterator capture_end() const;
1918 /// Determine the number of captures in this lambda.
1919 unsigned capture_size() const { return NumCaptures; }
1921 /// Retrieve this lambda's explicit captures.
1922 capture_range explicit_captures() const;
1924 /// Retrieve an iterator pointing to the first explicit
1926 capture_iterator explicit_capture_begin() const;
1928 /// Retrieve an iterator pointing past the end of the sequence of
1929 /// explicit lambda captures.
1930 capture_iterator explicit_capture_end() const;
1932 /// Retrieve this lambda's implicit captures.
1933 capture_range implicit_captures() const;
1935 /// Retrieve an iterator pointing to the first implicit
1937 capture_iterator implicit_capture_begin() const;
1939 /// Retrieve an iterator pointing past the end of the sequence of
1940 /// implicit lambda captures.
1941 capture_iterator implicit_capture_end() const;
1943 /// Iterator that walks over the capture initialization
1945 using capture_init_iterator = Expr **;
1947 /// Const iterator that walks over the capture initialization
1949 using const_capture_init_iterator = Expr *const *;
1951 /// Retrieve the initialization expressions for this lambda's captures.
1952 llvm::iterator_range<capture_init_iterator> capture_inits() {
1953 return llvm::make_range(capture_init_begin(), capture_init_end());
1956 /// Retrieve the initialization expressions for this lambda's captures.
1957 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1958 return llvm::make_range(capture_init_begin(), capture_init_end());
1961 /// Retrieve the first initialization argument for this
1962 /// lambda expression (which initializes the first capture field).
1963 capture_init_iterator capture_init_begin() {
1964 return reinterpret_cast<Expr **>(getStoredStmts());
1967 /// Retrieve the first initialization argument for this
1968 /// lambda expression (which initializes the first capture field).
1969 const_capture_init_iterator capture_init_begin() const {
1970 return reinterpret_cast<Expr *const *>(getStoredStmts());
1973 /// Retrieve the iterator pointing one past the last
1974 /// initialization argument for this lambda expression.
1975 capture_init_iterator capture_init_end() {
1976 return capture_init_begin() + NumCaptures;
1979 /// Retrieve the iterator pointing one past the last
1980 /// initialization argument for this lambda expression.
1981 const_capture_init_iterator capture_init_end() const {
1982 return capture_init_begin() + NumCaptures;
1985 /// Retrieve the source range covering the lambda introducer,
1986 /// which contains the explicit capture list surrounded by square
1987 /// brackets ([...]).
1988 SourceRange getIntroducerRange() const { return IntroducerRange; }
1990 /// Retrieve the class that corresponds to the lambda.
1992 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1993 /// captures in its fields and provides the various operations permitted
1994 /// on a lambda (copying, calling).
1995 CXXRecordDecl *getLambdaClass() const;
1997 /// Retrieve the function call operator associated with this
1998 /// lambda expression.
1999 CXXMethodDecl *getCallOperator() const;
2001 /// Retrieve the function template call operator associated with this
2002 /// lambda expression.
2003 FunctionTemplateDecl *getDependentCallOperator() const;
2005 /// If this is a generic lambda expression, retrieve the template
2006 /// parameter list associated with it, or else return null.
2007 TemplateParameterList *getTemplateParameterList() const;
2009 /// Get the template parameters were explicitly specified (as opposed to being
2010 /// invented by use of an auto parameter).
2011 ArrayRef<NamedDecl *> getExplicitTemplateParameters() const;
2013 /// Whether this is a generic lambda.
2014 bool isGenericLambda() const { return getTemplateParameterList(); }
2016 /// Retrieve the body of the lambda.
2017 CompoundStmt *getBody() const;
2019 /// Determine whether the lambda is mutable, meaning that any
2020 /// captures values can be modified.
2021 bool isMutable() const;
2023 /// Determine whether this lambda has an explicit parameter
2024 /// list vs. an implicit (empty) parameter list.
2025 bool hasExplicitParameters() const { return ExplicitParams; }
2027 /// Whether this lambda had its result type explicitly specified.
2028 bool hasExplicitResultType() const { return ExplicitResultType; }
2030 static bool classof(const Stmt *T) {
2031 return T->getStmtClass() == LambdaExprClass;
2034 SourceLocation getBeginLoc() const LLVM_READONLY {
2035 return IntroducerRange.getBegin();
2038 SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; }
2040 child_range children() {
2041 // Includes initialization exprs plus body stmt
2042 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
2045 const_child_range children() const {
2046 return const_child_range(getStoredStmts(),
2047 getStoredStmts() + NumCaptures + 1);
2051 /// An expression "T()" which creates a value-initialized rvalue of type
2052 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
2053 class CXXScalarValueInitExpr : public Expr {
2054 friend class ASTStmtReader;
2056 TypeSourceInfo *TypeInfo;
2059 /// Create an explicitly-written scalar-value initialization
2061 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
2062 SourceLocation RParenLoc)
2063 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, false,
2064 false, Type->isInstantiationDependentType(),
2065 Type->containsUnexpandedParameterPack()),
2066 TypeInfo(TypeInfo) {
2067 CXXScalarValueInitExprBits.RParenLoc = RParenLoc;
2070 explicit CXXScalarValueInitExpr(EmptyShell Shell)
2071 : Expr(CXXScalarValueInitExprClass, Shell) {}
2073 TypeSourceInfo *getTypeSourceInfo() const {
2077 SourceLocation getRParenLoc() const {
2078 return CXXScalarValueInitExprBits.RParenLoc;
2081 SourceLocation getBeginLoc() const LLVM_READONLY;
2082 SourceLocation getEndLoc() const { return getRParenLoc(); }
2084 static bool classof(const Stmt *T) {
2085 return T->getStmtClass() == CXXScalarValueInitExprClass;
2089 child_range children() {
2090 return child_range(child_iterator(), child_iterator());
2093 const_child_range children() const {
2094 return const_child_range(const_child_iterator(), const_child_iterator());
2098 /// Represents a new-expression for memory allocation and constructor
2099 /// calls, e.g: "new CXXNewExpr(foo)".
2100 class CXXNewExpr final
2102 private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> {
2103 friend class ASTStmtReader;
2104 friend class ASTStmtWriter;
2105 friend TrailingObjects;
2107 /// Points to the allocation function used.
2108 FunctionDecl *OperatorNew;
2110 /// Points to the deallocation function used in case of error. May be null.
2111 FunctionDecl *OperatorDelete;
2113 /// The allocated type-source information, as written in the source.
2114 TypeSourceInfo *AllocatedTypeInfo;
2116 /// Range of the entire new expression.
2119 /// Source-range of a paren-delimited initializer.
2120 SourceRange DirectInitRange;
2122 // CXXNewExpr is followed by several optional trailing objects.
2123 // They are in order:
2125 // * An optional "Stmt *" for the array size expression.
2126 // Present if and ony if isArray().
2128 // * An optional "Stmt *" for the init expression.
2129 // Present if and only if hasInitializer().
2131 // * An array of getNumPlacementArgs() "Stmt *" for the placement new
2132 // arguments, if any.
2134 // * An optional SourceRange for the range covering the parenthesized type-id
2135 // if the allocated type was expressed as a parenthesized type-id.
2136 // Present if and only if isParenTypeId().
2137 unsigned arraySizeOffset() const { return 0; }
2138 unsigned initExprOffset() const { return arraySizeOffset() + isArray(); }
2139 unsigned placementNewArgsOffset() const {
2140 return initExprOffset() + hasInitializer();
2143 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2144 return isArray() + hasInitializer() + getNumPlacementArgs();
2147 unsigned numTrailingObjects(OverloadToken<SourceRange>) const {
2148 return isParenTypeId();
2152 enum InitializationStyle {
2153 /// New-expression has no initializer as written.
2156 /// New-expression has a C++98 paren-delimited initializer.
2159 /// New-expression has a C++11 list-initializer.
2164 /// Build a c++ new expression.
2165 CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
2166 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2167 bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2168 SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2169 InitializationStyle InitializationStyle, Expr *Initializer,
2170 QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2171 SourceRange DirectInitRange);
2173 /// Build an empty c++ new expression.
2174 CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
2175 bool IsParenTypeId);
2178 /// Create a c++ new expression.
2180 Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew,
2181 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
2182 bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs,
2183 SourceRange TypeIdParens, Optional<Expr *> ArraySize,
2184 InitializationStyle InitializationStyle, Expr *Initializer,
2185 QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
2186 SourceRange DirectInitRange);
2188 /// Create an empty c++ new expression.
2189 static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
2190 bool HasInit, unsigned NumPlacementArgs,
2191 bool IsParenTypeId);
2193 QualType getAllocatedType() const {
2194 return getType()->castAs<PointerType>()->getPointeeType();
2197 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
2198 return AllocatedTypeInfo;
2201 /// True if the allocation result needs to be null-checked.
2203 /// C++11 [expr.new]p13:
2204 /// If the allocation function returns null, initialization shall
2205 /// not be done, the deallocation function shall not be called,
2206 /// and the value of the new-expression shall be null.
2209 /// If the allocation function is a reserved placement allocation
2210 /// function that returns null, the behavior is undefined.
2212 /// An allocation function is not allowed to return null unless it
2213 /// has a non-throwing exception-specification. The '03 rule is
2214 /// identical except that the definition of a non-throwing
2215 /// exception specification is just "is it throw()?".
2216 bool shouldNullCheckAllocation() const;
2218 FunctionDecl *getOperatorNew() const { return OperatorNew; }
2219 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
2220 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2221 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
2223 bool isArray() const { return CXXNewExprBits.IsArray; }
2225 Optional<Expr *> getArraySize() {
2228 return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2230 Optional<const Expr *> getArraySize() const {
2233 return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]);
2236 unsigned getNumPlacementArgs() const {
2237 return CXXNewExprBits.NumPlacementArgs;
2240 Expr **getPlacementArgs() {
2241 return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() +
2242 placementNewArgsOffset());
2245 Expr *getPlacementArg(unsigned I) {
2246 assert((I < getNumPlacementArgs()) && "Index out of range!");
2247 return getPlacementArgs()[I];
2249 const Expr *getPlacementArg(unsigned I) const {
2250 return const_cast<CXXNewExpr *>(this)->getPlacementArg(I);
2253 bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; }
2254 SourceRange getTypeIdParens() const {
2255 return isParenTypeId() ? getTrailingObjects<SourceRange>()[0]
2259 bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
2261 /// Whether this new-expression has any initializer at all.
2262 bool hasInitializer() const {
2263 return CXXNewExprBits.StoredInitializationStyle > 0;
2266 /// The kind of initializer this new-expression has.
2267 InitializationStyle getInitializationStyle() const {
2268 if (CXXNewExprBits.StoredInitializationStyle == 0)
2270 return static_cast<InitializationStyle>(
2271 CXXNewExprBits.StoredInitializationStyle - 1);
2274 /// The initializer of this new-expression.
2275 Expr *getInitializer() {
2276 return hasInitializer()
2277 ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2280 const Expr *getInitializer() const {
2281 return hasInitializer()
2282 ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()])
2286 /// Returns the CXXConstructExpr from this new-expression, or null.
2287 const CXXConstructExpr *getConstructExpr() const {
2288 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
2291 /// Indicates whether the required alignment should be implicitly passed to
2292 /// the allocation function.
2293 bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; }
2295 /// Answers whether the usual array deallocation function for the
2296 /// allocated type expects the size of the allocation as a
2298 bool doesUsualArrayDeleteWantSize() const {
2299 return CXXNewExprBits.UsualArrayDeleteWantsSize;
2302 using arg_iterator = ExprIterator;
2303 using const_arg_iterator = ConstExprIterator;
2305 llvm::iterator_range<arg_iterator> placement_arguments() {
2306 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2309 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
2310 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2313 arg_iterator placement_arg_begin() {
2314 return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2316 arg_iterator placement_arg_end() {
2317 return placement_arg_begin() + getNumPlacementArgs();
2319 const_arg_iterator placement_arg_begin() const {
2320 return getTrailingObjects<Stmt *>() + placementNewArgsOffset();
2322 const_arg_iterator placement_arg_end() const {
2323 return placement_arg_begin() + getNumPlacementArgs();
2326 using raw_arg_iterator = Stmt **;
2328 raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); }
2329 raw_arg_iterator raw_arg_end() {
2330 return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2332 const_arg_iterator raw_arg_begin() const {
2333 return getTrailingObjects<Stmt *>();
2335 const_arg_iterator raw_arg_end() const {
2336 return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>());
2339 SourceLocation getBeginLoc() const { return Range.getBegin(); }
2340 SourceLocation getEndLoc() const { return Range.getEnd(); }
2342 SourceRange getDirectInitRange() const { return DirectInitRange; }
2343 SourceRange getSourceRange() const { return Range; }
2345 static bool classof(const Stmt *T) {
2346 return T->getStmtClass() == CXXNewExprClass;
2350 child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); }
2352 const_child_range children() const {
2353 return const_child_range(const_cast<CXXNewExpr *>(this)->children());
2357 /// Represents a \c delete expression for memory deallocation and
2358 /// destructor calls, e.g. "delete[] pArray".
2359 class CXXDeleteExpr : public Expr {
2360 friend class ASTStmtReader;
2362 /// Points to the operator delete overload that is used. Could be a member.
2363 FunctionDecl *OperatorDelete = nullptr;
2365 /// The pointer expression to be deleted.
2366 Stmt *Argument = nullptr;
2369 CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm,
2370 bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize,
2371 FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc)
2372 : Expr(CXXDeleteExprClass, Ty, VK_RValue, OK_Ordinary, false,
2373 Arg->isValueDependent(), Arg->isInstantiationDependent(),
2374 Arg->containsUnexpandedParameterPack()),
2375 OperatorDelete(OperatorDelete), Argument(Arg) {
2376 CXXDeleteExprBits.GlobalDelete = GlobalDelete;
2377 CXXDeleteExprBits.ArrayForm = ArrayForm;
2378 CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten;
2379 CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
2380 CXXDeleteExprBits.Loc = Loc;
2383 explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {}
2385 bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; }
2386 bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; }
2387 bool isArrayFormAsWritten() const {
2388 return CXXDeleteExprBits.ArrayFormAsWritten;
2391 /// Answers whether the usual array deallocation function for the
2392 /// allocated type expects the size of the allocation as a
2393 /// parameter. This can be true even if the actual deallocation
2394 /// function that we're using doesn't want a size.
2395 bool doesUsualArrayDeleteWantSize() const {
2396 return CXXDeleteExprBits.UsualArrayDeleteWantsSize;
2399 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2401 Expr *getArgument() { return cast<Expr>(Argument); }
2402 const Expr *getArgument() const { return cast<Expr>(Argument); }
2404 /// Retrieve the type being destroyed.
2406 /// If the type being destroyed is a dependent type which may or may not
2407 /// be a pointer, return an invalid type.
2408 QualType getDestroyedType() const;
2410 SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; }
2411 SourceLocation getEndLoc() const LLVM_READONLY {
2412 return Argument->getEndLoc();
2415 static bool classof(const Stmt *T) {
2416 return T->getStmtClass() == CXXDeleteExprClass;
2420 child_range children() { return child_range(&Argument, &Argument + 1); }
2422 const_child_range children() const {
2423 return const_child_range(&Argument, &Argument + 1);
2427 /// Stores the type being destroyed by a pseudo-destructor expression.
2428 class PseudoDestructorTypeStorage {
2429 /// Either the type source information or the name of the type, if
2430 /// it couldn't be resolved due to type-dependence.
2431 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2433 /// The starting source location of the pseudo-destructor type.
2434 SourceLocation Location;
2437 PseudoDestructorTypeStorage() = default;
2439 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2440 : Type(II), Location(Loc) {}
2442 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2444 TypeSourceInfo *getTypeSourceInfo() const {
2445 return Type.dyn_cast<TypeSourceInfo *>();
2448 IdentifierInfo *getIdentifier() const {
2449 return Type.dyn_cast<IdentifierInfo *>();
2452 SourceLocation getLocation() const { return Location; }
2455 /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2457 /// A pseudo-destructor is an expression that looks like a member access to a
2458 /// destructor of a scalar type, except that scalar types don't have
2459 /// destructors. For example:
2463 /// void f(int *p) {
2468 /// Pseudo-destructors typically occur when instantiating templates such as:
2471 /// template<typename T>
2472 /// void destroy(T* ptr) {
2477 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2478 /// beyond evaluating the base expression.
2479 class CXXPseudoDestructorExpr : public Expr {
2480 friend class ASTStmtReader;
2482 /// The base expression (that is being destroyed).
2483 Stmt *Base = nullptr;
2485 /// Whether the operator was an arrow ('->'); otherwise, it was a
2489 /// The location of the '.' or '->' operator.
2490 SourceLocation OperatorLoc;
2492 /// The nested-name-specifier that follows the operator, if present.
2493 NestedNameSpecifierLoc QualifierLoc;
2495 /// The type that precedes the '::' in a qualified pseudo-destructor
2497 TypeSourceInfo *ScopeType = nullptr;
2499 /// The location of the '::' in a qualified pseudo-destructor
2501 SourceLocation ColonColonLoc;
2503 /// The location of the '~'.
2504 SourceLocation TildeLoc;
2506 /// The type being destroyed, or its name if we were unable to
2507 /// resolve the name.
2508 PseudoDestructorTypeStorage DestroyedType;
2511 CXXPseudoDestructorExpr(const ASTContext &Context,
2512 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2513 NestedNameSpecifierLoc QualifierLoc,
2514 TypeSourceInfo *ScopeType,
2515 SourceLocation ColonColonLoc,
2516 SourceLocation TildeLoc,
2517 PseudoDestructorTypeStorage DestroyedType);
2519 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2520 : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {}
2522 Expr *getBase() const { return cast<Expr>(Base); }
2524 /// Determines whether this member expression actually had
2525 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2527 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2529 /// Retrieves the nested-name-specifier that qualifies the type name,
2530 /// with source-location information.
2531 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2533 /// If the member name was qualified, retrieves the
2534 /// nested-name-specifier that precedes the member name. Otherwise, returns
2536 NestedNameSpecifier *getQualifier() const {
2537 return QualifierLoc.getNestedNameSpecifier();
2540 /// Determine whether this pseudo-destructor expression was written
2541 /// using an '->' (otherwise, it used a '.').
2542 bool isArrow() const { return IsArrow; }
2544 /// Retrieve the location of the '.' or '->' operator.
2545 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2547 /// Retrieve the scope type in a qualified pseudo-destructor
2550 /// Pseudo-destructor expressions can have extra qualification within them
2551 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2552 /// Here, if the object type of the expression is (or may be) a scalar type,
2553 /// \p T may also be a scalar type and, therefore, cannot be part of a
2554 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2555 /// destructor expression.
2556 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2558 /// Retrieve the location of the '::' in a qualified pseudo-destructor
2560 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2562 /// Retrieve the location of the '~'.
2563 SourceLocation getTildeLoc() const { return TildeLoc; }
2565 /// Retrieve the source location information for the type
2566 /// being destroyed.
2568 /// This type-source information is available for non-dependent
2569 /// pseudo-destructor expressions and some dependent pseudo-destructor
2570 /// expressions. Returns null if we only have the identifier for a
2571 /// dependent pseudo-destructor expression.
2572 TypeSourceInfo *getDestroyedTypeInfo() const {
2573 return DestroyedType.getTypeSourceInfo();
2576 /// In a dependent pseudo-destructor expression for which we do not
2577 /// have full type information on the destroyed type, provides the name
2578 /// of the destroyed type.
2579 IdentifierInfo *getDestroyedTypeIdentifier() const {
2580 return DestroyedType.getIdentifier();
2583 /// Retrieve the type being destroyed.
2584 QualType getDestroyedType() const;
2586 /// Retrieve the starting location of the type being destroyed.
2587 SourceLocation getDestroyedTypeLoc() const {
2588 return DestroyedType.getLocation();
2591 /// Set the name of destroyed type for a dependent pseudo-destructor
2593 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2594 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2597 /// Set the destroyed type.
2598 void setDestroyedType(TypeSourceInfo *Info) {
2599 DestroyedType = PseudoDestructorTypeStorage(Info);
2602 SourceLocation getBeginLoc() const LLVM_READONLY {
2603 return Base->getBeginLoc();
2605 SourceLocation getEndLoc() const LLVM_READONLY;
2607 static bool classof(const Stmt *T) {
2608 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2612 child_range children() { return child_range(&Base, &Base + 1); }
2614 const_child_range children() const {
2615 return const_child_range(&Base, &Base + 1);
2619 /// A type trait used in the implementation of various C++11 and
2620 /// Library TR1 trait templates.
2623 /// __is_pod(int) == true
2624 /// __is_enum(std::string) == false
2625 /// __is_trivially_constructible(vector<int>, int*, int*)
2627 class TypeTraitExpr final
2629 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2630 /// The location of the type trait keyword.
2633 /// The location of the closing parenthesis.
2634 SourceLocation RParenLoc;
2636 // Note: The TypeSourceInfos for the arguments are allocated after the
2639 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2640 ArrayRef<TypeSourceInfo *> Args,
2641 SourceLocation RParenLoc,
2644 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
2646 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2647 return getNumArgs();
2651 friend class ASTStmtReader;
2652 friend class ASTStmtWriter;
2653 friend TrailingObjects;
2655 /// Create a new type trait expression.
2656 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2657 SourceLocation Loc, TypeTrait Kind,
2658 ArrayRef<TypeSourceInfo *> Args,
2659 SourceLocation RParenLoc,
2662 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2665 /// Determine which type trait this expression uses.
2666 TypeTrait getTrait() const {
2667 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2670 bool getValue() const {
2671 assert(!isValueDependent());
2672 return TypeTraitExprBits.Value;
2675 /// Determine the number of arguments to this type trait.
2676 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2678 /// Retrieve the Ith argument.
2679 TypeSourceInfo *getArg(unsigned I) const {
2680 assert(I < getNumArgs() && "Argument out-of-range");
2681 return getArgs()[I];
2684 /// Retrieve the argument types.
2685 ArrayRef<TypeSourceInfo *> getArgs() const {
2686 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2690 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2691 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2693 static bool classof(const Stmt *T) {
2694 return T->getStmtClass() == TypeTraitExprClass;
2698 child_range children() {
2699 return child_range(child_iterator(), child_iterator());
2702 const_child_range children() const {
2703 return const_child_range(const_child_iterator(), const_child_iterator());
2707 /// An Embarcadero array type trait, as used in the implementation of
2708 /// __array_rank and __array_extent.
2712 /// __array_rank(int[10][20]) == 2
2713 /// __array_extent(int, 1) == 20
2715 class ArrayTypeTraitExpr : public Expr {
2716 /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2719 /// The value of the type trait. Unspecified if dependent.
2722 /// The array dimension being queried, or -1 if not used.
2725 /// The location of the type trait keyword.
2728 /// The location of the closing paren.
2729 SourceLocation RParen;
2731 /// The type being queried.
2732 TypeSourceInfo *QueriedType = nullptr;
2735 friend class ASTStmtReader;
2737 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2738 TypeSourceInfo *queried, uint64_t value,
2739 Expr *dimension, SourceLocation rparen, QualType ty)
2740 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2741 false, queried->getType()->isDependentType(),
2742 (queried->getType()->isInstantiationDependentType() ||
2743 (dimension && dimension->isInstantiationDependent())),
2744 queried->getType()->containsUnexpandedParameterPack()),
2745 ATT(att), Value(value), Dimension(dimension),
2746 Loc(loc), RParen(rparen), QueriedType(queried) {}
2748 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2749 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
2751 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2752 SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2754 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2756 QualType getQueriedType() const { return QueriedType->getType(); }
2758 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2760 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2762 Expr *getDimensionExpression() const { return Dimension; }
2764 static bool classof(const Stmt *T) {
2765 return T->getStmtClass() == ArrayTypeTraitExprClass;
2769 child_range children() {
2770 return child_range(child_iterator(), child_iterator());
2773 const_child_range children() const {
2774 return const_child_range(const_child_iterator(), const_child_iterator());
2778 /// An expression trait intrinsic.
2782 /// __is_lvalue_expr(std::cout) == true
2783 /// __is_lvalue_expr(1) == false
2785 class ExpressionTraitExpr : public Expr {
2786 /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2789 /// The value of the type trait. Unspecified if dependent.
2792 /// The location of the type trait keyword.
2795 /// The location of the closing paren.
2796 SourceLocation RParen;
2798 /// The expression being queried.
2799 Expr* QueriedExpression = nullptr;
2802 friend class ASTStmtReader;
2804 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2805 Expr *queried, bool value,
2806 SourceLocation rparen, QualType resultType)
2807 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2808 false, // Not type-dependent
2809 // Value-dependent if the argument is type-dependent.
2810 queried->isTypeDependent(),
2811 queried->isInstantiationDependent(),
2812 queried->containsUnexpandedParameterPack()),
2813 ET(et), Value(value), Loc(loc), RParen(rparen),
2814 QueriedExpression(queried) {}
2816 explicit ExpressionTraitExpr(EmptyShell Empty)
2817 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {}
2819 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
2820 SourceLocation getEndLoc() const LLVM_READONLY { return RParen; }
2822 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2824 Expr *getQueriedExpression() const { return QueriedExpression; }
2826 bool getValue() const { return Value; }
2828 static bool classof(const Stmt *T) {
2829 return T->getStmtClass() == ExpressionTraitExprClass;
2833 child_range children() {
2834 return child_range(child_iterator(), child_iterator());
2837 const_child_range children() const {
2838 return const_child_range(const_child_iterator(), const_child_iterator());
2842 /// A reference to an overloaded function set, either an
2843 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2844 class OverloadExpr : public Expr {
2845 friend class ASTStmtReader;
2846 friend class ASTStmtWriter;
2848 /// The common name of these declarations.
2849 DeclarationNameInfo NameInfo;
2851 /// The nested-name-specifier that qualifies the name, if any.
2852 NestedNameSpecifierLoc QualifierLoc;
2855 OverloadExpr(StmtClass SC, const ASTContext &Context,
2856 NestedNameSpecifierLoc QualifierLoc,
2857 SourceLocation TemplateKWLoc,
2858 const DeclarationNameInfo &NameInfo,
2859 const TemplateArgumentListInfo *TemplateArgs,
2860 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2861 bool KnownDependent, bool KnownInstantiationDependent,
2862 bool KnownContainsUnexpandedParameterPack);
2864 OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
2865 bool HasTemplateKWAndArgsInfo);
2867 /// Return the results. Defined after UnresolvedMemberExpr.
2868 inline DeclAccessPair *getTrailingResults();
2869 const DeclAccessPair *getTrailingResults() const {
2870 return const_cast<OverloadExpr *>(this)->getTrailingResults();
2873 /// Return the optional template keyword and arguments info.
2874 /// Defined after UnresolvedMemberExpr.
2875 inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo();
2876 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2877 return const_cast<OverloadExpr *>(this)
2878 ->getTrailingASTTemplateKWAndArgsInfo();
2881 /// Return the optional template arguments. Defined after
2882 /// UnresolvedMemberExpr.
2883 inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc();
2884 const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const {
2885 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2888 bool hasTemplateKWAndArgsInfo() const {
2889 return OverloadExprBits.HasTemplateKWAndArgsInfo;
2894 OverloadExpr *Expression;
2895 bool IsAddressOfOperand;
2896 bool HasFormOfMemberPointer;
2899 /// Finds the overloaded expression in the given expression \p E of
2902 /// \return the expression (which must be there) and true if it has
2903 /// the particular form of a member pointer expression
2904 static FindResult find(Expr *E) {
2905 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2909 E = E->IgnoreParens();
2910 if (isa<UnaryOperator>(E)) {
2911 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2912 E = cast<UnaryOperator>(E)->getSubExpr();
2913 auto *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2915 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2916 Result.IsAddressOfOperand = true;
2917 Result.Expression = Ovl;
2919 Result.HasFormOfMemberPointer = false;
2920 Result.IsAddressOfOperand = false;
2921 Result.Expression = cast<OverloadExpr>(E);
2927 /// Gets the naming class of this lookup, if any.
2928 /// Defined after UnresolvedMemberExpr.
2929 inline CXXRecordDecl *getNamingClass();
2930 const CXXRecordDecl *getNamingClass() const {
2931 return const_cast<OverloadExpr *>(this)->getNamingClass();
2934 using decls_iterator = UnresolvedSetImpl::iterator;
2936 decls_iterator decls_begin() const {
2937 return UnresolvedSetIterator(getTrailingResults());
2939 decls_iterator decls_end() const {
2940 return UnresolvedSetIterator(getTrailingResults() + getNumDecls());
2942 llvm::iterator_range<decls_iterator> decls() const {
2943 return llvm::make_range(decls_begin(), decls_end());
2946 /// Gets the number of declarations in the unresolved set.
2947 unsigned getNumDecls() const { return OverloadExprBits.NumResults; }
2949 /// Gets the full name info.
2950 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2952 /// Gets the name looked up.
2953 DeclarationName getName() const { return NameInfo.getName(); }
2955 /// Gets the location of the name.
2956 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2958 /// Fetches the nested-name qualifier, if one was given.
2959 NestedNameSpecifier *getQualifier() const {
2960 return QualifierLoc.getNestedNameSpecifier();
2963 /// Fetches the nested-name qualifier with source-location
2964 /// information, if one was given.
2965 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2967 /// Retrieve the location of the template keyword preceding
2968 /// this name, if any.
2969 SourceLocation getTemplateKeywordLoc() const {
2970 if (!hasTemplateKWAndArgsInfo())
2971 return SourceLocation();
2972 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2975 /// Retrieve the location of the left angle bracket starting the
2976 /// explicit template argument list following the name, if any.
2977 SourceLocation getLAngleLoc() const {
2978 if (!hasTemplateKWAndArgsInfo())
2979 return SourceLocation();
2980 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2983 /// Retrieve the location of the right angle bracket ending the
2984 /// explicit template argument list following the name, if any.
2985 SourceLocation getRAngleLoc() const {
2986 if (!hasTemplateKWAndArgsInfo())
2987 return SourceLocation();
2988 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2991 /// Determines whether the name was preceded by the template keyword.
2992 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2994 /// Determines whether this expression had explicit template arguments.
2995 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2997 TemplateArgumentLoc const *getTemplateArgs() const {
2998 if (!hasExplicitTemplateArgs())
3000 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
3003 unsigned getNumTemplateArgs() const {
3004 if (!hasExplicitTemplateArgs())
3007 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
3010 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3011 return {getTemplateArgs(), getNumTemplateArgs()};
3014 /// Copies the template arguments into the given structure.
3015 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3016 if (hasExplicitTemplateArgs())
3017 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
3020 static bool classof(const Stmt *T) {
3021 return T->getStmtClass() == UnresolvedLookupExprClass ||
3022 T->getStmtClass() == UnresolvedMemberExprClass;
3026 /// A reference to a name which we were able to look up during
3027 /// parsing but could not resolve to a specific declaration.
3029 /// This arises in several ways:
3030 /// * we might be waiting for argument-dependent lookup;
3031 /// * the name might resolve to an overloaded function;
3033 /// * the lookup might have included a function template.
3035 /// These never include UnresolvedUsingValueDecls, which are always class
3036 /// members and therefore appear only in UnresolvedMemberLookupExprs.
3037 class UnresolvedLookupExpr final
3038 : public OverloadExpr,
3039 private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair,
3040 ASTTemplateKWAndArgsInfo,
3041 TemplateArgumentLoc> {
3042 friend class ASTStmtReader;
3043 friend class OverloadExpr;
3044 friend TrailingObjects;
3046 /// The naming class (C++ [class.access.base]p5) of the lookup, if
3047 /// any. This can generally be recalculated from the context chain,
3048 /// but that can be fairly expensive for unqualified lookups.
3049 CXXRecordDecl *NamingClass;
3051 // UnresolvedLookupExpr is followed by several trailing objects.
3052 // They are in order:
3054 // * An array of getNumResults() DeclAccessPair for the results. These are
3055 // undesugared, which is to say, they may include UsingShadowDecls.
3056 // Access is relative to the naming class.
3058 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3059 // template keyword and arguments. Present if and only if
3060 // hasTemplateKWAndArgsInfo().
3062 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
3063 // location information for the explicitly specified template arguments.
3065 UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass,
3066 NestedNameSpecifierLoc QualifierLoc,
3067 SourceLocation TemplateKWLoc,
3068 const DeclarationNameInfo &NameInfo, bool RequiresADL,
3070 const TemplateArgumentListInfo *TemplateArgs,
3071 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3073 UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
3074 bool HasTemplateKWAndArgsInfo);
3076 unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3077 return getNumDecls();
3080 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3081 return hasTemplateKWAndArgsInfo();
3085 static UnresolvedLookupExpr *
3086 Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
3087 NestedNameSpecifierLoc QualifierLoc,
3088 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
3089 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3091 static UnresolvedLookupExpr *
3092 Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
3093 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3094 const DeclarationNameInfo &NameInfo, bool RequiresADL,
3095 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
3096 UnresolvedSetIterator End);
3098 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
3099 unsigned NumResults,
3100 bool HasTemplateKWAndArgsInfo,
3101 unsigned NumTemplateArgs);
3103 /// True if this declaration should be extended by
3104 /// argument-dependent lookup.
3105 bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; }
3107 /// True if this lookup is overloaded.
3108 bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; }
3110 /// Gets the 'naming class' (in the sense of C++0x
3111 /// [class.access.base]p5) of the lookup. This is the scope
3112 /// that was looked in to find these results.
3113 CXXRecordDecl *getNamingClass() { return NamingClass; }
3114 const CXXRecordDecl *getNamingClass() const { return NamingClass; }
3116 SourceLocation getBeginLoc() const LLVM_READONLY {
3117 if (NestedNameSpecifierLoc l = getQualifierLoc())
3118 return l.getBeginLoc();
3119 return getNameInfo().getBeginLoc();
3122 SourceLocation getEndLoc() const LLVM_READONLY {
3123 if (hasExplicitTemplateArgs())
3124 return getRAngleLoc();
3125 return getNameInfo().getEndLoc();
3128 child_range children() {
3129 return child_range(child_iterator(), child_iterator());
3132 const_child_range children() const {
3133 return const_child_range(const_child_iterator(), const_child_iterator());
3136 static bool classof(const Stmt *T) {
3137 return T->getStmtClass() == UnresolvedLookupExprClass;
3141 /// A qualified reference to a name whose declaration cannot
3142 /// yet be resolved.
3144 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
3145 /// it expresses a reference to a declaration such as
3146 /// X<T>::value. The difference, however, is that an
3147 /// DependentScopeDeclRefExpr node is used only within C++ templates when
3148 /// the qualification (e.g., X<T>::) refers to a dependent type. In
3149 /// this case, X<T>::value cannot resolve to a declaration because the
3150 /// declaration will differ from one instantiation of X<T> to the
3151 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
3152 /// qualifier (X<T>::) and the name of the entity being referenced
3153 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
3154 /// declaration can be found.
3155 class DependentScopeDeclRefExpr final
3157 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
3158 ASTTemplateKWAndArgsInfo,
3159 TemplateArgumentLoc> {
3160 friend class ASTStmtReader;
3161 friend class ASTStmtWriter;
3162 friend TrailingObjects;
3164 /// The nested-name-specifier that qualifies this unresolved
3165 /// declaration name.
3166 NestedNameSpecifierLoc QualifierLoc;
3168 /// The name of the entity we will be referencing.
3169 DeclarationNameInfo NameInfo;
3171 DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc,
3172 SourceLocation TemplateKWLoc,
3173 const DeclarationNameInfo &NameInfo,
3174 const TemplateArgumentListInfo *Args);
3176 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3177 return hasTemplateKWAndArgsInfo();
3180 bool hasTemplateKWAndArgsInfo() const {
3181 return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo;
3185 static DependentScopeDeclRefExpr *
3186 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
3187 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
3188 const TemplateArgumentListInfo *TemplateArgs);
3190 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context,
3191 bool HasTemplateKWAndArgsInfo,
3192 unsigned NumTemplateArgs);
3194 /// Retrieve the name that this expression refers to.
3195 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3197 /// Retrieve the name that this expression refers to.
3198 DeclarationName getDeclName() const { return NameInfo.getName(); }
3200 /// Retrieve the location of the name within the expression.
3202 /// For example, in "X<T>::value" this is the location of "value".
3203 SourceLocation getLocation() const { return NameInfo.getLoc(); }
3205 /// Retrieve the nested-name-specifier that qualifies the
3206 /// name, with source location information.
3207 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3209 /// Retrieve the nested-name-specifier that qualifies this
3211 NestedNameSpecifier *getQualifier() const {
3212 return QualifierLoc.getNestedNameSpecifier();
3215 /// Retrieve the location of the template keyword preceding
3216 /// this name, if any.
3217 SourceLocation getTemplateKeywordLoc() const {
3218 if (!hasTemplateKWAndArgsInfo())
3219 return SourceLocation();
3220 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3223 /// Retrieve the location of the left angle bracket starting the
3224 /// explicit template argument list following the name, if any.
3225 SourceLocation getLAngleLoc() const {
3226 if (!hasTemplateKWAndArgsInfo())
3227 return SourceLocation();
3228 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3231 /// Retrieve the location of the right angle bracket ending the
3232 /// explicit template argument list following the name, if any.
3233 SourceLocation getRAngleLoc() const {
3234 if (!hasTemplateKWAndArgsInfo())
3235 return SourceLocation();
3236 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3239 /// Determines whether the name was preceded by the template keyword.
3240 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3242 /// Determines whether this lookup had explicit template arguments.
3243 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3245 /// Copies the template arguments (if present) into the given
3247 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3248 if (hasExplicitTemplateArgs())
3249 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3250 getTrailingObjects<TemplateArgumentLoc>(), List);
3253 TemplateArgumentLoc const *getTemplateArgs() const {
3254 if (!hasExplicitTemplateArgs())
3257 return getTrailingObjects<TemplateArgumentLoc>();
3260 unsigned getNumTemplateArgs() const {
3261 if (!hasExplicitTemplateArgs())
3264 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3267 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3268 return {getTemplateArgs(), getNumTemplateArgs()};
3271 /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr,
3272 /// and differs from getLocation().getStart().
3273 SourceLocation getBeginLoc() const LLVM_READONLY {
3274 return QualifierLoc.getBeginLoc();
3277 SourceLocation getEndLoc() const LLVM_READONLY {
3278 if (hasExplicitTemplateArgs())
3279 return getRAngleLoc();
3280 return getLocation();
3283 static bool classof(const Stmt *T) {
3284 return T->getStmtClass() == DependentScopeDeclRefExprClass;
3287 child_range children() {
3288 return child_range(child_iterator(), child_iterator());
3291 const_child_range children() const {
3292 return const_child_range(const_child_iterator(), const_child_iterator());
3296 /// Represents an expression -- generally a full-expression -- that
3297 /// introduces cleanups to be run at the end of the sub-expression's
3298 /// evaluation. The most common source of expression-introduced
3299 /// cleanups is temporary objects in C++, but several other kinds of
3300 /// expressions can create cleanups, including basically every
3301 /// call in ARC that returns an Objective-C pointer.
3303 /// This expression also tracks whether the sub-expression contains a
3304 /// potentially-evaluated block literal. The lifetime of a block
3305 /// literal is the extent of the enclosing scope.
3306 class ExprWithCleanups final
3308 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
3310 /// The type of objects that are kept in the cleanup.
3311 /// It's useful to remember the set of blocks; we could also
3312 /// remember the set of temporaries, but there's currently
3314 using CleanupObject = BlockDecl *;
3317 friend class ASTStmtReader;
3318 friend TrailingObjects;
3320 ExprWithCleanups(EmptyShell, unsigned NumObjects);
3321 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
3322 ArrayRef<CleanupObject> Objects);
3325 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
3326 unsigned numObjects);
3328 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
3329 bool CleanupsHaveSideEffects,
3330 ArrayRef<CleanupObject> objects);
3332 ArrayRef<CleanupObject> getObjects() const {
3333 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
3337 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
3339 CleanupObject getObject(unsigned i) const {
3340 assert(i < getNumObjects() && "Index out of range");
3341 return getObjects()[i];
3344 bool cleanupsHaveSideEffects() const {
3345 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
3348 SourceLocation getBeginLoc() const LLVM_READONLY {
3349 return SubExpr->getBeginLoc();
3352 SourceLocation getEndLoc() const LLVM_READONLY {
3353 return SubExpr->getEndLoc();
3356 // Implement isa/cast/dyncast/etc.
3357 static bool classof(const Stmt *T) {
3358 return T->getStmtClass() == ExprWithCleanupsClass;
3362 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
3364 const_child_range children() const {
3365 return const_child_range(&SubExpr, &SubExpr + 1);
3369 /// Describes an explicit type conversion that uses functional
3370 /// notion but could not be resolved because one or more arguments are
3373 /// The explicit type conversions expressed by
3374 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
3375 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
3376 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
3377 /// type-dependent. For example, this would occur in a template such
3381 /// template<typename T, typename A1>
3382 /// inline T make_a(const A1& a1) {
3387 /// When the returned expression is instantiated, it may resolve to a
3388 /// constructor call, conversion function call, or some kind of type
3390 class CXXUnresolvedConstructExpr final
3392 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3393 friend class ASTStmtReader;
3394 friend TrailingObjects;
3396 /// The type being constructed.
3397 TypeSourceInfo *TSI;
3399 /// The location of the left parentheses ('(').
3400 SourceLocation LParenLoc;
3402 /// The location of the right parentheses (')').
3403 SourceLocation RParenLoc;
3405 CXXUnresolvedConstructExpr(TypeSourceInfo *TSI, SourceLocation LParenLoc,
3406 ArrayRef<Expr *> Args, SourceLocation RParenLoc);
3408 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3409 : Expr(CXXUnresolvedConstructExprClass, Empty) {
3410 CXXUnresolvedConstructExprBits.NumArgs = NumArgs;
3414 static CXXUnresolvedConstructExpr *Create(const ASTContext &Context,
3415 TypeSourceInfo *Type,
3416 SourceLocation LParenLoc,
3417 ArrayRef<Expr *> Args,
3418 SourceLocation RParenLoc);
3420 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context,
3423 /// Retrieve the type that is being constructed, as specified
3424 /// in the source code.
3425 QualType getTypeAsWritten() const { return TSI->getType(); }
3427 /// Retrieve the type source information for the type being
3429 TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
3431 /// Retrieve the location of the left parentheses ('(') that
3432 /// precedes the argument list.
3433 SourceLocation getLParenLoc() const { return LParenLoc; }
3434 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3436 /// Retrieve the location of the right parentheses (')') that
3437 /// follows the argument list.
3438 SourceLocation getRParenLoc() const { return RParenLoc; }
3439 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3441 /// Determine whether this expression models list-initialization.
3442 /// If so, there will be exactly one subexpression, which will be
3443 /// an InitListExpr.
3444 bool isListInitialization() const { return LParenLoc.isInvalid(); }
3446 /// Retrieve the number of arguments.
3447 unsigned arg_size() const { return CXXUnresolvedConstructExprBits.NumArgs; }
3449 using arg_iterator = Expr **;
3450 using arg_range = llvm::iterator_range<arg_iterator>;
3452 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3453 arg_iterator arg_end() { return arg_begin() + arg_size(); }
3454 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
3456 using const_arg_iterator = const Expr* const *;
3457 using const_arg_range = llvm::iterator_range<const_arg_iterator>;
3459 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3460 const_arg_iterator arg_end() const { return arg_begin() + arg_size(); }
3461 const_arg_range arguments() const {
3462 return const_arg_range(arg_begin(), arg_end());
3465 Expr *getArg(unsigned I) {
3466 assert(I < arg_size() && "Argument index out-of-range");
3467 return arg_begin()[I];
3470 const Expr *getArg(unsigned I) const {
3471 assert(I < arg_size() && "Argument index out-of-range");
3472 return arg_begin()[I];
3475 void setArg(unsigned I, Expr *E) {
3476 assert(I < arg_size() && "Argument index out-of-range");
3480 SourceLocation getBeginLoc() const LLVM_READONLY;
3481 SourceLocation getEndLoc() const LLVM_READONLY {
3482 if (!RParenLoc.isValid() && arg_size() > 0)
3483 return getArg(arg_size() - 1)->getEndLoc();
3487 static bool classof(const Stmt *T) {
3488 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3492 child_range children() {
3493 auto **begin = reinterpret_cast<Stmt **>(arg_begin());
3494 return child_range(begin, begin + arg_size());
3497 const_child_range children() const {
3498 auto **begin = reinterpret_cast<Stmt **>(
3499 const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin());
3500 return const_child_range(begin, begin + arg_size());
3504 /// Represents a C++ member access expression where the actual
3505 /// member referenced could not be resolved because the base
3506 /// expression or the member name was dependent.
3508 /// Like UnresolvedMemberExprs, these can be either implicit or
3509 /// explicit accesses. It is only possible to get one of these with
3510 /// an implicit access if a qualifier is provided.
3511 class CXXDependentScopeMemberExpr final
3513 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3514 ASTTemplateKWAndArgsInfo,
3515 TemplateArgumentLoc, NamedDecl *> {
3516 friend class ASTStmtReader;
3517 friend class ASTStmtWriter;
3518 friend TrailingObjects;
3520 /// The expression for the base pointer or class reference,
3521 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3524 /// The type of the base expression. Never null, even for
3525 /// implicit accesses.
3528 /// The nested-name-specifier that precedes the member name, if any.
3529 /// FIXME: This could be in principle store as a trailing object.
3530 /// However the performance impact of doing so should be investigated first.
3531 NestedNameSpecifierLoc QualifierLoc;
3533 /// The member to which this member expression refers, which
3534 /// can be name, overloaded operator, or destructor.
3536 /// FIXME: could also be a template-id
3537 DeclarationNameInfo MemberNameInfo;
3539 // CXXDependentScopeMemberExpr is followed by several trailing objects,
3540 // some of which optional. They are in order:
3542 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3543 // template keyword and arguments. Present if and only if
3544 // hasTemplateKWAndArgsInfo().
3546 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location
3547 // information for the explicitly specified template arguments.
3549 // * An optional NamedDecl *. In a qualified member access expression such
3550 // as t->Base::f, this member stores the resolves of name lookup in the
3551 // context of the member access expression, to be used at instantiation
3552 // time. Present if and only if hasFirstQualifierFoundInScope().
3554 bool hasTemplateKWAndArgsInfo() const {
3555 return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
3558 bool hasFirstQualifierFoundInScope() const {
3559 return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
3562 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3563 return hasTemplateKWAndArgsInfo();
3566 unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const {
3567 return getNumTemplateArgs();
3570 unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const {
3571 return hasFirstQualifierFoundInScope();
3574 CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base,
3575 QualType BaseType, bool IsArrow,
3576 SourceLocation OperatorLoc,
3577 NestedNameSpecifierLoc QualifierLoc,
3578 SourceLocation TemplateKWLoc,
3579 NamedDecl *FirstQualifierFoundInScope,
3580 DeclarationNameInfo MemberNameInfo,
3581 const TemplateArgumentListInfo *TemplateArgs);
3583 CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
3584 bool HasFirstQualifierFoundInScope);
3587 static CXXDependentScopeMemberExpr *
3588 Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
3589 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3590 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3591 DeclarationNameInfo MemberNameInfo,
3592 const TemplateArgumentListInfo *TemplateArgs);
3594 static CXXDependentScopeMemberExpr *
3595 CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
3596 unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope);
3598 /// True if this is an implicit access, i.e. one in which the
3599 /// member being accessed was not written in the source. The source
3600 /// location of the operator is invalid in this case.
3601 bool isImplicitAccess() const {
3604 return cast<Expr>(Base)->isImplicitCXXThis();
3607 /// Retrieve the base object of this member expressions,
3608 /// e.g., the \c x in \c x.m.
3609 Expr *getBase() const {
3610 assert(!isImplicitAccess());
3611 return cast<Expr>(Base);
3614 QualType getBaseType() const { return BaseType; }
3616 /// Determine whether this member expression used the '->'
3617 /// operator; otherwise, it used the '.' operator.
3618 bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; }
3620 /// Retrieve the location of the '->' or '.' operator.
3621 SourceLocation getOperatorLoc() const {
3622 return CXXDependentScopeMemberExprBits.OperatorLoc;
3625 /// Retrieve the nested-name-specifier that qualifies the member name.
3626 NestedNameSpecifier *getQualifier() const {
3627 return QualifierLoc.getNestedNameSpecifier();
3630 /// Retrieve the nested-name-specifier that qualifies the member
3631 /// name, with source location information.
3632 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3634 /// Retrieve the first part of the nested-name-specifier that was
3635 /// found in the scope of the member access expression when the member access
3636 /// was initially parsed.
3638 /// This function only returns a useful result when member access expression
3639 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3640 /// returned by this function describes what was found by unqualified name
3641 /// lookup for the identifier "Base" within the scope of the member access
3642 /// expression itself. At template instantiation time, this information is
3643 /// combined with the results of name lookup into the type of the object
3644 /// expression itself (the class type of x).
3645 NamedDecl *getFirstQualifierFoundInScope() const {
3646 if (!hasFirstQualifierFoundInScope())
3648 return *getTrailingObjects<NamedDecl *>();
3651 /// Retrieve the name of the member that this expression refers to.
3652 const DeclarationNameInfo &getMemberNameInfo() const {
3653 return MemberNameInfo;
3656 /// Retrieve the name of the member that this expression refers to.
3657 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3659 // Retrieve the location of the name of the member that this
3660 // expression refers to.
3661 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3663 /// Retrieve the location of the template keyword preceding the
3664 /// member name, if any.
3665 SourceLocation getTemplateKeywordLoc() const {
3666 if (!hasTemplateKWAndArgsInfo())
3667 return SourceLocation();
3668 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3671 /// Retrieve the location of the left angle bracket starting the
3672 /// explicit template argument list following the member name, if any.
3673 SourceLocation getLAngleLoc() const {
3674 if (!hasTemplateKWAndArgsInfo())
3675 return SourceLocation();
3676 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3679 /// Retrieve the location of the right angle bracket ending the
3680 /// explicit template argument list following the member name, if any.
3681 SourceLocation getRAngleLoc() const {
3682 if (!hasTemplateKWAndArgsInfo())
3683 return SourceLocation();
3684 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3687 /// Determines whether the member name was preceded by the template keyword.
3688 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3690 /// Determines whether this member expression actually had a C++
3691 /// template argument list explicitly specified, e.g., x.f<int>.
3692 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3694 /// Copies the template arguments (if present) into the given
3696 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3697 if (hasExplicitTemplateArgs())
3698 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3699 getTrailingObjects<TemplateArgumentLoc>(), List);
3702 /// Retrieve the template arguments provided as part of this
3704 const TemplateArgumentLoc *getTemplateArgs() const {
3705 if (!hasExplicitTemplateArgs())
3708 return getTrailingObjects<TemplateArgumentLoc>();
3711 /// Retrieve the number of template arguments provided as part of this
3713 unsigned getNumTemplateArgs() const {
3714 if (!hasExplicitTemplateArgs())
3717 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3720 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3721 return {getTemplateArgs(), getNumTemplateArgs()};
3724 SourceLocation getBeginLoc() const LLVM_READONLY {
3725 if (!isImplicitAccess())
3726 return Base->getBeginLoc();
3728 return getQualifierLoc().getBeginLoc();
3729 return MemberNameInfo.getBeginLoc();
3732 SourceLocation getEndLoc() const LLVM_READONLY {
3733 if (hasExplicitTemplateArgs())
3734 return getRAngleLoc();
3735 return MemberNameInfo.getEndLoc();
3738 static bool classof(const Stmt *T) {
3739 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3743 child_range children() {
3744 if (isImplicitAccess())
3745 return child_range(child_iterator(), child_iterator());
3746 return child_range(&Base, &Base + 1);
3749 const_child_range children() const {
3750 if (isImplicitAccess())
3751 return const_child_range(const_child_iterator(), const_child_iterator());
3752 return const_child_range(&Base, &Base + 1);
3756 /// Represents a C++ member access expression for which lookup
3757 /// produced a set of overloaded functions.
3759 /// The member access may be explicit or implicit:
3763 /// int explicitAccess() { return this->a + this->A::b; }
3764 /// int implicitAccess() { return a + A::b; }
3768 /// In the final AST, an explicit access always becomes a MemberExpr.
3769 /// An implicit access may become either a MemberExpr or a
3770 /// DeclRefExpr, depending on whether the member is static.
3771 class UnresolvedMemberExpr final
3772 : public OverloadExpr,
3773 private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair,
3774 ASTTemplateKWAndArgsInfo,
3775 TemplateArgumentLoc> {
3776 friend class ASTStmtReader;
3777 friend class OverloadExpr;
3778 friend TrailingObjects;
3780 /// The expression for the base pointer or class reference,
3781 /// e.g., the \c x in x.f.
3783 /// This can be null if this is an 'unbased' member expression.
3786 /// The type of the base expression; never null.
3789 /// The location of the '->' or '.' operator.
3790 SourceLocation OperatorLoc;
3792 // UnresolvedMemberExpr is followed by several trailing objects.
3793 // They are in order:
3795 // * An array of getNumResults() DeclAccessPair for the results. These are
3796 // undesugared, which is to say, they may include UsingShadowDecls.
3797 // Access is relative to the naming class.
3799 // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
3800 // template keyword and arguments. Present if and only if
3801 // hasTemplateKWAndArgsInfo().
3803 // * An array of getNumTemplateArgs() TemplateArgumentLoc containing
3804 // location information for the explicitly specified template arguments.
3806 UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing,
3807 Expr *Base, QualType BaseType, bool IsArrow,
3808 SourceLocation OperatorLoc,
3809 NestedNameSpecifierLoc QualifierLoc,
3810 SourceLocation TemplateKWLoc,
3811 const DeclarationNameInfo &MemberNameInfo,
3812 const TemplateArgumentListInfo *TemplateArgs,
3813 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3815 UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults,
3816 bool HasTemplateKWAndArgsInfo);
3818 unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3819 return getNumDecls();
3822 unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3823 return hasTemplateKWAndArgsInfo();
3827 static UnresolvedMemberExpr *
3828 Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
3829 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
3830 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3831 const DeclarationNameInfo &MemberNameInfo,
3832 const TemplateArgumentListInfo *TemplateArgs,
3833 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3835 static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context,
3836 unsigned NumResults,
3837 bool HasTemplateKWAndArgsInfo,
3838 unsigned NumTemplateArgs);
3840 /// True if this is an implicit access, i.e., one in which the
3841 /// member being accessed was not written in the source.
3843 /// The source location of the operator is invalid in this case.
3844 bool isImplicitAccess() const;
3846 /// Retrieve the base object of this member expressions,
3847 /// e.g., the \c x in \c x.m.
3849 assert(!isImplicitAccess());
3850 return cast<Expr>(Base);
3852 const Expr *getBase() const {
3853 assert(!isImplicitAccess());
3854 return cast<Expr>(Base);
3857 QualType getBaseType() const { return BaseType; }
3859 /// Determine whether the lookup results contain an unresolved using
3861 bool hasUnresolvedUsing() const {
3862 return UnresolvedMemberExprBits.HasUnresolvedUsing;
3865 /// Determine whether this member expression used the '->'
3866 /// operator; otherwise, it used the '.' operator.
3867 bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; }
3869 /// Retrieve the location of the '->' or '.' operator.
3870 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3872 /// Retrieve the naming class of this lookup.
3873 CXXRecordDecl *getNamingClass();
3874 const CXXRecordDecl *getNamingClass() const {
3875 return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass();
3878 /// Retrieve the full name info for the member that this expression
3880 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3882 /// Retrieve the name of the member that this expression refers to.
3883 DeclarationName getMemberName() const { return getName(); }
3885 /// Retrieve the location of the name of the member that this
3886 /// expression refers to.
3887 SourceLocation getMemberLoc() const { return getNameLoc(); }
3889 /// Return the preferred location (the member name) for the arrow when
3890 /// diagnosing a problem with this expression.
3891 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3893 SourceLocation getBeginLoc() const LLVM_READONLY {
3894 if (!isImplicitAccess())
3895 return Base->getBeginLoc();
3896 if (NestedNameSpecifierLoc l = getQualifierLoc())
3897 return l.getBeginLoc();
3898 return getMemberNameInfo().getBeginLoc();
3901 SourceLocation getEndLoc() const LLVM_READONLY {
3902 if (hasExplicitTemplateArgs())
3903 return getRAngleLoc();
3904 return getMemberNameInfo().getEndLoc();
3907 static bool classof(const Stmt *T) {
3908 return T->getStmtClass() == UnresolvedMemberExprClass;
3912 child_range children() {
3913 if (isImplicitAccess())
3914 return child_range(child_iterator(), child_iterator());
3915 return child_range(&Base, &Base + 1);
3918 const_child_range children() const {
3919 if (isImplicitAccess())
3920 return const_child_range(const_child_iterator(), const_child_iterator());
3921 return const_child_range(&Base, &Base + 1);
3925 DeclAccessPair *OverloadExpr::getTrailingResults() {
3926 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3927 return ULE->getTrailingObjects<DeclAccessPair>();
3928 return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>();
3931 ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3932 if (!hasTemplateKWAndArgsInfo())
3935 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3936 return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3937 return cast<UnresolvedMemberExpr>(this)
3938 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3941 TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3942 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3943 return ULE->getTrailingObjects<TemplateArgumentLoc>();
3944 return cast<UnresolvedMemberExpr>(this)
3945 ->getTrailingObjects<TemplateArgumentLoc>();
3948 CXXRecordDecl *OverloadExpr::getNamingClass() {
3949 if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this))
3950 return ULE->getNamingClass();
3951 return cast<UnresolvedMemberExpr>(this)->getNamingClass();
3954 /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3956 /// The noexcept expression tests whether a given expression might throw. Its
3957 /// result is a boolean constant.
3958 class CXXNoexceptExpr : public Expr {
3959 friend class ASTStmtReader;
3965 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3966 SourceLocation Keyword, SourceLocation RParen)
3967 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3968 /*TypeDependent*/ false,
3969 /*ValueDependent*/ Val == CT_Dependent,
3970 Val == CT_Dependent || Operand->isInstantiationDependent(),
3971 Operand->containsUnexpandedParameterPack()),
3972 Operand(Operand), Range(Keyword, RParen) {
3973 CXXNoexceptExprBits.Value = Val == CT_Cannot;
3976 CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
3978 Expr *getOperand() const { return static_cast<Expr *>(Operand); }
3980 SourceLocation getBeginLoc() const { return Range.getBegin(); }
3981 SourceLocation getEndLoc() const { return Range.getEnd(); }
3982 SourceRange getSourceRange() const { return Range; }
3984 bool getValue() const { return CXXNoexceptExprBits.Value; }
3986 static bool classof(const Stmt *T) {
3987 return T->getStmtClass() == CXXNoexceptExprClass;
3991 child_range children() { return child_range(&Operand, &Operand + 1); }
3993 const_child_range children() const {
3994 return const_child_range(&Operand, &Operand + 1);
3998 /// Represents a C++11 pack expansion that produces a sequence of
4001 /// A pack expansion expression contains a pattern (which itself is an
4002 /// expression) followed by an ellipsis. For example:
4005 /// template<typename F, typename ...Types>
4006 /// void forward(F f, Types &&...args) {
4007 /// f(static_cast<Types&&>(args)...);
4011 /// Here, the argument to the function object \c f is a pack expansion whose
4012 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
4013 /// template is instantiated, the pack expansion will instantiate to zero or
4014 /// or more function arguments to the function object \c f.
4015 class PackExpansionExpr : public Expr {
4016 friend class ASTStmtReader;
4017 friend class ASTStmtWriter;
4019 SourceLocation EllipsisLoc;
4021 /// The number of expansions that will be produced by this pack
4022 /// expansion expression, if known.
4024 /// When zero, the number of expansions is not known. Otherwise, this value
4025 /// is the number of expansions + 1.
4026 unsigned NumExpansions;
4031 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
4032 Optional<unsigned> NumExpansions)
4033 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
4034 Pattern->getObjectKind(), /*TypeDependent=*/true,
4035 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
4036 /*ContainsUnexpandedParameterPack=*/false),
4037 EllipsisLoc(EllipsisLoc),
4038 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
4041 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {}
4043 /// Retrieve the pattern of the pack expansion.
4044 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
4046 /// Retrieve the pattern of the pack expansion.
4047 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
4049 /// Retrieve the location of the ellipsis that describes this pack
4051 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4053 /// Determine the number of expansions that will be produced when
4054 /// this pack expansion is instantiated, if already known.
4055 Optional<unsigned> getNumExpansions() const {
4057 return NumExpansions - 1;
4062 SourceLocation getBeginLoc() const LLVM_READONLY {
4063 return Pattern->getBeginLoc();
4066 SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; }
4068 static bool classof(const Stmt *T) {
4069 return T->getStmtClass() == PackExpansionExprClass;
4073 child_range children() {
4074 return child_range(&Pattern, &Pattern + 1);
4077 const_child_range children() const {
4078 return const_child_range(&Pattern, &Pattern + 1);
4082 /// Represents an expression that computes the length of a parameter
4086 /// template<typename ...Types>
4088 /// static const unsigned value = sizeof...(Types);
4091 class SizeOfPackExpr final
4093 private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
4094 friend class ASTStmtReader;
4095 friend class ASTStmtWriter;
4096 friend TrailingObjects;
4098 /// The location of the \c sizeof keyword.
4099 SourceLocation OperatorLoc;
4101 /// The location of the name of the parameter pack.
4102 SourceLocation PackLoc;
4104 /// The location of the closing parenthesis.
4105 SourceLocation RParenLoc;
4107 /// The length of the parameter pack, if known.
4109 /// When this expression is not value-dependent, this is the length of
4110 /// the pack. When the expression was parsed rather than instantiated
4111 /// (and thus is value-dependent), this is zero.
4113 /// After partial substitution into a sizeof...(X) expression (for instance,
4114 /// within an alias template or during function template argument deduction),
4115 /// we store a trailing array of partially-substituted TemplateArguments,
4116 /// and this is the length of that array.
4119 /// The parameter pack.
4120 NamedDecl *Pack = nullptr;
4122 /// Create an expression that computes the length of
4123 /// the given parameter pack.
4124 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
4125 SourceLocation PackLoc, SourceLocation RParenLoc,
4126 Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
4127 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
4128 /*TypeDependent=*/false, /*ValueDependent=*/!Length,
4129 /*InstantiationDependent=*/!Length,
4130 /*ContainsUnexpandedParameterPack=*/false),
4131 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
4132 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
4133 assert((!Length || PartialArgs.empty()) &&
4134 "have partial args for non-dependent sizeof... expression");
4135 auto *Args = getTrailingObjects<TemplateArgument>();
4136 std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
4139 /// Create an empty expression.
4140 SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
4141 : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
4144 static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
4145 NamedDecl *Pack, SourceLocation PackLoc,
4146 SourceLocation RParenLoc,
4147 Optional<unsigned> Length = None,
4148 ArrayRef<TemplateArgument> PartialArgs = None);
4149 static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
4150 unsigned NumPartialArgs);
4152 /// Determine the location of the 'sizeof' keyword.
4153 SourceLocation getOperatorLoc() const { return OperatorLoc; }
4155 /// Determine the location of the parameter pack.
4156 SourceLocation getPackLoc() const { return PackLoc; }
4158 /// Determine the location of the right parenthesis.
4159 SourceLocation getRParenLoc() const { return RParenLoc; }
4161 /// Retrieve the parameter pack.
4162 NamedDecl *getPack() const { return Pack; }
4164 /// Retrieve the length of the parameter pack.
4166 /// This routine may only be invoked when the expression is not
4167 /// value-dependent.
4168 unsigned getPackLength() const {
4169 assert(!isValueDependent() &&
4170 "Cannot get the length of a value-dependent pack size expression");
4174 /// Determine whether this represents a partially-substituted sizeof...
4175 /// expression, such as is produced for:
4177 /// template<typename ...Ts> using X = int[sizeof...(Ts)];
4178 /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
4179 bool isPartiallySubstituted() const {
4180 return isValueDependent() && Length;
4184 ArrayRef<TemplateArgument> getPartialArguments() const {
4185 assert(isPartiallySubstituted());
4186 const auto *Args = getTrailingObjects<TemplateArgument>();
4187 return llvm::makeArrayRef(Args, Args + Length);
4190 SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
4191 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4193 static bool classof(const Stmt *T) {
4194 return T->getStmtClass() == SizeOfPackExprClass;
4198 child_range children() {
4199 return child_range(child_iterator(), child_iterator());
4202 const_child_range children() const {
4203 return const_child_range(const_child_iterator(), const_child_iterator());
4207 /// Represents a reference to a non-type template parameter
4208 /// that has been substituted with a template argument.
4209 class SubstNonTypeTemplateParmExpr : public Expr {
4210 friend class ASTReader;
4211 friend class ASTStmtReader;
4213 /// The replaced parameter.
4214 NonTypeTemplateParmDecl *Param;
4216 /// The replacement expression.
4219 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
4220 : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
4223 SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
4225 NonTypeTemplateParmDecl *Param,
4227 : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary,
4228 Replacement->isTypeDependent(), Replacement->isValueDependent(),
4229 Replacement->isInstantiationDependent(),
4230 Replacement->containsUnexpandedParameterPack()),
4231 Param(Param), Replacement(Replacement) {
4232 SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
4235 SourceLocation getNameLoc() const {
4236 return SubstNonTypeTemplateParmExprBits.NameLoc;
4238 SourceLocation getBeginLoc() const { return getNameLoc(); }
4239 SourceLocation getEndLoc() const { return getNameLoc(); }
4241 Expr *getReplacement() const { return cast<Expr>(Replacement); }
4243 NonTypeTemplateParmDecl *getParameter() const { return Param; }
4245 static bool classof(const Stmt *s) {
4246 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
4250 child_range children() { return child_range(&Replacement, &Replacement + 1); }
4252 const_child_range children() const {
4253 return const_child_range(&Replacement, &Replacement + 1);
4257 /// Represents a reference to a non-type template parameter pack that
4258 /// has been substituted with a non-template argument pack.
4260 /// When a pack expansion in the source code contains multiple parameter packs
4261 /// and those parameter packs correspond to different levels of template
4262 /// parameter lists, this node is used to represent a non-type template
4263 /// parameter pack from an outer level, which has already had its argument pack
4264 /// substituted but that still lives within a pack expansion that itself
4265 /// could not be instantiated. When actually performing a substitution into
4266 /// that pack expansion (e.g., when all template parameters have corresponding
4267 /// arguments), this type will be replaced with the appropriate underlying
4268 /// expression at the current pack substitution index.
4269 class SubstNonTypeTemplateParmPackExpr : public Expr {
4270 friend class ASTReader;
4271 friend class ASTStmtReader;
4273 /// The non-type template parameter pack itself.
4274 NonTypeTemplateParmDecl *Param;
4276 /// A pointer to the set of template arguments that this
4277 /// parameter pack is instantiated with.
4278 const TemplateArgument *Arguments;
4280 /// The number of template arguments in \c Arguments.
4281 unsigned NumArguments;
4283 /// The location of the non-type template parameter pack reference.
4284 SourceLocation NameLoc;
4286 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
4287 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {}
4290 SubstNonTypeTemplateParmPackExpr(QualType T,
4291 ExprValueKind ValueKind,
4292 NonTypeTemplateParmDecl *Param,
4293 SourceLocation NameLoc,
4294 const TemplateArgument &ArgPack);
4296 /// Retrieve the non-type template parameter pack being substituted.
4297 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
4299 /// Retrieve the location of the parameter pack name.
4300 SourceLocation getParameterPackLocation() const { return NameLoc; }
4302 /// Retrieve the template argument pack containing the substituted
4303 /// template arguments.
4304 TemplateArgument getArgumentPack() const;
4306 SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
4307 SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4309 static bool classof(const Stmt *T) {
4310 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
4314 child_range children() {
4315 return child_range(child_iterator(), child_iterator());
4318 const_child_range children() const {
4319 return const_child_range(const_child_iterator(), const_child_iterator());
4323 /// Represents a reference to a function parameter pack or init-capture pack
4324 /// that has been substituted but not yet expanded.
4326 /// When a pack expansion contains multiple parameter packs at different levels,
4327 /// this node is used to represent a function parameter pack at an outer level
4328 /// which we have already substituted to refer to expanded parameters, but where
4329 /// the containing pack expansion cannot yet be expanded.
4332 /// template<typename...Ts> struct S {
4333 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
4335 /// template struct S<int, int>;
4337 class FunctionParmPackExpr final
4339 private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> {
4340 friend class ASTReader;
4341 friend class ASTStmtReader;
4342 friend TrailingObjects;
4344 /// The function parameter pack which was referenced.
4347 /// The location of the function parameter pack reference.
4348 SourceLocation NameLoc;
4350 /// The number of expansions of this pack.
4351 unsigned NumParameters;
4353 FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
4354 SourceLocation NameLoc, unsigned NumParams,
4355 VarDecl *const *Params);
4358 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
4360 SourceLocation NameLoc,
4361 ArrayRef<VarDecl *> Params);
4362 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
4363 unsigned NumParams);
4365 /// Get the parameter pack which this expression refers to.
4366 VarDecl *getParameterPack() const { return ParamPack; }
4368 /// Get the location of the parameter pack.
4369 SourceLocation getParameterPackLocation() const { return NameLoc; }
4371 /// Iterators over the parameters which the parameter pack expanded
4373 using iterator = VarDecl * const *;
4374 iterator begin() const { return getTrailingObjects<VarDecl *>(); }
4375 iterator end() const { return begin() + NumParameters; }
4377 /// Get the number of parameters in this parameter pack.
4378 unsigned getNumExpansions() const { return NumParameters; }
4380 /// Get an expansion of the parameter pack by index.
4381 VarDecl *getExpansion(unsigned I) const { return begin()[I]; }
4383 SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
4384 SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
4386 static bool classof(const Stmt *T) {
4387 return T->getStmtClass() == FunctionParmPackExprClass;
4390 child_range children() {
4391 return child_range(child_iterator(), child_iterator());
4394 const_child_range children() const {
4395 return const_child_range(const_child_iterator(), const_child_iterator());
4399 /// Represents a prvalue temporary that is written into memory so that
4400 /// a reference can bind to it.
4402 /// Prvalue expressions are materialized when they need to have an address
4403 /// in memory for a reference to bind to. This happens when binding a
4404 /// reference to the result of a conversion, e.g.,
4407 /// const int &r = 1.0;
4410 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
4411 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
4412 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
4413 /// (either an lvalue or an xvalue, depending on the kind of reference binding
4414 /// to it), maintaining the invariant that references always bind to glvalues.
4416 /// Reference binding and copy-elision can both extend the lifetime of a
4417 /// temporary. When either happens, the expression will also track the
4418 /// declaration which is responsible for the lifetime extension.
4419 class MaterializeTemporaryExpr : public Expr {
4421 friend class ASTStmtReader;
4422 friend class ASTStmtWriter;
4424 llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State;
4427 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
4428 bool BoundToLvalueReference,
4429 LifetimeExtendedTemporaryDecl *MTD = nullptr);
4431 MaterializeTemporaryExpr(EmptyShell Empty)
4432 : Expr(MaterializeTemporaryExprClass, Empty) {}
4434 /// Retrieve the temporary-generating subexpression whose value will
4435 /// be materialized into a glvalue.
4436 Expr *getSubExpr() const {
4439 ? State.get<Stmt *>()
4440 : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr());
4443 /// Retrieve the storage duration for the materialized temporary.
4444 StorageDuration getStorageDuration() const {
4445 return State.is<Stmt *>() ? SD_FullExpression
4446 : State.get<LifetimeExtendedTemporaryDecl *>()
4447 ->getStorageDuration();
4450 /// Get the storage for the constant value of a materialized temporary
4451 /// of static storage duration.
4452 APValue *getOrCreateValue(bool MayCreate) const {
4453 assert(State.is<LifetimeExtendedTemporaryDecl *>() &&
4454 "the temporary has not been lifetime extended");
4455 return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue(
4459 LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() {
4460 return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
4462 const LifetimeExtendedTemporaryDecl *
4463 getLifetimeExtendedTemporaryDecl() const {
4464 return State.dyn_cast<LifetimeExtendedTemporaryDecl *>();
4467 /// Get the declaration which triggered the lifetime-extension of this
4468 /// temporary, if any.
4469 ValueDecl *getExtendingDecl() {
4470 return State.is<Stmt *>() ? nullptr
4471 : State.get<LifetimeExtendedTemporaryDecl *>()
4472 ->getExtendingDecl();
4474 const ValueDecl *getExtendingDecl() const {
4475 return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl();
4478 void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber);
4480 unsigned getManglingNumber() const {
4481 return State.is<Stmt *>() ? 0
4482 : State.get<LifetimeExtendedTemporaryDecl *>()
4483 ->getManglingNumber();
4486 /// Determine whether this materialized temporary is bound to an
4487 /// lvalue reference; otherwise, it's bound to an rvalue reference.
4488 bool isBoundToLvalueReference() const {
4489 return getValueKind() == VK_LValue;
4492 SourceLocation getBeginLoc() const LLVM_READONLY {
4493 return getSubExpr()->getBeginLoc();
4496 SourceLocation getEndLoc() const LLVM_READONLY {
4497 return getSubExpr()->getEndLoc();
4500 static bool classof(const Stmt *T) {
4501 return T->getStmtClass() == MaterializeTemporaryExprClass;
4505 child_range children() {
4506 return State.is<Stmt *>()
4507 ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1)
4508 : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr();
4511 const_child_range children() const {
4512 return State.is<Stmt *>()
4513 ? const_child_range(State.getAddrOfPtr1(),
4514 State.getAddrOfPtr1() + 1)
4515 : const_cast<const LifetimeExtendedTemporaryDecl *>(
4516 State.get<LifetimeExtendedTemporaryDecl *>())
4521 /// Represents a folding of a pack over an operator.
4523 /// This expression is always dependent and represents a pack expansion of the
4528 /// ( expr op ... op expr )
4529 class CXXFoldExpr : public Expr {
4530 friend class ASTStmtReader;
4531 friend class ASTStmtWriter;
4533 SourceLocation LParenLoc;
4534 SourceLocation EllipsisLoc;
4535 SourceLocation RParenLoc;
4536 // When 0, the number of expansions is not known. Otherwise, this is one more
4537 // than the number of expansions.
4538 unsigned NumExpansions;
4540 BinaryOperatorKind Opcode;
4543 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
4544 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
4545 SourceLocation RParenLoc, Optional<unsigned> NumExpansions)
4546 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
4547 /*Dependent*/ true, true, true,
4548 /*ContainsUnexpandedParameterPack*/ false),
4549 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4550 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) {
4555 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4557 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
4558 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
4560 /// Does this produce a right-associated sequence of operators?
4561 bool isRightFold() const {
4562 return getLHS() && getLHS()->containsUnexpandedParameterPack();
4565 /// Does this produce a left-associated sequence of operators?
4566 bool isLeftFold() const { return !isRightFold(); }
4568 /// Get the pattern, that is, the operand that contains an unexpanded pack.
4569 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4571 /// Get the operand that doesn't contain a pack, for a binary fold.
4572 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4574 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4575 BinaryOperatorKind getOperator() const { return Opcode; }
4577 Optional<unsigned> getNumExpansions() const {
4579 return NumExpansions - 1;
4583 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4585 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4587 static bool classof(const Stmt *T) {
4588 return T->getStmtClass() == CXXFoldExprClass;
4592 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4594 const_child_range children() const {
4595 return const_child_range(SubExprs, SubExprs + 2);
4599 /// Represents an expression that might suspend coroutine execution;
4600 /// either a co_await or co_yield expression.
4602 /// Evaluation of this expression first evaluates its 'ready' expression. If
4603 /// that returns 'false':
4604 /// -- execution of the coroutine is suspended
4605 /// -- the 'suspend' expression is evaluated
4606 /// -- if the 'suspend' expression returns 'false', the coroutine is
4608 /// -- otherwise, control passes back to the resumer.
4609 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4610 /// expression is evaluated, and its result is the result of the overall
4612 class CoroutineSuspendExpr : public Expr {
4613 friend class ASTStmtReader;
4615 SourceLocation KeywordLoc;
4617 enum SubExpr { Common, Ready, Suspend, Resume, Count };
4619 Stmt *SubExprs[SubExpr::Count];
4620 OpaqueValueExpr *OpaqueValue = nullptr;
4623 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4624 Expr *Ready, Expr *Suspend, Expr *Resume,
4625 OpaqueValueExpr *OpaqueValue)
4626 : Expr(SC, Resume->getType(), Resume->getValueKind(),
4627 Resume->getObjectKind(), Resume->isTypeDependent(),
4628 Resume->isValueDependent(), Common->isInstantiationDependent(),
4629 Common->containsUnexpandedParameterPack()),
4630 KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
4631 SubExprs[SubExpr::Common] = Common;
4632 SubExprs[SubExpr::Ready] = Ready;
4633 SubExprs[SubExpr::Suspend] = Suspend;
4634 SubExprs[SubExpr::Resume] = Resume;
4637 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4639 : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
4640 Common->containsUnexpandedParameterPack()),
4641 KeywordLoc(KeywordLoc) {
4642 assert(Common->isTypeDependent() && Ty->isDependentType() &&
4643 "wrong constructor for non-dependent co_await/co_yield expression");
4644 SubExprs[SubExpr::Common] = Common;
4645 SubExprs[SubExpr::Ready] = nullptr;
4646 SubExprs[SubExpr::Suspend] = nullptr;
4647 SubExprs[SubExpr::Resume] = nullptr;
4650 CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4651 SubExprs[SubExpr::Common] = nullptr;
4652 SubExprs[SubExpr::Ready] = nullptr;
4653 SubExprs[SubExpr::Suspend] = nullptr;
4654 SubExprs[SubExpr::Resume] = nullptr;
4657 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4659 Expr *getCommonExpr() const {
4660 return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4663 /// getOpaqueValue - Return the opaque value placeholder.
4664 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4666 Expr *getReadyExpr() const {
4667 return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4670 Expr *getSuspendExpr() const {
4671 return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4674 Expr *getResumeExpr() const {
4675 return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4678 SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4680 SourceLocation getEndLoc() const LLVM_READONLY {
4681 return getCommonExpr()->getEndLoc();
4684 child_range children() {
4685 return child_range(SubExprs, SubExprs + SubExpr::Count);
4688 const_child_range children() const {
4689 return const_child_range(SubExprs, SubExprs + SubExpr::Count);
4692 static bool classof(const Stmt *T) {
4693 return T->getStmtClass() == CoawaitExprClass ||
4694 T->getStmtClass() == CoyieldExprClass;
4698 /// Represents a 'co_await' expression.
4699 class CoawaitExpr : public CoroutineSuspendExpr {
4700 friend class ASTStmtReader;
4703 CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4704 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
4705 bool IsImplicit = false)
4706 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4707 Suspend, Resume, OpaqueValue) {
4708 CoawaitBits.IsImplicit = IsImplicit;
4711 CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
4712 bool IsImplicit = false)
4713 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
4714 CoawaitBits.IsImplicit = IsImplicit;
4717 CoawaitExpr(EmptyShell Empty)
4718 : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4720 Expr *getOperand() const {
4721 // FIXME: Dig out the actual operand or store it.
4722 return getCommonExpr();
4725 bool isImplicit() const { return CoawaitBits.IsImplicit; }
4726 void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
4728 static bool classof(const Stmt *T) {
4729 return T->getStmtClass() == CoawaitExprClass;
4733 /// Represents a 'co_await' expression while the type of the promise
4735 class DependentCoawaitExpr : public Expr {
4736 friend class ASTStmtReader;
4738 SourceLocation KeywordLoc;
4742 DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
4743 UnresolvedLookupExpr *OpCoawait)
4744 : Expr(DependentCoawaitExprClass, Ty, VK_RValue, OK_Ordinary,
4745 /*TypeDependent*/ true, /*ValueDependent*/ true,
4746 /*InstantiationDependent*/ true,
4747 Op->containsUnexpandedParameterPack()),
4748 KeywordLoc(KeywordLoc) {
4749 // NOTE: A co_await expression is dependent on the coroutines promise
4750 // type and may be dependent even when the `Op` expression is not.
4751 assert(Ty->isDependentType() &&
4752 "wrong constructor for non-dependent co_await/co_yield expression");
4754 SubExprs[1] = OpCoawait;
4757 DependentCoawaitExpr(EmptyShell Empty)
4758 : Expr(DependentCoawaitExprClass, Empty) {}
4760 Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
4762 UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
4763 return cast<UnresolvedLookupExpr>(SubExprs[1]);
4766 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4768 SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
4770 SourceLocation getEndLoc() const LLVM_READONLY {
4771 return getOperand()->getEndLoc();
4774 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4776 const_child_range children() const {
4777 return const_child_range(SubExprs, SubExprs + 2);
4780 static bool classof(const Stmt *T) {
4781 return T->getStmtClass() == DependentCoawaitExprClass;
4785 /// Represents a 'co_yield' expression.
4786 class CoyieldExpr : public CoroutineSuspendExpr {
4787 friend class ASTStmtReader;
4790 CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4791 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
4792 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4793 Suspend, Resume, OpaqueValue) {}
4794 CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4795 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
4796 CoyieldExpr(EmptyShell Empty)
4797 : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4799 Expr *getOperand() const {
4800 // FIXME: Dig out the actual operand or store it.
4801 return getCommonExpr();
4804 static bool classof(const Stmt *T) {
4805 return T->getStmtClass() == CoyieldExprClass;
4809 /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement
4810 /// std::bit_cast. These can sometimes be evaluated as part of a constant
4811 /// expression, but otherwise CodeGen to a simple memcpy in general.
4812 class BuiltinBitCastExpr final
4813 : public ExplicitCastExpr,
4814 private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> {
4815 friend class ASTStmtReader;
4816 friend class CastExpr;
4817 friend class TrailingObjects;
4819 SourceLocation KWLoc;
4820 SourceLocation RParenLoc;
4823 BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr,
4824 TypeSourceInfo *DstType, SourceLocation KWLoc,
4825 SourceLocation RParenLoc)
4826 : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0,
4828 KWLoc(KWLoc), RParenLoc(RParenLoc) {}
4830 SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; }
4831 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4833 static bool classof(const Stmt *T) {
4834 return T->getStmtClass() == BuiltinBitCastExprClass;
4838 } // namespace clang
4840 #endif // LLVM_CLANG_AST_EXPRCXX_H