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/DeclCXX.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/LambdaCapture.h"
22 #include "clang/AST/TemplateBase.h"
23 #include "clang/AST/UnresolvedSet.h"
24 #include "clang/Basic/ExpressionTraits.h"
25 #include "clang/Basic/TypeTraits.h"
26 #include "llvm/Support/Compiler.h"
32 class TemplateArgumentListInfo;
35 //===--------------------------------------------------------------------===//
37 //===--------------------------------------------------------------------===//
39 /// \brief A call to an overloaded operator written using operator
42 /// Represents a call to an overloaded operator written using operator
43 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
44 /// normal call, this AST node provides better information about the
45 /// syntactic representation of the call.
47 /// In a C++ template, this expression node kind will be used whenever
48 /// any of the arguments are type-dependent. In this case, the
49 /// function itself will be a (possibly empty) set of functions and
50 /// function templates that were found by name lookup at template
52 class CXXOperatorCallExpr : public CallExpr {
53 /// \brief The overloaded operator.
54 OverloadedOperatorKind Operator;
57 // Record the FP_CONTRACT state that applies to this operator call. Only
58 // meaningful for floating point types. For other types this value can be
60 unsigned FPContractable : 1;
62 SourceRange getSourceRangeImpl() const LLVM_READONLY;
64 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
65 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
66 SourceLocation operatorloc, bool fpContractable)
67 : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
68 Operator(Op), FPContractable(fpContractable) {
69 Range = getSourceRangeImpl();
71 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
72 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
75 /// \brief Returns the kind of overloaded operator that this
76 /// expression refers to.
77 OverloadedOperatorKind getOperator() const { return Operator; }
79 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
80 return Opc == OO_Equal || Opc == OO_StarEqual ||
81 Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
82 Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
83 Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
84 Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
87 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
89 /// \brief Is this written as an infix binary operator?
90 bool isInfixBinaryOp() const;
92 /// \brief Returns the location of the operator symbol in the expression.
94 /// When \c getOperator()==OO_Call, this is the location of the right
95 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
96 /// of the right bracket.
97 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
99 SourceLocation getExprLoc() const LLVM_READONLY {
100 return (Operator < OO_Plus || Operator >= OO_Arrow ||
101 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
106 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
107 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
108 SourceRange getSourceRange() const { return Range; }
110 static bool classof(const Stmt *T) {
111 return T->getStmtClass() == CXXOperatorCallExprClass;
114 // Set the FP contractability status of this operator. Only meaningful for
115 // operations on floating point types.
116 void setFPContractable(bool FPC) { FPContractable = FPC; }
118 // Get the FP contractability status of this operator. Only meaningful for
119 // operations on floating point types.
120 bool isFPContractable() const { return FPContractable; }
122 friend class ASTStmtReader;
123 friend class ASTStmtWriter;
126 /// Represents a call to a member function that
127 /// may be written either with member call syntax (e.g., "obj.func()"
128 /// or "objptr->func()") or with normal function-call syntax
129 /// ("func()") within a member function that ends up calling a member
130 /// function. The callee in either case is a MemberExpr that contains
131 /// both the object argument and the member function, while the
132 /// arguments are the arguments within the parentheses (not including
133 /// the object argument).
134 class CXXMemberCallExpr : public CallExpr {
136 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
137 QualType t, ExprValueKind VK, SourceLocation RP)
138 : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
140 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
141 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
143 /// \brief Retrieves the implicit object argument for the member call.
145 /// For example, in "x.f(5)", this returns the sub-expression "x".
146 Expr *getImplicitObjectArgument() const;
148 /// \brief Retrieves the declaration of the called method.
149 CXXMethodDecl *getMethodDecl() const;
151 /// \brief Retrieves the CXXRecordDecl for the underlying type of
152 /// the implicit object argument.
154 /// Note that this is may not be the same declaration as that of the class
155 /// context of the CXXMethodDecl which this function is calling.
156 /// FIXME: Returns 0 for member pointer call exprs.
157 CXXRecordDecl *getRecordDecl() const;
159 SourceLocation getExprLoc() const LLVM_READONLY {
160 SourceLocation CLoc = getCallee()->getExprLoc();
164 return getLocStart();
167 static bool classof(const Stmt *T) {
168 return T->getStmtClass() == CXXMemberCallExprClass;
172 /// \brief Represents a call to a CUDA kernel function.
173 class CUDAKernelCallExpr : public CallExpr {
175 enum { CONFIG, END_PREARG };
178 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
179 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
181 : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP) {}
183 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
184 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
186 const CallExpr *getConfig() const {
187 return cast_or_null<CallExpr>(getPreArg(CONFIG));
189 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
191 /// \brief Sets the kernel configuration expression.
193 /// Note that this method cannot be called if config has already been set to a
195 void setConfig(CallExpr *E) {
196 assert(!getConfig() &&
197 "Cannot call setConfig if config is not null");
198 setPreArg(CONFIG, E);
199 setInstantiationDependent(isInstantiationDependent() ||
200 E->isInstantiationDependent());
201 setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() ||
202 E->containsUnexpandedParameterPack());
205 static bool classof(const Stmt *T) {
206 return T->getStmtClass() == CUDAKernelCallExprClass;
210 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
212 /// This abstract class is inherited by all of the classes
213 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
214 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
215 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
216 class CXXNamedCastExpr : public ExplicitCastExpr {
218 SourceLocation Loc; // the location of the casting op
219 SourceLocation RParenLoc; // the location of the right parenthesis
220 SourceRange AngleBrackets; // range for '<' '>'
223 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
224 CastKind kind, Expr *op, unsigned PathSize,
225 TypeSourceInfo *writtenTy, SourceLocation l,
226 SourceLocation RParenLoc,
227 SourceRange AngleBrackets)
228 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
229 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
231 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
232 : ExplicitCastExpr(SC, Shell, PathSize) { }
234 friend class ASTStmtReader;
237 const char *getCastName() const;
239 /// \brief Retrieve the location of the cast operator keyword, e.g.,
241 SourceLocation getOperatorLoc() const { return Loc; }
243 /// \brief Retrieve the location of the closing parenthesis.
244 SourceLocation getRParenLoc() const { return RParenLoc; }
246 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
247 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
248 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
250 static bool classof(const Stmt *T) {
251 switch (T->getStmtClass()) {
252 case CXXStaticCastExprClass:
253 case CXXDynamicCastExprClass:
254 case CXXReinterpretCastExprClass:
255 case CXXConstCastExprClass:
263 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
265 /// This expression node represents a C++ static cast, e.g.,
266 /// \c static_cast<int>(1.0).
267 class CXXStaticCastExpr final
268 : public CXXNamedCastExpr,
269 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
270 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
271 unsigned pathSize, TypeSourceInfo *writtenTy,
272 SourceLocation l, SourceLocation RParenLoc,
273 SourceRange AngleBrackets)
274 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
275 writtenTy, l, RParenLoc, AngleBrackets) {}
277 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
278 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
281 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
282 ExprValueKind VK, CastKind K, Expr *Op,
283 const CXXCastPath *Path,
284 TypeSourceInfo *Written, SourceLocation L,
285 SourceLocation RParenLoc,
286 SourceRange AngleBrackets);
287 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
290 static bool classof(const Stmt *T) {
291 return T->getStmtClass() == CXXStaticCastExprClass;
294 friend TrailingObjects;
295 friend class CastExpr;
298 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
300 /// This expression node represents a dynamic cast, e.g.,
301 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
302 /// check to determine how to perform the type conversion.
303 class CXXDynamicCastExpr final
304 : public CXXNamedCastExpr,
305 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
306 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
307 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
308 SourceLocation l, SourceLocation RParenLoc,
309 SourceRange AngleBrackets)
310 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
311 writtenTy, l, RParenLoc, AngleBrackets) {}
313 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
314 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
317 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
318 ExprValueKind VK, CastKind Kind, Expr *Op,
319 const CXXCastPath *Path,
320 TypeSourceInfo *Written, SourceLocation L,
321 SourceLocation RParenLoc,
322 SourceRange AngleBrackets);
324 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
327 bool isAlwaysNull() const;
329 static bool classof(const Stmt *T) {
330 return T->getStmtClass() == CXXDynamicCastExprClass;
333 friend TrailingObjects;
334 friend class CastExpr;
337 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
339 /// This expression node represents a reinterpret cast, e.g.,
340 /// @c reinterpret_cast<int>(VoidPtr).
342 /// A reinterpret_cast provides a differently-typed view of a value but
343 /// (in Clang, as in most C++ implementations) performs no actual work at
345 class CXXReinterpretCastExpr final
346 : public CXXNamedCastExpr,
347 private llvm::TrailingObjects<CXXReinterpretCastExpr,
348 CXXBaseSpecifier *> {
349 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
350 Expr *op, unsigned pathSize,
351 TypeSourceInfo *writtenTy, SourceLocation l,
352 SourceLocation RParenLoc,
353 SourceRange AngleBrackets)
354 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
355 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
357 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
358 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
361 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
362 ExprValueKind VK, CastKind Kind,
363 Expr *Op, const CXXCastPath *Path,
364 TypeSourceInfo *WrittenTy, SourceLocation L,
365 SourceLocation RParenLoc,
366 SourceRange AngleBrackets);
367 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
370 static bool classof(const Stmt *T) {
371 return T->getStmtClass() == CXXReinterpretCastExprClass;
374 friend TrailingObjects;
375 friend class CastExpr;
378 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
380 /// This expression node represents a const cast, e.g.,
381 /// \c const_cast<char*>(PtrToConstChar).
383 /// A const_cast can remove type qualifiers but does not change the underlying
385 class CXXConstCastExpr final
386 : public CXXNamedCastExpr,
387 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
388 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
389 TypeSourceInfo *writtenTy, SourceLocation l,
390 SourceLocation RParenLoc, SourceRange AngleBrackets)
391 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
392 0, writtenTy, l, RParenLoc, AngleBrackets) {}
394 explicit CXXConstCastExpr(EmptyShell Empty)
395 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
398 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
399 ExprValueKind VK, Expr *Op,
400 TypeSourceInfo *WrittenTy, SourceLocation L,
401 SourceLocation RParenLoc,
402 SourceRange AngleBrackets);
403 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
405 static bool classof(const Stmt *T) {
406 return T->getStmtClass() == CXXConstCastExprClass;
409 friend TrailingObjects;
410 friend class CastExpr;
413 /// \brief A call to a literal operator (C++11 [over.literal])
414 /// written as a user-defined literal (C++11 [lit.ext]).
416 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
417 /// is semantically equivalent to a normal call, this AST node provides better
418 /// information about the syntactic representation of the literal.
420 /// Since literal operators are never found by ADL and can only be declared at
421 /// namespace scope, a user-defined literal is never dependent.
422 class UserDefinedLiteral : public CallExpr {
423 /// \brief The location of a ud-suffix within the literal.
424 SourceLocation UDSuffixLoc;
427 UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
428 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
429 SourceLocation SuffixLoc)
430 : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc),
431 UDSuffixLoc(SuffixLoc) {}
432 explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
433 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
435 /// The kind of literal operator which is invoked.
436 enum LiteralOperatorKind {
437 LOK_Raw, ///< Raw form: operator "" X (const char *)
438 LOK_Template, ///< Raw form: operator "" X<cs...> ()
439 LOK_Integer, ///< operator "" X (unsigned long long)
440 LOK_Floating, ///< operator "" X (long double)
441 LOK_String, ///< operator "" X (const CharT *, size_t)
442 LOK_Character ///< operator "" X (CharT)
445 /// \brief Returns the kind of literal operator invocation
446 /// which this expression represents.
447 LiteralOperatorKind getLiteralOperatorKind() const;
449 /// \brief If this is not a raw user-defined literal, get the
450 /// underlying cooked literal (representing the literal with the suffix
452 Expr *getCookedLiteral();
453 const Expr *getCookedLiteral() const {
454 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
457 SourceLocation getLocStart() const {
458 if (getLiteralOperatorKind() == LOK_Template)
459 return getRParenLoc();
460 return getArg(0)->getLocStart();
462 SourceLocation getLocEnd() const { return getRParenLoc(); }
465 /// \brief Returns the location of a ud-suffix in the expression.
467 /// For a string literal, there may be multiple identical suffixes. This
468 /// returns the first.
469 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
471 /// \brief Returns the ud-suffix specified for this literal.
472 const IdentifierInfo *getUDSuffix() const;
474 static bool classof(const Stmt *S) {
475 return S->getStmtClass() == UserDefinedLiteralClass;
478 friend class ASTStmtReader;
479 friend class ASTStmtWriter;
482 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
484 class CXXBoolLiteralExpr : public Expr {
488 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
489 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
491 Value(val), Loc(l) {}
493 explicit CXXBoolLiteralExpr(EmptyShell Empty)
494 : Expr(CXXBoolLiteralExprClass, Empty) { }
496 bool getValue() const { return Value; }
497 void setValue(bool V) { Value = V; }
499 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
500 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
502 SourceLocation getLocation() const { return Loc; }
503 void setLocation(SourceLocation L) { Loc = L; }
505 static bool classof(const Stmt *T) {
506 return T->getStmtClass() == CXXBoolLiteralExprClass;
510 child_range children() {
511 return child_range(child_iterator(), child_iterator());
515 /// \brief The null pointer literal (C++11 [lex.nullptr])
517 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
518 class CXXNullPtrLiteralExpr : public Expr {
521 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
522 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
526 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
527 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
529 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
530 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
532 SourceLocation getLocation() const { return Loc; }
533 void setLocation(SourceLocation L) { Loc = L; }
535 static bool classof(const Stmt *T) {
536 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
539 child_range children() {
540 return child_range(child_iterator(), child_iterator());
544 /// \brief Implicit construction of a std::initializer_list<T> object from an
545 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
546 class CXXStdInitializerListExpr : public Expr {
549 CXXStdInitializerListExpr(EmptyShell Empty)
550 : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
553 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
554 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
555 Ty->isDependentType(), SubExpr->isValueDependent(),
556 SubExpr->isInstantiationDependent(),
557 SubExpr->containsUnexpandedParameterPack()),
560 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
561 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
563 SourceLocation getLocStart() const LLVM_READONLY {
564 return SubExpr->getLocStart();
566 SourceLocation getLocEnd() const LLVM_READONLY {
567 return SubExpr->getLocEnd();
569 SourceRange getSourceRange() const LLVM_READONLY {
570 return SubExpr->getSourceRange();
573 static bool classof(const Stmt *S) {
574 return S->getStmtClass() == CXXStdInitializerListExprClass;
577 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
579 friend class ASTReader;
580 friend class ASTStmtReader;
583 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
584 /// the \c type_info that corresponds to the supplied type, or the (possibly
585 /// dynamic) type of the supplied expression.
587 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
588 class CXXTypeidExpr : public Expr {
590 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
594 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
595 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
596 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
598 // typeid is value-dependent if the type or expression are dependent
599 Operand->getType()->isDependentType(),
600 Operand->getType()->isInstantiationDependentType(),
601 Operand->getType()->containsUnexpandedParameterPack()),
602 Operand(Operand), Range(R) { }
604 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
605 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
606 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
608 // typeid is value-dependent if the type or expression are dependent
609 Operand->isTypeDependent() || Operand->isValueDependent(),
610 Operand->isInstantiationDependent(),
611 Operand->containsUnexpandedParameterPack()),
612 Operand(Operand), Range(R) { }
614 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
615 : Expr(CXXTypeidExprClass, Empty) {
617 Operand = (Expr*)nullptr;
619 Operand = (TypeSourceInfo*)nullptr;
622 /// Determine whether this typeid has a type operand which is potentially
623 /// evaluated, per C++11 [expr.typeid]p3.
624 bool isPotentiallyEvaluated() const;
626 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
628 /// \brief Retrieves the type operand of this typeid() expression after
629 /// various required adjustments (removing reference types, cv-qualifiers).
630 QualType getTypeOperand(ASTContext &Context) const;
632 /// \brief Retrieve source information for the type operand.
633 TypeSourceInfo *getTypeOperandSourceInfo() const {
634 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
635 return Operand.get<TypeSourceInfo *>();
638 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
639 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
643 Expr *getExprOperand() const {
644 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
645 return static_cast<Expr*>(Operand.get<Stmt *>());
648 void setExprOperand(Expr *E) {
649 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
653 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
654 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
655 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
656 void setSourceRange(SourceRange R) { Range = R; }
658 static bool classof(const Stmt *T) {
659 return T->getStmtClass() == CXXTypeidExprClass;
663 child_range children() {
665 return child_range(child_iterator(), child_iterator());
666 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
667 return child_range(begin, begin + 1);
671 /// \brief A member reference to an MSPropertyDecl.
673 /// This expression always has pseudo-object type, and therefore it is
674 /// typically not encountered in a fully-typechecked expression except
675 /// within the syntactic form of a PseudoObjectExpr.
676 class MSPropertyRefExpr : public Expr {
678 MSPropertyDecl *TheDecl;
679 SourceLocation MemberLoc;
681 NestedNameSpecifierLoc QualifierLoc;
684 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
685 QualType ty, ExprValueKind VK,
686 NestedNameSpecifierLoc qualifierLoc,
687 SourceLocation nameLoc)
688 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
689 /*type-dependent*/ false, baseExpr->isValueDependent(),
690 baseExpr->isInstantiationDependent(),
691 baseExpr->containsUnexpandedParameterPack()),
692 BaseExpr(baseExpr), TheDecl(decl),
693 MemberLoc(nameLoc), IsArrow(isArrow),
694 QualifierLoc(qualifierLoc) {}
696 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
698 SourceRange getSourceRange() const LLVM_READONLY {
699 return SourceRange(getLocStart(), getLocEnd());
701 bool isImplicitAccess() const {
702 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
704 SourceLocation getLocStart() const {
705 if (!isImplicitAccess())
706 return BaseExpr->getLocStart();
707 else if (QualifierLoc)
708 return QualifierLoc.getBeginLoc();
712 SourceLocation getLocEnd() const { return getMemberLoc(); }
714 child_range children() {
715 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
717 static bool classof(const Stmt *T) {
718 return T->getStmtClass() == MSPropertyRefExprClass;
721 Expr *getBaseExpr() const { return BaseExpr; }
722 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
723 bool isArrow() const { return IsArrow; }
724 SourceLocation getMemberLoc() const { return MemberLoc; }
725 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
727 friend class ASTStmtReader;
730 /// MS property subscript expression.
731 /// MSVC supports 'property' attribute and allows to apply it to the
732 /// declaration of an empty array in a class or structure definition.
735 /// __declspec(property(get=GetX, put=PutX)) int x[];
737 /// The above statement indicates that x[] can be used with one or more array
738 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
739 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
740 /// This is a syntactic pseudo-object expression.
741 class MSPropertySubscriptExpr : public Expr {
742 friend class ASTStmtReader;
743 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
744 Stmt *SubExprs[NUM_SUBEXPRS];
745 SourceLocation RBracketLoc;
747 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
748 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
751 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
752 ExprObjectKind OK, SourceLocation RBracketLoc)
753 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
754 Idx->isValueDependent(), Idx->isInstantiationDependent(),
755 Idx->containsUnexpandedParameterPack()),
756 RBracketLoc(RBracketLoc) {
757 SubExprs[BASE_EXPR] = Base;
758 SubExprs[IDX_EXPR] = Idx;
761 /// \brief Create an empty array subscript expression.
762 explicit MSPropertySubscriptExpr(EmptyShell Shell)
763 : Expr(MSPropertySubscriptExprClass, Shell) {}
765 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
766 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
768 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
769 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
771 SourceLocation getLocStart() const LLVM_READONLY {
772 return getBase()->getLocStart();
774 SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
776 SourceLocation getRBracketLoc() const { return RBracketLoc; }
777 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
779 SourceLocation getExprLoc() const LLVM_READONLY {
780 return getBase()->getExprLoc();
783 static bool classof(const Stmt *T) {
784 return T->getStmtClass() == MSPropertySubscriptExprClass;
788 child_range children() {
789 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
793 /// A Microsoft C++ @c __uuidof expression, which gets
794 /// the _GUID that corresponds to the supplied type or expression.
796 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
797 class CXXUuidofExpr : public Expr {
799 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
804 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
806 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
807 Operand->getType()->isDependentType(),
808 Operand->getType()->isInstantiationDependentType(),
809 Operand->getType()->containsUnexpandedParameterPack()),
810 Operand(Operand), UuidStr(UuidStr), Range(R) {}
812 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
813 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
814 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
815 Operand->containsUnexpandedParameterPack()),
816 Operand(Operand), UuidStr(UuidStr), Range(R) {}
818 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
819 : Expr(CXXUuidofExprClass, Empty) {
821 Operand = (Expr*)nullptr;
823 Operand = (TypeSourceInfo*)nullptr;
826 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
828 /// \brief Retrieves the type operand of this __uuidof() expression after
829 /// various required adjustments (removing reference types, cv-qualifiers).
830 QualType getTypeOperand(ASTContext &Context) const;
832 /// \brief Retrieve source information for the type operand.
833 TypeSourceInfo *getTypeOperandSourceInfo() const {
834 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
835 return Operand.get<TypeSourceInfo *>();
838 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
839 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
843 Expr *getExprOperand() const {
844 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
845 return static_cast<Expr*>(Operand.get<Stmt *>());
848 void setExprOperand(Expr *E) {
849 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
853 void setUuidStr(StringRef US) { UuidStr = US; }
854 StringRef getUuidStr() const { return UuidStr; }
856 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
857 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
858 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
859 void setSourceRange(SourceRange R) { Range = R; }
861 static bool classof(const Stmt *T) {
862 return T->getStmtClass() == CXXUuidofExprClass;
866 child_range children() {
868 return child_range(child_iterator(), child_iterator());
869 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
870 return child_range(begin, begin + 1);
874 /// \brief Represents the \c this expression in C++.
876 /// This is a pointer to the object on which the current member function is
877 /// executing (C++ [expr.prim]p3). Example:
883 /// void test() { this->bar(); }
886 class CXXThisExpr : public Expr {
891 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
892 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
893 // 'this' is type-dependent if the class type of the enclosing
894 // member function is dependent (C++ [temp.dep.expr]p2)
895 Type->isDependentType(), Type->isDependentType(),
896 Type->isInstantiationDependentType(),
897 /*ContainsUnexpandedParameterPack=*/false),
898 Loc(L), Implicit(isImplicit) { }
900 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
902 SourceLocation getLocation() const { return Loc; }
903 void setLocation(SourceLocation L) { Loc = L; }
905 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
906 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
908 bool isImplicit() const { return Implicit; }
909 void setImplicit(bool I) { Implicit = I; }
911 static bool classof(const Stmt *T) {
912 return T->getStmtClass() == CXXThisExprClass;
916 child_range children() {
917 return child_range(child_iterator(), child_iterator());
921 /// \brief A C++ throw-expression (C++ [except.throw]).
923 /// This handles 'throw' (for re-throwing the current exception) and
924 /// 'throw' assignment-expression. When assignment-expression isn't
925 /// present, Op will be null.
926 class CXXThrowExpr : public Expr {
928 SourceLocation ThrowLoc;
929 /// \brief Whether the thrown variable (if any) is in scope.
930 unsigned IsThrownVariableInScope : 1;
932 friend class ASTStmtReader;
935 // \p Ty is the void type which is used as the result type of the
936 // expression. The \p l is the location of the throw keyword. \p expr
937 // can by null, if the optional expression to throw isn't present.
938 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
939 bool IsThrownVariableInScope) :
940 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
941 expr && expr->isInstantiationDependent(),
942 expr && expr->containsUnexpandedParameterPack()),
943 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
944 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
946 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
947 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
949 SourceLocation getThrowLoc() const { return ThrowLoc; }
951 /// \brief Determines whether the variable thrown by this expression (if any!)
952 /// is within the innermost try block.
954 /// This information is required to determine whether the NRVO can apply to
956 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
958 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
959 SourceLocation getLocEnd() const LLVM_READONLY {
962 return getSubExpr()->getLocEnd();
965 static bool classof(const Stmt *T) {
966 return T->getStmtClass() == CXXThrowExprClass;
970 child_range children() {
971 return child_range(&Op, Op ? &Op+1 : &Op);
975 /// \brief A default argument (C++ [dcl.fct.default]).
977 /// This wraps up a function call argument that was created from the
978 /// corresponding parameter's default argument, when the call did not
979 /// explicitly supply arguments for all of the parameters.
980 class CXXDefaultArgExpr final : public Expr {
981 /// \brief The parameter whose default is being used.
984 /// \brief The location where the default argument expression was used.
987 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
989 param->hasUnparsedDefaultArg()
990 ? param->getType().getNonReferenceType()
991 : param->getDefaultArg()->getType(),
992 param->getDefaultArg()->getValueKind(),
993 param->getDefaultArg()->getObjectKind(), false, false, false, false),
994 Param(param), Loc(Loc) { }
997 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
999 // \p Param is the parameter whose default argument is used by this
1001 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1002 ParmVarDecl *Param) {
1003 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
1006 // Retrieve the parameter that the argument was created from.
1007 const ParmVarDecl *getParam() const { return Param; }
1008 ParmVarDecl *getParam() { return Param; }
1010 // Retrieve the actual argument to the function call.
1011 const Expr *getExpr() const {
1012 return getParam()->getDefaultArg();
1015 return getParam()->getDefaultArg();
1018 /// \brief Retrieve the location where this default argument was actually
1020 SourceLocation getUsedLocation() const { return Loc; }
1022 /// Default argument expressions have no representation in the
1023 /// source, so they have an empty source range.
1024 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1025 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1027 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1029 static bool classof(const Stmt *T) {
1030 return T->getStmtClass() == CXXDefaultArgExprClass;
1034 child_range children() {
1035 return child_range(child_iterator(), child_iterator());
1038 friend class ASTStmtReader;
1039 friend class ASTStmtWriter;
1042 /// \brief A use of a default initializer in a constructor or in aggregate
1045 /// This wraps a use of a C++ default initializer (technically,
1046 /// a brace-or-equal-initializer for a non-static data member) when it
1047 /// is implicitly used in a mem-initializer-list in a constructor
1048 /// (C++11 [class.base.init]p8) or in aggregate initialization
1049 /// (C++1y [dcl.init.aggr]p7).
1050 class CXXDefaultInitExpr : public Expr {
1051 /// \brief The field whose default is being used.
1054 /// \brief The location where the default initializer expression was used.
1057 CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
1060 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1063 /// \p Field is the non-static data member whose default initializer is used
1064 /// by this expression.
1065 static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
1067 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
1070 /// \brief Get the field whose initializer will be used.
1071 FieldDecl *getField() { return Field; }
1072 const FieldDecl *getField() const { return Field; }
1074 /// \brief Get the initialization expression that will be used.
1075 const Expr *getExpr() const {
1076 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1077 return Field->getInClassInitializer();
1080 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1081 return Field->getInClassInitializer();
1084 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1085 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1087 static bool classof(const Stmt *T) {
1088 return T->getStmtClass() == CXXDefaultInitExprClass;
1092 child_range children() {
1093 return child_range(child_iterator(), child_iterator());
1096 friend class ASTReader;
1097 friend class ASTStmtReader;
1100 /// \brief Represents a C++ temporary.
1101 class CXXTemporary {
1102 /// \brief The destructor that needs to be called.
1103 const CXXDestructorDecl *Destructor;
1105 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1106 : Destructor(destructor) { }
1109 static CXXTemporary *Create(const ASTContext &C,
1110 const CXXDestructorDecl *Destructor);
1112 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1113 void setDestructor(const CXXDestructorDecl *Dtor) {
1118 /// \brief Represents binding an expression to a temporary.
1120 /// This ensures the destructor is called for the temporary. It should only be
1121 /// needed for non-POD, non-trivially destructable class types. For example:
1125 /// S() { } // User defined constructor makes S non-POD.
1126 /// ~S() { } // User defined destructor makes it non-trivial.
1129 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1132 class CXXBindTemporaryExpr : public Expr {
1137 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1138 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1139 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1140 SubExpr->isValueDependent(),
1141 SubExpr->isInstantiationDependent(),
1142 SubExpr->containsUnexpandedParameterPack()),
1143 Temp(temp), SubExpr(SubExpr) { }
1146 CXXBindTemporaryExpr(EmptyShell Empty)
1147 : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
1149 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1152 CXXTemporary *getTemporary() { return Temp; }
1153 const CXXTemporary *getTemporary() const { return Temp; }
1154 void setTemporary(CXXTemporary *T) { Temp = T; }
1156 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1157 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1158 void setSubExpr(Expr *E) { SubExpr = E; }
1160 SourceLocation getLocStart() const LLVM_READONLY {
1161 return SubExpr->getLocStart();
1163 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1165 // Implement isa/cast/dyncast/etc.
1166 static bool classof(const Stmt *T) {
1167 return T->getStmtClass() == CXXBindTemporaryExprClass;
1171 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1174 /// \brief Represents a call to a C++ constructor.
1175 class CXXConstructExpr : public Expr {
1177 enum ConstructionKind {
1185 CXXConstructorDecl *Constructor;
1188 SourceRange ParenOrBraceRange;
1189 unsigned NumArgs : 16;
1190 unsigned Elidable : 1;
1191 unsigned HadMultipleCandidates : 1;
1192 unsigned ListInitialization : 1;
1193 unsigned StdInitListInitialization : 1;
1194 unsigned ZeroInitialization : 1;
1195 unsigned ConstructKind : 2;
1198 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1201 CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1203 CXXConstructorDecl *Ctor,
1205 ArrayRef<Expr *> Args,
1206 bool HadMultipleCandidates,
1207 bool ListInitialization,
1208 bool StdInitListInitialization,
1209 bool ZeroInitialization,
1210 ConstructionKind ConstructKind,
1211 SourceRange ParenOrBraceRange);
1213 /// \brief Construct an empty C++ construction expression.
1214 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1215 : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
1216 HadMultipleCandidates(false), ListInitialization(false),
1217 ZeroInitialization(false), ConstructKind(0), Args(nullptr)
1221 /// \brief Construct an empty C++ construction expression.
1222 explicit CXXConstructExpr(EmptyShell Empty)
1223 : CXXConstructExpr(CXXConstructExprClass, Empty) {}
1225 static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1227 CXXConstructorDecl *Ctor,
1229 ArrayRef<Expr *> Args,
1230 bool HadMultipleCandidates,
1231 bool ListInitialization,
1232 bool StdInitListInitialization,
1233 bool ZeroInitialization,
1234 ConstructionKind ConstructKind,
1235 SourceRange ParenOrBraceRange);
1237 /// \brief Get the constructor that this expression will (ultimately) call.
1238 CXXConstructorDecl *getConstructor() const { return Constructor; }
1240 SourceLocation getLocation() const { return Loc; }
1241 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1243 /// \brief Whether this construction is elidable.
1244 bool isElidable() const { return Elidable; }
1245 void setElidable(bool E) { Elidable = E; }
1247 /// \brief Whether the referred constructor was resolved from
1248 /// an overloaded set having size greater than 1.
1249 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1250 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1252 /// \brief Whether this constructor call was written as list-initialization.
1253 bool isListInitialization() const { return ListInitialization; }
1254 void setListInitialization(bool V) { ListInitialization = V; }
1256 /// \brief Whether this constructor call was written as list-initialization,
1257 /// but was interpreted as forming a std::initializer_list<T> from the list
1258 /// and passing that as a single constructor argument.
1259 /// See C++11 [over.match.list]p1 bullet 1.
1260 bool isStdInitListInitialization() const { return StdInitListInitialization; }
1261 void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1263 /// \brief Whether this construction first requires
1264 /// zero-initialization before the initializer is called.
1265 bool requiresZeroInitialization() const { return ZeroInitialization; }
1266 void setRequiresZeroInitialization(bool ZeroInit) {
1267 ZeroInitialization = ZeroInit;
1270 /// \brief Determine whether this constructor is actually constructing
1271 /// a base class (rather than a complete object).
1272 ConstructionKind getConstructionKind() const {
1273 return (ConstructionKind)ConstructKind;
1275 void setConstructionKind(ConstructionKind CK) {
1279 typedef ExprIterator arg_iterator;
1280 typedef ConstExprIterator const_arg_iterator;
1281 typedef llvm::iterator_range<arg_iterator> arg_range;
1282 typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
1284 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1285 arg_const_range arguments() const {
1286 return arg_const_range(arg_begin(), arg_end());
1289 arg_iterator arg_begin() { return Args; }
1290 arg_iterator arg_end() { return Args + NumArgs; }
1291 const_arg_iterator arg_begin() const { return Args; }
1292 const_arg_iterator arg_end() const { return Args + NumArgs; }
1294 Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
1295 const Expr *const *getArgs() const {
1296 return const_cast<CXXConstructExpr *>(this)->getArgs();
1298 unsigned getNumArgs() const { return NumArgs; }
1300 /// \brief Return the specified argument.
1301 Expr *getArg(unsigned Arg) {
1302 assert(Arg < NumArgs && "Arg access out of range!");
1303 return cast<Expr>(Args[Arg]);
1305 const Expr *getArg(unsigned Arg) const {
1306 assert(Arg < NumArgs && "Arg access out of range!");
1307 return cast<Expr>(Args[Arg]);
1310 /// \brief Set the specified argument.
1311 void setArg(unsigned Arg, Expr *ArgExpr) {
1312 assert(Arg < NumArgs && "Arg access out of range!");
1313 Args[Arg] = ArgExpr;
1316 SourceLocation getLocStart() const LLVM_READONLY;
1317 SourceLocation getLocEnd() const LLVM_READONLY;
1318 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1319 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1321 static bool classof(const Stmt *T) {
1322 return T->getStmtClass() == CXXConstructExprClass ||
1323 T->getStmtClass() == CXXTemporaryObjectExprClass;
1327 child_range children() {
1328 return child_range(&Args[0], &Args[0]+NumArgs);
1331 friend class ASTStmtReader;
1334 /// \brief Represents a call to an inherited base class constructor from an
1335 /// inheriting constructor. This call implicitly forwards the arguments from
1336 /// the enclosing context (an inheriting constructor) to the specified inherited
1337 /// base class constructor.
1338 class CXXInheritedCtorInitExpr : public Expr {
1340 CXXConstructorDecl *Constructor;
1342 /// The location of the using declaration.
1345 /// Whether this is the construction of a virtual base.
1346 unsigned ConstructsVirtualBase : 1;
1348 /// Whether the constructor is inherited from a virtual base class of the
1349 /// class that we construct.
1350 unsigned InheritedFromVirtualBase : 1;
1353 /// \brief Construct a C++ inheriting construction expression.
1354 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1355 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1356 bool InheritedFromVirtualBase)
1357 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1358 false, false, false),
1359 Constructor(Ctor), Loc(Loc),
1360 ConstructsVirtualBase(ConstructsVirtualBase),
1361 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1362 assert(!T->isDependentType());
1365 /// \brief Construct an empty C++ inheriting construction expression.
1366 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1367 : Expr(CXXInheritedCtorInitExprClass, Empty), Constructor(nullptr),
1368 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1370 /// \brief Get the constructor that this expression will call.
1371 CXXConstructorDecl *getConstructor() const { return Constructor; }
1373 /// \brief Determine whether this constructor is actually constructing
1374 /// a base class (rather than a complete object).
1375 bool constructsVBase() const { return ConstructsVirtualBase; }
1376 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1377 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1378 : CXXConstructExpr::CK_NonVirtualBase;
1381 /// \brief Determine whether the inherited constructor is inherited from a
1382 /// virtual base of the object we construct. If so, we are not responsible
1383 /// for calling the inherited constructor (the complete object constructor
1384 /// does that), and so we don't need to pass any arguments.
1385 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1387 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1388 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1389 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1391 static bool classof(const Stmt *T) {
1392 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1394 child_range children() {
1395 return child_range(child_iterator(), child_iterator());
1398 friend class ASTStmtReader;
1401 /// \brief Represents an explicit C++ type conversion that uses "functional"
1402 /// notation (C++ [expr.type.conv]).
1408 class CXXFunctionalCastExpr final
1409 : public ExplicitCastExpr,
1410 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1411 SourceLocation LParenLoc;
1412 SourceLocation RParenLoc;
1414 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1415 TypeSourceInfo *writtenTy,
1416 CastKind kind, Expr *castExpr, unsigned pathSize,
1417 SourceLocation lParenLoc, SourceLocation rParenLoc)
1418 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1419 castExpr, pathSize, writtenTy),
1420 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1422 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1423 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1426 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1428 TypeSourceInfo *Written,
1429 CastKind Kind, Expr *Op,
1430 const CXXCastPath *Path,
1431 SourceLocation LPLoc,
1432 SourceLocation RPLoc);
1433 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1436 SourceLocation getLParenLoc() const { return LParenLoc; }
1437 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1438 SourceLocation getRParenLoc() const { return RParenLoc; }
1439 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1441 SourceLocation getLocStart() const LLVM_READONLY;
1442 SourceLocation getLocEnd() const LLVM_READONLY;
1444 static bool classof(const Stmt *T) {
1445 return T->getStmtClass() == CXXFunctionalCastExprClass;
1448 friend TrailingObjects;
1449 friend class CastExpr;
1452 /// @brief Represents a C++ functional cast expression that builds a
1453 /// temporary object.
1455 /// This expression type represents a C++ "functional" cast
1456 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1457 /// constructor to build a temporary object. With N == 1 arguments the
1458 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1461 /// struct X { X(int, float); }
1464 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1467 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1468 TypeSourceInfo *Type;
1471 CXXTemporaryObjectExpr(const ASTContext &C,
1472 CXXConstructorDecl *Cons,
1473 TypeSourceInfo *Type,
1474 ArrayRef<Expr *> Args,
1475 SourceRange ParenOrBraceRange,
1476 bool HadMultipleCandidates,
1477 bool ListInitialization,
1478 bool StdInitListInitialization,
1479 bool ZeroInitialization);
1480 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1481 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1483 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1485 SourceLocation getLocStart() const LLVM_READONLY;
1486 SourceLocation getLocEnd() const LLVM_READONLY;
1488 static bool classof(const Stmt *T) {
1489 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1492 friend class ASTStmtReader;
1495 /// \brief A C++ lambda expression, which produces a function object
1496 /// (of unspecified type) that can be invoked later.
1500 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1501 /// values.erase(std::remove_if(values.begin(), values.end(),
1502 /// [=](double value) { return value > cutoff; });
1506 /// C++11 lambda expressions can capture local variables, either by copying
1507 /// the values of those local variables at the time the function
1508 /// object is constructed (not when it is called!) or by holding a
1509 /// reference to the local variable. These captures can occur either
1510 /// implicitly or can be written explicitly between the square
1511 /// brackets ([...]) that start the lambda expression.
1513 /// C++1y introduces a new form of "capture" called an init-capture that
1514 /// includes an initializing expression (rather than capturing a variable),
1515 /// and which can never occur implicitly.
1516 class LambdaExpr final : public Expr,
1517 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1518 /// \brief The source range that covers the lambda introducer ([...]).
1519 SourceRange IntroducerRange;
1521 /// \brief The source location of this lambda's capture-default ('=' or '&').
1522 SourceLocation CaptureDefaultLoc;
1524 /// \brief The number of captures.
1525 unsigned NumCaptures : 16;
1527 /// \brief The default capture kind, which is a value of type
1528 /// LambdaCaptureDefault.
1529 unsigned CaptureDefault : 2;
1531 /// \brief Whether this lambda had an explicit parameter list vs. an
1532 /// implicit (and empty) parameter list.
1533 unsigned ExplicitParams : 1;
1535 /// \brief Whether this lambda had the result type explicitly specified.
1536 unsigned ExplicitResultType : 1;
1538 /// \brief The location of the closing brace ('}') that completes
1541 /// The location of the brace is also available by looking up the
1542 /// function call operator in the lambda class. However, it is
1543 /// stored here to improve the performance of getSourceRange(), and
1544 /// to avoid having to deserialize the function call operator from a
1545 /// module file just to determine the source range.
1546 SourceLocation ClosingBrace;
1548 /// \brief Construct a lambda expression.
1549 LambdaExpr(QualType T, SourceRange IntroducerRange,
1550 LambdaCaptureDefault CaptureDefault,
1551 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1552 bool ExplicitParams, bool ExplicitResultType,
1553 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1554 bool ContainsUnexpandedParameterPack);
1556 /// \brief Construct an empty lambda expression.
1557 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1558 : Expr(LambdaExprClass, Empty),
1559 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1560 ExplicitResultType(false) {
1561 getStoredStmts()[NumCaptures] = nullptr;
1564 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1566 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1569 /// \brief Construct a new lambda expression.
1571 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1572 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1573 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1574 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1575 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1577 /// \brief Construct a new lambda expression that will be deserialized from
1578 /// an external source.
1579 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1580 unsigned NumCaptures);
1582 /// \brief Determine the default capture kind for this lambda.
1583 LambdaCaptureDefault getCaptureDefault() const {
1584 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1587 /// \brief Retrieve the location of this lambda's capture-default, if any.
1588 SourceLocation getCaptureDefaultLoc() const {
1589 return CaptureDefaultLoc;
1592 /// \brief Determine whether one of this lambda's captures is an init-capture.
1593 bool isInitCapture(const LambdaCapture *Capture) const;
1595 /// \brief An iterator that walks over the captures of the lambda,
1596 /// both implicit and explicit.
1597 typedef const LambdaCapture *capture_iterator;
1599 /// \brief An iterator over a range of lambda captures.
1600 typedef llvm::iterator_range<capture_iterator> capture_range;
1602 /// \brief Retrieve this lambda's captures.
1603 capture_range captures() const;
1605 /// \brief Retrieve an iterator pointing to the first lambda capture.
1606 capture_iterator capture_begin() const;
1608 /// \brief Retrieve an iterator pointing past the end of the
1609 /// sequence of lambda captures.
1610 capture_iterator capture_end() const;
1612 /// \brief Determine the number of captures in this lambda.
1613 unsigned capture_size() const { return NumCaptures; }
1615 /// \brief Retrieve this lambda's explicit captures.
1616 capture_range explicit_captures() const;
1618 /// \brief Retrieve an iterator pointing to the first explicit
1620 capture_iterator explicit_capture_begin() const;
1622 /// \brief Retrieve an iterator pointing past the end of the sequence of
1623 /// explicit lambda captures.
1624 capture_iterator explicit_capture_end() const;
1626 /// \brief Retrieve this lambda's implicit captures.
1627 capture_range implicit_captures() const;
1629 /// \brief Retrieve an iterator pointing to the first implicit
1631 capture_iterator implicit_capture_begin() const;
1633 /// \brief Retrieve an iterator pointing past the end of the sequence of
1634 /// implicit lambda captures.
1635 capture_iterator implicit_capture_end() const;
1637 /// \brief Iterator that walks over the capture initialization
1639 typedef Expr **capture_init_iterator;
1641 /// \brief Const iterator that walks over the capture initialization
1643 typedef Expr *const *const_capture_init_iterator;
1645 /// \brief Retrieve the initialization expressions for this lambda's captures.
1646 llvm::iterator_range<capture_init_iterator> capture_inits() {
1647 return llvm::make_range(capture_init_begin(), capture_init_end());
1650 /// \brief Retrieve the initialization expressions for this lambda's captures.
1651 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1652 return llvm::make_range(capture_init_begin(), capture_init_end());
1655 /// \brief Retrieve the first initialization argument for this
1656 /// lambda expression (which initializes the first capture field).
1657 capture_init_iterator capture_init_begin() {
1658 return reinterpret_cast<Expr **>(getStoredStmts());
1661 /// \brief Retrieve the first initialization argument for this
1662 /// lambda expression (which initializes the first capture field).
1663 const_capture_init_iterator capture_init_begin() const {
1664 return reinterpret_cast<Expr *const *>(getStoredStmts());
1667 /// \brief Retrieve the iterator pointing one past the last
1668 /// initialization argument for this lambda expression.
1669 capture_init_iterator capture_init_end() {
1670 return capture_init_begin() + NumCaptures;
1673 /// \brief Retrieve the iterator pointing one past the last
1674 /// initialization argument for this lambda expression.
1675 const_capture_init_iterator capture_init_end() const {
1676 return capture_init_begin() + NumCaptures;
1679 /// \brief Retrieve the source range covering the lambda introducer,
1680 /// which contains the explicit capture list surrounded by square
1681 /// brackets ([...]).
1682 SourceRange getIntroducerRange() const { return IntroducerRange; }
1684 /// \brief Retrieve the class that corresponds to the lambda.
1686 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1687 /// captures in its fields and provides the various operations permitted
1688 /// on a lambda (copying, calling).
1689 CXXRecordDecl *getLambdaClass() const;
1691 /// \brief Retrieve the function call operator associated with this
1692 /// lambda expression.
1693 CXXMethodDecl *getCallOperator() const;
1695 /// \brief If this is a generic lambda expression, retrieve the template
1696 /// parameter list associated with it, or else return null.
1697 TemplateParameterList *getTemplateParameterList() const;
1699 /// \brief Whether this is a generic lambda.
1700 bool isGenericLambda() const { return getTemplateParameterList(); }
1702 /// \brief Retrieve the body of the lambda.
1703 CompoundStmt *getBody() const;
1705 /// \brief Determine whether the lambda is mutable, meaning that any
1706 /// captures values can be modified.
1707 bool isMutable() const;
1709 /// \brief Determine whether this lambda has an explicit parameter
1710 /// list vs. an implicit (empty) parameter list.
1711 bool hasExplicitParameters() const { return ExplicitParams; }
1713 /// \brief Whether this lambda had its result type explicitly specified.
1714 bool hasExplicitResultType() const { return ExplicitResultType; }
1716 static bool classof(const Stmt *T) {
1717 return T->getStmtClass() == LambdaExprClass;
1720 SourceLocation getLocStart() const LLVM_READONLY {
1721 return IntroducerRange.getBegin();
1723 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1725 child_range children() {
1726 // Includes initialization exprs plus body stmt
1727 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1730 friend TrailingObjects;
1731 friend class ASTStmtReader;
1732 friend class ASTStmtWriter;
1735 /// An expression "T()" which creates a value-initialized rvalue of type
1736 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
1737 class CXXScalarValueInitExpr : public Expr {
1738 SourceLocation RParenLoc;
1739 TypeSourceInfo *TypeInfo;
1741 friend class ASTStmtReader;
1744 /// \brief Create an explicitly-written scalar-value initialization
1746 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1747 SourceLocation rParenLoc)
1748 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1749 false, false, Type->isInstantiationDependentType(),
1750 Type->containsUnexpandedParameterPack()),
1751 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1753 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1754 : Expr(CXXScalarValueInitExprClass, Shell) { }
1756 TypeSourceInfo *getTypeSourceInfo() const {
1760 SourceLocation getRParenLoc() const { return RParenLoc; }
1762 SourceLocation getLocStart() const LLVM_READONLY;
1763 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1765 static bool classof(const Stmt *T) {
1766 return T->getStmtClass() == CXXScalarValueInitExprClass;
1770 child_range children() {
1771 return child_range(child_iterator(), child_iterator());
1775 /// \brief Represents a new-expression for memory allocation and constructor
1776 /// calls, e.g: "new CXXNewExpr(foo)".
1777 class CXXNewExpr : public Expr {
1778 /// Contains an optional array size expression, an optional initialization
1779 /// expression, and any number of optional placement arguments, in that order.
1781 /// \brief Points to the allocation function used.
1782 FunctionDecl *OperatorNew;
1783 /// \brief Points to the deallocation function used in case of error. May be
1785 FunctionDecl *OperatorDelete;
1787 /// \brief The allocated type-source information, as written in the source.
1788 TypeSourceInfo *AllocatedTypeInfo;
1790 /// \brief If the allocated type was expressed as a parenthesized type-id,
1791 /// the source range covering the parenthesized type-id.
1792 SourceRange TypeIdParens;
1794 /// \brief Range of the entire new expression.
1797 /// \brief Source-range of a paren-delimited initializer.
1798 SourceRange DirectInitRange;
1800 /// Was the usage ::new, i.e. is the global new to be used?
1801 unsigned GlobalNew : 1;
1802 /// Do we allocate an array? If so, the first SubExpr is the size expression.
1804 /// Should the alignment be passed to the allocation function?
1805 unsigned PassAlignment : 1;
1806 /// If this is an array allocation, does the usual deallocation
1807 /// function for the allocated type want to know the allocated size?
1808 unsigned UsualArrayDeleteWantsSize : 1;
1809 /// The number of placement new arguments.
1810 unsigned NumPlacementArgs : 26;
1811 /// What kind of initializer do we have? Could be none, parens, or braces.
1812 /// In storage, we distinguish between "none, and no initializer expr", and
1813 /// "none, but an implicit initializer expr".
1814 unsigned StoredInitializationStyle : 2;
1816 friend class ASTStmtReader;
1817 friend class ASTStmtWriter;
1819 enum InitializationStyle {
1820 NoInit, ///< New-expression has no initializer as written.
1821 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1822 ListInit ///< New-expression has a C++11 list-initializer.
1825 CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1826 FunctionDecl *operatorDelete, bool PassAlignment,
1827 bool usualArrayDeleteWantsSize, ArrayRef<Expr*> placementArgs,
1828 SourceRange typeIdParens, Expr *arraySize,
1829 InitializationStyle initializationStyle, Expr *initializer,
1830 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1831 SourceRange Range, SourceRange directInitRange);
1832 explicit CXXNewExpr(EmptyShell Shell)
1833 : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
1835 void AllocateArgsArray(const ASTContext &C, bool isArray,
1836 unsigned numPlaceArgs, bool hasInitializer);
1838 QualType getAllocatedType() const {
1839 assert(getType()->isPointerType());
1840 return getType()->getAs<PointerType>()->getPointeeType();
1843 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1844 return AllocatedTypeInfo;
1847 /// \brief True if the allocation result needs to be null-checked.
1849 /// C++11 [expr.new]p13:
1850 /// If the allocation function returns null, initialization shall
1851 /// not be done, the deallocation function shall not be called,
1852 /// and the value of the new-expression shall be null.
1855 /// If the allocation function is a reserved placement allocation
1856 /// function that returns null, the behavior is undefined.
1858 /// An allocation function is not allowed to return null unless it
1859 /// has a non-throwing exception-specification. The '03 rule is
1860 /// identical except that the definition of a non-throwing
1861 /// exception specification is just "is it throw()?".
1862 bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1864 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1865 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1866 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1867 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1869 bool isArray() const { return Array; }
1870 Expr *getArraySize() {
1871 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1873 const Expr *getArraySize() const {
1874 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1877 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1878 Expr **getPlacementArgs() {
1879 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1882 Expr *getPlacementArg(unsigned i) {
1883 assert(i < NumPlacementArgs && "Index out of range");
1884 return getPlacementArgs()[i];
1886 const Expr *getPlacementArg(unsigned i) const {
1887 assert(i < NumPlacementArgs && "Index out of range");
1888 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1891 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1892 SourceRange getTypeIdParens() const { return TypeIdParens; }
1894 bool isGlobalNew() const { return GlobalNew; }
1896 /// \brief Whether this new-expression has any initializer at all.
1897 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1899 /// \brief The kind of initializer this new-expression has.
1900 InitializationStyle getInitializationStyle() const {
1901 if (StoredInitializationStyle == 0)
1903 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1906 /// \brief The initializer of this new-expression.
1907 Expr *getInitializer() {
1908 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1910 const Expr *getInitializer() const {
1911 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1914 /// \brief Returns the CXXConstructExpr from this new-expression, or null.
1915 const CXXConstructExpr *getConstructExpr() const {
1916 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1919 /// Indicates whether the required alignment should be implicitly passed to
1920 /// the allocation function.
1921 bool passAlignment() const {
1922 return PassAlignment;
1925 /// Answers whether the usual array deallocation function for the
1926 /// allocated type expects the size of the allocation as a
1928 bool doesUsualArrayDeleteWantSize() const {
1929 return UsualArrayDeleteWantsSize;
1932 typedef ExprIterator arg_iterator;
1933 typedef ConstExprIterator const_arg_iterator;
1935 llvm::iterator_range<arg_iterator> placement_arguments() {
1936 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1939 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
1940 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1943 arg_iterator placement_arg_begin() {
1944 return SubExprs + Array + hasInitializer();
1946 arg_iterator placement_arg_end() {
1947 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1949 const_arg_iterator placement_arg_begin() const {
1950 return SubExprs + Array + hasInitializer();
1952 const_arg_iterator placement_arg_end() const {
1953 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1956 typedef Stmt **raw_arg_iterator;
1957 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1958 raw_arg_iterator raw_arg_end() {
1959 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1961 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1962 const_arg_iterator raw_arg_end() const {
1963 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1966 SourceLocation getStartLoc() const { return Range.getBegin(); }
1967 SourceLocation getEndLoc() const { return Range.getEnd(); }
1969 SourceRange getDirectInitRange() const { return DirectInitRange; }
1971 SourceRange getSourceRange() const LLVM_READONLY {
1974 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
1975 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1977 static bool classof(const Stmt *T) {
1978 return T->getStmtClass() == CXXNewExprClass;
1982 child_range children() {
1983 return child_range(raw_arg_begin(), raw_arg_end());
1987 /// \brief Represents a \c delete expression for memory deallocation and
1988 /// destructor calls, e.g. "delete[] pArray".
1989 class CXXDeleteExpr : public Expr {
1990 /// Points to the operator delete overload that is used. Could be a member.
1991 FunctionDecl *OperatorDelete;
1992 /// The pointer expression to be deleted.
1994 /// Location of the expression.
1996 /// Is this a forced global delete, i.e. "::delete"?
1997 bool GlobalDelete : 1;
1998 /// Is this the array form of delete, i.e. "delete[]"?
2000 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
2001 /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
2003 bool ArrayFormAsWritten : 1;
2004 /// Does the usual deallocation function for the element type require
2005 /// a size_t argument?
2006 bool UsualArrayDeleteWantsSize : 1;
2008 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
2009 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
2010 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
2011 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
2012 arg->isInstantiationDependent(),
2013 arg->containsUnexpandedParameterPack()),
2014 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
2015 GlobalDelete(globalDelete),
2016 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
2017 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
2018 explicit CXXDeleteExpr(EmptyShell Shell)
2019 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
2020 Argument(nullptr) {}
2022 bool isGlobalDelete() const { return GlobalDelete; }
2023 bool isArrayForm() const { return ArrayForm; }
2024 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
2026 /// Answers whether the usual array deallocation function for the
2027 /// allocated type expects the size of the allocation as a
2028 /// parameter. This can be true even if the actual deallocation
2029 /// function that we're using doesn't want a size.
2030 bool doesUsualArrayDeleteWantSize() const {
2031 return UsualArrayDeleteWantsSize;
2034 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2036 Expr *getArgument() { return cast<Expr>(Argument); }
2037 const Expr *getArgument() const { return cast<Expr>(Argument); }
2039 /// \brief Retrieve the type being destroyed.
2041 /// If the type being destroyed is a dependent type which may or may not
2042 /// be a pointer, return an invalid type.
2043 QualType getDestroyedType() const;
2045 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2046 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
2048 static bool classof(const Stmt *T) {
2049 return T->getStmtClass() == CXXDeleteExprClass;
2053 child_range children() { return child_range(&Argument, &Argument+1); }
2055 friend class ASTStmtReader;
2058 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
2059 class PseudoDestructorTypeStorage {
2060 /// \brief Either the type source information or the name of the type, if
2061 /// it couldn't be resolved due to type-dependence.
2062 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2064 /// \brief The starting source location of the pseudo-destructor type.
2065 SourceLocation Location;
2068 PseudoDestructorTypeStorage() { }
2070 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2071 : Type(II), Location(Loc) { }
2073 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2075 TypeSourceInfo *getTypeSourceInfo() const {
2076 return Type.dyn_cast<TypeSourceInfo *>();
2079 IdentifierInfo *getIdentifier() const {
2080 return Type.dyn_cast<IdentifierInfo *>();
2083 SourceLocation getLocation() const { return Location; }
2086 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2088 /// A pseudo-destructor is an expression that looks like a member access to a
2089 /// destructor of a scalar type, except that scalar types don't have
2090 /// destructors. For example:
2094 /// void f(int *p) {
2099 /// Pseudo-destructors typically occur when instantiating templates such as:
2102 /// template<typename T>
2103 /// void destroy(T* ptr) {
2108 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2109 /// beyond evaluating the base expression.
2110 class CXXPseudoDestructorExpr : public Expr {
2111 /// \brief The base expression (that is being destroyed).
2114 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
2118 /// \brief The location of the '.' or '->' operator.
2119 SourceLocation OperatorLoc;
2121 /// \brief The nested-name-specifier that follows the operator, if present.
2122 NestedNameSpecifierLoc QualifierLoc;
2124 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
2126 TypeSourceInfo *ScopeType;
2128 /// \brief The location of the '::' in a qualified pseudo-destructor
2130 SourceLocation ColonColonLoc;
2132 /// \brief The location of the '~'.
2133 SourceLocation TildeLoc;
2135 /// \brief The type being destroyed, or its name if we were unable to
2136 /// resolve the name.
2137 PseudoDestructorTypeStorage DestroyedType;
2139 friend class ASTStmtReader;
2142 CXXPseudoDestructorExpr(const ASTContext &Context,
2143 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2144 NestedNameSpecifierLoc QualifierLoc,
2145 TypeSourceInfo *ScopeType,
2146 SourceLocation ColonColonLoc,
2147 SourceLocation TildeLoc,
2148 PseudoDestructorTypeStorage DestroyedType);
2150 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2151 : Expr(CXXPseudoDestructorExprClass, Shell),
2152 Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
2154 Expr *getBase() const { return cast<Expr>(Base); }
2156 /// \brief Determines whether this member expression actually had
2157 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2159 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2161 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
2162 /// with source-location information.
2163 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2165 /// \brief If the member name was qualified, retrieves the
2166 /// nested-name-specifier that precedes the member name. Otherwise, returns
2168 NestedNameSpecifier *getQualifier() const {
2169 return QualifierLoc.getNestedNameSpecifier();
2172 /// \brief Determine whether this pseudo-destructor expression was written
2173 /// using an '->' (otherwise, it used a '.').
2174 bool isArrow() const { return IsArrow; }
2176 /// \brief Retrieve the location of the '.' or '->' operator.
2177 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2179 /// \brief Retrieve the scope type in a qualified pseudo-destructor
2182 /// Pseudo-destructor expressions can have extra qualification within them
2183 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2184 /// Here, if the object type of the expression is (or may be) a scalar type,
2185 /// \p T may also be a scalar type and, therefore, cannot be part of a
2186 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2187 /// destructor expression.
2188 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2190 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2192 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2194 /// \brief Retrieve the location of the '~'.
2195 SourceLocation getTildeLoc() const { return TildeLoc; }
2197 /// \brief Retrieve the source location information for the type
2198 /// being destroyed.
2200 /// This type-source information is available for non-dependent
2201 /// pseudo-destructor expressions and some dependent pseudo-destructor
2202 /// expressions. Returns null if we only have the identifier for a
2203 /// dependent pseudo-destructor expression.
2204 TypeSourceInfo *getDestroyedTypeInfo() const {
2205 return DestroyedType.getTypeSourceInfo();
2208 /// \brief In a dependent pseudo-destructor expression for which we do not
2209 /// have full type information on the destroyed type, provides the name
2210 /// of the destroyed type.
2211 IdentifierInfo *getDestroyedTypeIdentifier() const {
2212 return DestroyedType.getIdentifier();
2215 /// \brief Retrieve the type being destroyed.
2216 QualType getDestroyedType() const;
2218 /// \brief Retrieve the starting location of the type being destroyed.
2219 SourceLocation getDestroyedTypeLoc() const {
2220 return DestroyedType.getLocation();
2223 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2225 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2226 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2229 /// \brief Set the destroyed type.
2230 void setDestroyedType(TypeSourceInfo *Info) {
2231 DestroyedType = PseudoDestructorTypeStorage(Info);
2234 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2235 SourceLocation getLocEnd() const LLVM_READONLY;
2237 static bool classof(const Stmt *T) {
2238 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2242 child_range children() { return child_range(&Base, &Base + 1); }
2245 /// \brief A type trait used in the implementation of various C++11 and
2246 /// Library TR1 trait templates.
2249 /// __is_pod(int) == true
2250 /// __is_enum(std::string) == false
2251 /// __is_trivially_constructible(vector<int>, int*, int*)
2253 class TypeTraitExpr final
2255 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2256 /// \brief The location of the type trait keyword.
2259 /// \brief The location of the closing parenthesis.
2260 SourceLocation RParenLoc;
2262 // Note: The TypeSourceInfos for the arguments are allocated after the
2265 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2266 ArrayRef<TypeSourceInfo *> Args,
2267 SourceLocation RParenLoc,
2270 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2272 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2273 return getNumArgs();
2277 /// \brief Create a new type trait expression.
2278 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2279 SourceLocation Loc, TypeTrait Kind,
2280 ArrayRef<TypeSourceInfo *> Args,
2281 SourceLocation RParenLoc,
2284 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2287 /// \brief Determine which type trait this expression uses.
2288 TypeTrait getTrait() const {
2289 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2292 bool getValue() const {
2293 assert(!isValueDependent());
2294 return TypeTraitExprBits.Value;
2297 /// \brief Determine the number of arguments to this type trait.
2298 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2300 /// \brief Retrieve the Ith argument.
2301 TypeSourceInfo *getArg(unsigned I) const {
2302 assert(I < getNumArgs() && "Argument out-of-range");
2303 return getArgs()[I];
2306 /// \brief Retrieve the argument types.
2307 ArrayRef<TypeSourceInfo *> getArgs() const {
2308 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2312 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2313 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2315 static bool classof(const Stmt *T) {
2316 return T->getStmtClass() == TypeTraitExprClass;
2320 child_range children() {
2321 return child_range(child_iterator(), child_iterator());
2324 friend TrailingObjects;
2325 friend class ASTStmtReader;
2326 friend class ASTStmtWriter;
2329 /// \brief An Embarcadero array type trait, as used in the implementation of
2330 /// __array_rank and __array_extent.
2334 /// __array_rank(int[10][20]) == 2
2335 /// __array_extent(int, 1) == 20
2337 class ArrayTypeTraitExpr : public Expr {
2338 virtual void anchor();
2340 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2343 /// \brief The value of the type trait. Unspecified if dependent.
2346 /// \brief The array dimension being queried, or -1 if not used.
2349 /// \brief The location of the type trait keyword.
2352 /// \brief The location of the closing paren.
2353 SourceLocation RParen;
2355 /// \brief The type being queried.
2356 TypeSourceInfo *QueriedType;
2359 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2360 TypeSourceInfo *queried, uint64_t value,
2361 Expr *dimension, SourceLocation rparen, QualType ty)
2362 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2363 false, queried->getType()->isDependentType(),
2364 (queried->getType()->isInstantiationDependentType() ||
2365 (dimension && dimension->isInstantiationDependent())),
2366 queried->getType()->containsUnexpandedParameterPack()),
2367 ATT(att), Value(value), Dimension(dimension),
2368 Loc(loc), RParen(rparen), QueriedType(queried) { }
2371 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2372 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2375 virtual ~ArrayTypeTraitExpr() { }
2377 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2378 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2380 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2382 QualType getQueriedType() const { return QueriedType->getType(); }
2384 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2386 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2388 Expr *getDimensionExpression() const { return Dimension; }
2390 static bool classof(const Stmt *T) {
2391 return T->getStmtClass() == ArrayTypeTraitExprClass;
2395 child_range children() {
2396 return child_range(child_iterator(), child_iterator());
2399 friend class ASTStmtReader;
2402 /// \brief An expression trait intrinsic.
2406 /// __is_lvalue_expr(std::cout) == true
2407 /// __is_lvalue_expr(1) == false
2409 class ExpressionTraitExpr : public Expr {
2410 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2412 /// \brief The value of the type trait. Unspecified if dependent.
2415 /// \brief The location of the type trait keyword.
2418 /// \brief The location of the closing paren.
2419 SourceLocation RParen;
2421 /// \brief The expression being queried.
2422 Expr* QueriedExpression;
2424 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2425 Expr *queried, bool value,
2426 SourceLocation rparen, QualType resultType)
2427 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2428 false, // Not type-dependent
2429 // Value-dependent if the argument is type-dependent.
2430 queried->isTypeDependent(),
2431 queried->isInstantiationDependent(),
2432 queried->containsUnexpandedParameterPack()),
2433 ET(et), Value(value), Loc(loc), RParen(rparen),
2434 QueriedExpression(queried) { }
2436 explicit ExpressionTraitExpr(EmptyShell Empty)
2437 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2438 QueriedExpression() { }
2440 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2441 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2443 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2445 Expr *getQueriedExpression() const { return QueriedExpression; }
2447 bool getValue() const { return Value; }
2449 static bool classof(const Stmt *T) {
2450 return T->getStmtClass() == ExpressionTraitExprClass;
2454 child_range children() {
2455 return child_range(child_iterator(), child_iterator());
2458 friend class ASTStmtReader;
2462 /// \brief A reference to an overloaded function set, either an
2463 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2464 class OverloadExpr : public Expr {
2465 /// \brief The common name of these declarations.
2466 DeclarationNameInfo NameInfo;
2468 /// \brief The nested-name-specifier that qualifies the name, if any.
2469 NestedNameSpecifierLoc QualifierLoc;
2471 /// The results. These are undesugared, which is to say, they may
2472 /// include UsingShadowDecls. Access is relative to the naming
2474 // FIXME: Allocate this data after the OverloadExpr subclass.
2475 DeclAccessPair *Results;
2476 unsigned NumResults;
2479 /// \brief Whether the name includes info for explicit template
2480 /// keyword and arguments.
2481 bool HasTemplateKWAndArgsInfo;
2483 /// \brief Return the optional template keyword and arguments info.
2484 ASTTemplateKWAndArgsInfo *
2485 getTrailingASTTemplateKWAndArgsInfo(); // defined far below.
2487 /// \brief Return the optional template keyword and arguments info.
2488 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2489 return const_cast<OverloadExpr *>(this)
2490 ->getTrailingASTTemplateKWAndArgsInfo();
2493 /// Return the optional template arguments.
2494 TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); // defined far below
2496 OverloadExpr(StmtClass K, const ASTContext &C,
2497 NestedNameSpecifierLoc QualifierLoc,
2498 SourceLocation TemplateKWLoc,
2499 const DeclarationNameInfo &NameInfo,
2500 const TemplateArgumentListInfo *TemplateArgs,
2501 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2502 bool KnownDependent,
2503 bool KnownInstantiationDependent,
2504 bool KnownContainsUnexpandedParameterPack);
2506 OverloadExpr(StmtClass K, EmptyShell Empty)
2507 : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
2508 HasTemplateKWAndArgsInfo(false) { }
2510 void initializeResults(const ASTContext &C,
2511 UnresolvedSetIterator Begin,
2512 UnresolvedSetIterator End);
2516 OverloadExpr *Expression;
2517 bool IsAddressOfOperand;
2518 bool HasFormOfMemberPointer;
2521 /// \brief Finds the overloaded expression in the given expression \p E of
2524 /// \return the expression (which must be there) and true if it has
2525 /// the particular form of a member pointer expression
2526 static FindResult find(Expr *E) {
2527 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2531 E = E->IgnoreParens();
2532 if (isa<UnaryOperator>(E)) {
2533 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2534 E = cast<UnaryOperator>(E)->getSubExpr();
2535 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2537 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2538 Result.IsAddressOfOperand = true;
2539 Result.Expression = Ovl;
2541 Result.HasFormOfMemberPointer = false;
2542 Result.IsAddressOfOperand = false;
2543 Result.Expression = cast<OverloadExpr>(E);
2549 /// \brief Gets the naming class of this lookup, if any.
2550 CXXRecordDecl *getNamingClass() const;
2552 typedef UnresolvedSetImpl::iterator decls_iterator;
2553 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2554 decls_iterator decls_end() const {
2555 return UnresolvedSetIterator(Results + NumResults);
2557 llvm::iterator_range<decls_iterator> decls() const {
2558 return llvm::make_range(decls_begin(), decls_end());
2561 /// \brief Gets the number of declarations in the unresolved set.
2562 unsigned getNumDecls() const { return NumResults; }
2564 /// \brief Gets the full name info.
2565 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2567 /// \brief Gets the name looked up.
2568 DeclarationName getName() const { return NameInfo.getName(); }
2570 /// \brief Gets the location of the name.
2571 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2573 /// \brief Fetches the nested-name qualifier, if one was given.
2574 NestedNameSpecifier *getQualifier() const {
2575 return QualifierLoc.getNestedNameSpecifier();
2578 /// \brief Fetches the nested-name qualifier with source-location
2579 /// information, if one was given.
2580 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2582 /// \brief Retrieve the location of the template keyword preceding
2583 /// this name, if any.
2584 SourceLocation getTemplateKeywordLoc() const {
2585 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2586 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2589 /// \brief Retrieve the location of the left angle bracket starting the
2590 /// explicit template argument list following the name, if any.
2591 SourceLocation getLAngleLoc() const {
2592 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2593 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2596 /// \brief Retrieve the location of the right angle bracket ending the
2597 /// explicit template argument list following the name, if any.
2598 SourceLocation getRAngleLoc() const {
2599 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2600 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2603 /// \brief Determines whether the name was preceded by the template keyword.
2604 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2606 /// \brief Determines whether this expression had explicit template arguments.
2607 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2609 TemplateArgumentLoc const *getTemplateArgs() const {
2610 if (!hasExplicitTemplateArgs())
2612 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2615 unsigned getNumTemplateArgs() const {
2616 if (!hasExplicitTemplateArgs())
2619 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
2622 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2623 return {getTemplateArgs(), getNumTemplateArgs()};
2626 /// \brief Copies the template arguments into the given structure.
2627 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2628 if (hasExplicitTemplateArgs())
2629 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
2632 static bool classof(const Stmt *T) {
2633 return T->getStmtClass() == UnresolvedLookupExprClass ||
2634 T->getStmtClass() == UnresolvedMemberExprClass;
2637 friend class ASTStmtReader;
2638 friend class ASTStmtWriter;
2641 /// \brief A reference to a name which we were able to look up during
2642 /// parsing but could not resolve to a specific declaration.
2644 /// This arises in several ways:
2645 /// * we might be waiting for argument-dependent lookup;
2646 /// * the name might resolve to an overloaded function;
2648 /// * the lookup might have included a function template.
2650 /// These never include UnresolvedUsingValueDecls, which are always class
2651 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2652 class UnresolvedLookupExpr final
2653 : public OverloadExpr,
2654 private llvm::TrailingObjects<
2655 UnresolvedLookupExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
2656 /// True if these lookup results should be extended by
2657 /// argument-dependent lookup if this is the operand of a function
2661 /// True if these lookup results are overloaded. This is pretty
2662 /// trivially rederivable if we urgently need to kill this field.
2665 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2666 /// any. This can generally be recalculated from the context chain,
2667 /// but that can be fairly expensive for unqualified lookups. If we
2668 /// want to improve memory use here, this could go in a union
2669 /// against the qualified-lookup bits.
2670 CXXRecordDecl *NamingClass;
2672 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2673 return HasTemplateKWAndArgsInfo ? 1 : 0;
2676 UnresolvedLookupExpr(const ASTContext &C,
2677 CXXRecordDecl *NamingClass,
2678 NestedNameSpecifierLoc QualifierLoc,
2679 SourceLocation TemplateKWLoc,
2680 const DeclarationNameInfo &NameInfo,
2681 bool RequiresADL, bool Overloaded,
2682 const TemplateArgumentListInfo *TemplateArgs,
2683 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2684 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2685 NameInfo, TemplateArgs, Begin, End, false, false, false),
2686 RequiresADL(RequiresADL),
2687 Overloaded(Overloaded), NamingClass(NamingClass)
2690 UnresolvedLookupExpr(EmptyShell Empty)
2691 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2692 RequiresADL(false), Overloaded(false), NamingClass(nullptr)
2695 friend TrailingObjects;
2696 friend class OverloadExpr;
2697 friend class ASTStmtReader;
2700 static UnresolvedLookupExpr *Create(const ASTContext &C,
2701 CXXRecordDecl *NamingClass,
2702 NestedNameSpecifierLoc QualifierLoc,
2703 const DeclarationNameInfo &NameInfo,
2704 bool ADL, bool Overloaded,
2705 UnresolvedSetIterator Begin,
2706 UnresolvedSetIterator End) {
2707 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2708 SourceLocation(), NameInfo,
2709 ADL, Overloaded, nullptr, Begin, End);
2712 static UnresolvedLookupExpr *Create(const ASTContext &C,
2713 CXXRecordDecl *NamingClass,
2714 NestedNameSpecifierLoc QualifierLoc,
2715 SourceLocation TemplateKWLoc,
2716 const DeclarationNameInfo &NameInfo,
2718 const TemplateArgumentListInfo *Args,
2719 UnresolvedSetIterator Begin,
2720 UnresolvedSetIterator End);
2722 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2723 bool HasTemplateKWAndArgsInfo,
2724 unsigned NumTemplateArgs);
2726 /// True if this declaration should be extended by
2727 /// argument-dependent lookup.
2728 bool requiresADL() const { return RequiresADL; }
2730 /// True if this lookup is overloaded.
2731 bool isOverloaded() const { return Overloaded; }
2733 /// Gets the 'naming class' (in the sense of C++0x
2734 /// [class.access.base]p5) of the lookup. This is the scope
2735 /// that was looked in to find these results.
2736 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2738 SourceLocation getLocStart() const LLVM_READONLY {
2739 if (NestedNameSpecifierLoc l = getQualifierLoc())
2740 return l.getBeginLoc();
2741 return getNameInfo().getLocStart();
2743 SourceLocation getLocEnd() const LLVM_READONLY {
2744 if (hasExplicitTemplateArgs())
2745 return getRAngleLoc();
2746 return getNameInfo().getLocEnd();
2749 child_range children() {
2750 return child_range(child_iterator(), child_iterator());
2753 static bool classof(const Stmt *T) {
2754 return T->getStmtClass() == UnresolvedLookupExprClass;
2758 /// \brief A qualified reference to a name whose declaration cannot
2759 /// yet be resolved.
2761 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2762 /// it expresses a reference to a declaration such as
2763 /// X<T>::value. The difference, however, is that an
2764 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2765 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2766 /// this case, X<T>::value cannot resolve to a declaration because the
2767 /// declaration will differ from one instantiation of X<T> to the
2768 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2769 /// qualifier (X<T>::) and the name of the entity being referenced
2770 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2771 /// declaration can be found.
2772 class DependentScopeDeclRefExpr final
2774 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
2775 ASTTemplateKWAndArgsInfo,
2776 TemplateArgumentLoc> {
2777 /// \brief The nested-name-specifier that qualifies this unresolved
2778 /// declaration name.
2779 NestedNameSpecifierLoc QualifierLoc;
2781 /// \brief The name of the entity we will be referencing.
2782 DeclarationNameInfo NameInfo;
2784 /// \brief Whether the name includes info for explicit template
2785 /// keyword and arguments.
2786 bool HasTemplateKWAndArgsInfo;
2788 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2789 return HasTemplateKWAndArgsInfo ? 1 : 0;
2792 DependentScopeDeclRefExpr(QualType T,
2793 NestedNameSpecifierLoc QualifierLoc,
2794 SourceLocation TemplateKWLoc,
2795 const DeclarationNameInfo &NameInfo,
2796 const TemplateArgumentListInfo *Args);
2799 static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2800 NestedNameSpecifierLoc QualifierLoc,
2801 SourceLocation TemplateKWLoc,
2802 const DeclarationNameInfo &NameInfo,
2803 const TemplateArgumentListInfo *TemplateArgs);
2805 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2806 bool HasTemplateKWAndArgsInfo,
2807 unsigned NumTemplateArgs);
2809 /// \brief Retrieve the name that this expression refers to.
2810 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2812 /// \brief Retrieve the name that this expression refers to.
2813 DeclarationName getDeclName() const { return NameInfo.getName(); }
2815 /// \brief Retrieve the location of the name within the expression.
2817 /// For example, in "X<T>::value" this is the location of "value".
2818 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2820 /// \brief Retrieve the nested-name-specifier that qualifies the
2821 /// name, with source location information.
2822 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2824 /// \brief Retrieve the nested-name-specifier that qualifies this
2826 NestedNameSpecifier *getQualifier() const {
2827 return QualifierLoc.getNestedNameSpecifier();
2830 /// \brief Retrieve the location of the template keyword preceding
2831 /// this name, if any.
2832 SourceLocation getTemplateKeywordLoc() const {
2833 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2834 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2837 /// \brief Retrieve the location of the left angle bracket starting the
2838 /// explicit template argument list following the name, if any.
2839 SourceLocation getLAngleLoc() const {
2840 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2841 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2844 /// \brief Retrieve the location of the right angle bracket ending the
2845 /// explicit template argument list following the name, if any.
2846 SourceLocation getRAngleLoc() const {
2847 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2848 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2851 /// Determines whether the name was preceded by the template keyword.
2852 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2854 /// Determines whether this lookup had explicit template arguments.
2855 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2857 /// \brief Copies the template arguments (if present) into the given
2859 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2860 if (hasExplicitTemplateArgs())
2861 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2862 getTrailingObjects<TemplateArgumentLoc>(), List);
2865 TemplateArgumentLoc const *getTemplateArgs() const {
2866 if (!hasExplicitTemplateArgs())
2869 return getTrailingObjects<TemplateArgumentLoc>();
2872 unsigned getNumTemplateArgs() const {
2873 if (!hasExplicitTemplateArgs())
2876 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2879 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2880 return {getTemplateArgs(), getNumTemplateArgs()};
2883 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2884 /// and differs from getLocation().getStart().
2885 SourceLocation getLocStart() const LLVM_READONLY {
2886 return QualifierLoc.getBeginLoc();
2888 SourceLocation getLocEnd() const LLVM_READONLY {
2889 if (hasExplicitTemplateArgs())
2890 return getRAngleLoc();
2891 return getLocation();
2894 static bool classof(const Stmt *T) {
2895 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2898 child_range children() {
2899 return child_range(child_iterator(), child_iterator());
2902 friend TrailingObjects;
2903 friend class ASTStmtReader;
2904 friend class ASTStmtWriter;
2907 /// Represents an expression -- generally a full-expression -- that
2908 /// introduces cleanups to be run at the end of the sub-expression's
2909 /// evaluation. The most common source of expression-introduced
2910 /// cleanups is temporary objects in C++, but several other kinds of
2911 /// expressions can create cleanups, including basically every
2912 /// call in ARC that returns an Objective-C pointer.
2914 /// This expression also tracks whether the sub-expression contains a
2915 /// potentially-evaluated block literal. The lifetime of a block
2916 /// literal is the extent of the enclosing scope.
2917 class ExprWithCleanups final
2919 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
2921 /// The type of objects that are kept in the cleanup.
2922 /// It's useful to remember the set of blocks; we could also
2923 /// remember the set of temporaries, but there's currently
2925 typedef BlockDecl *CleanupObject;
2930 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2931 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
2932 ArrayRef<CleanupObject> Objects);
2934 friend TrailingObjects;
2935 friend class ASTStmtReader;
2938 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
2939 unsigned numObjects);
2941 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
2942 bool CleanupsHaveSideEffects,
2943 ArrayRef<CleanupObject> objects);
2945 ArrayRef<CleanupObject> getObjects() const {
2946 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
2950 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2952 CleanupObject getObject(unsigned i) const {
2953 assert(i < getNumObjects() && "Index out of range");
2954 return getObjects()[i];
2957 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2958 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2959 bool cleanupsHaveSideEffects() const {
2960 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
2963 /// As with any mutator of the AST, be very careful
2964 /// when modifying an existing AST to preserve its invariants.
2965 void setSubExpr(Expr *E) { SubExpr = E; }
2967 SourceLocation getLocStart() const LLVM_READONLY {
2968 return SubExpr->getLocStart();
2970 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2972 // Implement isa/cast/dyncast/etc.
2973 static bool classof(const Stmt *T) {
2974 return T->getStmtClass() == ExprWithCleanupsClass;
2978 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2981 /// \brief Describes an explicit type conversion that uses functional
2982 /// notion but could not be resolved because one or more arguments are
2985 /// The explicit type conversions expressed by
2986 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2987 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2988 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2989 /// type-dependent. For example, this would occur in a template such
2993 /// template<typename T, typename A1>
2994 /// inline T make_a(const A1& a1) {
2999 /// When the returned expression is instantiated, it may resolve to a
3000 /// constructor call, conversion function call, or some kind of type
3002 class CXXUnresolvedConstructExpr final
3004 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3005 /// \brief The type being constructed.
3006 TypeSourceInfo *Type;
3008 /// \brief The location of the left parentheses ('(').
3009 SourceLocation LParenLoc;
3011 /// \brief The location of the right parentheses (')').
3012 SourceLocation RParenLoc;
3014 /// \brief The number of arguments used to construct the type.
3017 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
3018 SourceLocation LParenLoc,
3019 ArrayRef<Expr*> Args,
3020 SourceLocation RParenLoc);
3022 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3023 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
3025 friend TrailingObjects;
3026 friend class ASTStmtReader;
3029 static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
3030 TypeSourceInfo *Type,
3031 SourceLocation LParenLoc,
3032 ArrayRef<Expr*> Args,
3033 SourceLocation RParenLoc);
3035 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
3038 /// \brief Retrieve the type that is being constructed, as specified
3039 /// in the source code.
3040 QualType getTypeAsWritten() const { return Type->getType(); }
3042 /// \brief Retrieve the type source information for the type being
3044 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
3046 /// \brief Retrieve the location of the left parentheses ('(') that
3047 /// precedes the argument list.
3048 SourceLocation getLParenLoc() const { return LParenLoc; }
3049 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3051 /// \brief Retrieve the location of the right parentheses (')') that
3052 /// follows the argument list.
3053 SourceLocation getRParenLoc() const { return RParenLoc; }
3054 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3056 /// \brief Retrieve the number of arguments.
3057 unsigned arg_size() const { return NumArgs; }
3059 typedef Expr** arg_iterator;
3060 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3061 arg_iterator arg_end() { return arg_begin() + NumArgs; }
3063 typedef const Expr* const * const_arg_iterator;
3064 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3065 const_arg_iterator arg_end() const {
3066 return arg_begin() + NumArgs;
3069 Expr *getArg(unsigned I) {
3070 assert(I < NumArgs && "Argument index out-of-range");
3071 return *(arg_begin() + I);
3074 const Expr *getArg(unsigned I) const {
3075 assert(I < NumArgs && "Argument index out-of-range");
3076 return *(arg_begin() + I);
3079 void setArg(unsigned I, Expr *E) {
3080 assert(I < NumArgs && "Argument index out-of-range");
3081 *(arg_begin() + I) = E;
3084 SourceLocation getLocStart() const LLVM_READONLY;
3085 SourceLocation getLocEnd() const LLVM_READONLY {
3086 if (!RParenLoc.isValid() && NumArgs > 0)
3087 return getArg(NumArgs - 1)->getLocEnd();
3091 static bool classof(const Stmt *T) {
3092 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3096 child_range children() {
3097 Stmt **begin = reinterpret_cast<Stmt **>(arg_begin());
3098 return child_range(begin, begin + NumArgs);
3102 /// \brief Represents a C++ member access expression where the actual
3103 /// member referenced could not be resolved because the base
3104 /// expression or the member name was dependent.
3106 /// Like UnresolvedMemberExprs, these can be either implicit or
3107 /// explicit accesses. It is only possible to get one of these with
3108 /// an implicit access if a qualifier is provided.
3109 class CXXDependentScopeMemberExpr final
3111 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3112 ASTTemplateKWAndArgsInfo,
3113 TemplateArgumentLoc> {
3114 /// \brief The expression for the base pointer or class reference,
3115 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3118 /// \brief The type of the base expression. Never null, even for
3119 /// implicit accesses.
3122 /// \brief Whether this member expression used the '->' operator or
3123 /// the '.' operator.
3126 /// \brief Whether this member expression has info for explicit template
3127 /// keyword and arguments.
3128 bool HasTemplateKWAndArgsInfo : 1;
3130 /// \brief The location of the '->' or '.' operator.
3131 SourceLocation OperatorLoc;
3133 /// \brief The nested-name-specifier that precedes the member name, if any.
3134 NestedNameSpecifierLoc QualifierLoc;
3136 /// \brief In a qualified member access expression such as t->Base::f, this
3137 /// member stores the resolves of name lookup in the context of the member
3138 /// access expression, to be used at instantiation time.
3140 /// FIXME: This member, along with the QualifierLoc, could
3141 /// be stuck into a structure that is optionally allocated at the end of
3142 /// the CXXDependentScopeMemberExpr, to save space in the common case.
3143 NamedDecl *FirstQualifierFoundInScope;
3145 /// \brief The member to which this member expression refers, which
3146 /// can be name, overloaded operator, or destructor.
3148 /// FIXME: could also be a template-id
3149 DeclarationNameInfo MemberNameInfo;
3151 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3152 return HasTemplateKWAndArgsInfo ? 1 : 0;
3155 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3156 QualType BaseType, bool IsArrow,
3157 SourceLocation OperatorLoc,
3158 NestedNameSpecifierLoc QualifierLoc,
3159 SourceLocation TemplateKWLoc,
3160 NamedDecl *FirstQualifierFoundInScope,
3161 DeclarationNameInfo MemberNameInfo,
3162 const TemplateArgumentListInfo *TemplateArgs);
3165 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3166 QualType BaseType, bool IsArrow,
3167 SourceLocation OperatorLoc,
3168 NestedNameSpecifierLoc QualifierLoc,
3169 NamedDecl *FirstQualifierFoundInScope,
3170 DeclarationNameInfo MemberNameInfo);
3172 static CXXDependentScopeMemberExpr *
3173 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3174 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3175 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3176 DeclarationNameInfo MemberNameInfo,
3177 const TemplateArgumentListInfo *TemplateArgs);
3179 static CXXDependentScopeMemberExpr *
3180 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3181 unsigned NumTemplateArgs);
3183 /// \brief True if this is an implicit access, i.e. one in which the
3184 /// member being accessed was not written in the source. The source
3185 /// location of the operator is invalid in this case.
3186 bool isImplicitAccess() const;
3188 /// \brief Retrieve the base object of this member expressions,
3189 /// e.g., the \c x in \c x.m.
3190 Expr *getBase() const {
3191 assert(!isImplicitAccess());
3192 return cast<Expr>(Base);
3195 QualType getBaseType() const { return BaseType; }
3197 /// \brief Determine whether this member expression used the '->'
3198 /// operator; otherwise, it used the '.' operator.
3199 bool isArrow() const { return IsArrow; }
3201 /// \brief Retrieve the location of the '->' or '.' operator.
3202 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3204 /// \brief Retrieve the nested-name-specifier that qualifies the member
3206 NestedNameSpecifier *getQualifier() const {
3207 return QualifierLoc.getNestedNameSpecifier();
3210 /// \brief Retrieve the nested-name-specifier that qualifies the member
3211 /// name, with source location information.
3212 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3215 /// \brief Retrieve the first part of the nested-name-specifier that was
3216 /// found in the scope of the member access expression when the member access
3217 /// was initially parsed.
3219 /// This function only returns a useful result when member access expression
3220 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3221 /// returned by this function describes what was found by unqualified name
3222 /// lookup for the identifier "Base" within the scope of the member access
3223 /// expression itself. At template instantiation time, this information is
3224 /// combined with the results of name lookup into the type of the object
3225 /// expression itself (the class type of x).
3226 NamedDecl *getFirstQualifierFoundInScope() const {
3227 return FirstQualifierFoundInScope;
3230 /// \brief Retrieve the name of the member that this expression
3232 const DeclarationNameInfo &getMemberNameInfo() const {
3233 return MemberNameInfo;
3236 /// \brief Retrieve the name of the member that this expression
3238 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3240 // \brief Retrieve the location of the name of the member that this
3241 // expression refers to.
3242 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3244 /// \brief Retrieve the location of the template keyword preceding the
3245 /// member name, if any.
3246 SourceLocation getTemplateKeywordLoc() const {
3247 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3248 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3251 /// \brief Retrieve the location of the left angle bracket starting the
3252 /// explicit template argument list following the member name, if any.
3253 SourceLocation getLAngleLoc() const {
3254 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3255 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3258 /// \brief Retrieve the location of the right angle bracket ending the
3259 /// explicit template argument list following the member name, if any.
3260 SourceLocation getRAngleLoc() const {
3261 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3262 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3265 /// Determines whether the member name was preceded by the template keyword.
3266 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3268 /// \brief Determines whether this member expression actually had a C++
3269 /// template argument list explicitly specified, e.g., x.f<int>.
3270 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3272 /// \brief Copies the template arguments (if present) into the given
3274 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3275 if (hasExplicitTemplateArgs())
3276 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3277 getTrailingObjects<TemplateArgumentLoc>(), List);
3280 /// \brief Retrieve the template arguments provided as part of this
3282 const TemplateArgumentLoc *getTemplateArgs() const {
3283 if (!hasExplicitTemplateArgs())
3286 return getTrailingObjects<TemplateArgumentLoc>();
3289 /// \brief Retrieve the number of template arguments provided as part of this
3291 unsigned getNumTemplateArgs() const {
3292 if (!hasExplicitTemplateArgs())
3295 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3298 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3299 return {getTemplateArgs(), getNumTemplateArgs()};
3302 SourceLocation getLocStart() const LLVM_READONLY {
3303 if (!isImplicitAccess())
3304 return Base->getLocStart();
3306 return getQualifierLoc().getBeginLoc();
3307 return MemberNameInfo.getBeginLoc();
3310 SourceLocation getLocEnd() const LLVM_READONLY {
3311 if (hasExplicitTemplateArgs())
3312 return getRAngleLoc();
3313 return MemberNameInfo.getEndLoc();
3316 static bool classof(const Stmt *T) {
3317 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3321 child_range children() {
3322 if (isImplicitAccess())
3323 return child_range(child_iterator(), child_iterator());
3324 return child_range(&Base, &Base + 1);
3327 friend TrailingObjects;
3328 friend class ASTStmtReader;
3329 friend class ASTStmtWriter;
3332 /// \brief Represents a C++ member access expression for which lookup
3333 /// produced a set of overloaded functions.
3335 /// The member access may be explicit or implicit:
3339 /// int explicitAccess() { return this->a + this->A::b; }
3340 /// int implicitAccess() { return a + A::b; }
3344 /// In the final AST, an explicit access always becomes a MemberExpr.
3345 /// An implicit access may become either a MemberExpr or a
3346 /// DeclRefExpr, depending on whether the member is static.
3347 class UnresolvedMemberExpr final
3348 : public OverloadExpr,
3349 private llvm::TrailingObjects<
3350 UnresolvedMemberExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
3351 /// \brief Whether this member expression used the '->' operator or
3352 /// the '.' operator.
3355 /// \brief Whether the lookup results contain an unresolved using
3357 bool HasUnresolvedUsing : 1;
3359 /// \brief The expression for the base pointer or class reference,
3360 /// e.g., the \c x in x.f.
3362 /// This can be null if this is an 'unbased' member expression.
3365 /// \brief The type of the base expression; never null.
3368 /// \brief The location of the '->' or '.' operator.
3369 SourceLocation OperatorLoc;
3371 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3372 return HasTemplateKWAndArgsInfo ? 1 : 0;
3375 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3376 Expr *Base, QualType BaseType, bool IsArrow,
3377 SourceLocation OperatorLoc,
3378 NestedNameSpecifierLoc QualifierLoc,
3379 SourceLocation TemplateKWLoc,
3380 const DeclarationNameInfo &MemberNameInfo,
3381 const TemplateArgumentListInfo *TemplateArgs,
3382 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3384 UnresolvedMemberExpr(EmptyShell Empty)
3385 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3386 HasUnresolvedUsing(false), Base(nullptr) { }
3388 friend TrailingObjects;
3389 friend class OverloadExpr;
3390 friend class ASTStmtReader;
3393 static UnresolvedMemberExpr *
3394 Create(const ASTContext &C, bool HasUnresolvedUsing,
3395 Expr *Base, QualType BaseType, bool IsArrow,
3396 SourceLocation OperatorLoc,
3397 NestedNameSpecifierLoc QualifierLoc,
3398 SourceLocation TemplateKWLoc,
3399 const DeclarationNameInfo &MemberNameInfo,
3400 const TemplateArgumentListInfo *TemplateArgs,
3401 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3403 static UnresolvedMemberExpr *
3404 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3405 unsigned NumTemplateArgs);
3407 /// \brief True if this is an implicit access, i.e., one in which the
3408 /// member being accessed was not written in the source.
3410 /// The source location of the operator is invalid in this case.
3411 bool isImplicitAccess() const;
3413 /// \brief Retrieve the base object of this member expressions,
3414 /// e.g., the \c x in \c x.m.
3416 assert(!isImplicitAccess());
3417 return cast<Expr>(Base);
3419 const Expr *getBase() const {
3420 assert(!isImplicitAccess());
3421 return cast<Expr>(Base);
3424 QualType getBaseType() const { return BaseType; }
3426 /// \brief Determine whether the lookup results contain an unresolved using
3428 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3430 /// \brief Determine whether this member expression used the '->'
3431 /// operator; otherwise, it used the '.' operator.
3432 bool isArrow() const { return IsArrow; }
3434 /// \brief Retrieve the location of the '->' or '.' operator.
3435 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3437 /// \brief Retrieve the naming class of this lookup.
3438 CXXRecordDecl *getNamingClass() const;
3440 /// \brief Retrieve the full name info for the member that this expression
3442 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3444 /// \brief Retrieve the name of the member that this expression
3446 DeclarationName getMemberName() const { return getName(); }
3448 // \brief Retrieve the location of the name of the member that this
3449 // expression refers to.
3450 SourceLocation getMemberLoc() const { return getNameLoc(); }
3452 // \brief Return the preferred location (the member name) for the arrow when
3453 // diagnosing a problem with this expression.
3454 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3456 SourceLocation getLocStart() const LLVM_READONLY {
3457 if (!isImplicitAccess())
3458 return Base->getLocStart();
3459 if (NestedNameSpecifierLoc l = getQualifierLoc())
3460 return l.getBeginLoc();
3461 return getMemberNameInfo().getLocStart();
3463 SourceLocation getLocEnd() const LLVM_READONLY {
3464 if (hasExplicitTemplateArgs())
3465 return getRAngleLoc();
3466 return getMemberNameInfo().getLocEnd();
3469 static bool classof(const Stmt *T) {
3470 return T->getStmtClass() == UnresolvedMemberExprClass;
3474 child_range children() {
3475 if (isImplicitAccess())
3476 return child_range(child_iterator(), child_iterator());
3477 return child_range(&Base, &Base + 1);
3481 inline ASTTemplateKWAndArgsInfo *
3482 OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3483 if (!HasTemplateKWAndArgsInfo)
3486 if (isa<UnresolvedLookupExpr>(this))
3487 return cast<UnresolvedLookupExpr>(this)
3488 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3490 return cast<UnresolvedMemberExpr>(this)
3491 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3494 inline TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3495 if (isa<UnresolvedLookupExpr>(this))
3496 return cast<UnresolvedLookupExpr>(this)
3497 ->getTrailingObjects<TemplateArgumentLoc>();
3499 return cast<UnresolvedMemberExpr>(this)
3500 ->getTrailingObjects<TemplateArgumentLoc>();
3503 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3505 /// The noexcept expression tests whether a given expression might throw. Its
3506 /// result is a boolean constant.
3507 class CXXNoexceptExpr : public Expr {
3512 friend class ASTStmtReader;
3515 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3516 SourceLocation Keyword, SourceLocation RParen)
3517 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3518 /*TypeDependent*/false,
3519 /*ValueDependent*/Val == CT_Dependent,
3520 Val == CT_Dependent || Operand->isInstantiationDependent(),
3521 Operand->containsUnexpandedParameterPack()),
3522 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3525 CXXNoexceptExpr(EmptyShell Empty)
3526 : Expr(CXXNoexceptExprClass, Empty)
3529 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3531 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
3532 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3533 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3535 bool getValue() const { return Value; }
3537 static bool classof(const Stmt *T) {
3538 return T->getStmtClass() == CXXNoexceptExprClass;
3542 child_range children() { return child_range(&Operand, &Operand + 1); }
3545 /// \brief Represents a C++11 pack expansion that produces a sequence of
3548 /// A pack expansion expression contains a pattern (which itself is an
3549 /// expression) followed by an ellipsis. For example:
3552 /// template<typename F, typename ...Types>
3553 /// void forward(F f, Types &&...args) {
3554 /// f(static_cast<Types&&>(args)...);
3558 /// Here, the argument to the function object \c f is a pack expansion whose
3559 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3560 /// template is instantiated, the pack expansion will instantiate to zero or
3561 /// or more function arguments to the function object \c f.
3562 class PackExpansionExpr : public Expr {
3563 SourceLocation EllipsisLoc;
3565 /// \brief The number of expansions that will be produced by this pack
3566 /// expansion expression, if known.
3568 /// When zero, the number of expansions is not known. Otherwise, this value
3569 /// is the number of expansions + 1.
3570 unsigned NumExpansions;
3574 friend class ASTStmtReader;
3575 friend class ASTStmtWriter;
3578 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3579 Optional<unsigned> NumExpansions)
3580 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3581 Pattern->getObjectKind(), /*TypeDependent=*/true,
3582 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3583 /*ContainsUnexpandedParameterPack=*/false),
3584 EllipsisLoc(EllipsisLoc),
3585 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3586 Pattern(Pattern) { }
3588 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3590 /// \brief Retrieve the pattern of the pack expansion.
3591 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3593 /// \brief Retrieve the pattern of the pack expansion.
3594 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3596 /// \brief Retrieve the location of the ellipsis that describes this pack
3598 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3600 /// \brief Determine the number of expansions that will be produced when
3601 /// this pack expansion is instantiated, if already known.
3602 Optional<unsigned> getNumExpansions() const {
3604 return NumExpansions - 1;
3609 SourceLocation getLocStart() const LLVM_READONLY {
3610 return Pattern->getLocStart();
3612 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3614 static bool classof(const Stmt *T) {
3615 return T->getStmtClass() == PackExpansionExprClass;
3619 child_range children() {
3620 return child_range(&Pattern, &Pattern + 1);
3625 /// \brief Represents an expression that computes the length of a parameter
3629 /// template<typename ...Types>
3631 /// static const unsigned value = sizeof...(Types);
3634 class SizeOfPackExpr final
3636 private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
3637 /// \brief The location of the \c sizeof keyword.
3638 SourceLocation OperatorLoc;
3640 /// \brief The location of the name of the parameter pack.
3641 SourceLocation PackLoc;
3643 /// \brief The location of the closing parenthesis.
3644 SourceLocation RParenLoc;
3646 /// \brief The length of the parameter pack, if known.
3648 /// When this expression is not value-dependent, this is the length of
3649 /// the pack. When the expression was parsed rather than instantiated
3650 /// (and thus is value-dependent), this is zero.
3652 /// After partial substitution into a sizeof...(X) expression (for instance,
3653 /// within an alias template or during function template argument deduction),
3654 /// we store a trailing array of partially-substituted TemplateArguments,
3655 /// and this is the length of that array.
3658 /// \brief The parameter pack.
3661 friend TrailingObjects;
3662 friend class ASTStmtReader;
3663 friend class ASTStmtWriter;
3665 /// \brief Create an expression that computes the length of
3666 /// the given parameter pack.
3667 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3668 SourceLocation PackLoc, SourceLocation RParenLoc,
3669 Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
3670 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3671 /*TypeDependent=*/false, /*ValueDependent=*/!Length,
3672 /*InstantiationDependent=*/!Length,
3673 /*ContainsUnexpandedParameterPack=*/false),
3674 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3675 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
3676 assert((!Length || PartialArgs.empty()) &&
3677 "have partial args for non-dependent sizeof... expression");
3678 TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3679 std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
3682 /// \brief Create an empty expression.
3683 SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
3684 : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs), Pack() {}
3687 static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
3688 NamedDecl *Pack, SourceLocation PackLoc,
3689 SourceLocation RParenLoc,
3690 Optional<unsigned> Length = None,
3691 ArrayRef<TemplateArgument> PartialArgs = None);
3692 static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
3693 unsigned NumPartialArgs);
3695 /// \brief Determine the location of the 'sizeof' keyword.
3696 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3698 /// \brief Determine the location of the parameter pack.
3699 SourceLocation getPackLoc() const { return PackLoc; }
3701 /// \brief Determine the location of the right parenthesis.
3702 SourceLocation getRParenLoc() const { return RParenLoc; }
3704 /// \brief Retrieve the parameter pack.
3705 NamedDecl *getPack() const { return Pack; }
3707 /// \brief Retrieve the length of the parameter pack.
3709 /// This routine may only be invoked when the expression is not
3710 /// value-dependent.
3711 unsigned getPackLength() const {
3712 assert(!isValueDependent() &&
3713 "Cannot get the length of a value-dependent pack size expression");
3717 /// \brief Determine whether this represents a partially-substituted sizeof...
3718 /// expression, such as is produced for:
3720 /// template<typename ...Ts> using X = int[sizeof...(Ts)];
3721 /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
3722 bool isPartiallySubstituted() const {
3723 return isValueDependent() && Length;
3727 ArrayRef<TemplateArgument> getPartialArguments() const {
3728 assert(isPartiallySubstituted());
3729 const TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3730 return llvm::makeArrayRef(Args, Args + Length);
3733 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
3734 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3736 static bool classof(const Stmt *T) {
3737 return T->getStmtClass() == SizeOfPackExprClass;
3741 child_range children() {
3742 return child_range(child_iterator(), child_iterator());
3746 /// \brief Represents a reference to a non-type template parameter
3747 /// that has been substituted with a template argument.
3748 class SubstNonTypeTemplateParmExpr : public Expr {
3749 /// \brief The replaced parameter.
3750 NonTypeTemplateParmDecl *Param;
3752 /// \brief The replacement expression.
3755 /// \brief The location of the non-type template parameter reference.
3756 SourceLocation NameLoc;
3758 friend class ASTReader;
3759 friend class ASTStmtReader;
3760 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3761 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3764 SubstNonTypeTemplateParmExpr(QualType type,
3765 ExprValueKind valueKind,
3767 NonTypeTemplateParmDecl *param,
3769 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3770 replacement->isTypeDependent(), replacement->isValueDependent(),
3771 replacement->isInstantiationDependent(),
3772 replacement->containsUnexpandedParameterPack()),
3773 Param(param), Replacement(replacement), NameLoc(loc) {}
3775 SourceLocation getNameLoc() const { return NameLoc; }
3776 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3777 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3779 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3781 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3783 static bool classof(const Stmt *s) {
3784 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3788 child_range children() { return child_range(&Replacement, &Replacement+1); }
3791 /// \brief Represents a reference to a non-type template parameter pack that
3792 /// has been substituted with a non-template argument pack.
3794 /// When a pack expansion in the source code contains multiple parameter packs
3795 /// and those parameter packs correspond to different levels of template
3796 /// parameter lists, this node is used to represent a non-type template
3797 /// parameter pack from an outer level, which has already had its argument pack
3798 /// substituted but that still lives within a pack expansion that itself
3799 /// could not be instantiated. When actually performing a substitution into
3800 /// that pack expansion (e.g., when all template parameters have corresponding
3801 /// arguments), this type will be replaced with the appropriate underlying
3802 /// expression at the current pack substitution index.
3803 class SubstNonTypeTemplateParmPackExpr : public Expr {
3804 /// \brief The non-type template parameter pack itself.
3805 NonTypeTemplateParmDecl *Param;
3807 /// \brief A pointer to the set of template arguments that this
3808 /// parameter pack is instantiated with.
3809 const TemplateArgument *Arguments;
3811 /// \brief The number of template arguments in \c Arguments.
3812 unsigned NumArguments;
3814 /// \brief The location of the non-type template parameter pack reference.
3815 SourceLocation NameLoc;
3817 friend class ASTReader;
3818 friend class ASTStmtReader;
3819 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3820 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3823 SubstNonTypeTemplateParmPackExpr(QualType T,
3824 NonTypeTemplateParmDecl *Param,
3825 SourceLocation NameLoc,
3826 const TemplateArgument &ArgPack);
3828 /// \brief Retrieve the non-type template parameter pack being substituted.
3829 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3831 /// \brief Retrieve the location of the parameter pack name.
3832 SourceLocation getParameterPackLocation() const { return NameLoc; }
3834 /// \brief Retrieve the template argument pack containing the substituted
3835 /// template arguments.
3836 TemplateArgument getArgumentPack() const;
3838 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3839 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3841 static bool classof(const Stmt *T) {
3842 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3846 child_range children() {
3847 return child_range(child_iterator(), child_iterator());
3851 /// \brief Represents a reference to a function parameter pack that has been
3852 /// substituted but not yet expanded.
3854 /// When a pack expansion contains multiple parameter packs at different levels,
3855 /// this node is used to represent a function parameter pack at an outer level
3856 /// which we have already substituted to refer to expanded parameters, but where
3857 /// the containing pack expansion cannot yet be expanded.
3860 /// template<typename...Ts> struct S {
3861 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3863 /// template struct S<int, int>;
3865 class FunctionParmPackExpr final
3867 private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> {
3868 /// \brief The function parameter pack which was referenced.
3869 ParmVarDecl *ParamPack;
3871 /// \brief The location of the function parameter pack reference.
3872 SourceLocation NameLoc;
3874 /// \brief The number of expansions of this pack.
3875 unsigned NumParameters;
3877 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3878 SourceLocation NameLoc, unsigned NumParams,
3879 ParmVarDecl *const *Params);
3881 friend TrailingObjects;
3882 friend class ASTReader;
3883 friend class ASTStmtReader;
3886 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
3887 ParmVarDecl *ParamPack,
3888 SourceLocation NameLoc,
3889 ArrayRef<ParmVarDecl *> Params);
3890 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
3891 unsigned NumParams);
3893 /// \brief Get the parameter pack which this expression refers to.
3894 ParmVarDecl *getParameterPack() const { return ParamPack; }
3896 /// \brief Get the location of the parameter pack.
3897 SourceLocation getParameterPackLocation() const { return NameLoc; }
3899 /// \brief Iterators over the parameters which the parameter pack expanded
3901 typedef ParmVarDecl * const *iterator;
3902 iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); }
3903 iterator end() const { return begin() + NumParameters; }
3905 /// \brief Get the number of parameters in this parameter pack.
3906 unsigned getNumExpansions() const { return NumParameters; }
3908 /// \brief Get an expansion of the parameter pack by index.
3909 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3911 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3912 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3914 static bool classof(const Stmt *T) {
3915 return T->getStmtClass() == FunctionParmPackExprClass;
3918 child_range children() {
3919 return child_range(child_iterator(), child_iterator());
3923 /// \brief Represents a prvalue temporary that is written into memory so that
3924 /// a reference can bind to it.
3926 /// Prvalue expressions are materialized when they need to have an address
3927 /// in memory for a reference to bind to. This happens when binding a
3928 /// reference to the result of a conversion, e.g.,
3931 /// const int &r = 1.0;
3934 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3935 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3936 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3937 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3938 /// to it), maintaining the invariant that references always bind to glvalues.
3940 /// Reference binding and copy-elision can both extend the lifetime of a
3941 /// temporary. When either happens, the expression will also track the
3942 /// declaration which is responsible for the lifetime extension.
3943 class MaterializeTemporaryExpr : public Expr {
3946 /// \brief The temporary-generating expression whose value will be
3950 /// \brief The declaration which lifetime-extended this reference, if any.
3951 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3952 const ValueDecl *ExtendingDecl;
3954 unsigned ManglingNumber;
3956 llvm::PointerUnion<Stmt *, ExtraState *> State;
3958 friend class ASTStmtReader;
3959 friend class ASTStmtWriter;
3961 void initializeExtraState(const ValueDecl *ExtendedBy,
3962 unsigned ManglingNumber);
3965 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3966 bool BoundToLvalueReference)
3967 : Expr(MaterializeTemporaryExprClass, T,
3968 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3969 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3970 Temporary->isInstantiationDependent(),
3971 Temporary->containsUnexpandedParameterPack()),
3974 MaterializeTemporaryExpr(EmptyShell Empty)
3975 : Expr(MaterializeTemporaryExprClass, Empty) { }
3977 Stmt *getTemporary() const {
3978 return State.is<Stmt *>() ? State.get<Stmt *>()
3979 : State.get<ExtraState *>()->Temporary;
3982 /// \brief Retrieve the temporary-generating subexpression whose value will
3983 /// be materialized into a glvalue.
3984 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
3986 /// \brief Retrieve the storage duration for the materialized temporary.
3987 StorageDuration getStorageDuration() const {
3988 const ValueDecl *ExtendingDecl = getExtendingDecl();
3990 return SD_FullExpression;
3991 // FIXME: This is not necessarily correct for a temporary materialized
3992 // within a default initializer.
3993 if (isa<FieldDecl>(ExtendingDecl))
3994 return SD_Automatic;
3995 // FIXME: This only works because storage class specifiers are not allowed
3996 // on decomposition declarations.
3997 if (isa<BindingDecl>(ExtendingDecl))
3998 return ExtendingDecl->getDeclContext()->isFunctionOrMethod()
4001 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
4004 /// \brief Get the declaration which triggered the lifetime-extension of this
4005 /// temporary, if any.
4006 const ValueDecl *getExtendingDecl() const {
4007 return State.is<Stmt *>() ? nullptr
4008 : State.get<ExtraState *>()->ExtendingDecl;
4011 void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
4013 unsigned getManglingNumber() const {
4014 return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
4017 /// \brief Determine whether this materialized temporary is bound to an
4018 /// lvalue reference; otherwise, it's bound to an rvalue reference.
4019 bool isBoundToLvalueReference() const {
4020 return getValueKind() == VK_LValue;
4023 SourceLocation getLocStart() const LLVM_READONLY {
4024 return getTemporary()->getLocStart();
4026 SourceLocation getLocEnd() const LLVM_READONLY {
4027 return getTemporary()->getLocEnd();
4030 static bool classof(const Stmt *T) {
4031 return T->getStmtClass() == MaterializeTemporaryExprClass;
4035 child_range children() {
4036 if (State.is<Stmt *>())
4037 return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
4039 auto ES = State.get<ExtraState *>();
4040 return child_range(&ES->Temporary, &ES->Temporary + 1);
4044 /// \brief Represents a folding of a pack over an operator.
4046 /// This expression is always dependent and represents a pack expansion of the
4051 /// ( expr op ... op expr )
4052 class CXXFoldExpr : public Expr {
4053 SourceLocation LParenLoc;
4054 SourceLocation EllipsisLoc;
4055 SourceLocation RParenLoc;
4057 BinaryOperatorKind Opcode;
4059 friend class ASTStmtReader;
4060 friend class ASTStmtWriter;
4062 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
4063 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
4064 SourceLocation RParenLoc)
4065 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
4066 /*Dependent*/ true, true, true,
4067 /*ContainsUnexpandedParameterPack*/ false),
4068 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4073 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4075 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
4076 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
4078 /// Does this produce a right-associated sequence of operators?
4079 bool isRightFold() const {
4080 return getLHS() && getLHS()->containsUnexpandedParameterPack();
4082 /// Does this produce a left-associated sequence of operators?
4083 bool isLeftFold() const { return !isRightFold(); }
4084 /// Get the pattern, that is, the operand that contains an unexpanded pack.
4085 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4086 /// Get the operand that doesn't contain a pack, for a binary fold.
4087 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4089 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4090 BinaryOperatorKind getOperator() const { return Opcode; }
4092 SourceLocation getLocStart() const LLVM_READONLY {
4095 SourceLocation getLocEnd() const LLVM_READONLY {
4099 static bool classof(const Stmt *T) {
4100 return T->getStmtClass() == CXXFoldExprClass;
4104 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4107 /// \brief Represents an expression that might suspend coroutine execution;
4108 /// either a co_await or co_yield expression.
4110 /// Evaluation of this expression first evaluates its 'ready' expression. If
4111 /// that returns 'false':
4112 /// -- execution of the coroutine is suspended
4113 /// -- the 'suspend' expression is evaluated
4114 /// -- if the 'suspend' expression returns 'false', the coroutine is
4116 /// -- otherwise, control passes back to the resumer.
4117 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4118 /// expression is evaluated, and its result is the result of the overall
4120 class CoroutineSuspendExpr : public Expr {
4121 SourceLocation KeywordLoc;
4123 enum SubExpr { Common, Ready, Suspend, Resume, Count };
4124 Stmt *SubExprs[SubExpr::Count];
4126 friend class ASTStmtReader;
4128 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4129 Expr *Ready, Expr *Suspend, Expr *Resume)
4130 : Expr(SC, Resume->getType(), Resume->getValueKind(),
4131 Resume->getObjectKind(), Resume->isTypeDependent(),
4132 Resume->isValueDependent(), Common->isInstantiationDependent(),
4133 Common->containsUnexpandedParameterPack()),
4134 KeywordLoc(KeywordLoc) {
4135 SubExprs[SubExpr::Common] = Common;
4136 SubExprs[SubExpr::Ready] = Ready;
4137 SubExprs[SubExpr::Suspend] = Suspend;
4138 SubExprs[SubExpr::Resume] = Resume;
4140 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4142 : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
4143 Common->containsUnexpandedParameterPack()),
4144 KeywordLoc(KeywordLoc) {
4145 assert(Common->isTypeDependent() && Ty->isDependentType() &&
4146 "wrong constructor for non-dependent co_await/co_yield expression");
4147 SubExprs[SubExpr::Common] = Common;
4148 SubExprs[SubExpr::Ready] = nullptr;
4149 SubExprs[SubExpr::Suspend] = nullptr;
4150 SubExprs[SubExpr::Resume] = nullptr;
4152 CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4153 SubExprs[SubExpr::Common] = nullptr;
4154 SubExprs[SubExpr::Ready] = nullptr;
4155 SubExprs[SubExpr::Suspend] = nullptr;
4156 SubExprs[SubExpr::Resume] = nullptr;
4159 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4160 Expr *getCommonExpr() const {
4161 return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4164 Expr *getReadyExpr() const {
4165 return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4167 Expr *getSuspendExpr() const {
4168 return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4170 Expr *getResumeExpr() const {
4171 return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4174 SourceLocation getLocStart() const LLVM_READONLY {
4177 SourceLocation getLocEnd() const LLVM_READONLY {
4178 return getCommonExpr()->getLocEnd();
4181 child_range children() {
4182 return child_range(SubExprs, SubExprs + SubExpr::Count);
4185 static bool classof(const Stmt *T) {
4186 return T->getStmtClass() == CoawaitExprClass ||
4187 T->getStmtClass() == CoyieldExprClass;
4191 /// \brief Represents a 'co_await' expression.
4192 class CoawaitExpr : public CoroutineSuspendExpr {
4193 friend class ASTStmtReader;
4195 CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4196 Expr *Suspend, Expr *Resume)
4197 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4199 CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand)
4200 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {}
4201 CoawaitExpr(EmptyShell Empty)
4202 : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4204 Expr *getOperand() const {
4205 // FIXME: Dig out the actual operand or store it.
4206 return getCommonExpr();
4209 static bool classof(const Stmt *T) {
4210 return T->getStmtClass() == CoawaitExprClass;
4214 /// \brief Represents a 'co_yield' expression.
4215 class CoyieldExpr : public CoroutineSuspendExpr {
4216 friend class ASTStmtReader;
4218 CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4219 Expr *Suspend, Expr *Resume)
4220 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4222 CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4223 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
4224 CoyieldExpr(EmptyShell Empty)
4225 : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4227 Expr *getOperand() const {
4228 // FIXME: Dig out the actual operand or store it.
4229 return getCommonExpr();
4232 static bool classof(const Stmt *T) {
4233 return T->getStmtClass() == CoyieldExprClass;
4237 } // end namespace clang