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 // Only meaningful for floating point types.
60 SourceRange getSourceRangeImpl() const LLVM_READONLY;
62 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
63 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
64 SourceLocation operatorloc, FPOptions FPFeatures)
65 : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
66 Operator(Op), FPFeatures(FPFeatures) {
67 Range = getSourceRangeImpl();
69 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
70 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
73 /// \brief Returns the kind of overloaded operator that this
74 /// expression refers to.
75 OverloadedOperatorKind getOperator() const { return Operator; }
77 static bool isAssignmentOp(OverloadedOperatorKind Opc) {
78 return Opc == OO_Equal || Opc == OO_StarEqual ||
79 Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
80 Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
81 Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
82 Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
85 bool isAssignmentOp() const { return isAssignmentOp(getOperator()); }
87 /// \brief Is this written as an infix binary operator?
88 bool isInfixBinaryOp() const;
90 /// \brief Returns the location of the operator symbol in the expression.
92 /// When \c getOperator()==OO_Call, this is the location of the right
93 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
94 /// of the right bracket.
95 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
97 SourceLocation getExprLoc() const LLVM_READONLY {
98 return (Operator < OO_Plus || Operator >= OO_Arrow ||
99 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
104 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
105 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
106 SourceRange getSourceRange() const { return Range; }
108 static bool classof(const Stmt *T) {
109 return T->getStmtClass() == CXXOperatorCallExprClass;
112 // Set the FP contractability status of this operator. Only meaningful for
113 // operations on floating point types.
114 void setFPFeatures(FPOptions F) { FPFeatures = F; }
116 FPOptions getFPFeatures() const { return FPFeatures; }
118 // Get the FP contractability status of this operator. Only meaningful for
119 // operations on floating point types.
120 bool isFPContractableWithinStatement() const {
121 return FPFeatures.allowFPContractWithinStatement();
124 friend class ASTStmtReader;
125 friend class ASTStmtWriter;
128 /// Represents a call to a member function that
129 /// may be written either with member call syntax (e.g., "obj.func()"
130 /// or "objptr->func()") or with normal function-call syntax
131 /// ("func()") within a member function that ends up calling a member
132 /// function. The callee in either case is a MemberExpr that contains
133 /// both the object argument and the member function, while the
134 /// arguments are the arguments within the parentheses (not including
135 /// the object argument).
136 class CXXMemberCallExpr : public CallExpr {
138 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
139 QualType t, ExprValueKind VK, SourceLocation RP)
140 : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
142 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
143 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
145 /// \brief Retrieves the implicit object argument for the member call.
147 /// For example, in "x.f(5)", this returns the sub-expression "x".
148 Expr *getImplicitObjectArgument() const;
150 /// \brief Retrieves the declaration of the called method.
151 CXXMethodDecl *getMethodDecl() const;
153 /// \brief Retrieves the CXXRecordDecl for the underlying type of
154 /// the implicit object argument.
156 /// Note that this is may not be the same declaration as that of the class
157 /// context of the CXXMethodDecl which this function is calling.
158 /// FIXME: Returns 0 for member pointer call exprs.
159 CXXRecordDecl *getRecordDecl() const;
161 SourceLocation getExprLoc() const LLVM_READONLY {
162 SourceLocation CLoc = getCallee()->getExprLoc();
166 return getLocStart();
169 static bool classof(const Stmt *T) {
170 return T->getStmtClass() == CXXMemberCallExprClass;
174 /// \brief Represents a call to a CUDA kernel function.
175 class CUDAKernelCallExpr : public CallExpr {
177 enum { CONFIG, END_PREARG };
180 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
181 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
183 : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP) {}
185 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
186 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
188 const CallExpr *getConfig() const {
189 return cast_or_null<CallExpr>(getPreArg(CONFIG));
191 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
193 /// \brief Sets the kernel configuration expression.
195 /// Note that this method cannot be called if config has already been set to a
197 void setConfig(CallExpr *E) {
198 assert(!getConfig() &&
199 "Cannot call setConfig if config is not null");
200 setPreArg(CONFIG, E);
201 setInstantiationDependent(isInstantiationDependent() ||
202 E->isInstantiationDependent());
203 setContainsUnexpandedParameterPack(containsUnexpandedParameterPack() ||
204 E->containsUnexpandedParameterPack());
207 static bool classof(const Stmt *T) {
208 return T->getStmtClass() == CUDAKernelCallExprClass;
212 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
214 /// This abstract class is inherited by all of the classes
215 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
216 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
217 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
218 class CXXNamedCastExpr : public ExplicitCastExpr {
220 SourceLocation Loc; // the location of the casting op
221 SourceLocation RParenLoc; // the location of the right parenthesis
222 SourceRange AngleBrackets; // range for '<' '>'
225 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
226 CastKind kind, Expr *op, unsigned PathSize,
227 TypeSourceInfo *writtenTy, SourceLocation l,
228 SourceLocation RParenLoc,
229 SourceRange AngleBrackets)
230 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
231 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
233 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
234 : ExplicitCastExpr(SC, Shell, PathSize) { }
236 friend class ASTStmtReader;
239 const char *getCastName() const;
241 /// \brief Retrieve the location of the cast operator keyword, e.g.,
243 SourceLocation getOperatorLoc() const { return Loc; }
245 /// \brief Retrieve the location of the closing parenthesis.
246 SourceLocation getRParenLoc() const { return RParenLoc; }
248 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
249 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
250 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
252 static bool classof(const Stmt *T) {
253 switch (T->getStmtClass()) {
254 case CXXStaticCastExprClass:
255 case CXXDynamicCastExprClass:
256 case CXXReinterpretCastExprClass:
257 case CXXConstCastExprClass:
265 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
267 /// This expression node represents a C++ static cast, e.g.,
268 /// \c static_cast<int>(1.0).
269 class CXXStaticCastExpr final
270 : public CXXNamedCastExpr,
271 private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *> {
272 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
273 unsigned pathSize, TypeSourceInfo *writtenTy,
274 SourceLocation l, SourceLocation RParenLoc,
275 SourceRange AngleBrackets)
276 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
277 writtenTy, l, RParenLoc, AngleBrackets) {}
279 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
280 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
283 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
284 ExprValueKind VK, CastKind K, Expr *Op,
285 const CXXCastPath *Path,
286 TypeSourceInfo *Written, SourceLocation L,
287 SourceLocation RParenLoc,
288 SourceRange AngleBrackets);
289 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
292 static bool classof(const Stmt *T) {
293 return T->getStmtClass() == CXXStaticCastExprClass;
296 friend TrailingObjects;
297 friend class CastExpr;
300 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
302 /// This expression node represents a dynamic cast, e.g.,
303 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
304 /// check to determine how to perform the type conversion.
305 class CXXDynamicCastExpr final
306 : public CXXNamedCastExpr,
307 private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> {
308 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
309 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
310 SourceLocation l, SourceLocation RParenLoc,
311 SourceRange AngleBrackets)
312 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
313 writtenTy, l, RParenLoc, AngleBrackets) {}
315 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
316 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
319 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
320 ExprValueKind VK, CastKind Kind, Expr *Op,
321 const CXXCastPath *Path,
322 TypeSourceInfo *Written, SourceLocation L,
323 SourceLocation RParenLoc,
324 SourceRange AngleBrackets);
326 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
329 bool isAlwaysNull() const;
331 static bool classof(const Stmt *T) {
332 return T->getStmtClass() == CXXDynamicCastExprClass;
335 friend TrailingObjects;
336 friend class CastExpr;
339 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
341 /// This expression node represents a reinterpret cast, e.g.,
342 /// @c reinterpret_cast<int>(VoidPtr).
344 /// A reinterpret_cast provides a differently-typed view of a value but
345 /// (in Clang, as in most C++ implementations) performs no actual work at
347 class CXXReinterpretCastExpr final
348 : public CXXNamedCastExpr,
349 private llvm::TrailingObjects<CXXReinterpretCastExpr,
350 CXXBaseSpecifier *> {
351 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
352 Expr *op, unsigned pathSize,
353 TypeSourceInfo *writtenTy, SourceLocation l,
354 SourceLocation RParenLoc,
355 SourceRange AngleBrackets)
356 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
357 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
359 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
360 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
363 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
364 ExprValueKind VK, CastKind Kind,
365 Expr *Op, const CXXCastPath *Path,
366 TypeSourceInfo *WrittenTy, SourceLocation L,
367 SourceLocation RParenLoc,
368 SourceRange AngleBrackets);
369 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
372 static bool classof(const Stmt *T) {
373 return T->getStmtClass() == CXXReinterpretCastExprClass;
376 friend TrailingObjects;
377 friend class CastExpr;
380 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
382 /// This expression node represents a const cast, e.g.,
383 /// \c const_cast<char*>(PtrToConstChar).
385 /// A const_cast can remove type qualifiers but does not change the underlying
387 class CXXConstCastExpr final
388 : public CXXNamedCastExpr,
389 private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> {
390 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
391 TypeSourceInfo *writtenTy, SourceLocation l,
392 SourceLocation RParenLoc, SourceRange AngleBrackets)
393 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
394 0, writtenTy, l, RParenLoc, AngleBrackets) {}
396 explicit CXXConstCastExpr(EmptyShell Empty)
397 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
400 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
401 ExprValueKind VK, Expr *Op,
402 TypeSourceInfo *WrittenTy, SourceLocation L,
403 SourceLocation RParenLoc,
404 SourceRange AngleBrackets);
405 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
407 static bool classof(const Stmt *T) {
408 return T->getStmtClass() == CXXConstCastExprClass;
411 friend TrailingObjects;
412 friend class CastExpr;
415 /// \brief A call to a literal operator (C++11 [over.literal])
416 /// written as a user-defined literal (C++11 [lit.ext]).
418 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
419 /// is semantically equivalent to a normal call, this AST node provides better
420 /// information about the syntactic representation of the literal.
422 /// Since literal operators are never found by ADL and can only be declared at
423 /// namespace scope, a user-defined literal is never dependent.
424 class UserDefinedLiteral : public CallExpr {
425 /// \brief The location of a ud-suffix within the literal.
426 SourceLocation UDSuffixLoc;
429 UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
430 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
431 SourceLocation SuffixLoc)
432 : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc),
433 UDSuffixLoc(SuffixLoc) {}
434 explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
435 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
437 /// The kind of literal operator which is invoked.
438 enum LiteralOperatorKind {
439 LOK_Raw, ///< Raw form: operator "" X (const char *)
440 LOK_Template, ///< Raw form: operator "" X<cs...> ()
441 LOK_Integer, ///< operator "" X (unsigned long long)
442 LOK_Floating, ///< operator "" X (long double)
443 LOK_String, ///< operator "" X (const CharT *, size_t)
444 LOK_Character ///< operator "" X (CharT)
447 /// \brief Returns the kind of literal operator invocation
448 /// which this expression represents.
449 LiteralOperatorKind getLiteralOperatorKind() const;
451 /// \brief If this is not a raw user-defined literal, get the
452 /// underlying cooked literal (representing the literal with the suffix
454 Expr *getCookedLiteral();
455 const Expr *getCookedLiteral() const {
456 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
459 SourceLocation getLocStart() const {
460 if (getLiteralOperatorKind() == LOK_Template)
461 return getRParenLoc();
462 return getArg(0)->getLocStart();
464 SourceLocation getLocEnd() const { return getRParenLoc(); }
467 /// \brief Returns the location of a ud-suffix in the expression.
469 /// For a string literal, there may be multiple identical suffixes. This
470 /// returns the first.
471 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
473 /// \brief Returns the ud-suffix specified for this literal.
474 const IdentifierInfo *getUDSuffix() const;
476 static bool classof(const Stmt *S) {
477 return S->getStmtClass() == UserDefinedLiteralClass;
480 friend class ASTStmtReader;
481 friend class ASTStmtWriter;
484 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
486 class CXXBoolLiteralExpr : public Expr {
490 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
491 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
493 Value(val), Loc(l) {}
495 explicit CXXBoolLiteralExpr(EmptyShell Empty)
496 : Expr(CXXBoolLiteralExprClass, Empty) { }
498 bool getValue() const { return Value; }
499 void setValue(bool V) { Value = V; }
501 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
502 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
504 SourceLocation getLocation() const { return Loc; }
505 void setLocation(SourceLocation L) { Loc = L; }
507 static bool classof(const Stmt *T) {
508 return T->getStmtClass() == CXXBoolLiteralExprClass;
512 child_range children() {
513 return child_range(child_iterator(), child_iterator());
517 /// \brief The null pointer literal (C++11 [lex.nullptr])
519 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
520 class CXXNullPtrLiteralExpr : public Expr {
523 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
524 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
528 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
529 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
531 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
532 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
534 SourceLocation getLocation() const { return Loc; }
535 void setLocation(SourceLocation L) { Loc = L; }
537 static bool classof(const Stmt *T) {
538 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
541 child_range children() {
542 return child_range(child_iterator(), child_iterator());
546 /// \brief Implicit construction of a std::initializer_list<T> object from an
547 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
548 class CXXStdInitializerListExpr : public Expr {
551 CXXStdInitializerListExpr(EmptyShell Empty)
552 : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
555 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
556 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
557 Ty->isDependentType(), SubExpr->isValueDependent(),
558 SubExpr->isInstantiationDependent(),
559 SubExpr->containsUnexpandedParameterPack()),
562 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
563 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
565 SourceLocation getLocStart() const LLVM_READONLY {
566 return SubExpr->getLocStart();
568 SourceLocation getLocEnd() const LLVM_READONLY {
569 return SubExpr->getLocEnd();
571 SourceRange getSourceRange() const LLVM_READONLY {
572 return SubExpr->getSourceRange();
575 static bool classof(const Stmt *S) {
576 return S->getStmtClass() == CXXStdInitializerListExprClass;
579 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
581 friend class ASTReader;
582 friend class ASTStmtReader;
585 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
586 /// the \c type_info that corresponds to the supplied type, or the (possibly
587 /// dynamic) type of the supplied expression.
589 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
590 class CXXTypeidExpr : public Expr {
592 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
596 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
597 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
598 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
600 // typeid is value-dependent if the type or expression are dependent
601 Operand->getType()->isDependentType(),
602 Operand->getType()->isInstantiationDependentType(),
603 Operand->getType()->containsUnexpandedParameterPack()),
604 Operand(Operand), Range(R) { }
606 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
607 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
608 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
610 // typeid is value-dependent if the type or expression are dependent
611 Operand->isTypeDependent() || Operand->isValueDependent(),
612 Operand->isInstantiationDependent(),
613 Operand->containsUnexpandedParameterPack()),
614 Operand(Operand), Range(R) { }
616 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
617 : Expr(CXXTypeidExprClass, Empty) {
619 Operand = (Expr*)nullptr;
621 Operand = (TypeSourceInfo*)nullptr;
624 /// Determine whether this typeid has a type operand which is potentially
625 /// evaluated, per C++11 [expr.typeid]p3.
626 bool isPotentiallyEvaluated() const;
628 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
630 /// \brief Retrieves the type operand of this typeid() expression after
631 /// various required adjustments (removing reference types, cv-qualifiers).
632 QualType getTypeOperand(ASTContext &Context) const;
634 /// \brief Retrieve source information for the type operand.
635 TypeSourceInfo *getTypeOperandSourceInfo() const {
636 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
637 return Operand.get<TypeSourceInfo *>();
640 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
641 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
645 Expr *getExprOperand() const {
646 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
647 return static_cast<Expr*>(Operand.get<Stmt *>());
650 void setExprOperand(Expr *E) {
651 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
655 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
656 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
657 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
658 void setSourceRange(SourceRange R) { Range = R; }
660 static bool classof(const Stmt *T) {
661 return T->getStmtClass() == CXXTypeidExprClass;
665 child_range children() {
667 return child_range(child_iterator(), child_iterator());
668 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
669 return child_range(begin, begin + 1);
673 /// \brief A member reference to an MSPropertyDecl.
675 /// This expression always has pseudo-object type, and therefore it is
676 /// typically not encountered in a fully-typechecked expression except
677 /// within the syntactic form of a PseudoObjectExpr.
678 class MSPropertyRefExpr : public Expr {
680 MSPropertyDecl *TheDecl;
681 SourceLocation MemberLoc;
683 NestedNameSpecifierLoc QualifierLoc;
686 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
687 QualType ty, ExprValueKind VK,
688 NestedNameSpecifierLoc qualifierLoc,
689 SourceLocation nameLoc)
690 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
691 /*type-dependent*/ false, baseExpr->isValueDependent(),
692 baseExpr->isInstantiationDependent(),
693 baseExpr->containsUnexpandedParameterPack()),
694 BaseExpr(baseExpr), TheDecl(decl),
695 MemberLoc(nameLoc), IsArrow(isArrow),
696 QualifierLoc(qualifierLoc) {}
698 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
700 SourceRange getSourceRange() const LLVM_READONLY {
701 return SourceRange(getLocStart(), getLocEnd());
703 bool isImplicitAccess() const {
704 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
706 SourceLocation getLocStart() const {
707 if (!isImplicitAccess())
708 return BaseExpr->getLocStart();
709 else if (QualifierLoc)
710 return QualifierLoc.getBeginLoc();
714 SourceLocation getLocEnd() const { return getMemberLoc(); }
716 child_range children() {
717 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
719 static bool classof(const Stmt *T) {
720 return T->getStmtClass() == MSPropertyRefExprClass;
723 Expr *getBaseExpr() const { return BaseExpr; }
724 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
725 bool isArrow() const { return IsArrow; }
726 SourceLocation getMemberLoc() const { return MemberLoc; }
727 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
729 friend class ASTStmtReader;
732 /// MS property subscript expression.
733 /// MSVC supports 'property' attribute and allows to apply it to the
734 /// declaration of an empty array in a class or structure definition.
737 /// __declspec(property(get=GetX, put=PutX)) int x[];
739 /// The above statement indicates that x[] can be used with one or more array
740 /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and
741 /// p->x[a][b] = i will be turned into p->PutX(a, b, i).
742 /// This is a syntactic pseudo-object expression.
743 class MSPropertySubscriptExpr : public Expr {
744 friend class ASTStmtReader;
745 enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 };
746 Stmt *SubExprs[NUM_SUBEXPRS];
747 SourceLocation RBracketLoc;
749 void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; }
750 void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; }
753 MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK,
754 ExprObjectKind OK, SourceLocation RBracketLoc)
755 : Expr(MSPropertySubscriptExprClass, Ty, VK, OK, Idx->isTypeDependent(),
756 Idx->isValueDependent(), Idx->isInstantiationDependent(),
757 Idx->containsUnexpandedParameterPack()),
758 RBracketLoc(RBracketLoc) {
759 SubExprs[BASE_EXPR] = Base;
760 SubExprs[IDX_EXPR] = Idx;
763 /// \brief Create an empty array subscript expression.
764 explicit MSPropertySubscriptExpr(EmptyShell Shell)
765 : Expr(MSPropertySubscriptExprClass, Shell) {}
767 Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); }
768 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); }
770 Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); }
771 const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); }
773 SourceLocation getLocStart() const LLVM_READONLY {
774 return getBase()->getLocStart();
776 SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
778 SourceLocation getRBracketLoc() const { return RBracketLoc; }
779 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
781 SourceLocation getExprLoc() const LLVM_READONLY {
782 return getBase()->getExprLoc();
785 static bool classof(const Stmt *T) {
786 return T->getStmtClass() == MSPropertySubscriptExprClass;
790 child_range children() {
791 return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS);
795 /// A Microsoft C++ @c __uuidof expression, which gets
796 /// the _GUID that corresponds to the supplied type or expression.
798 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
799 class CXXUuidofExpr : public Expr {
801 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
806 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, StringRef UuidStr,
808 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
809 Operand->getType()->isDependentType(),
810 Operand->getType()->isInstantiationDependentType(),
811 Operand->getType()->containsUnexpandedParameterPack()),
812 Operand(Operand), UuidStr(UuidStr), Range(R) {}
814 CXXUuidofExpr(QualType Ty, Expr *Operand, StringRef UuidStr, SourceRange R)
815 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, false,
816 Operand->isTypeDependent(), Operand->isInstantiationDependent(),
817 Operand->containsUnexpandedParameterPack()),
818 Operand(Operand), UuidStr(UuidStr), Range(R) {}
820 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
821 : Expr(CXXUuidofExprClass, Empty) {
823 Operand = (Expr*)nullptr;
825 Operand = (TypeSourceInfo*)nullptr;
828 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
830 /// \brief Retrieves the type operand of this __uuidof() expression after
831 /// various required adjustments (removing reference types, cv-qualifiers).
832 QualType getTypeOperand(ASTContext &Context) const;
834 /// \brief Retrieve source information for the type operand.
835 TypeSourceInfo *getTypeOperandSourceInfo() const {
836 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
837 return Operand.get<TypeSourceInfo *>();
840 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
841 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
845 Expr *getExprOperand() const {
846 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
847 return static_cast<Expr*>(Operand.get<Stmt *>());
850 void setExprOperand(Expr *E) {
851 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
855 void setUuidStr(StringRef US) { UuidStr = US; }
856 StringRef getUuidStr() const { return UuidStr; }
858 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
859 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
860 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
861 void setSourceRange(SourceRange R) { Range = R; }
863 static bool classof(const Stmt *T) {
864 return T->getStmtClass() == CXXUuidofExprClass;
868 child_range children() {
870 return child_range(child_iterator(), child_iterator());
871 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
872 return child_range(begin, begin + 1);
876 /// \brief Represents the \c this expression in C++.
878 /// This is a pointer to the object on which the current member function is
879 /// executing (C++ [expr.prim]p3). Example:
885 /// void test() { this->bar(); }
888 class CXXThisExpr : public Expr {
893 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
894 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
895 // 'this' is type-dependent if the class type of the enclosing
896 // member function is dependent (C++ [temp.dep.expr]p2)
897 Type->isDependentType(), Type->isDependentType(),
898 Type->isInstantiationDependentType(),
899 /*ContainsUnexpandedParameterPack=*/false),
900 Loc(L), Implicit(isImplicit) { }
902 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
904 SourceLocation getLocation() const { return Loc; }
905 void setLocation(SourceLocation L) { Loc = L; }
907 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
908 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
910 bool isImplicit() const { return Implicit; }
911 void setImplicit(bool I) { Implicit = I; }
913 static bool classof(const Stmt *T) {
914 return T->getStmtClass() == CXXThisExprClass;
918 child_range children() {
919 return child_range(child_iterator(), child_iterator());
923 /// \brief A C++ throw-expression (C++ [except.throw]).
925 /// This handles 'throw' (for re-throwing the current exception) and
926 /// 'throw' assignment-expression. When assignment-expression isn't
927 /// present, Op will be null.
928 class CXXThrowExpr : public Expr {
930 SourceLocation ThrowLoc;
931 /// \brief Whether the thrown variable (if any) is in scope.
932 unsigned IsThrownVariableInScope : 1;
934 friend class ASTStmtReader;
937 // \p Ty is the void type which is used as the result type of the
938 // expression. The \p l is the location of the throw keyword. \p expr
939 // can by null, if the optional expression to throw isn't present.
940 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
941 bool IsThrownVariableInScope) :
942 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
943 expr && expr->isInstantiationDependent(),
944 expr && expr->containsUnexpandedParameterPack()),
945 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
946 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
948 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
949 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
951 SourceLocation getThrowLoc() const { return ThrowLoc; }
953 /// \brief Determines whether the variable thrown by this expression (if any!)
954 /// is within the innermost try block.
956 /// This information is required to determine whether the NRVO can apply to
958 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
960 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
961 SourceLocation getLocEnd() const LLVM_READONLY {
964 return getSubExpr()->getLocEnd();
967 static bool classof(const Stmt *T) {
968 return T->getStmtClass() == CXXThrowExprClass;
972 child_range children() {
973 return child_range(&Op, Op ? &Op+1 : &Op);
977 /// \brief A default argument (C++ [dcl.fct.default]).
979 /// This wraps up a function call argument that was created from the
980 /// corresponding parameter's default argument, when the call did not
981 /// explicitly supply arguments for all of the parameters.
982 class CXXDefaultArgExpr final : public Expr {
983 /// \brief The parameter whose default is being used.
986 /// \brief The location where the default argument expression was used.
989 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
991 param->hasUnparsedDefaultArg()
992 ? param->getType().getNonReferenceType()
993 : param->getDefaultArg()->getType(),
994 param->getDefaultArg()->getValueKind(),
995 param->getDefaultArg()->getObjectKind(), false, false, false, false),
996 Param(param), Loc(Loc) { }
999 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
1001 // \p Param is the parameter whose default argument is used by this
1003 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
1004 ParmVarDecl *Param) {
1005 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
1008 // Retrieve the parameter that the argument was created from.
1009 const ParmVarDecl *getParam() const { return Param; }
1010 ParmVarDecl *getParam() { return Param; }
1012 // Retrieve the actual argument to the function call.
1013 const Expr *getExpr() const {
1014 return getParam()->getDefaultArg();
1017 return getParam()->getDefaultArg();
1020 /// \brief Retrieve the location where this default argument was actually
1022 SourceLocation getUsedLocation() const { return Loc; }
1024 /// Default argument expressions have no representation in the
1025 /// source, so they have an empty source range.
1026 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1027 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1029 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1031 static bool classof(const Stmt *T) {
1032 return T->getStmtClass() == CXXDefaultArgExprClass;
1036 child_range children() {
1037 return child_range(child_iterator(), child_iterator());
1040 friend class ASTStmtReader;
1041 friend class ASTStmtWriter;
1044 /// \brief A use of a default initializer in a constructor or in aggregate
1047 /// This wraps a use of a C++ default initializer (technically,
1048 /// a brace-or-equal-initializer for a non-static data member) when it
1049 /// is implicitly used in a mem-initializer-list in a constructor
1050 /// (C++11 [class.base.init]p8) or in aggregate initialization
1051 /// (C++1y [dcl.init.aggr]p7).
1052 class CXXDefaultInitExpr : public Expr {
1053 /// \brief The field whose default is being used.
1056 /// \brief The location where the default initializer expression was used.
1059 CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
1062 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
1065 /// \p Field is the non-static data member whose default initializer is used
1066 /// by this expression.
1067 static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
1069 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
1072 /// \brief Get the field whose initializer will be used.
1073 FieldDecl *getField() { return Field; }
1074 const FieldDecl *getField() const { return Field; }
1076 /// \brief Get the initialization expression that will be used.
1077 const Expr *getExpr() const {
1078 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1079 return Field->getInClassInitializer();
1082 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
1083 return Field->getInClassInitializer();
1086 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1087 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1089 static bool classof(const Stmt *T) {
1090 return T->getStmtClass() == CXXDefaultInitExprClass;
1094 child_range children() {
1095 return child_range(child_iterator(), child_iterator());
1098 friend class ASTReader;
1099 friend class ASTStmtReader;
1102 /// \brief Represents a C++ temporary.
1103 class CXXTemporary {
1104 /// \brief The destructor that needs to be called.
1105 const CXXDestructorDecl *Destructor;
1107 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1108 : Destructor(destructor) { }
1111 static CXXTemporary *Create(const ASTContext &C,
1112 const CXXDestructorDecl *Destructor);
1114 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1115 void setDestructor(const CXXDestructorDecl *Dtor) {
1120 /// \brief Represents binding an expression to a temporary.
1122 /// This ensures the destructor is called for the temporary. It should only be
1123 /// needed for non-POD, non-trivially destructable class types. For example:
1127 /// S() { } // User defined constructor makes S non-POD.
1128 /// ~S() { } // User defined destructor makes it non-trivial.
1131 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1134 class CXXBindTemporaryExpr : public Expr {
1139 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1140 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1141 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1142 SubExpr->isValueDependent(),
1143 SubExpr->isInstantiationDependent(),
1144 SubExpr->containsUnexpandedParameterPack()),
1145 Temp(temp), SubExpr(SubExpr) { }
1148 CXXBindTemporaryExpr(EmptyShell Empty)
1149 : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
1151 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1154 CXXTemporary *getTemporary() { return Temp; }
1155 const CXXTemporary *getTemporary() const { return Temp; }
1156 void setTemporary(CXXTemporary *T) { Temp = T; }
1158 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1159 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1160 void setSubExpr(Expr *E) { SubExpr = E; }
1162 SourceLocation getLocStart() const LLVM_READONLY {
1163 return SubExpr->getLocStart();
1165 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1167 // Implement isa/cast/dyncast/etc.
1168 static bool classof(const Stmt *T) {
1169 return T->getStmtClass() == CXXBindTemporaryExprClass;
1173 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1176 /// \brief Represents a call to a C++ constructor.
1177 class CXXConstructExpr : public Expr {
1179 enum ConstructionKind {
1187 CXXConstructorDecl *Constructor;
1190 SourceRange ParenOrBraceRange;
1191 unsigned NumArgs : 16;
1192 unsigned Elidable : 1;
1193 unsigned HadMultipleCandidates : 1;
1194 unsigned ListInitialization : 1;
1195 unsigned StdInitListInitialization : 1;
1196 unsigned ZeroInitialization : 1;
1197 unsigned ConstructKind : 2;
1200 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1203 CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1205 CXXConstructorDecl *Ctor,
1207 ArrayRef<Expr *> Args,
1208 bool HadMultipleCandidates,
1209 bool ListInitialization,
1210 bool StdInitListInitialization,
1211 bool ZeroInitialization,
1212 ConstructionKind ConstructKind,
1213 SourceRange ParenOrBraceRange);
1215 /// \brief Construct an empty C++ construction expression.
1216 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1217 : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
1218 HadMultipleCandidates(false), ListInitialization(false),
1219 ZeroInitialization(false), ConstructKind(0), Args(nullptr)
1223 /// \brief Construct an empty C++ construction expression.
1224 explicit CXXConstructExpr(EmptyShell Empty)
1225 : CXXConstructExpr(CXXConstructExprClass, Empty) {}
1227 static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1229 CXXConstructorDecl *Ctor,
1231 ArrayRef<Expr *> Args,
1232 bool HadMultipleCandidates,
1233 bool ListInitialization,
1234 bool StdInitListInitialization,
1235 bool ZeroInitialization,
1236 ConstructionKind ConstructKind,
1237 SourceRange ParenOrBraceRange);
1239 /// \brief Get the constructor that this expression will (ultimately) call.
1240 CXXConstructorDecl *getConstructor() const { return Constructor; }
1242 SourceLocation getLocation() const { return Loc; }
1243 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1245 /// \brief Whether this construction is elidable.
1246 bool isElidable() const { return Elidable; }
1247 void setElidable(bool E) { Elidable = E; }
1249 /// \brief Whether the referred constructor was resolved from
1250 /// an overloaded set having size greater than 1.
1251 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1252 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1254 /// \brief Whether this constructor call was written as list-initialization.
1255 bool isListInitialization() const { return ListInitialization; }
1256 void setListInitialization(bool V) { ListInitialization = V; }
1258 /// \brief Whether this constructor call was written as list-initialization,
1259 /// but was interpreted as forming a std::initializer_list<T> from the list
1260 /// and passing that as a single constructor argument.
1261 /// See C++11 [over.match.list]p1 bullet 1.
1262 bool isStdInitListInitialization() const { return StdInitListInitialization; }
1263 void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1265 /// \brief Whether this construction first requires
1266 /// zero-initialization before the initializer is called.
1267 bool requiresZeroInitialization() const { return ZeroInitialization; }
1268 void setRequiresZeroInitialization(bool ZeroInit) {
1269 ZeroInitialization = ZeroInit;
1272 /// \brief Determine whether this constructor is actually constructing
1273 /// a base class (rather than a complete object).
1274 ConstructionKind getConstructionKind() const {
1275 return (ConstructionKind)ConstructKind;
1277 void setConstructionKind(ConstructionKind CK) {
1281 typedef ExprIterator arg_iterator;
1282 typedef ConstExprIterator const_arg_iterator;
1283 typedef llvm::iterator_range<arg_iterator> arg_range;
1284 typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
1286 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1287 arg_const_range arguments() const {
1288 return arg_const_range(arg_begin(), arg_end());
1291 arg_iterator arg_begin() { return Args; }
1292 arg_iterator arg_end() { return Args + NumArgs; }
1293 const_arg_iterator arg_begin() const { return Args; }
1294 const_arg_iterator arg_end() const { return Args + NumArgs; }
1296 Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
1297 const Expr *const *getArgs() const {
1298 return const_cast<CXXConstructExpr *>(this)->getArgs();
1300 unsigned getNumArgs() const { return NumArgs; }
1302 /// \brief Return the specified argument.
1303 Expr *getArg(unsigned Arg) {
1304 assert(Arg < NumArgs && "Arg access out of range!");
1305 return cast<Expr>(Args[Arg]);
1307 const Expr *getArg(unsigned Arg) const {
1308 assert(Arg < NumArgs && "Arg access out of range!");
1309 return cast<Expr>(Args[Arg]);
1312 /// \brief Set the specified argument.
1313 void setArg(unsigned Arg, Expr *ArgExpr) {
1314 assert(Arg < NumArgs && "Arg access out of range!");
1315 Args[Arg] = ArgExpr;
1318 SourceLocation getLocStart() const LLVM_READONLY;
1319 SourceLocation getLocEnd() const LLVM_READONLY;
1320 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1321 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1323 static bool classof(const Stmt *T) {
1324 return T->getStmtClass() == CXXConstructExprClass ||
1325 T->getStmtClass() == CXXTemporaryObjectExprClass;
1329 child_range children() {
1330 return child_range(&Args[0], &Args[0]+NumArgs);
1333 friend class ASTStmtReader;
1336 /// \brief Represents a call to an inherited base class constructor from an
1337 /// inheriting constructor. This call implicitly forwards the arguments from
1338 /// the enclosing context (an inheriting constructor) to the specified inherited
1339 /// base class constructor.
1340 class CXXInheritedCtorInitExpr : public Expr {
1342 CXXConstructorDecl *Constructor;
1344 /// The location of the using declaration.
1347 /// Whether this is the construction of a virtual base.
1348 unsigned ConstructsVirtualBase : 1;
1350 /// Whether the constructor is inherited from a virtual base class of the
1351 /// class that we construct.
1352 unsigned InheritedFromVirtualBase : 1;
1355 /// \brief Construct a C++ inheriting construction expression.
1356 CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T,
1357 CXXConstructorDecl *Ctor, bool ConstructsVirtualBase,
1358 bool InheritedFromVirtualBase)
1359 : Expr(CXXInheritedCtorInitExprClass, T, VK_RValue, OK_Ordinary, false,
1360 false, false, false),
1361 Constructor(Ctor), Loc(Loc),
1362 ConstructsVirtualBase(ConstructsVirtualBase),
1363 InheritedFromVirtualBase(InheritedFromVirtualBase) {
1364 assert(!T->isDependentType());
1367 /// \brief Construct an empty C++ inheriting construction expression.
1368 explicit CXXInheritedCtorInitExpr(EmptyShell Empty)
1369 : Expr(CXXInheritedCtorInitExprClass, Empty), Constructor(nullptr),
1370 ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {}
1372 /// \brief Get the constructor that this expression will call.
1373 CXXConstructorDecl *getConstructor() const { return Constructor; }
1375 /// \brief Determine whether this constructor is actually constructing
1376 /// a base class (rather than a complete object).
1377 bool constructsVBase() const { return ConstructsVirtualBase; }
1378 CXXConstructExpr::ConstructionKind getConstructionKind() const {
1379 return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase
1380 : CXXConstructExpr::CK_NonVirtualBase;
1383 /// \brief Determine whether the inherited constructor is inherited from a
1384 /// virtual base of the object we construct. If so, we are not responsible
1385 /// for calling the inherited constructor (the complete object constructor
1386 /// does that), and so we don't need to pass any arguments.
1387 bool inheritedFromVBase() const { return InheritedFromVirtualBase; }
1389 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
1390 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1391 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1393 static bool classof(const Stmt *T) {
1394 return T->getStmtClass() == CXXInheritedCtorInitExprClass;
1396 child_range children() {
1397 return child_range(child_iterator(), child_iterator());
1400 friend class ASTStmtReader;
1403 /// \brief Represents an explicit C++ type conversion that uses "functional"
1404 /// notation (C++ [expr.type.conv]).
1410 class CXXFunctionalCastExpr final
1411 : public ExplicitCastExpr,
1412 private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *> {
1413 SourceLocation LParenLoc;
1414 SourceLocation RParenLoc;
1416 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1417 TypeSourceInfo *writtenTy,
1418 CastKind kind, Expr *castExpr, unsigned pathSize,
1419 SourceLocation lParenLoc, SourceLocation rParenLoc)
1420 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1421 castExpr, pathSize, writtenTy),
1422 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1424 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1425 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1428 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1430 TypeSourceInfo *Written,
1431 CastKind Kind, Expr *Op,
1432 const CXXCastPath *Path,
1433 SourceLocation LPLoc,
1434 SourceLocation RPLoc);
1435 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1438 SourceLocation getLParenLoc() const { return LParenLoc; }
1439 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1440 SourceLocation getRParenLoc() const { return RParenLoc; }
1441 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1443 SourceLocation getLocStart() const LLVM_READONLY;
1444 SourceLocation getLocEnd() const LLVM_READONLY;
1446 static bool classof(const Stmt *T) {
1447 return T->getStmtClass() == CXXFunctionalCastExprClass;
1450 friend TrailingObjects;
1451 friend class CastExpr;
1454 /// @brief Represents a C++ functional cast expression that builds a
1455 /// temporary object.
1457 /// This expression type represents a C++ "functional" cast
1458 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1459 /// constructor to build a temporary object. With N == 1 arguments the
1460 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1463 /// struct X { X(int, float); }
1466 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1469 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1470 TypeSourceInfo *Type;
1473 CXXTemporaryObjectExpr(const ASTContext &C,
1474 CXXConstructorDecl *Cons,
1476 TypeSourceInfo *TSI,
1477 ArrayRef<Expr *> Args,
1478 SourceRange ParenOrBraceRange,
1479 bool HadMultipleCandidates,
1480 bool ListInitialization,
1481 bool StdInitListInitialization,
1482 bool ZeroInitialization);
1483 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1484 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1486 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1488 SourceLocation getLocStart() const LLVM_READONLY;
1489 SourceLocation getLocEnd() const LLVM_READONLY;
1491 static bool classof(const Stmt *T) {
1492 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1495 friend class ASTStmtReader;
1498 /// \brief A C++ lambda expression, which produces a function object
1499 /// (of unspecified type) that can be invoked later.
1503 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1504 /// values.erase(std::remove_if(values.begin(), values.end(),
1505 /// [=](double value) { return value > cutoff; });
1509 /// C++11 lambda expressions can capture local variables, either by copying
1510 /// the values of those local variables at the time the function
1511 /// object is constructed (not when it is called!) or by holding a
1512 /// reference to the local variable. These captures can occur either
1513 /// implicitly or can be written explicitly between the square
1514 /// brackets ([...]) that start the lambda expression.
1516 /// C++1y introduces a new form of "capture" called an init-capture that
1517 /// includes an initializing expression (rather than capturing a variable),
1518 /// and which can never occur implicitly.
1519 class LambdaExpr final : public Expr,
1520 private llvm::TrailingObjects<LambdaExpr, Stmt *> {
1521 /// \brief The source range that covers the lambda introducer ([...]).
1522 SourceRange IntroducerRange;
1524 /// \brief The source location of this lambda's capture-default ('=' or '&').
1525 SourceLocation CaptureDefaultLoc;
1527 /// \brief The number of captures.
1528 unsigned NumCaptures : 16;
1530 /// \brief The default capture kind, which is a value of type
1531 /// LambdaCaptureDefault.
1532 unsigned CaptureDefault : 2;
1534 /// \brief Whether this lambda had an explicit parameter list vs. an
1535 /// implicit (and empty) parameter list.
1536 unsigned ExplicitParams : 1;
1538 /// \brief Whether this lambda had the result type explicitly specified.
1539 unsigned ExplicitResultType : 1;
1541 /// \brief The location of the closing brace ('}') that completes
1544 /// The location of the brace is also available by looking up the
1545 /// function call operator in the lambda class. However, it is
1546 /// stored here to improve the performance of getSourceRange(), and
1547 /// to avoid having to deserialize the function call operator from a
1548 /// module file just to determine the source range.
1549 SourceLocation ClosingBrace;
1551 /// \brief Construct a lambda expression.
1552 LambdaExpr(QualType T, SourceRange IntroducerRange,
1553 LambdaCaptureDefault CaptureDefault,
1554 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1555 bool ExplicitParams, bool ExplicitResultType,
1556 ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace,
1557 bool ContainsUnexpandedParameterPack);
1559 /// \brief Construct an empty lambda expression.
1560 LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1561 : Expr(LambdaExprClass, Empty),
1562 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1563 ExplicitResultType(false) {
1564 getStoredStmts()[NumCaptures] = nullptr;
1567 Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); }
1569 Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); }
1572 /// \brief Construct a new lambda expression.
1574 Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange,
1575 LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc,
1576 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1577 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1578 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack);
1580 /// \brief Construct a new lambda expression that will be deserialized from
1581 /// an external source.
1582 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1583 unsigned NumCaptures);
1585 /// \brief Determine the default capture kind for this lambda.
1586 LambdaCaptureDefault getCaptureDefault() const {
1587 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1590 /// \brief Retrieve the location of this lambda's capture-default, if any.
1591 SourceLocation getCaptureDefaultLoc() const {
1592 return CaptureDefaultLoc;
1595 /// \brief Determine whether one of this lambda's captures is an init-capture.
1596 bool isInitCapture(const LambdaCapture *Capture) const;
1598 /// \brief An iterator that walks over the captures of the lambda,
1599 /// both implicit and explicit.
1600 typedef const LambdaCapture *capture_iterator;
1602 /// \brief An iterator over a range of lambda captures.
1603 typedef llvm::iterator_range<capture_iterator> capture_range;
1605 /// \brief Retrieve this lambda's captures.
1606 capture_range captures() const;
1608 /// \brief Retrieve an iterator pointing to the first lambda capture.
1609 capture_iterator capture_begin() const;
1611 /// \brief Retrieve an iterator pointing past the end of the
1612 /// sequence of lambda captures.
1613 capture_iterator capture_end() const;
1615 /// \brief Determine the number of captures in this lambda.
1616 unsigned capture_size() const { return NumCaptures; }
1618 /// \brief Retrieve this lambda's explicit captures.
1619 capture_range explicit_captures() const;
1621 /// \brief Retrieve an iterator pointing to the first explicit
1623 capture_iterator explicit_capture_begin() const;
1625 /// \brief Retrieve an iterator pointing past the end of the sequence of
1626 /// explicit lambda captures.
1627 capture_iterator explicit_capture_end() const;
1629 /// \brief Retrieve this lambda's implicit captures.
1630 capture_range implicit_captures() const;
1632 /// \brief Retrieve an iterator pointing to the first implicit
1634 capture_iterator implicit_capture_begin() const;
1636 /// \brief Retrieve an iterator pointing past the end of the sequence of
1637 /// implicit lambda captures.
1638 capture_iterator implicit_capture_end() const;
1640 /// \brief Iterator that walks over the capture initialization
1642 typedef Expr **capture_init_iterator;
1644 /// \brief Const iterator that walks over the capture initialization
1646 typedef Expr *const *const_capture_init_iterator;
1648 /// \brief Retrieve the initialization expressions for this lambda's captures.
1649 llvm::iterator_range<capture_init_iterator> capture_inits() {
1650 return llvm::make_range(capture_init_begin(), capture_init_end());
1653 /// \brief Retrieve the initialization expressions for this lambda's captures.
1654 llvm::iterator_range<const_capture_init_iterator> capture_inits() const {
1655 return llvm::make_range(capture_init_begin(), capture_init_end());
1658 /// \brief Retrieve the first initialization argument for this
1659 /// lambda expression (which initializes the first capture field).
1660 capture_init_iterator capture_init_begin() {
1661 return reinterpret_cast<Expr **>(getStoredStmts());
1664 /// \brief Retrieve the first initialization argument for this
1665 /// lambda expression (which initializes the first capture field).
1666 const_capture_init_iterator capture_init_begin() const {
1667 return reinterpret_cast<Expr *const *>(getStoredStmts());
1670 /// \brief Retrieve the iterator pointing one past the last
1671 /// initialization argument for this lambda expression.
1672 capture_init_iterator capture_init_end() {
1673 return capture_init_begin() + NumCaptures;
1676 /// \brief Retrieve the iterator pointing one past the last
1677 /// initialization argument for this lambda expression.
1678 const_capture_init_iterator capture_init_end() const {
1679 return capture_init_begin() + NumCaptures;
1682 /// \brief Retrieve the source range covering the lambda introducer,
1683 /// which contains the explicit capture list surrounded by square
1684 /// brackets ([...]).
1685 SourceRange getIntroducerRange() const { return IntroducerRange; }
1687 /// \brief Retrieve the class that corresponds to the lambda.
1689 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1690 /// captures in its fields and provides the various operations permitted
1691 /// on a lambda (copying, calling).
1692 CXXRecordDecl *getLambdaClass() const;
1694 /// \brief Retrieve the function call operator associated with this
1695 /// lambda expression.
1696 CXXMethodDecl *getCallOperator() const;
1698 /// \brief If this is a generic lambda expression, retrieve the template
1699 /// parameter list associated with it, or else return null.
1700 TemplateParameterList *getTemplateParameterList() const;
1702 /// \brief Whether this is a generic lambda.
1703 bool isGenericLambda() const { return getTemplateParameterList(); }
1705 /// \brief Retrieve the body of the lambda.
1706 CompoundStmt *getBody() const;
1708 /// \brief Determine whether the lambda is mutable, meaning that any
1709 /// captures values can be modified.
1710 bool isMutable() const;
1712 /// \brief Determine whether this lambda has an explicit parameter
1713 /// list vs. an implicit (empty) parameter list.
1714 bool hasExplicitParameters() const { return ExplicitParams; }
1716 /// \brief Whether this lambda had its result type explicitly specified.
1717 bool hasExplicitResultType() const { return ExplicitResultType; }
1719 static bool classof(const Stmt *T) {
1720 return T->getStmtClass() == LambdaExprClass;
1723 SourceLocation getLocStart() const LLVM_READONLY {
1724 return IntroducerRange.getBegin();
1726 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1728 child_range children() {
1729 // Includes initialization exprs plus body stmt
1730 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1733 friend TrailingObjects;
1734 friend class ASTStmtReader;
1735 friend class ASTStmtWriter;
1738 /// An expression "T()" which creates a value-initialized rvalue of type
1739 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
1740 class CXXScalarValueInitExpr : public Expr {
1741 SourceLocation RParenLoc;
1742 TypeSourceInfo *TypeInfo;
1744 friend class ASTStmtReader;
1747 /// \brief Create an explicitly-written scalar-value initialization
1749 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1750 SourceLocation rParenLoc)
1751 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1752 false, false, Type->isInstantiationDependentType(),
1753 Type->containsUnexpandedParameterPack()),
1754 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1756 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1757 : Expr(CXXScalarValueInitExprClass, Shell) { }
1759 TypeSourceInfo *getTypeSourceInfo() const {
1763 SourceLocation getRParenLoc() const { return RParenLoc; }
1765 SourceLocation getLocStart() const LLVM_READONLY;
1766 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1768 static bool classof(const Stmt *T) {
1769 return T->getStmtClass() == CXXScalarValueInitExprClass;
1773 child_range children() {
1774 return child_range(child_iterator(), child_iterator());
1778 /// \brief Represents a new-expression for memory allocation and constructor
1779 /// calls, e.g: "new CXXNewExpr(foo)".
1780 class CXXNewExpr : public Expr {
1781 /// Contains an optional array size expression, an optional initialization
1782 /// expression, and any number of optional placement arguments, in that order.
1784 /// \brief Points to the allocation function used.
1785 FunctionDecl *OperatorNew;
1786 /// \brief Points to the deallocation function used in case of error. May be
1788 FunctionDecl *OperatorDelete;
1790 /// \brief The allocated type-source information, as written in the source.
1791 TypeSourceInfo *AllocatedTypeInfo;
1793 /// \brief If the allocated type was expressed as a parenthesized type-id,
1794 /// the source range covering the parenthesized type-id.
1795 SourceRange TypeIdParens;
1797 /// \brief Range of the entire new expression.
1800 /// \brief Source-range of a paren-delimited initializer.
1801 SourceRange DirectInitRange;
1803 /// Was the usage ::new, i.e. is the global new to be used?
1804 unsigned GlobalNew : 1;
1805 /// Do we allocate an array? If so, the first SubExpr is the size expression.
1807 /// Should the alignment be passed to the allocation function?
1808 unsigned PassAlignment : 1;
1809 /// If this is an array allocation, does the usual deallocation
1810 /// function for the allocated type want to know the allocated size?
1811 unsigned UsualArrayDeleteWantsSize : 1;
1812 /// The number of placement new arguments.
1813 unsigned NumPlacementArgs : 26;
1814 /// What kind of initializer do we have? Could be none, parens, or braces.
1815 /// In storage, we distinguish between "none, and no initializer expr", and
1816 /// "none, but an implicit initializer expr".
1817 unsigned StoredInitializationStyle : 2;
1819 friend class ASTStmtReader;
1820 friend class ASTStmtWriter;
1822 enum InitializationStyle {
1823 NoInit, ///< New-expression has no initializer as written.
1824 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1825 ListInit ///< New-expression has a C++11 list-initializer.
1828 CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1829 FunctionDecl *operatorDelete, bool PassAlignment,
1830 bool usualArrayDeleteWantsSize, ArrayRef<Expr*> placementArgs,
1831 SourceRange typeIdParens, Expr *arraySize,
1832 InitializationStyle initializationStyle, Expr *initializer,
1833 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1834 SourceRange Range, SourceRange directInitRange);
1835 explicit CXXNewExpr(EmptyShell Shell)
1836 : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
1838 void AllocateArgsArray(const ASTContext &C, bool isArray,
1839 unsigned numPlaceArgs, bool hasInitializer);
1841 QualType getAllocatedType() const {
1842 assert(getType()->isPointerType());
1843 return getType()->getAs<PointerType>()->getPointeeType();
1846 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1847 return AllocatedTypeInfo;
1850 /// \brief True if the allocation result needs to be null-checked.
1852 /// C++11 [expr.new]p13:
1853 /// If the allocation function returns null, initialization shall
1854 /// not be done, the deallocation function shall not be called,
1855 /// and the value of the new-expression shall be null.
1858 /// If the allocation function is a reserved placement allocation
1859 /// function that returns null, the behavior is undefined.
1861 /// An allocation function is not allowed to return null unless it
1862 /// has a non-throwing exception-specification. The '03 rule is
1863 /// identical except that the definition of a non-throwing
1864 /// exception specification is just "is it throw()?".
1865 bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1867 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1868 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1869 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1870 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1872 bool isArray() const { return Array; }
1873 Expr *getArraySize() {
1874 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1876 const Expr *getArraySize() const {
1877 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1880 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1881 Expr **getPlacementArgs() {
1882 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1885 Expr *getPlacementArg(unsigned i) {
1886 assert(i < NumPlacementArgs && "Index out of range");
1887 return getPlacementArgs()[i];
1889 const Expr *getPlacementArg(unsigned i) const {
1890 assert(i < NumPlacementArgs && "Index out of range");
1891 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1894 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1895 SourceRange getTypeIdParens() const { return TypeIdParens; }
1897 bool isGlobalNew() const { return GlobalNew; }
1899 /// \brief Whether this new-expression has any initializer at all.
1900 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1902 /// \brief The kind of initializer this new-expression has.
1903 InitializationStyle getInitializationStyle() const {
1904 if (StoredInitializationStyle == 0)
1906 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1909 /// \brief The initializer of this new-expression.
1910 Expr *getInitializer() {
1911 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1913 const Expr *getInitializer() const {
1914 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1917 /// \brief Returns the CXXConstructExpr from this new-expression, or null.
1918 const CXXConstructExpr *getConstructExpr() const {
1919 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1922 /// Indicates whether the required alignment should be implicitly passed to
1923 /// the allocation function.
1924 bool passAlignment() const {
1925 return PassAlignment;
1928 /// Answers whether the usual array deallocation function for the
1929 /// allocated type expects the size of the allocation as a
1931 bool doesUsualArrayDeleteWantSize() const {
1932 return UsualArrayDeleteWantsSize;
1935 typedef ExprIterator arg_iterator;
1936 typedef ConstExprIterator const_arg_iterator;
1938 llvm::iterator_range<arg_iterator> placement_arguments() {
1939 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1942 llvm::iterator_range<const_arg_iterator> placement_arguments() const {
1943 return llvm::make_range(placement_arg_begin(), placement_arg_end());
1946 arg_iterator placement_arg_begin() {
1947 return SubExprs + Array + hasInitializer();
1949 arg_iterator placement_arg_end() {
1950 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1952 const_arg_iterator placement_arg_begin() const {
1953 return SubExprs + Array + hasInitializer();
1955 const_arg_iterator placement_arg_end() const {
1956 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1959 typedef Stmt **raw_arg_iterator;
1960 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1961 raw_arg_iterator raw_arg_end() {
1962 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1964 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1965 const_arg_iterator raw_arg_end() const {
1966 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1969 SourceLocation getStartLoc() const { return Range.getBegin(); }
1970 SourceLocation getEndLoc() const { return Range.getEnd(); }
1972 SourceRange getDirectInitRange() const { return DirectInitRange; }
1974 SourceRange getSourceRange() const LLVM_READONLY {
1977 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
1978 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1980 static bool classof(const Stmt *T) {
1981 return T->getStmtClass() == CXXNewExprClass;
1985 child_range children() {
1986 return child_range(raw_arg_begin(), raw_arg_end());
1990 /// \brief Represents a \c delete expression for memory deallocation and
1991 /// destructor calls, e.g. "delete[] pArray".
1992 class CXXDeleteExpr : public Expr {
1993 /// Points to the operator delete overload that is used. Could be a member.
1994 FunctionDecl *OperatorDelete;
1995 /// The pointer expression to be deleted.
1997 /// Location of the expression.
1999 /// Is this a forced global delete, i.e. "::delete"?
2000 bool GlobalDelete : 1;
2001 /// Is this the array form of delete, i.e. "delete[]"?
2003 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
2004 /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
2006 bool ArrayFormAsWritten : 1;
2007 /// Does the usual deallocation function for the element type require
2008 /// a size_t argument?
2009 bool UsualArrayDeleteWantsSize : 1;
2011 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
2012 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
2013 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
2014 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
2015 arg->isInstantiationDependent(),
2016 arg->containsUnexpandedParameterPack()),
2017 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
2018 GlobalDelete(globalDelete),
2019 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
2020 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
2021 explicit CXXDeleteExpr(EmptyShell Shell)
2022 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
2023 Argument(nullptr) {}
2025 bool isGlobalDelete() const { return GlobalDelete; }
2026 bool isArrayForm() const { return ArrayForm; }
2027 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
2029 /// Answers whether the usual array deallocation function for the
2030 /// allocated type expects the size of the allocation as a
2031 /// parameter. This can be true even if the actual deallocation
2032 /// function that we're using doesn't want a size.
2033 bool doesUsualArrayDeleteWantSize() const {
2034 return UsualArrayDeleteWantsSize;
2037 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
2039 Expr *getArgument() { return cast<Expr>(Argument); }
2040 const Expr *getArgument() const { return cast<Expr>(Argument); }
2042 /// \brief Retrieve the type being destroyed.
2044 /// If the type being destroyed is a dependent type which may or may not
2045 /// be a pointer, return an invalid type.
2046 QualType getDestroyedType() const;
2048 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2049 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
2051 static bool classof(const Stmt *T) {
2052 return T->getStmtClass() == CXXDeleteExprClass;
2056 child_range children() { return child_range(&Argument, &Argument+1); }
2058 friend class ASTStmtReader;
2061 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
2062 class PseudoDestructorTypeStorage {
2063 /// \brief Either the type source information or the name of the type, if
2064 /// it couldn't be resolved due to type-dependence.
2065 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
2067 /// \brief The starting source location of the pseudo-destructor type.
2068 SourceLocation Location;
2071 PseudoDestructorTypeStorage() { }
2073 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
2074 : Type(II), Location(Loc) { }
2076 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
2078 TypeSourceInfo *getTypeSourceInfo() const {
2079 return Type.dyn_cast<TypeSourceInfo *>();
2082 IdentifierInfo *getIdentifier() const {
2083 return Type.dyn_cast<IdentifierInfo *>();
2086 SourceLocation getLocation() const { return Location; }
2089 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
2091 /// A pseudo-destructor is an expression that looks like a member access to a
2092 /// destructor of a scalar type, except that scalar types don't have
2093 /// destructors. For example:
2097 /// void f(int *p) {
2102 /// Pseudo-destructors typically occur when instantiating templates such as:
2105 /// template<typename T>
2106 /// void destroy(T* ptr) {
2111 /// for scalar types. A pseudo-destructor expression has no run-time semantics
2112 /// beyond evaluating the base expression.
2113 class CXXPseudoDestructorExpr : public Expr {
2114 /// \brief The base expression (that is being destroyed).
2117 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
2121 /// \brief The location of the '.' or '->' operator.
2122 SourceLocation OperatorLoc;
2124 /// \brief The nested-name-specifier that follows the operator, if present.
2125 NestedNameSpecifierLoc QualifierLoc;
2127 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
2129 TypeSourceInfo *ScopeType;
2131 /// \brief The location of the '::' in a qualified pseudo-destructor
2133 SourceLocation ColonColonLoc;
2135 /// \brief The location of the '~'.
2136 SourceLocation TildeLoc;
2138 /// \brief The type being destroyed, or its name if we were unable to
2139 /// resolve the name.
2140 PseudoDestructorTypeStorage DestroyedType;
2142 friend class ASTStmtReader;
2145 CXXPseudoDestructorExpr(const ASTContext &Context,
2146 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2147 NestedNameSpecifierLoc QualifierLoc,
2148 TypeSourceInfo *ScopeType,
2149 SourceLocation ColonColonLoc,
2150 SourceLocation TildeLoc,
2151 PseudoDestructorTypeStorage DestroyedType);
2153 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2154 : Expr(CXXPseudoDestructorExprClass, Shell),
2155 Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
2157 Expr *getBase() const { return cast<Expr>(Base); }
2159 /// \brief Determines whether this member expression actually had
2160 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2162 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
2164 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
2165 /// with source-location information.
2166 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2168 /// \brief If the member name was qualified, retrieves the
2169 /// nested-name-specifier that precedes the member name. Otherwise, returns
2171 NestedNameSpecifier *getQualifier() const {
2172 return QualifierLoc.getNestedNameSpecifier();
2175 /// \brief Determine whether this pseudo-destructor expression was written
2176 /// using an '->' (otherwise, it used a '.').
2177 bool isArrow() const { return IsArrow; }
2179 /// \brief Retrieve the location of the '.' or '->' operator.
2180 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2182 /// \brief Retrieve the scope type in a qualified pseudo-destructor
2185 /// Pseudo-destructor expressions can have extra qualification within them
2186 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2187 /// Here, if the object type of the expression is (or may be) a scalar type,
2188 /// \p T may also be a scalar type and, therefore, cannot be part of a
2189 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2190 /// destructor expression.
2191 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2193 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2195 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2197 /// \brief Retrieve the location of the '~'.
2198 SourceLocation getTildeLoc() const { return TildeLoc; }
2200 /// \brief Retrieve the source location information for the type
2201 /// being destroyed.
2203 /// This type-source information is available for non-dependent
2204 /// pseudo-destructor expressions and some dependent pseudo-destructor
2205 /// expressions. Returns null if we only have the identifier for a
2206 /// dependent pseudo-destructor expression.
2207 TypeSourceInfo *getDestroyedTypeInfo() const {
2208 return DestroyedType.getTypeSourceInfo();
2211 /// \brief In a dependent pseudo-destructor expression for which we do not
2212 /// have full type information on the destroyed type, provides the name
2213 /// of the destroyed type.
2214 IdentifierInfo *getDestroyedTypeIdentifier() const {
2215 return DestroyedType.getIdentifier();
2218 /// \brief Retrieve the type being destroyed.
2219 QualType getDestroyedType() const;
2221 /// \brief Retrieve the starting location of the type being destroyed.
2222 SourceLocation getDestroyedTypeLoc() const {
2223 return DestroyedType.getLocation();
2226 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2228 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2229 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2232 /// \brief Set the destroyed type.
2233 void setDestroyedType(TypeSourceInfo *Info) {
2234 DestroyedType = PseudoDestructorTypeStorage(Info);
2237 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2238 SourceLocation getLocEnd() const LLVM_READONLY;
2240 static bool classof(const Stmt *T) {
2241 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2245 child_range children() { return child_range(&Base, &Base + 1); }
2248 /// \brief A type trait used in the implementation of various C++11 and
2249 /// Library TR1 trait templates.
2252 /// __is_pod(int) == true
2253 /// __is_enum(std::string) == false
2254 /// __is_trivially_constructible(vector<int>, int*, int*)
2256 class TypeTraitExpr final
2258 private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> {
2259 /// \brief The location of the type trait keyword.
2262 /// \brief The location of the closing parenthesis.
2263 SourceLocation RParenLoc;
2265 // Note: The TypeSourceInfos for the arguments are allocated after the
2268 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2269 ArrayRef<TypeSourceInfo *> Args,
2270 SourceLocation RParenLoc,
2273 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2275 size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
2276 return getNumArgs();
2280 /// \brief Create a new type trait expression.
2281 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2282 SourceLocation Loc, TypeTrait Kind,
2283 ArrayRef<TypeSourceInfo *> Args,
2284 SourceLocation RParenLoc,
2287 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2290 /// \brief Determine which type trait this expression uses.
2291 TypeTrait getTrait() const {
2292 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2295 bool getValue() const {
2296 assert(!isValueDependent());
2297 return TypeTraitExprBits.Value;
2300 /// \brief Determine the number of arguments to this type trait.
2301 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2303 /// \brief Retrieve the Ith argument.
2304 TypeSourceInfo *getArg(unsigned I) const {
2305 assert(I < getNumArgs() && "Argument out-of-range");
2306 return getArgs()[I];
2309 /// \brief Retrieve the argument types.
2310 ArrayRef<TypeSourceInfo *> getArgs() const {
2311 return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(),
2315 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2316 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2318 static bool classof(const Stmt *T) {
2319 return T->getStmtClass() == TypeTraitExprClass;
2323 child_range children() {
2324 return child_range(child_iterator(), child_iterator());
2327 friend TrailingObjects;
2328 friend class ASTStmtReader;
2329 friend class ASTStmtWriter;
2332 /// \brief An Embarcadero array type trait, as used in the implementation of
2333 /// __array_rank and __array_extent.
2337 /// __array_rank(int[10][20]) == 2
2338 /// __array_extent(int, 1) == 20
2340 class ArrayTypeTraitExpr : public Expr {
2341 virtual void anchor();
2343 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2346 /// \brief The value of the type trait. Unspecified if dependent.
2349 /// \brief The array dimension being queried, or -1 if not used.
2352 /// \brief The location of the type trait keyword.
2355 /// \brief The location of the closing paren.
2356 SourceLocation RParen;
2358 /// \brief The type being queried.
2359 TypeSourceInfo *QueriedType;
2362 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2363 TypeSourceInfo *queried, uint64_t value,
2364 Expr *dimension, SourceLocation rparen, QualType ty)
2365 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2366 false, queried->getType()->isDependentType(),
2367 (queried->getType()->isInstantiationDependentType() ||
2368 (dimension && dimension->isInstantiationDependent())),
2369 queried->getType()->containsUnexpandedParameterPack()),
2370 ATT(att), Value(value), Dimension(dimension),
2371 Loc(loc), RParen(rparen), QueriedType(queried) { }
2374 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2375 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2378 virtual ~ArrayTypeTraitExpr() { }
2380 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2381 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2383 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2385 QualType getQueriedType() const { return QueriedType->getType(); }
2387 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2389 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2391 Expr *getDimensionExpression() const { return Dimension; }
2393 static bool classof(const Stmt *T) {
2394 return T->getStmtClass() == ArrayTypeTraitExprClass;
2398 child_range children() {
2399 return child_range(child_iterator(), child_iterator());
2402 friend class ASTStmtReader;
2405 /// \brief An expression trait intrinsic.
2409 /// __is_lvalue_expr(std::cout) == true
2410 /// __is_lvalue_expr(1) == false
2412 class ExpressionTraitExpr : public Expr {
2413 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2415 /// \brief The value of the type trait. Unspecified if dependent.
2418 /// \brief The location of the type trait keyword.
2421 /// \brief The location of the closing paren.
2422 SourceLocation RParen;
2424 /// \brief The expression being queried.
2425 Expr* QueriedExpression;
2427 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2428 Expr *queried, bool value,
2429 SourceLocation rparen, QualType resultType)
2430 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2431 false, // Not type-dependent
2432 // Value-dependent if the argument is type-dependent.
2433 queried->isTypeDependent(),
2434 queried->isInstantiationDependent(),
2435 queried->containsUnexpandedParameterPack()),
2436 ET(et), Value(value), Loc(loc), RParen(rparen),
2437 QueriedExpression(queried) { }
2439 explicit ExpressionTraitExpr(EmptyShell Empty)
2440 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2441 QueriedExpression() { }
2443 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2444 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2446 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2448 Expr *getQueriedExpression() const { return QueriedExpression; }
2450 bool getValue() const { return Value; }
2452 static bool classof(const Stmt *T) {
2453 return T->getStmtClass() == ExpressionTraitExprClass;
2457 child_range children() {
2458 return child_range(child_iterator(), child_iterator());
2461 friend class ASTStmtReader;
2465 /// \brief A reference to an overloaded function set, either an
2466 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2467 class OverloadExpr : public Expr {
2468 /// \brief The common name of these declarations.
2469 DeclarationNameInfo NameInfo;
2471 /// \brief The nested-name-specifier that qualifies the name, if any.
2472 NestedNameSpecifierLoc QualifierLoc;
2474 /// The results. These are undesugared, which is to say, they may
2475 /// include UsingShadowDecls. Access is relative to the naming
2477 // FIXME: Allocate this data after the OverloadExpr subclass.
2478 DeclAccessPair *Results;
2479 unsigned NumResults;
2482 /// \brief Whether the name includes info for explicit template
2483 /// keyword and arguments.
2484 bool HasTemplateKWAndArgsInfo;
2486 /// \brief Return the optional template keyword and arguments info.
2487 ASTTemplateKWAndArgsInfo *
2488 getTrailingASTTemplateKWAndArgsInfo(); // defined far below.
2490 /// \brief Return the optional template keyword and arguments info.
2491 const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
2492 return const_cast<OverloadExpr *>(this)
2493 ->getTrailingASTTemplateKWAndArgsInfo();
2496 /// Return the optional template arguments.
2497 TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); // defined far below
2499 OverloadExpr(StmtClass K, const ASTContext &C,
2500 NestedNameSpecifierLoc QualifierLoc,
2501 SourceLocation TemplateKWLoc,
2502 const DeclarationNameInfo &NameInfo,
2503 const TemplateArgumentListInfo *TemplateArgs,
2504 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2505 bool KnownDependent,
2506 bool KnownInstantiationDependent,
2507 bool KnownContainsUnexpandedParameterPack);
2509 OverloadExpr(StmtClass K, EmptyShell Empty)
2510 : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
2511 HasTemplateKWAndArgsInfo(false) { }
2513 void initializeResults(const ASTContext &C,
2514 UnresolvedSetIterator Begin,
2515 UnresolvedSetIterator End);
2519 OverloadExpr *Expression;
2520 bool IsAddressOfOperand;
2521 bool HasFormOfMemberPointer;
2524 /// \brief Finds the overloaded expression in the given expression \p E of
2527 /// \return the expression (which must be there) and true if it has
2528 /// the particular form of a member pointer expression
2529 static FindResult find(Expr *E) {
2530 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2534 E = E->IgnoreParens();
2535 if (isa<UnaryOperator>(E)) {
2536 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2537 E = cast<UnaryOperator>(E)->getSubExpr();
2538 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2540 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2541 Result.IsAddressOfOperand = true;
2542 Result.Expression = Ovl;
2544 Result.HasFormOfMemberPointer = false;
2545 Result.IsAddressOfOperand = false;
2546 Result.Expression = cast<OverloadExpr>(E);
2552 /// \brief Gets the naming class of this lookup, if any.
2553 CXXRecordDecl *getNamingClass() const;
2555 typedef UnresolvedSetImpl::iterator decls_iterator;
2556 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2557 decls_iterator decls_end() const {
2558 return UnresolvedSetIterator(Results + NumResults);
2560 llvm::iterator_range<decls_iterator> decls() const {
2561 return llvm::make_range(decls_begin(), decls_end());
2564 /// \brief Gets the number of declarations in the unresolved set.
2565 unsigned getNumDecls() const { return NumResults; }
2567 /// \brief Gets the full name info.
2568 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2570 /// \brief Gets the name looked up.
2571 DeclarationName getName() const { return NameInfo.getName(); }
2573 /// \brief Gets the location of the name.
2574 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2576 /// \brief Fetches the nested-name qualifier, if one was given.
2577 NestedNameSpecifier *getQualifier() const {
2578 return QualifierLoc.getNestedNameSpecifier();
2581 /// \brief Fetches the nested-name qualifier with source-location
2582 /// information, if one was given.
2583 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2585 /// \brief Retrieve the location of the template keyword preceding
2586 /// this name, if any.
2587 SourceLocation getTemplateKeywordLoc() const {
2588 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2589 return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc;
2592 /// \brief Retrieve the location of the left angle bracket starting the
2593 /// explicit template argument list following the name, if any.
2594 SourceLocation getLAngleLoc() const {
2595 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2596 return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc;
2599 /// \brief Retrieve the location of the right angle bracket ending the
2600 /// explicit template argument list following the name, if any.
2601 SourceLocation getRAngleLoc() const {
2602 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2603 return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc;
2606 /// \brief Determines whether the name was preceded by the template keyword.
2607 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2609 /// \brief Determines whether this expression had explicit template arguments.
2610 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2612 TemplateArgumentLoc const *getTemplateArgs() const {
2613 if (!hasExplicitTemplateArgs())
2615 return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc();
2618 unsigned getNumTemplateArgs() const {
2619 if (!hasExplicitTemplateArgs())
2622 return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
2625 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2626 return {getTemplateArgs(), getNumTemplateArgs()};
2629 /// \brief Copies the template arguments into the given structure.
2630 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2631 if (hasExplicitTemplateArgs())
2632 getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List);
2635 static bool classof(const Stmt *T) {
2636 return T->getStmtClass() == UnresolvedLookupExprClass ||
2637 T->getStmtClass() == UnresolvedMemberExprClass;
2640 friend class ASTStmtReader;
2641 friend class ASTStmtWriter;
2644 /// \brief A reference to a name which we were able to look up during
2645 /// parsing but could not resolve to a specific declaration.
2647 /// This arises in several ways:
2648 /// * we might be waiting for argument-dependent lookup;
2649 /// * the name might resolve to an overloaded function;
2651 /// * the lookup might have included a function template.
2653 /// These never include UnresolvedUsingValueDecls, which are always class
2654 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2655 class UnresolvedLookupExpr final
2656 : public OverloadExpr,
2657 private llvm::TrailingObjects<
2658 UnresolvedLookupExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
2659 /// True if these lookup results should be extended by
2660 /// argument-dependent lookup if this is the operand of a function
2664 /// True if these lookup results are overloaded. This is pretty
2665 /// trivially rederivable if we urgently need to kill this field.
2668 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2669 /// any. This can generally be recalculated from the context chain,
2670 /// but that can be fairly expensive for unqualified lookups. If we
2671 /// want to improve memory use here, this could go in a union
2672 /// against the qualified-lookup bits.
2673 CXXRecordDecl *NamingClass;
2675 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2676 return HasTemplateKWAndArgsInfo ? 1 : 0;
2679 UnresolvedLookupExpr(const ASTContext &C,
2680 CXXRecordDecl *NamingClass,
2681 NestedNameSpecifierLoc QualifierLoc,
2682 SourceLocation TemplateKWLoc,
2683 const DeclarationNameInfo &NameInfo,
2684 bool RequiresADL, bool Overloaded,
2685 const TemplateArgumentListInfo *TemplateArgs,
2686 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2687 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2688 NameInfo, TemplateArgs, Begin, End, false, false, false),
2689 RequiresADL(RequiresADL),
2690 Overloaded(Overloaded), NamingClass(NamingClass)
2693 UnresolvedLookupExpr(EmptyShell Empty)
2694 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2695 RequiresADL(false), Overloaded(false), NamingClass(nullptr)
2698 friend TrailingObjects;
2699 friend class OverloadExpr;
2700 friend class ASTStmtReader;
2703 static UnresolvedLookupExpr *Create(const ASTContext &C,
2704 CXXRecordDecl *NamingClass,
2705 NestedNameSpecifierLoc QualifierLoc,
2706 const DeclarationNameInfo &NameInfo,
2707 bool ADL, bool Overloaded,
2708 UnresolvedSetIterator Begin,
2709 UnresolvedSetIterator End) {
2710 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2711 SourceLocation(), NameInfo,
2712 ADL, Overloaded, nullptr, Begin, End);
2715 static UnresolvedLookupExpr *Create(const ASTContext &C,
2716 CXXRecordDecl *NamingClass,
2717 NestedNameSpecifierLoc QualifierLoc,
2718 SourceLocation TemplateKWLoc,
2719 const DeclarationNameInfo &NameInfo,
2721 const TemplateArgumentListInfo *Args,
2722 UnresolvedSetIterator Begin,
2723 UnresolvedSetIterator End);
2725 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2726 bool HasTemplateKWAndArgsInfo,
2727 unsigned NumTemplateArgs);
2729 /// True if this declaration should be extended by
2730 /// argument-dependent lookup.
2731 bool requiresADL() const { return RequiresADL; }
2733 /// True if this lookup is overloaded.
2734 bool isOverloaded() const { return Overloaded; }
2736 /// Gets the 'naming class' (in the sense of C++0x
2737 /// [class.access.base]p5) of the lookup. This is the scope
2738 /// that was looked in to find these results.
2739 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2741 SourceLocation getLocStart() const LLVM_READONLY {
2742 if (NestedNameSpecifierLoc l = getQualifierLoc())
2743 return l.getBeginLoc();
2744 return getNameInfo().getLocStart();
2746 SourceLocation getLocEnd() const LLVM_READONLY {
2747 if (hasExplicitTemplateArgs())
2748 return getRAngleLoc();
2749 return getNameInfo().getLocEnd();
2752 child_range children() {
2753 return child_range(child_iterator(), child_iterator());
2756 static bool classof(const Stmt *T) {
2757 return T->getStmtClass() == UnresolvedLookupExprClass;
2761 /// \brief A qualified reference to a name whose declaration cannot
2762 /// yet be resolved.
2764 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2765 /// it expresses a reference to a declaration such as
2766 /// X<T>::value. The difference, however, is that an
2767 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2768 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2769 /// this case, X<T>::value cannot resolve to a declaration because the
2770 /// declaration will differ from one instantiation of X<T> to the
2771 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2772 /// qualifier (X<T>::) and the name of the entity being referenced
2773 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2774 /// declaration can be found.
2775 class DependentScopeDeclRefExpr final
2777 private llvm::TrailingObjects<DependentScopeDeclRefExpr,
2778 ASTTemplateKWAndArgsInfo,
2779 TemplateArgumentLoc> {
2780 /// \brief The nested-name-specifier that qualifies this unresolved
2781 /// declaration name.
2782 NestedNameSpecifierLoc QualifierLoc;
2784 /// \brief The name of the entity we will be referencing.
2785 DeclarationNameInfo NameInfo;
2787 /// \brief Whether the name includes info for explicit template
2788 /// keyword and arguments.
2789 bool HasTemplateKWAndArgsInfo;
2791 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2792 return HasTemplateKWAndArgsInfo ? 1 : 0;
2795 DependentScopeDeclRefExpr(QualType T,
2796 NestedNameSpecifierLoc QualifierLoc,
2797 SourceLocation TemplateKWLoc,
2798 const DeclarationNameInfo &NameInfo,
2799 const TemplateArgumentListInfo *Args);
2802 static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2803 NestedNameSpecifierLoc QualifierLoc,
2804 SourceLocation TemplateKWLoc,
2805 const DeclarationNameInfo &NameInfo,
2806 const TemplateArgumentListInfo *TemplateArgs);
2808 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2809 bool HasTemplateKWAndArgsInfo,
2810 unsigned NumTemplateArgs);
2812 /// \brief Retrieve the name that this expression refers to.
2813 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2815 /// \brief Retrieve the name that this expression refers to.
2816 DeclarationName getDeclName() const { return NameInfo.getName(); }
2818 /// \brief Retrieve the location of the name within the expression.
2820 /// For example, in "X<T>::value" this is the location of "value".
2821 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2823 /// \brief Retrieve the nested-name-specifier that qualifies the
2824 /// name, with source location information.
2825 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2827 /// \brief Retrieve the nested-name-specifier that qualifies this
2829 NestedNameSpecifier *getQualifier() const {
2830 return QualifierLoc.getNestedNameSpecifier();
2833 /// \brief Retrieve the location of the template keyword preceding
2834 /// this name, if any.
2835 SourceLocation getTemplateKeywordLoc() const {
2836 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2837 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2840 /// \brief Retrieve the location of the left angle bracket starting the
2841 /// explicit template argument list following the name, if any.
2842 SourceLocation getLAngleLoc() const {
2843 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2844 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2847 /// \brief Retrieve the location of the right angle bracket ending the
2848 /// explicit template argument list following the name, if any.
2849 SourceLocation getRAngleLoc() const {
2850 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2851 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2854 /// Determines whether the name was preceded by the template keyword.
2855 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2857 /// Determines whether this lookup had explicit template arguments.
2858 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2860 /// \brief Copies the template arguments (if present) into the given
2862 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2863 if (hasExplicitTemplateArgs())
2864 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2865 getTrailingObjects<TemplateArgumentLoc>(), List);
2868 TemplateArgumentLoc const *getTemplateArgs() const {
2869 if (!hasExplicitTemplateArgs())
2872 return getTrailingObjects<TemplateArgumentLoc>();
2875 unsigned getNumTemplateArgs() const {
2876 if (!hasExplicitTemplateArgs())
2879 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2882 ArrayRef<TemplateArgumentLoc> template_arguments() const {
2883 return {getTemplateArgs(), getNumTemplateArgs()};
2886 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2887 /// and differs from getLocation().getStart().
2888 SourceLocation getLocStart() const LLVM_READONLY {
2889 return QualifierLoc.getBeginLoc();
2891 SourceLocation getLocEnd() const LLVM_READONLY {
2892 if (hasExplicitTemplateArgs())
2893 return getRAngleLoc();
2894 return getLocation();
2897 static bool classof(const Stmt *T) {
2898 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2901 child_range children() {
2902 return child_range(child_iterator(), child_iterator());
2905 friend TrailingObjects;
2906 friend class ASTStmtReader;
2907 friend class ASTStmtWriter;
2910 /// Represents an expression -- generally a full-expression -- that
2911 /// introduces cleanups to be run at the end of the sub-expression's
2912 /// evaluation. The most common source of expression-introduced
2913 /// cleanups is temporary objects in C++, but several other kinds of
2914 /// expressions can create cleanups, including basically every
2915 /// call in ARC that returns an Objective-C pointer.
2917 /// This expression also tracks whether the sub-expression contains a
2918 /// potentially-evaluated block literal. The lifetime of a block
2919 /// literal is the extent of the enclosing scope.
2920 class ExprWithCleanups final
2922 private llvm::TrailingObjects<ExprWithCleanups, BlockDecl *> {
2924 /// The type of objects that are kept in the cleanup.
2925 /// It's useful to remember the set of blocks; we could also
2926 /// remember the set of temporaries, but there's currently
2928 typedef BlockDecl *CleanupObject;
2933 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2934 ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects,
2935 ArrayRef<CleanupObject> Objects);
2937 friend TrailingObjects;
2938 friend class ASTStmtReader;
2941 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
2942 unsigned numObjects);
2944 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
2945 bool CleanupsHaveSideEffects,
2946 ArrayRef<CleanupObject> objects);
2948 ArrayRef<CleanupObject> getObjects() const {
2949 return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(),
2953 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2955 CleanupObject getObject(unsigned i) const {
2956 assert(i < getNumObjects() && "Index out of range");
2957 return getObjects()[i];
2960 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2961 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2962 bool cleanupsHaveSideEffects() const {
2963 return ExprWithCleanupsBits.CleanupsHaveSideEffects;
2966 /// As with any mutator of the AST, be very careful
2967 /// when modifying an existing AST to preserve its invariants.
2968 void setSubExpr(Expr *E) { SubExpr = E; }
2970 SourceLocation getLocStart() const LLVM_READONLY {
2971 return SubExpr->getLocStart();
2973 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2975 // Implement isa/cast/dyncast/etc.
2976 static bool classof(const Stmt *T) {
2977 return T->getStmtClass() == ExprWithCleanupsClass;
2981 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2984 /// \brief Describes an explicit type conversion that uses functional
2985 /// notion but could not be resolved because one or more arguments are
2988 /// The explicit type conversions expressed by
2989 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2990 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2991 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2992 /// type-dependent. For example, this would occur in a template such
2996 /// template<typename T, typename A1>
2997 /// inline T make_a(const A1& a1) {
3002 /// When the returned expression is instantiated, it may resolve to a
3003 /// constructor call, conversion function call, or some kind of type
3005 class CXXUnresolvedConstructExpr final
3007 private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> {
3008 /// \brief The type being constructed.
3009 TypeSourceInfo *Type;
3011 /// \brief The location of the left parentheses ('(').
3012 SourceLocation LParenLoc;
3014 /// \brief The location of the right parentheses (')').
3015 SourceLocation RParenLoc;
3017 /// \brief The number of arguments used to construct the type.
3020 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
3021 SourceLocation LParenLoc,
3022 ArrayRef<Expr*> Args,
3023 SourceLocation RParenLoc);
3025 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3026 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
3028 friend TrailingObjects;
3029 friend class ASTStmtReader;
3032 static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
3033 TypeSourceInfo *Type,
3034 SourceLocation LParenLoc,
3035 ArrayRef<Expr*> Args,
3036 SourceLocation RParenLoc);
3038 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
3041 /// \brief Retrieve the type that is being constructed, as specified
3042 /// in the source code.
3043 QualType getTypeAsWritten() const { return Type->getType(); }
3045 /// \brief Retrieve the type source information for the type being
3047 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
3049 /// \brief Retrieve the location of the left parentheses ('(') that
3050 /// precedes the argument list.
3051 SourceLocation getLParenLoc() const { return LParenLoc; }
3052 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3054 /// \brief Retrieve the location of the right parentheses (')') that
3055 /// follows the argument list.
3056 SourceLocation getRParenLoc() const { return RParenLoc; }
3057 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3059 /// \brief Retrieve the number of arguments.
3060 unsigned arg_size() const { return NumArgs; }
3062 typedef Expr** arg_iterator;
3063 arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); }
3064 arg_iterator arg_end() { return arg_begin() + NumArgs; }
3066 typedef const Expr* const * const_arg_iterator;
3067 const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); }
3068 const_arg_iterator arg_end() const {
3069 return arg_begin() + NumArgs;
3072 Expr *getArg(unsigned I) {
3073 assert(I < NumArgs && "Argument index out-of-range");
3074 return *(arg_begin() + I);
3077 const Expr *getArg(unsigned I) const {
3078 assert(I < NumArgs && "Argument index out-of-range");
3079 return *(arg_begin() + I);
3082 void setArg(unsigned I, Expr *E) {
3083 assert(I < NumArgs && "Argument index out-of-range");
3084 *(arg_begin() + I) = E;
3087 SourceLocation getLocStart() const LLVM_READONLY;
3088 SourceLocation getLocEnd() const LLVM_READONLY {
3089 if (!RParenLoc.isValid() && NumArgs > 0)
3090 return getArg(NumArgs - 1)->getLocEnd();
3094 static bool classof(const Stmt *T) {
3095 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3099 child_range children() {
3100 Stmt **begin = reinterpret_cast<Stmt **>(arg_begin());
3101 return child_range(begin, begin + NumArgs);
3105 /// \brief Represents a C++ member access expression where the actual
3106 /// member referenced could not be resolved because the base
3107 /// expression or the member name was dependent.
3109 /// Like UnresolvedMemberExprs, these can be either implicit or
3110 /// explicit accesses. It is only possible to get one of these with
3111 /// an implicit access if a qualifier is provided.
3112 class CXXDependentScopeMemberExpr final
3114 private llvm::TrailingObjects<CXXDependentScopeMemberExpr,
3115 ASTTemplateKWAndArgsInfo,
3116 TemplateArgumentLoc> {
3117 /// \brief The expression for the base pointer or class reference,
3118 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3121 /// \brief The type of the base expression. Never null, even for
3122 /// implicit accesses.
3125 /// \brief Whether this member expression used the '->' operator or
3126 /// the '.' operator.
3129 /// \brief Whether this member expression has info for explicit template
3130 /// keyword and arguments.
3131 bool HasTemplateKWAndArgsInfo : 1;
3133 /// \brief The location of the '->' or '.' operator.
3134 SourceLocation OperatorLoc;
3136 /// \brief The nested-name-specifier that precedes the member name, if any.
3137 NestedNameSpecifierLoc QualifierLoc;
3139 /// \brief In a qualified member access expression such as t->Base::f, this
3140 /// member stores the resolves of name lookup in the context of the member
3141 /// access expression, to be used at instantiation time.
3143 /// FIXME: This member, along with the QualifierLoc, could
3144 /// be stuck into a structure that is optionally allocated at the end of
3145 /// the CXXDependentScopeMemberExpr, to save space in the common case.
3146 NamedDecl *FirstQualifierFoundInScope;
3148 /// \brief The member to which this member expression refers, which
3149 /// can be name, overloaded operator, or destructor.
3151 /// FIXME: could also be a template-id
3152 DeclarationNameInfo MemberNameInfo;
3154 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3155 return HasTemplateKWAndArgsInfo ? 1 : 0;
3158 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3159 QualType BaseType, bool IsArrow,
3160 SourceLocation OperatorLoc,
3161 NestedNameSpecifierLoc QualifierLoc,
3162 SourceLocation TemplateKWLoc,
3163 NamedDecl *FirstQualifierFoundInScope,
3164 DeclarationNameInfo MemberNameInfo,
3165 const TemplateArgumentListInfo *TemplateArgs);
3168 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3169 QualType BaseType, bool IsArrow,
3170 SourceLocation OperatorLoc,
3171 NestedNameSpecifierLoc QualifierLoc,
3172 NamedDecl *FirstQualifierFoundInScope,
3173 DeclarationNameInfo MemberNameInfo);
3175 static CXXDependentScopeMemberExpr *
3176 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3177 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3178 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3179 DeclarationNameInfo MemberNameInfo,
3180 const TemplateArgumentListInfo *TemplateArgs);
3182 static CXXDependentScopeMemberExpr *
3183 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3184 unsigned NumTemplateArgs);
3186 /// \brief True if this is an implicit access, i.e. one in which the
3187 /// member being accessed was not written in the source. The source
3188 /// location of the operator is invalid in this case.
3189 bool isImplicitAccess() const;
3191 /// \brief Retrieve the base object of this member expressions,
3192 /// e.g., the \c x in \c x.m.
3193 Expr *getBase() const {
3194 assert(!isImplicitAccess());
3195 return cast<Expr>(Base);
3198 QualType getBaseType() const { return BaseType; }
3200 /// \brief Determine whether this member expression used the '->'
3201 /// operator; otherwise, it used the '.' operator.
3202 bool isArrow() const { return IsArrow; }
3204 /// \brief Retrieve the location of the '->' or '.' operator.
3205 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3207 /// \brief Retrieve the nested-name-specifier that qualifies the member
3209 NestedNameSpecifier *getQualifier() const {
3210 return QualifierLoc.getNestedNameSpecifier();
3213 /// \brief Retrieve the nested-name-specifier that qualifies the member
3214 /// name, with source location information.
3215 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3218 /// \brief Retrieve the first part of the nested-name-specifier that was
3219 /// found in the scope of the member access expression when the member access
3220 /// was initially parsed.
3222 /// This function only returns a useful result when member access expression
3223 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3224 /// returned by this function describes what was found by unqualified name
3225 /// lookup for the identifier "Base" within the scope of the member access
3226 /// expression itself. At template instantiation time, this information is
3227 /// combined with the results of name lookup into the type of the object
3228 /// expression itself (the class type of x).
3229 NamedDecl *getFirstQualifierFoundInScope() const {
3230 return FirstQualifierFoundInScope;
3233 /// \brief Retrieve the name of the member that this expression
3235 const DeclarationNameInfo &getMemberNameInfo() const {
3236 return MemberNameInfo;
3239 /// \brief Retrieve the name of the member that this expression
3241 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3243 // \brief Retrieve the location of the name of the member that this
3244 // expression refers to.
3245 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3247 /// \brief Retrieve the location of the template keyword preceding the
3248 /// member name, if any.
3249 SourceLocation getTemplateKeywordLoc() const {
3250 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3251 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3254 /// \brief Retrieve the location of the left angle bracket starting the
3255 /// explicit template argument list following the member name, if any.
3256 SourceLocation getLAngleLoc() const {
3257 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3258 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3261 /// \brief Retrieve the location of the right angle bracket ending the
3262 /// explicit template argument list following the member name, if any.
3263 SourceLocation getRAngleLoc() const {
3264 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3265 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3268 /// Determines whether the member name was preceded by the template keyword.
3269 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3271 /// \brief Determines whether this member expression actually had a C++
3272 /// template argument list explicitly specified, e.g., x.f<int>.
3273 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3275 /// \brief Copies the template arguments (if present) into the given
3277 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3278 if (hasExplicitTemplateArgs())
3279 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3280 getTrailingObjects<TemplateArgumentLoc>(), List);
3283 /// \brief Retrieve the template arguments provided as part of this
3285 const TemplateArgumentLoc *getTemplateArgs() const {
3286 if (!hasExplicitTemplateArgs())
3289 return getTrailingObjects<TemplateArgumentLoc>();
3292 /// \brief Retrieve the number of template arguments provided as part of this
3294 unsigned getNumTemplateArgs() const {
3295 if (!hasExplicitTemplateArgs())
3298 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3301 ArrayRef<TemplateArgumentLoc> template_arguments() const {
3302 return {getTemplateArgs(), getNumTemplateArgs()};
3305 SourceLocation getLocStart() const LLVM_READONLY {
3306 if (!isImplicitAccess())
3307 return Base->getLocStart();
3309 return getQualifierLoc().getBeginLoc();
3310 return MemberNameInfo.getBeginLoc();
3313 SourceLocation getLocEnd() const LLVM_READONLY {
3314 if (hasExplicitTemplateArgs())
3315 return getRAngleLoc();
3316 return MemberNameInfo.getEndLoc();
3319 static bool classof(const Stmt *T) {
3320 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3324 child_range children() {
3325 if (isImplicitAccess())
3326 return child_range(child_iterator(), child_iterator());
3327 return child_range(&Base, &Base + 1);
3330 friend TrailingObjects;
3331 friend class ASTStmtReader;
3332 friend class ASTStmtWriter;
3335 /// \brief Represents a C++ member access expression for which lookup
3336 /// produced a set of overloaded functions.
3338 /// The member access may be explicit or implicit:
3342 /// int explicitAccess() { return this->a + this->A::b; }
3343 /// int implicitAccess() { return a + A::b; }
3347 /// In the final AST, an explicit access always becomes a MemberExpr.
3348 /// An implicit access may become either a MemberExpr or a
3349 /// DeclRefExpr, depending on whether the member is static.
3350 class UnresolvedMemberExpr final
3351 : public OverloadExpr,
3352 private llvm::TrailingObjects<
3353 UnresolvedMemberExpr, ASTTemplateKWAndArgsInfo, TemplateArgumentLoc> {
3354 /// \brief Whether this member expression used the '->' operator or
3355 /// the '.' operator.
3358 /// \brief Whether the lookup results contain an unresolved using
3360 bool HasUnresolvedUsing : 1;
3362 /// \brief The expression for the base pointer or class reference,
3363 /// e.g., the \c x in x.f.
3365 /// This can be null if this is an 'unbased' member expression.
3368 /// \brief The type of the base expression; never null.
3371 /// \brief The location of the '->' or '.' operator.
3372 SourceLocation OperatorLoc;
3374 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3375 return HasTemplateKWAndArgsInfo ? 1 : 0;
3378 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3379 Expr *Base, QualType BaseType, bool IsArrow,
3380 SourceLocation OperatorLoc,
3381 NestedNameSpecifierLoc QualifierLoc,
3382 SourceLocation TemplateKWLoc,
3383 const DeclarationNameInfo &MemberNameInfo,
3384 const TemplateArgumentListInfo *TemplateArgs,
3385 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3387 UnresolvedMemberExpr(EmptyShell Empty)
3388 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3389 HasUnresolvedUsing(false), Base(nullptr) { }
3391 friend TrailingObjects;
3392 friend class OverloadExpr;
3393 friend class ASTStmtReader;
3396 static UnresolvedMemberExpr *
3397 Create(const ASTContext &C, bool HasUnresolvedUsing,
3398 Expr *Base, QualType BaseType, bool IsArrow,
3399 SourceLocation OperatorLoc,
3400 NestedNameSpecifierLoc QualifierLoc,
3401 SourceLocation TemplateKWLoc,
3402 const DeclarationNameInfo &MemberNameInfo,
3403 const TemplateArgumentListInfo *TemplateArgs,
3404 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3406 static UnresolvedMemberExpr *
3407 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3408 unsigned NumTemplateArgs);
3410 /// \brief True if this is an implicit access, i.e., one in which the
3411 /// member being accessed was not written in the source.
3413 /// The source location of the operator is invalid in this case.
3414 bool isImplicitAccess() const;
3416 /// \brief Retrieve the base object of this member expressions,
3417 /// e.g., the \c x in \c x.m.
3419 assert(!isImplicitAccess());
3420 return cast<Expr>(Base);
3422 const Expr *getBase() const {
3423 assert(!isImplicitAccess());
3424 return cast<Expr>(Base);
3427 QualType getBaseType() const { return BaseType; }
3429 /// \brief Determine whether the lookup results contain an unresolved using
3431 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3433 /// \brief Determine whether this member expression used the '->'
3434 /// operator; otherwise, it used the '.' operator.
3435 bool isArrow() const { return IsArrow; }
3437 /// \brief Retrieve the location of the '->' or '.' operator.
3438 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3440 /// \brief Retrieve the naming class of this lookup.
3441 CXXRecordDecl *getNamingClass() const;
3443 /// \brief Retrieve the full name info for the member that this expression
3445 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3447 /// \brief Retrieve the name of the member that this expression
3449 DeclarationName getMemberName() const { return getName(); }
3451 // \brief Retrieve the location of the name of the member that this
3452 // expression refers to.
3453 SourceLocation getMemberLoc() const { return getNameLoc(); }
3455 // \brief Return the preferred location (the member name) for the arrow when
3456 // diagnosing a problem with this expression.
3457 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3459 SourceLocation getLocStart() const LLVM_READONLY {
3460 if (!isImplicitAccess())
3461 return Base->getLocStart();
3462 if (NestedNameSpecifierLoc l = getQualifierLoc())
3463 return l.getBeginLoc();
3464 return getMemberNameInfo().getLocStart();
3466 SourceLocation getLocEnd() const LLVM_READONLY {
3467 if (hasExplicitTemplateArgs())
3468 return getRAngleLoc();
3469 return getMemberNameInfo().getLocEnd();
3472 static bool classof(const Stmt *T) {
3473 return T->getStmtClass() == UnresolvedMemberExprClass;
3477 child_range children() {
3478 if (isImplicitAccess())
3479 return child_range(child_iterator(), child_iterator());
3480 return child_range(&Base, &Base + 1);
3484 inline ASTTemplateKWAndArgsInfo *
3485 OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() {
3486 if (!HasTemplateKWAndArgsInfo)
3489 if (isa<UnresolvedLookupExpr>(this))
3490 return cast<UnresolvedLookupExpr>(this)
3491 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3493 return cast<UnresolvedMemberExpr>(this)
3494 ->getTrailingObjects<ASTTemplateKWAndArgsInfo>();
3497 inline TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() {
3498 if (isa<UnresolvedLookupExpr>(this))
3499 return cast<UnresolvedLookupExpr>(this)
3500 ->getTrailingObjects<TemplateArgumentLoc>();
3502 return cast<UnresolvedMemberExpr>(this)
3503 ->getTrailingObjects<TemplateArgumentLoc>();
3506 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3508 /// The noexcept expression tests whether a given expression might throw. Its
3509 /// result is a boolean constant.
3510 class CXXNoexceptExpr : public Expr {
3515 friend class ASTStmtReader;
3518 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3519 SourceLocation Keyword, SourceLocation RParen)
3520 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3521 /*TypeDependent*/false,
3522 /*ValueDependent*/Val == CT_Dependent,
3523 Val == CT_Dependent || Operand->isInstantiationDependent(),
3524 Operand->containsUnexpandedParameterPack()),
3525 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3528 CXXNoexceptExpr(EmptyShell Empty)
3529 : Expr(CXXNoexceptExprClass, Empty)
3532 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3534 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
3535 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3536 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3538 bool getValue() const { return Value; }
3540 static bool classof(const Stmt *T) {
3541 return T->getStmtClass() == CXXNoexceptExprClass;
3545 child_range children() { return child_range(&Operand, &Operand + 1); }
3548 /// \brief Represents a C++11 pack expansion that produces a sequence of
3551 /// A pack expansion expression contains a pattern (which itself is an
3552 /// expression) followed by an ellipsis. For example:
3555 /// template<typename F, typename ...Types>
3556 /// void forward(F f, Types &&...args) {
3557 /// f(static_cast<Types&&>(args)...);
3561 /// Here, the argument to the function object \c f is a pack expansion whose
3562 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3563 /// template is instantiated, the pack expansion will instantiate to zero or
3564 /// or more function arguments to the function object \c f.
3565 class PackExpansionExpr : public Expr {
3566 SourceLocation EllipsisLoc;
3568 /// \brief The number of expansions that will be produced by this pack
3569 /// expansion expression, if known.
3571 /// When zero, the number of expansions is not known. Otherwise, this value
3572 /// is the number of expansions + 1.
3573 unsigned NumExpansions;
3577 friend class ASTStmtReader;
3578 friend class ASTStmtWriter;
3581 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3582 Optional<unsigned> NumExpansions)
3583 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3584 Pattern->getObjectKind(), /*TypeDependent=*/true,
3585 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3586 /*ContainsUnexpandedParameterPack=*/false),
3587 EllipsisLoc(EllipsisLoc),
3588 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3589 Pattern(Pattern) { }
3591 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3593 /// \brief Retrieve the pattern of the pack expansion.
3594 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3596 /// \brief Retrieve the pattern of the pack expansion.
3597 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3599 /// \brief Retrieve the location of the ellipsis that describes this pack
3601 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3603 /// \brief Determine the number of expansions that will be produced when
3604 /// this pack expansion is instantiated, if already known.
3605 Optional<unsigned> getNumExpansions() const {
3607 return NumExpansions - 1;
3612 SourceLocation getLocStart() const LLVM_READONLY {
3613 return Pattern->getLocStart();
3615 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3617 static bool classof(const Stmt *T) {
3618 return T->getStmtClass() == PackExpansionExprClass;
3622 child_range children() {
3623 return child_range(&Pattern, &Pattern + 1);
3628 /// \brief Represents an expression that computes the length of a parameter
3632 /// template<typename ...Types>
3634 /// static const unsigned value = sizeof...(Types);
3637 class SizeOfPackExpr final
3639 private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> {
3640 /// \brief The location of the \c sizeof keyword.
3641 SourceLocation OperatorLoc;
3643 /// \brief The location of the name of the parameter pack.
3644 SourceLocation PackLoc;
3646 /// \brief The location of the closing parenthesis.
3647 SourceLocation RParenLoc;
3649 /// \brief The length of the parameter pack, if known.
3651 /// When this expression is not value-dependent, this is the length of
3652 /// the pack. When the expression was parsed rather than instantiated
3653 /// (and thus is value-dependent), this is zero.
3655 /// After partial substitution into a sizeof...(X) expression (for instance,
3656 /// within an alias template or during function template argument deduction),
3657 /// we store a trailing array of partially-substituted TemplateArguments,
3658 /// and this is the length of that array.
3661 /// \brief The parameter pack.
3664 friend TrailingObjects;
3665 friend class ASTStmtReader;
3666 friend class ASTStmtWriter;
3668 /// \brief Create an expression that computes the length of
3669 /// the given parameter pack.
3670 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3671 SourceLocation PackLoc, SourceLocation RParenLoc,
3672 Optional<unsigned> Length, ArrayRef<TemplateArgument> PartialArgs)
3673 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3674 /*TypeDependent=*/false, /*ValueDependent=*/!Length,
3675 /*InstantiationDependent=*/!Length,
3676 /*ContainsUnexpandedParameterPack=*/false),
3677 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3678 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
3679 assert((!Length || PartialArgs.empty()) &&
3680 "have partial args for non-dependent sizeof... expression");
3681 TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3682 std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
3685 /// \brief Create an empty expression.
3686 SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs)
3687 : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs), Pack() {}
3690 static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc,
3691 NamedDecl *Pack, SourceLocation PackLoc,
3692 SourceLocation RParenLoc,
3693 Optional<unsigned> Length = None,
3694 ArrayRef<TemplateArgument> PartialArgs = None);
3695 static SizeOfPackExpr *CreateDeserialized(ASTContext &Context,
3696 unsigned NumPartialArgs);
3698 /// \brief Determine the location of the 'sizeof' keyword.
3699 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3701 /// \brief Determine the location of the parameter pack.
3702 SourceLocation getPackLoc() const { return PackLoc; }
3704 /// \brief Determine the location of the right parenthesis.
3705 SourceLocation getRParenLoc() const { return RParenLoc; }
3707 /// \brief Retrieve the parameter pack.
3708 NamedDecl *getPack() const { return Pack; }
3710 /// \brief Retrieve the length of the parameter pack.
3712 /// This routine may only be invoked when the expression is not
3713 /// value-dependent.
3714 unsigned getPackLength() const {
3715 assert(!isValueDependent() &&
3716 "Cannot get the length of a value-dependent pack size expression");
3720 /// \brief Determine whether this represents a partially-substituted sizeof...
3721 /// expression, such as is produced for:
3723 /// template<typename ...Ts> using X = int[sizeof...(Ts)];
3724 /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>);
3725 bool isPartiallySubstituted() const {
3726 return isValueDependent() && Length;
3730 ArrayRef<TemplateArgument> getPartialArguments() const {
3731 assert(isPartiallySubstituted());
3732 const TemplateArgument *Args = getTrailingObjects<TemplateArgument>();
3733 return llvm::makeArrayRef(Args, Args + Length);
3736 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
3737 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3739 static bool classof(const Stmt *T) {
3740 return T->getStmtClass() == SizeOfPackExprClass;
3744 child_range children() {
3745 return child_range(child_iterator(), child_iterator());
3749 /// \brief Represents a reference to a non-type template parameter
3750 /// that has been substituted with a template argument.
3751 class SubstNonTypeTemplateParmExpr : public Expr {
3752 /// \brief The replaced parameter.
3753 NonTypeTemplateParmDecl *Param;
3755 /// \brief The replacement expression.
3758 /// \brief The location of the non-type template parameter reference.
3759 SourceLocation NameLoc;
3761 friend class ASTReader;
3762 friend class ASTStmtReader;
3763 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3764 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3767 SubstNonTypeTemplateParmExpr(QualType type,
3768 ExprValueKind valueKind,
3770 NonTypeTemplateParmDecl *param,
3772 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3773 replacement->isTypeDependent(), replacement->isValueDependent(),
3774 replacement->isInstantiationDependent(),
3775 replacement->containsUnexpandedParameterPack()),
3776 Param(param), Replacement(replacement), NameLoc(loc) {}
3778 SourceLocation getNameLoc() const { return NameLoc; }
3779 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3780 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3782 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3784 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3786 static bool classof(const Stmt *s) {
3787 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3791 child_range children() { return child_range(&Replacement, &Replacement+1); }
3794 /// \brief Represents a reference to a non-type template parameter pack that
3795 /// has been substituted with a non-template argument pack.
3797 /// When a pack expansion in the source code contains multiple parameter packs
3798 /// and those parameter packs correspond to different levels of template
3799 /// parameter lists, this node is used to represent a non-type template
3800 /// parameter pack from an outer level, which has already had its argument pack
3801 /// substituted but that still lives within a pack expansion that itself
3802 /// could not be instantiated. When actually performing a substitution into
3803 /// that pack expansion (e.g., when all template parameters have corresponding
3804 /// arguments), this type will be replaced with the appropriate underlying
3805 /// expression at the current pack substitution index.
3806 class SubstNonTypeTemplateParmPackExpr : public Expr {
3807 /// \brief The non-type template parameter pack itself.
3808 NonTypeTemplateParmDecl *Param;
3810 /// \brief A pointer to the set of template arguments that this
3811 /// parameter pack is instantiated with.
3812 const TemplateArgument *Arguments;
3814 /// \brief The number of template arguments in \c Arguments.
3815 unsigned NumArguments;
3817 /// \brief The location of the non-type template parameter pack reference.
3818 SourceLocation NameLoc;
3820 friend class ASTReader;
3821 friend class ASTStmtReader;
3822 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3823 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3826 SubstNonTypeTemplateParmPackExpr(QualType T,
3827 NonTypeTemplateParmDecl *Param,
3828 SourceLocation NameLoc,
3829 const TemplateArgument &ArgPack);
3831 /// \brief Retrieve the non-type template parameter pack being substituted.
3832 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3834 /// \brief Retrieve the location of the parameter pack name.
3835 SourceLocation getParameterPackLocation() const { return NameLoc; }
3837 /// \brief Retrieve the template argument pack containing the substituted
3838 /// template arguments.
3839 TemplateArgument getArgumentPack() const;
3841 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3842 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3844 static bool classof(const Stmt *T) {
3845 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3849 child_range children() {
3850 return child_range(child_iterator(), child_iterator());
3854 /// \brief Represents a reference to a function parameter pack that has been
3855 /// substituted but not yet expanded.
3857 /// When a pack expansion contains multiple parameter packs at different levels,
3858 /// this node is used to represent a function parameter pack at an outer level
3859 /// which we have already substituted to refer to expanded parameters, but where
3860 /// the containing pack expansion cannot yet be expanded.
3863 /// template<typename...Ts> struct S {
3864 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3866 /// template struct S<int, int>;
3868 class FunctionParmPackExpr final
3870 private llvm::TrailingObjects<FunctionParmPackExpr, ParmVarDecl *> {
3871 /// \brief The function parameter pack which was referenced.
3872 ParmVarDecl *ParamPack;
3874 /// \brief The location of the function parameter pack reference.
3875 SourceLocation NameLoc;
3877 /// \brief The number of expansions of this pack.
3878 unsigned NumParameters;
3880 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3881 SourceLocation NameLoc, unsigned NumParams,
3882 ParmVarDecl *const *Params);
3884 friend TrailingObjects;
3885 friend class ASTReader;
3886 friend class ASTStmtReader;
3889 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
3890 ParmVarDecl *ParamPack,
3891 SourceLocation NameLoc,
3892 ArrayRef<ParmVarDecl *> Params);
3893 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
3894 unsigned NumParams);
3896 /// \brief Get the parameter pack which this expression refers to.
3897 ParmVarDecl *getParameterPack() const { return ParamPack; }
3899 /// \brief Get the location of the parameter pack.
3900 SourceLocation getParameterPackLocation() const { return NameLoc; }
3902 /// \brief Iterators over the parameters which the parameter pack expanded
3904 typedef ParmVarDecl * const *iterator;
3905 iterator begin() const { return getTrailingObjects<ParmVarDecl *>(); }
3906 iterator end() const { return begin() + NumParameters; }
3908 /// \brief Get the number of parameters in this parameter pack.
3909 unsigned getNumExpansions() const { return NumParameters; }
3911 /// \brief Get an expansion of the parameter pack by index.
3912 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3914 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3915 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3917 static bool classof(const Stmt *T) {
3918 return T->getStmtClass() == FunctionParmPackExprClass;
3921 child_range children() {
3922 return child_range(child_iterator(), child_iterator());
3926 /// \brief Represents a prvalue temporary that is written into memory so that
3927 /// a reference can bind to it.
3929 /// Prvalue expressions are materialized when they need to have an address
3930 /// in memory for a reference to bind to. This happens when binding a
3931 /// reference to the result of a conversion, e.g.,
3934 /// const int &r = 1.0;
3937 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3938 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3939 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3940 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3941 /// to it), maintaining the invariant that references always bind to glvalues.
3943 /// Reference binding and copy-elision can both extend the lifetime of a
3944 /// temporary. When either happens, the expression will also track the
3945 /// declaration which is responsible for the lifetime extension.
3946 class MaterializeTemporaryExpr : public Expr {
3949 /// \brief The temporary-generating expression whose value will be
3953 /// \brief The declaration which lifetime-extended this reference, if any.
3954 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3955 const ValueDecl *ExtendingDecl;
3957 unsigned ManglingNumber;
3959 llvm::PointerUnion<Stmt *, ExtraState *> State;
3961 friend class ASTStmtReader;
3962 friend class ASTStmtWriter;
3964 void initializeExtraState(const ValueDecl *ExtendedBy,
3965 unsigned ManglingNumber);
3968 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3969 bool BoundToLvalueReference)
3970 : Expr(MaterializeTemporaryExprClass, T,
3971 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3972 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3973 Temporary->isInstantiationDependent(),
3974 Temporary->containsUnexpandedParameterPack()),
3977 MaterializeTemporaryExpr(EmptyShell Empty)
3978 : Expr(MaterializeTemporaryExprClass, Empty) { }
3980 Stmt *getTemporary() const {
3981 return State.is<Stmt *>() ? State.get<Stmt *>()
3982 : State.get<ExtraState *>()->Temporary;
3985 /// \brief Retrieve the temporary-generating subexpression whose value will
3986 /// be materialized into a glvalue.
3987 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
3989 /// \brief Retrieve the storage duration for the materialized temporary.
3990 StorageDuration getStorageDuration() const {
3991 const ValueDecl *ExtendingDecl = getExtendingDecl();
3993 return SD_FullExpression;
3994 // FIXME: This is not necessarily correct for a temporary materialized
3995 // within a default initializer.
3996 if (isa<FieldDecl>(ExtendingDecl))
3997 return SD_Automatic;
3998 // FIXME: This only works because storage class specifiers are not allowed
3999 // on decomposition declarations.
4000 if (isa<BindingDecl>(ExtendingDecl))
4001 return ExtendingDecl->getDeclContext()->isFunctionOrMethod()
4004 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
4007 /// \brief Get the declaration which triggered the lifetime-extension of this
4008 /// temporary, if any.
4009 const ValueDecl *getExtendingDecl() const {
4010 return State.is<Stmt *>() ? nullptr
4011 : State.get<ExtraState *>()->ExtendingDecl;
4014 void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
4016 unsigned getManglingNumber() const {
4017 return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
4020 /// \brief Determine whether this materialized temporary is bound to an
4021 /// lvalue reference; otherwise, it's bound to an rvalue reference.
4022 bool isBoundToLvalueReference() const {
4023 return getValueKind() == VK_LValue;
4026 SourceLocation getLocStart() const LLVM_READONLY {
4027 return getTemporary()->getLocStart();
4029 SourceLocation getLocEnd() const LLVM_READONLY {
4030 return getTemporary()->getLocEnd();
4033 static bool classof(const Stmt *T) {
4034 return T->getStmtClass() == MaterializeTemporaryExprClass;
4038 child_range children() {
4039 if (State.is<Stmt *>())
4040 return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
4042 auto ES = State.get<ExtraState *>();
4043 return child_range(&ES->Temporary, &ES->Temporary + 1);
4047 /// \brief Represents a folding of a pack over an operator.
4049 /// This expression is always dependent and represents a pack expansion of the
4054 /// ( expr op ... op expr )
4055 class CXXFoldExpr : public Expr {
4056 SourceLocation LParenLoc;
4057 SourceLocation EllipsisLoc;
4058 SourceLocation RParenLoc;
4060 BinaryOperatorKind Opcode;
4062 friend class ASTStmtReader;
4063 friend class ASTStmtWriter;
4065 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
4066 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
4067 SourceLocation RParenLoc)
4068 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
4069 /*Dependent*/ true, true, true,
4070 /*ContainsUnexpandedParameterPack*/ false),
4071 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
4076 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4078 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
4079 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
4081 /// Does this produce a right-associated sequence of operators?
4082 bool isRightFold() const {
4083 return getLHS() && getLHS()->containsUnexpandedParameterPack();
4085 /// Does this produce a left-associated sequence of operators?
4086 bool isLeftFold() const { return !isRightFold(); }
4087 /// Get the pattern, that is, the operand that contains an unexpanded pack.
4088 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
4089 /// Get the operand that doesn't contain a pack, for a binary fold.
4090 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
4092 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
4093 BinaryOperatorKind getOperator() const { return Opcode; }
4095 SourceLocation getLocStart() const LLVM_READONLY {
4098 SourceLocation getLocEnd() const LLVM_READONLY {
4102 static bool classof(const Stmt *T) {
4103 return T->getStmtClass() == CXXFoldExprClass;
4107 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4110 /// \brief Represents an expression that might suspend coroutine execution;
4111 /// either a co_await or co_yield expression.
4113 /// Evaluation of this expression first evaluates its 'ready' expression. If
4114 /// that returns 'false':
4115 /// -- execution of the coroutine is suspended
4116 /// -- the 'suspend' expression is evaluated
4117 /// -- if the 'suspend' expression returns 'false', the coroutine is
4119 /// -- otherwise, control passes back to the resumer.
4120 /// If the coroutine is not suspended, or when it is resumed, the 'resume'
4121 /// expression is evaluated, and its result is the result of the overall
4123 class CoroutineSuspendExpr : public Expr {
4124 SourceLocation KeywordLoc;
4126 enum SubExpr { Common, Ready, Suspend, Resume, Count };
4127 Stmt *SubExprs[SubExpr::Count];
4128 OpaqueValueExpr *OpaqueValue = nullptr;
4130 friend class ASTStmtReader;
4132 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common,
4133 Expr *Ready, Expr *Suspend, Expr *Resume,
4134 OpaqueValueExpr *OpaqueValue)
4135 : Expr(SC, Resume->getType(), Resume->getValueKind(),
4136 Resume->getObjectKind(), Resume->isTypeDependent(),
4137 Resume->isValueDependent(), Common->isInstantiationDependent(),
4138 Common->containsUnexpandedParameterPack()),
4139 KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
4140 SubExprs[SubExpr::Common] = Common;
4141 SubExprs[SubExpr::Ready] = Ready;
4142 SubExprs[SubExpr::Suspend] = Suspend;
4143 SubExprs[SubExpr::Resume] = Resume;
4145 CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty,
4147 : Expr(SC, Ty, VK_RValue, OK_Ordinary, true, true, true,
4148 Common->containsUnexpandedParameterPack()),
4149 KeywordLoc(KeywordLoc) {
4150 assert(Common->isTypeDependent() && Ty->isDependentType() &&
4151 "wrong constructor for non-dependent co_await/co_yield expression");
4152 SubExprs[SubExpr::Common] = Common;
4153 SubExprs[SubExpr::Ready] = nullptr;
4154 SubExprs[SubExpr::Suspend] = nullptr;
4155 SubExprs[SubExpr::Resume] = nullptr;
4157 CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4158 SubExprs[SubExpr::Common] = nullptr;
4159 SubExprs[SubExpr::Ready] = nullptr;
4160 SubExprs[SubExpr::Suspend] = nullptr;
4161 SubExprs[SubExpr::Resume] = nullptr;
4164 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4165 Expr *getCommonExpr() const {
4166 return static_cast<Expr*>(SubExprs[SubExpr::Common]);
4168 /// \brief getOpaqueValue - Return the opaque value placeholder.
4169 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4171 Expr *getReadyExpr() const {
4172 return static_cast<Expr*>(SubExprs[SubExpr::Ready]);
4174 Expr *getSuspendExpr() const {
4175 return static_cast<Expr*>(SubExprs[SubExpr::Suspend]);
4177 Expr *getResumeExpr() const {
4178 return static_cast<Expr*>(SubExprs[SubExpr::Resume]);
4181 SourceLocation getLocStart() const LLVM_READONLY {
4184 SourceLocation getLocEnd() const LLVM_READONLY {
4185 return getCommonExpr()->getLocEnd();
4188 child_range children() {
4189 return child_range(SubExprs, SubExprs + SubExpr::Count);
4192 static bool classof(const Stmt *T) {
4193 return T->getStmtClass() == CoawaitExprClass ||
4194 T->getStmtClass() == CoyieldExprClass;
4198 /// \brief Represents a 'co_await' expression.
4199 class CoawaitExpr : public CoroutineSuspendExpr {
4200 friend class ASTStmtReader;
4202 CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready,
4203 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue,
4204 bool IsImplicit = false)
4205 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready,
4206 Suspend, Resume, OpaqueValue) {
4207 CoawaitBits.IsImplicit = IsImplicit;
4209 CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand,
4210 bool IsImplicit = false)
4211 : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) {
4212 CoawaitBits.IsImplicit = IsImplicit;
4214 CoawaitExpr(EmptyShell Empty)
4215 : CoroutineSuspendExpr(CoawaitExprClass, Empty) {}
4217 Expr *getOperand() const {
4218 // FIXME: Dig out the actual operand or store it.
4219 return getCommonExpr();
4222 bool isImplicit() const { return CoawaitBits.IsImplicit; }
4223 void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; }
4225 static bool classof(const Stmt *T) {
4226 return T->getStmtClass() == CoawaitExprClass;
4230 /// \brief Represents a 'co_await' expression while the type of the promise
4232 class DependentCoawaitExpr : public Expr {
4233 SourceLocation KeywordLoc;
4236 friend class ASTStmtReader;
4239 DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op,
4240 UnresolvedLookupExpr *OpCoawait)
4241 : Expr(DependentCoawaitExprClass, Ty, VK_RValue, OK_Ordinary,
4242 /*TypeDependent*/ true, /*ValueDependent*/ true,
4243 /*InstantiationDependent*/ true,
4244 Op->containsUnexpandedParameterPack()),
4245 KeywordLoc(KeywordLoc) {
4246 // NOTE: A co_await expression is dependent on the coroutines promise
4247 // type and may be dependent even when the `Op` expression is not.
4248 assert(Ty->isDependentType() &&
4249 "wrong constructor for non-dependent co_await/co_yield expression");
4251 SubExprs[1] = OpCoawait;
4254 DependentCoawaitExpr(EmptyShell Empty)
4255 : Expr(DependentCoawaitExprClass, Empty) {}
4257 Expr *getOperand() const { return cast<Expr>(SubExprs[0]); }
4258 UnresolvedLookupExpr *getOperatorCoawaitLookup() const {
4259 return cast<UnresolvedLookupExpr>(SubExprs[1]);
4261 SourceLocation getKeywordLoc() const { return KeywordLoc; }
4263 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
4264 SourceLocation getLocEnd() const LLVM_READONLY {
4265 return getOperand()->getLocEnd();
4268 child_range children() { return child_range(SubExprs, SubExprs + 2); }
4270 static bool classof(const Stmt *T) {
4271 return T->getStmtClass() == DependentCoawaitExprClass;
4275 /// \brief Represents a 'co_yield' expression.
4276 class CoyieldExpr : public CoroutineSuspendExpr {
4277 friend class ASTStmtReader;
4279 CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready,
4280 Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue)
4281 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready,
4282 Suspend, Resume, OpaqueValue) {}
4283 CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand)
4284 : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {}
4285 CoyieldExpr(EmptyShell Empty)
4286 : CoroutineSuspendExpr(CoyieldExprClass, Empty) {}
4288 Expr *getOperand() const {
4289 // FIXME: Dig out the actual operand or store it.
4290 return getCommonExpr();
4293 static bool classof(const Stmt *T) {
4294 return T->getStmtClass() == CoyieldExprClass;
4298 } // end namespace clang