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 //===----------------------------------------------------------------------===//
10 // This file defines the Expr interface and subclasses for C++ expressions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/UnresolvedSet.h"
20 #include "clang/AST/TemplateBase.h"
21 #include "clang/Basic/ExpressionTraits.h"
22 #include "clang/Basic/Lambda.h"
23 #include "clang/Basic/TypeTraits.h"
24 #include "llvm/Support/Compiler.h"
28 class CXXConstructorDecl;
29 class CXXDestructorDecl;
32 class TemplateArgumentListInfo;
34 //===--------------------------------------------------------------------===//
36 //===--------------------------------------------------------------------===//
38 /// \brief A call to an overloaded operator written using operator
41 /// Represents a call to an overloaded operator written using operator
42 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
43 /// normal call, this AST node provides better information about the
44 /// syntactic representation of the call.
46 /// In a C++ template, this expression node kind will be used whenever
47 /// any of the arguments are type-dependent. In this case, the
48 /// function itself will be a (possibly empty) set of functions and
49 /// function templates that were found by name lookup at template
51 class CXXOperatorCallExpr : public CallExpr {
52 /// \brief The overloaded operator.
53 OverloadedOperatorKind Operator;
56 // Record the FP_CONTRACT state that applies to this operator call. Only
57 // meaningful for floating point types. For other types this value can be
59 unsigned FPContractable : 1;
61 SourceRange getSourceRangeImpl() const LLVM_READONLY;
63 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
64 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
65 SourceLocation operatorloc, bool fpContractable)
66 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
68 Operator(Op), FPContractable(fpContractable) {
69 Range = getSourceRangeImpl();
71 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
72 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
75 /// getOperator - Returns the kind of overloaded operator that this
76 /// expression refers to.
77 OverloadedOperatorKind getOperator() const { return Operator; }
79 /// getOperatorLoc - Returns the location of the operator symbol in
80 /// the expression. When @c getOperator()==OO_Call, this is the
81 /// location of the right parentheses; when @c
82 /// getOperator()==OO_Subscript, this is the location of the right
84 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
86 SourceRange getSourceRange() const { return Range; }
88 static bool classof(const Stmt *T) {
89 return T->getStmtClass() == CXXOperatorCallExprClass;
92 // Set the FP contractability status of this operator. Only meaningful for
93 // operations on floating point types.
94 void setFPContractable(bool FPC) { FPContractable = FPC; }
96 // Get the FP contractability status of this operator. Only meaningful for
97 // operations on floating point types.
98 bool isFPContractable() const { return FPContractable; }
100 friend class ASTStmtReader;
101 friend class ASTStmtWriter;
104 /// CXXMemberCallExpr - Represents a call to a member function that
105 /// may be written either with member call syntax (e.g., "obj.func()"
106 /// or "objptr->func()") or with normal function-call syntax
107 /// ("func()") within a member function that ends up calling a member
108 /// function. The callee in either case is a MemberExpr that contains
109 /// both the object argument and the member function, while the
110 /// arguments are the arguments within the parentheses (not including
111 /// the object argument).
112 class CXXMemberCallExpr : public CallExpr {
114 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
115 QualType t, ExprValueKind VK, SourceLocation RP)
116 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
118 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
119 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
121 /// getImplicitObjectArgument - Retrieves the implicit object
122 /// argument for the member call. For example, in "x.f(5)", this
123 /// operation would return "x".
124 Expr *getImplicitObjectArgument() const;
126 /// Retrieves the declaration of the called method.
127 CXXMethodDecl *getMethodDecl() const;
129 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
130 /// the implicit object argument. Note that this is may not be the same
131 /// declaration as that of the class context of the CXXMethodDecl which this
132 /// function is calling.
133 /// FIXME: Returns 0 for member pointer call exprs.
134 CXXRecordDecl *getRecordDecl() const;
136 static bool classof(const Stmt *T) {
137 return T->getStmtClass() == CXXMemberCallExprClass;
141 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
142 class CUDAKernelCallExpr : public CallExpr {
144 enum { CONFIG, END_PREARG };
147 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
148 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
150 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
154 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
155 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
157 const CallExpr *getConfig() const {
158 return cast_or_null<CallExpr>(getPreArg(CONFIG));
160 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
161 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
163 static bool classof(const Stmt *T) {
164 return T->getStmtClass() == CUDAKernelCallExprClass;
168 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
169 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
172 /// This abstract class is inherited by all of the classes
173 /// representing "named" casts, e.g., CXXStaticCastExpr,
174 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
175 class CXXNamedCastExpr : public ExplicitCastExpr {
177 SourceLocation Loc; // the location of the casting op
178 SourceLocation RParenLoc; // the location of the right parenthesis
181 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
182 CastKind kind, Expr *op, unsigned PathSize,
183 TypeSourceInfo *writtenTy, SourceLocation l,
184 SourceLocation RParenLoc)
185 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
186 RParenLoc(RParenLoc) {}
188 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
189 : ExplicitCastExpr(SC, Shell, PathSize) { }
191 friend class ASTStmtReader;
194 const char *getCastName() const;
196 /// \brief Retrieve the location of the cast operator keyword, e.g.,
198 SourceLocation getOperatorLoc() const { return Loc; }
200 /// \brief Retrieve the location of the closing parenthesis.
201 SourceLocation getRParenLoc() const { return RParenLoc; }
203 SourceRange getSourceRange() const LLVM_READONLY {
204 return SourceRange(Loc, RParenLoc);
206 static bool classof(const Stmt *T) {
207 switch (T->getStmtClass()) {
208 case CXXStaticCastExprClass:
209 case CXXDynamicCastExprClass:
210 case CXXReinterpretCastExprClass:
211 case CXXConstCastExprClass:
219 /// CXXStaticCastExpr - A C++ @c static_cast expression
220 /// (C++ [expr.static.cast]).
222 /// This expression node represents a C++ static cast, e.g.,
223 /// @c static_cast<int>(1.0).
224 class CXXStaticCastExpr : public CXXNamedCastExpr {
225 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
226 unsigned pathSize, TypeSourceInfo *writtenTy,
227 SourceLocation l, SourceLocation RParenLoc)
228 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
229 writtenTy, l, RParenLoc) {}
231 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
232 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
235 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
236 ExprValueKind VK, CastKind K, Expr *Op,
237 const CXXCastPath *Path,
238 TypeSourceInfo *Written, SourceLocation L,
239 SourceLocation RParenLoc);
240 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
243 static bool classof(const Stmt *T) {
244 return T->getStmtClass() == CXXStaticCastExprClass;
248 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
249 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
250 /// determine how to perform the type cast.
252 /// This expression node represents a dynamic cast, e.g.,
253 /// @c dynamic_cast<Derived*>(BasePtr).
254 class CXXDynamicCastExpr : public CXXNamedCastExpr {
255 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
256 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
257 SourceLocation l, SourceLocation RParenLoc)
258 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
259 writtenTy, l, RParenLoc) {}
261 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
262 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
265 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
266 ExprValueKind VK, CastKind Kind, Expr *Op,
267 const CXXCastPath *Path,
268 TypeSourceInfo *Written, SourceLocation L,
269 SourceLocation RParenLoc);
271 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
274 bool isAlwaysNull() const;
276 static bool classof(const Stmt *T) {
277 return T->getStmtClass() == CXXDynamicCastExprClass;
281 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
282 /// [expr.reinterpret.cast]), which provides a differently-typed view
283 /// of a value but performs no actual work at run time.
285 /// This expression node represents a reinterpret cast, e.g.,
286 /// @c reinterpret_cast<int>(VoidPtr).
287 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
288 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
289 Expr *op, unsigned pathSize,
290 TypeSourceInfo *writtenTy, SourceLocation l,
291 SourceLocation RParenLoc)
292 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
293 pathSize, writtenTy, l, RParenLoc) {}
295 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
296 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
299 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
300 ExprValueKind VK, CastKind Kind,
301 Expr *Op, const CXXCastPath *Path,
302 TypeSourceInfo *WrittenTy, SourceLocation L,
303 SourceLocation RParenLoc);
304 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
307 static bool classof(const Stmt *T) {
308 return T->getStmtClass() == CXXReinterpretCastExprClass;
312 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
313 /// which can remove type qualifiers but does not change the underlying value.
315 /// This expression node represents a const cast, e.g.,
316 /// @c const_cast<char*>(PtrToConstChar).
317 class CXXConstCastExpr : public CXXNamedCastExpr {
318 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
319 TypeSourceInfo *writtenTy, SourceLocation l,
320 SourceLocation RParenLoc)
321 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
322 0, writtenTy, l, RParenLoc) {}
324 explicit CXXConstCastExpr(EmptyShell Empty)
325 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
328 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
329 ExprValueKind VK, Expr *Op,
330 TypeSourceInfo *WrittenTy, SourceLocation L,
331 SourceLocation RParenLoc);
332 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
334 static bool classof(const Stmt *T) {
335 return T->getStmtClass() == CXXConstCastExprClass;
339 /// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
340 /// written as a user-defined literal (C++11 [lit.ext]).
342 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
343 /// is semantically equivalent to a normal call, this AST node provides better
344 /// information about the syntactic representation of the literal.
346 /// Since literal operators are never found by ADL and can only be declared at
347 /// namespace scope, a user-defined literal is never dependent.
348 class UserDefinedLiteral : public CallExpr {
349 /// \brief The location of a ud-suffix within the literal.
350 SourceLocation UDSuffixLoc;
353 UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
354 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
355 SourceLocation SuffixLoc)
356 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
357 UDSuffixLoc(SuffixLoc) {}
358 explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
359 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
361 /// The kind of literal operator which is invoked.
362 enum LiteralOperatorKind {
363 LOK_Raw, ///< Raw form: operator "" X (const char *)
364 LOK_Template, ///< Raw form: operator "" X<cs...> ()
365 LOK_Integer, ///< operator "" X (unsigned long long)
366 LOK_Floating, ///< operator "" X (long double)
367 LOK_String, ///< operator "" X (const CharT *, size_t)
368 LOK_Character ///< operator "" X (CharT)
371 /// getLiteralOperatorKind - Returns the kind of literal operator invocation
372 /// which this expression represents.
373 LiteralOperatorKind getLiteralOperatorKind() const;
375 /// getCookedLiteral - If this is not a raw user-defined literal, get the
376 /// underlying cooked literal (representing the literal with the suffix
378 Expr *getCookedLiteral();
379 const Expr *getCookedLiteral() const {
380 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
383 SourceLocation getLocStart() const {
384 if (getLiteralOperatorKind() == LOK_Template)
385 return getRParenLoc();
386 return getArg(0)->getLocStart();
388 SourceLocation getLocEnd() const { return getRParenLoc(); }
389 SourceRange getSourceRange() const {
390 return SourceRange(getLocStart(), getLocEnd());
394 /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
395 /// For a string literal, there may be multiple identical suffixes. This
396 /// returns the first.
397 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
399 /// getUDSuffix - Returns the ud-suffix specified for this literal.
400 const IdentifierInfo *getUDSuffix() const;
402 static bool classof(const Stmt *S) {
403 return S->getStmtClass() == UserDefinedLiteralClass;
406 friend class ASTStmtReader;
407 friend class ASTStmtWriter;
410 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
412 class CXXBoolLiteralExpr : public Expr {
416 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
417 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
419 Value(val), Loc(l) {}
421 explicit CXXBoolLiteralExpr(EmptyShell Empty)
422 : Expr(CXXBoolLiteralExprClass, Empty) { }
424 bool getValue() const { return Value; }
425 void setValue(bool V) { Value = V; }
427 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
429 SourceLocation getLocation() const { return Loc; }
430 void setLocation(SourceLocation L) { Loc = L; }
432 static bool classof(const Stmt *T) {
433 return T->getStmtClass() == CXXBoolLiteralExprClass;
437 child_range children() { return child_range(); }
440 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
441 class CXXNullPtrLiteralExpr : public Expr {
444 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
445 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
449 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
450 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
452 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
454 SourceLocation getLocation() const { return Loc; }
455 void setLocation(SourceLocation L) { Loc = L; }
457 static bool classof(const Stmt *T) {
458 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
461 child_range children() { return child_range(); }
464 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
465 /// the type_info that corresponds to the supplied type, or the (possibly
466 /// dynamic) type of the supplied expression.
468 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
469 class CXXTypeidExpr : public Expr {
471 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
475 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
476 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
477 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
479 // typeid is value-dependent if the type or expression are dependent
480 Operand->getType()->isDependentType(),
481 Operand->getType()->isInstantiationDependentType(),
482 Operand->getType()->containsUnexpandedParameterPack()),
483 Operand(Operand), Range(R) { }
485 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
486 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
487 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
489 // typeid is value-dependent if the type or expression are dependent
490 Operand->isTypeDependent() || Operand->isValueDependent(),
491 Operand->isInstantiationDependent(),
492 Operand->containsUnexpandedParameterPack()),
493 Operand(Operand), Range(R) { }
495 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
496 : Expr(CXXTypeidExprClass, Empty) {
500 Operand = (TypeSourceInfo*)0;
503 /// Determine whether this typeid has a type operand which is potentially
504 /// evaluated, per C++11 [expr.typeid]p3.
505 bool isPotentiallyEvaluated() const;
507 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
509 /// \brief Retrieves the type operand of this typeid() expression after
510 /// various required adjustments (removing reference types, cv-qualifiers).
511 QualType getTypeOperand() const;
513 /// \brief Retrieve source information for the type operand.
514 TypeSourceInfo *getTypeOperandSourceInfo() const {
515 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
516 return Operand.get<TypeSourceInfo *>();
519 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
520 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
524 Expr *getExprOperand() const {
525 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
526 return static_cast<Expr*>(Operand.get<Stmt *>());
529 void setExprOperand(Expr *E) {
530 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
534 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
535 void setSourceRange(SourceRange R) { Range = R; }
537 static bool classof(const Stmt *T) {
538 return T->getStmtClass() == CXXTypeidExprClass;
542 child_range children() {
543 if (isTypeOperand()) return child_range();
544 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
545 return child_range(begin, begin + 1);
549 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
550 /// the _GUID that corresponds to the supplied type or expression.
552 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
553 class CXXUuidofExpr : public Expr {
555 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
559 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
560 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
561 false, Operand->getType()->isDependentType(),
562 Operand->getType()->isInstantiationDependentType(),
563 Operand->getType()->containsUnexpandedParameterPack()),
564 Operand(Operand), Range(R) { }
566 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
567 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
568 false, Operand->isTypeDependent(),
569 Operand->isInstantiationDependent(),
570 Operand->containsUnexpandedParameterPack()),
571 Operand(Operand), Range(R) { }
573 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
574 : Expr(CXXUuidofExprClass, Empty) {
578 Operand = (TypeSourceInfo*)0;
581 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
583 /// \brief Retrieves the type operand of this __uuidof() expression after
584 /// various required adjustments (removing reference types, cv-qualifiers).
585 QualType getTypeOperand() const;
587 /// \brief Retrieve source information for the type operand.
588 TypeSourceInfo *getTypeOperandSourceInfo() const {
589 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
590 return Operand.get<TypeSourceInfo *>();
593 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
594 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
598 Expr *getExprOperand() const {
599 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
600 return static_cast<Expr*>(Operand.get<Stmt *>());
603 void setExprOperand(Expr *E) {
604 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
608 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
609 void setSourceRange(SourceRange R) { Range = R; }
611 static bool classof(const Stmt *T) {
612 return T->getStmtClass() == CXXUuidofExprClass;
615 /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none.
616 static UuidAttr *GetUuidAttrOfType(QualType QT);
619 child_range children() {
620 if (isTypeOperand()) return child_range();
621 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
622 return child_range(begin, begin + 1);
626 /// CXXThisExpr - Represents the "this" expression in C++, which is a
627 /// pointer to the object on which the current member function is
628 /// executing (C++ [expr.prim]p3). Example:
634 /// void test() { this->bar(); }
637 class CXXThisExpr : public Expr {
642 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
643 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
644 // 'this' is type-dependent if the class type of the enclosing
645 // member function is dependent (C++ [temp.dep.expr]p2)
646 Type->isDependentType(), Type->isDependentType(),
647 Type->isInstantiationDependentType(),
648 /*ContainsUnexpandedParameterPack=*/false),
649 Loc(L), Implicit(isImplicit) { }
651 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
653 SourceLocation getLocation() const { return Loc; }
654 void setLocation(SourceLocation L) { Loc = L; }
656 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
658 bool isImplicit() const { return Implicit; }
659 void setImplicit(bool I) { Implicit = I; }
661 static bool classof(const Stmt *T) {
662 return T->getStmtClass() == CXXThisExprClass;
666 child_range children() { return child_range(); }
669 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
670 /// 'throw' and 'throw' assignment-expression. When
671 /// assignment-expression isn't present, Op will be null.
673 class CXXThrowExpr : public Expr {
675 SourceLocation ThrowLoc;
676 /// \brief Whether the thrown variable (if any) is in scope.
677 unsigned IsThrownVariableInScope : 1;
679 friend class ASTStmtReader;
682 // Ty is the void type which is used as the result type of the
683 // exepression. The l is the location of the throw keyword. expr
684 // can by null, if the optional expression to throw isn't present.
685 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
686 bool IsThrownVariableInScope) :
687 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
688 expr && expr->isInstantiationDependent(),
689 expr && expr->containsUnexpandedParameterPack()),
690 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
691 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
693 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
694 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
696 SourceLocation getThrowLoc() const { return ThrowLoc; }
698 /// \brief Determines whether the variable thrown by this expression (if any!)
699 /// is within the innermost try block.
701 /// This information is required to determine whether the NRVO can apply to
703 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
705 SourceRange getSourceRange() const LLVM_READONLY {
706 if (getSubExpr() == 0)
707 return SourceRange(ThrowLoc, ThrowLoc);
708 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
711 static bool classof(const Stmt *T) {
712 return T->getStmtClass() == CXXThrowExprClass;
716 child_range children() {
717 return child_range(&Op, Op ? &Op+1 : &Op);
721 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
722 /// function call argument that was created from the corresponding
723 /// parameter's default argument, when the call did not explicitly
724 /// supply arguments for all of the parameters.
725 class CXXDefaultArgExpr : public Expr {
726 /// \brief The parameter whose default is being used.
728 /// When the bit is set, the subexpression is stored after the
729 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
730 /// actual default expression is the subexpression.
731 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
733 /// \brief The location where the default argument expression was used.
736 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
738 param->hasUnparsedDefaultArg()
739 ? param->getType().getNonReferenceType()
740 : param->getDefaultArg()->getType(),
741 param->getDefaultArg()->getValueKind(),
742 param->getDefaultArg()->getObjectKind(), false, false, false, false),
743 Param(param, false), Loc(Loc) { }
745 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
747 : Expr(SC, SubExpr->getType(),
748 SubExpr->getValueKind(), SubExpr->getObjectKind(),
749 false, false, false, false),
750 Param(param, true), Loc(Loc) {
751 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
755 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
758 // Param is the parameter whose default argument is used by this
760 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
761 ParmVarDecl *Param) {
762 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
765 // Param is the parameter whose default argument is used by this
766 // expression, and SubExpr is the expression that will actually be used.
767 static CXXDefaultArgExpr *Create(ASTContext &C,
772 // Retrieve the parameter that the argument was created from.
773 const ParmVarDecl *getParam() const { return Param.getPointer(); }
774 ParmVarDecl *getParam() { return Param.getPointer(); }
776 // Retrieve the actual argument to the function call.
777 const Expr *getExpr() const {
779 return *reinterpret_cast<Expr const * const*> (this + 1);
780 return getParam()->getDefaultArg();
784 return *reinterpret_cast<Expr **> (this + 1);
785 return getParam()->getDefaultArg();
788 /// \brief Retrieve the location where this default argument was actually
790 SourceLocation getUsedLocation() const { return Loc; }
792 SourceRange getSourceRange() const LLVM_READONLY {
793 // Default argument expressions have no representation in the
794 // source, so they have an empty source range.
795 return SourceRange();
798 static bool classof(const Stmt *T) {
799 return T->getStmtClass() == CXXDefaultArgExprClass;
803 child_range children() { return child_range(); }
805 friend class ASTStmtReader;
806 friend class ASTStmtWriter;
809 /// CXXTemporary - Represents a C++ temporary.
811 /// Destructor - The destructor that needs to be called.
812 const CXXDestructorDecl *Destructor;
814 CXXTemporary(const CXXDestructorDecl *destructor)
815 : Destructor(destructor) { }
818 static CXXTemporary *Create(ASTContext &C,
819 const CXXDestructorDecl *Destructor);
821 const CXXDestructorDecl *getDestructor() const { return Destructor; }
822 void setDestructor(const CXXDestructorDecl *Dtor) {
827 /// \brief Represents binding an expression to a temporary.
829 /// This ensures the destructor is called for the temporary. It should only be
830 /// needed for non-POD, non-trivially destructable class types. For example:
834 /// S() { } // User defined constructor makes S non-POD.
835 /// ~S() { } // User defined destructor makes it non-trivial.
838 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
841 class CXXBindTemporaryExpr : public Expr {
846 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
847 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
848 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
849 SubExpr->isValueDependent(),
850 SubExpr->isInstantiationDependent(),
851 SubExpr->containsUnexpandedParameterPack()),
852 Temp(temp), SubExpr(SubExpr) { }
855 CXXBindTemporaryExpr(EmptyShell Empty)
856 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
858 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
861 CXXTemporary *getTemporary() { return Temp; }
862 const CXXTemporary *getTemporary() const { return Temp; }
863 void setTemporary(CXXTemporary *T) { Temp = T; }
865 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
866 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
867 void setSubExpr(Expr *E) { SubExpr = E; }
869 SourceRange getSourceRange() const LLVM_READONLY {
870 return SubExpr->getSourceRange();
873 // Implement isa/cast/dyncast/etc.
874 static bool classof(const Stmt *T) {
875 return T->getStmtClass() == CXXBindTemporaryExprClass;
879 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
882 /// \brief Represents a call to a C++ constructor.
883 class CXXConstructExpr : public Expr {
885 enum ConstructionKind {
893 CXXConstructorDecl *Constructor;
896 SourceRange ParenRange;
897 unsigned NumArgs : 16;
899 bool HadMultipleCandidates : 1;
900 bool ListInitialization : 1;
901 bool ZeroInitialization : 1;
902 unsigned ConstructKind : 2;
906 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
908 CXXConstructorDecl *d, bool elidable,
909 ArrayRef<Expr *> Args,
910 bool HadMultipleCandidates,
911 bool ListInitialization,
912 bool ZeroInitialization,
913 ConstructionKind ConstructKind,
914 SourceRange ParenRange);
916 /// \brief Construct an empty C++ construction expression.
917 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
918 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
919 HadMultipleCandidates(false), ListInitialization(false),
920 ZeroInitialization(false), ConstructKind(0), Args(0)
924 /// \brief Construct an empty C++ construction expression.
925 explicit CXXConstructExpr(EmptyShell Empty)
926 : Expr(CXXConstructExprClass, Empty), Constructor(0),
927 NumArgs(0), Elidable(false), HadMultipleCandidates(false),
928 ListInitialization(false), ZeroInitialization(false),
929 ConstructKind(0), Args(0)
932 static CXXConstructExpr *Create(ASTContext &C, QualType T,
934 CXXConstructorDecl *D, bool Elidable,
935 ArrayRef<Expr *> Args,
936 bool HadMultipleCandidates,
937 bool ListInitialization,
938 bool ZeroInitialization,
939 ConstructionKind ConstructKind,
940 SourceRange ParenRange);
942 CXXConstructorDecl* getConstructor() const { return Constructor; }
943 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
945 SourceLocation getLocation() const { return Loc; }
946 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
948 /// \brief Whether this construction is elidable.
949 bool isElidable() const { return Elidable; }
950 void setElidable(bool E) { Elidable = E; }
952 /// \brief Whether the referred constructor was resolved from
953 /// an overloaded set having size greater than 1.
954 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
955 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
957 /// \brief Whether this constructor call was written as list-initialization.
958 bool isListInitialization() const { return ListInitialization; }
959 void setListInitialization(bool V) { ListInitialization = V; }
961 /// \brief Whether this construction first requires
962 /// zero-initialization before the initializer is called.
963 bool requiresZeroInitialization() const { return ZeroInitialization; }
964 void setRequiresZeroInitialization(bool ZeroInit) {
965 ZeroInitialization = ZeroInit;
968 /// \brief Determines whether this constructor is actually constructing
969 /// a base class (rather than a complete object).
970 ConstructionKind getConstructionKind() const {
971 return (ConstructionKind)ConstructKind;
973 void setConstructionKind(ConstructionKind CK) {
977 typedef ExprIterator arg_iterator;
978 typedef ConstExprIterator const_arg_iterator;
980 arg_iterator arg_begin() { return Args; }
981 arg_iterator arg_end() { return Args + NumArgs; }
982 const_arg_iterator arg_begin() const { return Args; }
983 const_arg_iterator arg_end() const { return Args + NumArgs; }
985 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
986 unsigned getNumArgs() const { return NumArgs; }
988 /// getArg - Return the specified argument.
989 Expr *getArg(unsigned Arg) {
990 assert(Arg < NumArgs && "Arg access out of range!");
991 return cast<Expr>(Args[Arg]);
993 const Expr *getArg(unsigned Arg) const {
994 assert(Arg < NumArgs && "Arg access out of range!");
995 return cast<Expr>(Args[Arg]);
998 /// setArg - Set the specified argument.
999 void setArg(unsigned Arg, Expr *ArgExpr) {
1000 assert(Arg < NumArgs && "Arg access out of range!");
1001 Args[Arg] = ArgExpr;
1004 SourceRange getSourceRange() const LLVM_READONLY;
1005 SourceRange getParenRange() const { return ParenRange; }
1006 void setParenRange(SourceRange Range) { ParenRange = Range; }
1008 static bool classof(const Stmt *T) {
1009 return T->getStmtClass() == CXXConstructExprClass ||
1010 T->getStmtClass() == CXXTemporaryObjectExprClass;
1014 child_range children() {
1015 return child_range(&Args[0], &Args[0]+NumArgs);
1018 friend class ASTStmtReader;
1021 /// \brief Represents an explicit C++ type conversion that uses "functional"
1022 /// notation (C++ [expr.type.conv]).
1028 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1029 SourceLocation TyBeginLoc;
1030 SourceLocation RParenLoc;
1032 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1033 TypeSourceInfo *writtenTy,
1034 SourceLocation tyBeginLoc, CastKind kind,
1035 Expr *castExpr, unsigned pathSize,
1036 SourceLocation rParenLoc)
1037 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1038 castExpr, pathSize, writtenTy),
1039 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
1041 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1042 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1045 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1047 TypeSourceInfo *Written,
1048 SourceLocation TyBeginLoc,
1049 CastKind Kind, Expr *Op,
1050 const CXXCastPath *Path,
1051 SourceLocation RPLoc);
1052 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1055 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1056 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1057 SourceLocation getRParenLoc() const { return RParenLoc; }
1058 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1060 SourceRange getSourceRange() const LLVM_READONLY {
1061 return SourceRange(TyBeginLoc, RParenLoc);
1063 static bool classof(const Stmt *T) {
1064 return T->getStmtClass() == CXXFunctionalCastExprClass;
1068 /// @brief Represents a C++ functional cast expression that builds a
1069 /// temporary object.
1071 /// This expression type represents a C++ "functional" cast
1072 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1073 /// constructor to build a temporary object. With N == 1 arguments the
1074 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1077 /// struct X { X(int, float); }
1080 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1083 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1084 TypeSourceInfo *Type;
1087 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1088 TypeSourceInfo *Type,
1089 ArrayRef<Expr *> Args,
1090 SourceRange parenRange,
1091 bool HadMultipleCandidates,
1092 bool ZeroInitialization = false);
1093 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1094 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1096 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1098 SourceRange getSourceRange() const LLVM_READONLY;
1100 static bool classof(const Stmt *T) {
1101 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1104 friend class ASTStmtReader;
1107 /// \brief A C++ lambda expression, which produces a function object
1108 /// (of unspecified type) that can be invoked later.
1112 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1113 /// values.erase(std::remove_if(values.begin(), values.end(),
1114 // [=](double value) { return value > cutoff; });
1118 /// Lambda expressions can capture local variables, either by copying
1119 /// the values of those local variables at the time the function
1120 /// object is constructed (not when it is called!) or by holding a
1121 /// reference to the local variable. These captures can occur either
1122 /// implicitly or can be written explicitly between the square
1123 /// brackets ([...]) that start the lambda expression.
1124 class LambdaExpr : public Expr {
1126 /// \brief Flag used by the Capture class to indicate that the given
1127 /// capture was implicit.
1128 Capture_Implicit = 0x01,
1130 /// \brief Flag used by the Capture class to indciate that the
1131 /// given capture was by-copy.
1132 Capture_ByCopy = 0x02
1135 /// \brief The source range that covers the lambda introducer ([...]).
1136 SourceRange IntroducerRange;
1138 /// \brief The number of captures.
1139 unsigned NumCaptures : 16;
1141 /// \brief The default capture kind, which is a value of type
1142 /// LambdaCaptureDefault.
1143 unsigned CaptureDefault : 2;
1145 /// \brief Whether this lambda had an explicit parameter list vs. an
1146 /// implicit (and empty) parameter list.
1147 unsigned ExplicitParams : 1;
1149 /// \brief Whether this lambda had the result type explicitly specified.
1150 unsigned ExplicitResultType : 1;
1152 /// \brief Whether there are any array index variables stored at the end of
1153 /// this lambda expression.
1154 unsigned HasArrayIndexVars : 1;
1156 /// \brief The location of the closing brace ('}') that completes
1159 /// The location of the brace is also available by looking up the
1160 /// function call operator in the lambda class. However, it is
1161 /// stored here to improve the performance of getSourceRange(), and
1162 /// to avoid having to deserialize the function call operator from a
1163 /// module file just to determine the source range.
1164 SourceLocation ClosingBrace;
1166 // Note: The capture initializers are stored directly after the lambda
1167 // expression, along with the index variables used to initialize by-copy
1171 /// \brief Describes the capture of either a variable or 'this'.
1173 llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
1175 SourceLocation EllipsisLoc;
1177 friend class ASTStmtReader;
1178 friend class ASTStmtWriter;
1181 /// \brief Create a new capture.
1183 /// \param Loc The source location associated with this capture.
1185 /// \param Kind The kind of capture (this, byref, bycopy).
1187 /// \param Implicit Whether the capture was implicit or explicit.
1189 /// \param Var The local variable being captured, or null if capturing this.
1191 /// \param EllipsisLoc The location of the ellipsis (...) for a
1192 /// capture that is a pack expansion, or an invalid source
1193 /// location to indicate that this is not a pack expansion.
1194 Capture(SourceLocation Loc, bool Implicit,
1195 LambdaCaptureKind Kind, VarDecl *Var = 0,
1196 SourceLocation EllipsisLoc = SourceLocation());
1198 /// \brief Determine the kind of capture.
1199 LambdaCaptureKind getCaptureKind() const;
1201 /// \brief Determine whether this capture handles the C++ 'this'
1203 bool capturesThis() const { return VarAndBits.getPointer() == 0; }
1205 /// \brief Determine whether this capture handles a variable.
1206 bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
1208 /// \brief Retrieve the declaration of the local variable being
1211 /// This operation is only valid if this capture does not capture
1213 VarDecl *getCapturedVar() const {
1214 assert(!capturesThis() && "No variable available for 'this' capture");
1215 return VarAndBits.getPointer();
1218 /// \brief Determine whether this was an implicit capture (not
1219 /// written between the square brackets introducing the lambda).
1220 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
1222 /// \brief Determine whether this was an explicit capture, written
1223 /// between the square brackets introducing the lambda.
1224 bool isExplicit() const { return !isImplicit(); }
1226 /// \brief Retrieve the source location of the capture.
1228 /// For an explicit capture, this returns the location of the
1229 /// explicit capture in the source. For an implicit capture, this
1230 /// returns the location at which the variable or 'this' was first
1232 SourceLocation getLocation() const { return Loc; }
1234 /// \brief Determine whether this capture is a pack expansion,
1235 /// which captures a function parameter pack.
1236 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
1238 /// \brief Retrieve the location of the ellipsis for a capture
1239 /// that is a pack expansion.
1240 SourceLocation getEllipsisLoc() const {
1241 assert(isPackExpansion() && "No ellipsis location for a non-expansion");
1247 /// \brief Construct a lambda expression.
1248 LambdaExpr(QualType T, SourceRange IntroducerRange,
1249 LambdaCaptureDefault CaptureDefault,
1250 ArrayRef<Capture> Captures,
1251 bool ExplicitParams,
1252 bool ExplicitResultType,
1253 ArrayRef<Expr *> CaptureInits,
1254 ArrayRef<VarDecl *> ArrayIndexVars,
1255 ArrayRef<unsigned> ArrayIndexStarts,
1256 SourceLocation ClosingBrace,
1257 bool ContainsUnexpandedParameterPack);
1259 /// \brief Construct an empty lambda expression.
1260 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1261 : Expr(LambdaExprClass, Empty),
1262 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1263 ExplicitResultType(false), HasArrayIndexVars(true) {
1264 getStoredStmts()[NumCaptures] = 0;
1267 Stmt **getStoredStmts() const {
1268 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1271 /// \brief Retrieve the mapping from captures to the first array index
1273 unsigned *getArrayIndexStarts() const {
1274 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1277 /// \brief Retrieve the complete set of array-index variables.
1278 VarDecl **getArrayIndexVars() const {
1279 unsigned ArrayIndexSize =
1280 llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1281 llvm::alignOf<VarDecl*>());
1282 return reinterpret_cast<VarDecl **>(
1283 reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
1287 /// \brief Construct a new lambda expression.
1288 static LambdaExpr *Create(ASTContext &C,
1289 CXXRecordDecl *Class,
1290 SourceRange IntroducerRange,
1291 LambdaCaptureDefault CaptureDefault,
1292 ArrayRef<Capture> Captures,
1293 bool ExplicitParams,
1294 bool ExplicitResultType,
1295 ArrayRef<Expr *> CaptureInits,
1296 ArrayRef<VarDecl *> ArrayIndexVars,
1297 ArrayRef<unsigned> ArrayIndexStarts,
1298 SourceLocation ClosingBrace,
1299 bool ContainsUnexpandedParameterPack);
1301 /// \brief Construct a new lambda expression that will be deserialized from
1302 /// an external source.
1303 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
1304 unsigned NumArrayIndexVars);
1306 /// \brief Determine the default capture kind for this lambda.
1307 LambdaCaptureDefault getCaptureDefault() const {
1308 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1311 /// \brief An iterator that walks over the captures of the lambda,
1312 /// both implicit and explicit.
1313 typedef const Capture *capture_iterator;
1315 /// \brief Retrieve an iterator pointing to the first lambda capture.
1316 capture_iterator capture_begin() const;
1318 /// \brief Retrieve an iterator pointing past the end of the
1319 /// sequence of lambda captures.
1320 capture_iterator capture_end() const;
1322 /// \brief Determine the number of captures in this lambda.
1323 unsigned capture_size() const { return NumCaptures; }
1325 /// \brief Retrieve an iterator pointing to the first explicit
1327 capture_iterator explicit_capture_begin() const;
1329 /// \brief Retrieve an iterator pointing past the end of the sequence of
1330 /// explicit lambda captures.
1331 capture_iterator explicit_capture_end() const;
1333 /// \brief Retrieve an iterator pointing to the first implicit
1335 capture_iterator implicit_capture_begin() const;
1337 /// \brief Retrieve an iterator pointing past the end of the sequence of
1338 /// implicit lambda captures.
1339 capture_iterator implicit_capture_end() const;
1341 /// \brief Iterator that walks over the capture initialization
1343 typedef Expr **capture_init_iterator;
1345 /// \brief Retrieve the first initialization argument for this
1346 /// lambda expression (which initializes the first capture field).
1347 capture_init_iterator capture_init_begin() const {
1348 return reinterpret_cast<Expr **>(getStoredStmts());
1351 /// \brief Retrieve the iterator pointing one past the last
1352 /// initialization argument for this lambda expression.
1353 capture_init_iterator capture_init_end() const {
1354 return capture_init_begin() + NumCaptures;
1357 /// \brief Retrieve the set of index variables used in the capture
1358 /// initializer of an array captured by copy.
1360 /// \param Iter The iterator that points at the capture initializer for
1361 /// which we are extracting the corresponding index variables.
1362 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1364 /// \brief Retrieve the source range covering the lambda introducer,
1365 /// which contains the explicit capture list surrounded by square
1366 /// brackets ([...]).
1367 SourceRange getIntroducerRange() const { return IntroducerRange; }
1369 /// \brief Retrieve the class that corresponds to the lambda, which
1370 /// stores the captures in its fields and provides the various
1371 /// operations permitted on a lambda (copying, calling).
1372 CXXRecordDecl *getLambdaClass() const;
1374 /// \brief Retrieve the function call operator associated with this
1375 /// lambda expression.
1376 CXXMethodDecl *getCallOperator() const;
1378 /// \brief Retrieve the body of the lambda.
1379 CompoundStmt *getBody() const;
1381 /// \brief Determine whether the lambda is mutable, meaning that any
1382 /// captures values can be modified.
1383 bool isMutable() const;
1385 /// \brief Determine whether this lambda has an explicit parameter
1386 /// list vs. an implicit (empty) parameter list.
1387 bool hasExplicitParameters() const { return ExplicitParams; }
1389 /// \brief Whether this lambda had its result type explicitly specified.
1390 bool hasExplicitResultType() const { return ExplicitResultType; }
1392 static bool classof(const Stmt *T) {
1393 return T->getStmtClass() == LambdaExprClass;
1396 SourceRange getSourceRange() const LLVM_READONLY {
1397 return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
1400 child_range children() {
1401 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1404 friend class ASTStmtReader;
1405 friend class ASTStmtWriter;
1408 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1409 /// Expression "T()" which creates a value-initialized rvalue of type
1410 /// T, which is a non-class type.
1412 class CXXScalarValueInitExpr : public Expr {
1413 SourceLocation RParenLoc;
1414 TypeSourceInfo *TypeInfo;
1416 friend class ASTStmtReader;
1419 /// \brief Create an explicitly-written scalar-value initialization
1421 CXXScalarValueInitExpr(QualType Type,
1422 TypeSourceInfo *TypeInfo,
1423 SourceLocation rParenLoc ) :
1424 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1425 false, false, Type->isInstantiationDependentType(), false),
1426 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1428 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1429 : Expr(CXXScalarValueInitExprClass, Shell) { }
1431 TypeSourceInfo *getTypeSourceInfo() const {
1435 SourceLocation getRParenLoc() const { return RParenLoc; }
1437 SourceRange getSourceRange() const LLVM_READONLY;
1439 static bool classof(const Stmt *T) {
1440 return T->getStmtClass() == CXXScalarValueInitExprClass;
1444 child_range children() { return child_range(); }
1447 /// @brief Represents a new-expression for memory allocation and constructor
1448 // calls, e.g: "new CXXNewExpr(foo)".
1449 class CXXNewExpr : public Expr {
1450 // Contains an optional array size expression, an optional initialization
1451 // expression, and any number of optional placement arguments, in that order.
1453 /// \brief Points to the allocation function used.
1454 FunctionDecl *OperatorNew;
1455 /// \brief Points to the deallocation function used in case of error. May be
1457 FunctionDecl *OperatorDelete;
1459 /// \brief The allocated type-source information, as written in the source.
1460 TypeSourceInfo *AllocatedTypeInfo;
1462 /// \brief If the allocated type was expressed as a parenthesized type-id,
1463 /// the source range covering the parenthesized type-id.
1464 SourceRange TypeIdParens;
1466 /// \brief Range of the entire new expression.
1469 /// \brief Source-range of a paren-delimited initializer.
1470 SourceRange DirectInitRange;
1472 // Was the usage ::new, i.e. is the global new to be used?
1474 // Do we allocate an array? If so, the first SubExpr is the size expression.
1476 // If this is an array allocation, does the usual deallocation
1477 // function for the allocated type want to know the allocated size?
1478 bool UsualArrayDeleteWantsSize : 1;
1479 // The number of placement new arguments.
1480 unsigned NumPlacementArgs : 13;
1481 // What kind of initializer do we have? Could be none, parens, or braces.
1482 // In storage, we distinguish between "none, and no initializer expr", and
1483 // "none, but an implicit initializer expr".
1484 unsigned StoredInitializationStyle : 2;
1486 friend class ASTStmtReader;
1487 friend class ASTStmtWriter;
1489 enum InitializationStyle {
1490 NoInit, ///< New-expression has no initializer as written.
1491 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1492 ListInit ///< New-expression has a C++11 list-initializer.
1495 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1496 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1497 ArrayRef<Expr*> placementArgs,
1498 SourceRange typeIdParens, Expr *arraySize,
1499 InitializationStyle initializationStyle, Expr *initializer,
1500 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1501 SourceRange Range, SourceRange directInitRange);
1502 explicit CXXNewExpr(EmptyShell Shell)
1503 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1505 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1506 bool hasInitializer);
1508 QualType getAllocatedType() const {
1509 assert(getType()->isPointerType());
1510 return getType()->getAs<PointerType>()->getPointeeType();
1513 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1514 return AllocatedTypeInfo;
1517 /// \brief True if the allocation result needs to be null-checked.
1518 /// C++0x [expr.new]p13:
1519 /// If the allocation function returns null, initialization shall
1520 /// not be done, the deallocation function shall not be called,
1521 /// and the value of the new-expression shall be null.
1522 /// An allocation function is not allowed to return null unless it
1523 /// has a non-throwing exception-specification. The '03 rule is
1524 /// identical except that the definition of a non-throwing
1525 /// exception specification is just "is it throw()?".
1526 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1528 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1529 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1530 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1531 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1533 bool isArray() const { return Array; }
1534 Expr *getArraySize() {
1535 return Array ? cast<Expr>(SubExprs[0]) : 0;
1537 const Expr *getArraySize() const {
1538 return Array ? cast<Expr>(SubExprs[0]) : 0;
1541 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1542 Expr **getPlacementArgs() {
1543 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1546 Expr *getPlacementArg(unsigned i) {
1547 assert(i < NumPlacementArgs && "Index out of range");
1548 return getPlacementArgs()[i];
1550 const Expr *getPlacementArg(unsigned i) const {
1551 assert(i < NumPlacementArgs && "Index out of range");
1552 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1555 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1556 SourceRange getTypeIdParens() const { return TypeIdParens; }
1558 bool isGlobalNew() const { return GlobalNew; }
1560 /// \brief Whether this new-expression has any initializer at all.
1561 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1563 /// \brief The kind of initializer this new-expression has.
1564 InitializationStyle getInitializationStyle() const {
1565 if (StoredInitializationStyle == 0)
1567 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1570 /// \brief The initializer of this new-expression.
1571 Expr *getInitializer() {
1572 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1574 const Expr *getInitializer() const {
1575 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1578 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
1579 const CXXConstructExpr* getConstructExpr() const {
1580 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1583 /// Answers whether the usual array deallocation function for the
1584 /// allocated type expects the size of the allocation as a
1586 bool doesUsualArrayDeleteWantSize() const {
1587 return UsualArrayDeleteWantsSize;
1590 typedef ExprIterator arg_iterator;
1591 typedef ConstExprIterator const_arg_iterator;
1593 arg_iterator placement_arg_begin() {
1594 return SubExprs + Array + hasInitializer();
1596 arg_iterator placement_arg_end() {
1597 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1599 const_arg_iterator placement_arg_begin() const {
1600 return SubExprs + Array + hasInitializer();
1602 const_arg_iterator placement_arg_end() const {
1603 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1606 typedef Stmt **raw_arg_iterator;
1607 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1608 raw_arg_iterator raw_arg_end() {
1609 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1611 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1612 const_arg_iterator raw_arg_end() const {
1613 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1616 SourceLocation getStartLoc() const { return Range.getBegin(); }
1617 SourceLocation getEndLoc() const { return Range.getEnd(); }
1619 SourceRange getDirectInitRange() const { return DirectInitRange; }
1621 SourceRange getSourceRange() const LLVM_READONLY {
1625 static bool classof(const Stmt *T) {
1626 return T->getStmtClass() == CXXNewExprClass;
1630 child_range children() {
1631 return child_range(raw_arg_begin(), raw_arg_end());
1635 /// \brief Represents a \c delete expression for memory deallocation and
1636 /// destructor calls, e.g. "delete[] pArray".
1637 class CXXDeleteExpr : public Expr {
1638 // Points to the operator delete overload that is used. Could be a member.
1639 FunctionDecl *OperatorDelete;
1640 // The pointer expression to be deleted.
1642 // Location of the expression.
1644 // Is this a forced global delete, i.e. "::delete"?
1645 bool GlobalDelete : 1;
1646 // Is this the array form of delete, i.e. "delete[]"?
1648 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1649 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1651 bool ArrayFormAsWritten : 1;
1652 // Does the usual deallocation function for the element type require
1653 // a size_t argument?
1654 bool UsualArrayDeleteWantsSize : 1;
1656 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1657 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1658 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1659 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1660 arg->isInstantiationDependent(),
1661 arg->containsUnexpandedParameterPack()),
1662 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1663 GlobalDelete(globalDelete),
1664 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1665 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
1666 explicit CXXDeleteExpr(EmptyShell Shell)
1667 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1669 bool isGlobalDelete() const { return GlobalDelete; }
1670 bool isArrayForm() const { return ArrayForm; }
1671 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1673 /// Answers whether the usual array deallocation function for the
1674 /// allocated type expects the size of the allocation as a
1675 /// parameter. This can be true even if the actual deallocation
1676 /// function that we're using doesn't want a size.
1677 bool doesUsualArrayDeleteWantSize() const {
1678 return UsualArrayDeleteWantsSize;
1681 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1683 Expr *getArgument() { return cast<Expr>(Argument); }
1684 const Expr *getArgument() const { return cast<Expr>(Argument); }
1686 /// \brief Retrieve the type being destroyed. If the type being
1687 /// destroyed is a dependent type which may or may not be a pointer,
1688 /// return an invalid type.
1689 QualType getDestroyedType() const;
1691 SourceRange getSourceRange() const LLVM_READONLY {
1692 return SourceRange(Loc, Argument->getLocEnd());
1695 static bool classof(const Stmt *T) {
1696 return T->getStmtClass() == CXXDeleteExprClass;
1700 child_range children() { return child_range(&Argument, &Argument+1); }
1702 friend class ASTStmtReader;
1705 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
1706 class PseudoDestructorTypeStorage {
1707 /// \brief Either the type source information or the name of the type, if
1708 /// it couldn't be resolved due to type-dependence.
1709 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1711 /// \brief The starting source location of the pseudo-destructor type.
1712 SourceLocation Location;
1715 PseudoDestructorTypeStorage() { }
1717 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1718 : Type(II), Location(Loc) { }
1720 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1722 TypeSourceInfo *getTypeSourceInfo() const {
1723 return Type.dyn_cast<TypeSourceInfo *>();
1726 IdentifierInfo *getIdentifier() const {
1727 return Type.dyn_cast<IdentifierInfo *>();
1730 SourceLocation getLocation() const { return Location; }
1733 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1735 /// A pseudo-destructor is an expression that looks like a member access to a
1736 /// destructor of a scalar type, except that scalar types don't have
1737 /// destructors. For example:
1741 /// void f(int *p) {
1746 /// Pseudo-destructors typically occur when instantiating templates such as:
1749 /// template<typename T>
1750 /// void destroy(T* ptr) {
1755 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1756 /// beyond evaluating the base expression.
1757 class CXXPseudoDestructorExpr : public Expr {
1758 /// \brief The base expression (that is being destroyed).
1761 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1765 /// \brief The location of the '.' or '->' operator.
1766 SourceLocation OperatorLoc;
1768 /// \brief The nested-name-specifier that follows the operator, if present.
1769 NestedNameSpecifierLoc QualifierLoc;
1771 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1773 TypeSourceInfo *ScopeType;
1775 /// \brief The location of the '::' in a qualified pseudo-destructor
1777 SourceLocation ColonColonLoc;
1779 /// \brief The location of the '~'.
1780 SourceLocation TildeLoc;
1782 /// \brief The type being destroyed, or its name if we were unable to
1783 /// resolve the name.
1784 PseudoDestructorTypeStorage DestroyedType;
1786 friend class ASTStmtReader;
1789 CXXPseudoDestructorExpr(ASTContext &Context,
1790 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1791 NestedNameSpecifierLoc QualifierLoc,
1792 TypeSourceInfo *ScopeType,
1793 SourceLocation ColonColonLoc,
1794 SourceLocation TildeLoc,
1795 PseudoDestructorTypeStorage DestroyedType);
1797 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1798 : Expr(CXXPseudoDestructorExprClass, Shell),
1799 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1801 Expr *getBase() const { return cast<Expr>(Base); }
1803 /// \brief Determines whether this member expression actually had
1804 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1806 bool hasQualifier() const { return QualifierLoc; }
1808 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1809 /// with source-location information.
1810 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1812 /// \brief If the member name was qualified, retrieves the
1813 /// nested-name-specifier that precedes the member name. Otherwise, returns
1815 NestedNameSpecifier *getQualifier() const {
1816 return QualifierLoc.getNestedNameSpecifier();
1819 /// \brief Determine whether this pseudo-destructor expression was written
1820 /// using an '->' (otherwise, it used a '.').
1821 bool isArrow() const { return IsArrow; }
1823 /// \brief Retrieve the location of the '.' or '->' operator.
1824 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1826 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1829 /// Pseudo-destructor expressions can have extra qualification within them
1830 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1831 /// Here, if the object type of the expression is (or may be) a scalar type,
1832 /// \p T may also be a scalar type and, therefore, cannot be part of a
1833 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1834 /// destructor expression.
1835 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1837 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1839 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1841 /// \brief Retrieve the location of the '~'.
1842 SourceLocation getTildeLoc() const { return TildeLoc; }
1844 /// \brief Retrieve the source location information for the type
1845 /// being destroyed.
1847 /// This type-source information is available for non-dependent
1848 /// pseudo-destructor expressions and some dependent pseudo-destructor
1849 /// expressions. Returns NULL if we only have the identifier for a
1850 /// dependent pseudo-destructor expression.
1851 TypeSourceInfo *getDestroyedTypeInfo() const {
1852 return DestroyedType.getTypeSourceInfo();
1855 /// \brief In a dependent pseudo-destructor expression for which we do not
1856 /// have full type information on the destroyed type, provides the name
1857 /// of the destroyed type.
1858 IdentifierInfo *getDestroyedTypeIdentifier() const {
1859 return DestroyedType.getIdentifier();
1862 /// \brief Retrieve the type being destroyed.
1863 QualType getDestroyedType() const;
1865 /// \brief Retrieve the starting location of the type being destroyed.
1866 SourceLocation getDestroyedTypeLoc() const {
1867 return DestroyedType.getLocation();
1870 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1872 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1873 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1876 /// \brief Set the destroyed type.
1877 void setDestroyedType(TypeSourceInfo *Info) {
1878 DestroyedType = PseudoDestructorTypeStorage(Info);
1881 SourceRange getSourceRange() const LLVM_READONLY;
1883 static bool classof(const Stmt *T) {
1884 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1888 child_range children() { return child_range(&Base, &Base + 1); }
1891 /// \brief Represents a GCC or MS unary type trait, as used in the
1892 /// implementation of TR1/C++11 type trait templates.
1896 /// __is_pod(int) == true
1897 /// __is_enum(std::string) == false
1899 class UnaryTypeTraitExpr : public Expr {
1900 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1902 /// The value of the type trait. Unspecified if dependent.
1905 /// Loc - The location of the type trait keyword.
1908 /// RParen - The location of the closing paren.
1909 SourceLocation RParen;
1911 /// The type being queried.
1912 TypeSourceInfo *QueriedType;
1915 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1916 TypeSourceInfo *queried, bool value,
1917 SourceLocation rparen, QualType ty)
1918 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1919 false, queried->getType()->isDependentType(),
1920 queried->getType()->isInstantiationDependentType(),
1921 queried->getType()->containsUnexpandedParameterPack()),
1922 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1924 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1925 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1928 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
1930 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1932 QualType getQueriedType() const { return QueriedType->getType(); }
1934 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1936 bool getValue() const { return Value; }
1938 static bool classof(const Stmt *T) {
1939 return T->getStmtClass() == UnaryTypeTraitExprClass;
1943 child_range children() { return child_range(); }
1945 friend class ASTStmtReader;
1948 /// \brief Represents a GCC or MS binary type trait, as used in the
1949 /// implementation of TR1/C++11 type trait templates.
1953 /// __is_base_of(Base, Derived) == true
1955 class BinaryTypeTraitExpr : public Expr {
1956 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1959 /// The value of the type trait. Unspecified if dependent.
1962 /// Loc - The location of the type trait keyword.
1965 /// RParen - The location of the closing paren.
1966 SourceLocation RParen;
1968 /// The lhs type being queried.
1969 TypeSourceInfo *LhsType;
1971 /// The rhs type being queried.
1972 TypeSourceInfo *RhsType;
1975 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1976 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1977 bool value, SourceLocation rparen, QualType ty)
1978 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1979 lhsType->getType()->isDependentType() ||
1980 rhsType->getType()->isDependentType(),
1981 (lhsType->getType()->isInstantiationDependentType() ||
1982 rhsType->getType()->isInstantiationDependentType()),
1983 (lhsType->getType()->containsUnexpandedParameterPack() ||
1984 rhsType->getType()->containsUnexpandedParameterPack())),
1985 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1986 LhsType(lhsType), RhsType(rhsType) { }
1989 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1990 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1991 LhsType(), RhsType() { }
1993 SourceRange getSourceRange() const LLVM_READONLY {
1994 return SourceRange(Loc, RParen);
1997 BinaryTypeTrait getTrait() const {
1998 return static_cast<BinaryTypeTrait>(BTT);
2001 QualType getLhsType() const { return LhsType->getType(); }
2002 QualType getRhsType() const { return RhsType->getType(); }
2004 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
2005 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
2007 bool getValue() const { assert(!isTypeDependent()); return Value; }
2009 static bool classof(const Stmt *T) {
2010 return T->getStmtClass() == BinaryTypeTraitExprClass;
2014 child_range children() { return child_range(); }
2016 friend class ASTStmtReader;
2019 /// \brief A type trait used in the implementation of various C++11 and
2020 /// Library TR1 trait templates.
2023 /// __is_trivially_constructible(vector<int>, int*, int*)
2025 class TypeTraitExpr : public Expr {
2026 /// \brief The location of the type trait keyword.
2029 /// \brief The location of the closing parenthesis.
2030 SourceLocation RParenLoc;
2032 // Note: The TypeSourceInfos for the arguments are allocated after the
2035 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2036 ArrayRef<TypeSourceInfo *> Args,
2037 SourceLocation RParenLoc,
2040 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2042 /// \brief Retrieve the argument types.
2043 TypeSourceInfo **getTypeSourceInfos() {
2044 return reinterpret_cast<TypeSourceInfo **>(this+1);
2047 /// \brief Retrieve the argument types.
2048 TypeSourceInfo * const *getTypeSourceInfos() const {
2049 return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2053 /// \brief Create a new type trait expression.
2054 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
2056 ArrayRef<TypeSourceInfo *> Args,
2057 SourceLocation RParenLoc,
2060 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
2062 /// \brief Determine which type trait this expression uses.
2063 TypeTrait getTrait() const {
2064 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2067 bool getValue() const {
2068 assert(!isValueDependent());
2069 return TypeTraitExprBits.Value;
2072 /// \brief Determine the number of arguments to this type trait.
2073 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2075 /// \brief Retrieve the Ith argument.
2076 TypeSourceInfo *getArg(unsigned I) const {
2077 assert(I < getNumArgs() && "Argument out-of-range");
2078 return getArgs()[I];
2081 /// \brief Retrieve the argument types.
2082 ArrayRef<TypeSourceInfo *> getArgs() const {
2083 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
2086 typedef TypeSourceInfo **arg_iterator;
2087 arg_iterator arg_begin() {
2088 return getTypeSourceInfos();
2090 arg_iterator arg_end() {
2091 return getTypeSourceInfos() + getNumArgs();
2094 typedef TypeSourceInfo const * const *arg_const_iterator;
2095 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
2096 arg_const_iterator arg_end() const {
2097 return getTypeSourceInfos() + getNumArgs();
2100 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); }
2102 static bool classof(const Stmt *T) {
2103 return T->getStmtClass() == TypeTraitExprClass;
2107 child_range children() { return child_range(); }
2109 friend class ASTStmtReader;
2110 friend class ASTStmtWriter;
2114 /// \brief An Embarcadero array type trait, as used in the implementation of
2115 /// __array_rank and __array_extent.
2119 /// __array_rank(int[10][20]) == 2
2120 /// __array_extent(int, 1) == 20
2122 class ArrayTypeTraitExpr : public Expr {
2123 virtual void anchor();
2125 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2128 /// \brief The value of the type trait. Unspecified if dependent.
2131 /// \brief The array dimension being queried, or -1 if not used.
2134 /// \brief The location of the type trait keyword.
2137 /// \brief The location of the closing paren.
2138 SourceLocation RParen;
2140 /// \brief The type being queried.
2141 TypeSourceInfo *QueriedType;
2144 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2145 TypeSourceInfo *queried, uint64_t value,
2146 Expr *dimension, SourceLocation rparen, QualType ty)
2147 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2148 false, queried->getType()->isDependentType(),
2149 (queried->getType()->isInstantiationDependentType() ||
2150 (dimension && dimension->isInstantiationDependent())),
2151 queried->getType()->containsUnexpandedParameterPack()),
2152 ATT(att), Value(value), Dimension(dimension),
2153 Loc(loc), RParen(rparen), QueriedType(queried) { }
2156 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2157 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2160 virtual ~ArrayTypeTraitExpr() { }
2162 virtual SourceRange getSourceRange() const LLVM_READONLY {
2163 return SourceRange(Loc, RParen);
2166 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2168 QualType getQueriedType() const { return QueriedType->getType(); }
2170 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2172 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2174 Expr *getDimensionExpression() const { return Dimension; }
2176 static bool classof(const Stmt *T) {
2177 return T->getStmtClass() == ArrayTypeTraitExprClass;
2181 child_range children() { return child_range(); }
2183 friend class ASTStmtReader;
2186 /// \brief An expression trait intrinsic.
2190 /// __is_lvalue_expr(std::cout) == true
2191 /// __is_lvalue_expr(1) == false
2193 class ExpressionTraitExpr : public Expr {
2194 /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned.
2196 /// \brief The value of the type trait. Unspecified if dependent.
2199 /// \brief The location of the type trait keyword.
2202 /// \brief The location of the closing paren.
2203 SourceLocation RParen;
2205 /// \brief The expression being queried.
2206 Expr* QueriedExpression;
2208 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2209 Expr *queried, bool value,
2210 SourceLocation rparen, QualType resultType)
2211 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2212 false, // Not type-dependent
2213 // Value-dependent if the argument is type-dependent.
2214 queried->isTypeDependent(),
2215 queried->isInstantiationDependent(),
2216 queried->containsUnexpandedParameterPack()),
2217 ET(et), Value(value), Loc(loc), RParen(rparen),
2218 QueriedExpression(queried) { }
2220 explicit ExpressionTraitExpr(EmptyShell Empty)
2221 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2222 QueriedExpression() { }
2224 SourceRange getSourceRange() const LLVM_READONLY {
2225 return SourceRange(Loc, RParen);
2228 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2230 Expr *getQueriedExpression() const { return QueriedExpression; }
2232 bool getValue() const { return Value; }
2234 static bool classof(const Stmt *T) {
2235 return T->getStmtClass() == ExpressionTraitExprClass;
2239 child_range children() { return child_range(); }
2241 friend class ASTStmtReader;
2245 /// \brief A reference to an overloaded function set, either an
2246 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2247 class OverloadExpr : public Expr {
2248 /// \brief The common name of these declarations.
2249 DeclarationNameInfo NameInfo;
2251 /// \brief The nested-name-specifier that qualifies the name, if any.
2252 NestedNameSpecifierLoc QualifierLoc;
2254 /// The results. These are undesugared, which is to say, they may
2255 /// include UsingShadowDecls. Access is relative to the naming
2257 // FIXME: Allocate this data after the OverloadExpr subclass.
2258 DeclAccessPair *Results;
2259 unsigned NumResults;
2262 /// \brief Whether the name includes info for explicit template
2263 /// keyword and arguments.
2264 bool HasTemplateKWAndArgsInfo;
2266 /// \brief Return the optional template keyword and arguments info.
2267 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2269 /// \brief Return the optional template keyword and arguments info.
2270 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2271 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2274 OverloadExpr(StmtClass K, ASTContext &C,
2275 NestedNameSpecifierLoc QualifierLoc,
2276 SourceLocation TemplateKWLoc,
2277 const DeclarationNameInfo &NameInfo,
2278 const TemplateArgumentListInfo *TemplateArgs,
2279 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2280 bool KnownDependent,
2281 bool KnownInstantiationDependent,
2282 bool KnownContainsUnexpandedParameterPack);
2284 OverloadExpr(StmtClass K, EmptyShell Empty)
2285 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2286 HasTemplateKWAndArgsInfo(false) { }
2288 void initializeResults(ASTContext &C,
2289 UnresolvedSetIterator Begin,
2290 UnresolvedSetIterator End);
2294 OverloadExpr *Expression;
2295 bool IsAddressOfOperand;
2296 bool HasFormOfMemberPointer;
2299 /// Finds the overloaded expression in the given expression of
2302 /// \return the expression (which must be there) and true if it has
2303 /// the particular form of a member pointer expression
2304 static FindResult find(Expr *E) {
2305 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2309 E = E->IgnoreParens();
2310 if (isa<UnaryOperator>(E)) {
2311 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2312 E = cast<UnaryOperator>(E)->getSubExpr();
2313 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2315 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2316 Result.IsAddressOfOperand = true;
2317 Result.Expression = Ovl;
2319 Result.HasFormOfMemberPointer = false;
2320 Result.IsAddressOfOperand = false;
2321 Result.Expression = cast<OverloadExpr>(E);
2327 /// \brief Gets the naming class of this lookup, if any.
2328 CXXRecordDecl *getNamingClass() const;
2330 typedef UnresolvedSetImpl::iterator decls_iterator;
2331 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2332 decls_iterator decls_end() const {
2333 return UnresolvedSetIterator(Results + NumResults);
2336 /// \brief Gets the number of declarations in the unresolved set.
2337 unsigned getNumDecls() const { return NumResults; }
2339 /// \brief Gets the full name info.
2340 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2342 /// \brief Gets the name looked up.
2343 DeclarationName getName() const { return NameInfo.getName(); }
2345 /// \brief Gets the location of the name.
2346 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2348 /// \brief Fetches the nested-name qualifier, if one was given.
2349 NestedNameSpecifier *getQualifier() const {
2350 return QualifierLoc.getNestedNameSpecifier();
2353 /// \brief Fetches the nested-name qualifier with source-location
2354 /// information, if one was given.
2355 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2357 /// \brief Retrieve the location of the template keyword preceding
2358 /// this name, if any.
2359 SourceLocation getTemplateKeywordLoc() const {
2360 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2361 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2364 /// \brief Retrieve the location of the left angle bracket starting the
2365 /// explicit template argument list following the name, if any.
2366 SourceLocation getLAngleLoc() const {
2367 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2368 return getTemplateKWAndArgsInfo()->LAngleLoc;
2371 /// \brief Retrieve the location of the right angle bracket ending the
2372 /// explicit template argument list following the name, if any.
2373 SourceLocation getRAngleLoc() const {
2374 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2375 return getTemplateKWAndArgsInfo()->RAngleLoc;
2378 /// \brief Determines whether the name was preceded by the template keyword.
2379 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2381 /// \brief Determines whether this expression had explicit template arguments.
2382 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2384 // Note that, inconsistently with the explicit-template-argument AST
2385 // nodes, users are *forbidden* from calling these methods on objects
2386 // without explicit template arguments.
2388 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2389 assert(hasExplicitTemplateArgs());
2390 return *getTemplateKWAndArgsInfo();
2393 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2394 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2397 TemplateArgumentLoc const *getTemplateArgs() const {
2398 return getExplicitTemplateArgs().getTemplateArgs();
2401 unsigned getNumTemplateArgs() const {
2402 return getExplicitTemplateArgs().NumTemplateArgs;
2405 /// \brief Copies the template arguments into the given structure.
2406 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2407 getExplicitTemplateArgs().copyInto(List);
2410 /// \brief Retrieves the optional explicit template arguments.
2412 /// This points to the same data as getExplicitTemplateArgs(), but
2413 /// returns null if there are no explicit template arguments.
2414 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2415 if (!hasExplicitTemplateArgs()) return 0;
2416 return &getExplicitTemplateArgs();
2419 static bool classof(const Stmt *T) {
2420 return T->getStmtClass() == UnresolvedLookupExprClass ||
2421 T->getStmtClass() == UnresolvedMemberExprClass;
2424 friend class ASTStmtReader;
2425 friend class ASTStmtWriter;
2428 /// \brief A reference to a name which we were able to look up during
2429 /// parsing but could not resolve to a specific declaration.
2431 /// This arises in several ways:
2432 /// * we might be waiting for argument-dependent lookup
2433 /// * the name might resolve to an overloaded function
2435 /// * the lookup might have included a function template
2436 /// These never include UnresolvedUsingValueDecls, which are always class
2437 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2438 class UnresolvedLookupExpr : public OverloadExpr {
2439 /// True if these lookup results should be extended by
2440 /// argument-dependent lookup if this is the operand of a function
2444 /// True if these lookup results are overloaded. This is pretty
2445 /// trivially rederivable if we urgently need to kill this field.
2448 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2449 /// any. This can generally be recalculated from the context chain,
2450 /// but that can be fairly expensive for unqualified lookups. If we
2451 /// want to improve memory use here, this could go in a union
2452 /// against the qualified-lookup bits.
2453 CXXRecordDecl *NamingClass;
2455 UnresolvedLookupExpr(ASTContext &C,
2456 CXXRecordDecl *NamingClass,
2457 NestedNameSpecifierLoc QualifierLoc,
2458 SourceLocation TemplateKWLoc,
2459 const DeclarationNameInfo &NameInfo,
2460 bool RequiresADL, bool Overloaded,
2461 const TemplateArgumentListInfo *TemplateArgs,
2462 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2463 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2464 NameInfo, TemplateArgs, Begin, End, false, false, false),
2465 RequiresADL(RequiresADL),
2466 Overloaded(Overloaded), NamingClass(NamingClass)
2469 UnresolvedLookupExpr(EmptyShell Empty)
2470 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2471 RequiresADL(false), Overloaded(false), NamingClass(0)
2474 friend class ASTStmtReader;
2477 static UnresolvedLookupExpr *Create(ASTContext &C,
2478 CXXRecordDecl *NamingClass,
2479 NestedNameSpecifierLoc QualifierLoc,
2480 const DeclarationNameInfo &NameInfo,
2481 bool ADL, bool Overloaded,
2482 UnresolvedSetIterator Begin,
2483 UnresolvedSetIterator End) {
2484 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2485 SourceLocation(), NameInfo,
2486 ADL, Overloaded, 0, Begin, End);
2489 static UnresolvedLookupExpr *Create(ASTContext &C,
2490 CXXRecordDecl *NamingClass,
2491 NestedNameSpecifierLoc QualifierLoc,
2492 SourceLocation TemplateKWLoc,
2493 const DeclarationNameInfo &NameInfo,
2495 const TemplateArgumentListInfo *Args,
2496 UnresolvedSetIterator Begin,
2497 UnresolvedSetIterator End);
2499 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2500 bool HasTemplateKWAndArgsInfo,
2501 unsigned NumTemplateArgs);
2503 /// True if this declaration should be extended by
2504 /// argument-dependent lookup.
2505 bool requiresADL() const { return RequiresADL; }
2507 /// True if this lookup is overloaded.
2508 bool isOverloaded() const { return Overloaded; }
2510 /// Gets the 'naming class' (in the sense of C++0x
2511 /// [class.access.base]p5) of the lookup. This is the scope
2512 /// that was looked in to find these results.
2513 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2515 SourceRange getSourceRange() const LLVM_READONLY {
2516 SourceRange Range(getNameInfo().getSourceRange());
2517 if (getQualifierLoc())
2518 Range.setBegin(getQualifierLoc().getBeginLoc());
2519 if (hasExplicitTemplateArgs())
2520 Range.setEnd(getRAngleLoc());
2524 child_range children() { return child_range(); }
2526 static bool classof(const Stmt *T) {
2527 return T->getStmtClass() == UnresolvedLookupExprClass;
2531 /// \brief A qualified reference to a name whose declaration cannot
2532 /// yet be resolved.
2534 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2535 /// it expresses a reference to a declaration such as
2536 /// X<T>::value. The difference, however, is that an
2537 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2538 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2539 /// this case, X<T>::value cannot resolve to a declaration because the
2540 /// declaration will differ from on instantiation of X<T> to the
2541 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2542 /// qualifier (X<T>::) and the name of the entity being referenced
2543 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2544 /// declaration can be found.
2545 class DependentScopeDeclRefExpr : public Expr {
2546 /// \brief The nested-name-specifier that qualifies this unresolved
2547 /// declaration name.
2548 NestedNameSpecifierLoc QualifierLoc;
2550 /// The name of the entity we will be referencing.
2551 DeclarationNameInfo NameInfo;
2553 /// \brief Whether the name includes info for explicit template
2554 /// keyword and arguments.
2555 bool HasTemplateKWAndArgsInfo;
2557 /// \brief Return the optional template keyword and arguments info.
2558 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2559 if (!HasTemplateKWAndArgsInfo) return 0;
2560 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2562 /// \brief Return the optional template keyword and arguments info.
2563 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2564 return const_cast<DependentScopeDeclRefExpr*>(this)
2565 ->getTemplateKWAndArgsInfo();
2568 DependentScopeDeclRefExpr(QualType T,
2569 NestedNameSpecifierLoc QualifierLoc,
2570 SourceLocation TemplateKWLoc,
2571 const DeclarationNameInfo &NameInfo,
2572 const TemplateArgumentListInfo *Args);
2575 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2576 NestedNameSpecifierLoc QualifierLoc,
2577 SourceLocation TemplateKWLoc,
2578 const DeclarationNameInfo &NameInfo,
2579 const TemplateArgumentListInfo *TemplateArgs);
2581 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2582 bool HasTemplateKWAndArgsInfo,
2583 unsigned NumTemplateArgs);
2585 /// \brief Retrieve the name that this expression refers to.
2586 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2588 /// \brief Retrieve the name that this expression refers to.
2589 DeclarationName getDeclName() const { return NameInfo.getName(); }
2591 /// \brief Retrieve the location of the name within the expression.
2592 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2594 /// \brief Retrieve the nested-name-specifier that qualifies the
2595 /// name, with source location information.
2596 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2599 /// \brief Retrieve the nested-name-specifier that qualifies this
2601 NestedNameSpecifier *getQualifier() const {
2602 return QualifierLoc.getNestedNameSpecifier();
2605 /// \brief Retrieve the location of the template keyword preceding
2606 /// this name, if any.
2607 SourceLocation getTemplateKeywordLoc() const {
2608 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2609 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2612 /// \brief Retrieve the location of the left angle bracket starting the
2613 /// explicit template argument list following the name, if any.
2614 SourceLocation getLAngleLoc() const {
2615 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2616 return getTemplateKWAndArgsInfo()->LAngleLoc;
2619 /// \brief Retrieve the location of the right angle bracket ending the
2620 /// explicit template argument list following the name, if any.
2621 SourceLocation getRAngleLoc() const {
2622 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2623 return getTemplateKWAndArgsInfo()->RAngleLoc;
2626 /// Determines whether the name was preceded by the template keyword.
2627 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2629 /// Determines whether this lookup had explicit template arguments.
2630 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2632 // Note that, inconsistently with the explicit-template-argument AST
2633 // nodes, users are *forbidden* from calling these methods on objects
2634 // without explicit template arguments.
2636 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2637 assert(hasExplicitTemplateArgs());
2638 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2641 /// Gets a reference to the explicit template argument list.
2642 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2643 assert(hasExplicitTemplateArgs());
2644 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2647 /// \brief Retrieves the optional explicit template arguments.
2648 /// This points to the same data as getExplicitTemplateArgs(), but
2649 /// returns null if there are no explicit template arguments.
2650 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2651 if (!hasExplicitTemplateArgs()) return 0;
2652 return &getExplicitTemplateArgs();
2655 /// \brief Copies the template arguments (if present) into the given
2657 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2658 getExplicitTemplateArgs().copyInto(List);
2661 TemplateArgumentLoc const *getTemplateArgs() const {
2662 return getExplicitTemplateArgs().getTemplateArgs();
2665 unsigned getNumTemplateArgs() const {
2666 return getExplicitTemplateArgs().NumTemplateArgs;
2669 SourceRange getSourceRange() const LLVM_READONLY {
2670 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2671 if (hasExplicitTemplateArgs())
2672 Range.setEnd(getRAngleLoc());
2676 static bool classof(const Stmt *T) {
2677 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2680 child_range children() { return child_range(); }
2682 friend class ASTStmtReader;
2683 friend class ASTStmtWriter;
2686 /// Represents an expression --- generally a full-expression --- which
2687 /// introduces cleanups to be run at the end of the sub-expression's
2688 /// evaluation. The most common source of expression-introduced
2689 /// cleanups is temporary objects in C++, but several other kinds of
2690 /// expressions can create cleanups, including basically every
2691 /// call in ARC that returns an Objective-C pointer.
2693 /// This expression also tracks whether the sub-expression contains a
2694 /// potentially-evaluated block literal. The lifetime of a block
2695 /// literal is the extent of the enclosing scope.
2696 class ExprWithCleanups : public Expr {
2698 /// The type of objects that are kept in the cleanup.
2699 /// It's useful to remember the set of blocks; we could also
2700 /// remember the set of temporaries, but there's currently
2702 typedef BlockDecl *CleanupObject;
2707 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2708 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2710 CleanupObject *getObjectsBuffer() {
2711 return reinterpret_cast<CleanupObject*>(this + 1);
2713 const CleanupObject *getObjectsBuffer() const {
2714 return reinterpret_cast<const CleanupObject*>(this + 1);
2716 friend class ASTStmtReader;
2719 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
2720 unsigned numObjects);
2722 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
2723 ArrayRef<CleanupObject> objects);
2725 ArrayRef<CleanupObject> getObjects() const {
2726 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2729 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2731 CleanupObject getObject(unsigned i) const {
2732 assert(i < getNumObjects() && "Index out of range");
2733 return getObjects()[i];
2736 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2737 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2739 /// setSubExpr - As with any mutator of the AST, be very careful
2740 /// when modifying an existing AST to preserve its invariants.
2741 void setSubExpr(Expr *E) { SubExpr = E; }
2743 SourceRange getSourceRange() const LLVM_READONLY {
2744 return SubExpr->getSourceRange();
2747 // Implement isa/cast/dyncast/etc.
2748 static bool classof(const Stmt *T) {
2749 return T->getStmtClass() == ExprWithCleanupsClass;
2753 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2756 /// \brief Describes an explicit type conversion that uses functional
2757 /// notion but could not be resolved because one or more arguments are
2760 /// The explicit type conversions expressed by
2761 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2762 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2763 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2764 /// type-dependent. For example, this would occur in a template such
2768 /// template<typename T, typename A1>
2769 /// inline T make_a(const A1& a1) {
2774 /// When the returned expression is instantiated, it may resolve to a
2775 /// constructor call, conversion function call, or some kind of type
2777 class CXXUnresolvedConstructExpr : public Expr {
2778 /// \brief The type being constructed.
2779 TypeSourceInfo *Type;
2781 /// \brief The location of the left parentheses ('(').
2782 SourceLocation LParenLoc;
2784 /// \brief The location of the right parentheses (')').
2785 SourceLocation RParenLoc;
2787 /// \brief The number of arguments used to construct the type.
2790 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2791 SourceLocation LParenLoc,
2792 ArrayRef<Expr*> Args,
2793 SourceLocation RParenLoc);
2795 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2796 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2798 friend class ASTStmtReader;
2801 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2802 TypeSourceInfo *Type,
2803 SourceLocation LParenLoc,
2804 ArrayRef<Expr*> Args,
2805 SourceLocation RParenLoc);
2807 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2810 /// \brief Retrieve the type that is being constructed, as specified
2811 /// in the source code.
2812 QualType getTypeAsWritten() const { return Type->getType(); }
2814 /// \brief Retrieve the type source information for the type being
2816 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2818 /// \brief Retrieve the location of the left parentheses ('(') that
2819 /// precedes the argument list.
2820 SourceLocation getLParenLoc() const { return LParenLoc; }
2821 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2823 /// \brief Retrieve the location of the right parentheses (')') that
2824 /// follows the argument list.
2825 SourceLocation getRParenLoc() const { return RParenLoc; }
2826 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2828 /// \brief Retrieve the number of arguments.
2829 unsigned arg_size() const { return NumArgs; }
2831 typedef Expr** arg_iterator;
2832 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2833 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2835 typedef const Expr* const * const_arg_iterator;
2836 const_arg_iterator arg_begin() const {
2837 return reinterpret_cast<const Expr* const *>(this + 1);
2839 const_arg_iterator arg_end() const {
2840 return arg_begin() + NumArgs;
2843 Expr *getArg(unsigned I) {
2844 assert(I < NumArgs && "Argument index out-of-range");
2845 return *(arg_begin() + I);
2848 const Expr *getArg(unsigned I) const {
2849 assert(I < NumArgs && "Argument index out-of-range");
2850 return *(arg_begin() + I);
2853 void setArg(unsigned I, Expr *E) {
2854 assert(I < NumArgs && "Argument index out-of-range");
2855 *(arg_begin() + I) = E;
2858 SourceRange getSourceRange() const LLVM_READONLY;
2860 static bool classof(const Stmt *T) {
2861 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2865 child_range children() {
2866 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2867 return child_range(begin, begin + NumArgs);
2871 /// \brief Represents a C++ member access expression where the actual
2872 /// member referenced could not be resolved because the base
2873 /// expression or the member name was dependent.
2875 /// Like UnresolvedMemberExprs, these can be either implicit or
2876 /// explicit accesses. It is only possible to get one of these with
2877 /// an implicit access if a qualifier is provided.
2878 class CXXDependentScopeMemberExpr : public Expr {
2879 /// \brief The expression for the base pointer or class reference,
2880 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2883 /// \brief The type of the base expression. Never null, even for
2884 /// implicit accesses.
2887 /// \brief Whether this member expression used the '->' operator or
2888 /// the '.' operator.
2891 /// \brief Whether this member expression has info for explicit template
2892 /// keyword and arguments.
2893 bool HasTemplateKWAndArgsInfo : 1;
2895 /// \brief The location of the '->' or '.' operator.
2896 SourceLocation OperatorLoc;
2898 /// \brief The nested-name-specifier that precedes the member name, if any.
2899 NestedNameSpecifierLoc QualifierLoc;
2901 /// \brief In a qualified member access expression such as t->Base::f, this
2902 /// member stores the resolves of name lookup in the context of the member
2903 /// access expression, to be used at instantiation time.
2905 /// FIXME: This member, along with the QualifierLoc, could
2906 /// be stuck into a structure that is optionally allocated at the end of
2907 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2908 NamedDecl *FirstQualifierFoundInScope;
2910 /// \brief The member to which this member expression refers, which
2911 /// can be name, overloaded operator, or destructor.
2912 /// FIXME: could also be a template-id
2913 DeclarationNameInfo MemberNameInfo;
2915 /// \brief Return the optional template keyword and arguments info.
2916 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2917 if (!HasTemplateKWAndArgsInfo) return 0;
2918 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2920 /// \brief Return the optional template keyword and arguments info.
2921 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2922 return const_cast<CXXDependentScopeMemberExpr*>(this)
2923 ->getTemplateKWAndArgsInfo();
2926 CXXDependentScopeMemberExpr(ASTContext &C,
2927 Expr *Base, QualType BaseType, bool IsArrow,
2928 SourceLocation OperatorLoc,
2929 NestedNameSpecifierLoc QualifierLoc,
2930 SourceLocation TemplateKWLoc,
2931 NamedDecl *FirstQualifierFoundInScope,
2932 DeclarationNameInfo MemberNameInfo,
2933 const TemplateArgumentListInfo *TemplateArgs);
2936 CXXDependentScopeMemberExpr(ASTContext &C,
2937 Expr *Base, QualType BaseType,
2939 SourceLocation OperatorLoc,
2940 NestedNameSpecifierLoc QualifierLoc,
2941 NamedDecl *FirstQualifierFoundInScope,
2942 DeclarationNameInfo MemberNameInfo);
2944 static CXXDependentScopeMemberExpr *
2945 Create(ASTContext &C,
2946 Expr *Base, QualType BaseType, bool IsArrow,
2947 SourceLocation OperatorLoc,
2948 NestedNameSpecifierLoc QualifierLoc,
2949 SourceLocation TemplateKWLoc,
2950 NamedDecl *FirstQualifierFoundInScope,
2951 DeclarationNameInfo MemberNameInfo,
2952 const TemplateArgumentListInfo *TemplateArgs);
2954 static CXXDependentScopeMemberExpr *
2955 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2956 unsigned NumTemplateArgs);
2958 /// \brief True if this is an implicit access, i.e. one in which the
2959 /// member being accessed was not written in the source. The source
2960 /// location of the operator is invalid in this case.
2961 bool isImplicitAccess() const;
2963 /// \brief Retrieve the base object of this member expressions,
2964 /// e.g., the \c x in \c x.m.
2965 Expr *getBase() const {
2966 assert(!isImplicitAccess());
2967 return cast<Expr>(Base);
2970 QualType getBaseType() const { return BaseType; }
2972 /// \brief Determine whether this member expression used the '->'
2973 /// operator; otherwise, it used the '.' operator.
2974 bool isArrow() const { return IsArrow; }
2976 /// \brief Retrieve the location of the '->' or '.' operator.
2977 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2979 /// \brief Retrieve the nested-name-specifier that qualifies the member
2981 NestedNameSpecifier *getQualifier() const {
2982 return QualifierLoc.getNestedNameSpecifier();
2985 /// \brief Retrieve the nested-name-specifier that qualifies the member
2986 /// name, with source location information.
2987 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2990 /// \brief Retrieve the first part of the nested-name-specifier that was
2991 /// found in the scope of the member access expression when the member access
2992 /// was initially parsed.
2994 /// This function only returns a useful result when member access expression
2995 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2996 /// returned by this function describes what was found by unqualified name
2997 /// lookup for the identifier "Base" within the scope of the member access
2998 /// expression itself. At template instantiation time, this information is
2999 /// combined with the results of name lookup into the type of the object
3000 /// expression itself (the class type of x).
3001 NamedDecl *getFirstQualifierFoundInScope() const {
3002 return FirstQualifierFoundInScope;
3005 /// \brief Retrieve the name of the member that this expression
3007 const DeclarationNameInfo &getMemberNameInfo() const {
3008 return MemberNameInfo;
3011 /// \brief Retrieve the name of the member that this expression
3013 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3015 // \brief Retrieve the location of the name of the member that this
3016 // expression refers to.
3017 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3019 /// \brief Retrieve the location of the template keyword preceding the
3020 /// member name, if any.
3021 SourceLocation getTemplateKeywordLoc() const {
3022 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3023 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3026 /// \brief Retrieve the location of the left angle bracket starting the
3027 /// explicit template argument list following the member name, if any.
3028 SourceLocation getLAngleLoc() const {
3029 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3030 return getTemplateKWAndArgsInfo()->LAngleLoc;
3033 /// \brief Retrieve the location of the right angle bracket ending the
3034 /// explicit template argument list following the member name, if any.
3035 SourceLocation getRAngleLoc() const {
3036 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3037 return getTemplateKWAndArgsInfo()->RAngleLoc;
3040 /// Determines whether the member name was preceded by the template keyword.
3041 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3043 /// \brief Determines whether this member expression actually had a C++
3044 /// template argument list explicitly specified, e.g., x.f<int>.
3045 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3047 /// \brief Retrieve the explicit template argument list that followed the
3048 /// member template name, if any.
3049 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3050 assert(hasExplicitTemplateArgs());
3051 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3054 /// \brief Retrieve the explicit template argument list that followed the
3055 /// member template name, if any.
3056 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3057 return const_cast<CXXDependentScopeMemberExpr *>(this)
3058 ->getExplicitTemplateArgs();
3061 /// \brief Retrieves the optional explicit template arguments.
3062 /// This points to the same data as getExplicitTemplateArgs(), but
3063 /// returns null if there are no explicit template arguments.
3064 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
3065 if (!hasExplicitTemplateArgs()) return 0;
3066 return &getExplicitTemplateArgs();
3069 /// \brief Copies the template arguments (if present) into the given
3071 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3072 getExplicitTemplateArgs().copyInto(List);
3075 /// \brief Initializes the template arguments using the given structure.
3076 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3077 getExplicitTemplateArgs().initializeFrom(List);
3080 /// \brief Retrieve the template arguments provided as part of this
3082 const TemplateArgumentLoc *getTemplateArgs() const {
3083 return getExplicitTemplateArgs().getTemplateArgs();
3086 /// \brief Retrieve the number of template arguments provided as part of this
3088 unsigned getNumTemplateArgs() const {
3089 return getExplicitTemplateArgs().NumTemplateArgs;
3092 SourceRange getSourceRange() const LLVM_READONLY {
3094 if (!isImplicitAccess())
3095 Range.setBegin(Base->getSourceRange().getBegin());
3096 else if (getQualifier())
3097 Range.setBegin(getQualifierLoc().getBeginLoc());
3099 Range.setBegin(MemberNameInfo.getBeginLoc());
3101 if (hasExplicitTemplateArgs())
3102 Range.setEnd(getRAngleLoc());
3104 Range.setEnd(MemberNameInfo.getEndLoc());
3108 static bool classof(const Stmt *T) {
3109 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3113 child_range children() {
3114 if (isImplicitAccess()) return child_range();
3115 return child_range(&Base, &Base + 1);
3118 friend class ASTStmtReader;
3119 friend class ASTStmtWriter;
3122 /// \brief Represents a C++ member access expression for which lookup
3123 /// produced a set of overloaded functions.
3125 /// The member access may be explicit or implicit:
3128 /// int explicitAccess() { return this->a + this->A::b; }
3129 /// int implicitAccess() { return a + A::b; }
3132 /// In the final AST, an explicit access always becomes a MemberExpr.
3133 /// An implicit access may become either a MemberExpr or a
3134 /// DeclRefExpr, depending on whether the member is static.
3135 class UnresolvedMemberExpr : public OverloadExpr {
3136 /// \brief Whether this member expression used the '->' operator or
3137 /// the '.' operator.
3140 /// \brief Whether the lookup results contain an unresolved using
3142 bool HasUnresolvedUsing : 1;
3144 /// \brief The expression for the base pointer or class reference,
3145 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
3146 /// member expression
3149 /// \brief The type of the base expression; never null.
3152 /// \brief The location of the '->' or '.' operator.
3153 SourceLocation OperatorLoc;
3155 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3156 Expr *Base, QualType BaseType, bool IsArrow,
3157 SourceLocation OperatorLoc,
3158 NestedNameSpecifierLoc QualifierLoc,
3159 SourceLocation TemplateKWLoc,
3160 const DeclarationNameInfo &MemberNameInfo,
3161 const TemplateArgumentListInfo *TemplateArgs,
3162 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3164 UnresolvedMemberExpr(EmptyShell Empty)
3165 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3166 HasUnresolvedUsing(false), Base(0) { }
3168 friend class ASTStmtReader;
3171 static UnresolvedMemberExpr *
3172 Create(ASTContext &C, bool HasUnresolvedUsing,
3173 Expr *Base, QualType BaseType, bool IsArrow,
3174 SourceLocation OperatorLoc,
3175 NestedNameSpecifierLoc QualifierLoc,
3176 SourceLocation TemplateKWLoc,
3177 const DeclarationNameInfo &MemberNameInfo,
3178 const TemplateArgumentListInfo *TemplateArgs,
3179 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3181 static UnresolvedMemberExpr *
3182 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3183 unsigned NumTemplateArgs);
3185 /// \brief True if this is an implicit access, i.e. one in which the
3186 /// member being accessed was not written in the source. The source
3187 /// location of the operator is invalid in this case.
3188 bool isImplicitAccess() const;
3190 /// \brief Retrieve the base object of this member expressions,
3191 /// e.g., the \c x in \c x.m.
3193 assert(!isImplicitAccess());
3194 return cast<Expr>(Base);
3196 const Expr *getBase() const {
3197 assert(!isImplicitAccess());
3198 return cast<Expr>(Base);
3201 QualType getBaseType() const { return BaseType; }
3203 /// \brief Determine whether the lookup results contain an unresolved using
3205 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3207 /// \brief Determine whether this member expression used the '->'
3208 /// operator; otherwise, it used the '.' operator.
3209 bool isArrow() const { return IsArrow; }
3211 /// \brief Retrieve the location of the '->' or '.' operator.
3212 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3214 /// \brief Retrieves the naming class of this lookup.
3215 CXXRecordDecl *getNamingClass() const;
3217 /// \brief Retrieve the full name info for the member that this expression
3219 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3221 /// \brief Retrieve the name of the member that this expression
3223 DeclarationName getMemberName() const { return getName(); }
3225 // \brief Retrieve the location of the name of the member that this
3226 // expression refers to.
3227 SourceLocation getMemberLoc() const { return getNameLoc(); }
3229 SourceRange getSourceRange() const LLVM_READONLY {
3230 SourceRange Range = getMemberNameInfo().getSourceRange();
3231 if (!isImplicitAccess())
3232 Range.setBegin(Base->getSourceRange().getBegin());
3233 else if (getQualifierLoc())
3234 Range.setBegin(getQualifierLoc().getBeginLoc());
3236 if (hasExplicitTemplateArgs())
3237 Range.setEnd(getRAngleLoc());
3241 static bool classof(const Stmt *T) {
3242 return T->getStmtClass() == UnresolvedMemberExprClass;
3246 child_range children() {
3247 if (isImplicitAccess()) return child_range();
3248 return child_range(&Base, &Base + 1);
3252 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
3254 /// The noexcept expression tests whether a given expression might throw. Its
3255 /// result is a boolean constant.
3256 class CXXNoexceptExpr : public Expr {
3261 friend class ASTStmtReader;
3264 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3265 SourceLocation Keyword, SourceLocation RParen)
3266 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3267 /*TypeDependent*/false,
3268 /*ValueDependent*/Val == CT_Dependent,
3269 Val == CT_Dependent || Operand->isInstantiationDependent(),
3270 Operand->containsUnexpandedParameterPack()),
3271 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3274 CXXNoexceptExpr(EmptyShell Empty)
3275 : Expr(CXXNoexceptExprClass, Empty)
3278 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3280 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3282 bool getValue() const { return Value; }
3284 static bool classof(const Stmt *T) {
3285 return T->getStmtClass() == CXXNoexceptExprClass;
3289 child_range children() { return child_range(&Operand, &Operand + 1); }
3292 /// \brief Represents a C++0x pack expansion that produces a sequence of
3295 /// A pack expansion expression contains a pattern (which itself is an
3296 /// expression) followed by an ellipsis. For example:
3299 /// template<typename F, typename ...Types>
3300 /// void forward(F f, Types &&...args) {
3301 /// f(static_cast<Types&&>(args)...);
3305 /// Here, the argument to the function object \c f is a pack expansion whose
3306 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3307 /// template is instantiated, the pack expansion will instantiate to zero or
3308 /// or more function arguments to the function object \c f.
3309 class PackExpansionExpr : public Expr {
3310 SourceLocation EllipsisLoc;
3312 /// \brief The number of expansions that will be produced by this pack
3313 /// expansion expression, if known.
3315 /// When zero, the number of expansions is not known. Otherwise, this value
3316 /// is the number of expansions + 1.
3317 unsigned NumExpansions;
3321 friend class ASTStmtReader;
3322 friend class ASTStmtWriter;
3325 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3326 llvm::Optional<unsigned> NumExpansions)
3327 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3328 Pattern->getObjectKind(), /*TypeDependent=*/true,
3329 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3330 /*ContainsUnexpandedParameterPack=*/false),
3331 EllipsisLoc(EllipsisLoc),
3332 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3333 Pattern(Pattern) { }
3335 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3337 /// \brief Retrieve the pattern of the pack expansion.
3338 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3340 /// \brief Retrieve the pattern of the pack expansion.
3341 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3343 /// \brief Retrieve the location of the ellipsis that describes this pack
3345 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3347 /// \brief Determine the number of expansions that will be produced when
3348 /// this pack expansion is instantiated, if already known.
3349 llvm::Optional<unsigned> getNumExpansions() const {
3351 return NumExpansions - 1;
3353 return llvm::Optional<unsigned>();
3356 SourceRange getSourceRange() const LLVM_READONLY {
3357 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
3360 static bool classof(const Stmt *T) {
3361 return T->getStmtClass() == PackExpansionExprClass;
3365 child_range children() {
3366 return child_range(&Pattern, &Pattern + 1);
3370 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3371 if (!HasTemplateKWAndArgsInfo) return 0;
3372 if (isa<UnresolvedLookupExpr>(this))
3373 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3374 (cast<UnresolvedLookupExpr>(this) + 1);
3376 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3377 (cast<UnresolvedMemberExpr>(this) + 1);
3380 /// \brief Represents an expression that computes the length of a parameter
3384 /// template<typename ...Types>
3386 /// static const unsigned value = sizeof...(Types);
3389 class SizeOfPackExpr : public Expr {
3390 /// \brief The location of the 'sizeof' keyword.
3391 SourceLocation OperatorLoc;
3393 /// \brief The location of the name of the parameter pack.
3394 SourceLocation PackLoc;
3396 /// \brief The location of the closing parenthesis.
3397 SourceLocation RParenLoc;
3399 /// \brief The length of the parameter pack, if known.
3401 /// When this expression is value-dependent, the length of the parameter pack
3402 /// is unknown. When this expression is not value-dependent, the length is
3406 /// \brief The parameter pack itself.
3409 friend class ASTStmtReader;
3410 friend class ASTStmtWriter;
3413 /// \brief Creates a value-dependent expression that computes the length of
3414 /// the given parameter pack.
3415 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3416 SourceLocation PackLoc, SourceLocation RParenLoc)
3417 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3418 /*TypeDependent=*/false, /*ValueDependent=*/true,
3419 /*InstantiationDependent=*/true,
3420 /*ContainsUnexpandedParameterPack=*/false),
3421 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3422 Length(0), Pack(Pack) { }
3424 /// \brief Creates an expression that computes the length of
3425 /// the given parameter pack, which is already known.
3426 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3427 SourceLocation PackLoc, SourceLocation RParenLoc,
3429 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3430 /*TypeDependent=*/false, /*ValueDependent=*/false,
3431 /*InstantiationDependent=*/false,
3432 /*ContainsUnexpandedParameterPack=*/false),
3433 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3434 Length(Length), Pack(Pack) { }
3436 /// \brief Create an empty expression.
3437 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3439 /// \brief Determine the location of the 'sizeof' keyword.
3440 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3442 /// \brief Determine the location of the parameter pack.
3443 SourceLocation getPackLoc() const { return PackLoc; }
3445 /// \brief Determine the location of the right parenthesis.
3446 SourceLocation getRParenLoc() const { return RParenLoc; }
3448 /// \brief Retrieve the parameter pack.
3449 NamedDecl *getPack() const { return Pack; }
3451 /// \brief Retrieve the length of the parameter pack.
3453 /// This routine may only be invoked when the expression is not
3454 /// value-dependent.
3455 unsigned getPackLength() const {
3456 assert(!isValueDependent() &&
3457 "Cannot get the length of a value-dependent pack size expression");
3461 SourceRange getSourceRange() const LLVM_READONLY {
3462 return SourceRange(OperatorLoc, RParenLoc);
3465 static bool classof(const Stmt *T) {
3466 return T->getStmtClass() == SizeOfPackExprClass;
3470 child_range children() { return child_range(); }
3473 /// \brief Represents a reference to a non-type template parameter
3474 /// that has been substituted with a template argument.
3475 class SubstNonTypeTemplateParmExpr : public Expr {
3476 /// \brief The replaced parameter.
3477 NonTypeTemplateParmDecl *Param;
3479 /// \brief The replacement expression.
3482 /// \brief The location of the non-type template parameter reference.
3483 SourceLocation NameLoc;
3485 friend class ASTReader;
3486 friend class ASTStmtReader;
3487 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3488 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3491 SubstNonTypeTemplateParmExpr(QualType type,
3492 ExprValueKind valueKind,
3494 NonTypeTemplateParmDecl *param,
3496 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3497 replacement->isTypeDependent(), replacement->isValueDependent(),
3498 replacement->isInstantiationDependent(),
3499 replacement->containsUnexpandedParameterPack()),
3500 Param(param), Replacement(replacement), NameLoc(loc) {}
3502 SourceLocation getNameLoc() const { return NameLoc; }
3503 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3505 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3507 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3509 static bool classof(const Stmt *s) {
3510 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3514 child_range children() { return child_range(&Replacement, &Replacement+1); }
3517 /// \brief Represents a reference to a non-type template parameter pack that
3518 /// has been substituted with a non-template argument pack.
3520 /// When a pack expansion in the source code contains multiple parameter packs
3521 /// and those parameter packs correspond to different levels of template
3522 /// parameter lists, this node is used to represent a non-type template
3523 /// parameter pack from an outer level, which has already had its argument pack
3524 /// substituted but that still lives within a pack expansion that itself
3525 /// could not be instantiated. When actually performing a substitution into
3526 /// that pack expansion (e.g., when all template parameters have corresponding
3527 /// arguments), this type will be replaced with the appropriate underlying
3528 /// expression at the current pack substitution index.
3529 class SubstNonTypeTemplateParmPackExpr : public Expr {
3530 /// \brief The non-type template parameter pack itself.
3531 NonTypeTemplateParmDecl *Param;
3533 /// \brief A pointer to the set of template arguments that this
3534 /// parameter pack is instantiated with.
3535 const TemplateArgument *Arguments;
3537 /// \brief The number of template arguments in \c Arguments.
3538 unsigned NumArguments;
3540 /// \brief The location of the non-type template parameter pack reference.
3541 SourceLocation NameLoc;
3543 friend class ASTReader;
3544 friend class ASTStmtReader;
3545 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3546 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3549 SubstNonTypeTemplateParmPackExpr(QualType T,
3550 NonTypeTemplateParmDecl *Param,
3551 SourceLocation NameLoc,
3552 const TemplateArgument &ArgPack);
3554 /// \brief Retrieve the non-type template parameter pack being substituted.
3555 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3557 /// \brief Retrieve the location of the parameter pack name.
3558 SourceLocation getParameterPackLocation() const { return NameLoc; }
3560 /// \brief Retrieve the template argument pack containing the substituted
3561 /// template arguments.
3562 TemplateArgument getArgumentPack() const;
3564 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3566 static bool classof(const Stmt *T) {
3567 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3571 child_range children() { return child_range(); }
3574 /// \brief Represents a reference to a function parameter pack that has been
3575 /// substituted but not yet expanded.
3577 /// When a pack expansion contains multiple parameter packs at different levels,
3578 /// this node is used to represent a function parameter pack at an outer level
3579 /// which we have already substituted to refer to expanded parameters, but where
3580 /// the containing pack expansion cannot yet be expanded.
3583 /// template<typename...Ts> struct S {
3584 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3586 /// template struct S<int, int>;
3588 class FunctionParmPackExpr : public Expr {
3589 /// \brief The function parameter pack which was referenced.
3590 ParmVarDecl *ParamPack;
3592 /// \brief The location of the function parameter pack reference.
3593 SourceLocation NameLoc;
3595 /// \brief The number of expansions of this pack.
3596 unsigned NumParameters;
3598 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3599 SourceLocation NameLoc, unsigned NumParams,
3600 Decl * const *Params);
3602 friend class ASTReader;
3603 friend class ASTStmtReader;
3606 static FunctionParmPackExpr *Create(ASTContext &Context, QualType T,
3607 ParmVarDecl *ParamPack,
3608 SourceLocation NameLoc,
3609 llvm::ArrayRef<Decl*> Params);
3610 static FunctionParmPackExpr *CreateEmpty(ASTContext &Context,
3611 unsigned NumParams);
3613 /// \brief Get the parameter pack which this expression refers to.
3614 ParmVarDecl *getParameterPack() const { return ParamPack; }
3616 /// \brief Get the location of the parameter pack.
3617 SourceLocation getParameterPackLocation() const { return NameLoc; }
3619 /// \brief Iterators over the parameters which the parameter pack expanded
3621 typedef ParmVarDecl * const *iterator;
3622 iterator begin() const { return reinterpret_cast<iterator>(this+1); }
3623 iterator end() const { return begin() + NumParameters; }
3625 /// \brief Get the number of parameters in this parameter pack.
3626 unsigned getNumExpansions() const { return NumParameters; }
3628 /// \brief Get an expansion of the parameter pack by index.
3629 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3631 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3633 static bool classof(const Stmt *T) {
3634 return T->getStmtClass() == FunctionParmPackExprClass;
3637 child_range children() { return child_range(); }
3640 /// \brief Represents a prvalue temporary that written into memory so that
3641 /// a reference can bind to it.
3643 /// Prvalue expressions are materialized when they need to have an address
3644 /// in memory for a reference to bind to. This happens when binding a
3645 /// reference to the result of a conversion, e.g.,
3648 /// const int &r = 1.0;
3651 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3652 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3653 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3654 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3655 /// to it), maintaining the invariant that references always bind to glvalues.
3656 class MaterializeTemporaryExpr : public Expr {
3657 /// \brief The temporary-generating expression whose value will be
3661 friend class ASTStmtReader;
3662 friend class ASTStmtWriter;
3665 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3666 bool BoundToLvalueReference)
3667 : Expr(MaterializeTemporaryExprClass, T,
3668 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3669 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3670 Temporary->isInstantiationDependent(),
3671 Temporary->containsUnexpandedParameterPack()),
3672 Temporary(Temporary) { }
3674 MaterializeTemporaryExpr(EmptyShell Empty)
3675 : Expr(MaterializeTemporaryExprClass, Empty) { }
3677 /// \brief Retrieve the temporary-generating subexpression whose value will
3678 /// be materialized into a glvalue.
3679 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3681 /// \brief Determine whether this materialized temporary is bound to an
3682 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3683 bool isBoundToLvalueReference() const {
3684 return getValueKind() == VK_LValue;
3687 SourceRange getSourceRange() const LLVM_READONLY {
3688 return Temporary->getSourceRange();
3691 static bool classof(const Stmt *T) {
3692 return T->getStmtClass() == MaterializeTemporaryExprClass;
3696 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3699 } // end namespace clang