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/Expr.h"
18 #include "clang/AST/UnresolvedSet.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/Basic/ExpressionTraits.h"
21 #include "clang/Basic/Lambda.h"
22 #include "clang/Basic/TypeTraits.h"
23 #include "llvm/Support/Compiler.h"
27 class CXXConstructorDecl;
28 class CXXDestructorDecl;
31 class TemplateArgumentListInfo;
33 //===--------------------------------------------------------------------===//
35 //===--------------------------------------------------------------------===//
37 /// \brief A call to an overloaded operator written using operator
40 /// Represents a call to an overloaded operator written using operator
41 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
42 /// normal call, this AST node provides better information about the
43 /// syntactic representation of the call.
45 /// In a C++ template, this expression node kind will be used whenever
46 /// any of the arguments are type-dependent. In this case, the
47 /// function itself will be a (possibly empty) set of functions and
48 /// function templates that were found by name lookup at template
50 class CXXOperatorCallExpr : public CallExpr {
51 /// \brief The overloaded operator.
52 OverloadedOperatorKind Operator;
55 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
56 Expr **args, unsigned numargs, QualType t,
57 ExprValueKind VK, SourceLocation operatorloc)
58 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
61 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
62 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
65 /// getOperator - Returns the kind of overloaded operator that this
66 /// expression refers to.
67 OverloadedOperatorKind getOperator() const { return Operator; }
68 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
70 /// getOperatorLoc - Returns the location of the operator symbol in
71 /// the expression. When @c getOperator()==OO_Call, this is the
72 /// location of the right parentheses; when @c
73 /// getOperator()==OO_Subscript, this is the location of the right
75 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
77 SourceRange getSourceRange() const LLVM_READONLY;
79 static bool classof(const Stmt *T) {
80 return T->getStmtClass() == CXXOperatorCallExprClass;
82 static bool classof(const CXXOperatorCallExpr *) { return true; }
85 /// CXXMemberCallExpr - Represents a call to a member function that
86 /// may be written either with member call syntax (e.g., "obj.func()"
87 /// or "objptr->func()") or with normal function-call syntax
88 /// ("func()") within a member function that ends up calling a member
89 /// function. The callee in either case is a MemberExpr that contains
90 /// both the object argument and the member function, while the
91 /// arguments are the arguments within the parentheses (not including
92 /// the object argument).
93 class CXXMemberCallExpr : public CallExpr {
95 CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
96 QualType t, ExprValueKind VK, SourceLocation RP)
97 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
99 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
100 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
102 /// getImplicitObjectArgument - Retrieves the implicit object
103 /// argument for the member call. For example, in "x.f(5)", this
104 /// operation would return "x".
105 Expr *getImplicitObjectArgument() const;
107 /// Retrieves the declaration of the called method.
108 CXXMethodDecl *getMethodDecl() const;
110 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
111 /// the implicit object argument. Note that this is may not be the same
112 /// declaration as that of the class context of the CXXMethodDecl which this
113 /// function is calling.
114 /// FIXME: Returns 0 for member pointer call exprs.
115 CXXRecordDecl *getRecordDecl();
117 static bool classof(const Stmt *T) {
118 return T->getStmtClass() == CXXMemberCallExprClass;
120 static bool classof(const CXXMemberCallExpr *) { return true; }
123 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
124 class CUDAKernelCallExpr : public CallExpr {
126 enum { CONFIG, END_PREARG };
129 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
130 Expr **args, unsigned numargs, QualType t,
131 ExprValueKind VK, SourceLocation RP)
132 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
137 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
138 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
140 const CallExpr *getConfig() const {
141 return cast_or_null<CallExpr>(getPreArg(CONFIG));
143 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
144 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
146 static bool classof(const Stmt *T) {
147 return T->getStmtClass() == CUDAKernelCallExprClass;
149 static bool classof(const CUDAKernelCallExpr *) { return true; }
152 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
153 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
156 /// This abstract class is inherited by all of the classes
157 /// representing "named" casts, e.g., CXXStaticCastExpr,
158 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
159 class CXXNamedCastExpr : public ExplicitCastExpr {
161 SourceLocation Loc; // the location of the casting op
162 SourceLocation RParenLoc; // the location of the right parenthesis
165 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
166 CastKind kind, Expr *op, unsigned PathSize,
167 TypeSourceInfo *writtenTy, SourceLocation l,
168 SourceLocation RParenLoc)
169 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
170 RParenLoc(RParenLoc) {}
172 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
173 : ExplicitCastExpr(SC, Shell, PathSize) { }
175 friend class ASTStmtReader;
178 const char *getCastName() const;
180 /// \brief Retrieve the location of the cast operator keyword, e.g.,
182 SourceLocation getOperatorLoc() const { return Loc; }
184 /// \brief Retrieve the location of the closing parenthesis.
185 SourceLocation getRParenLoc() const { return RParenLoc; }
187 SourceRange getSourceRange() const LLVM_READONLY {
188 return SourceRange(Loc, RParenLoc);
190 static bool classof(const Stmt *T) {
191 switch (T->getStmtClass()) {
192 case CXXStaticCastExprClass:
193 case CXXDynamicCastExprClass:
194 case CXXReinterpretCastExprClass:
195 case CXXConstCastExprClass:
201 static bool classof(const CXXNamedCastExpr *) { return true; }
204 /// CXXStaticCastExpr - A C++ @c static_cast expression
205 /// (C++ [expr.static.cast]).
207 /// This expression node represents a C++ static cast, e.g.,
208 /// @c static_cast<int>(1.0).
209 class CXXStaticCastExpr : public CXXNamedCastExpr {
210 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
211 unsigned pathSize, TypeSourceInfo *writtenTy,
212 SourceLocation l, SourceLocation RParenLoc)
213 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
214 writtenTy, l, RParenLoc) {}
216 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
217 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
220 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
221 ExprValueKind VK, CastKind K, Expr *Op,
222 const CXXCastPath *Path,
223 TypeSourceInfo *Written, SourceLocation L,
224 SourceLocation RParenLoc);
225 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
228 static bool classof(const Stmt *T) {
229 return T->getStmtClass() == CXXStaticCastExprClass;
231 static bool classof(const CXXStaticCastExpr *) { return true; }
234 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
235 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
236 /// determine how to perform the type cast.
238 /// This expression node represents a dynamic cast, e.g.,
239 /// @c dynamic_cast<Derived*>(BasePtr).
240 class CXXDynamicCastExpr : public CXXNamedCastExpr {
241 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
242 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
243 SourceLocation l, SourceLocation RParenLoc)
244 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
245 writtenTy, l, RParenLoc) {}
247 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
248 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
251 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
252 ExprValueKind VK, CastKind Kind, Expr *Op,
253 const CXXCastPath *Path,
254 TypeSourceInfo *Written, SourceLocation L,
255 SourceLocation RParenLoc);
257 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
260 bool isAlwaysNull() const;
262 static bool classof(const Stmt *T) {
263 return T->getStmtClass() == CXXDynamicCastExprClass;
265 static bool classof(const CXXDynamicCastExpr *) { return true; }
268 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
269 /// [expr.reinterpret.cast]), which provides a differently-typed view
270 /// of a value but performs no actual work at run time.
272 /// This expression node represents a reinterpret cast, e.g.,
273 /// @c reinterpret_cast<int>(VoidPtr).
274 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
275 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
276 Expr *op, unsigned pathSize,
277 TypeSourceInfo *writtenTy, SourceLocation l,
278 SourceLocation RParenLoc)
279 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
280 pathSize, writtenTy, l, RParenLoc) {}
282 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
283 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
286 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
287 ExprValueKind VK, CastKind Kind,
288 Expr *Op, const CXXCastPath *Path,
289 TypeSourceInfo *WrittenTy, SourceLocation L,
290 SourceLocation RParenLoc);
291 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
294 static bool classof(const Stmt *T) {
295 return T->getStmtClass() == CXXReinterpretCastExprClass;
297 static bool classof(const CXXReinterpretCastExpr *) { return true; }
300 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
301 /// which can remove type qualifiers but does not change the underlying value.
303 /// This expression node represents a const cast, e.g.,
304 /// @c const_cast<char*>(PtrToConstChar).
305 class CXXConstCastExpr : public CXXNamedCastExpr {
306 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
307 TypeSourceInfo *writtenTy, SourceLocation l,
308 SourceLocation RParenLoc)
309 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
310 0, writtenTy, l, RParenLoc) {}
312 explicit CXXConstCastExpr(EmptyShell Empty)
313 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
316 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
317 ExprValueKind VK, Expr *Op,
318 TypeSourceInfo *WrittenTy, SourceLocation L,
319 SourceLocation RParenLoc);
320 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
322 static bool classof(const Stmt *T) {
323 return T->getStmtClass() == CXXConstCastExprClass;
325 static bool classof(const CXXConstCastExpr *) { return true; }
328 /// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
329 /// written as a user-defined literal (C++11 [lit.ext]).
331 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
332 /// is semantically equivalent to a normal call, this AST node provides better
333 /// information about the syntactic representation of the literal.
335 /// Since literal operators are never found by ADL and can only be declared at
336 /// namespace scope, a user-defined literal is never dependent.
337 class UserDefinedLiteral : public CallExpr {
338 /// \brief The location of a ud-suffix within the literal.
339 SourceLocation UDSuffixLoc;
342 UserDefinedLiteral(ASTContext &C, Expr *Fn, Expr **Args, unsigned NumArgs,
343 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
344 SourceLocation SuffixLoc)
345 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, NumArgs, T, VK,
346 LitEndLoc), UDSuffixLoc(SuffixLoc) {}
347 explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
348 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
350 /// The kind of literal operator which is invoked.
351 enum LiteralOperatorKind {
352 LOK_Raw, ///< Raw form: operator "" X (const char *)
353 LOK_Template, ///< Raw form: operator "" X<cs...> ()
354 LOK_Integer, ///< operator "" X (unsigned long long)
355 LOK_Floating, ///< operator "" X (long double)
356 LOK_String, ///< operator "" X (const CharT *, size_t)
357 LOK_Character ///< operator "" X (CharT)
360 /// getLiteralOperatorKind - Returns the kind of literal operator invocation
361 /// which this expression represents.
362 LiteralOperatorKind getLiteralOperatorKind() const;
364 /// getCookedLiteral - If this is not a raw user-defined literal, get the
365 /// underlying cooked literal (representing the literal with the suffix
367 Expr *getCookedLiteral();
368 const Expr *getCookedLiteral() const {
369 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
372 /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
373 /// For a string literal, there may be multiple identical suffixes. This
374 /// returns the first.
375 SourceLocation getUDSuffixLoc() const { return getRParenLoc(); }
377 /// getUDSuffix - Returns the ud-suffix specified for this literal.
378 const IdentifierInfo *getUDSuffix() const;
380 static bool classof(const Stmt *S) {
381 return S->getStmtClass() == UserDefinedLiteralClass;
383 static bool classof(const UserDefinedLiteral *) { return true; }
385 friend class ASTStmtReader;
386 friend class ASTStmtWriter;
389 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
391 class CXXBoolLiteralExpr : public Expr {
395 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
396 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
398 Value(val), Loc(l) {}
400 explicit CXXBoolLiteralExpr(EmptyShell Empty)
401 : Expr(CXXBoolLiteralExprClass, Empty) { }
403 bool getValue() const { return Value; }
404 void setValue(bool V) { Value = V; }
406 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
408 SourceLocation getLocation() const { return Loc; }
409 void setLocation(SourceLocation L) { Loc = L; }
411 static bool classof(const Stmt *T) {
412 return T->getStmtClass() == CXXBoolLiteralExprClass;
414 static bool classof(const CXXBoolLiteralExpr *) { return true; }
417 child_range children() { return child_range(); }
420 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
421 class CXXNullPtrLiteralExpr : public Expr {
424 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
425 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
429 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
430 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
432 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
434 SourceLocation getLocation() const { return Loc; }
435 void setLocation(SourceLocation L) { Loc = L; }
437 static bool classof(const Stmt *T) {
438 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
440 static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
442 child_range children() { return child_range(); }
445 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
446 /// the type_info that corresponds to the supplied type, or the (possibly
447 /// dynamic) type of the supplied expression.
449 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
450 class CXXTypeidExpr : public Expr {
452 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
456 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
457 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
458 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
460 // typeid is value-dependent if the type or expression are dependent
461 Operand->getType()->isDependentType(),
462 Operand->getType()->isInstantiationDependentType(),
463 Operand->getType()->containsUnexpandedParameterPack()),
464 Operand(Operand), Range(R) { }
466 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
467 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
468 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
470 // typeid is value-dependent if the type or expression are dependent
471 Operand->isTypeDependent() || Operand->isValueDependent(),
472 Operand->isInstantiationDependent(),
473 Operand->containsUnexpandedParameterPack()),
474 Operand(Operand), Range(R) { }
476 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
477 : Expr(CXXTypeidExprClass, Empty) {
481 Operand = (TypeSourceInfo*)0;
484 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
486 /// \brief Retrieves the type operand of this typeid() expression after
487 /// various required adjustments (removing reference types, cv-qualifiers).
488 QualType getTypeOperand() const;
490 /// \brief Retrieve source information for the type operand.
491 TypeSourceInfo *getTypeOperandSourceInfo() const {
492 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
493 return Operand.get<TypeSourceInfo *>();
496 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
497 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
501 Expr *getExprOperand() const {
502 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
503 return static_cast<Expr*>(Operand.get<Stmt *>());
506 void setExprOperand(Expr *E) {
507 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
511 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
512 void setSourceRange(SourceRange R) { Range = R; }
514 static bool classof(const Stmt *T) {
515 return T->getStmtClass() == CXXTypeidExprClass;
517 static bool classof(const CXXTypeidExpr *) { return true; }
520 child_range children() {
521 if (isTypeOperand()) return child_range();
522 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
523 return child_range(begin, begin + 1);
527 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
528 /// the _GUID that corresponds to the supplied type or expression.
530 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
531 class CXXUuidofExpr : public Expr {
533 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
537 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
538 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
539 false, Operand->getType()->isDependentType(),
540 Operand->getType()->isInstantiationDependentType(),
541 Operand->getType()->containsUnexpandedParameterPack()),
542 Operand(Operand), Range(R) { }
544 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
545 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
546 false, Operand->isTypeDependent(),
547 Operand->isInstantiationDependent(),
548 Operand->containsUnexpandedParameterPack()),
549 Operand(Operand), Range(R) { }
551 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
552 : Expr(CXXUuidofExprClass, Empty) {
556 Operand = (TypeSourceInfo*)0;
559 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
561 /// \brief Retrieves the type operand of this __uuidof() expression after
562 /// various required adjustments (removing reference types, cv-qualifiers).
563 QualType getTypeOperand() const;
565 /// \brief Retrieve source information for the type operand.
566 TypeSourceInfo *getTypeOperandSourceInfo() const {
567 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
568 return Operand.get<TypeSourceInfo *>();
571 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
572 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
576 Expr *getExprOperand() const {
577 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
578 return static_cast<Expr*>(Operand.get<Stmt *>());
581 void setExprOperand(Expr *E) {
582 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
586 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
587 void setSourceRange(SourceRange R) { Range = R; }
589 static bool classof(const Stmt *T) {
590 return T->getStmtClass() == CXXUuidofExprClass;
592 static bool classof(const CXXUuidofExpr *) { return true; }
595 child_range children() {
596 if (isTypeOperand()) return child_range();
597 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
598 return child_range(begin, begin + 1);
602 /// CXXThisExpr - Represents the "this" expression in C++, which is a
603 /// pointer to the object on which the current member function is
604 /// executing (C++ [expr.prim]p3). Example:
610 /// void test() { this->bar(); }
613 class CXXThisExpr : public Expr {
618 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
619 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
620 // 'this' is type-dependent if the class type of the enclosing
621 // member function is dependent (C++ [temp.dep.expr]p2)
622 Type->isDependentType(), Type->isDependentType(),
623 Type->isInstantiationDependentType(),
624 /*ContainsUnexpandedParameterPack=*/false),
625 Loc(L), Implicit(isImplicit) { }
627 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
629 SourceLocation getLocation() const { return Loc; }
630 void setLocation(SourceLocation L) { Loc = L; }
632 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
634 bool isImplicit() const { return Implicit; }
635 void setImplicit(bool I) { Implicit = I; }
637 static bool classof(const Stmt *T) {
638 return T->getStmtClass() == CXXThisExprClass;
640 static bool classof(const CXXThisExpr *) { return true; }
643 child_range children() { return child_range(); }
646 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
647 /// 'throw' and 'throw' assignment-expression. When
648 /// assignment-expression isn't present, Op will be null.
650 class CXXThrowExpr : public Expr {
652 SourceLocation ThrowLoc;
653 /// \brief Whether the thrown variable (if any) is in scope.
654 unsigned IsThrownVariableInScope : 1;
656 friend class ASTStmtReader;
659 // Ty is the void type which is used as the result type of the
660 // exepression. The l is the location of the throw keyword. expr
661 // can by null, if the optional expression to throw isn't present.
662 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
663 bool IsThrownVariableInScope) :
664 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
665 expr && expr->isInstantiationDependent(),
666 expr && expr->containsUnexpandedParameterPack()),
667 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
668 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
670 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
671 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
673 SourceLocation getThrowLoc() const { return ThrowLoc; }
675 /// \brief Determines whether the variable thrown by this expression (if any!)
676 /// is within the innermost try block.
678 /// This information is required to determine whether the NRVO can apply to
680 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
682 SourceRange getSourceRange() const LLVM_READONLY {
683 if (getSubExpr() == 0)
684 return SourceRange(ThrowLoc, ThrowLoc);
685 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
688 static bool classof(const Stmt *T) {
689 return T->getStmtClass() == CXXThrowExprClass;
691 static bool classof(const CXXThrowExpr *) { return true; }
694 child_range children() {
695 return child_range(&Op, Op ? &Op+1 : &Op);
699 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
700 /// function call argument that was created from the corresponding
701 /// parameter's default argument, when the call did not explicitly
702 /// supply arguments for all of the parameters.
703 class CXXDefaultArgExpr : public Expr {
704 /// \brief The parameter whose default is being used.
706 /// When the bit is set, the subexpression is stored after the
707 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
708 /// actual default expression is the subexpression.
709 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
711 /// \brief The location where the default argument expression was used.
714 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
716 param->hasUnparsedDefaultArg()
717 ? param->getType().getNonReferenceType()
718 : param->getDefaultArg()->getType(),
719 param->getDefaultArg()->getValueKind(),
720 param->getDefaultArg()->getObjectKind(), false, false, false, false),
721 Param(param, false), Loc(Loc) { }
723 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
725 : Expr(SC, SubExpr->getType(),
726 SubExpr->getValueKind(), SubExpr->getObjectKind(),
727 false, false, false, false),
728 Param(param, true), Loc(Loc) {
729 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
733 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
736 // Param is the parameter whose default argument is used by this
738 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
739 ParmVarDecl *Param) {
740 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
743 // Param is the parameter whose default argument is used by this
744 // expression, and SubExpr is the expression that will actually be used.
745 static CXXDefaultArgExpr *Create(ASTContext &C,
750 // Retrieve the parameter that the argument was created from.
751 const ParmVarDecl *getParam() const { return Param.getPointer(); }
752 ParmVarDecl *getParam() { return Param.getPointer(); }
754 // Retrieve the actual argument to the function call.
755 const Expr *getExpr() const {
757 return *reinterpret_cast<Expr const * const*> (this + 1);
758 return getParam()->getDefaultArg();
762 return *reinterpret_cast<Expr **> (this + 1);
763 return getParam()->getDefaultArg();
766 /// \brief Retrieve the location where this default argument was actually
768 SourceLocation getUsedLocation() const { return Loc; }
770 SourceRange getSourceRange() const LLVM_READONLY {
771 // Default argument expressions have no representation in the
772 // source, so they have an empty source range.
773 return SourceRange();
776 static bool classof(const Stmt *T) {
777 return T->getStmtClass() == CXXDefaultArgExprClass;
779 static bool classof(const CXXDefaultArgExpr *) { return true; }
782 child_range children() { return child_range(); }
784 friend class ASTStmtReader;
785 friend class ASTStmtWriter;
788 /// CXXTemporary - Represents a C++ temporary.
790 /// Destructor - The destructor that needs to be called.
791 const CXXDestructorDecl *Destructor;
793 CXXTemporary(const CXXDestructorDecl *destructor)
794 : Destructor(destructor) { }
797 static CXXTemporary *Create(ASTContext &C,
798 const CXXDestructorDecl *Destructor);
800 const CXXDestructorDecl *getDestructor() const { return Destructor; }
801 void setDestructor(const CXXDestructorDecl *Dtor) {
806 /// \brief Represents binding an expression to a temporary.
808 /// This ensures the destructor is called for the temporary. It should only be
809 /// needed for non-POD, non-trivially destructable class types. For example:
813 /// S() { } // User defined constructor makes S non-POD.
814 /// ~S() { } // User defined destructor makes it non-trivial.
817 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
820 class CXXBindTemporaryExpr : public Expr {
825 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
826 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
827 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
828 SubExpr->isValueDependent(),
829 SubExpr->isInstantiationDependent(),
830 SubExpr->containsUnexpandedParameterPack()),
831 Temp(temp), SubExpr(SubExpr) { }
834 CXXBindTemporaryExpr(EmptyShell Empty)
835 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
837 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
840 CXXTemporary *getTemporary() { return Temp; }
841 const CXXTemporary *getTemporary() const { return Temp; }
842 void setTemporary(CXXTemporary *T) { Temp = T; }
844 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
845 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
846 void setSubExpr(Expr *E) { SubExpr = E; }
848 SourceRange getSourceRange() const LLVM_READONLY {
849 return SubExpr->getSourceRange();
852 // Implement isa/cast/dyncast/etc.
853 static bool classof(const Stmt *T) {
854 return T->getStmtClass() == CXXBindTemporaryExprClass;
856 static bool classof(const CXXBindTemporaryExpr *) { return true; }
859 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
862 /// CXXConstructExpr - Represents a call to a C++ constructor.
863 class CXXConstructExpr : public Expr {
865 enum ConstructionKind {
873 CXXConstructorDecl *Constructor;
876 SourceRange ParenRange;
877 unsigned NumArgs : 16;
879 bool HadMultipleCandidates : 1;
880 bool ListInitialization : 1;
881 bool ZeroInitialization : 1;
882 unsigned ConstructKind : 2;
886 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
888 CXXConstructorDecl *d, bool elidable,
889 Expr **args, unsigned numargs,
890 bool HadMultipleCandidates,
891 bool ListInitialization,
892 bool ZeroInitialization,
893 ConstructionKind ConstructKind,
894 SourceRange ParenRange);
896 /// \brief Construct an empty C++ construction expression.
897 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
898 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
899 HadMultipleCandidates(false), ListInitialization(false),
900 ZeroInitialization(false), ConstructKind(0), Args(0)
904 /// \brief Construct an empty C++ construction expression.
905 explicit CXXConstructExpr(EmptyShell Empty)
906 : Expr(CXXConstructExprClass, Empty), Constructor(0),
907 NumArgs(0), Elidable(false), HadMultipleCandidates(false),
908 ListInitialization(false), ZeroInitialization(false),
909 ConstructKind(0), Args(0)
912 static CXXConstructExpr *Create(ASTContext &C, QualType T,
914 CXXConstructorDecl *D, bool Elidable,
915 Expr **Args, unsigned NumArgs,
916 bool HadMultipleCandidates,
917 bool ListInitialization,
918 bool ZeroInitialization,
919 ConstructionKind ConstructKind,
920 SourceRange ParenRange);
922 CXXConstructorDecl* getConstructor() const { return Constructor; }
923 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
925 SourceLocation getLocation() const { return Loc; }
926 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
928 /// \brief Whether this construction is elidable.
929 bool isElidable() const { return Elidable; }
930 void setElidable(bool E) { Elidable = E; }
932 /// \brief Whether the referred constructor was resolved from
933 /// an overloaded set having size greater than 1.
934 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
935 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
937 /// \brief Whether this constructor call was written as list-initialization.
938 bool isListInitialization() const { return ListInitialization; }
939 void setListInitialization(bool V) { ListInitialization = V; }
941 /// \brief Whether this construction first requires
942 /// zero-initialization before the initializer is called.
943 bool requiresZeroInitialization() const { return ZeroInitialization; }
944 void setRequiresZeroInitialization(bool ZeroInit) {
945 ZeroInitialization = ZeroInit;
948 /// \brief Determines whether this constructor is actually constructing
949 /// a base class (rather than a complete object).
950 ConstructionKind getConstructionKind() const {
951 return (ConstructionKind)ConstructKind;
953 void setConstructionKind(ConstructionKind CK) {
957 typedef ExprIterator arg_iterator;
958 typedef ConstExprIterator const_arg_iterator;
960 arg_iterator arg_begin() { return Args; }
961 arg_iterator arg_end() { return Args + NumArgs; }
962 const_arg_iterator arg_begin() const { return Args; }
963 const_arg_iterator arg_end() const { return Args + NumArgs; }
965 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
966 unsigned getNumArgs() const { return NumArgs; }
968 /// getArg - Return the specified argument.
969 Expr *getArg(unsigned Arg) {
970 assert(Arg < NumArgs && "Arg access out of range!");
971 return cast<Expr>(Args[Arg]);
973 const Expr *getArg(unsigned Arg) const {
974 assert(Arg < NumArgs && "Arg access out of range!");
975 return cast<Expr>(Args[Arg]);
978 /// setArg - Set the specified argument.
979 void setArg(unsigned Arg, Expr *ArgExpr) {
980 assert(Arg < NumArgs && "Arg access out of range!");
984 SourceRange getSourceRange() const LLVM_READONLY;
985 SourceRange getParenRange() const { return ParenRange; }
987 static bool classof(const Stmt *T) {
988 return T->getStmtClass() == CXXConstructExprClass ||
989 T->getStmtClass() == CXXTemporaryObjectExprClass;
991 static bool classof(const CXXConstructExpr *) { return true; }
994 child_range children() {
995 return child_range(&Args[0], &Args[0]+NumArgs);
998 friend class ASTStmtReader;
1001 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
1002 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
1004 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1005 SourceLocation TyBeginLoc;
1006 SourceLocation RParenLoc;
1008 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1009 TypeSourceInfo *writtenTy,
1010 SourceLocation tyBeginLoc, CastKind kind,
1011 Expr *castExpr, unsigned pathSize,
1012 SourceLocation rParenLoc)
1013 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1014 castExpr, pathSize, writtenTy),
1015 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
1017 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1018 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1021 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1023 TypeSourceInfo *Written,
1024 SourceLocation TyBeginLoc,
1025 CastKind Kind, Expr *Op,
1026 const CXXCastPath *Path,
1027 SourceLocation RPLoc);
1028 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1031 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1032 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1033 SourceLocation getRParenLoc() const { return RParenLoc; }
1034 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1036 SourceRange getSourceRange() const LLVM_READONLY {
1037 return SourceRange(TyBeginLoc, RParenLoc);
1039 static bool classof(const Stmt *T) {
1040 return T->getStmtClass() == CXXFunctionalCastExprClass;
1042 static bool classof(const CXXFunctionalCastExpr *) { return true; }
1045 /// @brief Represents a C++ functional cast expression that builds a
1046 /// temporary object.
1048 /// This expression type represents a C++ "functional" cast
1049 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1050 /// constructor to build a temporary object. With N == 1 arguments the
1051 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1054 /// struct X { X(int, float); }
1057 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1060 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1061 TypeSourceInfo *Type;
1064 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1065 TypeSourceInfo *Type,
1066 Expr **Args,unsigned NumArgs,
1067 SourceRange parenRange,
1068 bool HadMultipleCandidates,
1069 bool ZeroInitialization = false);
1070 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1071 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1073 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1075 SourceRange getSourceRange() const LLVM_READONLY;
1077 static bool classof(const Stmt *T) {
1078 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1080 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
1082 friend class ASTStmtReader;
1085 /// \brief A C++ lambda expression, which produces a function object
1086 /// (of unspecified type) that can be invoked later.
1090 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1091 /// values.erase(std::remove_if(values.begin(), values.end(),
1092 // [=](double value) { return value > cutoff; });
1096 /// Lambda expressions can capture local variables, either by copying
1097 /// the values of those local variables at the time the function
1098 /// object is constructed (not when it is called!) or by holding a
1099 /// reference to the local variable. These captures can occur either
1100 /// implicitly or can be written explicitly between the square
1101 /// brackets ([...]) that start the lambda expression.
1102 class LambdaExpr : public Expr {
1104 /// \brief Flag used by the Capture class to indicate that the given
1105 /// capture was implicit.
1106 Capture_Implicit = 0x01,
1108 /// \brief Flag used by the Capture class to indciate that the
1109 /// given capture was by-copy.
1110 Capture_ByCopy = 0x02
1113 /// \brief The source range that covers the lambda introducer ([...]).
1114 SourceRange IntroducerRange;
1116 /// \brief The number of captures.
1117 unsigned NumCaptures : 16;
1119 /// \brief The default capture kind, which is a value of type
1120 /// LambdaCaptureDefault.
1121 unsigned CaptureDefault : 2;
1123 /// \brief Whether this lambda had an explicit parameter list vs. an
1124 /// implicit (and empty) parameter list.
1125 unsigned ExplicitParams : 1;
1127 /// \brief Whether this lambda had the result type explicitly specified.
1128 unsigned ExplicitResultType : 1;
1130 /// \brief Whether there are any array index variables stored at the end of
1131 /// this lambda expression.
1132 unsigned HasArrayIndexVars : 1;
1134 /// \brief The location of the closing brace ('}') that completes
1137 /// The location of the brace is also available by looking up the
1138 /// function call operator in the lambda class. However, it is
1139 /// stored here to improve the performance of getSourceRange(), and
1140 /// to avoid having to deserialize the function call operator from a
1141 /// module file just to determine the source range.
1142 SourceLocation ClosingBrace;
1144 // Note: The capture initializers are stored directly after the lambda
1145 // expression, along with the index variables used to initialize by-copy
1149 /// \brief Describes the capture of either a variable or 'this'.
1151 llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
1153 SourceLocation EllipsisLoc;
1155 friend class ASTStmtReader;
1156 friend class ASTStmtWriter;
1159 /// \brief Create a new capture.
1161 /// \param Loc The source location associated with this capture.
1163 /// \param Kind The kind of capture (this, byref, bycopy).
1165 /// \param Implicit Whether the capture was implicit or explicit.
1167 /// \param Var The local variable being captured, or null if capturing this.
1169 /// \param EllipsisLoc The location of the ellipsis (...) for a
1170 /// capture that is a pack expansion, or an invalid source
1171 /// location to indicate that this is not a pack expansion.
1172 Capture(SourceLocation Loc, bool Implicit,
1173 LambdaCaptureKind Kind, VarDecl *Var = 0,
1174 SourceLocation EllipsisLoc = SourceLocation());
1176 /// \brief Determine the kind of capture.
1177 LambdaCaptureKind getCaptureKind() const;
1179 /// \brief Determine whether this capture handles the C++ 'this'
1181 bool capturesThis() const { return VarAndBits.getPointer() == 0; }
1183 /// \brief Determine whether this capture handles a variable.
1184 bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
1186 /// \brief Retrieve the declaration of the local variable being
1189 /// This operation is only valid if this capture does not capture
1191 VarDecl *getCapturedVar() const {
1192 assert(!capturesThis() && "No variable available for 'this' capture");
1193 return VarAndBits.getPointer();
1196 /// \brief Determine whether this was an implicit capture (not
1197 /// written between the square brackets introducing the lambda).
1198 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
1200 /// \brief Determine whether this was an explicit capture, written
1201 /// between the square brackets introducing the lambda.
1202 bool isExplicit() const { return !isImplicit(); }
1204 /// \brief Retrieve the source location of the capture.
1206 /// For an explicit capture, this returns the location of the
1207 /// explicit capture in the source. For an implicit capture, this
1208 /// returns the location at which the variable or 'this' was first
1210 SourceLocation getLocation() const { return Loc; }
1212 /// \brief Determine whether this capture is a pack expansion,
1213 /// which captures a function parameter pack.
1214 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
1216 /// \brief Retrieve the location of the ellipsis for a capture
1217 /// that is a pack expansion.
1218 SourceLocation getEllipsisLoc() const {
1219 assert(isPackExpansion() && "No ellipsis location for a non-expansion");
1225 /// \brief Construct a lambda expression.
1226 LambdaExpr(QualType T, SourceRange IntroducerRange,
1227 LambdaCaptureDefault CaptureDefault,
1228 ArrayRef<Capture> Captures,
1229 bool ExplicitParams,
1230 bool ExplicitResultType,
1231 ArrayRef<Expr *> CaptureInits,
1232 ArrayRef<VarDecl *> ArrayIndexVars,
1233 ArrayRef<unsigned> ArrayIndexStarts,
1234 SourceLocation ClosingBrace);
1236 /// \brief Construct an empty lambda expression.
1237 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1238 : Expr(LambdaExprClass, Empty),
1239 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1240 ExplicitResultType(false), HasArrayIndexVars(true) {
1241 getStoredStmts()[NumCaptures] = 0;
1244 Stmt **getStoredStmts() const {
1245 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1248 /// \brief Retrieve the mapping from captures to the first array index
1250 unsigned *getArrayIndexStarts() const {
1251 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1254 /// \brief Retrieve the complete set of array-index variables.
1255 VarDecl **getArrayIndexVars() const {
1256 return reinterpret_cast<VarDecl **>(
1257 getArrayIndexStarts() + NumCaptures + 1);
1261 /// \brief Construct a new lambda expression.
1262 static LambdaExpr *Create(ASTContext &C,
1263 CXXRecordDecl *Class,
1264 SourceRange IntroducerRange,
1265 LambdaCaptureDefault CaptureDefault,
1266 ArrayRef<Capture> Captures,
1267 bool ExplicitParams,
1268 bool ExplicitResultType,
1269 ArrayRef<Expr *> CaptureInits,
1270 ArrayRef<VarDecl *> ArrayIndexVars,
1271 ArrayRef<unsigned> ArrayIndexStarts,
1272 SourceLocation ClosingBrace);
1274 /// \brief Construct a new lambda expression that will be deserialized from
1275 /// an external source.
1276 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
1277 unsigned NumArrayIndexVars);
1279 /// \brief Determine the default capture kind for this lambda.
1280 LambdaCaptureDefault getCaptureDefault() const {
1281 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1284 /// \brief An iterator that walks over the captures of the lambda,
1285 /// both implicit and explicit.
1286 typedef const Capture *capture_iterator;
1288 /// \brief Retrieve an iterator pointing to the first lambda capture.
1289 capture_iterator capture_begin() const;
1291 /// \brief Retrieve an iterator pointing past the end of the
1292 /// sequence of lambda captures.
1293 capture_iterator capture_end() const;
1295 /// \brief Determine the number of captures in this lambda.
1296 unsigned capture_size() const { return NumCaptures; }
1298 /// \brief Retrieve an iterator pointing to the first explicit
1300 capture_iterator explicit_capture_begin() const;
1302 /// \brief Retrieve an iterator pointing past the end of the sequence of
1303 /// explicit lambda captures.
1304 capture_iterator explicit_capture_end() const;
1306 /// \brief Retrieve an iterator pointing to the first implicit
1308 capture_iterator implicit_capture_begin() const;
1310 /// \brief Retrieve an iterator pointing past the end of the sequence of
1311 /// implicit lambda captures.
1312 capture_iterator implicit_capture_end() const;
1314 /// \brief Iterator that walks over the capture initialization
1316 typedef Expr **capture_init_iterator;
1318 /// \brief Retrieve the first initialization argument for this
1319 /// lambda expression (which initializes the first capture field).
1320 capture_init_iterator capture_init_begin() const {
1321 return reinterpret_cast<Expr **>(getStoredStmts());
1324 /// \brief Retrieve the iterator pointing one past the last
1325 /// initialization argument for this lambda expression.
1326 capture_init_iterator capture_init_end() const {
1327 return capture_init_begin() + NumCaptures;
1330 /// \brief Retrieve the set of index variables used in the capture
1331 /// initializer of an array captured by copy.
1333 /// \param Iter The iterator that points at the capture initializer for
1334 /// which we are extracting the corresponding index variables.
1335 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1337 /// \brief Retrieve the source range covering the lambda introducer,
1338 /// which contains the explicit capture list surrounded by square
1339 /// brackets ([...]).
1340 SourceRange getIntroducerRange() const { return IntroducerRange; }
1342 /// \brief Retrieve the class that corresponds to the lambda, which
1343 /// stores the captures in its fields and provides the various
1344 /// operations permitted on a lambda (copying, calling).
1345 CXXRecordDecl *getLambdaClass() const;
1347 /// \brief Retrieve the function call operator associated with this
1348 /// lambda expression.
1349 CXXMethodDecl *getCallOperator() const;
1351 /// \brief Retrieve the body of the lambda.
1352 CompoundStmt *getBody() const;
1354 /// \brief Determine whether the lambda is mutable, meaning that any
1355 /// captures values can be modified.
1356 bool isMutable() const;
1358 /// \brief Determine whether this lambda has an explicit parameter
1359 /// list vs. an implicit (empty) parameter list.
1360 bool hasExplicitParameters() const { return ExplicitParams; }
1362 /// \brief Whether this lambda had its result type explicitly specified.
1363 bool hasExplicitResultType() const { return ExplicitResultType; }
1365 static bool classof(const Stmt *T) {
1366 return T->getStmtClass() == LambdaExprClass;
1368 static bool classof(const LambdaExpr *) { return true; }
1370 SourceRange getSourceRange() const LLVM_READONLY {
1371 return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
1374 child_range children() {
1375 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1378 friend class ASTStmtReader;
1379 friend class ASTStmtWriter;
1382 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1383 /// Expression "T()" which creates a value-initialized rvalue of type
1384 /// T, which is a non-class type.
1386 class CXXScalarValueInitExpr : public Expr {
1387 SourceLocation RParenLoc;
1388 TypeSourceInfo *TypeInfo;
1390 friend class ASTStmtReader;
1393 /// \brief Create an explicitly-written scalar-value initialization
1395 CXXScalarValueInitExpr(QualType Type,
1396 TypeSourceInfo *TypeInfo,
1397 SourceLocation rParenLoc ) :
1398 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1399 false, false, Type->isInstantiationDependentType(), false),
1400 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1402 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1403 : Expr(CXXScalarValueInitExprClass, Shell) { }
1405 TypeSourceInfo *getTypeSourceInfo() const {
1409 SourceLocation getRParenLoc() const { return RParenLoc; }
1411 SourceRange getSourceRange() const LLVM_READONLY;
1413 static bool classof(const Stmt *T) {
1414 return T->getStmtClass() == CXXScalarValueInitExprClass;
1416 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1419 child_range children() { return child_range(); }
1422 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1423 /// e.g: "new CXXNewExpr(foo)".
1424 class CXXNewExpr : public Expr {
1425 // Contains an optional array size expression, an optional initialization
1426 // expression, and any number of optional placement arguments, in that order.
1428 // Points to the allocation function used.
1429 FunctionDecl *OperatorNew;
1430 // Points to the deallocation function used in case of error. May be null.
1431 FunctionDecl *OperatorDelete;
1433 /// \brief The allocated type-source information, as written in the source.
1434 TypeSourceInfo *AllocatedTypeInfo;
1436 /// \brief If the allocated type was expressed as a parenthesized type-id,
1437 /// the source range covering the parenthesized type-id.
1438 SourceRange TypeIdParens;
1440 /// \brief Location of the first token.
1441 SourceLocation StartLoc;
1443 /// \brief Source-range of a paren-delimited initializer.
1444 SourceRange DirectInitRange;
1446 // Was the usage ::new, i.e. is the global new to be used?
1448 // Do we allocate an array? If so, the first SubExpr is the size expression.
1450 // If this is an array allocation, does the usual deallocation
1451 // function for the allocated type want to know the allocated size?
1452 bool UsualArrayDeleteWantsSize : 1;
1453 // The number of placement new arguments.
1454 unsigned NumPlacementArgs : 13;
1455 // What kind of initializer do we have? Could be none, parens, or braces.
1456 // In storage, we distinguish between "none, and no initializer expr", and
1457 // "none, but an implicit initializer expr".
1458 unsigned StoredInitializationStyle : 2;
1460 friend class ASTStmtReader;
1461 friend class ASTStmtWriter;
1463 enum InitializationStyle {
1464 NoInit, ///< New-expression has no initializer as written.
1465 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1466 ListInit ///< New-expression has a C++11 list-initializer.
1469 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1470 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1471 Expr **placementArgs, unsigned numPlaceArgs,
1472 SourceRange typeIdParens, Expr *arraySize,
1473 InitializationStyle initializationStyle, Expr *initializer,
1474 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1475 SourceLocation startLoc, SourceRange directInitRange);
1476 explicit CXXNewExpr(EmptyShell Shell)
1477 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1479 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1480 bool hasInitializer);
1482 QualType getAllocatedType() const {
1483 assert(getType()->isPointerType());
1484 return getType()->getAs<PointerType>()->getPointeeType();
1487 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1488 return AllocatedTypeInfo;
1491 /// \brief True if the allocation result needs to be null-checked.
1492 /// C++0x [expr.new]p13:
1493 /// If the allocation function returns null, initialization shall
1494 /// not be done, the deallocation function shall not be called,
1495 /// and the value of the new-expression shall be null.
1496 /// An allocation function is not allowed to return null unless it
1497 /// has a non-throwing exception-specification. The '03 rule is
1498 /// identical except that the definition of a non-throwing
1499 /// exception specification is just "is it throw()?".
1500 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1502 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1503 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1504 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1505 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1507 bool isArray() const { return Array; }
1508 Expr *getArraySize() {
1509 return Array ? cast<Expr>(SubExprs[0]) : 0;
1511 const Expr *getArraySize() const {
1512 return Array ? cast<Expr>(SubExprs[0]) : 0;
1515 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1516 Expr **getPlacementArgs() {
1517 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1520 Expr *getPlacementArg(unsigned i) {
1521 assert(i < NumPlacementArgs && "Index out of range");
1522 return getPlacementArgs()[i];
1524 const Expr *getPlacementArg(unsigned i) const {
1525 assert(i < NumPlacementArgs && "Index out of range");
1526 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1529 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1530 SourceRange getTypeIdParens() const { return TypeIdParens; }
1532 bool isGlobalNew() const { return GlobalNew; }
1534 /// \brief Whether this new-expression has any initializer at all.
1535 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1537 /// \brief The kind of initializer this new-expression has.
1538 InitializationStyle getInitializationStyle() const {
1539 if (StoredInitializationStyle == 0)
1541 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1544 /// \brief The initializer of this new-expression.
1545 Expr *getInitializer() {
1546 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1548 const Expr *getInitializer() const {
1549 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1552 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
1553 const CXXConstructExpr* getConstructExpr() {
1554 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1557 /// Answers whether the usual array deallocation function for the
1558 /// allocated type expects the size of the allocation as a
1560 bool doesUsualArrayDeleteWantSize() const {
1561 return UsualArrayDeleteWantsSize;
1564 typedef ExprIterator arg_iterator;
1565 typedef ConstExprIterator const_arg_iterator;
1567 arg_iterator placement_arg_begin() {
1568 return SubExprs + Array + hasInitializer();
1570 arg_iterator placement_arg_end() {
1571 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1573 const_arg_iterator placement_arg_begin() const {
1574 return SubExprs + Array + hasInitializer();
1576 const_arg_iterator placement_arg_end() const {
1577 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1580 typedef Stmt **raw_arg_iterator;
1581 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1582 raw_arg_iterator raw_arg_end() {
1583 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1585 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1586 const_arg_iterator raw_arg_end() const {
1587 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1590 SourceLocation getStartLoc() const { return StartLoc; }
1591 SourceLocation getEndLoc() const;
1593 SourceRange getDirectInitRange() const { return DirectInitRange; }
1595 SourceRange getSourceRange() const LLVM_READONLY {
1596 return SourceRange(getStartLoc(), getEndLoc());
1599 static bool classof(const Stmt *T) {
1600 return T->getStmtClass() == CXXNewExprClass;
1602 static bool classof(const CXXNewExpr *) { return true; }
1605 child_range children() {
1606 return child_range(raw_arg_begin(), raw_arg_end());
1610 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1611 /// calls, e.g. "delete[] pArray".
1612 class CXXDeleteExpr : public Expr {
1613 // Points to the operator delete overload that is used. Could be a member.
1614 FunctionDecl *OperatorDelete;
1615 // The pointer expression to be deleted.
1617 // Location of the expression.
1619 // Is this a forced global delete, i.e. "::delete"?
1620 bool GlobalDelete : 1;
1621 // Is this the array form of delete, i.e. "delete[]"?
1623 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1624 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1626 bool ArrayFormAsWritten : 1;
1627 // Does the usual deallocation function for the element type require
1628 // a size_t argument?
1629 bool UsualArrayDeleteWantsSize : 1;
1631 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1632 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1633 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1634 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1635 arg->isInstantiationDependent(),
1636 arg->containsUnexpandedParameterPack()),
1637 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1638 GlobalDelete(globalDelete),
1639 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1640 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
1641 explicit CXXDeleteExpr(EmptyShell Shell)
1642 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1644 bool isGlobalDelete() const { return GlobalDelete; }
1645 bool isArrayForm() const { return ArrayForm; }
1646 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1648 /// Answers whether the usual array deallocation function for the
1649 /// allocated type expects the size of the allocation as a
1650 /// parameter. This can be true even if the actual deallocation
1651 /// function that we're using doesn't want a size.
1652 bool doesUsualArrayDeleteWantSize() const {
1653 return UsualArrayDeleteWantsSize;
1656 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1658 Expr *getArgument() { return cast<Expr>(Argument); }
1659 const Expr *getArgument() const { return cast<Expr>(Argument); }
1661 /// \brief Retrieve the type being destroyed. If the type being
1662 /// destroyed is a dependent type which may or may not be a pointer,
1663 /// return an invalid type.
1664 QualType getDestroyedType() const;
1666 SourceRange getSourceRange() const LLVM_READONLY {
1667 return SourceRange(Loc, Argument->getLocEnd());
1670 static bool classof(const Stmt *T) {
1671 return T->getStmtClass() == CXXDeleteExprClass;
1673 static bool classof(const CXXDeleteExpr *) { return true; }
1676 child_range children() { return child_range(&Argument, &Argument+1); }
1678 friend class ASTStmtReader;
1681 /// \brief Structure used to store the type being destroyed by a
1682 /// pseudo-destructor expression.
1683 class PseudoDestructorTypeStorage {
1684 /// \brief Either the type source information or the name of the type, if
1685 /// it couldn't be resolved due to type-dependence.
1686 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1688 /// \brief The starting source location of the pseudo-destructor type.
1689 SourceLocation Location;
1692 PseudoDestructorTypeStorage() { }
1694 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1695 : Type(II), Location(Loc) { }
1697 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1699 TypeSourceInfo *getTypeSourceInfo() const {
1700 return Type.dyn_cast<TypeSourceInfo *>();
1703 IdentifierInfo *getIdentifier() const {
1704 return Type.dyn_cast<IdentifierInfo *>();
1707 SourceLocation getLocation() const { return Location; }
1710 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1712 /// A pseudo-destructor is an expression that looks like a member access to a
1713 /// destructor of a scalar type, except that scalar types don't have
1714 /// destructors. For example:
1718 /// void f(int *p) {
1723 /// Pseudo-destructors typically occur when instantiating templates such as:
1726 /// template<typename T>
1727 /// void destroy(T* ptr) {
1732 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1733 /// beyond evaluating the base expression.
1734 class CXXPseudoDestructorExpr : public Expr {
1735 /// \brief The base expression (that is being destroyed).
1738 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1742 /// \brief The location of the '.' or '->' operator.
1743 SourceLocation OperatorLoc;
1745 /// \brief The nested-name-specifier that follows the operator, if present.
1746 NestedNameSpecifierLoc QualifierLoc;
1748 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1750 TypeSourceInfo *ScopeType;
1752 /// \brief The location of the '::' in a qualified pseudo-destructor
1754 SourceLocation ColonColonLoc;
1756 /// \brief The location of the '~'.
1757 SourceLocation TildeLoc;
1759 /// \brief The type being destroyed, or its name if we were unable to
1760 /// resolve the name.
1761 PseudoDestructorTypeStorage DestroyedType;
1763 friend class ASTStmtReader;
1766 CXXPseudoDestructorExpr(ASTContext &Context,
1767 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1768 NestedNameSpecifierLoc QualifierLoc,
1769 TypeSourceInfo *ScopeType,
1770 SourceLocation ColonColonLoc,
1771 SourceLocation TildeLoc,
1772 PseudoDestructorTypeStorage DestroyedType);
1774 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1775 : Expr(CXXPseudoDestructorExprClass, Shell),
1776 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1778 Expr *getBase() const { return cast<Expr>(Base); }
1780 /// \brief Determines whether this member expression actually had
1781 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1783 bool hasQualifier() const { return QualifierLoc; }
1785 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1786 /// with source-location information.
1787 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1789 /// \brief If the member name was qualified, retrieves the
1790 /// nested-name-specifier that precedes the member name. Otherwise, returns
1792 NestedNameSpecifier *getQualifier() const {
1793 return QualifierLoc.getNestedNameSpecifier();
1796 /// \brief Determine whether this pseudo-destructor expression was written
1797 /// using an '->' (otherwise, it used a '.').
1798 bool isArrow() const { return IsArrow; }
1800 /// \brief Retrieve the location of the '.' or '->' operator.
1801 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1803 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1806 /// Pseudo-destructor expressions can have extra qualification within them
1807 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1808 /// Here, if the object type of the expression is (or may be) a scalar type,
1809 /// \p T may also be a scalar type and, therefore, cannot be part of a
1810 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1811 /// destructor expression.
1812 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1814 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1816 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1818 /// \brief Retrieve the location of the '~'.
1819 SourceLocation getTildeLoc() const { return TildeLoc; }
1821 /// \brief Retrieve the source location information for the type
1822 /// being destroyed.
1824 /// This type-source information is available for non-dependent
1825 /// pseudo-destructor expressions and some dependent pseudo-destructor
1826 /// expressions. Returns NULL if we only have the identifier for a
1827 /// dependent pseudo-destructor expression.
1828 TypeSourceInfo *getDestroyedTypeInfo() const {
1829 return DestroyedType.getTypeSourceInfo();
1832 /// \brief In a dependent pseudo-destructor expression for which we do not
1833 /// have full type information on the destroyed type, provides the name
1834 /// of the destroyed type.
1835 IdentifierInfo *getDestroyedTypeIdentifier() const {
1836 return DestroyedType.getIdentifier();
1839 /// \brief Retrieve the type being destroyed.
1840 QualType getDestroyedType() const;
1842 /// \brief Retrieve the starting location of the type being destroyed.
1843 SourceLocation getDestroyedTypeLoc() const {
1844 return DestroyedType.getLocation();
1847 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1849 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1850 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1853 /// \brief Set the destroyed type.
1854 void setDestroyedType(TypeSourceInfo *Info) {
1855 DestroyedType = PseudoDestructorTypeStorage(Info);
1858 SourceRange getSourceRange() const LLVM_READONLY;
1860 static bool classof(const Stmt *T) {
1861 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1863 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1866 child_range children() { return child_range(&Base, &Base + 1); }
1869 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1870 /// implementation of TR1/C++0x type trait templates.
1872 /// __is_pod(int) == true
1873 /// __is_enum(std::string) == false
1874 class UnaryTypeTraitExpr : public Expr {
1875 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1877 /// The value of the type trait. Unspecified if dependent.
1880 /// Loc - The location of the type trait keyword.
1883 /// RParen - The location of the closing paren.
1884 SourceLocation RParen;
1886 /// The type being queried.
1887 TypeSourceInfo *QueriedType;
1890 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1891 TypeSourceInfo *queried, bool value,
1892 SourceLocation rparen, QualType ty)
1893 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1894 false, queried->getType()->isDependentType(),
1895 queried->getType()->isInstantiationDependentType(),
1896 queried->getType()->containsUnexpandedParameterPack()),
1897 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1899 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1900 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1903 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
1905 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1907 QualType getQueriedType() const { return QueriedType->getType(); }
1909 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1911 bool getValue() const { return Value; }
1913 static bool classof(const Stmt *T) {
1914 return T->getStmtClass() == UnaryTypeTraitExprClass;
1916 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1919 child_range children() { return child_range(); }
1921 friend class ASTStmtReader;
1924 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1925 /// implementation of TR1/C++0x type trait templates.
1927 /// __is_base_of(Base, Derived) == true
1928 class BinaryTypeTraitExpr : public Expr {
1929 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1932 /// The value of the type trait. Unspecified if dependent.
1935 /// Loc - The location of the type trait keyword.
1938 /// RParen - The location of the closing paren.
1939 SourceLocation RParen;
1941 /// The lhs type being queried.
1942 TypeSourceInfo *LhsType;
1944 /// The rhs type being queried.
1945 TypeSourceInfo *RhsType;
1948 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1949 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1950 bool value, SourceLocation rparen, QualType ty)
1951 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1952 lhsType->getType()->isDependentType() ||
1953 rhsType->getType()->isDependentType(),
1954 (lhsType->getType()->isInstantiationDependentType() ||
1955 rhsType->getType()->isInstantiationDependentType()),
1956 (lhsType->getType()->containsUnexpandedParameterPack() ||
1957 rhsType->getType()->containsUnexpandedParameterPack())),
1958 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1959 LhsType(lhsType), RhsType(rhsType) { }
1962 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1963 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1964 LhsType(), RhsType() { }
1966 SourceRange getSourceRange() const LLVM_READONLY {
1967 return SourceRange(Loc, RParen);
1970 BinaryTypeTrait getTrait() const {
1971 return static_cast<BinaryTypeTrait>(BTT);
1974 QualType getLhsType() const { return LhsType->getType(); }
1975 QualType getRhsType() const { return RhsType->getType(); }
1977 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
1978 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1980 bool getValue() const { assert(!isTypeDependent()); return Value; }
1982 static bool classof(const Stmt *T) {
1983 return T->getStmtClass() == BinaryTypeTraitExprClass;
1985 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1988 child_range children() { return child_range(); }
1990 friend class ASTStmtReader;
1993 /// \brief A type trait used in the implementation of various C++11 and
1994 /// Library TR1 trait templates.
1997 /// __is_trivially_constructible(vector<int>, int*, int*)
1999 class TypeTraitExpr : public Expr {
2000 /// \brief The location of the type trait keyword.
2003 /// \brief The location of the closing parenthesis.
2004 SourceLocation RParenLoc;
2006 // Note: The TypeSourceInfos for the arguments are allocated after the
2009 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2010 ArrayRef<TypeSourceInfo *> Args,
2011 SourceLocation RParenLoc,
2014 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2016 /// \brief Retrieve the argument types.
2017 TypeSourceInfo **getTypeSourceInfos() {
2018 return reinterpret_cast<TypeSourceInfo **>(this+1);
2021 /// \brief Retrieve the argument types.
2022 TypeSourceInfo * const *getTypeSourceInfos() const {
2023 return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2027 /// \brief Create a new type trait expression.
2028 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
2030 ArrayRef<TypeSourceInfo *> Args,
2031 SourceLocation RParenLoc,
2034 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
2036 /// \brief Determine which type trait this expression uses.
2037 TypeTrait getTrait() const {
2038 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2041 bool getValue() const {
2042 assert(!isValueDependent());
2043 return TypeTraitExprBits.Value;
2046 /// \brief Determine the number of arguments to this type trait.
2047 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2049 /// \brief Retrieve the Ith argument.
2050 TypeSourceInfo *getArg(unsigned I) const {
2051 assert(I < getNumArgs() && "Argument out-of-range");
2052 return getArgs()[I];
2055 /// \brief Retrieve the argument types.
2056 ArrayRef<TypeSourceInfo *> getArgs() const {
2057 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
2060 typedef TypeSourceInfo **arg_iterator;
2061 arg_iterator arg_begin() {
2062 return getTypeSourceInfos();
2064 arg_iterator arg_end() {
2065 return getTypeSourceInfos() + getNumArgs();
2068 typedef TypeSourceInfo const * const *arg_const_iterator;
2069 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
2070 arg_const_iterator arg_end() const {
2071 return getTypeSourceInfos() + getNumArgs();
2074 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); }
2076 static bool classof(const Stmt *T) {
2077 return T->getStmtClass() == TypeTraitExprClass;
2079 static bool classof(const TypeTraitExpr *) { return true; }
2082 child_range children() { return child_range(); }
2084 friend class ASTStmtReader;
2085 friend class ASTStmtWriter;
2089 /// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
2090 /// implementation of __array_rank and __array_extent.
2092 /// __array_rank(int[10][20]) == 2
2093 /// __array_extent(int, 1) == 20
2094 class ArrayTypeTraitExpr : public Expr {
2095 virtual void anchor();
2097 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2100 /// The value of the type trait. Unspecified if dependent.
2103 /// The array dimension being queried, or -1 if not used
2106 /// Loc - The location of the type trait keyword.
2109 /// RParen - The location of the closing paren.
2110 SourceLocation RParen;
2112 /// The type being queried.
2113 TypeSourceInfo *QueriedType;
2116 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2117 TypeSourceInfo *queried, uint64_t value,
2118 Expr *dimension, SourceLocation rparen, QualType ty)
2119 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2120 false, queried->getType()->isDependentType(),
2121 (queried->getType()->isInstantiationDependentType() ||
2122 (dimension && dimension->isInstantiationDependent())),
2123 queried->getType()->containsUnexpandedParameterPack()),
2124 ATT(att), Value(value), Dimension(dimension),
2125 Loc(loc), RParen(rparen), QueriedType(queried) { }
2128 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2129 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2132 virtual ~ArrayTypeTraitExpr() { }
2134 virtual SourceRange getSourceRange() const LLVM_READONLY {
2135 return SourceRange(Loc, RParen);
2138 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2140 QualType getQueriedType() const { return QueriedType->getType(); }
2142 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2144 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2146 Expr *getDimensionExpression() const { return Dimension; }
2148 static bool classof(const Stmt *T) {
2149 return T->getStmtClass() == ArrayTypeTraitExprClass;
2151 static bool classof(const ArrayTypeTraitExpr *) { return true; }
2154 child_range children() { return child_range(); }
2156 friend class ASTStmtReader;
2159 /// ExpressionTraitExpr - An expression trait intrinsic
2161 /// __is_lvalue_expr(std::cout) == true
2162 /// __is_lvalue_expr(1) == false
2163 class ExpressionTraitExpr : public Expr {
2164 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
2166 /// The value of the type trait. Unspecified if dependent.
2169 /// Loc - The location of the type trait keyword.
2172 /// RParen - The location of the closing paren.
2173 SourceLocation RParen;
2175 Expr* QueriedExpression;
2177 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2178 Expr *queried, bool value,
2179 SourceLocation rparen, QualType resultType)
2180 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2181 false, // Not type-dependent
2182 // Value-dependent if the argument is type-dependent.
2183 queried->isTypeDependent(),
2184 queried->isInstantiationDependent(),
2185 queried->containsUnexpandedParameterPack()),
2186 ET(et), Value(value), Loc(loc), RParen(rparen),
2187 QueriedExpression(queried) { }
2189 explicit ExpressionTraitExpr(EmptyShell Empty)
2190 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2191 QueriedExpression() { }
2193 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
2195 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2197 Expr *getQueriedExpression() const { return QueriedExpression; }
2199 bool getValue() const { return Value; }
2201 static bool classof(const Stmt *T) {
2202 return T->getStmtClass() == ExpressionTraitExprClass;
2204 static bool classof(const ExpressionTraitExpr *) { return true; }
2207 child_range children() { return child_range(); }
2209 friend class ASTStmtReader;
2213 /// \brief A reference to an overloaded function set, either an
2214 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
2215 class OverloadExpr : public Expr {
2216 /// The common name of these declarations.
2217 DeclarationNameInfo NameInfo;
2219 /// \brief The nested-name-specifier that qualifies the name, if any.
2220 NestedNameSpecifierLoc QualifierLoc;
2222 /// The results. These are undesugared, which is to say, they may
2223 /// include UsingShadowDecls. Access is relative to the naming
2225 // FIXME: Allocate this data after the OverloadExpr subclass.
2226 DeclAccessPair *Results;
2227 unsigned NumResults;
2230 /// \brief Whether the name includes info for explicit template
2231 /// keyword and arguments.
2232 bool HasTemplateKWAndArgsInfo;
2234 /// \brief Return the optional template keyword and arguments info.
2235 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2237 /// \brief Return the optional template keyword and arguments info.
2238 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2239 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2242 OverloadExpr(StmtClass K, ASTContext &C,
2243 NestedNameSpecifierLoc QualifierLoc,
2244 SourceLocation TemplateKWLoc,
2245 const DeclarationNameInfo &NameInfo,
2246 const TemplateArgumentListInfo *TemplateArgs,
2247 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2248 bool KnownDependent,
2249 bool KnownInstantiationDependent,
2250 bool KnownContainsUnexpandedParameterPack);
2252 OverloadExpr(StmtClass K, EmptyShell Empty)
2253 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2254 HasTemplateKWAndArgsInfo(false) { }
2256 void initializeResults(ASTContext &C,
2257 UnresolvedSetIterator Begin,
2258 UnresolvedSetIterator End);
2262 OverloadExpr *Expression;
2263 bool IsAddressOfOperand;
2264 bool HasFormOfMemberPointer;
2267 /// Finds the overloaded expression in the given expression of
2270 /// \return the expression (which must be there) and true if it has
2271 /// the particular form of a member pointer expression
2272 static FindResult find(Expr *E) {
2273 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2277 E = E->IgnoreParens();
2278 if (isa<UnaryOperator>(E)) {
2279 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2280 E = cast<UnaryOperator>(E)->getSubExpr();
2281 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2283 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2284 Result.IsAddressOfOperand = true;
2285 Result.Expression = Ovl;
2287 Result.HasFormOfMemberPointer = false;
2288 Result.IsAddressOfOperand = false;
2289 Result.Expression = cast<OverloadExpr>(E);
2295 /// Gets the naming class of this lookup, if any.
2296 CXXRecordDecl *getNamingClass() const;
2298 typedef UnresolvedSetImpl::iterator decls_iterator;
2299 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2300 decls_iterator decls_end() const {
2301 return UnresolvedSetIterator(Results + NumResults);
2304 /// Gets the number of declarations in the unresolved set.
2305 unsigned getNumDecls() const { return NumResults; }
2307 /// Gets the full name info.
2308 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2310 /// Gets the name looked up.
2311 DeclarationName getName() const { return NameInfo.getName(); }
2313 /// Gets the location of the name.
2314 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2316 /// Fetches the nested-name qualifier, if one was given.
2317 NestedNameSpecifier *getQualifier() const {
2318 return QualifierLoc.getNestedNameSpecifier();
2321 /// Fetches the nested-name qualifier with source-location information, if
2323 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2325 /// \brief Retrieve the location of the template keyword preceding
2326 /// this name, if any.
2327 SourceLocation getTemplateKeywordLoc() const {
2328 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2329 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2332 /// \brief Retrieve the location of the left angle bracket starting the
2333 /// explicit template argument list following the name, if any.
2334 SourceLocation getLAngleLoc() const {
2335 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2336 return getTemplateKWAndArgsInfo()->LAngleLoc;
2339 /// \brief Retrieve the location of the right angle bracket ending the
2340 /// explicit template argument list following the name, if any.
2341 SourceLocation getRAngleLoc() const {
2342 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2343 return getTemplateKWAndArgsInfo()->RAngleLoc;
2346 /// Determines whether the name was preceded by the template keyword.
2347 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2349 /// Determines whether this expression had explicit template arguments.
2350 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2352 // Note that, inconsistently with the explicit-template-argument AST
2353 // nodes, users are *forbidden* from calling these methods on objects
2354 // without explicit template arguments.
2356 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2357 assert(hasExplicitTemplateArgs());
2358 return *getTemplateKWAndArgsInfo();
2361 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2362 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2365 TemplateArgumentLoc const *getTemplateArgs() const {
2366 return getExplicitTemplateArgs().getTemplateArgs();
2369 unsigned getNumTemplateArgs() const {
2370 return getExplicitTemplateArgs().NumTemplateArgs;
2373 /// Copies the template arguments into the given structure.
2374 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2375 getExplicitTemplateArgs().copyInto(List);
2378 /// \brief Retrieves the optional explicit template arguments.
2379 /// This points to the same data as getExplicitTemplateArgs(), but
2380 /// returns null if there are no explicit template arguments.
2381 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2382 if (!hasExplicitTemplateArgs()) return 0;
2383 return &getExplicitTemplateArgs();
2386 static bool classof(const Stmt *T) {
2387 return T->getStmtClass() == UnresolvedLookupExprClass ||
2388 T->getStmtClass() == UnresolvedMemberExprClass;
2390 static bool classof(const OverloadExpr *) { return true; }
2392 friend class ASTStmtReader;
2393 friend class ASTStmtWriter;
2396 /// \brief A reference to a name which we were able to look up during
2397 /// parsing but could not resolve to a specific declaration. This
2398 /// arises in several ways:
2399 /// * we might be waiting for argument-dependent lookup
2400 /// * the name might resolve to an overloaded function
2402 /// * the lookup might have included a function template
2403 /// These never include UnresolvedUsingValueDecls, which are always
2404 /// class members and therefore appear only in
2405 /// UnresolvedMemberLookupExprs.
2406 class UnresolvedLookupExpr : public OverloadExpr {
2407 /// True if these lookup results should be extended by
2408 /// argument-dependent lookup if this is the operand of a function
2412 /// True if namespace ::std should be considered an associated namespace
2413 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
2414 bool StdIsAssociatedNamespace;
2416 /// True if these lookup results are overloaded. This is pretty
2417 /// trivially rederivable if we urgently need to kill this field.
2420 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2421 /// any. This can generally be recalculated from the context chain,
2422 /// but that can be fairly expensive for unqualified lookups. If we
2423 /// want to improve memory use here, this could go in a union
2424 /// against the qualified-lookup bits.
2425 CXXRecordDecl *NamingClass;
2427 UnresolvedLookupExpr(ASTContext &C,
2428 CXXRecordDecl *NamingClass,
2429 NestedNameSpecifierLoc QualifierLoc,
2430 SourceLocation TemplateKWLoc,
2431 const DeclarationNameInfo &NameInfo,
2432 bool RequiresADL, bool Overloaded,
2433 const TemplateArgumentListInfo *TemplateArgs,
2434 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2435 bool StdIsAssociatedNamespace)
2436 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2437 NameInfo, TemplateArgs, Begin, End, false, false, false),
2438 RequiresADL(RequiresADL),
2439 StdIsAssociatedNamespace(StdIsAssociatedNamespace),
2440 Overloaded(Overloaded), NamingClass(NamingClass)
2443 UnresolvedLookupExpr(EmptyShell Empty)
2444 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2445 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
2449 friend class ASTStmtReader;
2452 static UnresolvedLookupExpr *Create(ASTContext &C,
2453 CXXRecordDecl *NamingClass,
2454 NestedNameSpecifierLoc QualifierLoc,
2455 const DeclarationNameInfo &NameInfo,
2456 bool ADL, bool Overloaded,
2457 UnresolvedSetIterator Begin,
2458 UnresolvedSetIterator End,
2459 bool StdIsAssociatedNamespace = false) {
2460 assert((ADL || !StdIsAssociatedNamespace) &&
2461 "std considered associated namespace when not performing ADL");
2462 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2463 SourceLocation(), NameInfo,
2464 ADL, Overloaded, 0, Begin, End,
2465 StdIsAssociatedNamespace);
2468 static UnresolvedLookupExpr *Create(ASTContext &C,
2469 CXXRecordDecl *NamingClass,
2470 NestedNameSpecifierLoc QualifierLoc,
2471 SourceLocation TemplateKWLoc,
2472 const DeclarationNameInfo &NameInfo,
2474 const TemplateArgumentListInfo *Args,
2475 UnresolvedSetIterator Begin,
2476 UnresolvedSetIterator End);
2478 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2479 bool HasTemplateKWAndArgsInfo,
2480 unsigned NumTemplateArgs);
2482 /// True if this declaration should be extended by
2483 /// argument-dependent lookup.
2484 bool requiresADL() const { return RequiresADL; }
2486 /// True if namespace ::std should be artificially added to the set of
2487 /// associated namespaecs for argument-dependent lookup purposes.
2488 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
2490 /// True if this lookup is overloaded.
2491 bool isOverloaded() const { return Overloaded; }
2493 /// Gets the 'naming class' (in the sense of C++0x
2494 /// [class.access.base]p5) of the lookup. This is the scope
2495 /// that was looked in to find these results.
2496 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2498 SourceRange getSourceRange() const LLVM_READONLY {
2499 SourceRange Range(getNameInfo().getSourceRange());
2500 if (getQualifierLoc())
2501 Range.setBegin(getQualifierLoc().getBeginLoc());
2502 if (hasExplicitTemplateArgs())
2503 Range.setEnd(getRAngleLoc());
2507 child_range children() { return child_range(); }
2509 static bool classof(const Stmt *T) {
2510 return T->getStmtClass() == UnresolvedLookupExprClass;
2512 static bool classof(const UnresolvedLookupExpr *) { return true; }
2515 /// \brief A qualified reference to a name whose declaration cannot
2516 /// yet be resolved.
2518 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2519 /// it expresses a reference to a declaration such as
2520 /// X<T>::value. The difference, however, is that an
2521 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2522 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2523 /// this case, X<T>::value cannot resolve to a declaration because the
2524 /// declaration will differ from on instantiation of X<T> to the
2525 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2526 /// qualifier (X<T>::) and the name of the entity being referenced
2527 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2528 /// declaration can be found.
2529 class DependentScopeDeclRefExpr : public Expr {
2530 /// \brief The nested-name-specifier that qualifies this unresolved
2531 /// declaration name.
2532 NestedNameSpecifierLoc QualifierLoc;
2534 /// The name of the entity we will be referencing.
2535 DeclarationNameInfo NameInfo;
2537 /// \brief Whether the name includes info for explicit template
2538 /// keyword and arguments.
2539 bool HasTemplateKWAndArgsInfo;
2541 /// \brief Return the optional template keyword and arguments info.
2542 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2543 if (!HasTemplateKWAndArgsInfo) return 0;
2544 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2546 /// \brief Return the optional template keyword and arguments info.
2547 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2548 return const_cast<DependentScopeDeclRefExpr*>(this)
2549 ->getTemplateKWAndArgsInfo();
2552 DependentScopeDeclRefExpr(QualType T,
2553 NestedNameSpecifierLoc QualifierLoc,
2554 SourceLocation TemplateKWLoc,
2555 const DeclarationNameInfo &NameInfo,
2556 const TemplateArgumentListInfo *Args);
2559 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2560 NestedNameSpecifierLoc QualifierLoc,
2561 SourceLocation TemplateKWLoc,
2562 const DeclarationNameInfo &NameInfo,
2563 const TemplateArgumentListInfo *TemplateArgs);
2565 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2566 bool HasTemplateKWAndArgsInfo,
2567 unsigned NumTemplateArgs);
2569 /// \brief Retrieve the name that this expression refers to.
2570 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2572 /// \brief Retrieve the name that this expression refers to.
2573 DeclarationName getDeclName() const { return NameInfo.getName(); }
2575 /// \brief Retrieve the location of the name within the expression.
2576 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2578 /// \brief Retrieve the nested-name-specifier that qualifies the
2579 /// name, with source location information.
2580 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2583 /// \brief Retrieve the nested-name-specifier that qualifies this
2585 NestedNameSpecifier *getQualifier() const {
2586 return QualifierLoc.getNestedNameSpecifier();
2589 /// \brief Retrieve the location of the template keyword preceding
2590 /// this name, if any.
2591 SourceLocation getTemplateKeywordLoc() const {
2592 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2593 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2596 /// \brief Retrieve the location of the left angle bracket starting the
2597 /// explicit template argument list following the name, if any.
2598 SourceLocation getLAngleLoc() const {
2599 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2600 return getTemplateKWAndArgsInfo()->LAngleLoc;
2603 /// \brief Retrieve the location of the right angle bracket ending the
2604 /// explicit template argument list following the name, if any.
2605 SourceLocation getRAngleLoc() const {
2606 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2607 return getTemplateKWAndArgsInfo()->RAngleLoc;
2610 /// Determines whether the name was preceded by the template keyword.
2611 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2613 /// Determines whether this lookup had explicit template arguments.
2614 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2616 // Note that, inconsistently with the explicit-template-argument AST
2617 // nodes, users are *forbidden* from calling these methods on objects
2618 // without explicit template arguments.
2620 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2621 assert(hasExplicitTemplateArgs());
2622 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2625 /// Gets a reference to the explicit template argument list.
2626 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2627 assert(hasExplicitTemplateArgs());
2628 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2631 /// \brief Retrieves the optional explicit template arguments.
2632 /// This points to the same data as getExplicitTemplateArgs(), but
2633 /// returns null if there are no explicit template arguments.
2634 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2635 if (!hasExplicitTemplateArgs()) return 0;
2636 return &getExplicitTemplateArgs();
2639 /// \brief Copies the template arguments (if present) into the given
2641 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2642 getExplicitTemplateArgs().copyInto(List);
2645 TemplateArgumentLoc const *getTemplateArgs() const {
2646 return getExplicitTemplateArgs().getTemplateArgs();
2649 unsigned getNumTemplateArgs() const {
2650 return getExplicitTemplateArgs().NumTemplateArgs;
2653 SourceRange getSourceRange() const LLVM_READONLY {
2654 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2655 if (hasExplicitTemplateArgs())
2656 Range.setEnd(getRAngleLoc());
2660 static bool classof(const Stmt *T) {
2661 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2663 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2665 child_range children() { return child_range(); }
2667 friend class ASTStmtReader;
2668 friend class ASTStmtWriter;
2671 /// Represents an expression --- generally a full-expression --- which
2672 /// introduces cleanups to be run at the end of the sub-expression's
2673 /// evaluation. The most common source of expression-introduced
2674 /// cleanups is temporary objects in C++, but several other kinds of
2675 /// expressions can create cleanups, including basically every
2676 /// call in ARC that returns an Objective-C pointer.
2678 /// This expression also tracks whether the sub-expression contains a
2679 /// potentially-evaluated block literal. The lifetime of a block
2680 /// literal is the extent of the enclosing scope.
2681 class ExprWithCleanups : public Expr {
2683 /// The type of objects that are kept in the cleanup.
2684 /// It's useful to remember the set of blocks; we could also
2685 /// remember the set of temporaries, but there's currently
2687 typedef BlockDecl *CleanupObject;
2692 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2693 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2695 CleanupObject *getObjectsBuffer() {
2696 return reinterpret_cast<CleanupObject*>(this + 1);
2698 const CleanupObject *getObjectsBuffer() const {
2699 return reinterpret_cast<const CleanupObject*>(this + 1);
2701 friend class ASTStmtReader;
2704 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
2705 unsigned numObjects);
2707 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
2708 ArrayRef<CleanupObject> objects);
2710 ArrayRef<CleanupObject> getObjects() const {
2711 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2714 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2716 CleanupObject getObject(unsigned i) const {
2717 assert(i < getNumObjects() && "Index out of range");
2718 return getObjects()[i];
2721 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2722 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2724 /// setSubExpr - As with any mutator of the AST, be very careful
2725 /// when modifying an existing AST to preserve its invariants.
2726 void setSubExpr(Expr *E) { SubExpr = E; }
2728 SourceRange getSourceRange() const LLVM_READONLY {
2729 return SubExpr->getSourceRange();
2732 // Implement isa/cast/dyncast/etc.
2733 static bool classof(const Stmt *T) {
2734 return T->getStmtClass() == ExprWithCleanupsClass;
2736 static bool classof(const ExprWithCleanups *) { return true; }
2739 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2742 /// \brief Describes an explicit type conversion that uses functional
2743 /// notion but could not be resolved because one or more arguments are
2746 /// The explicit type conversions expressed by
2747 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2748 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2749 /// either \C T is a dependent type or one or more of the \c a's is
2750 /// type-dependent. For example, this would occur in a template such
2754 /// template<typename T, typename A1>
2755 /// inline T make_a(const A1& a1) {
2760 /// When the returned expression is instantiated, it may resolve to a
2761 /// constructor call, conversion function call, or some kind of type
2763 class CXXUnresolvedConstructExpr : public Expr {
2764 /// \brief The type being constructed.
2765 TypeSourceInfo *Type;
2767 /// \brief The location of the left parentheses ('(').
2768 SourceLocation LParenLoc;
2770 /// \brief The location of the right parentheses (')').
2771 SourceLocation RParenLoc;
2773 /// \brief The number of arguments used to construct the type.
2776 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2777 SourceLocation LParenLoc,
2780 SourceLocation RParenLoc);
2782 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2783 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2785 friend class ASTStmtReader;
2788 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2789 TypeSourceInfo *Type,
2790 SourceLocation LParenLoc,
2793 SourceLocation RParenLoc);
2795 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2798 /// \brief Retrieve the type that is being constructed, as specified
2799 /// in the source code.
2800 QualType getTypeAsWritten() const { return Type->getType(); }
2802 /// \brief Retrieve the type source information for the type being
2804 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2806 /// \brief Retrieve the location of the left parentheses ('(') that
2807 /// precedes the argument list.
2808 SourceLocation getLParenLoc() const { return LParenLoc; }
2809 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2811 /// \brief Retrieve the location of the right parentheses (')') that
2812 /// follows the argument list.
2813 SourceLocation getRParenLoc() const { return RParenLoc; }
2814 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2816 /// \brief Retrieve the number of arguments.
2817 unsigned arg_size() const { return NumArgs; }
2819 typedef Expr** arg_iterator;
2820 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2821 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2823 typedef const Expr* const * const_arg_iterator;
2824 const_arg_iterator arg_begin() const {
2825 return reinterpret_cast<const Expr* const *>(this + 1);
2827 const_arg_iterator arg_end() const {
2828 return arg_begin() + NumArgs;
2831 Expr *getArg(unsigned I) {
2832 assert(I < NumArgs && "Argument index out-of-range");
2833 return *(arg_begin() + I);
2836 const Expr *getArg(unsigned I) const {
2837 assert(I < NumArgs && "Argument index out-of-range");
2838 return *(arg_begin() + I);
2841 void setArg(unsigned I, Expr *E) {
2842 assert(I < NumArgs && "Argument index out-of-range");
2843 *(arg_begin() + I) = E;
2846 SourceRange getSourceRange() const LLVM_READONLY;
2848 static bool classof(const Stmt *T) {
2849 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2851 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2854 child_range children() {
2855 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2856 return child_range(begin, begin + NumArgs);
2860 /// \brief Represents a C++ member access expression where the actual
2861 /// member referenced could not be resolved because the base
2862 /// expression or the member name was dependent.
2864 /// Like UnresolvedMemberExprs, these can be either implicit or
2865 /// explicit accesses. It is only possible to get one of these with
2866 /// an implicit access if a qualifier is provided.
2867 class CXXDependentScopeMemberExpr : public Expr {
2868 /// \brief The expression for the base pointer or class reference,
2869 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2872 /// \brief The type of the base expression. Never null, even for
2873 /// implicit accesses.
2876 /// \brief Whether this member expression used the '->' operator or
2877 /// the '.' operator.
2880 /// \brief Whether this member expression has info for explicit template
2881 /// keyword and arguments.
2882 bool HasTemplateKWAndArgsInfo : 1;
2884 /// \brief The location of the '->' or '.' operator.
2885 SourceLocation OperatorLoc;
2887 /// \brief The nested-name-specifier that precedes the member name, if any.
2888 NestedNameSpecifierLoc QualifierLoc;
2890 /// \brief In a qualified member access expression such as t->Base::f, this
2891 /// member stores the resolves of name lookup in the context of the member
2892 /// access expression, to be used at instantiation time.
2894 /// FIXME: This member, along with the QualifierLoc, could
2895 /// be stuck into a structure that is optionally allocated at the end of
2896 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2897 NamedDecl *FirstQualifierFoundInScope;
2899 /// \brief The member to which this member expression refers, which
2900 /// can be name, overloaded operator, or destructor.
2901 /// FIXME: could also be a template-id
2902 DeclarationNameInfo MemberNameInfo;
2904 /// \brief Return the optional template keyword and arguments info.
2905 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2906 if (!HasTemplateKWAndArgsInfo) return 0;
2907 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2909 /// \brief Return the optional template keyword and arguments info.
2910 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2911 return const_cast<CXXDependentScopeMemberExpr*>(this)
2912 ->getTemplateKWAndArgsInfo();
2915 CXXDependentScopeMemberExpr(ASTContext &C,
2916 Expr *Base, QualType BaseType, bool IsArrow,
2917 SourceLocation OperatorLoc,
2918 NestedNameSpecifierLoc QualifierLoc,
2919 SourceLocation TemplateKWLoc,
2920 NamedDecl *FirstQualifierFoundInScope,
2921 DeclarationNameInfo MemberNameInfo,
2922 const TemplateArgumentListInfo *TemplateArgs);
2925 CXXDependentScopeMemberExpr(ASTContext &C,
2926 Expr *Base, QualType BaseType,
2928 SourceLocation OperatorLoc,
2929 NestedNameSpecifierLoc QualifierLoc,
2930 NamedDecl *FirstQualifierFoundInScope,
2931 DeclarationNameInfo MemberNameInfo);
2933 static CXXDependentScopeMemberExpr *
2934 Create(ASTContext &C,
2935 Expr *Base, QualType BaseType, bool IsArrow,
2936 SourceLocation OperatorLoc,
2937 NestedNameSpecifierLoc QualifierLoc,
2938 SourceLocation TemplateKWLoc,
2939 NamedDecl *FirstQualifierFoundInScope,
2940 DeclarationNameInfo MemberNameInfo,
2941 const TemplateArgumentListInfo *TemplateArgs);
2943 static CXXDependentScopeMemberExpr *
2944 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2945 unsigned NumTemplateArgs);
2947 /// \brief True if this is an implicit access, i.e. one in which the
2948 /// member being accessed was not written in the source. The source
2949 /// location of the operator is invalid in this case.
2950 bool isImplicitAccess() const;
2952 /// \brief Retrieve the base object of this member expressions,
2953 /// e.g., the \c x in \c x.m.
2954 Expr *getBase() const {
2955 assert(!isImplicitAccess());
2956 return cast<Expr>(Base);
2959 QualType getBaseType() const { return BaseType; }
2961 /// \brief Determine whether this member expression used the '->'
2962 /// operator; otherwise, it used the '.' operator.
2963 bool isArrow() const { return IsArrow; }
2965 /// \brief Retrieve the location of the '->' or '.' operator.
2966 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2968 /// \brief Retrieve the nested-name-specifier that qualifies the member
2970 NestedNameSpecifier *getQualifier() const {
2971 return QualifierLoc.getNestedNameSpecifier();
2974 /// \brief Retrieve the nested-name-specifier that qualifies the member
2975 /// name, with source location information.
2976 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2979 /// \brief Retrieve the first part of the nested-name-specifier that was
2980 /// found in the scope of the member access expression when the member access
2981 /// was initially parsed.
2983 /// This function only returns a useful result when member access expression
2984 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2985 /// returned by this function describes what was found by unqualified name
2986 /// lookup for the identifier "Base" within the scope of the member access
2987 /// expression itself. At template instantiation time, this information is
2988 /// combined with the results of name lookup into the type of the object
2989 /// expression itself (the class type of x).
2990 NamedDecl *getFirstQualifierFoundInScope() const {
2991 return FirstQualifierFoundInScope;
2994 /// \brief Retrieve the name of the member that this expression
2996 const DeclarationNameInfo &getMemberNameInfo() const {
2997 return MemberNameInfo;
3000 /// \brief Retrieve the name of the member that this expression
3002 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3004 // \brief Retrieve the location of the name of the member that this
3005 // expression refers to.
3006 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3008 /// \brief Retrieve the location of the template keyword preceding the
3009 /// member name, if any.
3010 SourceLocation getTemplateKeywordLoc() const {
3011 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3012 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3015 /// \brief Retrieve the location of the left angle bracket starting the
3016 /// explicit template argument list following the member name, if any.
3017 SourceLocation getLAngleLoc() const {
3018 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3019 return getTemplateKWAndArgsInfo()->LAngleLoc;
3022 /// \brief Retrieve the location of the right angle bracket ending the
3023 /// explicit template argument list following the member name, if any.
3024 SourceLocation getRAngleLoc() const {
3025 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3026 return getTemplateKWAndArgsInfo()->RAngleLoc;
3029 /// Determines whether the member name was preceded by the template keyword.
3030 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3032 /// \brief Determines whether this member expression actually had a C++
3033 /// template argument list explicitly specified, e.g., x.f<int>.
3034 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3036 /// \brief Retrieve the explicit template argument list that followed the
3037 /// member template name, if any.
3038 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3039 assert(hasExplicitTemplateArgs());
3040 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3043 /// \brief Retrieve the explicit template argument list that followed the
3044 /// member template name, if any.
3045 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3046 return const_cast<CXXDependentScopeMemberExpr *>(this)
3047 ->getExplicitTemplateArgs();
3050 /// \brief Retrieves the optional explicit template arguments.
3051 /// This points to the same data as getExplicitTemplateArgs(), but
3052 /// returns null if there are no explicit template arguments.
3053 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
3054 if (!hasExplicitTemplateArgs()) return 0;
3055 return &getExplicitTemplateArgs();
3058 /// \brief Copies the template arguments (if present) into the given
3060 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3061 getExplicitTemplateArgs().copyInto(List);
3064 /// \brief Initializes the template arguments using the given structure.
3065 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3066 getExplicitTemplateArgs().initializeFrom(List);
3069 /// \brief Retrieve the template arguments provided as part of this
3071 const TemplateArgumentLoc *getTemplateArgs() const {
3072 return getExplicitTemplateArgs().getTemplateArgs();
3075 /// \brief Retrieve the number of template arguments provided as part of this
3077 unsigned getNumTemplateArgs() const {
3078 return getExplicitTemplateArgs().NumTemplateArgs;
3081 SourceRange getSourceRange() const LLVM_READONLY {
3083 if (!isImplicitAccess())
3084 Range.setBegin(Base->getSourceRange().getBegin());
3085 else if (getQualifier())
3086 Range.setBegin(getQualifierLoc().getBeginLoc());
3088 Range.setBegin(MemberNameInfo.getBeginLoc());
3090 if (hasExplicitTemplateArgs())
3091 Range.setEnd(getRAngleLoc());
3093 Range.setEnd(MemberNameInfo.getEndLoc());
3097 static bool classof(const Stmt *T) {
3098 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3100 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
3103 child_range children() {
3104 if (isImplicitAccess()) return child_range();
3105 return child_range(&Base, &Base + 1);
3108 friend class ASTStmtReader;
3109 friend class ASTStmtWriter;
3112 /// \brief Represents a C++ member access expression for which lookup
3113 /// produced a set of overloaded functions.
3115 /// The member access may be explicit or implicit:
3118 /// int explicitAccess() { return this->a + this->A::b; }
3119 /// int implicitAccess() { return a + A::b; }
3122 /// In the final AST, an explicit access always becomes a MemberExpr.
3123 /// An implicit access may become either a MemberExpr or a
3124 /// DeclRefExpr, depending on whether the member is static.
3125 class UnresolvedMemberExpr : public OverloadExpr {
3126 /// \brief Whether this member expression used the '->' operator or
3127 /// the '.' operator.
3130 /// \brief Whether the lookup results contain an unresolved using
3132 bool HasUnresolvedUsing : 1;
3134 /// \brief The expression for the base pointer or class reference,
3135 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
3136 /// member expression
3139 /// \brief The type of the base expression; never null.
3142 /// \brief The location of the '->' or '.' operator.
3143 SourceLocation OperatorLoc;
3145 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3146 Expr *Base, QualType BaseType, bool IsArrow,
3147 SourceLocation OperatorLoc,
3148 NestedNameSpecifierLoc QualifierLoc,
3149 SourceLocation TemplateKWLoc,
3150 const DeclarationNameInfo &MemberNameInfo,
3151 const TemplateArgumentListInfo *TemplateArgs,
3152 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3154 UnresolvedMemberExpr(EmptyShell Empty)
3155 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3156 HasUnresolvedUsing(false), Base(0) { }
3158 friend class ASTStmtReader;
3161 static UnresolvedMemberExpr *
3162 Create(ASTContext &C, bool HasUnresolvedUsing,
3163 Expr *Base, QualType BaseType, bool IsArrow,
3164 SourceLocation OperatorLoc,
3165 NestedNameSpecifierLoc QualifierLoc,
3166 SourceLocation TemplateKWLoc,
3167 const DeclarationNameInfo &MemberNameInfo,
3168 const TemplateArgumentListInfo *TemplateArgs,
3169 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3171 static UnresolvedMemberExpr *
3172 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3173 unsigned NumTemplateArgs);
3175 /// \brief True if this is an implicit access, i.e. one in which the
3176 /// member being accessed was not written in the source. The source
3177 /// location of the operator is invalid in this case.
3178 bool isImplicitAccess() const;
3180 /// \brief Retrieve the base object of this member expressions,
3181 /// e.g., the \c x in \c x.m.
3183 assert(!isImplicitAccess());
3184 return cast<Expr>(Base);
3186 const Expr *getBase() const {
3187 assert(!isImplicitAccess());
3188 return cast<Expr>(Base);
3191 QualType getBaseType() const { return BaseType; }
3193 /// \brief Determine whether the lookup results contain an unresolved using
3195 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3197 /// \brief Determine whether this member expression used the '->'
3198 /// operator; otherwise, it used the '.' operator.
3199 bool isArrow() const { return IsArrow; }
3201 /// \brief Retrieve the location of the '->' or '.' operator.
3202 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3204 /// \brief Retrieves the naming class of this lookup.
3205 CXXRecordDecl *getNamingClass() const;
3207 /// \brief Retrieve the full name info for the member that this expression
3209 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3211 /// \brief Retrieve the name of the member that this expression
3213 DeclarationName getMemberName() const { return getName(); }
3215 // \brief Retrieve the location of the name of the member that this
3216 // expression refers to.
3217 SourceLocation getMemberLoc() const { return getNameLoc(); }
3219 SourceRange getSourceRange() const LLVM_READONLY {
3220 SourceRange Range = getMemberNameInfo().getSourceRange();
3221 if (!isImplicitAccess())
3222 Range.setBegin(Base->getSourceRange().getBegin());
3223 else if (getQualifierLoc())
3224 Range.setBegin(getQualifierLoc().getBeginLoc());
3226 if (hasExplicitTemplateArgs())
3227 Range.setEnd(getRAngleLoc());
3231 static bool classof(const Stmt *T) {
3232 return T->getStmtClass() == UnresolvedMemberExprClass;
3234 static bool classof(const UnresolvedMemberExpr *) { return true; }
3237 child_range children() {
3238 if (isImplicitAccess()) return child_range();
3239 return child_range(&Base, &Base + 1);
3243 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
3245 /// The noexcept expression tests whether a given expression might throw. Its
3246 /// result is a boolean constant.
3247 class CXXNoexceptExpr : public Expr {
3252 friend class ASTStmtReader;
3255 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3256 SourceLocation Keyword, SourceLocation RParen)
3257 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3258 /*TypeDependent*/false,
3259 /*ValueDependent*/Val == CT_Dependent,
3260 Val == CT_Dependent || Operand->isInstantiationDependent(),
3261 Operand->containsUnexpandedParameterPack()),
3262 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3265 CXXNoexceptExpr(EmptyShell Empty)
3266 : Expr(CXXNoexceptExprClass, Empty)
3269 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3271 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3273 bool getValue() const { return Value; }
3275 static bool classof(const Stmt *T) {
3276 return T->getStmtClass() == CXXNoexceptExprClass;
3278 static bool classof(const CXXNoexceptExpr *) { return true; }
3281 child_range children() { return child_range(&Operand, &Operand + 1); }
3284 /// \brief Represents a C++0x pack expansion that produces a sequence of
3287 /// A pack expansion expression contains a pattern (which itself is an
3288 /// expression) followed by an ellipsis. For example:
3291 /// template<typename F, typename ...Types>
3292 /// void forward(F f, Types &&...args) {
3293 /// f(static_cast<Types&&>(args)...);
3297 /// Here, the argument to the function object \c f is a pack expansion whose
3298 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3299 /// template is instantiated, the pack expansion will instantiate to zero or
3300 /// or more function arguments to the function object \c f.
3301 class PackExpansionExpr : public Expr {
3302 SourceLocation EllipsisLoc;
3304 /// \brief The number of expansions that will be produced by this pack
3305 /// expansion expression, if known.
3307 /// When zero, the number of expansions is not known. Otherwise, this value
3308 /// is the number of expansions + 1.
3309 unsigned NumExpansions;
3313 friend class ASTStmtReader;
3314 friend class ASTStmtWriter;
3317 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3318 llvm::Optional<unsigned> NumExpansions)
3319 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3320 Pattern->getObjectKind(), /*TypeDependent=*/true,
3321 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3322 /*ContainsUnexpandedParameterPack=*/false),
3323 EllipsisLoc(EllipsisLoc),
3324 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3325 Pattern(Pattern) { }
3327 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3329 /// \brief Retrieve the pattern of the pack expansion.
3330 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3332 /// \brief Retrieve the pattern of the pack expansion.
3333 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3335 /// \brief Retrieve the location of the ellipsis that describes this pack
3337 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3339 /// \brief Determine the number of expansions that will be produced when
3340 /// this pack expansion is instantiated, if already known.
3341 llvm::Optional<unsigned> getNumExpansions() const {
3343 return NumExpansions - 1;
3345 return llvm::Optional<unsigned>();
3348 SourceRange getSourceRange() const LLVM_READONLY {
3349 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
3352 static bool classof(const Stmt *T) {
3353 return T->getStmtClass() == PackExpansionExprClass;
3355 static bool classof(const PackExpansionExpr *) { return true; }
3358 child_range children() {
3359 return child_range(&Pattern, &Pattern + 1);
3363 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3364 if (!HasTemplateKWAndArgsInfo) return 0;
3365 if (isa<UnresolvedLookupExpr>(this))
3366 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3367 (cast<UnresolvedLookupExpr>(this) + 1);
3369 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3370 (cast<UnresolvedMemberExpr>(this) + 1);
3373 /// \brief Represents an expression that computes the length of a parameter
3377 /// template<typename ...Types>
3379 /// static const unsigned value = sizeof...(Types);
3382 class SizeOfPackExpr : public Expr {
3383 /// \brief The location of the 'sizeof' keyword.
3384 SourceLocation OperatorLoc;
3386 /// \brief The location of the name of the parameter pack.
3387 SourceLocation PackLoc;
3389 /// \brief The location of the closing parenthesis.
3390 SourceLocation RParenLoc;
3392 /// \brief The length of the parameter pack, if known.
3394 /// When this expression is value-dependent, the length of the parameter pack
3395 /// is unknown. When this expression is not value-dependent, the length is
3399 /// \brief The parameter pack itself.
3402 friend class ASTStmtReader;
3403 friend class ASTStmtWriter;
3406 /// \brief Creates a value-dependent expression that computes the length of
3407 /// the given parameter pack.
3408 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3409 SourceLocation PackLoc, SourceLocation RParenLoc)
3410 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3411 /*TypeDependent=*/false, /*ValueDependent=*/true,
3412 /*InstantiationDependent=*/true,
3413 /*ContainsUnexpandedParameterPack=*/false),
3414 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3415 Length(0), Pack(Pack) { }
3417 /// \brief Creates an expression that computes the length of
3418 /// the given parameter pack, which is already known.
3419 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3420 SourceLocation PackLoc, SourceLocation RParenLoc,
3422 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3423 /*TypeDependent=*/false, /*ValueDependent=*/false,
3424 /*InstantiationDependent=*/false,
3425 /*ContainsUnexpandedParameterPack=*/false),
3426 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3427 Length(Length), Pack(Pack) { }
3429 /// \brief Create an empty expression.
3430 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3432 /// \brief Determine the location of the 'sizeof' keyword.
3433 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3435 /// \brief Determine the location of the parameter pack.
3436 SourceLocation getPackLoc() const { return PackLoc; }
3438 /// \brief Determine the location of the right parenthesis.
3439 SourceLocation getRParenLoc() const { return RParenLoc; }
3441 /// \brief Retrieve the parameter pack.
3442 NamedDecl *getPack() const { return Pack; }
3444 /// \brief Retrieve the length of the parameter pack.
3446 /// This routine may only be invoked when the expression is not
3447 /// value-dependent.
3448 unsigned getPackLength() const {
3449 assert(!isValueDependent() &&
3450 "Cannot get the length of a value-dependent pack size expression");
3454 SourceRange getSourceRange() const LLVM_READONLY {
3455 return SourceRange(OperatorLoc, RParenLoc);
3458 static bool classof(const Stmt *T) {
3459 return T->getStmtClass() == SizeOfPackExprClass;
3461 static bool classof(const SizeOfPackExpr *) { return true; }
3464 child_range children() { return child_range(); }
3467 /// \brief Represents a reference to a non-type template parameter
3468 /// that has been substituted with a template argument.
3469 class SubstNonTypeTemplateParmExpr : public Expr {
3470 /// \brief The replaced parameter.
3471 NonTypeTemplateParmDecl *Param;
3473 /// \brief The replacement expression.
3476 /// \brief The location of the non-type template parameter reference.
3477 SourceLocation NameLoc;
3479 friend class ASTReader;
3480 friend class ASTStmtReader;
3481 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3482 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3485 SubstNonTypeTemplateParmExpr(QualType type,
3486 ExprValueKind valueKind,
3488 NonTypeTemplateParmDecl *param,
3490 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3491 replacement->isTypeDependent(), replacement->isValueDependent(),
3492 replacement->isInstantiationDependent(),
3493 replacement->containsUnexpandedParameterPack()),
3494 Param(param), Replacement(replacement), NameLoc(loc) {}
3496 SourceLocation getNameLoc() const { return NameLoc; }
3497 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3499 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3501 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3503 static bool classof(const Stmt *s) {
3504 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3506 static bool classof(const SubstNonTypeTemplateParmExpr *) {
3511 child_range children() { return child_range(&Replacement, &Replacement+1); }
3514 /// \brief Represents a reference to a non-type template parameter pack that
3515 /// has been substituted with a non-template argument pack.
3517 /// When a pack expansion in the source code contains multiple parameter packs
3518 /// and those parameter packs correspond to different levels of template
3519 /// parameter lists, this node node is used to represent a non-type template
3520 /// parameter pack from an outer level, which has already had its argument pack
3521 /// substituted but that still lives within a pack expansion that itself
3522 /// could not be instantiated. When actually performing a substitution into
3523 /// that pack expansion (e.g., when all template parameters have corresponding
3524 /// arguments), this type will be replaced with the appropriate underlying
3525 /// expression at the current pack substitution index.
3526 class SubstNonTypeTemplateParmPackExpr : public Expr {
3527 /// \brief The non-type template parameter pack itself.
3528 NonTypeTemplateParmDecl *Param;
3530 /// \brief A pointer to the set of template arguments that this
3531 /// parameter pack is instantiated with.
3532 const TemplateArgument *Arguments;
3534 /// \brief The number of template arguments in \c Arguments.
3535 unsigned NumArguments;
3537 /// \brief The location of the non-type template parameter pack reference.
3538 SourceLocation NameLoc;
3540 friend class ASTReader;
3541 friend class ASTStmtReader;
3542 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3543 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3546 SubstNonTypeTemplateParmPackExpr(QualType T,
3547 NonTypeTemplateParmDecl *Param,
3548 SourceLocation NameLoc,
3549 const TemplateArgument &ArgPack);
3551 /// \brief Retrieve the non-type template parameter pack being substituted.
3552 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3554 /// \brief Retrieve the location of the parameter pack name.
3555 SourceLocation getParameterPackLocation() const { return NameLoc; }
3557 /// \brief Retrieve the template argument pack containing the substituted
3558 /// template arguments.
3559 TemplateArgument getArgumentPack() const;
3561 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3563 static bool classof(const Stmt *T) {
3564 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3566 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3571 child_range children() { return child_range(); }
3574 /// \brief Represents a prvalue temporary that written into memory so that
3575 /// a reference can bind to it.
3577 /// Prvalue expressions are materialized when they need to have an address
3578 /// in memory for a reference to bind to. This happens when binding a
3579 /// reference to the result of a conversion, e.g.,
3582 /// const int &r = 1.0;
3585 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3586 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3587 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3588 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3589 /// to it), maintaining the invariant that references always bind to glvalues.
3590 class MaterializeTemporaryExpr : public Expr {
3591 /// \brief The temporary-generating expression whose value will be
3595 friend class ASTStmtReader;
3596 friend class ASTStmtWriter;
3599 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3600 bool BoundToLvalueReference)
3601 : Expr(MaterializeTemporaryExprClass, T,
3602 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3603 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3604 Temporary->isInstantiationDependent(),
3605 Temporary->containsUnexpandedParameterPack()),
3606 Temporary(Temporary) { }
3608 MaterializeTemporaryExpr(EmptyShell Empty)
3609 : Expr(MaterializeTemporaryExprClass, Empty) { }
3611 /// \brief Retrieve the temporary-generating subexpression whose value will
3612 /// be materialized into a glvalue.
3613 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3615 /// \brief Determine whether this materialized temporary is bound to an
3616 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3617 bool isBoundToLvalueReference() const {
3618 return getValueKind() == VK_LValue;
3621 SourceRange getSourceRange() const LLVM_READONLY {
3622 return Temporary->getSourceRange();
3625 static bool classof(const Stmt *T) {
3626 return T->getStmtClass() == MaterializeTemporaryExprClass;
3628 static bool classof(const MaterializeTemporaryExpr *) {
3633 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3636 } // end namespace clang