1 //===- ExprCXX.h - Classes for representing expressions ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::Expr interface and subclasses for C++ expressions.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_EXPRCXX_H
16 #define LLVM_CLANG_AST_EXPRCXX_H
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclBase.h"
20 #include "clang/AST/DeclCXX.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 /// \brief 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 : public CallExpr {
79 /// \brief The overloaded operator.
80 OverloadedOperatorKind Operator;
84 // Only meaningful for floating point types.
87 SourceRange getSourceRangeImpl() const LLVM_READONLY;
90 friend class ASTStmtReader;
91 friend class ASTStmtWriter;
93 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
94 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
95 SourceLocation operatorloc, FPOptions FPFeatures)
96 : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
97 Operator(Op), FPFeatures(FPFeatures) {
98 Range = getSourceRangeImpl();
101 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty)
102 : CallExpr(C, CXXOperatorCallExprClass, Empty) {}
104 /// \brief Returns the kind of overloaded operator that this
105 /// expression refers to.
106 OverloadedOperatorKind getOperator() const { return Operator; }
108 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
109 return Opc == OO_Equal || Opc == OO_StarEqual ||
110 Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
111 Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
112 Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
113 Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
116 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
118 /// \brief Is this written as an infix binary operator?
119 bool isInfixBinaryOp() const;
121 /// \brief Returns the location of the operator symbol in the expression.
123 /// When \c getOperator()==OO_Call, this is the location of the right
124 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
125 /// of the right bracket.
126 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
128 SourceLocation getExprLoc() const LLVM_READONLY {
129 return (Operator < OO_Plus || Operator >= OO_Arrow ||
130 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
135 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
136 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
137 SourceRange getSourceRange() const { return Range; }
139 static bool classof(const Stmt *T) {
140 return T->getStmtClass() == CXXOperatorCallExprClass;
143 // Set the FP contractability status of this operator. Only meaningful for
144 // operations on floating point types.
145 void setFPFeatures(FPOptions F) { FPFeatures = F; }
147 FPOptions getFPFeatures() const { return FPFeatures; }
149 // Get the FP contractability status of this operator. Only meaningful for
150 // operations on floating point types.
151 bool isFPContractableWithinStatement() const {
152 return FPFeatures.allowFPContractWithinStatement();
156 /// Represents a call to a member function that
157 /// may be written either with member call syntax (e.g., "obj.func()"
158 /// or "objptr->func()") or with normal function-call syntax
159 /// ("func()") within a member function that ends up calling a member
160 /// function. The callee in either case is a MemberExpr that contains
161 /// both the object argument and the member function, while the
162 /// arguments are the arguments within the parentheses (not including
163 /// the object argument).
164 class CXXMemberCallExpr : public CallExpr {
166 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
167 QualType t, ExprValueKind VK, SourceLocation RP)
168 : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
170 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
171 : CallExpr(C, CXXMemberCallExprClass, Empty) {}
173 /// \brief Retrieves the implicit object argument for the member call.
175 /// For example, in "x.f(5)", this returns the sub-expression "x".
176 Expr *getImplicitObjectArgument() const;
178 /// \brief Retrieves the declaration of the called method.
179 CXXMethodDecl *getMethodDecl() const;
181 /// \brief Retrieves the CXXRecordDecl for the underlying type of
182 /// the implicit object argument.
184 /// Note that this is may not be the same declaration as that of the class
185 /// context of the CXXMethodDecl which this function is calling.
186 /// FIXME: Returns 0 for member pointer call exprs.
187 CXXRecordDecl *getRecordDecl() const;
189 SourceLocation getExprLoc() const LLVM_READONLY {
190 SourceLocation CLoc = getCallee()->getExprLoc();
194 return getLocStart();
197 static bool classof(const Stmt *T) {
198 return T->getStmtClass() == CXXMemberCallExprClass;
202 /// \brief Represents a call to a CUDA kernel function.
203 class CUDAKernelCallExpr : public CallExpr {
205 enum { CONFIG, END_PREARG };
208 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
209 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
211 : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP) {}
213 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
214 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) {}
216 const CallExpr *getConfig() const {
217 return cast_or_null<CallExpr>(getPreArg(CONFIG));
219 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
221 /// \brief Sets the kernel configuration expression.
223 /// Note that this method cannot be called if config has already been set to a
225 void setConfig(CallExpr *E) {
226 assert(!getConfig() &&
227 "Cannot call setConfig if config is not null");
228 setPreArg(CONFIG, E);
229 setInstantiationDependent(isInstantiationDependent() ||
230 E->isInstantiationDependent());
231 setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() ||
232 E->containsUnexpandedParameterPack());
235 static bool classof(const Stmt *T) {
236 return T->getStmtClass() == CUDAKernelCallExprClass;
240 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
242 /// This abstract class is inherited by all of the classes
243 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
244 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
245 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
246 class CXXNamedCastExpr : public ExplicitCastExpr {
248 // the location of the casting op
251 // the location of the right parenthesis
252 SourceLocation RParenLoc;
255 SourceRange AngleBrackets;
258 friend class ASTStmtReader;
260 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
261 CastKind kind, Expr *op, unsigned PathSize,
262 TypeSourceInfo *writtenTy, SourceLocation l,
263 SourceLocation RParenLoc,
264 SourceRange AngleBrackets)
265 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
266 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
268 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
269 : ExplicitCastExpr(SC, Shell, PathSize) {}
272 const char *getCastName() const;
274 /// \brief Retrieve the location of the cast operator keyword, e.g.,
276 SourceLocation getOperatorLoc() const { return Loc; }
278 /// \brief Retrieve the location of the closing parenthesis.
279 SourceLocation getRParenLoc() const { return RParenLoc; }
281 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
282 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
283 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
285 static bool classof(const Stmt *T) {
286 switch (T->getStmtClass()) {
287 case CXXStaticCastExprClass:
288 case CXXDynamicCastExprClass:
289 case CXXReinterpretCastExprClass:
290 case CXXConstCastExprClass:
298 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
300 /// This expression node represents a C++ static cast, e.g.,
301 /// \c static_cast<int>(1.0).
302 class CXXStaticCastExpr final
303 : public CXXNamedCastExpr,
304 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
305 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
306 unsigned pathSize, TypeSourceInfo *writtenTy,
307 SourceLocation l, SourceLocation RParenLoc,
308 SourceRange AngleBrackets)
309 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
310 writtenTy, l, RParenLoc, AngleBrackets) {}
312 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
313 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) {}
316 friend class CastExpr;
317 friend TrailingObjects;
319 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
320 ExprValueKind VK, CastKind K, Expr *Op,
321 const CXXCastPath *Path,
322 TypeSourceInfo *Written, SourceLocation L,
323 SourceLocation RParenLoc,
324 SourceRange AngleBrackets);
325 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
328 static bool classof(const Stmt *T) {
329 return T->getStmtClass() == CXXStaticCastExprClass;
333 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
335 /// This expression node represents a dynamic cast, e.g.,
336 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
337 /// check to determine how to perform the type conversion.
338 class CXXDynamicCastExpr final
339 : public CXXNamedCastExpr,
340 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
341 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
342 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
343 SourceLocation l, SourceLocation RParenLoc,
344 SourceRange AngleBrackets)
345 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
346 writtenTy, l, RParenLoc, AngleBrackets) {}
348 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
349 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) {}
352 friend class CastExpr;
353 friend TrailingObjects;
355 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
356 ExprValueKind VK, CastKind Kind, Expr *Op,
357 const CXXCastPath *Path,
358 TypeSourceInfo *Written, SourceLocation L,
359 SourceLocation RParenLoc,
360 SourceRange AngleBrackets);
362 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
365 bool isAlwaysNull() const;
367 static bool classof(const Stmt *T) {
368 return T->getStmtClass() == CXXDynamicCastExprClass;
372 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
374 /// This expression node represents a reinterpret cast, e.g.,
375 /// @c reinterpret_cast<int>(VoidPtr).
377 /// A reinterpret_cast provides a differently-typed view of a value but
378 /// (in Clang, as in most C++ implementations) performs no actual work at
380 class CXXReinterpretCastExpr final
381 : public CXXNamedCastExpr,
382 private llvm::TrailingObjects<CXXReinterpretCastExpr,
383 CXXBaseSpecifier *> {
384 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
385 Expr *op, unsigned pathSize,
386 TypeSourceInfo *writtenTy, SourceLocation l,
387 SourceLocation RParenLoc,
388 SourceRange AngleBrackets)
389 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
390 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
392 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
393 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) {}
396 friend class CastExpr;
397 friend TrailingObjects;
399 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
400 ExprValueKind VK, CastKind Kind,
401 Expr *Op, const CXXCastPath *Path,
402 TypeSourceInfo *WrittenTy, SourceLocation L,
403 SourceLocation RParenLoc,
404 SourceRange AngleBrackets);
405 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
408 static bool classof(const Stmt *T) {
409 return T->getStmtClass() == CXXReinterpretCastExprClass;
413 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
415 /// This expression node represents a const cast, e.g.,
416 /// \c const_cast<char*>(PtrToConstChar).
418 /// A const_cast can remove type qualifiers but does not change the underlying
420 class CXXConstCastExpr final
421 : public CXXNamedCastExpr,
422 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
423 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
424 TypeSourceInfo *writtenTy, SourceLocation l,
425 SourceLocation RParenLoc, SourceRange AngleBrackets)
426 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
427 0, writtenTy, l, RParenLoc, AngleBrackets) {}
429 explicit CXXConstCastExpr(EmptyShell Empty)
430 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) {}
433 friend class CastExpr;
434 friend TrailingObjects;
436 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
437 ExprValueKind VK, Expr *Op,
438 TypeSourceInfo *WrittenTy, SourceLocation L,
439 SourceLocation RParenLoc,
440 SourceRange AngleBrackets);
441 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
443 static bool classof(const Stmt *T) {
444 return T->getStmtClass() == CXXConstCastExprClass;
448 /// \brief A call to a literal operator (C++11 [over.literal])
449 /// written as a user-defined literal (C++11 [lit.ext]).
451 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
452 /// is semantically equivalent to a normal call, this AST node provides better
453 /// information about the syntactic representation of the literal.
455 /// Since literal operators are never found by ADL and can only be declared at
456 /// namespace scope, a user-defined literal is never dependent.
457 class UserDefinedLiteral : public CallExpr {
458 /// \brief The location of a ud-suffix within the literal.
459 SourceLocation UDSuffixLoc;
462 friend class ASTStmtReader;
463 friend class ASTStmtWriter;
465 UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
466 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
467 SourceLocation SuffixLoc)
468 : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc),
469 UDSuffixLoc(SuffixLoc) {}
471 explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
472 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
474 /// The kind of literal operator which is invoked.
475 enum LiteralOperatorKind {
476 /// Raw form: operator "" X (const char *)
479 /// Raw form: operator "" X<cs...> ()
482 /// operator "" X (unsigned long long)
485 /// operator "" X (long double)
488 /// operator "" X (const CharT *, size_t)
491 /// operator "" X (CharT)
495 /// \brief Returns the kind of literal operator invocation
496 /// which this expression represents.
497 LiteralOperatorKind getLiteralOperatorKind() const;
499 /// \brief If this is not a raw user-defined literal, get the
500 /// underlying cooked literal (representing the literal with the suffix
502 Expr *getCookedLiteral();
503 const Expr *getCookedLiteral() const {
504 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
507 SourceLocation getLocStart() const {
508 if (getLiteralOperatorKind() == LOK_Template)
509 return getRParenLoc();
510 return getArg(0)->getLocStart();
513 SourceLocation getLocEnd() const { return getRParenLoc(); }
515 /// \brief Returns the location of a ud-suffix in the expression.
517 /// For a string literal, there may be multiple identical suffixes. This
518 /// returns the first.
519 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
521 /// \brief Returns the ud-suffix specified for this literal.
522 const IdentifierInfo *getUDSuffix() const;
524 static bool classof(const Stmt *S) {
525 return S->getStmtClass() == UserDefinedLiteralClass;
529 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
530 class CXXBoolLiteralExpr : public Expr {
535 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l)
536 : Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
538 Value(val), Loc(l) {}
540 explicit CXXBoolLiteralExpr(EmptyShell Empty)
541 : Expr(CXXBoolLiteralExprClass, Empty) {}
543 bool getValue() const { return Value; }
544 void setValue(bool V) { Value = V; }
546 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
547 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
549 SourceLocation getLocation() const { return Loc; }
550 void setLocation(SourceLocation L) { Loc = L; }
552 static bool classof(const Stmt *T) {
553 return T->getStmtClass() == CXXBoolLiteralExprClass;
557 child_range children() {
558 return child_range(child_iterator(), child_iterator());
562 /// \brief The null pointer literal (C++11 [lex.nullptr])
564 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
565 class CXXNullPtrLiteralExpr : public Expr {
569 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l)
570 : Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false,
571 false, false, false),
574 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
575 : Expr(CXXNullPtrLiteralExprClass, Empty) {}
577 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
578 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
580 SourceLocation getLocation() const { return Loc; }
581 void setLocation(SourceLocation L) { Loc = L; }
583 static bool classof(const Stmt *T) {
584 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
587 child_range children() {
588 return child_range(child_iterator(), child_iterator());
592 /// \brief Implicit construction of a std::initializer_list<T> object from an
593 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
594 class CXXStdInitializerListExpr : public Expr {
595 Stmt *SubExpr = nullptr;
597 CXXStdInitializerListExpr(EmptyShell Empty)
598 : Expr(CXXStdInitializerListExprClass, Empty) {}
601 friend class ASTReader;
602 friend class ASTStmtReader;
604 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
605 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
606 Ty->isDependentType(), SubExpr->isValueDependent(),
607 SubExpr->isInstantiationDependent(),
608 SubExpr->containsUnexpandedParameterPack()),
611 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
612 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
614 SourceLocation getLocStart() const LLVM_READONLY {
615 return SubExpr->getLocStart();
618 SourceLocation getLocEnd() const LLVM_READONLY {
619 return SubExpr->getLocEnd();
622 SourceRange getSourceRange() const LLVM_READONLY {
623 return SubExpr->getSourceRange();
626 static bool classof(const Stmt *S) {
627 return S->getStmtClass() == CXXStdInitializerListExprClass;
630 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
633 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
634 /// the \c type_info that corresponds to the supplied type, or the (possibly
635 /// dynamic) type of the supplied expression.
637 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
638 class CXXTypeidExpr : public Expr {
640 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
644 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
645 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
646 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
648 // typeid is value-dependent if the type or expression are
650 Operand->getType()->isDependentType(),
651 Operand->getType()->isInstantiationDependentType(),
652 Operand->getType()->containsUnexpandedParameterPack()),
653 Operand(Operand), Range(R) {}
655 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
656 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
657 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
659 // typeid is value-dependent if the type or expression are
661 Operand->isTypeDependent() || Operand->isValueDependent(),
662 Operand->isInstantiationDependent(),
663 Operand->containsUnexpandedParameterPack()),
664 Operand(Operand), Range(R) {}
666 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
667 : Expr(CXXTypeidExprClass, Empty) {
669 Operand = (Expr*)nullptr;
671 Operand = (TypeSourceInfo*)nullptr;
674 /// Determine whether this typeid has a type operand which is potentially
675 /// evaluated, per C++11 [expr.typeid]p3.
676 bool isPotentiallyEvaluated() const;
678 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
680 /// \brief Retrieves the type operand of this typeid() expression after
681 /// various required adjustments (removing reference types, cv-qualifiers).
682 QualType getTypeOperand(ASTContext &Context) const;
684 /// \brief Retrieve source information for the type operand.
685 TypeSourceInfo *getTypeOperandSourceInfo() const {
686 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
687 return Operand.get<TypeSourceInfo *>();
690 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
691 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
695 Expr *getExprOperand() const {
696 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
697 return static_cast<Expr*>(Operand.get<Stmt *>());
700 void setExprOperand(Expr *E) {
701 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
705 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
706 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
707 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
708 void setSourceRange(SourceRange R) { Range = R; }
710 static bool classof(const Stmt *T) {
711 return T->getStmtClass() == CXXTypeidExprClass;
715 child_range children() {
717 return child_range(child_iterator(), child_iterator());
718 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
719 return child_range(begin, begin + 1);
723 /// \brief A member reference to an MSPropertyDecl.
725 /// This expression always has pseudo-object type, and therefore it is
726 /// typically not encountered in a fully-typechecked expression except
727 /// within the syntactic form of a PseudoObjectExpr.
728 class MSPropertyRefExpr : public Expr {
730 MSPropertyDecl *TheDecl;
731 SourceLocation MemberLoc;
733 NestedNameSpecifierLoc QualifierLoc;
736 friend class ASTStmtReader;
738 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
739 QualType ty, ExprValueKind VK,
740 NestedNameSpecifierLoc qualifierLoc,
741 SourceLocation nameLoc)
742 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
743 /*type-dependent*/ false, baseExpr->isValueDependent(),
744 baseExpr->isInstantiationDependent(),
745 baseExpr->containsUnexpandedParameterPack()),
746 BaseExpr(baseExpr), TheDecl(decl),
747 MemberLoc(nameLoc), IsArrow(isArrow),
748 QualifierLoc(qualifierLoc) {}
750 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
752 SourceRange getSourceRange() const LLVM_READONLY {
753 return SourceRange(getLocStart(), getLocEnd());
756 bool isImplicitAccess() const {
757 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
760 SourceLocation getLocStart() const {
761 if (!isImplicitAccess())
762 return BaseExpr->getLocStart();
763 else if (QualifierLoc)
764 return QualifierLoc.getBeginLoc();
769 SourceLocation getLocEnd() const { return getMemberLoc(); }
771 child_range children() {
772 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
775 static bool classof(const Stmt *T) {
776 return T->getStmtClass() == MSPropertyRefExprClass;
779 Expr *getBaseExpr() const { return BaseExpr; }
780 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
781 bool isArrow() const { return IsArrow; }
782 SourceLocation getMemberLoc() const { return MemberLoc; }
783 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
786 /// MS property subscript expression.
787 /// MSVC supports 'property' attribute and allows to apply it to the
788 /// declaration of an empty array in a class or structure definition.
791 /// __declspec(property(get=GetX, put=PutX)) int x[];
793 /// The above statement indicates that x[] can be used with one or more array
794 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
795 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
796 /// This is a syntactic pseudo-object expression.
797 class MSPropertySubscriptExpr : public Expr {
798 friend class ASTStmtReader;
800 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
802 Stmt *SubExprs[NUM_SUBEXPRS];
803 SourceLocation RBracketLoc;
805 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
806 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
809 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
810 ExprObjectKind OK, SourceLocation RBracketLoc)
811 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
812 Idx->isValueDependent(), Idx->isInstantiationDependent(),
813 Idx->containsUnexpandedParameterPack()),
814 RBracketLoc(RBracketLoc) {
815 SubExprs[BASE_EXPR] = Base;
816 SubExprs[IDX_EXPR] = Idx;
819 /// \brief Create an empty array subscript expression.
820 explicit MSPropertySubscriptExpr(EmptyShell Shell)
821 : Expr(MSPropertySubscriptExprClass, Shell) {}
823 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
824 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
826 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
827 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
829 SourceLocation getLocStart() const LLVM_READONLY {
830 return getBase()->getLocStart();
833 SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
835 SourceLocation getRBracketLoc() const { return RBracketLoc; }
836 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
838 SourceLocation getExprLoc() const LLVM_READONLY {
839 return getBase()->getExprLoc();
842 static bool classof(const Stmt *T) {
843 return T->getStmtClass() == MSPropertySubscriptExprClass;
847 child_range children() {
848 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
852 /// A Microsoft C++ @c __uuidof expression, which gets
853 /// the _GUID that corresponds to the supplied type or expression.
855 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
856 class CXXUuidofExpr : public Expr {
858 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
863 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
865 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
866 Operand->getType()->isDependentType(),
867 Operand->getType()->isInstantiationDependentType(),
868 Operand->getType()->containsUnexpandedParameterPack()),
869 Operand(Operand), UuidStr(UuidStr), Range(R) {}
871 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
872 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
873 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
874 Operand->containsUnexpandedParameterPack()),
875 Operand(Operand), UuidStr(UuidStr), Range(R) {}
877 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
878 : Expr(CXXUuidofExprClass, Empty) {
880 Operand = (Expr*)nullptr;
882 Operand = (TypeSourceInfo*)nullptr;
885 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
887 /// \brief Retrieves the type operand of this __uuidof() expression after
888 /// various required adjustments (removing reference types, cv-qualifiers).
889 QualType getTypeOperand(ASTContext &Context) const;
891 /// \brief Retrieve source information for the type operand.
892 TypeSourceInfo *getTypeOperandSourceInfo() const {
893 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
894 return Operand.get<TypeSourceInfo *>();
897 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
898 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
902 Expr *getExprOperand() const {
903 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
904 return static_cast<Expr*>(Operand.get<Stmt *>());
907 void setExprOperand(Expr *E) {
908 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
912 void setUuidStr(StringRef US) { UuidStr = US; }
913 StringRef getUuidStr() const { return UuidStr; }
915 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
916 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
917 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
918 void setSourceRange(SourceRange R) { Range = R; }
920 static bool classof(const Stmt *T) {
921 return T->getStmtClass() == CXXUuidofExprClass;
925 child_range children() {
927 return child_range(child_iterator(), child_iterator());
928 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
929 return child_range(begin, begin + 1);
933 /// \brief Represents the \c this expression in C++.
935 /// This is a pointer to the object on which the current member function is
936 /// executing (C++ [expr.prim]p3). Example:
942 /// void test() { this->bar(); }
945 class CXXThisExpr : public Expr {
950 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
951 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
952 // 'this' is type-dependent if the class type of the enclosing
953 // member function is dependent (C++ [temp.dep.expr]p2)
954 Type->isDependentType(), Type->isDependentType(),
955 Type->isInstantiationDependentType(),
956 /*ContainsUnexpandedParameterPack=*/false),
957 Loc(L), Implicit(isImplicit) {}
959 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
961 SourceLocation getLocation() const { return Loc; }
962 void setLocation(SourceLocation L) { Loc = L; }
964 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
965 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
967 bool isImplicit() const { return Implicit; }
968 void setImplicit(bool I) { Implicit = I; }
970 static bool classof(const Stmt *T) {
971 return T->getStmtClass() == CXXThisExprClass;
975 child_range children() {
976 return child_range(child_iterator(), child_iterator());
980 /// \brief A C++ throw-expression (C++ [except.throw]).
982 /// This handles 'throw' (for re-throwing the current exception) and
983 /// 'throw' assignment-expression. When assignment-expression isn't
984 /// present, Op will be null.
985 class CXXThrowExpr : public Expr {
986 friend class ASTStmtReader;
989 SourceLocation ThrowLoc;
991 /// \brief Whether the thrown variable (if any) is in scope.
992 unsigned IsThrownVariableInScope : 1;
995 // \p Ty is the void type which is used as the result type of the
996 // expression. The \p l is the location of the throw keyword. \p expr
997 // can by null, if the optional expression to throw isn't present.
998 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
999 bool IsThrownVariableInScope)
1000 : Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
1001 expr && expr->isInstantiationDependent(),
1002 expr && expr->containsUnexpandedParameterPack()),
1003 Op(expr), ThrowLoc(l),
1004 IsThrownVariableInScope(IsThrownVariableInScope) {}
1005 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
1007 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
1008 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
1010 SourceLocation getThrowLoc() const { return ThrowLoc; }
1012 /// \brief Determines whether the variable thrown by this expression (if any!)
1013 /// is within the innermost try block.
1015 /// This information is required to determine whether the NRVO can apply to
1017 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
1019 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
1021 SourceLocation getLocEnd() const LLVM_READONLY {
1024 return getSubExpr()->getLocEnd();
1027 static bool classof(const Stmt *T) {
1028 return T->getStmtClass() == CXXThrowExprClass;
1032 child_range children() {
1033 return child_range(&Op, Op ? &Op+1 : &Op);
1037 /// \brief A default argument (C++ [dcl.fct.default]).
1039 /// This wraps up a function call argument that was created from the
1040 /// corresponding parameter's default argument, when the call did not
1041 /// explicitly supply arguments for all of the parameters.
1042 class CXXDefaultArgExpr final : public Expr {
1043 /// \brief The parameter whose default is being used.
1046 /// \brief The location where the default argument expression was used.
1049 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
1051 param->hasUnparsedDefaultArg()
1052 ? param->getType().getNonReferenceType()
1053 : param->getDefaultArg()->getType(),
1054 param->getDefaultArg()->getValueKind(),
1055 param->getDefaultArg()->getObjectKind(), false, false, false,
1057 Param(param), Loc(Loc) {}
1060 friend class ASTStmtReader;
1061 friend class ASTStmtWriter;
1063 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
1065 // \p Param is the parameter whose default argument is used by this
1067 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1068 ParmVarDecl *Param) {
1069 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
1072 // Retrieve the parameter that the argument was created from.
1073 const ParmVarDecl *getParam() const { return Param; }
1074 ParmVarDecl *getParam() { return Param; }
1076 // Retrieve the actual argument to the function call.
1077 const Expr *getExpr() const {
1078 return getParam()->getDefaultArg();
1081 return getParam()->getDefaultArg();
1084 /// \brief Retrieve the location where this default argument was actually
1086 SourceLocation getUsedLocation() const { return Loc; }
1088 /// Default argument expressions have no representation in the
1089 /// source, so they have an empty source range.
1090 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1091 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1093 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1095 static bool classof(const Stmt *T) {
1096 return T->getStmtClass() == CXXDefaultArgExprClass;
1100 child_range children() {
1101 return child_range(child_iterator(), child_iterator());
1105 /// \brief A use of a default initializer in a constructor or in aggregate
1108 /// This wraps a use of a C++ default initializer (technically,
1109 /// a brace-or-equal-initializer for a non-static data member) when it
1110 /// is implicitly used in a mem-initializer-list in a constructor
1111 /// (C++11 [class.base.init]p8) or in aggregate initialization
1112 /// (C++1y [dcl.init.aggr]p7).
1113 class CXXDefaultInitExpr : public Expr {
1114 /// \brief The field whose default is being used.
1117 /// \brief The location where the default initializer expression was used.
1120 CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
1123 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1126 friend class ASTReader;
1127 friend class ASTStmtReader;
1129 /// \p Field is the non-static data member whose default initializer is used
1130 /// by this expression.
1131 static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
1133 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
1136 /// \brief Get the field whose initializer will be used.
1137 FieldDecl *getField() { return Field; }
1138 const FieldDecl *getField() const { return Field; }
1140 /// \brief Get the initialization expression that will be used.
1141 const Expr *getExpr() const {
1142 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1143 return Field->getInClassInitializer();
1146 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1147 return Field->getInClassInitializer();
1150 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1151 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1153 static bool classof(const Stmt *T) {
1154 return T->getStmtClass() == CXXDefaultInitExprClass;
1158 child_range children() {
1159 return child_range(child_iterator(), child_iterator());
1163 /// \brief Represents a C++ temporary.
1164 class CXXTemporary {
1165 /// \brief The destructor that needs to be called.
1166 const CXXDestructorDecl *Destructor;
1168 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1169 : Destructor(destructor) {}
1172 static CXXTemporary *Create(const ASTContext &C,
1173 const CXXDestructorDecl *Destructor);
1175 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1177 void setDestructor(const CXXDestructorDecl *Dtor) {
1182 /// \brief Represents binding an expression to a temporary.
1184 /// This ensures the destructor is called for the temporary. It should only be
1185 /// needed for non-POD, non-trivially destructable class types. For example:
1189 /// S() { } // User defined constructor makes S non-POD.
1190 /// ~S() { } // User defined destructor makes it non-trivial.
1193 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1196 class CXXBindTemporaryExpr : public Expr {
1197 CXXTemporary *Temp = nullptr;
1198 Stmt *SubExpr = nullptr;
1200 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1201 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1202 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1203 SubExpr->isValueDependent(),
1204 SubExpr->isInstantiationDependent(),
1205 SubExpr->containsUnexpandedParameterPack()),
1206 Temp(temp), SubExpr(SubExpr) {}
1209 CXXBindTemporaryExpr(EmptyShell Empty)
1210 : Expr(CXXBindTemporaryExprClass, Empty) {}
1212 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1215 CXXTemporary *getTemporary() { return Temp; }
1216 const CXXTemporary *getTemporary() const { return Temp; }
1217 void setTemporary(CXXTemporary *T) { Temp = T; }
1219 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1220 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1221 void setSubExpr(Expr *E) { SubExpr = E; }
1223 SourceLocation getLocStart() const LLVM_READONLY {
1224 return SubExpr->getLocStart();
1227 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1229 // Implement isa/cast/dyncast/etc.
1230 static bool classof(const Stmt *T) {
1231 return T->getStmtClass() == CXXBindTemporaryExprClass;
1235 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1238 /// \brief Represents a call to a C++ constructor.
1239 class CXXConstructExpr : public Expr {
1241 enum ConstructionKind {
1249 CXXConstructorDecl *Constructor = nullptr;
1251 SourceRange ParenOrBraceRange;
1252 unsigned NumArgs : 16;
1253 unsigned Elidable : 1;
1254 unsigned HadMultipleCandidates : 1;
1255 unsigned ListInitialization : 1;
1256 unsigned StdInitListInitialization : 1;
1257 unsigned ZeroInitialization : 1;
1258 unsigned ConstructKind : 2;
1259 Stmt **Args = nullptr;
1261 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1264 CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1266 CXXConstructorDecl *Ctor,
1268 ArrayRef<Expr *> Args,
1269 bool HadMultipleCandidates,
1270 bool ListInitialization,
1271 bool StdInitListInitialization,
1272 bool ZeroInitialization,
1273 ConstructionKind ConstructKind,
1274 SourceRange ParenOrBraceRange);
1276 /// \brief Construct an empty C++ construction expression.
1277 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1278 : Expr(SC, Empty), NumArgs(0), Elidable(false),
1279 HadMultipleCandidates(false), ListInitialization(false),
1280 ZeroInitialization(false), ConstructKind(0) {}
1283 friend class ASTStmtReader;
1285 /// \brief Construct an empty C++ construction expression.
1286 explicit CXXConstructExpr(EmptyShell Empty)
1287 : CXXConstructExpr(CXXConstructExprClass, Empty) {}
1289 static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1291 CXXConstructorDecl *Ctor,
1293 ArrayRef<Expr *> Args,
1294 bool HadMultipleCandidates,
1295 bool ListInitialization,
1296 bool StdInitListInitialization,
1297 bool ZeroInitialization,
1298 ConstructionKind ConstructKind,
1299 SourceRange ParenOrBraceRange);
1301 /// \brief Get the constructor that this expression will (ultimately) call.
1302 CXXConstructorDecl *getConstructor() const { return Constructor; }
1304 SourceLocation getLocation() const { return Loc; }
1305 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1307 /// \brief Whether this construction is elidable.
1308 bool isElidable() const { return Elidable; }
1309 void setElidable(bool E) { Elidable = E; }
1311 /// \brief Whether the referred constructor was resolved from
1312 /// an overloaded set having size greater than 1.
1313 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1314 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1316 /// \brief Whether this constructor call was written as list-initialization.
1317 bool isListInitialization() const { return ListInitialization; }
1318 void setListInitialization(bool V) { ListInitialization = V; }
1320 /// \brief Whether this constructor call was written as list-initialization,
1321 /// but was interpreted as forming a std::initializer_list<T> from the list
1322 /// and passing that as a single constructor argument.
1323 /// See C++11 [over.match.list]p1 bullet 1.
1324 bool isStdInitListInitialization() const { return StdInitListInitialization; }
1325 void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1327 /// \brief Whether this construction first requires
1328 /// zero-initialization before the initializer is called.
1329 bool requiresZeroInitialization() const { return ZeroInitialization; }
1330 void setRequiresZeroInitialization(bool ZeroInit) {
1331 ZeroInitialization = ZeroInit;
1334 /// \brief Determine whether this constructor is actually constructing
1335 /// a base class (rather than a complete object).
1336 ConstructionKind getConstructionKind() const {
1337 return (ConstructionKind)ConstructKind;
1339 void setConstructionKind(ConstructionKind CK) {
1343 using arg_iterator = ExprIterator;
1344 using const_arg_iterator = ConstExprIterator;
1345 using arg_range = llvm::iterator_range<arg_iterator>;
1346 using arg_const_range = llvm::iterator_range<const_arg_iterator>;
1348 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1349 arg_const_range arguments() const {
1350 return arg_const_range(arg_begin(), arg_end());
1353 arg_iterator arg_begin() { return Args; }
1354 arg_iterator arg_end() { return Args + NumArgs; }
1355 const_arg_iterator arg_begin() const { return Args; }
1356 const_arg_iterator arg_end() const { return Args + NumArgs; }
1358 Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
1359 const Expr *const *getArgs() const {
1360 return const_cast<CXXConstructExpr *>(this)->getArgs();
1362 unsigned getNumArgs() const { return NumArgs; }
1364 /// \brief Return the specified argument.
1365 Expr *getArg(unsigned Arg) {
1366 assert(Arg < NumArgs && "Arg access out of range!");
1367 return cast<Expr>(Args[Arg]);
1369 const Expr *getArg(unsigned Arg) const {
1370 assert(Arg < NumArgs && "Arg access out of range!");
1371 return cast<Expr>(Args[Arg]);
1374 /// \brief Set the specified argument.
1375 void setArg(unsigned Arg, Expr *ArgExpr) {
1376 assert(Arg < NumArgs && "Arg access out of range!");
1377 Args[Arg] = ArgExpr;
1380 SourceLocation getLocStart() const LLVM_READONLY;
1381 SourceLocation getLocEnd() const LLVM_READONLY;
1382 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1383 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1385 static bool classof(const Stmt *T) {
1386 return T->getStmtClass() == CXXConstructExprClass ||
1387 T->getStmtClass() == CXXTemporaryObjectExprClass;
1391 child_range children() {
1392 return child_range(&Args[0], &Args[0]+NumArgs);
1396 /// \brief Represents a call to an inherited base class constructor from an
1397 /// inheriting constructor. This call implicitly forwards the arguments from
1398 /// the enclosing context (an inheriting constructor) to the specified inherited
1399 /// base class constructor.
1400 class CXXInheritedCtorInitExpr : public Expr {
1402 CXXConstructorDecl *Constructor = nullptr;
1404 /// The location of the using declaration.
1407 /// Whether this is the construction of a virtual base.
1408 unsigned ConstructsVirtualBase : 1;
1410 /// Whether the constructor is inherited from a virtual base class of the
1411 /// class that we construct.
1412 unsigned InheritedFromVirtualBase : 1;
1415 friend class ASTStmtReader;
1417 /// \brief Construct a C++ inheriting construction expression.
1418 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1419 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1420 bool InheritedFromVirtualBase)
1421 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1422 false, false, false),
1423 Constructor(Ctor), Loc(Loc),
1424 ConstructsVirtualBase(ConstructsVirtualBase),
1425 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1426 assert(!T->isDependentType());
1429 /// \brief Construct an empty C++ inheriting construction expression.
1430 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1431 : Expr(CXXInheritedCtorInitExprClass, Empty),
1432 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1434 /// \brief Get the constructor that this expression will call.
1435 CXXConstructorDecl *getConstructor() const { return Constructor; }
1437 /// \brief Determine whether this constructor is actually constructing
1438 /// a base class (rather than a complete object).
1439 bool constructsVBase() const { return ConstructsVirtualBase; }
1440 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1441 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1442 : CXXConstructExpr::CK_NonVirtualBase;
1445 /// \brief Determine whether the inherited constructor is inherited from a
1446 /// virtual base of the object we construct. If so, we are not responsible
1447 /// for calling the inherited constructor (the complete object constructor
1448 /// does that), and so we don't need to pass any arguments.
1449 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1451 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1452 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1453 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1455 static bool classof(const Stmt *T) {
1456 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1459 child_range children() {
1460 return child_range(child_iterator(), child_iterator());
1464 /// \brief Represents an explicit C++ type conversion that uses "functional"
1465 /// notation (C++ [expr.type.conv]).
1471 class CXXFunctionalCastExpr final
1472 : public ExplicitCastExpr,
1473 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1474 SourceLocation LParenLoc;
1475 SourceLocation RParenLoc;
1477 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1478 TypeSourceInfo *writtenTy,
1479 CastKind kind, Expr *castExpr, unsigned pathSize,
1480 SourceLocation lParenLoc, SourceLocation rParenLoc)
1481 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1482 castExpr, pathSize, writtenTy),
1483 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1485 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1486 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) {}
1489 friend class CastExpr;
1490 friend TrailingObjects;
1492 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1494 TypeSourceInfo *Written,
1495 CastKind Kind, Expr *Op,
1496 const CXXCastPath *Path,
1497 SourceLocation LPLoc,
1498 SourceLocation RPLoc);
1499 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1502 SourceLocation getLParenLoc() const { return LParenLoc; }
1503 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1504 SourceLocation getRParenLoc() const { return RParenLoc; }
1505 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1507 SourceLocation getLocStart() const LLVM_READONLY;
1508 SourceLocation getLocEnd() const LLVM_READONLY;
1510 static bool classof(const Stmt *T) {
1511 return T->getStmtClass() == CXXFunctionalCastExprClass;
1515 /// @brief Represents a C++ functional cast expression that builds a
1516 /// temporary object.
1518 /// This expression type represents a C++ "functional" cast
1519 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1520 /// constructor to build a temporary object. With N == 1 arguments the
1521 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1524 /// struct X { X(int, float); }
1527 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1530 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1531 TypeSourceInfo *Type = nullptr;
1534 friend class ASTStmtReader;
1536 CXXTemporaryObjectExpr(const ASTContext &C,
1537 CXXConstructorDecl *Cons,
1539 TypeSourceInfo *TSI,
1540 ArrayRef<Expr *> Args,
1541 SourceRange ParenOrBraceRange,
1542 bool HadMultipleCandidates,
1543 bool ListInitialization,
1544 bool StdInitListInitialization,
1545 bool ZeroInitialization);
1546 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1547 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty) {}
1549 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1551 SourceLocation getLocStart() const LLVM_READONLY;
1552 SourceLocation getLocEnd() const LLVM_READONLY;
1554 static bool classof(const Stmt *T) {
1555 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1559 /// \brief A C++ lambda expression, which produces a function object
1560 /// (of unspecified type) that can be invoked later.
1564 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1565 /// values.erase(std::remove_if(values.begin(), values.end(),
1566 /// [=](double value) { return value > cutoff; });
1570 /// C++11 lambda expressions can capture local variables, either by copying
1571 /// the values of those local variables at the time the function
1572 /// object is constructed (not when it is called!) or by holding a
1573 /// reference to the local variable. These captures can occur either
1574 /// implicitly or can be written explicitly between the square
1575 /// brackets ([...]) that start the lambda expression.
1577 /// C++1y introduces a new form of "capture" called an init-capture that
1578 /// includes an initializing expression (rather than capturing a variable),
1579 /// and which can never occur implicitly.
1580 class LambdaExpr final : public Expr,
1581 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1582 /// \brief The source range that covers the lambda introducer ([...]).
1583 SourceRange IntroducerRange;
1585 /// \brief The source location of this lambda's capture-default ('=' or '&').
1586 SourceLocation CaptureDefaultLoc;
1588 /// \brief The number of captures.
1589 unsigned NumCaptures : 16;
1591 /// \brief The default capture kind, which is a value of type
1592 /// LambdaCaptureDefault.
1593 unsigned CaptureDefault : 2;
1595 /// \brief Whether this lambda had an explicit parameter list vs. an
1596 /// implicit (and empty) parameter list.
1597 unsigned ExplicitParams : 1;
1599 /// \brief Whether this lambda had the result type explicitly specified.
1600 unsigned ExplicitResultType : 1;
1602 /// \brief The location of the closing brace ('}') that completes
1605 /// The location of the brace is also available by looking up the
1606 /// function call operator in the lambda class. However, it is
1607 /// stored here to improve the performance of getSourceRange(), and
1608 /// to avoid having to deserialize the function call operator from a
1609 /// module file just to determine the source range.
1610 SourceLocation ClosingBrace;
1612 /// \brief Construct a lambda expression.
1613 LambdaExpr(QualType T, SourceRange IntroducerRange,
1614 LambdaCaptureDefault CaptureDefault,
1615 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1616 bool ExplicitParams, bool ExplicitResultType,
1617 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1618 bool ContainsUnexpandedParameterPack);
1620 /// \brief Construct an empty lambda expression.
1621 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1622 : Expr(LambdaExprClass, Empty), NumCaptures(NumCaptures),
1623 CaptureDefault(LCD_None), ExplicitParams(false),
1624 ExplicitResultType(false) {
1625 getStoredStmts()[NumCaptures] = nullptr;
1628 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1630 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1633 friend class ASTStmtReader;
1634 friend class ASTStmtWriter;
1635 friend TrailingObjects;
1637 /// \brief Construct a new lambda expression.
1639 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1640 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1641 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1642 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1643 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1645 /// \brief Construct a new lambda expression that will be deserialized from
1646 /// an external source.
1647 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1648 unsigned NumCaptures);
1650 /// \brief Determine the default capture kind for this lambda.
1651 LambdaCaptureDefault getCaptureDefault() const {
1652 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1655 /// \brief Retrieve the location of this lambda's capture-default, if any.
1656 SourceLocation getCaptureDefaultLoc() const {
1657 return CaptureDefaultLoc;
1660 /// \brief Determine whether one of this lambda's captures is an init-capture.
1661 bool isInitCapture(const LambdaCapture *Capture) const;
1663 /// \brief An iterator that walks over the captures of the lambda,
1664 /// both implicit and explicit.
1665 using capture_iterator = const LambdaCapture *;
1667 /// \brief An iterator over a range of lambda captures.
1668 using capture_range = llvm::iterator_range<capture_iterator>;
1670 /// \brief Retrieve this lambda's captures.
1671 capture_range captures() const;
1673 /// \brief Retrieve an iterator pointing to the first lambda capture.
1674 capture_iterator capture_begin() const;
1676 /// \brief Retrieve an iterator pointing past the end of the
1677 /// sequence of lambda captures.
1678 capture_iterator capture_end() const;
1680 /// \brief Determine the number of captures in this lambda.
1681 unsigned capture_size() const { return NumCaptures; }
1683 /// \brief Retrieve this lambda's explicit captures.
1684 capture_range explicit_captures() const;
1686 /// \brief Retrieve an iterator pointing to the first explicit
1688 capture_iterator explicit_capture_begin() const;
1690 /// \brief Retrieve an iterator pointing past the end of the sequence of
1691 /// explicit lambda captures.
1692 capture_iterator explicit_capture_end() const;
1694 /// \brief Retrieve this lambda's implicit captures.
1695 capture_range implicit_captures() const;
1697 /// \brief Retrieve an iterator pointing to the first implicit
1699 capture_iterator implicit_capture_begin() const;
1701 /// \brief Retrieve an iterator pointing past the end of the sequence of
1702 /// implicit lambda captures.
1703 capture_iterator implicit_capture_end() const;
1705 /// \brief Iterator that walks over the capture initialization
1707 using capture_init_iterator = Expr **;
1709 /// \brief Const iterator that walks over the capture initialization
1711 using const_capture_init_iterator = Expr *const *;
1713 /// \brief Retrieve the initialization expressions for this lambda's captures.
1714 llvm::iterator_range<capture_init_iterator> capture_inits() {
1715 return llvm::make_range(capture_init_begin(), capture_init_end());
1718 /// \brief Retrieve the initialization expressions for this lambda's captures.
1719 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1720 return llvm::make_range(capture_init_begin(), capture_init_end());
1723 /// \brief Retrieve the first initialization argument for this
1724 /// lambda expression (which initializes the first capture field).
1725 capture_init_iterator capture_init_begin() {
1726 return reinterpret_cast<Expr **>(getStoredStmts());
1729 /// \brief Retrieve the first initialization argument for this
1730 /// lambda expression (which initializes the first capture field).
1731 const_capture_init_iterator capture_init_begin() const {
1732 return reinterpret_cast<Expr *const *>(getStoredStmts());
1735 /// \brief Retrieve the iterator pointing one past the last
1736 /// initialization argument for this lambda expression.
1737 capture_init_iterator capture_init_end() {
1738 return capture_init_begin() + NumCaptures;
1741 /// \brief Retrieve the iterator pointing one past the last
1742 /// initialization argument for this lambda expression.
1743 const_capture_init_iterator capture_init_end() const {
1744 return capture_init_begin() + NumCaptures;
1747 /// \brief Retrieve the source range covering the lambda introducer,
1748 /// which contains the explicit capture list surrounded by square
1749 /// brackets ([...]).
1750 SourceRange getIntroducerRange() const { return IntroducerRange; }
1752 /// \brief Retrieve the class that corresponds to the lambda.
1754 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1755 /// captures in its fields and provides the various operations permitted
1756 /// on a lambda (copying, calling).
1757 CXXRecordDecl *getLambdaClass() const;
1759 /// \brief Retrieve the function call operator associated with this
1760 /// lambda expression.
1761 CXXMethodDecl *getCallOperator() const;
1763 /// \brief If this is a generic lambda expression, retrieve the template
1764 /// parameter list associated with it, or else return null.
1765 TemplateParameterList *getTemplateParameterList() const;
1767 /// \brief Whether this is a generic lambda.
1768 bool isGenericLambda() const { return getTemplateParameterList(); }
1770 /// \brief Retrieve the body of the lambda.
1771 CompoundStmt *getBody() const;
1773 /// \brief Determine whether the lambda is mutable, meaning that any
1774 /// captures values can be modified.
1775 bool isMutable() const;
1777 /// \brief Determine whether this lambda has an explicit parameter
1778 /// list vs. an implicit (empty) parameter list.
1779 bool hasExplicitParameters() const { return ExplicitParams; }
1781 /// \brief Whether this lambda had its result type explicitly specified.
1782 bool hasExplicitResultType() const { return ExplicitResultType; }
1784 static bool classof(const Stmt *T) {
1785 return T->getStmtClass() == LambdaExprClass;
1788 SourceLocation getLocStart() const LLVM_READONLY {
1789 return IntroducerRange.getBegin();
1792 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1794 child_range children() {
1795 // Includes initialization exprs plus body stmt
1796 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1800 /// An expression "T()" which creates a value-initialized rvalue of type
1801 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
1802 class CXXScalarValueInitExpr : public Expr {
1803 friend class ASTStmtReader;
1805 SourceLocation RParenLoc;
1806 TypeSourceInfo *TypeInfo;
1809 /// \brief Create an explicitly-written scalar-value initialization
1811 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1812 SourceLocation rParenLoc)
1813 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1814 false, false, Type->isInstantiationDependentType(),
1815 Type->containsUnexpandedParameterPack()),
1816 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1818 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1819 : Expr(CXXScalarValueInitExprClass, Shell) {}
1821 TypeSourceInfo *getTypeSourceInfo() const {
1825 SourceLocation getRParenLoc() const { return RParenLoc; }
1827 SourceLocation getLocStart() const LLVM_READONLY;
1828 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1830 static bool classof(const Stmt *T) {
1831 return T->getStmtClass() == CXXScalarValueInitExprClass;
1835 child_range children() {
1836 return child_range(child_iterator(), child_iterator());
1840 /// \brief Represents a new-expression for memory allocation and constructor
1841 /// calls, e.g: "new CXXNewExpr(foo)".
1842 class CXXNewExpr : public Expr {
1843 friend class ASTStmtReader;
1844 friend class ASTStmtWriter;
1846 /// Contains an optional array size expression, an optional initialization
1847 /// expression, and any number of optional placement arguments, in that order.
1848 Stmt **SubExprs = nullptr;
1850 /// \brief Points to the allocation function used.
1851 FunctionDecl *OperatorNew;
1853 /// \brief Points to the deallocation function used in case of error. May be
1855 FunctionDecl *OperatorDelete;
1857 /// \brief The allocated type-source information, as written in the source.
1858 TypeSourceInfo *AllocatedTypeInfo;
1860 /// \brief If the allocated type was expressed as a parenthesized type-id,
1861 /// the source range covering the parenthesized type-id.
1862 SourceRange TypeIdParens;
1864 /// \brief Range of the entire new expression.
1867 /// \brief Source-range of a paren-delimited initializer.
1868 SourceRange DirectInitRange;
1870 /// Was the usage ::new, i.e. is the global new to be used?
1871 unsigned GlobalNew : 1;
1873 /// Do we allocate an array? If so, the first SubExpr is the size expression.
1876 /// Should the alignment be passed to the allocation function?
1877 unsigned PassAlignment : 1;
1879 /// If this is an array allocation, does the usual deallocation
1880 /// function for the allocated type want to know the allocated size?
1881 unsigned UsualArrayDeleteWantsSize : 1;
1883 /// The number of placement new arguments.
1884 unsigned NumPlacementArgs : 26;
1886 /// What kind of initializer do we have? Could be none, parens, or braces.
1887 /// In storage, we distinguish between "none, and no initializer expr", and
1888 /// "none, but an implicit initializer expr".
1889 unsigned StoredInitializationStyle : 2;
1892 enum InitializationStyle {
1893 /// New-expression has no initializer as written.
1896 /// New-expression has a C++98 paren-delimited initializer.
1899 /// New-expression has a C++11 list-initializer.
1903 CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1904 FunctionDecl *operatorDelete, bool PassAlignment,
1905 bool usualArrayDeleteWantsSize, ArrayRef<Expr*> placementArgs,
1906 SourceRange typeIdParens, Expr *arraySize,
1907 InitializationStyle initializationStyle, Expr *initializer,
1908 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1909 SourceRange Range, SourceRange directInitRange);
1910 explicit CXXNewExpr(EmptyShell Shell)
1911 : Expr(CXXNewExprClass, Shell) {}
1913 void AllocateArgsArray(const ASTContext &C, bool isArray,
1914 unsigned numPlaceArgs, bool hasInitializer);
1916 QualType getAllocatedType() const {
1917 assert(getType()->isPointerType());
1918 return getType()->getAs<PointerType>()->getPointeeType();
1921 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1922 return AllocatedTypeInfo;
1925 /// \brief True if the allocation result needs to be null-checked.
1927 /// C++11 [expr.new]p13:
1928 /// If the allocation function returns null, initialization shall
1929 /// not be done, the deallocation function shall not be called,
1930 /// and the value of the new-expression shall be null.
1933 /// If the allocation function is a reserved placement allocation
1934 /// function that returns null, the behavior is undefined.
1936 /// An allocation function is not allowed to return null unless it
1937 /// has a non-throwing exception-specification. The '03 rule is
1938 /// identical except that the definition of a non-throwing
1939 /// exception specification is just "is it throw()?".
1940 bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1942 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1943 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1944 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1945 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1947 bool isArray() const { return Array; }
1949 Expr *getArraySize() {
1950 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1952 const Expr *getArraySize() const {
1953 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1956 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1958 Expr **getPlacementArgs() {
1959 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1962 Expr *getPlacementArg(unsigned i) {
1963 assert(i < NumPlacementArgs && "Index out of range");
1964 return getPlacementArgs()[i];
1966 const Expr *getPlacementArg(unsigned i) const {
1967 assert(i < NumPlacementArgs && "Index out of range");
1968 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1971 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1972 SourceRange getTypeIdParens() const { return TypeIdParens; }
1974 bool isGlobalNew() const { return GlobalNew; }
1976 /// \brief Whether this new-expression has any initializer at all.
1977 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1979 /// \brief The kind of initializer this new-expression has.
1980 InitializationStyle getInitializationStyle() const {
1981 if (StoredInitializationStyle == 0)
1983 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1986 /// \brief The initializer of this new-expression.
1987 Expr *getInitializer() {
1988 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1990 const Expr *getInitializer() const {
1991 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1994 /// \brief Returns the CXXConstructExpr from this new-expression, or null.
1995 const CXXConstructExpr *getConstructExpr() const {
1996 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1999 /// Indicates whether the required alignment should be implicitly passed to
2000 /// the allocation function.
2001 bool passAlignment() const {
2002 return PassAlignment;
2005 /// Answers whether the usual array deallocation function for the
2006 /// allocated type expects the size of the allocation as a
2008 bool doesUsualArrayDeleteWantSize() const {
2009 return UsualArrayDeleteWantsSize;
2012 using arg_iterator = ExprIterator;
2013 using const_arg_iterator = ConstExprIterator;
2015 llvm::iterator_range<arg_iterator> placement_arguments() {
2016 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2019 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
2020 return llvm::make_range(placement_arg_begin(), placement_arg_end());
2023 arg_iterator placement_arg_begin() {
2024 return SubExprs + Array + hasInitializer();
2026 arg_iterator placement_arg_end() {
2027 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
2029 const_arg_iterator placement_arg_begin() const {
2030 return SubExprs + Array + hasInitializer();
2032 const_arg_iterator placement_arg_end() const {
2033 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
2036 using raw_arg_iterator = Stmt **;
2038 raw_arg_iterator raw_arg_begin() { return SubExprs; }
2039 raw_arg_iterator raw_arg_end() {
2040 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
2042 const_arg_iterator raw_arg_begin() const { return SubExprs; }
2043 const_arg_iterator raw_arg_end() const {
2044 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
2047 SourceLocation getStartLoc() const { return Range.getBegin(); }
2048 SourceLocation getEndLoc() const { return Range.getEnd(); }
2050 SourceRange getDirectInitRange() const { return DirectInitRange; }
2052 SourceRange getSourceRange() const LLVM_READONLY {
2056 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
2057 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
2059 static bool classof(const Stmt *T) {
2060 return T->getStmtClass() == CXXNewExprClass;
2064 child_range children() {
2065 return child_range(raw_arg_begin(), raw_arg_end());
2069 /// \brief Represents a \c delete expression for memory deallocation and
2070 /// destructor calls, e.g. "delete[] pArray".
2071 class CXXDeleteExpr : public Expr {
2072 /// Points to the operator delete overload that is used. Could be a member.
2073 FunctionDecl *OperatorDelete = nullptr;
2075 /// The pointer expression to be deleted.
2076 Stmt *Argument = nullptr;
2078 /// Location of the expression.
2081 /// Is this a forced global delete, i.e. "::delete"?
2082 bool GlobalDelete : 1;
2084 /// Is this the array form of delete, i.e. "delete[]"?
2087 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
2088 /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
2090 bool ArrayFormAsWritten : 1;
2092 /// Does the usual deallocation function for the element type require
2093 /// a size_t argument?
2094 bool UsualArrayDeleteWantsSize : 1;
2097 friend class ASTStmtReader;
2099 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
2100 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
2101 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
2102 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
2103 arg->isInstantiationDependent(),
2104 arg->containsUnexpandedParameterPack()),
2105 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
2106 GlobalDelete(globalDelete),
2107 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
2108 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {}
2109 explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {}
2111 bool isGlobalDelete() const { return GlobalDelete; }
2112 bool isArrayForm() const { return ArrayForm; }
2113 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
2115 /// Answers whether the usual array deallocation function for the
2116 /// allocated type expects the size of the allocation as a
2117 /// parameter. This can be true even if the actual deallocation
2118 /// function that we're using doesn't want a size.
2119 bool doesUsualArrayDeleteWantSize() const {
2120 return UsualArrayDeleteWantsSize;
2123 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2125 Expr *getArgument() { return cast<Expr>(Argument); }
2126 const Expr *getArgument() const { return cast<Expr>(Argument); }
2128 /// \brief Retrieve the type being destroyed.
2130 /// If the type being destroyed is a dependent type which may or may not
2131 /// be a pointer, return an invalid type.
2132 QualType getDestroyedType() const;
2134 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2135 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
2137 static bool classof(const Stmt *T) {
2138 return T->getStmtClass() == CXXDeleteExprClass;
2142 child_range children() { return child_range(&Argument, &Argument+1); }
2145 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
2146 class PseudoDestructorTypeStorage {
2147 /// \brief Either the type source information or the name of the type, if
2148 /// it couldn't be resolved due to type-dependence.
2149 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2151 /// \brief The starting source location of the pseudo-destructor type.
2152 SourceLocation Location;
2155 PseudoDestructorTypeStorage() = default;
2157 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2158 : Type(II), Location(Loc) {}
2160 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2162 TypeSourceInfo *getTypeSourceInfo() const {
2163 return Type.dyn_cast<TypeSourceInfo *>();
2166 IdentifierInfo *getIdentifier() const {
2167 return Type.dyn_cast<IdentifierInfo *>();
2170 SourceLocation getLocation() const { return Location; }
2173 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2175 /// A pseudo-destructor is an expression that looks like a member access to a
2176 /// destructor of a scalar type, except that scalar types don't have
2177 /// destructors. For example:
2181 /// void f(int *p) {
2186 /// Pseudo-destructors typically occur when instantiating templates such as:
2189 /// template<typename T>
2190 /// void destroy(T* ptr) {
2195 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2196 /// beyond evaluating the base expression.
2197 class CXXPseudoDestructorExpr : public Expr {
2198 friend class ASTStmtReader;
2200 /// \brief The base expression (that is being destroyed).
2201 Stmt *Base = nullptr;
2203 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
2207 /// \brief The location of the '.' or '->' operator.
2208 SourceLocation OperatorLoc;
2210 /// \brief The nested-name-specifier that follows the operator, if present.
2211 NestedNameSpecifierLoc QualifierLoc;
2213 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
2215 TypeSourceInfo *ScopeType = nullptr;
2217 /// \brief The location of the '::' in a qualified pseudo-destructor
2219 SourceLocation ColonColonLoc;
2221 /// \brief The location of the '~'.
2222 SourceLocation TildeLoc;
2224 /// \brief The type being destroyed, or its name if we were unable to
2225 /// resolve the name.
2226 PseudoDestructorTypeStorage DestroyedType;
2229 CXXPseudoDestructorExpr(const ASTContext &Context,
2230 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2231 NestedNameSpecifierLoc QualifierLoc,
2232 TypeSourceInfo *ScopeType,
2233 SourceLocation ColonColonLoc,
2234 SourceLocation TildeLoc,
2235 PseudoDestructorTypeStorage DestroyedType);
2237 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2238 : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {}
2240 Expr *getBase() const { return cast<Expr>(Base); }
2242 /// \brief Determines whether this member expression actually had
2243 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2245 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2247 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
2248 /// with source-location information.
2249 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2251 /// \brief If the member name was qualified, retrieves the
2252 /// nested-name-specifier that precedes the member name. Otherwise, returns
2254 NestedNameSpecifier *getQualifier() const {
2255 return QualifierLoc.getNestedNameSpecifier();
2258 /// \brief Determine whether this pseudo-destructor expression was written
2259 /// using an '->' (otherwise, it used a '.').
2260 bool isArrow() const { return IsArrow; }
2262 /// \brief Retrieve the location of the '.' or '->' operator.
2263 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2265 /// \brief Retrieve the scope type in a qualified pseudo-destructor
2268 /// Pseudo-destructor expressions can have extra qualification within them
2269 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2270 /// Here, if the object type of the expression is (or may be) a scalar type,
2271 /// \p T may also be a scalar type and, therefore, cannot be part of a
2272 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2273 /// destructor expression.
2274 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2276 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2278 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2280 /// \brief Retrieve the location of the '~'.
2281 SourceLocation getTildeLoc() const { return TildeLoc; }
2283 /// \brief Retrieve the source location information for the type
2284 /// being destroyed.
2286 /// This type-source information is available for non-dependent
2287 /// pseudo-destructor expressions and some dependent pseudo-destructor
2288 /// expressions. Returns null if we only have the identifier for a
2289 /// dependent pseudo-destructor expression.
2290 TypeSourceInfo *getDestroyedTypeInfo() const {
2291 return DestroyedType.getTypeSourceInfo();
2294 /// \brief In a dependent pseudo-destructor expression for which we do not
2295 /// have full type information on the destroyed type, provides the name
2296 /// of the destroyed type.
2297 IdentifierInfo *getDestroyedTypeIdentifier() const {
2298 return DestroyedType.getIdentifier();
2301 /// \brief Retrieve the type being destroyed.
2302 QualType getDestroyedType() const;
2304 /// \brief Retrieve the starting location of the type being destroyed.
2305 SourceLocation getDestroyedTypeLoc() const {
2306 return DestroyedType.getLocation();
2309 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2311 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2312 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2315 /// \brief Set the destroyed type.
2316 void setDestroyedType(TypeSourceInfo *Info) {
2317 DestroyedType = PseudoDestructorTypeStorage(Info);
2320 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2321 SourceLocation getLocEnd() const LLVM_READONLY;
2323 static bool classof(const Stmt *T) {
2324 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2328 child_range children() { return child_range(&Base, &Base + 1); }
2331 /// \brief A type trait used in the implementation of various C++11 and
2332 /// Library TR1 trait templates.
2335 /// __is_pod(int) == true
2336 /// __is_enum(std::string) == false
2337 /// __is_trivially_constructible(vector<int>, int*, int*)
2339 class TypeTraitExpr final
2341 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2342 /// \brief The location of the type trait keyword.
2345 /// \brief The location of the closing parenthesis.
2346 SourceLocation RParenLoc;
2348 // Note: The TypeSourceInfos for the arguments are allocated after the
2351 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2352 ArrayRef<TypeSourceInfo *> Args,
2353 SourceLocation RParenLoc,
2356 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
2358 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2359 return getNumArgs();
2363 friend class ASTStmtReader;
2364 friend class ASTStmtWriter;
2365 friend TrailingObjects;
2367 /// \brief Create a new type trait expression.
2368 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2369 SourceLocation Loc, TypeTrait Kind,
2370 ArrayRef<TypeSourceInfo *> Args,
2371 SourceLocation RParenLoc,
2374 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2377 /// \brief Determine which type trait this expression uses.
2378 TypeTrait getTrait() const {
2379 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2382 bool getValue() const {
2383 assert(!isValueDependent());
2384 return TypeTraitExprBits.Value;
2387 /// \brief Determine the number of arguments to this type trait.
2388 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2390 /// \brief Retrieve the Ith argument.
2391 TypeSourceInfo *getArg(unsigned I) const {
2392 assert(I < getNumArgs() && "Argument out-of-range");
2393 return getArgs()[I];
2396 /// \brief Retrieve the argument types.
2397 ArrayRef<TypeSourceInfo *> getArgs() const {
2398 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2402 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2403 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2405 static bool classof(const Stmt *T) {
2406 return T->getStmtClass() == TypeTraitExprClass;
2410 child_range children() {
2411 return child_range(child_iterator(), child_iterator());
2415 /// \brief An Embarcadero array type trait, as used in the implementation of
2416 /// __array_rank and __array_extent.
2420 /// __array_rank(int[10][20]) == 2
2421 /// __array_extent(int, 1) == 20
2423 class ArrayTypeTraitExpr : public Expr {
2424 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2427 /// \brief The value of the type trait. Unspecified if dependent.
2430 /// \brief The array dimension being queried, or -1 if not used.
2433 /// \brief The location of the type trait keyword.
2436 /// \brief The location of the closing paren.
2437 SourceLocation RParen;
2439 /// \brief The type being queried.
2440 TypeSourceInfo *QueriedType = nullptr;
2442 virtual void anchor();
2445 friend class ASTStmtReader;
2447 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2448 TypeSourceInfo *queried, uint64_t value,
2449 Expr *dimension, SourceLocation rparen, QualType ty)
2450 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2451 false, queried->getType()->isDependentType(),
2452 (queried->getType()->isInstantiationDependentType() ||
2453 (dimension && dimension->isInstantiationDependent())),
2454 queried->getType()->containsUnexpandedParameterPack()),
2455 ATT(att), Value(value), Dimension(dimension),
2456 Loc(loc), RParen(rparen), QueriedType(queried) {}
2458 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2459 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {}
2461 virtual ~ArrayTypeTraitExpr() = default;
2463 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2464 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2466 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2468 QualType getQueriedType() const { return QueriedType->getType(); }
2470 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2472 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2474 Expr *getDimensionExpression() const { return Dimension; }
2476 static bool classof(const Stmt *T) {
2477 return T->getStmtClass() == ArrayTypeTraitExprClass;
2481 child_range children() {
2482 return child_range(child_iterator(), child_iterator());
2486 /// \brief An expression trait intrinsic.
2490 /// __is_lvalue_expr(std::cout) == true
2491 /// __is_lvalue_expr(1) == false
2493 class ExpressionTraitExpr : public Expr {
2494 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2497 /// \brief The value of the type trait. Unspecified if dependent.
2500 /// \brief The location of the type trait keyword.
2503 /// \brief The location of the closing paren.
2504 SourceLocation RParen;
2506 /// \brief The expression being queried.
2507 Expr* QueriedExpression = nullptr;
2510 friend class ASTStmtReader;
2512 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2513 Expr *queried, bool value,
2514 SourceLocation rparen, QualType resultType)
2515 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2516 false, // Not type-dependent
2517 // Value-dependent if the argument is type-dependent.
2518 queried->isTypeDependent(),
2519 queried->isInstantiationDependent(),
2520 queried->containsUnexpandedParameterPack()),
2521 ET(et), Value(value), Loc(loc), RParen(rparen),
2522 QueriedExpression(queried) {}
2524 explicit ExpressionTraitExpr(EmptyShell Empty)
2525 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {}
2527 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2528 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2530 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2532 Expr *getQueriedExpression() const { return QueriedExpression; }
2534 bool getValue() const { return Value; }
2536 static bool classof(const Stmt *T) {
2537 return T->getStmtClass() == ExpressionTraitExprClass;
2541 child_range children() {
2542 return child_range(child_iterator(), child_iterator());
2546 /// \brief A reference to an overloaded function set, either an
2547 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2548 class OverloadExpr : public Expr {
2549 /// \brief The common name of these declarations.
2550 DeclarationNameInfo NameInfo;
2552 /// \brief The nested-name-specifier that qualifies the name, if any.
2553 NestedNameSpecifierLoc QualifierLoc;
2555 /// The results. These are undesugared, which is to say, they may
2556 /// include UsingShadowDecls. Access is relative to the naming
2558 // FIXME: Allocate this data after the OverloadExpr subclass.
2559 DeclAccessPair *Results = nullptr;
2561 unsigned NumResults = 0;
2564 /// \brief Whether the name includes info for explicit template
2565 /// keyword and arguments.
2566 bool HasTemplateKWAndArgsInfo = false;
2568 OverloadExpr(StmtClass K, const ASTContext &C,
2569 NestedNameSpecifierLoc QualifierLoc,
2570 SourceLocation TemplateKWLoc,
2571 const DeclarationNameInfo &NameInfo,
2572 const TemplateArgumentListInfo *TemplateArgs,
2573 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2574 bool KnownDependent,
2575 bool KnownInstantiationDependent,
2576 bool KnownContainsUnexpandedParameterPack);
2578 OverloadExpr(StmtClass K, EmptyShell Empty) : Expr(K, Empty) {}
2580 /// \brief Return the optional template keyword and arguments info.
2581 ASTTemplateKWAndArgsInfo *
2582 getTrailingASTTemplateKWAndArgsInfo(); // defined far below.
2584 /// \brief Return the optional template keyword and arguments info.
2585 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2586 return const_cast<OverloadExpr *>(this)
2587 ->getTrailingASTTemplateKWAndArgsInfo();
2590 /// Return the optional template arguments.
2591 TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); // defined far below
2593 void initializeResults(const ASTContext &C,
2594 UnresolvedSetIterator Begin,
2595 UnresolvedSetIterator End);
2598 friend class ASTStmtReader;
2599 friend class ASTStmtWriter;
2602 OverloadExpr *Expression;
2603 bool IsAddressOfOperand;
2604 bool HasFormOfMemberPointer;
2607 /// \brief Finds the overloaded expression in the given expression \p E of
2610 /// \return the expression (which must be there) and true if it has
2611 /// the particular form of a member pointer expression
2612 static FindResult find(Expr *E) {
2613 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2617 E = E->IgnoreParens();
2618 if (isa<UnaryOperator>(E)) {
2619 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2620 E = cast<UnaryOperator>(E)->getSubExpr();
2621 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2623 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2624 Result.IsAddressOfOperand = true;
2625 Result.Expression = Ovl;
2627 Result.HasFormOfMemberPointer = false;
2628 Result.IsAddressOfOperand = false;
2629 Result.Expression = cast<OverloadExpr>(E);
2635 /// \brief Gets the naming class of this lookup, if any.
2636 CXXRecordDecl *getNamingClass() const;
2638 using decls_iterator = UnresolvedSetImpl::iterator;
2640 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2641 decls_iterator decls_end() const {
2642 return UnresolvedSetIterator(Results + NumResults);
2644 llvm::iterator_range<decls_iterator> decls() const {
2645 return llvm::make_range(decls_begin(), decls_end());
2648 /// \brief Gets the number of declarations in the unresolved set.
2649 unsigned getNumDecls() const { return NumResults; }
2651 /// \brief Gets the full name info.
2652 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2654 /// \brief Gets the name looked up.
2655 DeclarationName getName() const { return NameInfo.getName(); }
2657 /// \brief Gets the location of the name.
2658 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2660 /// \brief Fetches the nested-name qualifier, if one was given.
2661 NestedNameSpecifier *getQualifier() const {
2662 return QualifierLoc.getNestedNameSpecifier();
2665 /// \brief Fetches the nested-name qualifier with source-location
2666 /// information, if one was given.
2667 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2669 /// \brief Retrieve the location of the template keyword preceding
2670 /// this name, if any.
2671 SourceLocation getTemplateKeywordLoc() const {
2672 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2673 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2676 /// \brief Retrieve the location of the left angle bracket starting the
2677 /// explicit template argument list following the name, if any.
2678 SourceLocation getLAngleLoc() const {
2679 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2680 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2683 /// \brief Retrieve the location of the right angle bracket ending the
2684 /// explicit template argument list following the name, if any.
2685 SourceLocation getRAngleLoc() const {
2686 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2687 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2690 /// \brief Determines whether the name was preceded by the template keyword.
2691 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2693 /// \brief Determines whether this expression had explicit template arguments.
2694 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2696 TemplateArgumentLoc const *getTemplateArgs() const {
2697 if (!hasExplicitTemplateArgs())
2699 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2702 unsigned getNumTemplateArgs() const {
2703 if (!hasExplicitTemplateArgs())
2706 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
2709 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2710 return {getTemplateArgs(), getNumTemplateArgs()};
2713 /// \brief Copies the template arguments into the given structure.
2714 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2715 if (hasExplicitTemplateArgs())
2716 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
2719 static bool classof(const Stmt *T) {
2720 return T->getStmtClass() == UnresolvedLookupExprClass ||
2721 T->getStmtClass() == UnresolvedMemberExprClass;
2725 /// \brief A reference to a name which we were able to look up during
2726 /// parsing but could not resolve to a specific declaration.
2728 /// This arises in several ways:
2729 /// * we might be waiting for argument-dependent lookup;
2730 /// * the name might resolve to an overloaded function;
2732 /// * the lookup might have included a function template.
2734 /// These never include UnresolvedUsingValueDecls, which are always class
2735 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2736 class UnresolvedLookupExpr final
2737 : public OverloadExpr,
2738 private llvm::TrailingObjects<
2739 UnresolvedLookupExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
2740 friend class ASTStmtReader;
2741 friend class OverloadExpr;
2742 friend TrailingObjects;
2744 /// True if these lookup results should be extended by
2745 /// argument-dependent lookup if this is the operand of a function
2747 bool RequiresADL = false;
2749 /// True if these lookup results are overloaded. This is pretty
2750 /// trivially rederivable if we urgently need to kill this field.
2751 bool Overloaded = false;
2753 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2754 /// any. This can generally be recalculated from the context chain,
2755 /// but that can be fairly expensive for unqualified lookups. If we
2756 /// want to improve memory use here, this could go in a union
2757 /// against the qualified-lookup bits.
2758 CXXRecordDecl *NamingClass = nullptr;
2760 UnresolvedLookupExpr(const ASTContext &C,
2761 CXXRecordDecl *NamingClass,
2762 NestedNameSpecifierLoc QualifierLoc,
2763 SourceLocation TemplateKWLoc,
2764 const DeclarationNameInfo &NameInfo,
2765 bool RequiresADL, bool Overloaded,
2766 const TemplateArgumentListInfo *TemplateArgs,
2767 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2768 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2769 NameInfo, TemplateArgs, Begin, End, false, false, false),
2770 RequiresADL(RequiresADL),
2771 Overloaded(Overloaded), NamingClass(NamingClass) {}
2773 UnresolvedLookupExpr(EmptyShell Empty)
2774 : OverloadExpr(UnresolvedLookupExprClass, Empty) {}
2776 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2777 return HasTemplateKWAndArgsInfo ? 1 : 0;
2781 static UnresolvedLookupExpr *Create(const ASTContext &C,
2782 CXXRecordDecl *NamingClass,
2783 NestedNameSpecifierLoc QualifierLoc,
2784 const DeclarationNameInfo &NameInfo,
2785 bool ADL, bool Overloaded,
2786 UnresolvedSetIterator Begin,
2787 UnresolvedSetIterator End) {
2788 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2789 SourceLocation(), NameInfo,
2790 ADL, Overloaded, nullptr, Begin, End);
2793 static UnresolvedLookupExpr *Create(const ASTContext &C,
2794 CXXRecordDecl *NamingClass,
2795 NestedNameSpecifierLoc QualifierLoc,
2796 SourceLocation TemplateKWLoc,
2797 const DeclarationNameInfo &NameInfo,
2799 const TemplateArgumentListInfo *Args,
2800 UnresolvedSetIterator Begin,
2801 UnresolvedSetIterator End);
2803 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2804 bool HasTemplateKWAndArgsInfo,
2805 unsigned NumTemplateArgs);
2807 /// True if this declaration should be extended by
2808 /// argument-dependent lookup.
2809 bool requiresADL() const { return RequiresADL; }
2811 /// True if this lookup is overloaded.
2812 bool isOverloaded() const { return Overloaded; }
2814 /// Gets the 'naming class' (in the sense of C++0x
2815 /// [class.access.base]p5) of the lookup. This is the scope
2816 /// that was looked in to find these results.
2817 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2819 SourceLocation getLocStart() const LLVM_READONLY {
2820 if (NestedNameSpecifierLoc l = getQualifierLoc())
2821 return l.getBeginLoc();
2822 return getNameInfo().getLocStart();
2825 SourceLocation getLocEnd() const LLVM_READONLY {
2826 if (hasExplicitTemplateArgs())
2827 return getRAngleLoc();
2828 return getNameInfo().getLocEnd();
2831 child_range children() {
2832 return child_range(child_iterator(), child_iterator());
2835 static bool classof(const Stmt *T) {
2836 return T->getStmtClass() == UnresolvedLookupExprClass;
2840 /// \brief A qualified reference to a name whose declaration cannot
2841 /// yet be resolved.
2843 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2844 /// it expresses a reference to a declaration such as
2845 /// X<T>::value. The difference, however, is that an
2846 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2847 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2848 /// this case, X<T>::value cannot resolve to a declaration because the
2849 /// declaration will differ from one instantiation of X<T> to the
2850 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2851 /// qualifier (X<T>::) and the name of the entity being referenced
2852 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2853 /// declaration can be found.
2854 class DependentScopeDeclRefExpr final
2856 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
2857 ASTTemplateKWAndArgsInfo,
2858 TemplateArgumentLoc> {
2859 /// \brief The nested-name-specifier that qualifies this unresolved
2860 /// declaration name.
2861 NestedNameSpecifierLoc QualifierLoc;
2863 /// \brief The name of the entity we will be referencing.
2864 DeclarationNameInfo NameInfo;
2866 /// \brief Whether the name includes info for explicit template
2867 /// keyword and arguments.
2868 bool HasTemplateKWAndArgsInfo;
2870 DependentScopeDeclRefExpr(QualType T,
2871 NestedNameSpecifierLoc QualifierLoc,
2872 SourceLocation TemplateKWLoc,
2873 const DeclarationNameInfo &NameInfo,
2874 const TemplateArgumentListInfo *Args);
2876 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2877 return HasTemplateKWAndArgsInfo ? 1 : 0;
2881 friend class ASTStmtReader;
2882 friend class ASTStmtWriter;
2883 friend TrailingObjects;
2885 static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2886 NestedNameSpecifierLoc QualifierLoc,
2887 SourceLocation TemplateKWLoc,
2888 const DeclarationNameInfo &NameInfo,
2889 const TemplateArgumentListInfo *TemplateArgs);
2891 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2892 bool HasTemplateKWAndArgsInfo,
2893 unsigned NumTemplateArgs);
2895 /// \brief Retrieve the name that this expression refers to.
2896 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2898 /// \brief Retrieve the name that this expression refers to.
2899 DeclarationName getDeclName() const { return NameInfo.getName(); }
2901 /// \brief Retrieve the location of the name within the expression.
2903 /// For example, in "X<T>::value" this is the location of "value".
2904 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2906 /// \brief Retrieve the nested-name-specifier that qualifies the
2907 /// name, with source location information.
2908 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2910 /// \brief Retrieve the nested-name-specifier that qualifies this
2912 NestedNameSpecifier *getQualifier() const {
2913 return QualifierLoc.getNestedNameSpecifier();
2916 /// \brief Retrieve the location of the template keyword preceding
2917 /// this name, if any.
2918 SourceLocation getTemplateKeywordLoc() const {
2919 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2920 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2923 /// \brief Retrieve the location of the left angle bracket starting the
2924 /// explicit template argument list following the name, if any.
2925 SourceLocation getLAngleLoc() const {
2926 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2927 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2930 /// \brief Retrieve the location of the right angle bracket ending the
2931 /// explicit template argument list following the name, if any.
2932 SourceLocation getRAngleLoc() const {
2933 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2934 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2937 /// Determines whether the name was preceded by the template keyword.
2938 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2940 /// Determines whether this lookup had explicit template arguments.
2941 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2943 /// \brief Copies the template arguments (if present) into the given
2945 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2946 if (hasExplicitTemplateArgs())
2947 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2948 getTrailingObjects<TemplateArgumentLoc>(), List);
2951 TemplateArgumentLoc const *getTemplateArgs() const {
2952 if (!hasExplicitTemplateArgs())
2955 return getTrailingObjects<TemplateArgumentLoc>();
2958 unsigned getNumTemplateArgs() const {
2959 if (!hasExplicitTemplateArgs())
2962 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2965 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2966 return {getTemplateArgs(), getNumTemplateArgs()};
2969 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2970 /// and differs from getLocation().getStart().
2971 SourceLocation getLocStart() const LLVM_READONLY {
2972 return QualifierLoc.getBeginLoc();
2975 SourceLocation getLocEnd() const LLVM_READONLY {
2976 if (hasExplicitTemplateArgs())
2977 return getRAngleLoc();
2978 return getLocation();
2981 static bool classof(const Stmt *T) {
2982 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2985 child_range children() {
2986 return child_range(child_iterator(), child_iterator());
2990 /// Represents an expression -- generally a full-expression -- that
2991 /// introduces cleanups to be run at the end of the sub-expression's
2992 /// evaluation. The most common source of expression-introduced
2993 /// cleanups is temporary objects in C++, but several other kinds of
2994 /// expressions can create cleanups, including basically every
2995 /// call in ARC that returns an Objective-C pointer.
2997 /// This expression also tracks whether the sub-expression contains a
2998 /// potentially-evaluated block literal. The lifetime of a block
2999 /// literal is the extent of the enclosing scope.
3000 class ExprWithCleanups final
3002 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
3004 /// The type of objects that are kept in the cleanup.
3005 /// It's useful to remember the set of blocks; we could also
3006 /// remember the set of temporaries, but there's currently
3008 using CleanupObject = BlockDecl *;
3011 friend class ASTStmtReader;
3012 friend TrailingObjects;
3016 ExprWithCleanups(EmptyShell, unsigned NumObjects);
3017 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
3018 ArrayRef<CleanupObject> Objects);
3021 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
3022 unsigned numObjects);
3024 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
3025 bool CleanupsHaveSideEffects,
3026 ArrayRef<CleanupObject> objects);
3028 ArrayRef<CleanupObject> getObjects() const {
3029 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
3033 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
3035 CleanupObject getObject(unsigned i) const {
3036 assert(i < getNumObjects() && "Index out of range");
3037 return getObjects()[i];
3040 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
3041 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
3043 bool cleanupsHaveSideEffects() const {
3044 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
3047 /// As with any mutator of the AST, be very careful
3048 /// when modifying an existing AST to preserve its invariants.
3049 void setSubExpr(Expr *E) { SubExpr = E; }
3051 SourceLocation getLocStart() const LLVM_READONLY {
3052 return SubExpr->getLocStart();
3055 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
3057 // Implement isa/cast/dyncast/etc.
3058 static bool classof(const Stmt *T) {
3059 return T->getStmtClass() == ExprWithCleanupsClass;
3063 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
3066 /// \brief Describes an explicit type conversion that uses functional
3067 /// notion but could not be resolved because one or more arguments are
3070 /// The explicit type conversions expressed by
3071 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
3072 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
3073 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
3074 /// type-dependent. For example, this would occur in a template such
3078 /// template<typename T, typename A1>
3079 /// inline T make_a(const A1& a1) {
3084 /// When the returned expression is instantiated, it may resolve to a
3085 /// constructor call, conversion function call, or some kind of type
3087 class CXXUnresolvedConstructExpr final
3089 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3090 friend class ASTStmtReader;
3091 friend TrailingObjects;
3093 /// \brief The type being constructed.
3094 TypeSourceInfo *Type = nullptr;
3096 /// \brief The location of the left parentheses ('(').
3097 SourceLocation LParenLoc;
3099 /// \brief The location of the right parentheses (')').
3100 SourceLocation RParenLoc;
3102 /// \brief The number of arguments used to construct the type.
3105 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
3106 SourceLocation LParenLoc,
3107 ArrayRef<Expr*> Args,
3108 SourceLocation RParenLoc);
3110 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3111 : Expr(CXXUnresolvedConstructExprClass, Empty), NumArgs(NumArgs) {}
3114 static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
3115 TypeSourceInfo *Type,
3116 SourceLocation LParenLoc,
3117 ArrayRef<Expr*> Args,
3118 SourceLocation RParenLoc);
3120 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
3123 /// \brief Retrieve the type that is being constructed, as specified
3124 /// in the source code.
3125 QualType getTypeAsWritten() const { return Type->getType(); }
3127 /// \brief Retrieve the type source information for the type being
3129 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
3131 /// \brief Retrieve the location of the left parentheses ('(') that
3132 /// precedes the argument list.
3133 SourceLocation getLParenLoc() const { return LParenLoc; }
3134 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3136 /// \brief Retrieve the location of the right parentheses (')') that
3137 /// follows the argument list.
3138 SourceLocation getRParenLoc() const { return RParenLoc; }
3139 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3141 /// Determine whether this expression models list-initialization.
3142 /// If so, there will be exactly one subexpression, which will be
3143 /// an InitListExpr.
3144 bool isListInitialization() const { return LParenLoc.isInvalid(); }
3146 /// \brief Retrieve the number of arguments.
3147 unsigned arg_size() const { return NumArgs; }
3149 using arg_iterator = Expr **;
3151 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3152 arg_iterator arg_end() { return arg_begin() + NumArgs; }
3154 using const_arg_iterator = const Expr* const *;
3156 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3157 const_arg_iterator arg_end() const {
3158 return arg_begin() + NumArgs;
3161 Expr *getArg(unsigned I) {
3162 assert(I < NumArgs && "Argument index out-of-range");
3163 return *(arg_begin() + I);
3166 const Expr *getArg(unsigned I) const {
3167 assert(I < NumArgs && "Argument index out-of-range");
3168 return *(arg_begin() + I);
3171 void setArg(unsigned I, Expr *E) {
3172 assert(I < NumArgs && "Argument index out-of-range");
3173 *(arg_begin() + I) = E;
3176 SourceLocation getLocStart() const LLVM_READONLY;
3178 SourceLocation getLocEnd() const LLVM_READONLY {
3179 if (!RParenLoc.isValid() && NumArgs > 0)
3180 return getArg(NumArgs - 1)->getLocEnd();
3184 static bool classof(const Stmt *T) {
3185 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3189 child_range children() {
3190 Stmt **begin = reinterpret_cast<Stmt **>(arg_begin());
3191 return child_range(begin, begin + NumArgs);
3195 /// \brief Represents a C++ member access expression where the actual
3196 /// member referenced could not be resolved because the base
3197 /// expression or the member name was dependent.
3199 /// Like UnresolvedMemberExprs, these can be either implicit or
3200 /// explicit accesses. It is only possible to get one of these with
3201 /// an implicit access if a qualifier is provided.
3202 class CXXDependentScopeMemberExpr final
3204 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3205 ASTTemplateKWAndArgsInfo,
3206 TemplateArgumentLoc> {
3207 /// \brief The expression for the base pointer or class reference,
3208 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3211 /// \brief The type of the base expression. Never null, even for
3212 /// implicit accesses.
3215 /// \brief Whether this member expression used the '->' operator or
3216 /// the '.' operator.
3219 /// \brief Whether this member expression has info for explicit template
3220 /// keyword and arguments.
3221 bool HasTemplateKWAndArgsInfo : 1;
3223 /// \brief The location of the '->' or '.' operator.
3224 SourceLocation OperatorLoc;
3226 /// \brief The nested-name-specifier that precedes the member name, if any.
3227 NestedNameSpecifierLoc QualifierLoc;
3229 /// \brief In a qualified member access expression such as t->Base::f, this
3230 /// member stores the resolves of name lookup in the context of the member
3231 /// access expression, to be used at instantiation time.
3233 /// FIXME: This member, along with the QualifierLoc, could
3234 /// be stuck into a structure that is optionally allocated at the end of
3235 /// the CXXDependentScopeMemberExpr, to save space in the common case.
3236 NamedDecl *FirstQualifierFoundInScope;
3238 /// \brief The member to which this member expression refers, which
3239 /// can be name, overloaded operator, or destructor.
3241 /// FIXME: could also be a template-id
3242 DeclarationNameInfo MemberNameInfo;
3244 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3245 return HasTemplateKWAndArgsInfo ? 1 : 0;
3248 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3249 QualType BaseType, bool IsArrow,
3250 SourceLocation OperatorLoc,
3251 NestedNameSpecifierLoc QualifierLoc,
3252 SourceLocation TemplateKWLoc,
3253 NamedDecl *FirstQualifierFoundInScope,
3254 DeclarationNameInfo MemberNameInfo,
3255 const TemplateArgumentListInfo *TemplateArgs);
3258 friend class ASTStmtReader;
3259 friend class ASTStmtWriter;
3260 friend TrailingObjects;
3262 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3263 QualType BaseType, bool IsArrow,
3264 SourceLocation OperatorLoc,
3265 NestedNameSpecifierLoc QualifierLoc,
3266 NamedDecl *FirstQualifierFoundInScope,
3267 DeclarationNameInfo MemberNameInfo);
3269 static CXXDependentScopeMemberExpr *
3270 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3271 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3272 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3273 DeclarationNameInfo MemberNameInfo,
3274 const TemplateArgumentListInfo *TemplateArgs);
3276 static CXXDependentScopeMemberExpr *
3277 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3278 unsigned NumTemplateArgs);
3280 /// \brief True if this is an implicit access, i.e. one in which the
3281 /// member being accessed was not written in the source. The source
3282 /// location of the operator is invalid in this case.
3283 bool isImplicitAccess() const;
3285 /// \brief Retrieve the base object of this member expressions,
3286 /// e.g., the \c x in \c x.m.
3287 Expr *getBase() const {
3288 assert(!isImplicitAccess());
3289 return cast<Expr>(Base);
3292 QualType getBaseType() const { return BaseType; }
3294 /// \brief Determine whether this member expression used the '->'
3295 /// operator; otherwise, it used the '.' operator.
3296 bool isArrow() const { return IsArrow; }
3298 /// \brief Retrieve the location of the '->' or '.' operator.
3299 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3301 /// \brief Retrieve the nested-name-specifier that qualifies the member
3303 NestedNameSpecifier *getQualifier() const {
3304 return QualifierLoc.getNestedNameSpecifier();
3307 /// \brief Retrieve the nested-name-specifier that qualifies the member
3308 /// name, with source location information.
3309 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3311 /// \brief Retrieve the first part of the nested-name-specifier that was
3312 /// found in the scope of the member access expression when the member access
3313 /// was initially parsed.
3315 /// This function only returns a useful result when member access expression
3316 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3317 /// returned by this function describes what was found by unqualified name
3318 /// lookup for the identifier "Base" within the scope of the member access
3319 /// expression itself. At template instantiation time, this information is
3320 /// combined with the results of name lookup into the type of the object
3321 /// expression itself (the class type of x).
3322 NamedDecl *getFirstQualifierFoundInScope() const {
3323 return FirstQualifierFoundInScope;
3326 /// \brief Retrieve the name of the member that this expression
3328 const DeclarationNameInfo &getMemberNameInfo() const {
3329 return MemberNameInfo;
3332 /// \brief Retrieve the name of the member that this expression
3334 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3336 // \brief Retrieve the location of the name of the member that this
3337 // expression refers to.
3338 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3340 /// \brief Retrieve the location of the template keyword preceding the
3341 /// member name, if any.
3342 SourceLocation getTemplateKeywordLoc() const {
3343 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3344 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3347 /// \brief Retrieve the location of the left angle bracket starting the
3348 /// explicit template argument list following the member name, if any.
3349 SourceLocation getLAngleLoc() const {
3350 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3351 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3354 /// \brief Retrieve the location of the right angle bracket ending the
3355 /// explicit template argument list following the member name, if any.
3356 SourceLocation getRAngleLoc() const {
3357 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3358 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3361 /// Determines whether the member name was preceded by the template keyword.
3362 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3364 /// \brief Determines whether this member expression actually had a C++
3365 /// template argument list explicitly specified, e.g., x.f<int>.
3366 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3368 /// \brief Copies the template arguments (if present) into the given
3370 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3371 if (hasExplicitTemplateArgs())
3372 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3373 getTrailingObjects<TemplateArgumentLoc>(), List);
3376 /// \brief Retrieve the template arguments provided as part of this
3378 const TemplateArgumentLoc *getTemplateArgs() const {
3379 if (!hasExplicitTemplateArgs())
3382 return getTrailingObjects<TemplateArgumentLoc>();
3385 /// \brief Retrieve the number of template arguments provided as part of this
3387 unsigned getNumTemplateArgs() const {
3388 if (!hasExplicitTemplateArgs())
3391 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3394 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3395 return {getTemplateArgs(), getNumTemplateArgs()};
3398 SourceLocation getLocStart() const LLVM_READONLY {
3399 if (!isImplicitAccess())
3400 return Base->getLocStart();
3402 return getQualifierLoc().getBeginLoc();
3403 return MemberNameInfo.getBeginLoc();
3406 SourceLocation getLocEnd() const LLVM_READONLY {
3407 if (hasExplicitTemplateArgs())
3408 return getRAngleLoc();
3409 return MemberNameInfo.getEndLoc();
3412 static bool classof(const Stmt *T) {
3413 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3417 child_range children() {
3418 if (isImplicitAccess())
3419 return child_range(child_iterator(), child_iterator());
3420 return child_range(&Base, &Base + 1);
3424 /// \brief Represents a C++ member access expression for which lookup
3425 /// produced a set of overloaded functions.
3427 /// The member access may be explicit or implicit:
3431 /// int explicitAccess() { return this->a + this->A::b; }
3432 /// int implicitAccess() { return a + A::b; }
3436 /// In the final AST, an explicit access always becomes a MemberExpr.
3437 /// An implicit access may become either a MemberExpr or a
3438 /// DeclRefExpr, depending on whether the member is static.
3439 class UnresolvedMemberExpr final
3440 : public OverloadExpr,
3441 private llvm::TrailingObjects<
3442 UnresolvedMemberExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
3443 friend class ASTStmtReader;
3444 friend class OverloadExpr;
3445 friend TrailingObjects;
3447 /// \brief Whether this member expression used the '->' operator or
3448 /// the '.' operator.
3451 /// \brief Whether the lookup results contain an unresolved using
3453 bool HasUnresolvedUsing : 1;
3455 /// \brief The expression for the base pointer or class reference,
3456 /// e.g., the \c x in x.f.
3458 /// This can be null if this is an 'unbased' member expression.
3459 Stmt *Base = nullptr;
3461 /// \brief The type of the base expression; never null.
3464 /// \brief The location of the '->' or '.' operator.
3465 SourceLocation OperatorLoc;
3467 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3468 Expr *Base, QualType BaseType, bool IsArrow,
3469 SourceLocation OperatorLoc,
3470 NestedNameSpecifierLoc QualifierLoc,
3471 SourceLocation TemplateKWLoc,
3472 const DeclarationNameInfo &MemberNameInfo,
3473 const TemplateArgumentListInfo *TemplateArgs,
3474 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3476 UnresolvedMemberExpr(EmptyShell Empty)
3477 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3478 HasUnresolvedUsing(false) {}
3480 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3481 return HasTemplateKWAndArgsInfo ? 1 : 0;
3485 static UnresolvedMemberExpr *
3486 Create(const ASTContext &C, bool HasUnresolvedUsing,
3487 Expr *Base, QualType BaseType, bool IsArrow,
3488 SourceLocation OperatorLoc,
3489 NestedNameSpecifierLoc QualifierLoc,
3490 SourceLocation TemplateKWLoc,
3491 const DeclarationNameInfo &MemberNameInfo,
3492 const TemplateArgumentListInfo *TemplateArgs,
3493 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3495 static UnresolvedMemberExpr *
3496 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3497 unsigned NumTemplateArgs);
3499 /// \brief True if this is an implicit access, i.e., one in which the
3500 /// member being accessed was not written in the source.
3502 /// The source location of the operator is invalid in this case.
3503 bool isImplicitAccess() const;
3505 /// \brief Retrieve the base object of this member expressions,
3506 /// e.g., the \c x in \c x.m.
3508 assert(!isImplicitAccess());
3509 return cast<Expr>(Base);
3511 const Expr *getBase() const {
3512 assert(!isImplicitAccess());
3513 return cast<Expr>(Base);
3516 QualType getBaseType() const { return BaseType; }
3518 /// \brief Determine whether the lookup results contain an unresolved using
3520 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3522 /// \brief Determine whether this member expression used the '->'
3523 /// operator; otherwise, it used the '.' operator.
3524 bool isArrow() const { return IsArrow; }
3526 /// \brief Retrieve the location of the '->' or '.' operator.
3527 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3529 /// \brief Retrieve the naming class of this lookup.
3530 CXXRecordDecl *getNamingClass() const;
3532 /// \brief Retrieve the full name info for the member that this expression
3534 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3536 /// \brief Retrieve the name of the member that this expression
3538 DeclarationName getMemberName() const { return getName(); }
3540 // \brief Retrieve the location of the name of the member that this
3541 // expression refers to.
3542 SourceLocation getMemberLoc() const { return getNameLoc(); }
3544 // \brief Return the preferred location (the member name) for the arrow when
3545 // diagnosing a problem with this expression.
3546 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3548 SourceLocation getLocStart() const LLVM_READONLY {
3549 if (!isImplicitAccess())
3550 return Base->getLocStart();
3551 if (NestedNameSpecifierLoc l = getQualifierLoc())
3552 return l.getBeginLoc();
3553 return getMemberNameInfo().getLocStart();
3556 SourceLocation getLocEnd() const LLVM_READONLY {
3557 if (hasExplicitTemplateArgs())
3558 return getRAngleLoc();
3559 return getMemberNameInfo().getLocEnd();
3562 static bool classof(const Stmt *T) {
3563 return T->getStmtClass() == UnresolvedMemberExprClass;
3567 child_range children() {
3568 if (isImplicitAccess())
3569 return child_range(child_iterator(), child_iterator());
3570 return child_range(&Base, &Base + 1);
3574 inline ASTTemplateKWAndArgsInfo *
3575 OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3576 if (!HasTemplateKWAndArgsInfo)
3579 if (isa<UnresolvedLookupExpr>(this))
3580 return cast<UnresolvedLookupExpr>(this)
3581 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3583 return cast<UnresolvedMemberExpr>(this)
3584 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3587 inline TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3588 if (isa<UnresolvedLookupExpr>(this))
3589 return cast<UnresolvedLookupExpr>(this)
3590 ->getTrailingObjects<TemplateArgumentLoc>();
3592 return cast<UnresolvedMemberExpr>(this)
3593 ->getTrailingObjects<TemplateArgumentLoc>();
3596 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3598 /// The noexcept expression tests whether a given expression might throw. Its
3599 /// result is a boolean constant.
3600 class CXXNoexceptExpr : public Expr {
3601 friend class ASTStmtReader;
3608 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3609 SourceLocation Keyword, SourceLocation RParen)
3610 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3611 /*TypeDependent*/false,
3612 /*ValueDependent*/Val == CT_Dependent,
3613 Val == CT_Dependent || Operand->isInstantiationDependent(),
3614 Operand->containsUnexpandedParameterPack()),
3615 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) {}
3617 CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
3619 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3621 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
3622 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3623 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3625 bool getValue() const { return Value; }
3627 static bool classof(const Stmt *T) {
3628 return T->getStmtClass() == CXXNoexceptExprClass;
3632 child_range children() { return child_range(&Operand, &Operand + 1); }
3635 /// \brief Represents a C++11 pack expansion that produces a sequence of
3638 /// A pack expansion expression contains a pattern (which itself is an
3639 /// expression) followed by an ellipsis. For example:
3642 /// template<typename F, typename ...Types>
3643 /// void forward(F f, Types &&...args) {
3644 /// f(static_cast<Types&&>(args)...);
3648 /// Here, the argument to the function object \c f is a pack expansion whose
3649 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3650 /// template is instantiated, the pack expansion will instantiate to zero or
3651 /// or more function arguments to the function object \c f.
3652 class PackExpansionExpr : public Expr {
3653 friend class ASTStmtReader;
3654 friend class ASTStmtWriter;
3656 SourceLocation EllipsisLoc;
3658 /// \brief The number of expansions that will be produced by this pack
3659 /// expansion expression, if known.
3661 /// When zero, the number of expansions is not known. Otherwise, this value
3662 /// is the number of expansions + 1.
3663 unsigned NumExpansions;
3668 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3669 Optional<unsigned> NumExpansions)
3670 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3671 Pattern->getObjectKind(), /*TypeDependent=*/true,
3672 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3673 /*ContainsUnexpandedParameterPack=*/false),
3674 EllipsisLoc(EllipsisLoc),
3675 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
3678 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {}
3680 /// \brief Retrieve the pattern of the pack expansion.
3681 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3683 /// \brief Retrieve the pattern of the pack expansion.
3684 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3686 /// \brief Retrieve the location of the ellipsis that describes this pack
3688 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3690 /// \brief Determine the number of expansions that will be produced when
3691 /// this pack expansion is instantiated, if already known.
3692 Optional<unsigned> getNumExpansions() const {
3694 return NumExpansions - 1;
3699 SourceLocation getLocStart() const LLVM_READONLY {
3700 return Pattern->getLocStart();
3703 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3705 static bool classof(const Stmt *T) {
3706 return T->getStmtClass() == PackExpansionExprClass;
3710 child_range children() {
3711 return child_range(&Pattern, &Pattern + 1);
3715 /// \brief Represents an expression that computes the length of a parameter
3719 /// template<typename ...Types>
3721 /// static const unsigned value = sizeof...(Types);
3724 class SizeOfPackExpr final
3726 private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
3727 friend class ASTStmtReader;
3728 friend class ASTStmtWriter;
3729 friend TrailingObjects;
3731 /// \brief The location of the \c sizeof keyword.
3732 SourceLocation OperatorLoc;
3734 /// \brief The location of the name of the parameter pack.
3735 SourceLocation PackLoc;
3737 /// \brief The location of the closing parenthesis.
3738 SourceLocation RParenLoc;
3740 /// \brief The length of the parameter pack, if known.
3742 /// When this expression is not value-dependent, this is the length of
3743 /// the pack. When the expression was parsed rather than instantiated
3744 /// (and thus is value-dependent), this is zero.
3746 /// After partial substitution into a sizeof...(X) expression (for instance,
3747 /// within an alias template or during function template argument deduction),
3748 /// we store a trailing array of partially-substituted TemplateArguments,
3749 /// and this is the length of that array.
3752 /// \brief The parameter pack.
3753 NamedDecl *Pack = nullptr;
3755 /// \brief Create an expression that computes the length of
3756 /// the given parameter pack.
3757 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3758 SourceLocation PackLoc, SourceLocation RParenLoc,
3759 Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
3760 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3761 /*TypeDependent=*/false, /*ValueDependent=*/!Length,
3762 /*InstantiationDependent=*/!Length,
3763 /*ContainsUnexpandedParameterPack=*/false),
3764 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3765 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
3766 assert((!Length || PartialArgs.empty()) &&
3767 "have partial args for non-dependent sizeof... expression");
3768 TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3769 std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
3772 /// \brief Create an empty expression.
3773 SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
3774 : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {}
3777 static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
3778 NamedDecl *Pack, SourceLocation PackLoc,
3779 SourceLocation RParenLoc,
3780 Optional<unsigned> Length = None,
3781 ArrayRef<TemplateArgument> PartialArgs = None);
3782 static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
3783 unsigned NumPartialArgs);
3785 /// \brief Determine the location of the 'sizeof' keyword.
3786 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3788 /// \brief Determine the location of the parameter pack.
3789 SourceLocation getPackLoc() const { return PackLoc; }
3791 /// \brief Determine the location of the right parenthesis.
3792 SourceLocation getRParenLoc() const { return RParenLoc; }
3794 /// \brief Retrieve the parameter pack.
3795 NamedDecl *getPack() const { return Pack; }
3797 /// \brief Retrieve the length of the parameter pack.
3799 /// This routine may only be invoked when the expression is not
3800 /// value-dependent.
3801 unsigned getPackLength() const {
3802 assert(!isValueDependent() &&
3803 "Cannot get the length of a value-dependent pack size expression");
3807 /// \brief Determine whether this represents a partially-substituted sizeof...
3808 /// expression, such as is produced for:
3810 /// template<typename ...Ts> using X = int[sizeof...(Ts)];
3811 /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
3812 bool isPartiallySubstituted() const {
3813 return isValueDependent() && Length;
3817 ArrayRef<TemplateArgument> getPartialArguments() const {
3818 assert(isPartiallySubstituted());
3819 const TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3820 return llvm::makeArrayRef(Args, Args + Length);
3823 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
3824 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3826 static bool classof(const Stmt *T) {
3827 return T->getStmtClass() == SizeOfPackExprClass;
3831 child_range children() {
3832 return child_range(child_iterator(), child_iterator());
3836 /// \brief Represents a reference to a non-type template parameter
3837 /// that has been substituted with a template argument.
3838 class SubstNonTypeTemplateParmExpr : public Expr {
3839 friend class ASTReader;
3840 friend class ASTStmtReader;
3842 /// \brief The replaced parameter.
3843 NonTypeTemplateParmDecl *Param;
3845 /// \brief The replacement expression.
3848 /// \brief The location of the non-type template parameter reference.
3849 SourceLocation NameLoc;
3851 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3852 : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
3855 SubstNonTypeTemplateParmExpr(QualType type,
3856 ExprValueKind valueKind,
3858 NonTypeTemplateParmDecl *param,
3860 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3861 replacement->isTypeDependent(), replacement->isValueDependent(),
3862 replacement->isInstantiationDependent(),
3863 replacement->containsUnexpandedParameterPack()),
3864 Param(param), Replacement(replacement), NameLoc(loc) {}
3866 SourceLocation getNameLoc() const { return NameLoc; }
3867 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3868 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3870 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3872 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3874 static bool classof(const Stmt *s) {
3875 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3879 child_range children() { return child_range(&Replacement, &Replacement+1); }
3882 /// \brief Represents a reference to a non-type template parameter pack that
3883 /// has been substituted with a non-template argument pack.
3885 /// When a pack expansion in the source code contains multiple parameter packs
3886 /// and those parameter packs correspond to different levels of template
3887 /// parameter lists, this node is used to represent a non-type template
3888 /// parameter pack from an outer level, which has already had its argument pack
3889 /// substituted but that still lives within a pack expansion that itself
3890 /// could not be instantiated. When actually performing a substitution into
3891 /// that pack expansion (e.g., when all template parameters have corresponding
3892 /// arguments), this type will be replaced with the appropriate underlying
3893 /// expression at the current pack substitution index.
3894 class SubstNonTypeTemplateParmPackExpr : public Expr {
3895 friend class ASTReader;
3896 friend class ASTStmtReader;
3898 /// \brief The non-type template parameter pack itself.
3899 NonTypeTemplateParmDecl *Param;
3901 /// \brief A pointer to the set of template arguments that this
3902 /// parameter pack is instantiated with.
3903 const TemplateArgument *Arguments;
3905 /// \brief The number of template arguments in \c Arguments.
3906 unsigned NumArguments;
3908 /// \brief The location of the non-type template parameter pack reference.
3909 SourceLocation NameLoc;
3911 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3912 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {}
3915 SubstNonTypeTemplateParmPackExpr(QualType T,
3916 NonTypeTemplateParmDecl *Param,
3917 SourceLocation NameLoc,
3918 const TemplateArgument &ArgPack);
3920 /// \brief Retrieve the non-type template parameter pack being substituted.
3921 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3923 /// \brief Retrieve the location of the parameter pack name.
3924 SourceLocation getParameterPackLocation() const { return NameLoc; }
3926 /// \brief Retrieve the template argument pack containing the substituted
3927 /// template arguments.
3928 TemplateArgument getArgumentPack() const;
3930 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3931 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3933 static bool classof(const Stmt *T) {
3934 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3938 child_range children() {
3939 return child_range(child_iterator(), child_iterator());
3943 /// \brief Represents a reference to a function parameter pack that has been
3944 /// substituted but not yet expanded.
3946 /// When a pack expansion contains multiple parameter packs at different levels,
3947 /// this node is used to represent a function parameter pack at an outer level
3948 /// which we have already substituted to refer to expanded parameters, but where
3949 /// the containing pack expansion cannot yet be expanded.
3952 /// template<typename...Ts> struct S {
3953 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3955 /// template struct S<int, int>;
3957 class FunctionParmPackExpr final
3959 private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> {
3960 friend class ASTReader;
3961 friend class ASTStmtReader;
3962 friend TrailingObjects;
3964 /// \brief The function parameter pack which was referenced.
3965 ParmVarDecl *ParamPack;
3967 /// \brief The location of the function parameter pack reference.
3968 SourceLocation NameLoc;
3970 /// \brief The number of expansions of this pack.
3971 unsigned NumParameters;
3973 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3974 SourceLocation NameLoc, unsigned NumParams,
3975 ParmVarDecl *const *Params);
3978 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
3979 ParmVarDecl *ParamPack,
3980 SourceLocation NameLoc,
3981 ArrayRef<ParmVarDecl *> Params);
3982 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
3983 unsigned NumParams);
3985 /// \brief Get the parameter pack which this expression refers to.
3986 ParmVarDecl *getParameterPack() const { return ParamPack; }
3988 /// \brief Get the location of the parameter pack.
3989 SourceLocation getParameterPackLocation() const { return NameLoc; }
3991 /// \brief Iterators over the parameters which the parameter pack expanded
3993 using iterator = ParmVarDecl * const *;
3994 iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); }
3995 iterator end() const { return begin() + NumParameters; }
3997 /// \brief Get the number of parameters in this parameter pack.
3998 unsigned getNumExpansions() const { return NumParameters; }
4000 /// \brief Get an expansion of the parameter pack by index.
4001 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
4003 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
4004 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
4006 static bool classof(const Stmt *T) {
4007 return T->getStmtClass() == FunctionParmPackExprClass;
4010 child_range children() {
4011 return child_range(child_iterator(), child_iterator());
4015 /// \brief Represents a prvalue temporary that is written into memory so that
4016 /// a reference can bind to it.
4018 /// Prvalue expressions are materialized when they need to have an address
4019 /// in memory for a reference to bind to. This happens when binding a
4020 /// reference to the result of a conversion, e.g.,
4023 /// const int &r = 1.0;
4026 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
4027 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
4028 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
4029 /// (either an lvalue or an xvalue, depending on the kind of reference binding
4030 /// to it), maintaining the invariant that references always bind to glvalues.
4032 /// Reference binding and copy-elision can both extend the lifetime of a
4033 /// temporary. When either happens, the expression will also track the
4034 /// declaration which is responsible for the lifetime extension.
4035 class MaterializeTemporaryExpr : public Expr {
4037 friend class ASTStmtReader;
4038 friend class ASTStmtWriter;
4041 /// \brief The temporary-generating expression whose value will be
4045 /// \brief The declaration which lifetime-extended this reference, if any.
4046 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
4047 const ValueDecl *ExtendingDecl;
4049 unsigned ManglingNumber;
4051 llvm::PointerUnion<Stmt *, ExtraState *> State;
4053 void initializeExtraState(const ValueDecl *ExtendedBy,
4054 unsigned ManglingNumber);
4057 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
4058 bool BoundToLvalueReference)
4059 : Expr(MaterializeTemporaryExprClass, T,
4060 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
4061 Temporary->isTypeDependent(), Temporary->isValueDependent(),
4062 Temporary->isInstantiationDependent(),
4063 Temporary->containsUnexpandedParameterPack()),
4066 MaterializeTemporaryExpr(EmptyShell Empty)
4067 : Expr(MaterializeTemporaryExprClass, Empty) {}
4069 Stmt *getTemporary() const {
4070 return State.is<Stmt *>() ? State.get<Stmt *>()
4071 : State.get<ExtraState *>()->Temporary;
4074 /// \brief Retrieve the temporary-generating subexpression whose value will
4075 /// be materialized into a glvalue.
4076 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
4078 /// \brief Retrieve the storage duration for the materialized temporary.
4079 StorageDuration getStorageDuration() const {
4080 const ValueDecl *ExtendingDecl = getExtendingDecl();
4082 return SD_FullExpression;
4083 // FIXME: This is not necessarily correct for a temporary materialized
4084 // within a default initializer.
4085 if (isa<FieldDecl>(ExtendingDecl))
4086 return SD_Automatic;
4087 // FIXME: This only works because storage class specifiers are not allowed
4088 // on decomposition declarations.
4089 if (isa<BindingDecl>(ExtendingDecl))
4090 return ExtendingDecl->getDeclContext()->isFunctionOrMethod()
4093 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
4096 /// \brief Get the declaration which triggered the lifetime-extension of this
4097 /// temporary, if any.
4098 const ValueDecl *getExtendingDecl() const {
4099 return State.is<Stmt *>() ? nullptr
4100 : State.get<ExtraState *>()->ExtendingDecl;
4103 void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
4105 unsigned getManglingNumber() const {
4106 return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
4109 /// \brief Determine whether this materialized temporary is bound to an
4110 /// lvalue reference; otherwise, it's bound to an rvalue reference.
4111 bool isBoundToLvalueReference() const {
4112 return getValueKind() == VK_LValue;
4115 SourceLocation getLocStart() const LLVM_READONLY {
4116 return getTemporary()->getLocStart();
4119 SourceLocation getLocEnd() const LLVM_READONLY {
4120 return getTemporary()->getLocEnd();
4123 static bool classof(const Stmt *T) {
4124 return T->getStmtClass() == MaterializeTemporaryExprClass;
4128 child_range children() {
4129 if (State.is<Stmt *>())
4130 return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
4132 auto ES = State.get<ExtraState *>();
4133 return child_range(&ES->Temporary, &ES->Temporary + 1);
4137 /// \brief Represents a folding of a pack over an operator.
4139 /// This expression is always dependent and represents a pack expansion of the
4144 /// ( expr op ... op expr )
4145 class CXXFoldExpr : public Expr {
4146 friend class ASTStmtReader;
4147 friend class ASTStmtWriter;
4149 SourceLocation LParenLoc;
4150 SourceLocation EllipsisLoc;
4151 SourceLocation RParenLoc;
4153 BinaryOperatorKind Opcode;
4156 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
4157 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
4158 SourceLocation RParenLoc)
4159 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
4160 /*Dependent*/ true, true, true,
4161 /*ContainsUnexpandedParameterPack*/ false),
4162 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4168 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4170 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
4171 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
4173 /// Does this produce a right-associated sequence of operators?
4174 bool isRightFold() const {
4175 return getLHS() && getLHS()->containsUnexpandedParameterPack();
4178 /// Does this produce a left-associated sequence of operators?
4179 bool isLeftFold() const { return !isRightFold(); }
4181 /// Get the pattern, that is, the operand that contains an unexpanded pack.
4182 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4184 /// Get the operand that doesn't contain a pack, for a binary fold.
4185 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4187 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4188 BinaryOperatorKind getOperator() const { return Opcode; }
4190 SourceLocation getLocStart() const LLVM_READONLY {
4194 SourceLocation getLocEnd() const LLVM_READONLY {
4198 static bool classof(const Stmt *T) {
4199 return T->getStmtClass() == CXXFoldExprClass;
4203 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4206 /// \brief Represents an expression that might suspend coroutine execution;
4207 /// either a co_await or co_yield expression.
4209 /// Evaluation of this expression first evaluates its 'ready' expression. If
4210 /// that returns 'false':
4211 /// -- execution of the coroutine is suspended
4212 /// -- the 'suspend' expression is evaluated
4213 /// -- if the 'suspend' expression returns 'false', the coroutine is
4215 /// -- otherwise, control passes back to the resumer.
4216 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4217 /// expression is evaluated, and its result is the result of the overall
4219 class CoroutineSuspendExpr : public Expr {
4220 friend class ASTStmtReader;
4222 SourceLocation KeywordLoc;
4224 enum SubExpr { Common, Ready, Suspend, Resume, Count };
4226 Stmt *SubExprs[SubExpr::Count];
4227 OpaqueValueExpr *OpaqueValue = nullptr;
4230 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4231 Expr *Ready, Expr *Suspend, Expr *Resume,
4232 OpaqueValueExpr *OpaqueValue)
4233 : Expr(SC, Resume->getType(), Resume->getValueKind(),
4234 Resume->getObjectKind(), Resume->isTypeDependent(),
4235 Resume->isValueDependent(), Common->isInstantiationDependent(),
4236 Common->containsUnexpandedParameterPack()),
4237 KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
4238 SubExprs[SubExpr::Common] = Common;
4239 SubExprs[SubExpr::Ready] = Ready;
4240 SubExprs[SubExpr::Suspend] = Suspend;
4241 SubExprs[SubExpr::Resume] = Resume;
4244 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4246 : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
4247 Common->containsUnexpandedParameterPack()),
4248 KeywordLoc(KeywordLoc) {
4249 assert(Common->isTypeDependent() && Ty->isDependentType() &&
4250 "wrong constructor for non-dependent co_await/co_yield expression");
4251 SubExprs[SubExpr::Common] = Common;
4252 SubExprs[SubExpr::Ready] = nullptr;
4253 SubExprs[SubExpr::Suspend] = nullptr;
4254 SubExprs[SubExpr::Resume] = nullptr;
4257 CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4258 SubExprs[SubExpr::Common] = nullptr;
4259 SubExprs[SubExpr::Ready] = nullptr;
4260 SubExprs[SubExpr::Suspend] = nullptr;
4261 SubExprs[SubExpr::Resume] = nullptr;
4264 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4266 Expr *getCommonExpr() const {
4267 return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4270 /// \brief getOpaqueValue - Return the opaque value placeholder.
4271 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4273 Expr *getReadyExpr() const {
4274 return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4277 Expr *getSuspendExpr() const {
4278 return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4281 Expr *getResumeExpr() const {
4282 return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4285 SourceLocation getLocStart() const LLVM_READONLY {
4289 SourceLocation getLocEnd() const LLVM_READONLY {
4290 return getCommonExpr()->getLocEnd();
4293 child_range children() {
4294 return child_range(SubExprs, SubExprs + SubExpr::Count);
4297 static bool classof(const Stmt *T) {
4298 return T->getStmtClass() == CoawaitExprClass ||
4299 T->getStmtClass() == CoyieldExprClass;
4303 /// \brief Represents a 'co_await' expression.
4304 class CoawaitExpr : public CoroutineSuspendExpr {
4305 friend class ASTStmtReader;
4308 CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4309 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
4310 bool IsImplicit = false)
4311 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4312 Suspend, Resume, OpaqueValue) {
4313 CoawaitBits.IsImplicit = IsImplicit;
4316 CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
4317 bool IsImplicit = false)
4318 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
4319 CoawaitBits.IsImplicit = IsImplicit;
4322 CoawaitExpr(EmptyShell Empty)
4323 : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4325 Expr *getOperand() const {
4326 // FIXME: Dig out the actual operand or store it.
4327 return getCommonExpr();
4330 bool isImplicit() const { return CoawaitBits.IsImplicit; }
4331 void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
4333 static bool classof(const Stmt *T) {
4334 return T->getStmtClass() == CoawaitExprClass;
4338 /// \brief Represents a 'co_await' expression while the type of the promise
4340 class DependentCoawaitExpr : public Expr {
4341 friend class ASTStmtReader;
4343 SourceLocation KeywordLoc;
4347 DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
4348 UnresolvedLookupExpr *OpCoawait)
4349 : Expr(DependentCoawaitExprClass, Ty, VK_RValue, OK_Ordinary,
4350 /*TypeDependent*/ true, /*ValueDependent*/ true,
4351 /*InstantiationDependent*/ true,
4352 Op->containsUnexpandedParameterPack()),
4353 KeywordLoc(KeywordLoc) {
4354 // NOTE: A co_await expression is dependent on the coroutines promise
4355 // type and may be dependent even when the `Op` expression is not.
4356 assert(Ty->isDependentType() &&
4357 "wrong constructor for non-dependent co_await/co_yield expression");
4359 SubExprs[1] = OpCoawait;
4362 DependentCoawaitExpr(EmptyShell Empty)
4363 : Expr(DependentCoawaitExprClass, Empty) {}
4365 Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
4367 UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
4368 return cast<UnresolvedLookupExpr>(SubExprs[1]);
4371 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4373 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
4375 SourceLocation getLocEnd() const LLVM_READONLY {
4376 return getOperand()->getLocEnd();
4379 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4381 static bool classof(const Stmt *T) {
4382 return T->getStmtClass() == DependentCoawaitExprClass;
4386 /// \brief Represents a 'co_yield' expression.
4387 class CoyieldExpr : public CoroutineSuspendExpr {
4388 friend class ASTStmtReader;
4391 CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4392 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
4393 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4394 Suspend, Resume, OpaqueValue) {}
4395 CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4396 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
4397 CoyieldExpr(EmptyShell Empty)
4398 : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4400 Expr *getOperand() const {
4401 // FIXME: Dig out the actual operand or store it.
4402 return getCommonExpr();
4405 static bool classof(const Stmt *T) {
4406 return T->getStmtClass() == CoyieldExprClass;
4410 } // namespace clang
4412 #endif // LLVM_CLANG_AST_EXPRCXX_H