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/Expr.h"
20 #include "clang/AST/LambdaCapture.h"
21 #include "clang/AST/TemplateBase.h"
22 #include "clang/AST/UnresolvedSet.h"
23 #include "clang/Basic/ExpressionTraits.h"
24 #include "clang/Basic/TypeTraits.h"
25 #include "llvm/Support/Compiler.h"
29 class CXXConstructorDecl;
30 class CXXDestructorDecl;
34 class TemplateArgumentListInfo;
37 //===--------------------------------------------------------------------===//
39 //===--------------------------------------------------------------------===//
41 /// \brief A call to an overloaded operator written using operator
44 /// Represents a call to an overloaded operator written using operator
45 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
46 /// normal call, this AST node provides better information about the
47 /// syntactic representation of the call.
49 /// In a C++ template, this expression node kind will be used whenever
50 /// any of the arguments are type-dependent. In this case, the
51 /// function itself will be a (possibly empty) set of functions and
52 /// function templates that were found by name lookup at template
54 class CXXOperatorCallExpr : public CallExpr {
55 /// \brief The overloaded operator.
56 OverloadedOperatorKind Operator;
59 // Record the FP_CONTRACT state that applies to this operator call. Only
60 // meaningful for floating point types. For other types this value can be
62 unsigned FPContractable : 1;
64 SourceRange getSourceRangeImpl() const LLVM_READONLY;
66 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
67 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
68 SourceLocation operatorloc, bool fpContractable)
69 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
71 Operator(Op), FPContractable(fpContractable) {
72 Range = getSourceRangeImpl();
74 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
75 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
78 /// \brief Returns the kind of overloaded operator that this
79 /// expression refers to.
80 OverloadedOperatorKind getOperator() const { return Operator; }
82 /// \brief Returns the location of the operator symbol in the expression.
84 /// When \c getOperator()==OO_Call, this is the location of the right
85 /// parentheses; when \c getOperator()==OO_Subscript, this is the location
86 /// of the right bracket.
87 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
89 SourceLocation getExprLoc() const LLVM_READONLY {
90 return (Operator < OO_Plus || Operator >= OO_Arrow ||
91 Operator == OO_PlusPlus || Operator == OO_MinusMinus)
96 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
97 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
98 SourceRange getSourceRange() const { return Range; }
100 static bool classof(const Stmt *T) {
101 return T->getStmtClass() == CXXOperatorCallExprClass;
104 // Set the FP contractability status of this operator. Only meaningful for
105 // operations on floating point types.
106 void setFPContractable(bool FPC) { FPContractable = FPC; }
108 // Get the FP contractability status of this operator. Only meaningful for
109 // operations on floating point types.
110 bool isFPContractable() const { return FPContractable; }
112 friend class ASTStmtReader;
113 friend class ASTStmtWriter;
116 /// Represents a call to a member function that
117 /// may be written either with member call syntax (e.g., "obj.func()"
118 /// or "objptr->func()") or with normal function-call syntax
119 /// ("func()") within a member function that ends up calling a member
120 /// function. The callee in either case is a MemberExpr that contains
121 /// both the object argument and the member function, while the
122 /// arguments are the arguments within the parentheses (not including
123 /// the object argument).
124 class CXXMemberCallExpr : public CallExpr {
126 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
127 QualType t, ExprValueKind VK, SourceLocation RP)
128 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
130 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
131 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
133 /// \brief Retrieves the implicit object argument for the member call.
135 /// For example, in "x.f(5)", this returns the sub-expression "x".
136 Expr *getImplicitObjectArgument() const;
138 /// \brief Retrieves the declaration of the called method.
139 CXXMethodDecl *getMethodDecl() const;
141 /// \brief Retrieves the CXXRecordDecl for the underlying type of
142 /// the implicit object argument.
144 /// Note that this is may not be the same declaration as that of the class
145 /// context of the CXXMethodDecl which this function is calling.
146 /// FIXME: Returns 0 for member pointer call exprs.
147 CXXRecordDecl *getRecordDecl() const;
149 static bool classof(const Stmt *T) {
150 return T->getStmtClass() == CXXMemberCallExprClass;
154 /// \brief Represents a call to a CUDA kernel function.
155 class CUDAKernelCallExpr : public CallExpr {
157 enum { CONFIG, END_PREARG };
160 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
161 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
163 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
167 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
168 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
170 const CallExpr *getConfig() const {
171 return cast_or_null<CallExpr>(getPreArg(CONFIG));
173 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
174 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
176 static bool classof(const Stmt *T) {
177 return T->getStmtClass() == CUDAKernelCallExprClass;
181 /// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
183 /// This abstract class is inherited by all of the classes
184 /// representing "named" casts: CXXStaticCastExpr for \c static_cast,
185 /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
186 /// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
187 class CXXNamedCastExpr : public ExplicitCastExpr {
189 SourceLocation Loc; // the location of the casting op
190 SourceLocation RParenLoc; // the location of the right parenthesis
191 SourceRange AngleBrackets; // range for '<' '>'
194 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
195 CastKind kind, Expr *op, unsigned PathSize,
196 TypeSourceInfo *writtenTy, SourceLocation l,
197 SourceLocation RParenLoc,
198 SourceRange AngleBrackets)
199 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
200 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
202 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
203 : ExplicitCastExpr(SC, Shell, PathSize) { }
205 friend class ASTStmtReader;
208 const char *getCastName() const;
210 /// \brief Retrieve the location of the cast operator keyword, e.g.,
212 SourceLocation getOperatorLoc() const { return Loc; }
214 /// \brief Retrieve the location of the closing parenthesis.
215 SourceLocation getRParenLoc() const { return RParenLoc; }
217 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
218 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
219 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
221 static bool classof(const Stmt *T) {
222 switch (T->getStmtClass()) {
223 case CXXStaticCastExprClass:
224 case CXXDynamicCastExprClass:
225 case CXXReinterpretCastExprClass:
226 case CXXConstCastExprClass:
234 /// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
236 /// This expression node represents a C++ static cast, e.g.,
237 /// \c static_cast<int>(1.0).
238 class CXXStaticCastExpr : public CXXNamedCastExpr {
239 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
240 unsigned pathSize, TypeSourceInfo *writtenTy,
241 SourceLocation l, SourceLocation RParenLoc,
242 SourceRange AngleBrackets)
243 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
244 writtenTy, l, RParenLoc, AngleBrackets) {}
246 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
247 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
250 static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
251 ExprValueKind VK, CastKind K, Expr *Op,
252 const CXXCastPath *Path,
253 TypeSourceInfo *Written, SourceLocation L,
254 SourceLocation RParenLoc,
255 SourceRange AngleBrackets);
256 static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
259 static bool classof(const Stmt *T) {
260 return T->getStmtClass() == CXXStaticCastExprClass;
264 /// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
266 /// This expression node represents a dynamic cast, e.g.,
267 /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
268 /// check to determine how to perform the type conversion.
269 class CXXDynamicCastExpr : public CXXNamedCastExpr {
270 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
271 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
272 SourceLocation l, SourceLocation RParenLoc,
273 SourceRange AngleBrackets)
274 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
275 writtenTy, l, RParenLoc, AngleBrackets) {}
277 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
278 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
281 static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
282 ExprValueKind VK, CastKind Kind, Expr *Op,
283 const CXXCastPath *Path,
284 TypeSourceInfo *Written, SourceLocation L,
285 SourceLocation RParenLoc,
286 SourceRange AngleBrackets);
288 static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
291 bool isAlwaysNull() const;
293 static bool classof(const Stmt *T) {
294 return T->getStmtClass() == CXXDynamicCastExprClass;
298 /// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
300 /// This expression node represents a reinterpret cast, e.g.,
301 /// @c reinterpret_cast<int>(VoidPtr).
303 /// A reinterpret_cast provides a differently-typed view of a value but
304 /// (in Clang, as in most C++ implementations) performs no actual work at
306 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
307 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
308 Expr *op, unsigned pathSize,
309 TypeSourceInfo *writtenTy, SourceLocation l,
310 SourceLocation RParenLoc,
311 SourceRange AngleBrackets)
312 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
313 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
315 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
316 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
319 static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
320 ExprValueKind VK, CastKind Kind,
321 Expr *Op, const CXXCastPath *Path,
322 TypeSourceInfo *WrittenTy, SourceLocation L,
323 SourceLocation RParenLoc,
324 SourceRange AngleBrackets);
325 static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
328 static bool classof(const Stmt *T) {
329 return T->getStmtClass() == CXXReinterpretCastExprClass;
333 /// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
335 /// This expression node represents a const cast, e.g.,
336 /// \c const_cast<char*>(PtrToConstChar).
338 /// A const_cast can remove type qualifiers but does not change the underlying
340 class CXXConstCastExpr : public CXXNamedCastExpr {
341 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
342 TypeSourceInfo *writtenTy, SourceLocation l,
343 SourceLocation RParenLoc, SourceRange AngleBrackets)
344 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
345 0, writtenTy, l, RParenLoc, AngleBrackets) {}
347 explicit CXXConstCastExpr(EmptyShell Empty)
348 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
351 static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
352 ExprValueKind VK, Expr *Op,
353 TypeSourceInfo *WrittenTy, SourceLocation L,
354 SourceLocation RParenLoc,
355 SourceRange AngleBrackets);
356 static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
358 static bool classof(const Stmt *T) {
359 return T->getStmtClass() == CXXConstCastExprClass;
363 /// \brief A call to a literal operator (C++11 [over.literal])
364 /// written as a user-defined literal (C++11 [lit.ext]).
366 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
367 /// is semantically equivalent to a normal call, this AST node provides better
368 /// information about the syntactic representation of the literal.
370 /// Since literal operators are never found by ADL and can only be declared at
371 /// namespace scope, a user-defined literal is never dependent.
372 class UserDefinedLiteral : public CallExpr {
373 /// \brief The location of a ud-suffix within the literal.
374 SourceLocation UDSuffixLoc;
377 UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
378 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
379 SourceLocation SuffixLoc)
380 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
381 UDSuffixLoc(SuffixLoc) {}
382 explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
383 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
385 /// The kind of literal operator which is invoked.
386 enum LiteralOperatorKind {
387 LOK_Raw, ///< Raw form: operator "" X (const char *)
388 LOK_Template, ///< Raw form: operator "" X<cs...> ()
389 LOK_Integer, ///< operator "" X (unsigned long long)
390 LOK_Floating, ///< operator "" X (long double)
391 LOK_String, ///< operator "" X (const CharT *, size_t)
392 LOK_Character ///< operator "" X (CharT)
395 /// \brief Returns the kind of literal operator invocation
396 /// which this expression represents.
397 LiteralOperatorKind getLiteralOperatorKind() const;
399 /// \brief If this is not a raw user-defined literal, get the
400 /// underlying cooked literal (representing the literal with the suffix
402 Expr *getCookedLiteral();
403 const Expr *getCookedLiteral() const {
404 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
407 SourceLocation getLocStart() const {
408 if (getLiteralOperatorKind() == LOK_Template)
409 return getRParenLoc();
410 return getArg(0)->getLocStart();
412 SourceLocation getLocEnd() const { return getRParenLoc(); }
415 /// \brief Returns the location of a ud-suffix in the expression.
417 /// For a string literal, there may be multiple identical suffixes. This
418 /// returns the first.
419 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
421 /// \brief Returns the ud-suffix specified for this literal.
422 const IdentifierInfo *getUDSuffix() const;
424 static bool classof(const Stmt *S) {
425 return S->getStmtClass() == UserDefinedLiteralClass;
428 friend class ASTStmtReader;
429 friend class ASTStmtWriter;
432 /// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
434 class CXXBoolLiteralExpr : public Expr {
438 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
439 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
441 Value(val), Loc(l) {}
443 explicit CXXBoolLiteralExpr(EmptyShell Empty)
444 : Expr(CXXBoolLiteralExprClass, Empty) { }
446 bool getValue() const { return Value; }
447 void setValue(bool V) { Value = V; }
449 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
450 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
452 SourceLocation getLocation() const { return Loc; }
453 void setLocation(SourceLocation L) { Loc = L; }
455 static bool classof(const Stmt *T) {
456 return T->getStmtClass() == CXXBoolLiteralExprClass;
460 child_range children() { return child_range(); }
463 /// \brief The null pointer literal (C++11 [lex.nullptr])
465 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
466 class CXXNullPtrLiteralExpr : public Expr {
469 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
470 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
474 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
475 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
477 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
478 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
480 SourceLocation getLocation() const { return Loc; }
481 void setLocation(SourceLocation L) { Loc = L; }
483 static bool classof(const Stmt *T) {
484 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
487 child_range children() { return child_range(); }
490 /// \brief Implicit construction of a std::initializer_list<T> object from an
491 /// array temporary within list-initialization (C++11 [dcl.init.list]p5).
492 class CXXStdInitializerListExpr : public Expr {
495 CXXStdInitializerListExpr(EmptyShell Empty)
496 : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(nullptr) {}
499 CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
500 : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
501 Ty->isDependentType(), SubExpr->isValueDependent(),
502 SubExpr->isInstantiationDependent(),
503 SubExpr->containsUnexpandedParameterPack()),
506 Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
507 const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
509 SourceLocation getLocStart() const LLVM_READONLY {
510 return SubExpr->getLocStart();
512 SourceLocation getLocEnd() const LLVM_READONLY {
513 return SubExpr->getLocEnd();
515 SourceRange getSourceRange() const LLVM_READONLY {
516 return SubExpr->getSourceRange();
519 static bool classof(const Stmt *S) {
520 return S->getStmtClass() == CXXStdInitializerListExprClass;
523 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
525 friend class ASTReader;
526 friend class ASTStmtReader;
529 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
530 /// the \c type_info that corresponds to the supplied type, or the (possibly
531 /// dynamic) type of the supplied expression.
533 /// This represents code like \c typeid(int) or \c typeid(*objPtr)
534 class CXXTypeidExpr : public Expr {
536 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
540 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
541 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
542 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
544 // typeid is value-dependent if the type or expression are dependent
545 Operand->getType()->isDependentType(),
546 Operand->getType()->isInstantiationDependentType(),
547 Operand->getType()->containsUnexpandedParameterPack()),
548 Operand(Operand), Range(R) { }
550 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
551 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
552 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
554 // typeid is value-dependent if the type or expression are dependent
555 Operand->isTypeDependent() || Operand->isValueDependent(),
556 Operand->isInstantiationDependent(),
557 Operand->containsUnexpandedParameterPack()),
558 Operand(Operand), Range(R) { }
560 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
561 : Expr(CXXTypeidExprClass, Empty) {
563 Operand = (Expr*)nullptr;
565 Operand = (TypeSourceInfo*)nullptr;
568 /// Determine whether this typeid has a type operand which is potentially
569 /// evaluated, per C++11 [expr.typeid]p3.
570 bool isPotentiallyEvaluated() const;
572 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
574 /// \brief Retrieves the type operand of this typeid() expression after
575 /// various required adjustments (removing reference types, cv-qualifiers).
576 QualType getTypeOperand(ASTContext &Context) const;
578 /// \brief Retrieve source information for the type operand.
579 TypeSourceInfo *getTypeOperandSourceInfo() const {
580 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
581 return Operand.get<TypeSourceInfo *>();
584 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
585 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
589 Expr *getExprOperand() const {
590 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
591 return static_cast<Expr*>(Operand.get<Stmt *>());
594 void setExprOperand(Expr *E) {
595 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
599 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
600 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
601 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
602 void setSourceRange(SourceRange R) { Range = R; }
604 static bool classof(const Stmt *T) {
605 return T->getStmtClass() == CXXTypeidExprClass;
609 child_range children() {
610 if (isTypeOperand()) return child_range();
611 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
612 return child_range(begin, begin + 1);
616 /// \brief A member reference to an MSPropertyDecl.
618 /// This expression always has pseudo-object type, and therefore it is
619 /// typically not encountered in a fully-typechecked expression except
620 /// within the syntactic form of a PseudoObjectExpr.
621 class MSPropertyRefExpr : public Expr {
623 MSPropertyDecl *TheDecl;
624 SourceLocation MemberLoc;
626 NestedNameSpecifierLoc QualifierLoc;
629 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
630 QualType ty, ExprValueKind VK,
631 NestedNameSpecifierLoc qualifierLoc,
632 SourceLocation nameLoc)
633 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
634 /*type-dependent*/ false, baseExpr->isValueDependent(),
635 baseExpr->isInstantiationDependent(),
636 baseExpr->containsUnexpandedParameterPack()),
637 BaseExpr(baseExpr), TheDecl(decl),
638 MemberLoc(nameLoc), IsArrow(isArrow),
639 QualifierLoc(qualifierLoc) {}
641 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
643 SourceRange getSourceRange() const LLVM_READONLY {
644 return SourceRange(getLocStart(), getLocEnd());
646 bool isImplicitAccess() const {
647 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
649 SourceLocation getLocStart() const {
650 if (!isImplicitAccess())
651 return BaseExpr->getLocStart();
652 else if (QualifierLoc)
653 return QualifierLoc.getBeginLoc();
657 SourceLocation getLocEnd() const { return getMemberLoc(); }
659 child_range children() {
660 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
662 static bool classof(const Stmt *T) {
663 return T->getStmtClass() == MSPropertyRefExprClass;
666 Expr *getBaseExpr() const { return BaseExpr; }
667 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
668 bool isArrow() const { return IsArrow; }
669 SourceLocation getMemberLoc() const { return MemberLoc; }
670 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
672 friend class ASTStmtReader;
675 /// A Microsoft C++ @c __uuidof expression, which gets
676 /// the _GUID that corresponds to the supplied type or expression.
678 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
679 class CXXUuidofExpr : public Expr {
681 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
685 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
686 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
687 false, Operand->getType()->isDependentType(),
688 Operand->getType()->isInstantiationDependentType(),
689 Operand->getType()->containsUnexpandedParameterPack()),
690 Operand(Operand), Range(R) { }
692 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
693 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
694 false, Operand->isTypeDependent(),
695 Operand->isInstantiationDependent(),
696 Operand->containsUnexpandedParameterPack()),
697 Operand(Operand), Range(R) { }
699 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
700 : Expr(CXXUuidofExprClass, Empty) {
702 Operand = (Expr*)nullptr;
704 Operand = (TypeSourceInfo*)nullptr;
707 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
709 /// \brief Retrieves the type operand of this __uuidof() expression after
710 /// various required adjustments (removing reference types, cv-qualifiers).
711 QualType getTypeOperand(ASTContext &Context) const;
713 /// \brief Retrieve source information for the type operand.
714 TypeSourceInfo *getTypeOperandSourceInfo() const {
715 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
716 return Operand.get<TypeSourceInfo *>();
719 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
720 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
724 Expr *getExprOperand() const {
725 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
726 return static_cast<Expr*>(Operand.get<Stmt *>());
729 void setExprOperand(Expr *E) {
730 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
734 StringRef getUuidAsStringRef(ASTContext &Context) const;
736 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
737 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
738 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
739 void setSourceRange(SourceRange R) { Range = R; }
741 static bool classof(const Stmt *T) {
742 return T->getStmtClass() == CXXUuidofExprClass;
745 /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to
747 static const UuidAttr *GetUuidAttrOfType(QualType QT,
748 bool *HasMultipleGUIDsPtr = nullptr);
751 child_range children() {
752 if (isTypeOperand()) return child_range();
753 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
754 return child_range(begin, begin + 1);
758 /// \brief Represents the \c this expression in C++.
760 /// This is a pointer to the object on which the current member function is
761 /// executing (C++ [expr.prim]p3). Example:
767 /// void test() { this->bar(); }
770 class CXXThisExpr : public Expr {
775 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
776 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
777 // 'this' is type-dependent if the class type of the enclosing
778 // member function is dependent (C++ [temp.dep.expr]p2)
779 Type->isDependentType(), Type->isDependentType(),
780 Type->isInstantiationDependentType(),
781 /*ContainsUnexpandedParameterPack=*/false),
782 Loc(L), Implicit(isImplicit) { }
784 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
786 SourceLocation getLocation() const { return Loc; }
787 void setLocation(SourceLocation L) { Loc = L; }
789 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
790 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
792 bool isImplicit() const { return Implicit; }
793 void setImplicit(bool I) { Implicit = I; }
795 static bool classof(const Stmt *T) {
796 return T->getStmtClass() == CXXThisExprClass;
800 child_range children() { return child_range(); }
803 /// \brief A C++ throw-expression (C++ [except.throw]).
805 /// This handles 'throw' (for re-throwing the current exception) and
806 /// 'throw' assignment-expression. When assignment-expression isn't
807 /// present, Op will be null.
808 class CXXThrowExpr : public Expr {
810 SourceLocation ThrowLoc;
811 /// \brief Whether the thrown variable (if any) is in scope.
812 unsigned IsThrownVariableInScope : 1;
814 friend class ASTStmtReader;
817 // \p Ty is the void type which is used as the result type of the
818 // expression. The \p l is the location of the throw keyword. \p expr
819 // can by null, if the optional expression to throw isn't present.
820 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
821 bool IsThrownVariableInScope) :
822 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
823 expr && expr->isInstantiationDependent(),
824 expr && expr->containsUnexpandedParameterPack()),
825 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
826 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
828 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
829 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
831 SourceLocation getThrowLoc() const { return ThrowLoc; }
833 /// \brief Determines whether the variable thrown by this expression (if any!)
834 /// is within the innermost try block.
836 /// This information is required to determine whether the NRVO can apply to
838 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
840 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
841 SourceLocation getLocEnd() const LLVM_READONLY {
844 return getSubExpr()->getLocEnd();
847 static bool classof(const Stmt *T) {
848 return T->getStmtClass() == CXXThrowExprClass;
852 child_range children() {
853 return child_range(&Op, Op ? &Op+1 : &Op);
857 /// \brief A default argument (C++ [dcl.fct.default]).
859 /// This wraps up a function call argument that was created from the
860 /// corresponding parameter's default argument, when the call did not
861 /// explicitly supply arguments for all of the parameters.
862 class CXXDefaultArgExpr : public Expr {
863 /// \brief The parameter whose default is being used.
865 /// When the bit is set, the subexpression is stored after the
866 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
867 /// actual default expression is the subexpression.
868 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
870 /// \brief The location where the default argument expression was used.
873 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
875 param->hasUnparsedDefaultArg()
876 ? param->getType().getNonReferenceType()
877 : param->getDefaultArg()->getType(),
878 param->getDefaultArg()->getValueKind(),
879 param->getDefaultArg()->getObjectKind(), false, false, false, false),
880 Param(param, false), Loc(Loc) { }
882 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
884 : Expr(SC, SubExpr->getType(),
885 SubExpr->getValueKind(), SubExpr->getObjectKind(),
886 false, false, false, false),
887 Param(param, true), Loc(Loc) {
888 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
892 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
894 // \p Param is the parameter whose default argument is used by this
896 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
897 ParmVarDecl *Param) {
898 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
901 // \p Param is the parameter whose default argument is used by this
902 // expression, and \p SubExpr is the expression that will actually be used.
903 static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
904 ParmVarDecl *Param, Expr *SubExpr);
906 // Retrieve the parameter that the argument was created from.
907 const ParmVarDecl *getParam() const { return Param.getPointer(); }
908 ParmVarDecl *getParam() { return Param.getPointer(); }
910 // Retrieve the actual argument to the function call.
911 const Expr *getExpr() const {
913 return *reinterpret_cast<Expr const * const*> (this + 1);
914 return getParam()->getDefaultArg();
918 return *reinterpret_cast<Expr **> (this + 1);
919 return getParam()->getDefaultArg();
922 /// \brief Retrieve the location where this default argument was actually
924 SourceLocation getUsedLocation() const { return Loc; }
926 /// Default argument expressions have no representation in the
927 /// source, so they have an empty source range.
928 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
929 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
931 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
933 static bool classof(const Stmt *T) {
934 return T->getStmtClass() == CXXDefaultArgExprClass;
938 child_range children() { return child_range(); }
940 friend class ASTStmtReader;
941 friend class ASTStmtWriter;
944 /// \brief A use of a default initializer in a constructor or in aggregate
947 /// This wraps a use of a C++ default initializer (technically,
948 /// a brace-or-equal-initializer for a non-static data member) when it
949 /// is implicitly used in a mem-initializer-list in a constructor
950 /// (C++11 [class.base.init]p8) or in aggregate initialization
951 /// (C++1y [dcl.init.aggr]p7).
952 class CXXDefaultInitExpr : public Expr {
953 /// \brief The field whose default is being used.
956 /// \brief The location where the default initializer expression was used.
959 CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
962 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
965 /// \p Field is the non-static data member whose default initializer is used
966 /// by this expression.
967 static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
969 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
972 /// \brief Get the field whose initializer will be used.
973 FieldDecl *getField() { return Field; }
974 const FieldDecl *getField() const { return Field; }
976 /// \brief Get the initialization expression that will be used.
977 const Expr *getExpr() const {
978 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
979 return Field->getInClassInitializer();
982 assert(Field->getInClassInitializer() && "initializer hasn't been parsed");
983 return Field->getInClassInitializer();
986 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
987 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
989 static bool classof(const Stmt *T) {
990 return T->getStmtClass() == CXXDefaultInitExprClass;
994 child_range children() { return child_range(); }
996 friend class ASTReader;
997 friend class ASTStmtReader;
1000 /// \brief Represents a C++ temporary.
1001 class CXXTemporary {
1002 /// \brief The destructor that needs to be called.
1003 const CXXDestructorDecl *Destructor;
1005 explicit CXXTemporary(const CXXDestructorDecl *destructor)
1006 : Destructor(destructor) { }
1009 static CXXTemporary *Create(const ASTContext &C,
1010 const CXXDestructorDecl *Destructor);
1012 const CXXDestructorDecl *getDestructor() const { return Destructor; }
1013 void setDestructor(const CXXDestructorDecl *Dtor) {
1018 /// \brief Represents binding an expression to a temporary.
1020 /// This ensures the destructor is called for the temporary. It should only be
1021 /// needed for non-POD, non-trivially destructable class types. For example:
1025 /// S() { } // User defined constructor makes S non-POD.
1026 /// ~S() { } // User defined destructor makes it non-trivial.
1029 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1032 class CXXBindTemporaryExpr : public Expr {
1037 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1038 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1039 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1040 SubExpr->isValueDependent(),
1041 SubExpr->isInstantiationDependent(),
1042 SubExpr->containsUnexpandedParameterPack()),
1043 Temp(temp), SubExpr(SubExpr) { }
1046 CXXBindTemporaryExpr(EmptyShell Empty)
1047 : Expr(CXXBindTemporaryExprClass, Empty), Temp(nullptr), SubExpr(nullptr) {}
1049 static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1052 CXXTemporary *getTemporary() { return Temp; }
1053 const CXXTemporary *getTemporary() const { return Temp; }
1054 void setTemporary(CXXTemporary *T) { Temp = T; }
1056 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1057 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1058 void setSubExpr(Expr *E) { SubExpr = E; }
1060 SourceLocation getLocStart() const LLVM_READONLY {
1061 return SubExpr->getLocStart();
1063 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1065 // Implement isa/cast/dyncast/etc.
1066 static bool classof(const Stmt *T) {
1067 return T->getStmtClass() == CXXBindTemporaryExprClass;
1071 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1074 /// \brief Represents a call to a C++ constructor.
1075 class CXXConstructExpr : public Expr {
1077 enum ConstructionKind {
1085 CXXConstructorDecl *Constructor;
1088 SourceRange ParenOrBraceRange;
1089 unsigned NumArgs : 16;
1091 bool HadMultipleCandidates : 1;
1092 bool ListInitialization : 1;
1093 bool StdInitListInitialization : 1;
1094 bool ZeroInitialization : 1;
1095 unsigned ConstructKind : 2;
1099 CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
1101 CXXConstructorDecl *d, bool elidable,
1102 ArrayRef<Expr *> Args,
1103 bool HadMultipleCandidates,
1104 bool ListInitialization,
1105 bool StdInitListInitialization,
1106 bool ZeroInitialization,
1107 ConstructionKind ConstructKind,
1108 SourceRange ParenOrBraceRange);
1110 /// \brief Construct an empty C++ construction expression.
1111 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1112 : Expr(SC, Empty), Constructor(nullptr), NumArgs(0), Elidable(false),
1113 HadMultipleCandidates(false), ListInitialization(false),
1114 ZeroInitialization(false), ConstructKind(0), Args(nullptr)
1118 /// \brief Construct an empty C++ construction expression.
1119 explicit CXXConstructExpr(EmptyShell Empty)
1120 : Expr(CXXConstructExprClass, Empty), Constructor(nullptr),
1121 NumArgs(0), Elidable(false), HadMultipleCandidates(false),
1122 ListInitialization(false), ZeroInitialization(false),
1123 ConstructKind(0), Args(nullptr)
1126 static CXXConstructExpr *Create(const ASTContext &C, QualType T,
1128 CXXConstructorDecl *D, bool Elidable,
1129 ArrayRef<Expr *> Args,
1130 bool HadMultipleCandidates,
1131 bool ListInitialization,
1132 bool StdInitListInitialization,
1133 bool ZeroInitialization,
1134 ConstructionKind ConstructKind,
1135 SourceRange ParenOrBraceRange);
1137 CXXConstructorDecl *getConstructor() const { return Constructor; }
1138 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1140 SourceLocation getLocation() const { return Loc; }
1141 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1143 /// \brief Whether this construction is elidable.
1144 bool isElidable() const { return Elidable; }
1145 void setElidable(bool E) { Elidable = E; }
1147 /// \brief Whether the referred constructor was resolved from
1148 /// an overloaded set having size greater than 1.
1149 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1150 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1152 /// \brief Whether this constructor call was written as list-initialization.
1153 bool isListInitialization() const { return ListInitialization; }
1154 void setListInitialization(bool V) { ListInitialization = V; }
1156 /// \brief Whether this constructor call was written as list-initialization,
1157 /// but was interpreted as forming a std::initializer_list<T> from the list
1158 /// and passing that as a single constructor argument.
1159 /// See C++11 [over.match.list]p1 bullet 1.
1160 bool isStdInitListInitialization() const { return StdInitListInitialization; }
1161 void setStdInitListInitialization(bool V) { StdInitListInitialization = V; }
1163 /// \brief Whether this construction first requires
1164 /// zero-initialization before the initializer is called.
1165 bool requiresZeroInitialization() const { return ZeroInitialization; }
1166 void setRequiresZeroInitialization(bool ZeroInit) {
1167 ZeroInitialization = ZeroInit;
1170 /// \brief Determine whether this constructor is actually constructing
1171 /// a base class (rather than a complete object).
1172 ConstructionKind getConstructionKind() const {
1173 return (ConstructionKind)ConstructKind;
1175 void setConstructionKind(ConstructionKind CK) {
1179 typedef ExprIterator arg_iterator;
1180 typedef ConstExprIterator const_arg_iterator;
1181 typedef llvm::iterator_range<arg_iterator> arg_range;
1182 typedef llvm::iterator_range<const_arg_iterator> arg_const_range;
1184 arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
1185 arg_const_range arguments() const {
1186 return arg_const_range(arg_begin(), arg_end());
1189 arg_iterator arg_begin() { return Args; }
1190 arg_iterator arg_end() { return Args + NumArgs; }
1191 const_arg_iterator arg_begin() const { return Args; }
1192 const_arg_iterator arg_end() const { return Args + NumArgs; }
1194 Expr **getArgs() { return reinterpret_cast<Expr **>(Args); }
1195 const Expr *const *getArgs() const {
1196 return const_cast<CXXConstructExpr *>(this)->getArgs();
1198 unsigned getNumArgs() const { return NumArgs; }
1200 /// \brief Return the specified argument.
1201 Expr *getArg(unsigned Arg) {
1202 assert(Arg < NumArgs && "Arg access out of range!");
1203 return cast<Expr>(Args[Arg]);
1205 const Expr *getArg(unsigned Arg) const {
1206 assert(Arg < NumArgs && "Arg access out of range!");
1207 return cast<Expr>(Args[Arg]);
1210 /// \brief Set the specified argument.
1211 void setArg(unsigned Arg, Expr *ArgExpr) {
1212 assert(Arg < NumArgs && "Arg access out of range!");
1213 Args[Arg] = ArgExpr;
1216 SourceLocation getLocStart() const LLVM_READONLY;
1217 SourceLocation getLocEnd() const LLVM_READONLY;
1218 SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
1219 void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
1221 static bool classof(const Stmt *T) {
1222 return T->getStmtClass() == CXXConstructExprClass ||
1223 T->getStmtClass() == CXXTemporaryObjectExprClass;
1227 child_range children() {
1228 return child_range(&Args[0], &Args[0]+NumArgs);
1231 friend class ASTStmtReader;
1234 /// \brief Represents an explicit C++ type conversion that uses "functional"
1235 /// notation (C++ [expr.type.conv]).
1241 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1242 SourceLocation LParenLoc;
1243 SourceLocation RParenLoc;
1245 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1246 TypeSourceInfo *writtenTy,
1247 CastKind kind, Expr *castExpr, unsigned pathSize,
1248 SourceLocation lParenLoc, SourceLocation rParenLoc)
1249 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1250 castExpr, pathSize, writtenTy),
1251 LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
1253 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1254 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1257 static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1259 TypeSourceInfo *Written,
1260 CastKind Kind, Expr *Op,
1261 const CXXCastPath *Path,
1262 SourceLocation LPLoc,
1263 SourceLocation RPLoc);
1264 static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1267 SourceLocation getLParenLoc() const { return LParenLoc; }
1268 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1269 SourceLocation getRParenLoc() const { return RParenLoc; }
1270 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1272 SourceLocation getLocStart() const LLVM_READONLY;
1273 SourceLocation getLocEnd() const LLVM_READONLY;
1275 static bool classof(const Stmt *T) {
1276 return T->getStmtClass() == CXXFunctionalCastExprClass;
1280 /// @brief Represents a C++ functional cast expression that builds a
1281 /// temporary object.
1283 /// This expression type represents a C++ "functional" cast
1284 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1285 /// constructor to build a temporary object. With N == 1 arguments the
1286 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1289 /// struct X { X(int, float); }
1292 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1295 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1296 TypeSourceInfo *Type;
1299 CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons,
1300 TypeSourceInfo *Type,
1301 ArrayRef<Expr *> Args,
1302 SourceRange ParenOrBraceRange,
1303 bool HadMultipleCandidates,
1304 bool ListInitialization,
1305 bool StdInitListInitialization,
1306 bool ZeroInitialization);
1307 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1308 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1310 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1312 SourceLocation getLocStart() const LLVM_READONLY;
1313 SourceLocation getLocEnd() const LLVM_READONLY;
1315 static bool classof(const Stmt *T) {
1316 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1319 friend class ASTStmtReader;
1322 /// \brief A C++ lambda expression, which produces a function object
1323 /// (of unspecified type) that can be invoked later.
1327 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1328 /// values.erase(std::remove_if(values.begin(), values.end(),
1329 /// [=](double value) { return value > cutoff; });
1333 /// C++11 lambda expressions can capture local variables, either by copying
1334 /// the values of those local variables at the time the function
1335 /// object is constructed (not when it is called!) or by holding a
1336 /// reference to the local variable. These captures can occur either
1337 /// implicitly or can be written explicitly between the square
1338 /// brackets ([...]) that start the lambda expression.
1340 /// C++1y introduces a new form of "capture" called an init-capture that
1341 /// includes an initializing expression (rather than capturing a variable),
1342 /// and which can never occur implicitly.
1343 class LambdaExpr : public Expr {
1344 /// \brief The source range that covers the lambda introducer ([...]).
1345 SourceRange IntroducerRange;
1347 /// \brief The source location of this lambda's capture-default ('=' or '&').
1348 SourceLocation CaptureDefaultLoc;
1350 /// \brief The number of captures.
1351 unsigned NumCaptures : 16;
1353 /// \brief The default capture kind, which is a value of type
1354 /// LambdaCaptureDefault.
1355 unsigned CaptureDefault : 2;
1357 /// \brief Whether this lambda had an explicit parameter list vs. an
1358 /// implicit (and empty) parameter list.
1359 unsigned ExplicitParams : 1;
1361 /// \brief Whether this lambda had the result type explicitly specified.
1362 unsigned ExplicitResultType : 1;
1364 /// \brief Whether there are any array index variables stored at the end of
1365 /// this lambda expression.
1366 unsigned HasArrayIndexVars : 1;
1368 /// \brief The location of the closing brace ('}') that completes
1371 /// The location of the brace is also available by looking up the
1372 /// function call operator in the lambda class. However, it is
1373 /// stored here to improve the performance of getSourceRange(), and
1374 /// to avoid having to deserialize the function call operator from a
1375 /// module file just to determine the source range.
1376 SourceLocation ClosingBrace;
1378 // Note: The capture initializers are stored directly after the lambda
1379 // expression, along with the index variables used to initialize by-copy
1382 typedef LambdaCapture Capture;
1384 /// \brief Construct a lambda expression.
1385 LambdaExpr(QualType T, SourceRange IntroducerRange,
1386 LambdaCaptureDefault CaptureDefault,
1387 SourceLocation CaptureDefaultLoc,
1388 ArrayRef<Capture> Captures,
1389 bool ExplicitParams,
1390 bool ExplicitResultType,
1391 ArrayRef<Expr *> CaptureInits,
1392 ArrayRef<VarDecl *> ArrayIndexVars,
1393 ArrayRef<unsigned> ArrayIndexStarts,
1394 SourceLocation ClosingBrace,
1395 bool ContainsUnexpandedParameterPack);
1397 /// \brief Construct an empty lambda expression.
1398 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1399 : Expr(LambdaExprClass, Empty),
1400 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1401 ExplicitResultType(false), HasArrayIndexVars(true) {
1402 getStoredStmts()[NumCaptures] = nullptr;
1405 Stmt **getStoredStmts() const {
1406 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1409 /// \brief Retrieve the mapping from captures to the first array index
1411 unsigned *getArrayIndexStarts() const {
1412 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1415 /// \brief Retrieve the complete set of array-index variables.
1416 VarDecl **getArrayIndexVars() const {
1417 unsigned ArrayIndexSize = llvm::RoundUpToAlignment(
1418 sizeof(unsigned) * (NumCaptures + 1), llvm::alignOf<VarDecl *>());
1419 return reinterpret_cast<VarDecl **>(
1420 reinterpret_cast<char *>(getArrayIndexStarts()) + ArrayIndexSize);
1424 /// \brief Construct a new lambda expression.
1425 static LambdaExpr *Create(const ASTContext &C,
1426 CXXRecordDecl *Class,
1427 SourceRange IntroducerRange,
1428 LambdaCaptureDefault CaptureDefault,
1429 SourceLocation CaptureDefaultLoc,
1430 ArrayRef<Capture> Captures,
1431 bool ExplicitParams,
1432 bool ExplicitResultType,
1433 ArrayRef<Expr *> CaptureInits,
1434 ArrayRef<VarDecl *> ArrayIndexVars,
1435 ArrayRef<unsigned> ArrayIndexStarts,
1436 SourceLocation ClosingBrace,
1437 bool ContainsUnexpandedParameterPack);
1439 /// \brief Construct a new lambda expression that will be deserialized from
1440 /// an external source.
1441 static LambdaExpr *CreateDeserialized(const ASTContext &C,
1442 unsigned NumCaptures,
1443 unsigned NumArrayIndexVars);
1445 /// \brief Determine the default capture kind for this lambda.
1446 LambdaCaptureDefault getCaptureDefault() const {
1447 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1450 /// \brief Retrieve the location of this lambda's capture-default, if any.
1451 SourceLocation getCaptureDefaultLoc() const {
1452 return CaptureDefaultLoc;
1455 /// \brief Determine whether one of this lambda's captures is an init-capture.
1456 bool isInitCapture(const LambdaCapture *Capture) const;
1458 /// \brief An iterator that walks over the captures of the lambda,
1459 /// both implicit and explicit.
1460 typedef const Capture *capture_iterator;
1462 /// \brief An iterator over a range of lambda captures.
1463 typedef llvm::iterator_range<capture_iterator> capture_range;
1465 /// \brief Retrieve this lambda's captures.
1466 capture_range captures() const;
1468 /// \brief Retrieve an iterator pointing to the first lambda capture.
1469 capture_iterator capture_begin() const;
1471 /// \brief Retrieve an iterator pointing past the end of the
1472 /// sequence of lambda captures.
1473 capture_iterator capture_end() const;
1475 /// \brief Determine the number of captures in this lambda.
1476 unsigned capture_size() const { return NumCaptures; }
1478 /// \brief Retrieve this lambda's explicit captures.
1479 capture_range explicit_captures() const;
1481 /// \brief Retrieve an iterator pointing to the first explicit
1483 capture_iterator explicit_capture_begin() const;
1485 /// \brief Retrieve an iterator pointing past the end of the sequence of
1486 /// explicit lambda captures.
1487 capture_iterator explicit_capture_end() const;
1489 /// \brief Retrieve this lambda's implicit captures.
1490 capture_range implicit_captures() const;
1492 /// \brief Retrieve an iterator pointing to the first implicit
1494 capture_iterator implicit_capture_begin() const;
1496 /// \brief Retrieve an iterator pointing past the end of the sequence of
1497 /// implicit lambda captures.
1498 capture_iterator implicit_capture_end() const;
1500 /// \brief Iterator that walks over the capture initialization
1502 typedef Expr **capture_init_iterator;
1504 /// \brief Retrieve the initialization expressions for this lambda's captures.
1505 llvm::iterator_range<capture_init_iterator> capture_inits() const {
1506 return llvm::iterator_range<capture_init_iterator>(capture_init_begin(),
1507 capture_init_end());
1510 /// \brief Retrieve the first initialization argument for this
1511 /// lambda expression (which initializes the first capture field).
1512 capture_init_iterator capture_init_begin() const {
1513 return reinterpret_cast<Expr **>(getStoredStmts());
1516 /// \brief Retrieve the iterator pointing one past the last
1517 /// initialization argument for this lambda expression.
1518 capture_init_iterator capture_init_end() const {
1519 return capture_init_begin() + NumCaptures;
1522 /// \brief Retrieve the set of index variables used in the capture
1523 /// initializer of an array captured by copy.
1525 /// \param Iter The iterator that points at the capture initializer for
1526 /// which we are extracting the corresponding index variables.
1527 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1529 /// \brief Retrieve the source range covering the lambda introducer,
1530 /// which contains the explicit capture list surrounded by square
1531 /// brackets ([...]).
1532 SourceRange getIntroducerRange() const { return IntroducerRange; }
1534 /// \brief Retrieve the class that corresponds to the lambda.
1536 /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1537 /// captures in its fields and provides the various operations permitted
1538 /// on a lambda (copying, calling).
1539 CXXRecordDecl *getLambdaClass() const;
1541 /// \brief Retrieve the function call operator associated with this
1542 /// lambda expression.
1543 CXXMethodDecl *getCallOperator() const;
1545 /// \brief If this is a generic lambda expression, retrieve the template
1546 /// parameter list associated with it, or else return null.
1547 TemplateParameterList *getTemplateParameterList() const;
1549 /// \brief Whether this is a generic lambda.
1550 bool isGenericLambda() const { return getTemplateParameterList(); }
1552 /// \brief Retrieve the body of the lambda.
1553 CompoundStmt *getBody() const;
1555 /// \brief Determine whether the lambda is mutable, meaning that any
1556 /// captures values can be modified.
1557 bool isMutable() const;
1559 /// \brief Determine whether this lambda has an explicit parameter
1560 /// list vs. an implicit (empty) parameter list.
1561 bool hasExplicitParameters() const { return ExplicitParams; }
1563 /// \brief Whether this lambda had its result type explicitly specified.
1564 bool hasExplicitResultType() const { return ExplicitResultType; }
1566 static bool classof(const Stmt *T) {
1567 return T->getStmtClass() == LambdaExprClass;
1570 SourceLocation getLocStart() const LLVM_READONLY {
1571 return IntroducerRange.getBegin();
1573 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1575 child_range children() {
1576 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1579 friend class ASTStmtReader;
1580 friend class ASTStmtWriter;
1583 /// An expression "T()" which creates a value-initialized rvalue of type
1584 /// T, which is a non-class type. See (C++98 [5.2.3p2]).
1585 class CXXScalarValueInitExpr : public Expr {
1586 SourceLocation RParenLoc;
1587 TypeSourceInfo *TypeInfo;
1589 friend class ASTStmtReader;
1592 /// \brief Create an explicitly-written scalar-value initialization
1594 CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
1595 SourceLocation rParenLoc)
1596 : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1597 false, false, Type->isInstantiationDependentType(),
1598 Type->containsUnexpandedParameterPack()),
1599 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1601 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1602 : Expr(CXXScalarValueInitExprClass, Shell) { }
1604 TypeSourceInfo *getTypeSourceInfo() const {
1608 SourceLocation getRParenLoc() const { return RParenLoc; }
1610 SourceLocation getLocStart() const LLVM_READONLY;
1611 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1613 static bool classof(const Stmt *T) {
1614 return T->getStmtClass() == CXXScalarValueInitExprClass;
1618 child_range children() { return child_range(); }
1621 /// \brief Represents a new-expression for memory allocation and constructor
1622 /// calls, e.g: "new CXXNewExpr(foo)".
1623 class CXXNewExpr : public Expr {
1624 /// Contains an optional array size expression, an optional initialization
1625 /// expression, and any number of optional placement arguments, in that order.
1627 /// \brief Points to the allocation function used.
1628 FunctionDecl *OperatorNew;
1629 /// \brief Points to the deallocation function used in case of error. May be
1631 FunctionDecl *OperatorDelete;
1633 /// \brief The allocated type-source information, as written in the source.
1634 TypeSourceInfo *AllocatedTypeInfo;
1636 /// \brief If the allocated type was expressed as a parenthesized type-id,
1637 /// the source range covering the parenthesized type-id.
1638 SourceRange TypeIdParens;
1640 /// \brief Range of the entire new expression.
1643 /// \brief Source-range of a paren-delimited initializer.
1644 SourceRange DirectInitRange;
1646 /// Was the usage ::new, i.e. is the global new to be used?
1648 /// Do we allocate an array? If so, the first SubExpr is the size expression.
1650 /// If this is an array allocation, does the usual deallocation
1651 /// function for the allocated type want to know the allocated size?
1652 bool UsualArrayDeleteWantsSize : 1;
1653 /// The number of placement new arguments.
1654 unsigned NumPlacementArgs : 13;
1655 /// What kind of initializer do we have? Could be none, parens, or braces.
1656 /// In storage, we distinguish between "none, and no initializer expr", and
1657 /// "none, but an implicit initializer expr".
1658 unsigned StoredInitializationStyle : 2;
1660 friend class ASTStmtReader;
1661 friend class ASTStmtWriter;
1663 enum InitializationStyle {
1664 NoInit, ///< New-expression has no initializer as written.
1665 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1666 ListInit ///< New-expression has a C++11 list-initializer.
1669 CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1670 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1671 ArrayRef<Expr*> placementArgs,
1672 SourceRange typeIdParens, Expr *arraySize,
1673 InitializationStyle initializationStyle, Expr *initializer,
1674 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1675 SourceRange Range, SourceRange directInitRange);
1676 explicit CXXNewExpr(EmptyShell Shell)
1677 : Expr(CXXNewExprClass, Shell), SubExprs(nullptr) { }
1679 void AllocateArgsArray(const ASTContext &C, bool isArray,
1680 unsigned numPlaceArgs, bool hasInitializer);
1682 QualType getAllocatedType() const {
1683 assert(getType()->isPointerType());
1684 return getType()->getAs<PointerType>()->getPointeeType();
1687 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1688 return AllocatedTypeInfo;
1691 /// \brief True if the allocation result needs to be null-checked.
1693 /// C++11 [expr.new]p13:
1694 /// If the allocation function returns null, initialization shall
1695 /// not be done, the deallocation function shall not be called,
1696 /// and the value of the new-expression shall be null.
1699 /// If the allocation function is a reserved placement allocation
1700 /// function that returns null, the behavior is undefined.
1702 /// An allocation function is not allowed to return null unless it
1703 /// has a non-throwing exception-specification. The '03 rule is
1704 /// identical except that the definition of a non-throwing
1705 /// exception specification is just "is it throw()?".
1706 bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1708 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1709 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1710 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1711 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1713 bool isArray() const { return Array; }
1714 Expr *getArraySize() {
1715 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1717 const Expr *getArraySize() const {
1718 return Array ? cast<Expr>(SubExprs[0]) : nullptr;
1721 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1722 Expr **getPlacementArgs() {
1723 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1726 Expr *getPlacementArg(unsigned i) {
1727 assert(i < NumPlacementArgs && "Index out of range");
1728 return getPlacementArgs()[i];
1730 const Expr *getPlacementArg(unsigned i) const {
1731 assert(i < NumPlacementArgs && "Index out of range");
1732 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1735 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1736 SourceRange getTypeIdParens() const { return TypeIdParens; }
1738 bool isGlobalNew() const { return GlobalNew; }
1740 /// \brief Whether this new-expression has any initializer at all.
1741 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1743 /// \brief The kind of initializer this new-expression has.
1744 InitializationStyle getInitializationStyle() const {
1745 if (StoredInitializationStyle == 0)
1747 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1750 /// \brief The initializer of this new-expression.
1751 Expr *getInitializer() {
1752 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1754 const Expr *getInitializer() const {
1755 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : nullptr;
1758 /// \brief Returns the CXXConstructExpr from this new-expression, or null.
1759 const CXXConstructExpr* getConstructExpr() const {
1760 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1763 /// Answers whether the usual array deallocation function for the
1764 /// allocated type expects the size of the allocation as a
1766 bool doesUsualArrayDeleteWantSize() const {
1767 return UsualArrayDeleteWantsSize;
1770 typedef ExprIterator arg_iterator;
1771 typedef ConstExprIterator const_arg_iterator;
1773 arg_iterator placement_arg_begin() {
1774 return SubExprs + Array + hasInitializer();
1776 arg_iterator placement_arg_end() {
1777 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1779 const_arg_iterator placement_arg_begin() const {
1780 return SubExprs + Array + hasInitializer();
1782 const_arg_iterator placement_arg_end() const {
1783 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1786 typedef Stmt **raw_arg_iterator;
1787 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1788 raw_arg_iterator raw_arg_end() {
1789 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1791 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1792 const_arg_iterator raw_arg_end() const {
1793 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1796 SourceLocation getStartLoc() const { return Range.getBegin(); }
1797 SourceLocation getEndLoc() const { return Range.getEnd(); }
1799 SourceRange getDirectInitRange() const { return DirectInitRange; }
1801 SourceRange getSourceRange() const LLVM_READONLY {
1804 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
1805 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1807 static bool classof(const Stmt *T) {
1808 return T->getStmtClass() == CXXNewExprClass;
1812 child_range children() {
1813 return child_range(raw_arg_begin(), raw_arg_end());
1817 /// \brief Represents a \c delete expression for memory deallocation and
1818 /// destructor calls, e.g. "delete[] pArray".
1819 class CXXDeleteExpr : public Expr {
1820 /// Points to the operator delete overload that is used. Could be a member.
1821 FunctionDecl *OperatorDelete;
1822 /// The pointer expression to be deleted.
1824 /// Location of the expression.
1826 /// Is this a forced global delete, i.e. "::delete"?
1827 bool GlobalDelete : 1;
1828 /// Is this the array form of delete, i.e. "delete[]"?
1830 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1831 /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1833 bool ArrayFormAsWritten : 1;
1834 /// Does the usual deallocation function for the element type require
1835 /// a size_t argument?
1836 bool UsualArrayDeleteWantsSize : 1;
1838 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1839 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1840 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1841 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1842 arg->isInstantiationDependent(),
1843 arg->containsUnexpandedParameterPack()),
1844 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1845 GlobalDelete(globalDelete),
1846 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1847 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
1848 explicit CXXDeleteExpr(EmptyShell Shell)
1849 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(nullptr),
1850 Argument(nullptr) {}
1852 bool isGlobalDelete() const { return GlobalDelete; }
1853 bool isArrayForm() const { return ArrayForm; }
1854 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1856 /// Answers whether the usual array deallocation function for the
1857 /// allocated type expects the size of the allocation as a
1858 /// parameter. This can be true even if the actual deallocation
1859 /// function that we're using doesn't want a size.
1860 bool doesUsualArrayDeleteWantSize() const {
1861 return UsualArrayDeleteWantsSize;
1864 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1866 Expr *getArgument() { return cast<Expr>(Argument); }
1867 const Expr *getArgument() const { return cast<Expr>(Argument); }
1869 /// \brief Retrieve the type being destroyed.
1871 /// If the type being destroyed is a dependent type which may or may not
1872 /// be a pointer, return an invalid type.
1873 QualType getDestroyedType() const;
1875 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1876 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
1878 static bool classof(const Stmt *T) {
1879 return T->getStmtClass() == CXXDeleteExprClass;
1883 child_range children() { return child_range(&Argument, &Argument+1); }
1885 friend class ASTStmtReader;
1888 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
1889 class PseudoDestructorTypeStorage {
1890 /// \brief Either the type source information or the name of the type, if
1891 /// it couldn't be resolved due to type-dependence.
1892 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1894 /// \brief The starting source location of the pseudo-destructor type.
1895 SourceLocation Location;
1898 PseudoDestructorTypeStorage() { }
1900 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1901 : Type(II), Location(Loc) { }
1903 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1905 TypeSourceInfo *getTypeSourceInfo() const {
1906 return Type.dyn_cast<TypeSourceInfo *>();
1909 IdentifierInfo *getIdentifier() const {
1910 return Type.dyn_cast<IdentifierInfo *>();
1913 SourceLocation getLocation() const { return Location; }
1916 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1918 /// A pseudo-destructor is an expression that looks like a member access to a
1919 /// destructor of a scalar type, except that scalar types don't have
1920 /// destructors. For example:
1924 /// void f(int *p) {
1929 /// Pseudo-destructors typically occur when instantiating templates such as:
1932 /// template<typename T>
1933 /// void destroy(T* ptr) {
1938 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1939 /// beyond evaluating the base expression.
1940 class CXXPseudoDestructorExpr : public Expr {
1941 /// \brief The base expression (that is being destroyed).
1944 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1948 /// \brief The location of the '.' or '->' operator.
1949 SourceLocation OperatorLoc;
1951 /// \brief The nested-name-specifier that follows the operator, if present.
1952 NestedNameSpecifierLoc QualifierLoc;
1954 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1956 TypeSourceInfo *ScopeType;
1958 /// \brief The location of the '::' in a qualified pseudo-destructor
1960 SourceLocation ColonColonLoc;
1962 /// \brief The location of the '~'.
1963 SourceLocation TildeLoc;
1965 /// \brief The type being destroyed, or its name if we were unable to
1966 /// resolve the name.
1967 PseudoDestructorTypeStorage DestroyedType;
1969 friend class ASTStmtReader;
1972 CXXPseudoDestructorExpr(const ASTContext &Context,
1973 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1974 NestedNameSpecifierLoc QualifierLoc,
1975 TypeSourceInfo *ScopeType,
1976 SourceLocation ColonColonLoc,
1977 SourceLocation TildeLoc,
1978 PseudoDestructorTypeStorage DestroyedType);
1980 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1981 : Expr(CXXPseudoDestructorExprClass, Shell),
1982 Base(nullptr), IsArrow(false), QualifierLoc(), ScopeType(nullptr) { }
1984 Expr *getBase() const { return cast<Expr>(Base); }
1986 /// \brief Determines whether this member expression actually had
1987 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1989 bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
1991 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1992 /// with source-location information.
1993 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1995 /// \brief If the member name was qualified, retrieves the
1996 /// nested-name-specifier that precedes the member name. Otherwise, returns
1998 NestedNameSpecifier *getQualifier() const {
1999 return QualifierLoc.getNestedNameSpecifier();
2002 /// \brief Determine whether this pseudo-destructor expression was written
2003 /// using an '->' (otherwise, it used a '.').
2004 bool isArrow() const { return IsArrow; }
2006 /// \brief Retrieve the location of the '.' or '->' operator.
2007 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2009 /// \brief Retrieve the scope type in a qualified pseudo-destructor
2012 /// Pseudo-destructor expressions can have extra qualification within them
2013 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2014 /// Here, if the object type of the expression is (or may be) a scalar type,
2015 /// \p T may also be a scalar type and, therefore, cannot be part of a
2016 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2017 /// destructor expression.
2018 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2020 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2022 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2024 /// \brief Retrieve the location of the '~'.
2025 SourceLocation getTildeLoc() const { return TildeLoc; }
2027 /// \brief Retrieve the source location information for the type
2028 /// being destroyed.
2030 /// This type-source information is available for non-dependent
2031 /// pseudo-destructor expressions and some dependent pseudo-destructor
2032 /// expressions. Returns null if we only have the identifier for a
2033 /// dependent pseudo-destructor expression.
2034 TypeSourceInfo *getDestroyedTypeInfo() const {
2035 return DestroyedType.getTypeSourceInfo();
2038 /// \brief In a dependent pseudo-destructor expression for which we do not
2039 /// have full type information on the destroyed type, provides the name
2040 /// of the destroyed type.
2041 IdentifierInfo *getDestroyedTypeIdentifier() const {
2042 return DestroyedType.getIdentifier();
2045 /// \brief Retrieve the type being destroyed.
2046 QualType getDestroyedType() const;
2048 /// \brief Retrieve the starting location of the type being destroyed.
2049 SourceLocation getDestroyedTypeLoc() const {
2050 return DestroyedType.getLocation();
2053 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2055 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2056 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2059 /// \brief Set the destroyed type.
2060 void setDestroyedType(TypeSourceInfo *Info) {
2061 DestroyedType = PseudoDestructorTypeStorage(Info);
2064 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2065 SourceLocation getLocEnd() const LLVM_READONLY;
2067 static bool classof(const Stmt *T) {
2068 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2072 child_range children() { return child_range(&Base, &Base + 1); }
2075 /// \brief A type trait used in the implementation of various C++11 and
2076 /// Library TR1 trait templates.
2079 /// __is_pod(int) == true
2080 /// __is_enum(std::string) == false
2081 /// __is_trivially_constructible(vector<int>, int*, int*)
2083 class TypeTraitExpr : public Expr {
2084 /// \brief The location of the type trait keyword.
2087 /// \brief The location of the closing parenthesis.
2088 SourceLocation RParenLoc;
2090 // Note: The TypeSourceInfos for the arguments are allocated after the
2093 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2094 ArrayRef<TypeSourceInfo *> Args,
2095 SourceLocation RParenLoc,
2098 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2100 /// \brief Retrieve the argument types.
2101 TypeSourceInfo **getTypeSourceInfos() {
2102 return reinterpret_cast<TypeSourceInfo **>(this+1);
2105 /// \brief Retrieve the argument types.
2106 TypeSourceInfo * const *getTypeSourceInfos() const {
2107 return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2111 /// \brief Create a new type trait expression.
2112 static TypeTraitExpr *Create(const ASTContext &C, QualType T,
2113 SourceLocation Loc, TypeTrait Kind,
2114 ArrayRef<TypeSourceInfo *> Args,
2115 SourceLocation RParenLoc,
2118 static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
2121 /// \brief Determine which type trait this expression uses.
2122 TypeTrait getTrait() const {
2123 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2126 bool getValue() const {
2127 assert(!isValueDependent());
2128 return TypeTraitExprBits.Value;
2131 /// \brief Determine the number of arguments to this type trait.
2132 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2134 /// \brief Retrieve the Ith argument.
2135 TypeSourceInfo *getArg(unsigned I) const {
2136 assert(I < getNumArgs() && "Argument out-of-range");
2137 return getArgs()[I];
2140 /// \brief Retrieve the argument types.
2141 ArrayRef<TypeSourceInfo *> getArgs() const {
2142 return llvm::makeArrayRef(getTypeSourceInfos(), getNumArgs());
2145 typedef TypeSourceInfo **arg_iterator;
2146 arg_iterator arg_begin() {
2147 return getTypeSourceInfos();
2149 arg_iterator arg_end() {
2150 return getTypeSourceInfos() + getNumArgs();
2153 typedef TypeSourceInfo const * const *arg_const_iterator;
2154 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
2155 arg_const_iterator arg_end() const {
2156 return getTypeSourceInfos() + getNumArgs();
2159 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2160 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2162 static bool classof(const Stmt *T) {
2163 return T->getStmtClass() == TypeTraitExprClass;
2167 child_range children() { return child_range(); }
2169 friend class ASTStmtReader;
2170 friend class ASTStmtWriter;
2174 /// \brief An Embarcadero array type trait, as used in the implementation of
2175 /// __array_rank and __array_extent.
2179 /// __array_rank(int[10][20]) == 2
2180 /// __array_extent(int, 1) == 20
2182 class ArrayTypeTraitExpr : public Expr {
2183 virtual void anchor();
2185 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2188 /// \brief The value of the type trait. Unspecified if dependent.
2191 /// \brief The array dimension being queried, or -1 if not used.
2194 /// \brief The location of the type trait keyword.
2197 /// \brief The location of the closing paren.
2198 SourceLocation RParen;
2200 /// \brief The type being queried.
2201 TypeSourceInfo *QueriedType;
2204 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2205 TypeSourceInfo *queried, uint64_t value,
2206 Expr *dimension, SourceLocation rparen, QualType ty)
2207 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2208 false, queried->getType()->isDependentType(),
2209 (queried->getType()->isInstantiationDependentType() ||
2210 (dimension && dimension->isInstantiationDependent())),
2211 queried->getType()->containsUnexpandedParameterPack()),
2212 ATT(att), Value(value), Dimension(dimension),
2213 Loc(loc), RParen(rparen), QueriedType(queried) { }
2216 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2217 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2220 virtual ~ArrayTypeTraitExpr() { }
2222 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2223 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2225 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2227 QualType getQueriedType() const { return QueriedType->getType(); }
2229 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2231 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2233 Expr *getDimensionExpression() const { return Dimension; }
2235 static bool classof(const Stmt *T) {
2236 return T->getStmtClass() == ArrayTypeTraitExprClass;
2240 child_range children() { return child_range(); }
2242 friend class ASTStmtReader;
2245 /// \brief An expression trait intrinsic.
2249 /// __is_lvalue_expr(std::cout) == true
2250 /// __is_lvalue_expr(1) == false
2252 class ExpressionTraitExpr : public Expr {
2253 /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2255 /// \brief The value of the type trait. Unspecified if dependent.
2258 /// \brief The location of the type trait keyword.
2261 /// \brief The location of the closing paren.
2262 SourceLocation RParen;
2264 /// \brief The expression being queried.
2265 Expr* QueriedExpression;
2267 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2268 Expr *queried, bool value,
2269 SourceLocation rparen, QualType resultType)
2270 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2271 false, // Not type-dependent
2272 // Value-dependent if the argument is type-dependent.
2273 queried->isTypeDependent(),
2274 queried->isInstantiationDependent(),
2275 queried->containsUnexpandedParameterPack()),
2276 ET(et), Value(value), Loc(loc), RParen(rparen),
2277 QueriedExpression(queried) { }
2279 explicit ExpressionTraitExpr(EmptyShell Empty)
2280 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2281 QueriedExpression() { }
2283 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2284 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2286 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2288 Expr *getQueriedExpression() const { return QueriedExpression; }
2290 bool getValue() const { return Value; }
2292 static bool classof(const Stmt *T) {
2293 return T->getStmtClass() == ExpressionTraitExprClass;
2297 child_range children() { return child_range(); }
2299 friend class ASTStmtReader;
2303 /// \brief A reference to an overloaded function set, either an
2304 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2305 class OverloadExpr : public Expr {
2306 /// \brief The common name of these declarations.
2307 DeclarationNameInfo NameInfo;
2309 /// \brief The nested-name-specifier that qualifies the name, if any.
2310 NestedNameSpecifierLoc QualifierLoc;
2312 /// The results. These are undesugared, which is to say, they may
2313 /// include UsingShadowDecls. Access is relative to the naming
2315 // FIXME: Allocate this data after the OverloadExpr subclass.
2316 DeclAccessPair *Results;
2317 unsigned NumResults;
2320 /// \brief Whether the name includes info for explicit template
2321 /// keyword and arguments.
2322 bool HasTemplateKWAndArgsInfo;
2324 /// \brief Return the optional template keyword and arguments info.
2325 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2327 /// \brief Return the optional template keyword and arguments info.
2328 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2329 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2332 OverloadExpr(StmtClass K, const ASTContext &C,
2333 NestedNameSpecifierLoc QualifierLoc,
2334 SourceLocation TemplateKWLoc,
2335 const DeclarationNameInfo &NameInfo,
2336 const TemplateArgumentListInfo *TemplateArgs,
2337 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2338 bool KnownDependent,
2339 bool KnownInstantiationDependent,
2340 bool KnownContainsUnexpandedParameterPack);
2342 OverloadExpr(StmtClass K, EmptyShell Empty)
2343 : Expr(K, Empty), QualifierLoc(), Results(nullptr), NumResults(0),
2344 HasTemplateKWAndArgsInfo(false) { }
2346 void initializeResults(const ASTContext &C,
2347 UnresolvedSetIterator Begin,
2348 UnresolvedSetIterator End);
2352 OverloadExpr *Expression;
2353 bool IsAddressOfOperand;
2354 bool HasFormOfMemberPointer;
2357 /// \brief Finds the overloaded expression in the given expression \p E of
2360 /// \return the expression (which must be there) and true if it has
2361 /// the particular form of a member pointer expression
2362 static FindResult find(Expr *E) {
2363 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2367 E = E->IgnoreParens();
2368 if (isa<UnaryOperator>(E)) {
2369 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2370 E = cast<UnaryOperator>(E)->getSubExpr();
2371 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2373 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2374 Result.IsAddressOfOperand = true;
2375 Result.Expression = Ovl;
2377 Result.HasFormOfMemberPointer = false;
2378 Result.IsAddressOfOperand = false;
2379 Result.Expression = cast<OverloadExpr>(E);
2385 /// \brief Gets the naming class of this lookup, if any.
2386 CXXRecordDecl *getNamingClass() const;
2388 typedef UnresolvedSetImpl::iterator decls_iterator;
2389 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2390 decls_iterator decls_end() const {
2391 return UnresolvedSetIterator(Results + NumResults);
2393 llvm::iterator_range<decls_iterator> decls() const {
2394 return llvm::iterator_range<decls_iterator>(decls_begin(), decls_end());
2397 /// \brief Gets the number of declarations in the unresolved set.
2398 unsigned getNumDecls() const { return NumResults; }
2400 /// \brief Gets the full name info.
2401 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2403 /// \brief Gets the name looked up.
2404 DeclarationName getName() const { return NameInfo.getName(); }
2406 /// \brief Gets the location of the name.
2407 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2409 /// \brief Fetches the nested-name qualifier, if one was given.
2410 NestedNameSpecifier *getQualifier() const {
2411 return QualifierLoc.getNestedNameSpecifier();
2414 /// \brief Fetches the nested-name qualifier with source-location
2415 /// information, if one was given.
2416 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2418 /// \brief Retrieve the location of the template keyword preceding
2419 /// this name, if any.
2420 SourceLocation getTemplateKeywordLoc() const {
2421 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2422 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2425 /// \brief Retrieve the location of the left angle bracket starting the
2426 /// explicit template argument list following the name, if any.
2427 SourceLocation getLAngleLoc() const {
2428 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2429 return getTemplateKWAndArgsInfo()->LAngleLoc;
2432 /// \brief Retrieve the location of the right angle bracket ending the
2433 /// explicit template argument list following the name, if any.
2434 SourceLocation getRAngleLoc() const {
2435 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2436 return getTemplateKWAndArgsInfo()->RAngleLoc;
2439 /// \brief Determines whether the name was preceded by the template keyword.
2440 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2442 /// \brief Determines whether this expression had explicit template arguments.
2443 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2445 // Note that, inconsistently with the explicit-template-argument AST
2446 // nodes, users are *forbidden* from calling these methods on objects
2447 // without explicit template arguments.
2449 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2450 assert(hasExplicitTemplateArgs());
2451 return *getTemplateKWAndArgsInfo();
2454 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2455 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2458 TemplateArgumentLoc const *getTemplateArgs() const {
2459 return getExplicitTemplateArgs().getTemplateArgs();
2462 unsigned getNumTemplateArgs() const {
2463 return getExplicitTemplateArgs().NumTemplateArgs;
2466 /// \brief Copies the template arguments into the given structure.
2467 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2468 getExplicitTemplateArgs().copyInto(List);
2471 /// \brief Retrieves the optional explicit template arguments.
2473 /// This points to the same data as getExplicitTemplateArgs(), but
2474 /// returns null if there are no explicit template arguments.
2475 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2476 if (!hasExplicitTemplateArgs()) return nullptr;
2477 return &getExplicitTemplateArgs();
2480 static bool classof(const Stmt *T) {
2481 return T->getStmtClass() == UnresolvedLookupExprClass ||
2482 T->getStmtClass() == UnresolvedMemberExprClass;
2485 friend class ASTStmtReader;
2486 friend class ASTStmtWriter;
2489 /// \brief A reference to a name which we were able to look up during
2490 /// parsing but could not resolve to a specific declaration.
2492 /// This arises in several ways:
2493 /// * we might be waiting for argument-dependent lookup;
2494 /// * the name might resolve to an overloaded function;
2496 /// * the lookup might have included a function template.
2498 /// These never include UnresolvedUsingValueDecls, which are always class
2499 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2500 class UnresolvedLookupExpr : public OverloadExpr {
2501 /// True if these lookup results should be extended by
2502 /// argument-dependent lookup if this is the operand of a function
2506 /// True if these lookup results are overloaded. This is pretty
2507 /// trivially rederivable if we urgently need to kill this field.
2510 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2511 /// any. This can generally be recalculated from the context chain,
2512 /// but that can be fairly expensive for unqualified lookups. If we
2513 /// want to improve memory use here, this could go in a union
2514 /// against the qualified-lookup bits.
2515 CXXRecordDecl *NamingClass;
2517 UnresolvedLookupExpr(const ASTContext &C,
2518 CXXRecordDecl *NamingClass,
2519 NestedNameSpecifierLoc QualifierLoc,
2520 SourceLocation TemplateKWLoc,
2521 const DeclarationNameInfo &NameInfo,
2522 bool RequiresADL, bool Overloaded,
2523 const TemplateArgumentListInfo *TemplateArgs,
2524 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2525 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2526 NameInfo, TemplateArgs, Begin, End, false, false, false),
2527 RequiresADL(RequiresADL),
2528 Overloaded(Overloaded), NamingClass(NamingClass)
2531 UnresolvedLookupExpr(EmptyShell Empty)
2532 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2533 RequiresADL(false), Overloaded(false), NamingClass(nullptr)
2536 friend class ASTStmtReader;
2539 static UnresolvedLookupExpr *Create(const ASTContext &C,
2540 CXXRecordDecl *NamingClass,
2541 NestedNameSpecifierLoc QualifierLoc,
2542 const DeclarationNameInfo &NameInfo,
2543 bool ADL, bool Overloaded,
2544 UnresolvedSetIterator Begin,
2545 UnresolvedSetIterator End) {
2546 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2547 SourceLocation(), NameInfo,
2548 ADL, Overloaded, nullptr, Begin, End);
2551 static UnresolvedLookupExpr *Create(const ASTContext &C,
2552 CXXRecordDecl *NamingClass,
2553 NestedNameSpecifierLoc QualifierLoc,
2554 SourceLocation TemplateKWLoc,
2555 const DeclarationNameInfo &NameInfo,
2557 const TemplateArgumentListInfo *Args,
2558 UnresolvedSetIterator Begin,
2559 UnresolvedSetIterator End);
2561 static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2562 bool HasTemplateKWAndArgsInfo,
2563 unsigned NumTemplateArgs);
2565 /// True if this declaration should be extended by
2566 /// argument-dependent lookup.
2567 bool requiresADL() const { return RequiresADL; }
2569 /// True if this lookup is overloaded.
2570 bool isOverloaded() const { return Overloaded; }
2572 /// Gets the 'naming class' (in the sense of C++0x
2573 /// [class.access.base]p5) of the lookup. This is the scope
2574 /// that was looked in to find these results.
2575 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2577 SourceLocation getLocStart() const LLVM_READONLY {
2578 if (NestedNameSpecifierLoc l = getQualifierLoc())
2579 return l.getBeginLoc();
2580 return getNameInfo().getLocStart();
2582 SourceLocation getLocEnd() const LLVM_READONLY {
2583 if (hasExplicitTemplateArgs())
2584 return getRAngleLoc();
2585 return getNameInfo().getLocEnd();
2588 child_range children() { return child_range(); }
2590 static bool classof(const Stmt *T) {
2591 return T->getStmtClass() == UnresolvedLookupExprClass;
2595 /// \brief A qualified reference to a name whose declaration cannot
2596 /// yet be resolved.
2598 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2599 /// it expresses a reference to a declaration such as
2600 /// X<T>::value. The difference, however, is that an
2601 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2602 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2603 /// this case, X<T>::value cannot resolve to a declaration because the
2604 /// declaration will differ from one instantiation of X<T> to the
2605 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2606 /// qualifier (X<T>::) and the name of the entity being referenced
2607 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2608 /// declaration can be found.
2609 class DependentScopeDeclRefExpr : public Expr {
2610 /// \brief The nested-name-specifier that qualifies this unresolved
2611 /// declaration name.
2612 NestedNameSpecifierLoc QualifierLoc;
2614 /// \brief The name of the entity we will be referencing.
2615 DeclarationNameInfo NameInfo;
2617 /// \brief Whether the name includes info for explicit template
2618 /// keyword and arguments.
2619 bool HasTemplateKWAndArgsInfo;
2621 /// \brief Return the optional template keyword and arguments info.
2622 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2623 if (!HasTemplateKWAndArgsInfo) return nullptr;
2624 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2626 /// \brief Return the optional template keyword and arguments info.
2627 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2628 return const_cast<DependentScopeDeclRefExpr*>(this)
2629 ->getTemplateKWAndArgsInfo();
2632 DependentScopeDeclRefExpr(QualType T,
2633 NestedNameSpecifierLoc QualifierLoc,
2634 SourceLocation TemplateKWLoc,
2635 const DeclarationNameInfo &NameInfo,
2636 const TemplateArgumentListInfo *Args);
2639 static DependentScopeDeclRefExpr *Create(const ASTContext &C,
2640 NestedNameSpecifierLoc QualifierLoc,
2641 SourceLocation TemplateKWLoc,
2642 const DeclarationNameInfo &NameInfo,
2643 const TemplateArgumentListInfo *TemplateArgs);
2645 static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2646 bool HasTemplateKWAndArgsInfo,
2647 unsigned NumTemplateArgs);
2649 /// \brief Retrieve the name that this expression refers to.
2650 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2652 /// \brief Retrieve the name that this expression refers to.
2653 DeclarationName getDeclName() const { return NameInfo.getName(); }
2655 /// \brief Retrieve the location of the name within the expression.
2657 /// For example, in "X<T>::value" this is the location of "value".
2658 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2660 /// \brief Retrieve the nested-name-specifier that qualifies the
2661 /// name, with source location information.
2662 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2664 /// \brief Retrieve the nested-name-specifier that qualifies this
2666 NestedNameSpecifier *getQualifier() const {
2667 return QualifierLoc.getNestedNameSpecifier();
2670 /// \brief Retrieve the location of the template keyword preceding
2671 /// this name, if any.
2672 SourceLocation getTemplateKeywordLoc() const {
2673 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2674 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2677 /// \brief Retrieve the location of the left angle bracket starting the
2678 /// explicit template argument list following the name, if any.
2679 SourceLocation getLAngleLoc() const {
2680 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2681 return getTemplateKWAndArgsInfo()->LAngleLoc;
2684 /// \brief Retrieve the location of the right angle bracket ending the
2685 /// explicit template argument list following the name, if any.
2686 SourceLocation getRAngleLoc() const {
2687 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2688 return getTemplateKWAndArgsInfo()->RAngleLoc;
2691 /// Determines whether the name was preceded by the template keyword.
2692 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2694 /// Determines whether this lookup had explicit template arguments.
2695 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2697 // Note that, inconsistently with the explicit-template-argument AST
2698 // nodes, users are *forbidden* from calling these methods on objects
2699 // without explicit template arguments.
2701 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2702 assert(hasExplicitTemplateArgs());
2703 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2706 /// Gets a reference to the explicit template argument list.
2707 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2708 assert(hasExplicitTemplateArgs());
2709 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2712 /// \brief Retrieves the optional explicit template arguments.
2714 /// This points to the same data as getExplicitTemplateArgs(), but
2715 /// returns null if there are no explicit template arguments.
2716 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2717 if (!hasExplicitTemplateArgs()) return nullptr;
2718 return &getExplicitTemplateArgs();
2721 /// \brief Copies the template arguments (if present) into the given
2723 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2724 getExplicitTemplateArgs().copyInto(List);
2727 TemplateArgumentLoc const *getTemplateArgs() const {
2728 return getExplicitTemplateArgs().getTemplateArgs();
2731 unsigned getNumTemplateArgs() const {
2732 return getExplicitTemplateArgs().NumTemplateArgs;
2735 /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
2736 /// and differs from getLocation().getStart().
2737 SourceLocation getLocStart() const LLVM_READONLY {
2738 return QualifierLoc.getBeginLoc();
2740 SourceLocation getLocEnd() const LLVM_READONLY {
2741 if (hasExplicitTemplateArgs())
2742 return getRAngleLoc();
2743 return getLocation();
2746 static bool classof(const Stmt *T) {
2747 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2750 child_range children() { return child_range(); }
2752 friend class ASTStmtReader;
2753 friend class ASTStmtWriter;
2756 /// Represents an expression -- generally a full-expression -- that
2757 /// introduces cleanups to be run at the end of the sub-expression's
2758 /// evaluation. The most common source of expression-introduced
2759 /// cleanups is temporary objects in C++, but several other kinds of
2760 /// expressions can create cleanups, including basically every
2761 /// call in ARC that returns an Objective-C pointer.
2763 /// This expression also tracks whether the sub-expression contains a
2764 /// potentially-evaluated block literal. The lifetime of a block
2765 /// literal is the extent of the enclosing scope.
2766 class ExprWithCleanups : public Expr {
2768 /// The type of objects that are kept in the cleanup.
2769 /// It's useful to remember the set of blocks; we could also
2770 /// remember the set of temporaries, but there's currently
2772 typedef BlockDecl *CleanupObject;
2777 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2778 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2780 CleanupObject *getObjectsBuffer() {
2781 return reinterpret_cast<CleanupObject*>(this + 1);
2783 const CleanupObject *getObjectsBuffer() const {
2784 return reinterpret_cast<const CleanupObject*>(this + 1);
2786 friend class ASTStmtReader;
2789 static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
2790 unsigned numObjects);
2792 static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
2793 ArrayRef<CleanupObject> objects);
2795 ArrayRef<CleanupObject> getObjects() const {
2796 return llvm::makeArrayRef(getObjectsBuffer(), getNumObjects());
2799 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2801 CleanupObject getObject(unsigned i) const {
2802 assert(i < getNumObjects() && "Index out of range");
2803 return getObjects()[i];
2806 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2807 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2809 /// As with any mutator of the AST, be very careful
2810 /// when modifying an existing AST to preserve its invariants.
2811 void setSubExpr(Expr *E) { SubExpr = E; }
2813 SourceLocation getLocStart() const LLVM_READONLY {
2814 return SubExpr->getLocStart();
2816 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2818 // Implement isa/cast/dyncast/etc.
2819 static bool classof(const Stmt *T) {
2820 return T->getStmtClass() == ExprWithCleanupsClass;
2824 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2827 /// \brief Describes an explicit type conversion that uses functional
2828 /// notion but could not be resolved because one or more arguments are
2831 /// The explicit type conversions expressed by
2832 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2833 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2834 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2835 /// type-dependent. For example, this would occur in a template such
2839 /// template<typename T, typename A1>
2840 /// inline T make_a(const A1& a1) {
2845 /// When the returned expression is instantiated, it may resolve to a
2846 /// constructor call, conversion function call, or some kind of type
2848 class CXXUnresolvedConstructExpr : public Expr {
2849 /// \brief The type being constructed.
2850 TypeSourceInfo *Type;
2852 /// \brief The location of the left parentheses ('(').
2853 SourceLocation LParenLoc;
2855 /// \brief The location of the right parentheses (')').
2856 SourceLocation RParenLoc;
2858 /// \brief The number of arguments used to construct the type.
2861 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2862 SourceLocation LParenLoc,
2863 ArrayRef<Expr*> Args,
2864 SourceLocation RParenLoc);
2866 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2867 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2869 friend class ASTStmtReader;
2872 static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
2873 TypeSourceInfo *Type,
2874 SourceLocation LParenLoc,
2875 ArrayRef<Expr*> Args,
2876 SourceLocation RParenLoc);
2878 static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
2881 /// \brief Retrieve the type that is being constructed, as specified
2882 /// in the source code.
2883 QualType getTypeAsWritten() const { return Type->getType(); }
2885 /// \brief Retrieve the type source information for the type being
2887 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2889 /// \brief Retrieve the location of the left parentheses ('(') that
2890 /// precedes the argument list.
2891 SourceLocation getLParenLoc() const { return LParenLoc; }
2892 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2894 /// \brief Retrieve the location of the right parentheses (')') that
2895 /// follows the argument list.
2896 SourceLocation getRParenLoc() const { return RParenLoc; }
2897 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2899 /// \brief Retrieve the number of arguments.
2900 unsigned arg_size() const { return NumArgs; }
2902 typedef Expr** arg_iterator;
2903 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2904 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2906 typedef const Expr* const * const_arg_iterator;
2907 const_arg_iterator arg_begin() const {
2908 return reinterpret_cast<const Expr* const *>(this + 1);
2910 const_arg_iterator arg_end() const {
2911 return arg_begin() + NumArgs;
2914 Expr *getArg(unsigned I) {
2915 assert(I < NumArgs && "Argument index out-of-range");
2916 return *(arg_begin() + I);
2919 const Expr *getArg(unsigned I) const {
2920 assert(I < NumArgs && "Argument index out-of-range");
2921 return *(arg_begin() + I);
2924 void setArg(unsigned I, Expr *E) {
2925 assert(I < NumArgs && "Argument index out-of-range");
2926 *(arg_begin() + I) = E;
2929 SourceLocation getLocStart() const LLVM_READONLY;
2930 SourceLocation getLocEnd() const LLVM_READONLY {
2931 if (!RParenLoc.isValid() && NumArgs > 0)
2932 return getArg(NumArgs - 1)->getLocEnd();
2936 static bool classof(const Stmt *T) {
2937 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2941 child_range children() {
2942 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2943 return child_range(begin, begin + NumArgs);
2947 /// \brief Represents a C++ member access expression where the actual
2948 /// member referenced could not be resolved because the base
2949 /// expression or the member name was dependent.
2951 /// Like UnresolvedMemberExprs, these can be either implicit or
2952 /// explicit accesses. It is only possible to get one of these with
2953 /// an implicit access if a qualifier is provided.
2954 class CXXDependentScopeMemberExpr : public Expr {
2955 /// \brief The expression for the base pointer or class reference,
2956 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2959 /// \brief The type of the base expression. Never null, even for
2960 /// implicit accesses.
2963 /// \brief Whether this member expression used the '->' operator or
2964 /// the '.' operator.
2967 /// \brief Whether this member expression has info for explicit template
2968 /// keyword and arguments.
2969 bool HasTemplateKWAndArgsInfo : 1;
2971 /// \brief The location of the '->' or '.' operator.
2972 SourceLocation OperatorLoc;
2974 /// \brief The nested-name-specifier that precedes the member name, if any.
2975 NestedNameSpecifierLoc QualifierLoc;
2977 /// \brief In a qualified member access expression such as t->Base::f, this
2978 /// member stores the resolves of name lookup in the context of the member
2979 /// access expression, to be used at instantiation time.
2981 /// FIXME: This member, along with the QualifierLoc, could
2982 /// be stuck into a structure that is optionally allocated at the end of
2983 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2984 NamedDecl *FirstQualifierFoundInScope;
2986 /// \brief The member to which this member expression refers, which
2987 /// can be name, overloaded operator, or destructor.
2989 /// FIXME: could also be a template-id
2990 DeclarationNameInfo MemberNameInfo;
2992 /// \brief Return the optional template keyword and arguments info.
2993 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2994 if (!HasTemplateKWAndArgsInfo) return nullptr;
2995 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2997 /// \brief Return the optional template keyword and arguments info.
2998 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2999 return const_cast<CXXDependentScopeMemberExpr*>(this)
3000 ->getTemplateKWAndArgsInfo();
3003 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3004 QualType BaseType, bool IsArrow,
3005 SourceLocation OperatorLoc,
3006 NestedNameSpecifierLoc QualifierLoc,
3007 SourceLocation TemplateKWLoc,
3008 NamedDecl *FirstQualifierFoundInScope,
3009 DeclarationNameInfo MemberNameInfo,
3010 const TemplateArgumentListInfo *TemplateArgs);
3013 CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
3014 QualType BaseType, bool IsArrow,
3015 SourceLocation OperatorLoc,
3016 NestedNameSpecifierLoc QualifierLoc,
3017 NamedDecl *FirstQualifierFoundInScope,
3018 DeclarationNameInfo MemberNameInfo);
3020 static CXXDependentScopeMemberExpr *
3021 Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
3022 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
3023 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
3024 DeclarationNameInfo MemberNameInfo,
3025 const TemplateArgumentListInfo *TemplateArgs);
3027 static CXXDependentScopeMemberExpr *
3028 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3029 unsigned NumTemplateArgs);
3031 /// \brief True if this is an implicit access, i.e. one in which the
3032 /// member being accessed was not written in the source. The source
3033 /// location of the operator is invalid in this case.
3034 bool isImplicitAccess() const;
3036 /// \brief Retrieve the base object of this member expressions,
3037 /// e.g., the \c x in \c x.m.
3038 Expr *getBase() const {
3039 assert(!isImplicitAccess());
3040 return cast<Expr>(Base);
3043 QualType getBaseType() const { return BaseType; }
3045 /// \brief Determine whether this member expression used the '->'
3046 /// operator; otherwise, it used the '.' operator.
3047 bool isArrow() const { return IsArrow; }
3049 /// \brief Retrieve the location of the '->' or '.' operator.
3050 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3052 /// \brief Retrieve the nested-name-specifier that qualifies the member
3054 NestedNameSpecifier *getQualifier() const {
3055 return QualifierLoc.getNestedNameSpecifier();
3058 /// \brief Retrieve the nested-name-specifier that qualifies the member
3059 /// name, with source location information.
3060 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3063 /// \brief Retrieve the first part of the nested-name-specifier that was
3064 /// found in the scope of the member access expression when the member access
3065 /// was initially parsed.
3067 /// This function only returns a useful result when member access expression
3068 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3069 /// returned by this function describes what was found by unqualified name
3070 /// lookup for the identifier "Base" within the scope of the member access
3071 /// expression itself. At template instantiation time, this information is
3072 /// combined with the results of name lookup into the type of the object
3073 /// expression itself (the class type of x).
3074 NamedDecl *getFirstQualifierFoundInScope() const {
3075 return FirstQualifierFoundInScope;
3078 /// \brief Retrieve the name of the member that this expression
3080 const DeclarationNameInfo &getMemberNameInfo() const {
3081 return MemberNameInfo;
3084 /// \brief Retrieve the name of the member that this expression
3086 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3088 // \brief Retrieve the location of the name of the member that this
3089 // expression refers to.
3090 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3092 /// \brief Retrieve the location of the template keyword preceding the
3093 /// member name, if any.
3094 SourceLocation getTemplateKeywordLoc() const {
3095 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3096 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3099 /// \brief Retrieve the location of the left angle bracket starting the
3100 /// explicit template argument list following the member name, if any.
3101 SourceLocation getLAngleLoc() const {
3102 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3103 return getTemplateKWAndArgsInfo()->LAngleLoc;
3106 /// \brief Retrieve the location of the right angle bracket ending the
3107 /// explicit template argument list following the member name, if any.
3108 SourceLocation getRAngleLoc() const {
3109 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3110 return getTemplateKWAndArgsInfo()->RAngleLoc;
3113 /// Determines whether the member name was preceded by the template keyword.
3114 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3116 /// \brief Determines whether this member expression actually had a C++
3117 /// template argument list explicitly specified, e.g., x.f<int>.
3118 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3120 /// \brief Retrieve the explicit template argument list that followed the
3121 /// member template name, if any.
3122 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3123 assert(hasExplicitTemplateArgs());
3124 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3127 /// \brief Retrieve the explicit template argument list that followed the
3128 /// member template name, if any.
3129 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3130 return const_cast<CXXDependentScopeMemberExpr *>(this)
3131 ->getExplicitTemplateArgs();
3134 /// \brief Retrieves the optional explicit template arguments.
3136 /// This points to the same data as getExplicitTemplateArgs(), but
3137 /// returns null if there are no explicit template arguments.
3138 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
3139 if (!hasExplicitTemplateArgs()) return nullptr;
3140 return &getExplicitTemplateArgs();
3143 /// \brief Copies the template arguments (if present) into the given
3145 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3146 getExplicitTemplateArgs().copyInto(List);
3149 /// \brief Initializes the template arguments using the given structure.
3150 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3151 getExplicitTemplateArgs().initializeFrom(List);
3154 /// \brief Retrieve the template arguments provided as part of this
3156 const TemplateArgumentLoc *getTemplateArgs() const {
3157 return getExplicitTemplateArgs().getTemplateArgs();
3160 /// \brief Retrieve the number of template arguments provided as part of this
3162 unsigned getNumTemplateArgs() const {
3163 return getExplicitTemplateArgs().NumTemplateArgs;
3166 SourceLocation getLocStart() const LLVM_READONLY {
3167 if (!isImplicitAccess())
3168 return Base->getLocStart();
3170 return getQualifierLoc().getBeginLoc();
3171 return MemberNameInfo.getBeginLoc();
3174 SourceLocation getLocEnd() const LLVM_READONLY {
3175 if (hasExplicitTemplateArgs())
3176 return getRAngleLoc();
3177 return MemberNameInfo.getEndLoc();
3180 static bool classof(const Stmt *T) {
3181 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3185 child_range children() {
3186 if (isImplicitAccess()) return child_range();
3187 return child_range(&Base, &Base + 1);
3190 friend class ASTStmtReader;
3191 friend class ASTStmtWriter;
3194 /// \brief Represents a C++ member access expression for which lookup
3195 /// produced a set of overloaded functions.
3197 /// The member access may be explicit or implicit:
3201 /// int explicitAccess() { return this->a + this->A::b; }
3202 /// int implicitAccess() { return a + A::b; }
3206 /// In the final AST, an explicit access always becomes a MemberExpr.
3207 /// An implicit access may become either a MemberExpr or a
3208 /// DeclRefExpr, depending on whether the member is static.
3209 class UnresolvedMemberExpr : public OverloadExpr {
3210 /// \brief Whether this member expression used the '->' operator or
3211 /// the '.' operator.
3214 /// \brief Whether the lookup results contain an unresolved using
3216 bool HasUnresolvedUsing : 1;
3218 /// \brief The expression for the base pointer or class reference,
3219 /// e.g., the \c x in x.f.
3221 /// This can be null if this is an 'unbased' member expression.
3224 /// \brief The type of the base expression; never null.
3227 /// \brief The location of the '->' or '.' operator.
3228 SourceLocation OperatorLoc;
3230 UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3231 Expr *Base, QualType BaseType, bool IsArrow,
3232 SourceLocation OperatorLoc,
3233 NestedNameSpecifierLoc QualifierLoc,
3234 SourceLocation TemplateKWLoc,
3235 const DeclarationNameInfo &MemberNameInfo,
3236 const TemplateArgumentListInfo *TemplateArgs,
3237 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3239 UnresolvedMemberExpr(EmptyShell Empty)
3240 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3241 HasUnresolvedUsing(false), Base(nullptr) { }
3243 friend class ASTStmtReader;
3246 static UnresolvedMemberExpr *
3247 Create(const ASTContext &C, bool HasUnresolvedUsing,
3248 Expr *Base, QualType BaseType, bool IsArrow,
3249 SourceLocation OperatorLoc,
3250 NestedNameSpecifierLoc QualifierLoc,
3251 SourceLocation TemplateKWLoc,
3252 const DeclarationNameInfo &MemberNameInfo,
3253 const TemplateArgumentListInfo *TemplateArgs,
3254 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3256 static UnresolvedMemberExpr *
3257 CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3258 unsigned NumTemplateArgs);
3260 /// \brief True if this is an implicit access, i.e., one in which the
3261 /// member being accessed was not written in the source.
3263 /// The source location of the operator is invalid in this case.
3264 bool isImplicitAccess() const;
3266 /// \brief Retrieve the base object of this member expressions,
3267 /// e.g., the \c x in \c x.m.
3269 assert(!isImplicitAccess());
3270 return cast<Expr>(Base);
3272 const Expr *getBase() const {
3273 assert(!isImplicitAccess());
3274 return cast<Expr>(Base);
3277 QualType getBaseType() const { return BaseType; }
3279 /// \brief Determine whether the lookup results contain an unresolved using
3281 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3283 /// \brief Determine whether this member expression used the '->'
3284 /// operator; otherwise, it used the '.' operator.
3285 bool isArrow() const { return IsArrow; }
3287 /// \brief Retrieve the location of the '->' or '.' operator.
3288 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3290 /// \brief Retrieve the naming class of this lookup.
3291 CXXRecordDecl *getNamingClass() const;
3293 /// \brief Retrieve the full name info for the member that this expression
3295 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3297 /// \brief Retrieve the name of the member that this expression
3299 DeclarationName getMemberName() const { return getName(); }
3301 // \brief Retrieve the location of the name of the member that this
3302 // expression refers to.
3303 SourceLocation getMemberLoc() const { return getNameLoc(); }
3305 // \brief Return the preferred location (the member name) for the arrow when
3306 // diagnosing a problem with this expression.
3307 SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
3309 SourceLocation getLocStart() const LLVM_READONLY {
3310 if (!isImplicitAccess())
3311 return Base->getLocStart();
3312 if (NestedNameSpecifierLoc l = getQualifierLoc())
3313 return l.getBeginLoc();
3314 return getMemberNameInfo().getLocStart();
3316 SourceLocation getLocEnd() const LLVM_READONLY {
3317 if (hasExplicitTemplateArgs())
3318 return getRAngleLoc();
3319 return getMemberNameInfo().getLocEnd();
3322 static bool classof(const Stmt *T) {
3323 return T->getStmtClass() == UnresolvedMemberExprClass;
3327 child_range children() {
3328 if (isImplicitAccess()) return child_range();
3329 return child_range(&Base, &Base + 1);
3333 /// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
3335 /// The noexcept expression tests whether a given expression might throw. Its
3336 /// result is a boolean constant.
3337 class CXXNoexceptExpr : public Expr {
3342 friend class ASTStmtReader;
3345 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3346 SourceLocation Keyword, SourceLocation RParen)
3347 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3348 /*TypeDependent*/false,
3349 /*ValueDependent*/Val == CT_Dependent,
3350 Val == CT_Dependent || Operand->isInstantiationDependent(),
3351 Operand->containsUnexpandedParameterPack()),
3352 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3355 CXXNoexceptExpr(EmptyShell Empty)
3356 : Expr(CXXNoexceptExprClass, Empty)
3359 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3361 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
3362 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3363 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3365 bool getValue() const { return Value; }
3367 static bool classof(const Stmt *T) {
3368 return T->getStmtClass() == CXXNoexceptExprClass;
3372 child_range children() { return child_range(&Operand, &Operand + 1); }
3375 /// \brief Represents a C++11 pack expansion that produces a sequence of
3378 /// A pack expansion expression contains a pattern (which itself is an
3379 /// expression) followed by an ellipsis. For example:
3382 /// template<typename F, typename ...Types>
3383 /// void forward(F f, Types &&...args) {
3384 /// f(static_cast<Types&&>(args)...);
3388 /// Here, the argument to the function object \c f is a pack expansion whose
3389 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3390 /// template is instantiated, the pack expansion will instantiate to zero or
3391 /// or more function arguments to the function object \c f.
3392 class PackExpansionExpr : public Expr {
3393 SourceLocation EllipsisLoc;
3395 /// \brief The number of expansions that will be produced by this pack
3396 /// expansion expression, if known.
3398 /// When zero, the number of expansions is not known. Otherwise, this value
3399 /// is the number of expansions + 1.
3400 unsigned NumExpansions;
3404 friend class ASTStmtReader;
3405 friend class ASTStmtWriter;
3408 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3409 Optional<unsigned> NumExpansions)
3410 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3411 Pattern->getObjectKind(), /*TypeDependent=*/true,
3412 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3413 /*ContainsUnexpandedParameterPack=*/false),
3414 EllipsisLoc(EllipsisLoc),
3415 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3416 Pattern(Pattern) { }
3418 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3420 /// \brief Retrieve the pattern of the pack expansion.
3421 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3423 /// \brief Retrieve the pattern of the pack expansion.
3424 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3426 /// \brief Retrieve the location of the ellipsis that describes this pack
3428 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3430 /// \brief Determine the number of expansions that will be produced when
3431 /// this pack expansion is instantiated, if already known.
3432 Optional<unsigned> getNumExpansions() const {
3434 return NumExpansions - 1;
3439 SourceLocation getLocStart() const LLVM_READONLY {
3440 return Pattern->getLocStart();
3442 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3444 static bool classof(const Stmt *T) {
3445 return T->getStmtClass() == PackExpansionExprClass;
3449 child_range children() {
3450 return child_range(&Pattern, &Pattern + 1);
3454 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3455 if (!HasTemplateKWAndArgsInfo) return nullptr;
3456 if (isa<UnresolvedLookupExpr>(this))
3457 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3458 (cast<UnresolvedLookupExpr>(this) + 1);
3460 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3461 (cast<UnresolvedMemberExpr>(this) + 1);
3464 /// \brief Represents an expression that computes the length of a parameter
3468 /// template<typename ...Types>
3470 /// static const unsigned value = sizeof...(Types);
3473 class SizeOfPackExpr : public Expr {
3474 /// \brief The location of the \c sizeof keyword.
3475 SourceLocation OperatorLoc;
3477 /// \brief The location of the name of the parameter pack.
3478 SourceLocation PackLoc;
3480 /// \brief The location of the closing parenthesis.
3481 SourceLocation RParenLoc;
3483 /// \brief The length of the parameter pack, if known.
3485 /// When this expression is value-dependent, the length of the parameter pack
3486 /// is unknown. When this expression is not value-dependent, the length is
3490 /// \brief The parameter pack itself.
3493 friend class ASTStmtReader;
3494 friend class ASTStmtWriter;
3497 /// \brief Create a value-dependent expression that computes the length of
3498 /// the given parameter pack.
3499 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3500 SourceLocation PackLoc, SourceLocation RParenLoc)
3501 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3502 /*TypeDependent=*/false, /*ValueDependent=*/true,
3503 /*InstantiationDependent=*/true,
3504 /*ContainsUnexpandedParameterPack=*/false),
3505 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3506 Length(0), Pack(Pack) { }
3508 /// \brief Create an expression that computes the length of
3509 /// the given parameter pack, which is already known.
3510 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3511 SourceLocation PackLoc, SourceLocation RParenLoc,
3513 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3514 /*TypeDependent=*/false, /*ValueDependent=*/false,
3515 /*InstantiationDependent=*/false,
3516 /*ContainsUnexpandedParameterPack=*/false),
3517 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3518 Length(Length), Pack(Pack) { }
3520 /// \brief Create an empty expression.
3521 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3523 /// \brief Determine the location of the 'sizeof' keyword.
3524 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3526 /// \brief Determine the location of the parameter pack.
3527 SourceLocation getPackLoc() const { return PackLoc; }
3529 /// \brief Determine the location of the right parenthesis.
3530 SourceLocation getRParenLoc() const { return RParenLoc; }
3532 /// \brief Retrieve the parameter pack.
3533 NamedDecl *getPack() const { return Pack; }
3535 /// \brief Retrieve the length of the parameter pack.
3537 /// This routine may only be invoked when the expression is not
3538 /// value-dependent.
3539 unsigned getPackLength() const {
3540 assert(!isValueDependent() &&
3541 "Cannot get the length of a value-dependent pack size expression");
3545 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
3546 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3548 static bool classof(const Stmt *T) {
3549 return T->getStmtClass() == SizeOfPackExprClass;
3553 child_range children() { return child_range(); }
3556 /// \brief Represents a reference to a non-type template parameter
3557 /// that has been substituted with a template argument.
3558 class SubstNonTypeTemplateParmExpr : public Expr {
3559 /// \brief The replaced parameter.
3560 NonTypeTemplateParmDecl *Param;
3562 /// \brief The replacement expression.
3565 /// \brief The location of the non-type template parameter reference.
3566 SourceLocation NameLoc;
3568 friend class ASTReader;
3569 friend class ASTStmtReader;
3570 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3571 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3574 SubstNonTypeTemplateParmExpr(QualType type,
3575 ExprValueKind valueKind,
3577 NonTypeTemplateParmDecl *param,
3579 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3580 replacement->isTypeDependent(), replacement->isValueDependent(),
3581 replacement->isInstantiationDependent(),
3582 replacement->containsUnexpandedParameterPack()),
3583 Param(param), Replacement(replacement), NameLoc(loc) {}
3585 SourceLocation getNameLoc() const { return NameLoc; }
3586 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3587 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3589 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3591 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3593 static bool classof(const Stmt *s) {
3594 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3598 child_range children() { return child_range(&Replacement, &Replacement+1); }
3601 /// \brief Represents a reference to a non-type template parameter pack that
3602 /// has been substituted with a non-template argument pack.
3604 /// When a pack expansion in the source code contains multiple parameter packs
3605 /// and those parameter packs correspond to different levels of template
3606 /// parameter lists, this node is used to represent a non-type template
3607 /// parameter pack from an outer level, which has already had its argument pack
3608 /// substituted but that still lives within a pack expansion that itself
3609 /// could not be instantiated. When actually performing a substitution into
3610 /// that pack expansion (e.g., when all template parameters have corresponding
3611 /// arguments), this type will be replaced with the appropriate underlying
3612 /// expression at the current pack substitution index.
3613 class SubstNonTypeTemplateParmPackExpr : public Expr {
3614 /// \brief The non-type template parameter pack itself.
3615 NonTypeTemplateParmDecl *Param;
3617 /// \brief A pointer to the set of template arguments that this
3618 /// parameter pack is instantiated with.
3619 const TemplateArgument *Arguments;
3621 /// \brief The number of template arguments in \c Arguments.
3622 unsigned NumArguments;
3624 /// \brief The location of the non-type template parameter pack reference.
3625 SourceLocation NameLoc;
3627 friend class ASTReader;
3628 friend class ASTStmtReader;
3629 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3630 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3633 SubstNonTypeTemplateParmPackExpr(QualType T,
3634 NonTypeTemplateParmDecl *Param,
3635 SourceLocation NameLoc,
3636 const TemplateArgument &ArgPack);
3638 /// \brief Retrieve the non-type template parameter pack being substituted.
3639 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3641 /// \brief Retrieve the location of the parameter pack name.
3642 SourceLocation getParameterPackLocation() const { return NameLoc; }
3644 /// \brief Retrieve the template argument pack containing the substituted
3645 /// template arguments.
3646 TemplateArgument getArgumentPack() const;
3648 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3649 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3651 static bool classof(const Stmt *T) {
3652 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3656 child_range children() { return child_range(); }
3659 /// \brief Represents a reference to a function parameter pack that has been
3660 /// substituted but not yet expanded.
3662 /// When a pack expansion contains multiple parameter packs at different levels,
3663 /// this node is used to represent a function parameter pack at an outer level
3664 /// which we have already substituted to refer to expanded parameters, but where
3665 /// the containing pack expansion cannot yet be expanded.
3668 /// template<typename...Ts> struct S {
3669 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3671 /// template struct S<int, int>;
3673 class FunctionParmPackExpr : public Expr {
3674 /// \brief The function parameter pack which was referenced.
3675 ParmVarDecl *ParamPack;
3677 /// \brief The location of the function parameter pack reference.
3678 SourceLocation NameLoc;
3680 /// \brief The number of expansions of this pack.
3681 unsigned NumParameters;
3683 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3684 SourceLocation NameLoc, unsigned NumParams,
3685 Decl * const *Params);
3687 friend class ASTReader;
3688 friend class ASTStmtReader;
3691 static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
3692 ParmVarDecl *ParamPack,
3693 SourceLocation NameLoc,
3694 ArrayRef<Decl *> Params);
3695 static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
3696 unsigned NumParams);
3698 /// \brief Get the parameter pack which this expression refers to.
3699 ParmVarDecl *getParameterPack() const { return ParamPack; }
3701 /// \brief Get the location of the parameter pack.
3702 SourceLocation getParameterPackLocation() const { return NameLoc; }
3704 /// \brief Iterators over the parameters which the parameter pack expanded
3706 typedef ParmVarDecl * const *iterator;
3707 iterator begin() const { return reinterpret_cast<iterator>(this+1); }
3708 iterator end() const { return begin() + NumParameters; }
3710 /// \brief Get the number of parameters in this parameter pack.
3711 unsigned getNumExpansions() const { return NumParameters; }
3713 /// \brief Get an expansion of the parameter pack by index.
3714 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3716 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3717 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3719 static bool classof(const Stmt *T) {
3720 return T->getStmtClass() == FunctionParmPackExprClass;
3723 child_range children() { return child_range(); }
3726 /// \brief Represents a prvalue temporary that is written into memory so that
3727 /// a reference can bind to it.
3729 /// Prvalue expressions are materialized when they need to have an address
3730 /// in memory for a reference to bind to. This happens when binding a
3731 /// reference to the result of a conversion, e.g.,
3734 /// const int &r = 1.0;
3737 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3738 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3739 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3740 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3741 /// to it), maintaining the invariant that references always bind to glvalues.
3743 /// Reference binding and copy-elision can both extend the lifetime of a
3744 /// temporary. When either happens, the expression will also track the
3745 /// declaration which is responsible for the lifetime extension.
3746 class MaterializeTemporaryExpr : public Expr {
3749 /// \brief The temporary-generating expression whose value will be
3753 /// \brief The declaration which lifetime-extended this reference, if any.
3754 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3755 const ValueDecl *ExtendingDecl;
3757 unsigned ManglingNumber;
3759 llvm::PointerUnion<Stmt *, ExtraState *> State;
3761 friend class ASTStmtReader;
3762 friend class ASTStmtWriter;
3764 void initializeExtraState(const ValueDecl *ExtendedBy,
3765 unsigned ManglingNumber);
3768 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3769 bool BoundToLvalueReference)
3770 : Expr(MaterializeTemporaryExprClass, T,
3771 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3772 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3773 Temporary->isInstantiationDependent(),
3774 Temporary->containsUnexpandedParameterPack()),
3777 MaterializeTemporaryExpr(EmptyShell Empty)
3778 : Expr(MaterializeTemporaryExprClass, Empty) { }
3780 Stmt *getTemporary() const {
3781 return State.is<Stmt *>() ? State.get<Stmt *>()
3782 : State.get<ExtraState *>()->Temporary;
3785 /// \brief Retrieve the temporary-generating subexpression whose value will
3786 /// be materialized into a glvalue.
3787 Expr *GetTemporaryExpr() const { return static_cast<Expr *>(getTemporary()); }
3789 /// \brief Retrieve the storage duration for the materialized temporary.
3790 StorageDuration getStorageDuration() const {
3791 const ValueDecl *ExtendingDecl = getExtendingDecl();
3793 return SD_FullExpression;
3794 // FIXME: This is not necessarily correct for a temporary materialized
3795 // within a default initializer.
3796 if (isa<FieldDecl>(ExtendingDecl))
3797 return SD_Automatic;
3798 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3801 /// \brief Get the declaration which triggered the lifetime-extension of this
3802 /// temporary, if any.
3803 const ValueDecl *getExtendingDecl() const {
3804 return State.is<Stmt *>() ? nullptr
3805 : State.get<ExtraState *>()->ExtendingDecl;
3808 void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber);
3810 unsigned getManglingNumber() const {
3811 return State.is<Stmt *>() ? 0 : State.get<ExtraState *>()->ManglingNumber;
3814 /// \brief Determine whether this materialized temporary is bound to an
3815 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3816 bool isBoundToLvalueReference() const {
3817 return getValueKind() == VK_LValue;
3820 SourceLocation getLocStart() const LLVM_READONLY {
3821 return getTemporary()->getLocStart();
3823 SourceLocation getLocEnd() const LLVM_READONLY {
3824 return getTemporary()->getLocEnd();
3827 static bool classof(const Stmt *T) {
3828 return T->getStmtClass() == MaterializeTemporaryExprClass;
3832 child_range children() {
3833 if (State.is<Stmt *>())
3834 return child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1);
3836 auto ES = State.get<ExtraState *>();
3837 return child_range(&ES->Temporary, &ES->Temporary + 1);
3841 /// \brief Represents a folding of a pack over an operator.
3843 /// This expression is always dependent and represents a pack expansion of the
3848 /// ( expr op ... op expr )
3849 class CXXFoldExpr : public Expr {
3850 SourceLocation LParenLoc;
3851 SourceLocation EllipsisLoc;
3852 SourceLocation RParenLoc;
3854 BinaryOperatorKind Opcode;
3856 friend class ASTStmtReader;
3857 friend class ASTStmtWriter;
3859 CXXFoldExpr(QualType T, SourceLocation LParenLoc, Expr *LHS,
3860 BinaryOperatorKind Opcode, SourceLocation EllipsisLoc, Expr *RHS,
3861 SourceLocation RParenLoc)
3862 : Expr(CXXFoldExprClass, T, VK_RValue, OK_Ordinary,
3863 /*Dependent*/ true, true, true,
3864 /*ContainsUnexpandedParameterPack*/ false),
3865 LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc),
3870 CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
3872 Expr *getLHS() const { return static_cast<Expr*>(SubExprs[0]); }
3873 Expr *getRHS() const { return static_cast<Expr*>(SubExprs[1]); }
3875 /// Does this produce a right-associated sequence of operators?
3876 bool isRightFold() const {
3877 return getLHS() && getLHS()->containsUnexpandedParameterPack();
3879 /// Does this produce a left-associated sequence of operators?
3880 bool isLeftFold() const { return !isRightFold(); }
3881 /// Get the pattern, that is, the operand that contains an unexpanded pack.
3882 Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); }
3883 /// Get the operand that doesn't contain a pack, for a binary fold.
3884 Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
3886 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3887 BinaryOperatorKind getOperator() const { return Opcode; }
3889 SourceLocation getLocStart() const LLVM_READONLY {
3892 SourceLocation getLocEnd() const LLVM_READONLY {
3896 static bool classof(const Stmt *T) {
3897 return T->getStmtClass() == CXXFoldExprClass;
3901 child_range children() { return child_range(SubExprs, SubExprs + 2); }
3904 } // end namespace clang