1 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Expr interface and subclasses for C++ expressions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/AST/UnresolvedSet.h"
21 #include "clang/Basic/ExpressionTraits.h"
22 #include "clang/Basic/Lambda.h"
23 #include "clang/Basic/TypeTraits.h"
24 #include "llvm/Support/Compiler.h"
28 class CXXConstructorDecl;
29 class CXXDestructorDecl;
33 class TemplateArgumentListInfo;
36 //===--------------------------------------------------------------------===//
38 //===--------------------------------------------------------------------===//
40 /// \brief A call to an overloaded operator written using operator
43 /// Represents a call to an overloaded operator written using operator
44 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
45 /// normal call, this AST node provides better information about the
46 /// syntactic representation of the call.
48 /// In a C++ template, this expression node kind will be used whenever
49 /// any of the arguments are type-dependent. In this case, the
50 /// function itself will be a (possibly empty) set of functions and
51 /// function templates that were found by name lookup at template
53 class CXXOperatorCallExpr : public CallExpr {
54 /// \brief The overloaded operator.
55 OverloadedOperatorKind Operator;
58 // Record the FP_CONTRACT state that applies to this operator call. Only
59 // meaningful for floating point types. For other types this value can be
61 unsigned FPContractable : 1;
63 SourceRange getSourceRangeImpl() const LLVM_READONLY;
65 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
66 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
67 SourceLocation operatorloc, bool fpContractable)
68 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
70 Operator(Op), FPContractable(fpContractable) {
71 Range = getSourceRangeImpl();
73 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
74 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
77 /// getOperator - Returns the kind of overloaded operator that this
78 /// expression refers to.
79 OverloadedOperatorKind getOperator() const { return Operator; }
81 /// getOperatorLoc - Returns the location of the operator symbol in
82 /// the expression. When @c getOperator()==OO_Call, this is the
83 /// location of the right parentheses; when @c
84 /// getOperator()==OO_Subscript, this is the location of the right
86 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
88 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
89 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
90 SourceRange getSourceRange() const { return Range; }
92 static bool classof(const Stmt *T) {
93 return T->getStmtClass() == CXXOperatorCallExprClass;
96 // Set the FP contractability status of this operator. Only meaningful for
97 // operations on floating point types.
98 void setFPContractable(bool FPC) { FPContractable = FPC; }
100 // Get the FP contractability status of this operator. Only meaningful for
101 // operations on floating point types.
102 bool isFPContractable() const { return FPContractable; }
104 friend class ASTStmtReader;
105 friend class ASTStmtWriter;
108 /// CXXMemberCallExpr - Represents a call to a member function that
109 /// may be written either with member call syntax (e.g., "obj.func()"
110 /// or "objptr->func()") or with normal function-call syntax
111 /// ("func()") within a member function that ends up calling a member
112 /// function. The callee in either case is a MemberExpr that contains
113 /// both the object argument and the member function, while the
114 /// arguments are the arguments within the parentheses (not including
115 /// the object argument).
116 class CXXMemberCallExpr : public CallExpr {
118 CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
119 QualType t, ExprValueKind VK, SourceLocation RP)
120 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
122 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
123 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
125 /// getImplicitObjectArgument - Retrieves the implicit object
126 /// argument for the member call. For example, in "x.f(5)", this
127 /// operation would return "x".
128 Expr *getImplicitObjectArgument() const;
130 /// Retrieves the declaration of the called method.
131 CXXMethodDecl *getMethodDecl() const;
133 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
134 /// the implicit object argument. Note that this is may not be the same
135 /// declaration as that of the class context of the CXXMethodDecl which this
136 /// function is calling.
137 /// FIXME: Returns 0 for member pointer call exprs.
138 CXXRecordDecl *getRecordDecl() const;
140 static bool classof(const Stmt *T) {
141 return T->getStmtClass() == CXXMemberCallExprClass;
145 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
146 class CUDAKernelCallExpr : public CallExpr {
148 enum { CONFIG, END_PREARG };
151 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
152 ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
154 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
158 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
159 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
161 const CallExpr *getConfig() const {
162 return cast_or_null<CallExpr>(getPreArg(CONFIG));
164 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
165 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
167 static bool classof(const Stmt *T) {
168 return T->getStmtClass() == CUDAKernelCallExprClass;
172 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
173 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
176 /// This abstract class is inherited by all of the classes
177 /// representing "named" casts, e.g., CXXStaticCastExpr,
178 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
179 class CXXNamedCastExpr : public ExplicitCastExpr {
181 SourceLocation Loc; // the location of the casting op
182 SourceLocation RParenLoc; // the location of the right parenthesis
183 SourceRange AngleBrackets; // range for '<' '>'
186 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
187 CastKind kind, Expr *op, unsigned PathSize,
188 TypeSourceInfo *writtenTy, SourceLocation l,
189 SourceLocation RParenLoc,
190 SourceRange AngleBrackets)
191 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
192 RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
194 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
195 : ExplicitCastExpr(SC, Shell, PathSize) { }
197 friend class ASTStmtReader;
200 const char *getCastName() const;
202 /// \brief Retrieve the location of the cast operator keyword, e.g.,
204 SourceLocation getOperatorLoc() const { return Loc; }
206 /// \brief Retrieve the location of the closing parenthesis.
207 SourceLocation getRParenLoc() const { return RParenLoc; }
209 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
210 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
211 SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
213 static bool classof(const Stmt *T) {
214 switch (T->getStmtClass()) {
215 case CXXStaticCastExprClass:
216 case CXXDynamicCastExprClass:
217 case CXXReinterpretCastExprClass:
218 case CXXConstCastExprClass:
226 /// CXXStaticCastExpr - A C++ @c static_cast expression
227 /// (C++ [expr.static.cast]).
229 /// This expression node represents a C++ static cast, e.g.,
230 /// @c static_cast<int>(1.0).
231 class CXXStaticCastExpr : public CXXNamedCastExpr {
232 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
233 unsigned pathSize, TypeSourceInfo *writtenTy,
234 SourceLocation l, SourceLocation RParenLoc,
235 SourceRange AngleBrackets)
236 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
237 writtenTy, l, RParenLoc, AngleBrackets) {}
239 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
240 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
243 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
244 ExprValueKind VK, CastKind K, Expr *Op,
245 const CXXCastPath *Path,
246 TypeSourceInfo *Written, SourceLocation L,
247 SourceLocation RParenLoc,
248 SourceRange AngleBrackets);
249 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
252 static bool classof(const Stmt *T) {
253 return T->getStmtClass() == CXXStaticCastExprClass;
257 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
258 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
259 /// determine how to perform the type cast.
261 /// This expression node represents a dynamic cast, e.g.,
262 /// @c dynamic_cast<Derived*>(BasePtr).
263 class CXXDynamicCastExpr : public CXXNamedCastExpr {
264 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
265 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
266 SourceLocation l, SourceLocation RParenLoc,
267 SourceRange AngleBrackets)
268 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
269 writtenTy, l, RParenLoc, AngleBrackets) {}
271 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
272 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
275 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
276 ExprValueKind VK, CastKind Kind, Expr *Op,
277 const CXXCastPath *Path,
278 TypeSourceInfo *Written, SourceLocation L,
279 SourceLocation RParenLoc,
280 SourceRange AngleBrackets);
282 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
285 bool isAlwaysNull() const;
287 static bool classof(const Stmt *T) {
288 return T->getStmtClass() == CXXDynamicCastExprClass;
292 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
293 /// [expr.reinterpret.cast]), which provides a differently-typed view
294 /// of a value but performs no actual work at run time.
296 /// This expression node represents a reinterpret cast, e.g.,
297 /// @c reinterpret_cast<int>(VoidPtr).
298 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
299 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
300 Expr *op, unsigned pathSize,
301 TypeSourceInfo *writtenTy, SourceLocation l,
302 SourceLocation RParenLoc,
303 SourceRange AngleBrackets)
304 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
305 pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
307 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
308 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
311 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
312 ExprValueKind VK, CastKind Kind,
313 Expr *Op, const CXXCastPath *Path,
314 TypeSourceInfo *WrittenTy, SourceLocation L,
315 SourceLocation RParenLoc,
316 SourceRange AngleBrackets);
317 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
320 static bool classof(const Stmt *T) {
321 return T->getStmtClass() == CXXReinterpretCastExprClass;
325 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
326 /// which can remove type qualifiers but does not change the underlying value.
328 /// This expression node represents a const cast, e.g.,
329 /// @c const_cast<char*>(PtrToConstChar).
330 class CXXConstCastExpr : public CXXNamedCastExpr {
331 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
332 TypeSourceInfo *writtenTy, SourceLocation l,
333 SourceLocation RParenLoc, SourceRange AngleBrackets)
334 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
335 0, writtenTy, l, RParenLoc, AngleBrackets) {}
337 explicit CXXConstCastExpr(EmptyShell Empty)
338 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
341 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
342 ExprValueKind VK, Expr *Op,
343 TypeSourceInfo *WrittenTy, SourceLocation L,
344 SourceLocation RParenLoc,
345 SourceRange AngleBrackets);
346 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
348 static bool classof(const Stmt *T) {
349 return T->getStmtClass() == CXXConstCastExprClass;
353 /// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
354 /// written as a user-defined literal (C++11 [lit.ext]).
356 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
357 /// is semantically equivalent to a normal call, this AST node provides better
358 /// information about the syntactic representation of the literal.
360 /// Since literal operators are never found by ADL and can only be declared at
361 /// namespace scope, a user-defined literal is never dependent.
362 class UserDefinedLiteral : public CallExpr {
363 /// \brief The location of a ud-suffix within the literal.
364 SourceLocation UDSuffixLoc;
367 UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
368 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
369 SourceLocation SuffixLoc)
370 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
371 UDSuffixLoc(SuffixLoc) {}
372 explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
373 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
375 /// The kind of literal operator which is invoked.
376 enum LiteralOperatorKind {
377 LOK_Raw, ///< Raw form: operator "" X (const char *)
378 LOK_Template, ///< Raw form: operator "" X<cs...> ()
379 LOK_Integer, ///< operator "" X (unsigned long long)
380 LOK_Floating, ///< operator "" X (long double)
381 LOK_String, ///< operator "" X (const CharT *, size_t)
382 LOK_Character ///< operator "" X (CharT)
385 /// getLiteralOperatorKind - Returns the kind of literal operator invocation
386 /// which this expression represents.
387 LiteralOperatorKind getLiteralOperatorKind() const;
389 /// getCookedLiteral - If this is not a raw user-defined literal, get the
390 /// underlying cooked literal (representing the literal with the suffix
392 Expr *getCookedLiteral();
393 const Expr *getCookedLiteral() const {
394 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
397 SourceLocation getLocStart() const {
398 if (getLiteralOperatorKind() == LOK_Template)
399 return getRParenLoc();
400 return getArg(0)->getLocStart();
402 SourceLocation getLocEnd() const { return getRParenLoc(); }
405 /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
406 /// For a string literal, there may be multiple identical suffixes. This
407 /// returns the first.
408 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
410 /// getUDSuffix - Returns the ud-suffix specified for this literal.
411 const IdentifierInfo *getUDSuffix() const;
413 static bool classof(const Stmt *S) {
414 return S->getStmtClass() == UserDefinedLiteralClass;
417 friend class ASTStmtReader;
418 friend class ASTStmtWriter;
421 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
423 class CXXBoolLiteralExpr : public Expr {
427 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
428 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
430 Value(val), Loc(l) {}
432 explicit CXXBoolLiteralExpr(EmptyShell Empty)
433 : Expr(CXXBoolLiteralExprClass, Empty) { }
435 bool getValue() const { return Value; }
436 void setValue(bool V) { Value = V; }
438 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
439 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
441 SourceLocation getLocation() const { return Loc; }
442 void setLocation(SourceLocation L) { Loc = L; }
444 static bool classof(const Stmt *T) {
445 return T->getStmtClass() == CXXBoolLiteralExprClass;
449 child_range children() { return child_range(); }
452 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
453 class CXXNullPtrLiteralExpr : public Expr {
456 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
457 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
461 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
462 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
464 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
465 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
467 SourceLocation getLocation() const { return Loc; }
468 void setLocation(SourceLocation L) { Loc = L; }
470 static bool classof(const Stmt *T) {
471 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
474 child_range children() { return child_range(); }
477 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
478 /// the type_info that corresponds to the supplied type, or the (possibly
479 /// dynamic) type of the supplied expression.
481 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
482 class CXXTypeidExpr : public Expr {
484 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
488 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
489 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
490 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
492 // typeid is value-dependent if the type or expression are dependent
493 Operand->getType()->isDependentType(),
494 Operand->getType()->isInstantiationDependentType(),
495 Operand->getType()->containsUnexpandedParameterPack()),
496 Operand(Operand), Range(R) { }
498 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
499 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
500 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
502 // typeid is value-dependent if the type or expression are dependent
503 Operand->isTypeDependent() || Operand->isValueDependent(),
504 Operand->isInstantiationDependent(),
505 Operand->containsUnexpandedParameterPack()),
506 Operand(Operand), Range(R) { }
508 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
509 : Expr(CXXTypeidExprClass, Empty) {
513 Operand = (TypeSourceInfo*)0;
516 /// Determine whether this typeid has a type operand which is potentially
517 /// evaluated, per C++11 [expr.typeid]p3.
518 bool isPotentiallyEvaluated() const;
520 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
522 /// \brief Retrieves the type operand of this typeid() expression after
523 /// various required adjustments (removing reference types, cv-qualifiers).
524 QualType getTypeOperand() const;
526 /// \brief Retrieve source information for the type operand.
527 TypeSourceInfo *getTypeOperandSourceInfo() const {
528 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
529 return Operand.get<TypeSourceInfo *>();
532 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
533 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
537 Expr *getExprOperand() const {
538 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
539 return static_cast<Expr*>(Operand.get<Stmt *>());
542 void setExprOperand(Expr *E) {
543 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
547 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
548 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
549 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
550 void setSourceRange(SourceRange R) { Range = R; }
552 static bool classof(const Stmt *T) {
553 return T->getStmtClass() == CXXTypeidExprClass;
557 child_range children() {
558 if (isTypeOperand()) return child_range();
559 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
560 return child_range(begin, begin + 1);
564 /// A member reference to an MSPropertyDecl. This expression always
565 /// has pseudo-object type, and therefore it is typically not
566 /// encountered in a fully-typechecked expression except within the
567 /// syntactic form of a PseudoObjectExpr.
568 class MSPropertyRefExpr : public Expr {
570 MSPropertyDecl *TheDecl;
571 SourceLocation MemberLoc;
573 NestedNameSpecifierLoc QualifierLoc;
576 MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
577 QualType ty, ExprValueKind VK,
578 NestedNameSpecifierLoc qualifierLoc,
579 SourceLocation nameLoc)
580 : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
581 /*type-dependent*/ false, baseExpr->isValueDependent(),
582 baseExpr->isInstantiationDependent(),
583 baseExpr->containsUnexpandedParameterPack()),
584 BaseExpr(baseExpr), TheDecl(decl),
585 MemberLoc(nameLoc), IsArrow(isArrow),
586 QualifierLoc(qualifierLoc) {}
588 MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
590 SourceRange getSourceRange() const LLVM_READONLY {
591 return SourceRange(getLocStart(), getLocEnd());
593 bool isImplicitAccess() const {
594 return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
596 SourceLocation getLocStart() const {
597 if (!isImplicitAccess())
598 return BaseExpr->getLocStart();
599 else if (QualifierLoc)
600 return QualifierLoc.getBeginLoc();
604 SourceLocation getLocEnd() const { return getMemberLoc(); }
606 child_range children() {
607 return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
609 static bool classof(const Stmt *T) {
610 return T->getStmtClass() == MSPropertyRefExprClass;
613 Expr *getBaseExpr() const { return BaseExpr; }
614 MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
615 bool isArrow() const { return IsArrow; }
616 SourceLocation getMemberLoc() const { return MemberLoc; }
617 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
619 friend class ASTStmtReader;
622 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
623 /// the _GUID that corresponds to the supplied type or expression.
625 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
626 class CXXUuidofExpr : public Expr {
628 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
632 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
633 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
634 false, Operand->getType()->isDependentType(),
635 Operand->getType()->isInstantiationDependentType(),
636 Operand->getType()->containsUnexpandedParameterPack()),
637 Operand(Operand), Range(R) { }
639 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
640 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
641 false, Operand->isTypeDependent(),
642 Operand->isInstantiationDependent(),
643 Operand->containsUnexpandedParameterPack()),
644 Operand(Operand), Range(R) { }
646 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
647 : Expr(CXXUuidofExprClass, Empty) {
651 Operand = (TypeSourceInfo*)0;
654 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
656 /// \brief Retrieves the type operand of this __uuidof() expression after
657 /// various required adjustments (removing reference types, cv-qualifiers).
658 QualType getTypeOperand() const;
660 /// \brief Retrieve source information for the type operand.
661 TypeSourceInfo *getTypeOperandSourceInfo() const {
662 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
663 return Operand.get<TypeSourceInfo *>();
666 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
667 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
671 Expr *getExprOperand() const {
672 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
673 return static_cast<Expr*>(Operand.get<Stmt *>());
676 void setExprOperand(Expr *E) {
677 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
681 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
682 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
683 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
684 void setSourceRange(SourceRange R) { Range = R; }
686 static bool classof(const Stmt *T) {
687 return T->getStmtClass() == CXXUuidofExprClass;
690 /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none.
691 static UuidAttr *GetUuidAttrOfType(QualType QT);
694 child_range children() {
695 if (isTypeOperand()) return child_range();
696 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
697 return child_range(begin, begin + 1);
701 /// CXXThisExpr - Represents the "this" expression in C++, which is a
702 /// pointer to the object on which the current member function is
703 /// executing (C++ [expr.prim]p3). Example:
709 /// void test() { this->bar(); }
712 class CXXThisExpr : public Expr {
717 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
718 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
719 // 'this' is type-dependent if the class type of the enclosing
720 // member function is dependent (C++ [temp.dep.expr]p2)
721 Type->isDependentType(), Type->isDependentType(),
722 Type->isInstantiationDependentType(),
723 /*ContainsUnexpandedParameterPack=*/false),
724 Loc(L), Implicit(isImplicit) { }
726 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
728 SourceLocation getLocation() const { return Loc; }
729 void setLocation(SourceLocation L) { Loc = L; }
731 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
732 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
734 bool isImplicit() const { return Implicit; }
735 void setImplicit(bool I) { Implicit = I; }
737 static bool classof(const Stmt *T) {
738 return T->getStmtClass() == CXXThisExprClass;
742 child_range children() { return child_range(); }
745 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
746 /// 'throw' and 'throw' assignment-expression. When
747 /// assignment-expression isn't present, Op will be null.
749 class CXXThrowExpr : public Expr {
751 SourceLocation ThrowLoc;
752 /// \brief Whether the thrown variable (if any) is in scope.
753 unsigned IsThrownVariableInScope : 1;
755 friend class ASTStmtReader;
758 // Ty is the void type which is used as the result type of the
759 // exepression. The l is the location of the throw keyword. expr
760 // can by null, if the optional expression to throw isn't present.
761 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
762 bool IsThrownVariableInScope) :
763 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
764 expr && expr->isInstantiationDependent(),
765 expr && expr->containsUnexpandedParameterPack()),
766 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
767 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
769 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
770 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
772 SourceLocation getThrowLoc() const { return ThrowLoc; }
774 /// \brief Determines whether the variable thrown by this expression (if any!)
775 /// is within the innermost try block.
777 /// This information is required to determine whether the NRVO can apply to
779 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
781 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
782 SourceLocation getLocEnd() const LLVM_READONLY {
783 if (getSubExpr() == 0)
785 return getSubExpr()->getLocEnd();
788 static bool classof(const Stmt *T) {
789 return T->getStmtClass() == CXXThrowExprClass;
793 child_range children() {
794 return child_range(&Op, Op ? &Op+1 : &Op);
798 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
799 /// function call argument that was created from the corresponding
800 /// parameter's default argument, when the call did not explicitly
801 /// supply arguments for all of the parameters.
802 class CXXDefaultArgExpr : public Expr {
803 /// \brief The parameter whose default is being used.
805 /// When the bit is set, the subexpression is stored after the
806 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
807 /// actual default expression is the subexpression.
808 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
810 /// \brief The location where the default argument expression was used.
813 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
815 param->hasUnparsedDefaultArg()
816 ? param->getType().getNonReferenceType()
817 : param->getDefaultArg()->getType(),
818 param->getDefaultArg()->getValueKind(),
819 param->getDefaultArg()->getObjectKind(), false, false, false, false),
820 Param(param, false), Loc(Loc) { }
822 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
824 : Expr(SC, SubExpr->getType(),
825 SubExpr->getValueKind(), SubExpr->getObjectKind(),
826 false, false, false, false),
827 Param(param, true), Loc(Loc) {
828 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
832 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
835 // Param is the parameter whose default argument is used by this
837 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
838 ParmVarDecl *Param) {
839 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
842 // Param is the parameter whose default argument is used by this
843 // expression, and SubExpr is the expression that will actually be used.
844 static CXXDefaultArgExpr *Create(ASTContext &C,
849 // Retrieve the parameter that the argument was created from.
850 const ParmVarDecl *getParam() const { return Param.getPointer(); }
851 ParmVarDecl *getParam() { return Param.getPointer(); }
853 // Retrieve the actual argument to the function call.
854 const Expr *getExpr() const {
856 return *reinterpret_cast<Expr const * const*> (this + 1);
857 return getParam()->getDefaultArg();
861 return *reinterpret_cast<Expr **> (this + 1);
862 return getParam()->getDefaultArg();
865 /// \brief Retrieve the location where this default argument was actually
867 SourceLocation getUsedLocation() const { return Loc; }
869 // Default argument expressions have no representation in the
870 // source, so they have an empty source range.
871 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
872 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
874 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
876 static bool classof(const Stmt *T) {
877 return T->getStmtClass() == CXXDefaultArgExprClass;
881 child_range children() { return child_range(); }
883 friend class ASTStmtReader;
884 friend class ASTStmtWriter;
887 /// \brief This wraps a use of a C++ default initializer (technically,
888 /// a brace-or-equal-initializer for a non-static data member) when it
889 /// is implicitly used in a mem-initializer-list in a constructor
890 /// (C++11 [class.base.init]p8) or in aggregate initialization
891 /// (C++1y [dcl.init.aggr]p7).
892 class CXXDefaultInitExpr : public Expr {
893 /// \brief The field whose default is being used.
896 /// \brief The location where the default initializer expression was used.
899 CXXDefaultInitExpr(ASTContext &C, SourceLocation Loc, FieldDecl *Field,
902 CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
905 // Field is the non-static data member whose default initializer is used
906 // by this expression.
907 static CXXDefaultInitExpr *Create(ASTContext &C, SourceLocation Loc,
909 return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
912 // Get the field whose initializer will be used.
913 FieldDecl *getField() { return Field; }
914 const FieldDecl *getField() const { return Field; }
916 // Get the initialization expression that will be used.
917 const Expr *getExpr() const { return Field->getInClassInitializer(); }
918 Expr *getExpr() { return Field->getInClassInitializer(); }
920 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
921 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
923 static bool classof(const Stmt *T) {
924 return T->getStmtClass() == CXXDefaultInitExprClass;
928 child_range children() { return child_range(); }
930 friend class ASTReader;
931 friend class ASTStmtReader;
934 /// CXXTemporary - Represents a C++ temporary.
936 /// Destructor - The destructor that needs to be called.
937 const CXXDestructorDecl *Destructor;
939 CXXTemporary(const CXXDestructorDecl *destructor)
940 : Destructor(destructor) { }
943 static CXXTemporary *Create(ASTContext &C,
944 const CXXDestructorDecl *Destructor);
946 const CXXDestructorDecl *getDestructor() const { return Destructor; }
947 void setDestructor(const CXXDestructorDecl *Dtor) {
952 /// \brief Represents binding an expression to a temporary.
954 /// This ensures the destructor is called for the temporary. It should only be
955 /// needed for non-POD, non-trivially destructable class types. For example:
959 /// S() { } // User defined constructor makes S non-POD.
960 /// ~S() { } // User defined destructor makes it non-trivial.
963 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
966 class CXXBindTemporaryExpr : public Expr {
971 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
972 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
973 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
974 SubExpr->isValueDependent(),
975 SubExpr->isInstantiationDependent(),
976 SubExpr->containsUnexpandedParameterPack()),
977 Temp(temp), SubExpr(SubExpr) { }
980 CXXBindTemporaryExpr(EmptyShell Empty)
981 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
983 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
986 CXXTemporary *getTemporary() { return Temp; }
987 const CXXTemporary *getTemporary() const { return Temp; }
988 void setTemporary(CXXTemporary *T) { Temp = T; }
990 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
991 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
992 void setSubExpr(Expr *E) { SubExpr = E; }
994 SourceLocation getLocStart() const LLVM_READONLY {
995 return SubExpr->getLocStart();
997 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
999 // Implement isa/cast/dyncast/etc.
1000 static bool classof(const Stmt *T) {
1001 return T->getStmtClass() == CXXBindTemporaryExprClass;
1005 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1008 /// \brief Represents a call to a C++ constructor.
1009 class CXXConstructExpr : public Expr {
1011 enum ConstructionKind {
1019 CXXConstructorDecl *Constructor;
1022 SourceRange ParenRange;
1023 unsigned NumArgs : 16;
1025 bool HadMultipleCandidates : 1;
1026 bool ListInitialization : 1;
1027 bool ZeroInitialization : 1;
1028 unsigned ConstructKind : 2;
1032 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
1034 CXXConstructorDecl *d, bool elidable,
1035 ArrayRef<Expr *> Args,
1036 bool HadMultipleCandidates,
1037 bool ListInitialization,
1038 bool ZeroInitialization,
1039 ConstructionKind ConstructKind,
1040 SourceRange ParenRange);
1042 /// \brief Construct an empty C++ construction expression.
1043 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
1044 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
1045 HadMultipleCandidates(false), ListInitialization(false),
1046 ZeroInitialization(false), ConstructKind(0), Args(0)
1050 /// \brief Construct an empty C++ construction expression.
1051 explicit CXXConstructExpr(EmptyShell Empty)
1052 : Expr(CXXConstructExprClass, Empty), Constructor(0),
1053 NumArgs(0), Elidable(false), HadMultipleCandidates(false),
1054 ListInitialization(false), ZeroInitialization(false),
1055 ConstructKind(0), Args(0)
1058 static CXXConstructExpr *Create(ASTContext &C, QualType T,
1060 CXXConstructorDecl *D, bool Elidable,
1061 ArrayRef<Expr *> Args,
1062 bool HadMultipleCandidates,
1063 bool ListInitialization,
1064 bool ZeroInitialization,
1065 ConstructionKind ConstructKind,
1066 SourceRange ParenRange);
1068 CXXConstructorDecl* getConstructor() const { return Constructor; }
1069 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1071 SourceLocation getLocation() const { return Loc; }
1072 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1074 /// \brief Whether this construction is elidable.
1075 bool isElidable() const { return Elidable; }
1076 void setElidable(bool E) { Elidable = E; }
1078 /// \brief Whether the referred constructor was resolved from
1079 /// an overloaded set having size greater than 1.
1080 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
1081 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
1083 /// \brief Whether this constructor call was written as list-initialization.
1084 bool isListInitialization() const { return ListInitialization; }
1085 void setListInitialization(bool V) { ListInitialization = V; }
1087 /// \brief Whether this construction first requires
1088 /// zero-initialization before the initializer is called.
1089 bool requiresZeroInitialization() const { return ZeroInitialization; }
1090 void setRequiresZeroInitialization(bool ZeroInit) {
1091 ZeroInitialization = ZeroInit;
1094 /// \brief Determines whether this constructor is actually constructing
1095 /// a base class (rather than a complete object).
1096 ConstructionKind getConstructionKind() const {
1097 return (ConstructionKind)ConstructKind;
1099 void setConstructionKind(ConstructionKind CK) {
1103 typedef ExprIterator arg_iterator;
1104 typedef ConstExprIterator const_arg_iterator;
1106 arg_iterator arg_begin() { return Args; }
1107 arg_iterator arg_end() { return Args + NumArgs; }
1108 const_arg_iterator arg_begin() const { return Args; }
1109 const_arg_iterator arg_end() const { return Args + NumArgs; }
1111 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
1112 unsigned getNumArgs() const { return NumArgs; }
1114 /// getArg - Return the specified argument.
1115 Expr *getArg(unsigned Arg) {
1116 assert(Arg < NumArgs && "Arg access out of range!");
1117 return cast<Expr>(Args[Arg]);
1119 const Expr *getArg(unsigned Arg) const {
1120 assert(Arg < NumArgs && "Arg access out of range!");
1121 return cast<Expr>(Args[Arg]);
1124 /// setArg - Set the specified argument.
1125 void setArg(unsigned Arg, Expr *ArgExpr) {
1126 assert(Arg < NumArgs && "Arg access out of range!");
1127 Args[Arg] = ArgExpr;
1130 SourceLocation getLocStart() const LLVM_READONLY;
1131 SourceLocation getLocEnd() const LLVM_READONLY;
1132 SourceRange getParenRange() const { return ParenRange; }
1133 void setParenRange(SourceRange Range) { ParenRange = Range; }
1135 static bool classof(const Stmt *T) {
1136 return T->getStmtClass() == CXXConstructExprClass ||
1137 T->getStmtClass() == CXXTemporaryObjectExprClass;
1141 child_range children() {
1142 return child_range(&Args[0], &Args[0]+NumArgs);
1145 friend class ASTStmtReader;
1148 /// \brief Represents an explicit C++ type conversion that uses "functional"
1149 /// notation (C++ [expr.type.conv]).
1155 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1156 SourceLocation TyBeginLoc;
1157 SourceLocation RParenLoc;
1159 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1160 TypeSourceInfo *writtenTy,
1161 SourceLocation tyBeginLoc, CastKind kind,
1162 Expr *castExpr, unsigned pathSize,
1163 SourceLocation rParenLoc)
1164 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1165 castExpr, pathSize, writtenTy),
1166 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
1168 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1169 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1172 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1174 TypeSourceInfo *Written,
1175 SourceLocation TyBeginLoc,
1176 CastKind Kind, Expr *Op,
1177 const CXXCastPath *Path,
1178 SourceLocation RPLoc);
1179 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1182 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1183 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1184 SourceLocation getRParenLoc() const { return RParenLoc; }
1185 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1187 SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; }
1188 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1190 static bool classof(const Stmt *T) {
1191 return T->getStmtClass() == CXXFunctionalCastExprClass;
1195 /// @brief Represents a C++ functional cast expression that builds a
1196 /// temporary object.
1198 /// This expression type represents a C++ "functional" cast
1199 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1200 /// constructor to build a temporary object. With N == 1 arguments the
1201 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1204 /// struct X { X(int, float); }
1207 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1210 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1211 TypeSourceInfo *Type;
1214 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1215 TypeSourceInfo *Type,
1216 ArrayRef<Expr *> Args,
1217 SourceRange parenRange,
1218 bool HadMultipleCandidates,
1219 bool ListInitialization,
1220 bool ZeroInitialization);
1221 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1222 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1224 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1226 SourceLocation getLocStart() const LLVM_READONLY;
1227 SourceLocation getLocEnd() const LLVM_READONLY;
1229 static bool classof(const Stmt *T) {
1230 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1233 friend class ASTStmtReader;
1236 /// \brief A C++ lambda expression, which produces a function object
1237 /// (of unspecified type) that can be invoked later.
1241 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1242 /// values.erase(std::remove_if(values.begin(), values.end(),
1243 /// [=](double value) { return value > cutoff; });
1247 /// Lambda expressions can capture local variables, either by copying
1248 /// the values of those local variables at the time the function
1249 /// object is constructed (not when it is called!) or by holding a
1250 /// reference to the local variable. These captures can occur either
1251 /// implicitly or can be written explicitly between the square
1252 /// brackets ([...]) that start the lambda expression.
1253 class LambdaExpr : public Expr {
1255 /// \brief Flag used by the Capture class to indicate that the given
1256 /// capture was implicit.
1257 Capture_Implicit = 0x01,
1259 /// \brief Flag used by the Capture class to indciate that the
1260 /// given capture was by-copy.
1261 Capture_ByCopy = 0x02
1264 /// \brief The source range that covers the lambda introducer ([...]).
1265 SourceRange IntroducerRange;
1267 /// \brief The number of captures.
1268 unsigned NumCaptures : 16;
1270 /// \brief The default capture kind, which is a value of type
1271 /// LambdaCaptureDefault.
1272 unsigned CaptureDefault : 2;
1274 /// \brief Whether this lambda had an explicit parameter list vs. an
1275 /// implicit (and empty) parameter list.
1276 unsigned ExplicitParams : 1;
1278 /// \brief Whether this lambda had the result type explicitly specified.
1279 unsigned ExplicitResultType : 1;
1281 /// \brief Whether there are any array index variables stored at the end of
1282 /// this lambda expression.
1283 unsigned HasArrayIndexVars : 1;
1285 /// \brief The location of the closing brace ('}') that completes
1288 /// The location of the brace is also available by looking up the
1289 /// function call operator in the lambda class. However, it is
1290 /// stored here to improve the performance of getSourceRange(), and
1291 /// to avoid having to deserialize the function call operator from a
1292 /// module file just to determine the source range.
1293 SourceLocation ClosingBrace;
1295 // Note: The capture initializers are stored directly after the lambda
1296 // expression, along with the index variables used to initialize by-copy
1300 /// \brief Describes the capture of either a variable or 'this'.
1302 llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
1304 SourceLocation EllipsisLoc;
1306 friend class ASTStmtReader;
1307 friend class ASTStmtWriter;
1310 /// \brief Create a new capture.
1312 /// \param Loc The source location associated with this capture.
1314 /// \param Kind The kind of capture (this, byref, bycopy).
1316 /// \param Implicit Whether the capture was implicit or explicit.
1318 /// \param Var The local variable being captured, or null if capturing this.
1320 /// \param EllipsisLoc The location of the ellipsis (...) for a
1321 /// capture that is a pack expansion, or an invalid source
1322 /// location to indicate that this is not a pack expansion.
1323 Capture(SourceLocation Loc, bool Implicit,
1324 LambdaCaptureKind Kind, VarDecl *Var = 0,
1325 SourceLocation EllipsisLoc = SourceLocation());
1327 /// \brief Determine the kind of capture.
1328 LambdaCaptureKind getCaptureKind() const;
1330 /// \brief Determine whether this capture handles the C++ 'this'
1332 bool capturesThis() const { return VarAndBits.getPointer() == 0; }
1334 /// \brief Determine whether this capture handles a variable.
1335 bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
1337 /// \brief Retrieve the declaration of the local variable being
1340 /// This operation is only valid if this capture does not capture
1342 VarDecl *getCapturedVar() const {
1343 assert(!capturesThis() && "No variable available for 'this' capture");
1344 return VarAndBits.getPointer();
1347 /// \brief Determine whether this was an implicit capture (not
1348 /// written between the square brackets introducing the lambda).
1349 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
1351 /// \brief Determine whether this was an explicit capture, written
1352 /// between the square brackets introducing the lambda.
1353 bool isExplicit() const { return !isImplicit(); }
1355 /// \brief Retrieve the source location of the capture.
1357 /// For an explicit capture, this returns the location of the
1358 /// explicit capture in the source. For an implicit capture, this
1359 /// returns the location at which the variable or 'this' was first
1361 SourceLocation getLocation() const { return Loc; }
1363 /// \brief Determine whether this capture is a pack expansion,
1364 /// which captures a function parameter pack.
1365 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
1367 /// \brief Retrieve the location of the ellipsis for a capture
1368 /// that is a pack expansion.
1369 SourceLocation getEllipsisLoc() const {
1370 assert(isPackExpansion() && "No ellipsis location for a non-expansion");
1376 /// \brief Construct a lambda expression.
1377 LambdaExpr(QualType T, SourceRange IntroducerRange,
1378 LambdaCaptureDefault CaptureDefault,
1379 ArrayRef<Capture> Captures,
1380 bool ExplicitParams,
1381 bool ExplicitResultType,
1382 ArrayRef<Expr *> CaptureInits,
1383 ArrayRef<VarDecl *> ArrayIndexVars,
1384 ArrayRef<unsigned> ArrayIndexStarts,
1385 SourceLocation ClosingBrace,
1386 bool ContainsUnexpandedParameterPack);
1388 /// \brief Construct an empty lambda expression.
1389 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1390 : Expr(LambdaExprClass, Empty),
1391 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1392 ExplicitResultType(false), HasArrayIndexVars(true) {
1393 getStoredStmts()[NumCaptures] = 0;
1396 Stmt **getStoredStmts() const {
1397 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1400 /// \brief Retrieve the mapping from captures to the first array index
1402 unsigned *getArrayIndexStarts() const {
1403 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1406 /// \brief Retrieve the complete set of array-index variables.
1407 VarDecl **getArrayIndexVars() const {
1408 unsigned ArrayIndexSize =
1409 llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1410 llvm::alignOf<VarDecl*>());
1411 return reinterpret_cast<VarDecl **>(
1412 reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
1416 /// \brief Construct a new lambda expression.
1417 static LambdaExpr *Create(ASTContext &C,
1418 CXXRecordDecl *Class,
1419 SourceRange IntroducerRange,
1420 LambdaCaptureDefault CaptureDefault,
1421 ArrayRef<Capture> Captures,
1422 bool ExplicitParams,
1423 bool ExplicitResultType,
1424 ArrayRef<Expr *> CaptureInits,
1425 ArrayRef<VarDecl *> ArrayIndexVars,
1426 ArrayRef<unsigned> ArrayIndexStarts,
1427 SourceLocation ClosingBrace,
1428 bool ContainsUnexpandedParameterPack);
1430 /// \brief Construct a new lambda expression that will be deserialized from
1431 /// an external source.
1432 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
1433 unsigned NumArrayIndexVars);
1435 /// \brief Determine the default capture kind for this lambda.
1436 LambdaCaptureDefault getCaptureDefault() const {
1437 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1440 /// \brief An iterator that walks over the captures of the lambda,
1441 /// both implicit and explicit.
1442 typedef const Capture *capture_iterator;
1444 /// \brief Retrieve an iterator pointing to the first lambda capture.
1445 capture_iterator capture_begin() const;
1447 /// \brief Retrieve an iterator pointing past the end of the
1448 /// sequence of lambda captures.
1449 capture_iterator capture_end() const;
1451 /// \brief Determine the number of captures in this lambda.
1452 unsigned capture_size() const { return NumCaptures; }
1454 /// \brief Retrieve an iterator pointing to the first explicit
1456 capture_iterator explicit_capture_begin() const;
1458 /// \brief Retrieve an iterator pointing past the end of the sequence of
1459 /// explicit lambda captures.
1460 capture_iterator explicit_capture_end() const;
1462 /// \brief Retrieve an iterator pointing to the first implicit
1464 capture_iterator implicit_capture_begin() const;
1466 /// \brief Retrieve an iterator pointing past the end of the sequence of
1467 /// implicit lambda captures.
1468 capture_iterator implicit_capture_end() const;
1470 /// \brief Iterator that walks over the capture initialization
1472 typedef Expr **capture_init_iterator;
1474 /// \brief Retrieve the first initialization argument for this
1475 /// lambda expression (which initializes the first capture field).
1476 capture_init_iterator capture_init_begin() const {
1477 return reinterpret_cast<Expr **>(getStoredStmts());
1480 /// \brief Retrieve the iterator pointing one past the last
1481 /// initialization argument for this lambda expression.
1482 capture_init_iterator capture_init_end() const {
1483 return capture_init_begin() + NumCaptures;
1486 /// \brief Retrieve the set of index variables used in the capture
1487 /// initializer of an array captured by copy.
1489 /// \param Iter The iterator that points at the capture initializer for
1490 /// which we are extracting the corresponding index variables.
1491 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1493 /// \brief Retrieve the source range covering the lambda introducer,
1494 /// which contains the explicit capture list surrounded by square
1495 /// brackets ([...]).
1496 SourceRange getIntroducerRange() const { return IntroducerRange; }
1498 /// \brief Retrieve the class that corresponds to the lambda, which
1499 /// stores the captures in its fields and provides the various
1500 /// operations permitted on a lambda (copying, calling).
1501 CXXRecordDecl *getLambdaClass() const;
1503 /// \brief Retrieve the function call operator associated with this
1504 /// lambda expression.
1505 CXXMethodDecl *getCallOperator() const;
1507 /// \brief Retrieve the body of the lambda.
1508 CompoundStmt *getBody() const;
1510 /// \brief Determine whether the lambda is mutable, meaning that any
1511 /// captures values can be modified.
1512 bool isMutable() const;
1514 /// \brief Determine whether this lambda has an explicit parameter
1515 /// list vs. an implicit (empty) parameter list.
1516 bool hasExplicitParameters() const { return ExplicitParams; }
1518 /// \brief Whether this lambda had its result type explicitly specified.
1519 bool hasExplicitResultType() const { return ExplicitResultType; }
1521 static bool classof(const Stmt *T) {
1522 return T->getStmtClass() == LambdaExprClass;
1525 SourceLocation getLocStart() const LLVM_READONLY {
1526 return IntroducerRange.getBegin();
1528 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
1530 child_range children() {
1531 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1534 friend class ASTStmtReader;
1535 friend class ASTStmtWriter;
1538 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1539 /// Expression "T()" which creates a value-initialized rvalue of type
1540 /// T, which is a non-class type.
1542 class CXXScalarValueInitExpr : public Expr {
1543 SourceLocation RParenLoc;
1544 TypeSourceInfo *TypeInfo;
1546 friend class ASTStmtReader;
1549 /// \brief Create an explicitly-written scalar-value initialization
1551 CXXScalarValueInitExpr(QualType Type,
1552 TypeSourceInfo *TypeInfo,
1553 SourceLocation rParenLoc ) :
1554 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1555 false, false, Type->isInstantiationDependentType(), false),
1556 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1558 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1559 : Expr(CXXScalarValueInitExprClass, Shell) { }
1561 TypeSourceInfo *getTypeSourceInfo() const {
1565 SourceLocation getRParenLoc() const { return RParenLoc; }
1567 SourceLocation getLocStart() const LLVM_READONLY;
1568 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1570 static bool classof(const Stmt *T) {
1571 return T->getStmtClass() == CXXScalarValueInitExprClass;
1575 child_range children() { return child_range(); }
1578 /// @brief Represents a new-expression for memory allocation and constructor
1579 // calls, e.g: "new CXXNewExpr(foo)".
1580 class CXXNewExpr : public Expr {
1581 // Contains an optional array size expression, an optional initialization
1582 // expression, and any number of optional placement arguments, in that order.
1584 /// \brief Points to the allocation function used.
1585 FunctionDecl *OperatorNew;
1586 /// \brief Points to the deallocation function used in case of error. May be
1588 FunctionDecl *OperatorDelete;
1590 /// \brief The allocated type-source information, as written in the source.
1591 TypeSourceInfo *AllocatedTypeInfo;
1593 /// \brief If the allocated type was expressed as a parenthesized type-id,
1594 /// the source range covering the parenthesized type-id.
1595 SourceRange TypeIdParens;
1597 /// \brief Range of the entire new expression.
1600 /// \brief Source-range of a paren-delimited initializer.
1601 SourceRange DirectInitRange;
1603 // Was the usage ::new, i.e. is the global new to be used?
1605 // Do we allocate an array? If so, the first SubExpr is the size expression.
1607 // If this is an array allocation, does the usual deallocation
1608 // function for the allocated type want to know the allocated size?
1609 bool UsualArrayDeleteWantsSize : 1;
1610 // The number of placement new arguments.
1611 unsigned NumPlacementArgs : 13;
1612 // What kind of initializer do we have? Could be none, parens, or braces.
1613 // In storage, we distinguish between "none, and no initializer expr", and
1614 // "none, but an implicit initializer expr".
1615 unsigned StoredInitializationStyle : 2;
1617 friend class ASTStmtReader;
1618 friend class ASTStmtWriter;
1620 enum InitializationStyle {
1621 NoInit, ///< New-expression has no initializer as written.
1622 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1623 ListInit ///< New-expression has a C++11 list-initializer.
1626 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1627 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1628 ArrayRef<Expr*> placementArgs,
1629 SourceRange typeIdParens, Expr *arraySize,
1630 InitializationStyle initializationStyle, Expr *initializer,
1631 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1632 SourceRange Range, SourceRange directInitRange);
1633 explicit CXXNewExpr(EmptyShell Shell)
1634 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1636 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1637 bool hasInitializer);
1639 QualType getAllocatedType() const {
1640 assert(getType()->isPointerType());
1641 return getType()->getAs<PointerType>()->getPointeeType();
1644 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1645 return AllocatedTypeInfo;
1648 /// \brief True if the allocation result needs to be null-checked.
1649 /// C++0x [expr.new]p13:
1650 /// If the allocation function returns null, initialization shall
1651 /// not be done, the deallocation function shall not be called,
1652 /// and the value of the new-expression shall be null.
1653 /// An allocation function is not allowed to return null unless it
1654 /// has a non-throwing exception-specification. The '03 rule is
1655 /// identical except that the definition of a non-throwing
1656 /// exception specification is just "is it throw()?".
1657 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1659 FunctionDecl *getOperatorNew() const { return OperatorNew; }
1660 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1661 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1662 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1664 bool isArray() const { return Array; }
1665 Expr *getArraySize() {
1666 return Array ? cast<Expr>(SubExprs[0]) : 0;
1668 const Expr *getArraySize() const {
1669 return Array ? cast<Expr>(SubExprs[0]) : 0;
1672 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1673 Expr **getPlacementArgs() {
1674 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1677 Expr *getPlacementArg(unsigned i) {
1678 assert(i < NumPlacementArgs && "Index out of range");
1679 return getPlacementArgs()[i];
1681 const Expr *getPlacementArg(unsigned i) const {
1682 assert(i < NumPlacementArgs && "Index out of range");
1683 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1686 bool isParenTypeId() const { return TypeIdParens.isValid(); }
1687 SourceRange getTypeIdParens() const { return TypeIdParens; }
1689 bool isGlobalNew() const { return GlobalNew; }
1691 /// \brief Whether this new-expression has any initializer at all.
1692 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1694 /// \brief The kind of initializer this new-expression has.
1695 InitializationStyle getInitializationStyle() const {
1696 if (StoredInitializationStyle == 0)
1698 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1701 /// \brief The initializer of this new-expression.
1702 Expr *getInitializer() {
1703 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1705 const Expr *getInitializer() const {
1706 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1709 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
1710 const CXXConstructExpr* getConstructExpr() const {
1711 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1714 /// Answers whether the usual array deallocation function for the
1715 /// allocated type expects the size of the allocation as a
1717 bool doesUsualArrayDeleteWantSize() const {
1718 return UsualArrayDeleteWantsSize;
1721 typedef ExprIterator arg_iterator;
1722 typedef ConstExprIterator const_arg_iterator;
1724 arg_iterator placement_arg_begin() {
1725 return SubExprs + Array + hasInitializer();
1727 arg_iterator placement_arg_end() {
1728 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1730 const_arg_iterator placement_arg_begin() const {
1731 return SubExprs + Array + hasInitializer();
1733 const_arg_iterator placement_arg_end() const {
1734 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1737 typedef Stmt **raw_arg_iterator;
1738 raw_arg_iterator raw_arg_begin() { return SubExprs; }
1739 raw_arg_iterator raw_arg_end() {
1740 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1742 const_arg_iterator raw_arg_begin() const { return SubExprs; }
1743 const_arg_iterator raw_arg_end() const {
1744 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1747 SourceLocation getStartLoc() const { return Range.getBegin(); }
1748 SourceLocation getEndLoc() const { return Range.getEnd(); }
1750 SourceRange getDirectInitRange() const { return DirectInitRange; }
1752 SourceRange getSourceRange() const LLVM_READONLY {
1755 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
1756 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1758 static bool classof(const Stmt *T) {
1759 return T->getStmtClass() == CXXNewExprClass;
1763 child_range children() {
1764 return child_range(raw_arg_begin(), raw_arg_end());
1768 /// \brief Represents a \c delete expression for memory deallocation and
1769 /// destructor calls, e.g. "delete[] pArray".
1770 class CXXDeleteExpr : public Expr {
1771 // Points to the operator delete overload that is used. Could be a member.
1772 FunctionDecl *OperatorDelete;
1773 // The pointer expression to be deleted.
1775 // Location of the expression.
1777 // Is this a forced global delete, i.e. "::delete"?
1778 bool GlobalDelete : 1;
1779 // Is this the array form of delete, i.e. "delete[]"?
1781 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1782 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1784 bool ArrayFormAsWritten : 1;
1785 // Does the usual deallocation function for the element type require
1786 // a size_t argument?
1787 bool UsualArrayDeleteWantsSize : 1;
1789 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1790 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1791 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1792 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1793 arg->isInstantiationDependent(),
1794 arg->containsUnexpandedParameterPack()),
1795 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1796 GlobalDelete(globalDelete),
1797 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1798 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
1799 explicit CXXDeleteExpr(EmptyShell Shell)
1800 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1802 bool isGlobalDelete() const { return GlobalDelete; }
1803 bool isArrayForm() const { return ArrayForm; }
1804 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1806 /// Answers whether the usual array deallocation function for the
1807 /// allocated type expects the size of the allocation as a
1808 /// parameter. This can be true even if the actual deallocation
1809 /// function that we're using doesn't want a size.
1810 bool doesUsualArrayDeleteWantSize() const {
1811 return UsualArrayDeleteWantsSize;
1814 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1816 Expr *getArgument() { return cast<Expr>(Argument); }
1817 const Expr *getArgument() const { return cast<Expr>(Argument); }
1819 /// \brief Retrieve the type being destroyed. If the type being
1820 /// destroyed is a dependent type which may or may not be a pointer,
1821 /// return an invalid type.
1822 QualType getDestroyedType() const;
1824 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1825 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
1827 static bool classof(const Stmt *T) {
1828 return T->getStmtClass() == CXXDeleteExprClass;
1832 child_range children() { return child_range(&Argument, &Argument+1); }
1834 friend class ASTStmtReader;
1837 /// \brief Stores the type being destroyed by a pseudo-destructor expression.
1838 class PseudoDestructorTypeStorage {
1839 /// \brief Either the type source information or the name of the type, if
1840 /// it couldn't be resolved due to type-dependence.
1841 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1843 /// \brief The starting source location of the pseudo-destructor type.
1844 SourceLocation Location;
1847 PseudoDestructorTypeStorage() { }
1849 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1850 : Type(II), Location(Loc) { }
1852 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1854 TypeSourceInfo *getTypeSourceInfo() const {
1855 return Type.dyn_cast<TypeSourceInfo *>();
1858 IdentifierInfo *getIdentifier() const {
1859 return Type.dyn_cast<IdentifierInfo *>();
1862 SourceLocation getLocation() const { return Location; }
1865 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1867 /// A pseudo-destructor is an expression that looks like a member access to a
1868 /// destructor of a scalar type, except that scalar types don't have
1869 /// destructors. For example:
1873 /// void f(int *p) {
1878 /// Pseudo-destructors typically occur when instantiating templates such as:
1881 /// template<typename T>
1882 /// void destroy(T* ptr) {
1887 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1888 /// beyond evaluating the base expression.
1889 class CXXPseudoDestructorExpr : public Expr {
1890 /// \brief The base expression (that is being destroyed).
1893 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1897 /// \brief The location of the '.' or '->' operator.
1898 SourceLocation OperatorLoc;
1900 /// \brief The nested-name-specifier that follows the operator, if present.
1901 NestedNameSpecifierLoc QualifierLoc;
1903 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1905 TypeSourceInfo *ScopeType;
1907 /// \brief The location of the '::' in a qualified pseudo-destructor
1909 SourceLocation ColonColonLoc;
1911 /// \brief The location of the '~'.
1912 SourceLocation TildeLoc;
1914 /// \brief The type being destroyed, or its name if we were unable to
1915 /// resolve the name.
1916 PseudoDestructorTypeStorage DestroyedType;
1918 friend class ASTStmtReader;
1921 CXXPseudoDestructorExpr(ASTContext &Context,
1922 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1923 NestedNameSpecifierLoc QualifierLoc,
1924 TypeSourceInfo *ScopeType,
1925 SourceLocation ColonColonLoc,
1926 SourceLocation TildeLoc,
1927 PseudoDestructorTypeStorage DestroyedType);
1929 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1930 : Expr(CXXPseudoDestructorExprClass, Shell),
1931 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1933 Expr *getBase() const { return cast<Expr>(Base); }
1935 /// \brief Determines whether this member expression actually had
1936 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1938 bool hasQualifier() const { return QualifierLoc; }
1940 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1941 /// with source-location information.
1942 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1944 /// \brief If the member name was qualified, retrieves the
1945 /// nested-name-specifier that precedes the member name. Otherwise, returns
1947 NestedNameSpecifier *getQualifier() const {
1948 return QualifierLoc.getNestedNameSpecifier();
1951 /// \brief Determine whether this pseudo-destructor expression was written
1952 /// using an '->' (otherwise, it used a '.').
1953 bool isArrow() const { return IsArrow; }
1955 /// \brief Retrieve the location of the '.' or '->' operator.
1956 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1958 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1961 /// Pseudo-destructor expressions can have extra qualification within them
1962 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1963 /// Here, if the object type of the expression is (or may be) a scalar type,
1964 /// \p T may also be a scalar type and, therefore, cannot be part of a
1965 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1966 /// destructor expression.
1967 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1969 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1971 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1973 /// \brief Retrieve the location of the '~'.
1974 SourceLocation getTildeLoc() const { return TildeLoc; }
1976 /// \brief Retrieve the source location information for the type
1977 /// being destroyed.
1979 /// This type-source information is available for non-dependent
1980 /// pseudo-destructor expressions and some dependent pseudo-destructor
1981 /// expressions. Returns NULL if we only have the identifier for a
1982 /// dependent pseudo-destructor expression.
1983 TypeSourceInfo *getDestroyedTypeInfo() const {
1984 return DestroyedType.getTypeSourceInfo();
1987 /// \brief In a dependent pseudo-destructor expression for which we do not
1988 /// have full type information on the destroyed type, provides the name
1989 /// of the destroyed type.
1990 IdentifierInfo *getDestroyedTypeIdentifier() const {
1991 return DestroyedType.getIdentifier();
1994 /// \brief Retrieve the type being destroyed.
1995 QualType getDestroyedType() const;
1997 /// \brief Retrieve the starting location of the type being destroyed.
1998 SourceLocation getDestroyedTypeLoc() const {
1999 return DestroyedType.getLocation();
2002 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2004 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2005 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2008 /// \brief Set the destroyed type.
2009 void setDestroyedType(TypeSourceInfo *Info) {
2010 DestroyedType = PseudoDestructorTypeStorage(Info);
2013 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
2014 SourceLocation getLocEnd() const LLVM_READONLY;
2016 static bool classof(const Stmt *T) {
2017 return T->getStmtClass() == CXXPseudoDestructorExprClass;
2021 child_range children() { return child_range(&Base, &Base + 1); }
2024 /// \brief Represents a GCC or MS unary type trait, as used in the
2025 /// implementation of TR1/C++11 type trait templates.
2029 /// __is_pod(int) == true
2030 /// __is_enum(std::string) == false
2032 class UnaryTypeTraitExpr : public Expr {
2033 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
2035 /// The value of the type trait. Unspecified if dependent.
2038 /// Loc - The location of the type trait keyword.
2041 /// RParen - The location of the closing paren.
2042 SourceLocation RParen;
2044 /// The type being queried.
2045 TypeSourceInfo *QueriedType;
2048 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
2049 TypeSourceInfo *queried, bool value,
2050 SourceLocation rparen, QualType ty)
2051 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2052 false, queried->getType()->isDependentType(),
2053 queried->getType()->isInstantiationDependentType(),
2054 queried->getType()->containsUnexpandedParameterPack()),
2055 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
2057 explicit UnaryTypeTraitExpr(EmptyShell Empty)
2058 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
2061 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2062 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2064 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
2066 QualType getQueriedType() const { return QueriedType->getType(); }
2068 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2070 bool getValue() const { return Value; }
2072 static bool classof(const Stmt *T) {
2073 return T->getStmtClass() == UnaryTypeTraitExprClass;
2077 child_range children() { return child_range(); }
2079 friend class ASTStmtReader;
2082 /// \brief Represents a GCC or MS binary type trait, as used in the
2083 /// implementation of TR1/C++11 type trait templates.
2087 /// __is_base_of(Base, Derived) == true
2089 class BinaryTypeTraitExpr : public Expr {
2090 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
2093 /// The value of the type trait. Unspecified if dependent.
2096 /// Loc - The location of the type trait keyword.
2099 /// RParen - The location of the closing paren.
2100 SourceLocation RParen;
2102 /// The lhs type being queried.
2103 TypeSourceInfo *LhsType;
2105 /// The rhs type being queried.
2106 TypeSourceInfo *RhsType;
2109 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
2110 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
2111 bool value, SourceLocation rparen, QualType ty)
2112 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
2113 lhsType->getType()->isDependentType() ||
2114 rhsType->getType()->isDependentType(),
2115 (lhsType->getType()->isInstantiationDependentType() ||
2116 rhsType->getType()->isInstantiationDependentType()),
2117 (lhsType->getType()->containsUnexpandedParameterPack() ||
2118 rhsType->getType()->containsUnexpandedParameterPack())),
2119 BTT(btt), Value(value), Loc(loc), RParen(rparen),
2120 LhsType(lhsType), RhsType(rhsType) { }
2123 explicit BinaryTypeTraitExpr(EmptyShell Empty)
2124 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
2125 LhsType(), RhsType() { }
2127 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2128 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2130 BinaryTypeTrait getTrait() const {
2131 return static_cast<BinaryTypeTrait>(BTT);
2134 QualType getLhsType() const { return LhsType->getType(); }
2135 QualType getRhsType() const { return RhsType->getType(); }
2137 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
2138 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
2140 bool getValue() const { assert(!isTypeDependent()); return Value; }
2142 static bool classof(const Stmt *T) {
2143 return T->getStmtClass() == BinaryTypeTraitExprClass;
2147 child_range children() { return child_range(); }
2149 friend class ASTStmtReader;
2152 /// \brief A type trait used in the implementation of various C++11 and
2153 /// Library TR1 trait templates.
2156 /// __is_trivially_constructible(vector<int>, int*, int*)
2158 class TypeTraitExpr : public Expr {
2159 /// \brief The location of the type trait keyword.
2162 /// \brief The location of the closing parenthesis.
2163 SourceLocation RParenLoc;
2165 // Note: The TypeSourceInfos for the arguments are allocated after the
2168 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2169 ArrayRef<TypeSourceInfo *> Args,
2170 SourceLocation RParenLoc,
2173 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2175 /// \brief Retrieve the argument types.
2176 TypeSourceInfo **getTypeSourceInfos() {
2177 return reinterpret_cast<TypeSourceInfo **>(this+1);
2180 /// \brief Retrieve the argument types.
2181 TypeSourceInfo * const *getTypeSourceInfos() const {
2182 return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2186 /// \brief Create a new type trait expression.
2187 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
2189 ArrayRef<TypeSourceInfo *> Args,
2190 SourceLocation RParenLoc,
2193 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
2195 /// \brief Determine which type trait this expression uses.
2196 TypeTrait getTrait() const {
2197 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2200 bool getValue() const {
2201 assert(!isValueDependent());
2202 return TypeTraitExprBits.Value;
2205 /// \brief Determine the number of arguments to this type trait.
2206 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2208 /// \brief Retrieve the Ith argument.
2209 TypeSourceInfo *getArg(unsigned I) const {
2210 assert(I < getNumArgs() && "Argument out-of-range");
2211 return getArgs()[I];
2214 /// \brief Retrieve the argument types.
2215 ArrayRef<TypeSourceInfo *> getArgs() const {
2216 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
2219 typedef TypeSourceInfo **arg_iterator;
2220 arg_iterator arg_begin() {
2221 return getTypeSourceInfos();
2223 arg_iterator arg_end() {
2224 return getTypeSourceInfos() + getNumArgs();
2227 typedef TypeSourceInfo const * const *arg_const_iterator;
2228 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
2229 arg_const_iterator arg_end() const {
2230 return getTypeSourceInfos() + getNumArgs();
2233 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2234 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2236 static bool classof(const Stmt *T) {
2237 return T->getStmtClass() == TypeTraitExprClass;
2241 child_range children() { return child_range(); }
2243 friend class ASTStmtReader;
2244 friend class ASTStmtWriter;
2248 /// \brief An Embarcadero array type trait, as used in the implementation of
2249 /// __array_rank and __array_extent.
2253 /// __array_rank(int[10][20]) == 2
2254 /// __array_extent(int, 1) == 20
2256 class ArrayTypeTraitExpr : public Expr {
2257 virtual void anchor();
2259 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2262 /// \brief The value of the type trait. Unspecified if dependent.
2265 /// \brief The array dimension being queried, or -1 if not used.
2268 /// \brief The location of the type trait keyword.
2271 /// \brief The location of the closing paren.
2272 SourceLocation RParen;
2274 /// \brief The type being queried.
2275 TypeSourceInfo *QueriedType;
2278 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2279 TypeSourceInfo *queried, uint64_t value,
2280 Expr *dimension, SourceLocation rparen, QualType ty)
2281 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2282 false, queried->getType()->isDependentType(),
2283 (queried->getType()->isInstantiationDependentType() ||
2284 (dimension && dimension->isInstantiationDependent())),
2285 queried->getType()->containsUnexpandedParameterPack()),
2286 ATT(att), Value(value), Dimension(dimension),
2287 Loc(loc), RParen(rparen), QueriedType(queried) { }
2290 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2291 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2294 virtual ~ArrayTypeTraitExpr() { }
2296 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2297 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2299 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2301 QualType getQueriedType() const { return QueriedType->getType(); }
2303 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2305 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2307 Expr *getDimensionExpression() const { return Dimension; }
2309 static bool classof(const Stmt *T) {
2310 return T->getStmtClass() == ArrayTypeTraitExprClass;
2314 child_range children() { return child_range(); }
2316 friend class ASTStmtReader;
2319 /// \brief An expression trait intrinsic.
2323 /// __is_lvalue_expr(std::cout) == true
2324 /// __is_lvalue_expr(1) == false
2326 class ExpressionTraitExpr : public Expr {
2327 /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned.
2329 /// \brief The value of the type trait. Unspecified if dependent.
2332 /// \brief The location of the type trait keyword.
2335 /// \brief The location of the closing paren.
2336 SourceLocation RParen;
2338 /// \brief The expression being queried.
2339 Expr* QueriedExpression;
2341 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2342 Expr *queried, bool value,
2343 SourceLocation rparen, QualType resultType)
2344 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2345 false, // Not type-dependent
2346 // Value-dependent if the argument is type-dependent.
2347 queried->isTypeDependent(),
2348 queried->isInstantiationDependent(),
2349 queried->containsUnexpandedParameterPack()),
2350 ET(et), Value(value), Loc(loc), RParen(rparen),
2351 QueriedExpression(queried) { }
2353 explicit ExpressionTraitExpr(EmptyShell Empty)
2354 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2355 QueriedExpression() { }
2357 SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
2358 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2360 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2362 Expr *getQueriedExpression() const { return QueriedExpression; }
2364 bool getValue() const { return Value; }
2366 static bool classof(const Stmt *T) {
2367 return T->getStmtClass() == ExpressionTraitExprClass;
2371 child_range children() { return child_range(); }
2373 friend class ASTStmtReader;
2377 /// \brief A reference to an overloaded function set, either an
2378 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
2379 class OverloadExpr : public Expr {
2380 /// \brief The common name of these declarations.
2381 DeclarationNameInfo NameInfo;
2383 /// \brief The nested-name-specifier that qualifies the name, if any.
2384 NestedNameSpecifierLoc QualifierLoc;
2386 /// The results. These are undesugared, which is to say, they may
2387 /// include UsingShadowDecls. Access is relative to the naming
2389 // FIXME: Allocate this data after the OverloadExpr subclass.
2390 DeclAccessPair *Results;
2391 unsigned NumResults;
2394 /// \brief Whether the name includes info for explicit template
2395 /// keyword and arguments.
2396 bool HasTemplateKWAndArgsInfo;
2398 /// \brief Return the optional template keyword and arguments info.
2399 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2401 /// \brief Return the optional template keyword and arguments info.
2402 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2403 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2406 OverloadExpr(StmtClass K, ASTContext &C,
2407 NestedNameSpecifierLoc QualifierLoc,
2408 SourceLocation TemplateKWLoc,
2409 const DeclarationNameInfo &NameInfo,
2410 const TemplateArgumentListInfo *TemplateArgs,
2411 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2412 bool KnownDependent,
2413 bool KnownInstantiationDependent,
2414 bool KnownContainsUnexpandedParameterPack);
2416 OverloadExpr(StmtClass K, EmptyShell Empty)
2417 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2418 HasTemplateKWAndArgsInfo(false) { }
2420 void initializeResults(ASTContext &C,
2421 UnresolvedSetIterator Begin,
2422 UnresolvedSetIterator End);
2426 OverloadExpr *Expression;
2427 bool IsAddressOfOperand;
2428 bool HasFormOfMemberPointer;
2431 /// Finds the overloaded expression in the given expression of
2434 /// \return the expression (which must be there) and true if it has
2435 /// the particular form of a member pointer expression
2436 static FindResult find(Expr *E) {
2437 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2441 E = E->IgnoreParens();
2442 if (isa<UnaryOperator>(E)) {
2443 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2444 E = cast<UnaryOperator>(E)->getSubExpr();
2445 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2447 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2448 Result.IsAddressOfOperand = true;
2449 Result.Expression = Ovl;
2451 Result.HasFormOfMemberPointer = false;
2452 Result.IsAddressOfOperand = false;
2453 Result.Expression = cast<OverloadExpr>(E);
2459 /// \brief Gets the naming class of this lookup, if any.
2460 CXXRecordDecl *getNamingClass() const;
2462 typedef UnresolvedSetImpl::iterator decls_iterator;
2463 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2464 decls_iterator decls_end() const {
2465 return UnresolvedSetIterator(Results + NumResults);
2468 /// \brief Gets the number of declarations in the unresolved set.
2469 unsigned getNumDecls() const { return NumResults; }
2471 /// \brief Gets the full name info.
2472 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2474 /// \brief Gets the name looked up.
2475 DeclarationName getName() const { return NameInfo.getName(); }
2477 /// \brief Gets the location of the name.
2478 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2480 /// \brief Fetches the nested-name qualifier, if one was given.
2481 NestedNameSpecifier *getQualifier() const {
2482 return QualifierLoc.getNestedNameSpecifier();
2485 /// \brief Fetches the nested-name qualifier with source-location
2486 /// information, if one was given.
2487 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2489 /// \brief Retrieve the location of the template keyword preceding
2490 /// this name, if any.
2491 SourceLocation getTemplateKeywordLoc() const {
2492 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2493 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2496 /// \brief Retrieve the location of the left angle bracket starting the
2497 /// explicit template argument list following the name, if any.
2498 SourceLocation getLAngleLoc() const {
2499 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2500 return getTemplateKWAndArgsInfo()->LAngleLoc;
2503 /// \brief Retrieve the location of the right angle bracket ending the
2504 /// explicit template argument list following the name, if any.
2505 SourceLocation getRAngleLoc() const {
2506 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2507 return getTemplateKWAndArgsInfo()->RAngleLoc;
2510 /// \brief Determines whether the name was preceded by the template keyword.
2511 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2513 /// \brief Determines whether this expression had explicit template arguments.
2514 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2516 // Note that, inconsistently with the explicit-template-argument AST
2517 // nodes, users are *forbidden* from calling these methods on objects
2518 // without explicit template arguments.
2520 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2521 assert(hasExplicitTemplateArgs());
2522 return *getTemplateKWAndArgsInfo();
2525 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2526 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2529 TemplateArgumentLoc const *getTemplateArgs() const {
2530 return getExplicitTemplateArgs().getTemplateArgs();
2533 unsigned getNumTemplateArgs() const {
2534 return getExplicitTemplateArgs().NumTemplateArgs;
2537 /// \brief Copies the template arguments into the given structure.
2538 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2539 getExplicitTemplateArgs().copyInto(List);
2542 /// \brief Retrieves the optional explicit template arguments.
2544 /// This points to the same data as getExplicitTemplateArgs(), but
2545 /// returns null if there are no explicit template arguments.
2546 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2547 if (!hasExplicitTemplateArgs()) return 0;
2548 return &getExplicitTemplateArgs();
2551 static bool classof(const Stmt *T) {
2552 return T->getStmtClass() == UnresolvedLookupExprClass ||
2553 T->getStmtClass() == UnresolvedMemberExprClass;
2556 friend class ASTStmtReader;
2557 friend class ASTStmtWriter;
2560 /// \brief A reference to a name which we were able to look up during
2561 /// parsing but could not resolve to a specific declaration.
2563 /// This arises in several ways:
2564 /// * we might be waiting for argument-dependent lookup
2565 /// * the name might resolve to an overloaded function
2567 /// * the lookup might have included a function template
2568 /// These never include UnresolvedUsingValueDecls, which are always class
2569 /// members and therefore appear only in UnresolvedMemberLookupExprs.
2570 class UnresolvedLookupExpr : public OverloadExpr {
2571 /// True if these lookup results should be extended by
2572 /// argument-dependent lookup if this is the operand of a function
2576 /// True if these lookup results are overloaded. This is pretty
2577 /// trivially rederivable if we urgently need to kill this field.
2580 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2581 /// any. This can generally be recalculated from the context chain,
2582 /// but that can be fairly expensive for unqualified lookups. If we
2583 /// want to improve memory use here, this could go in a union
2584 /// against the qualified-lookup bits.
2585 CXXRecordDecl *NamingClass;
2587 UnresolvedLookupExpr(ASTContext &C,
2588 CXXRecordDecl *NamingClass,
2589 NestedNameSpecifierLoc QualifierLoc,
2590 SourceLocation TemplateKWLoc,
2591 const DeclarationNameInfo &NameInfo,
2592 bool RequiresADL, bool Overloaded,
2593 const TemplateArgumentListInfo *TemplateArgs,
2594 UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2595 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2596 NameInfo, TemplateArgs, Begin, End, false, false, false),
2597 RequiresADL(RequiresADL),
2598 Overloaded(Overloaded), NamingClass(NamingClass)
2601 UnresolvedLookupExpr(EmptyShell Empty)
2602 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2603 RequiresADL(false), Overloaded(false), NamingClass(0)
2606 friend class ASTStmtReader;
2609 static UnresolvedLookupExpr *Create(ASTContext &C,
2610 CXXRecordDecl *NamingClass,
2611 NestedNameSpecifierLoc QualifierLoc,
2612 const DeclarationNameInfo &NameInfo,
2613 bool ADL, bool Overloaded,
2614 UnresolvedSetIterator Begin,
2615 UnresolvedSetIterator End) {
2616 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2617 SourceLocation(), NameInfo,
2618 ADL, Overloaded, 0, Begin, End);
2621 static UnresolvedLookupExpr *Create(ASTContext &C,
2622 CXXRecordDecl *NamingClass,
2623 NestedNameSpecifierLoc QualifierLoc,
2624 SourceLocation TemplateKWLoc,
2625 const DeclarationNameInfo &NameInfo,
2627 const TemplateArgumentListInfo *Args,
2628 UnresolvedSetIterator Begin,
2629 UnresolvedSetIterator End);
2631 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2632 bool HasTemplateKWAndArgsInfo,
2633 unsigned NumTemplateArgs);
2635 /// True if this declaration should be extended by
2636 /// argument-dependent lookup.
2637 bool requiresADL() const { return RequiresADL; }
2639 /// True if this lookup is overloaded.
2640 bool isOverloaded() const { return Overloaded; }
2642 /// Gets the 'naming class' (in the sense of C++0x
2643 /// [class.access.base]p5) of the lookup. This is the scope
2644 /// that was looked in to find these results.
2645 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2647 SourceLocation getLocStart() const LLVM_READONLY {
2648 if (NestedNameSpecifierLoc l = getQualifierLoc())
2649 return l.getBeginLoc();
2650 return getNameInfo().getLocStart();
2652 SourceLocation getLocEnd() const LLVM_READONLY {
2653 if (hasExplicitTemplateArgs())
2654 return getRAngleLoc();
2655 return getNameInfo().getLocEnd();
2658 child_range children() { return child_range(); }
2660 static bool classof(const Stmt *T) {
2661 return T->getStmtClass() == UnresolvedLookupExprClass;
2665 /// \brief A qualified reference to a name whose declaration cannot
2666 /// yet be resolved.
2668 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2669 /// it expresses a reference to a declaration such as
2670 /// X<T>::value. The difference, however, is that an
2671 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2672 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2673 /// this case, X<T>::value cannot resolve to a declaration because the
2674 /// declaration will differ from on instantiation of X<T> to the
2675 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2676 /// qualifier (X<T>::) and the name of the entity being referenced
2677 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2678 /// declaration can be found.
2679 class DependentScopeDeclRefExpr : public Expr {
2680 /// \brief The nested-name-specifier that qualifies this unresolved
2681 /// declaration name.
2682 NestedNameSpecifierLoc QualifierLoc;
2684 /// The name of the entity we will be referencing.
2685 DeclarationNameInfo NameInfo;
2687 /// \brief Whether the name includes info for explicit template
2688 /// keyword and arguments.
2689 bool HasTemplateKWAndArgsInfo;
2691 /// \brief Return the optional template keyword and arguments info.
2692 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2693 if (!HasTemplateKWAndArgsInfo) return 0;
2694 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2696 /// \brief Return the optional template keyword and arguments info.
2697 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2698 return const_cast<DependentScopeDeclRefExpr*>(this)
2699 ->getTemplateKWAndArgsInfo();
2702 DependentScopeDeclRefExpr(QualType T,
2703 NestedNameSpecifierLoc QualifierLoc,
2704 SourceLocation TemplateKWLoc,
2705 const DeclarationNameInfo &NameInfo,
2706 const TemplateArgumentListInfo *Args);
2709 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2710 NestedNameSpecifierLoc QualifierLoc,
2711 SourceLocation TemplateKWLoc,
2712 const DeclarationNameInfo &NameInfo,
2713 const TemplateArgumentListInfo *TemplateArgs);
2715 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2716 bool HasTemplateKWAndArgsInfo,
2717 unsigned NumTemplateArgs);
2719 /// \brief Retrieve the name that this expression refers to.
2720 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2722 /// \brief Retrieve the name that this expression refers to.
2723 DeclarationName getDeclName() const { return NameInfo.getName(); }
2725 /// \brief Retrieve the location of the name within the expression.
2726 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2728 /// \brief Retrieve the nested-name-specifier that qualifies the
2729 /// name, with source location information.
2730 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2733 /// \brief Retrieve the nested-name-specifier that qualifies this
2735 NestedNameSpecifier *getQualifier() const {
2736 return QualifierLoc.getNestedNameSpecifier();
2739 /// \brief Retrieve the location of the template keyword preceding
2740 /// this name, if any.
2741 SourceLocation getTemplateKeywordLoc() const {
2742 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2743 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2746 /// \brief Retrieve the location of the left angle bracket starting the
2747 /// explicit template argument list following the name, if any.
2748 SourceLocation getLAngleLoc() const {
2749 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2750 return getTemplateKWAndArgsInfo()->LAngleLoc;
2753 /// \brief Retrieve the location of the right angle bracket ending the
2754 /// explicit template argument list following the name, if any.
2755 SourceLocation getRAngleLoc() const {
2756 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2757 return getTemplateKWAndArgsInfo()->RAngleLoc;
2760 /// Determines whether the name was preceded by the template keyword.
2761 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2763 /// Determines whether this lookup had explicit template arguments.
2764 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2766 // Note that, inconsistently with the explicit-template-argument AST
2767 // nodes, users are *forbidden* from calling these methods on objects
2768 // without explicit template arguments.
2770 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2771 assert(hasExplicitTemplateArgs());
2772 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2775 /// Gets a reference to the explicit template argument list.
2776 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2777 assert(hasExplicitTemplateArgs());
2778 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2781 /// \brief Retrieves the optional explicit template arguments.
2782 /// This points to the same data as getExplicitTemplateArgs(), but
2783 /// returns null if there are no explicit template arguments.
2784 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2785 if (!hasExplicitTemplateArgs()) return 0;
2786 return &getExplicitTemplateArgs();
2789 /// \brief Copies the template arguments (if present) into the given
2791 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2792 getExplicitTemplateArgs().copyInto(List);
2795 TemplateArgumentLoc const *getTemplateArgs() const {
2796 return getExplicitTemplateArgs().getTemplateArgs();
2799 unsigned getNumTemplateArgs() const {
2800 return getExplicitTemplateArgs().NumTemplateArgs;
2803 SourceLocation getLocStart() const LLVM_READONLY {
2804 return QualifierLoc.getBeginLoc();
2806 SourceLocation getLocEnd() const LLVM_READONLY {
2807 if (hasExplicitTemplateArgs())
2808 return getRAngleLoc();
2809 return getLocation();
2812 static bool classof(const Stmt *T) {
2813 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2816 child_range children() { return child_range(); }
2818 friend class ASTStmtReader;
2819 friend class ASTStmtWriter;
2822 /// Represents an expression --- generally a full-expression --- which
2823 /// introduces cleanups to be run at the end of the sub-expression's
2824 /// evaluation. The most common source of expression-introduced
2825 /// cleanups is temporary objects in C++, but several other kinds of
2826 /// expressions can create cleanups, including basically every
2827 /// call in ARC that returns an Objective-C pointer.
2829 /// This expression also tracks whether the sub-expression contains a
2830 /// potentially-evaluated block literal. The lifetime of a block
2831 /// literal is the extent of the enclosing scope.
2832 class ExprWithCleanups : public Expr {
2834 /// The type of objects that are kept in the cleanup.
2835 /// It's useful to remember the set of blocks; we could also
2836 /// remember the set of temporaries, but there's currently
2838 typedef BlockDecl *CleanupObject;
2843 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2844 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2846 CleanupObject *getObjectsBuffer() {
2847 return reinterpret_cast<CleanupObject*>(this + 1);
2849 const CleanupObject *getObjectsBuffer() const {
2850 return reinterpret_cast<const CleanupObject*>(this + 1);
2852 friend class ASTStmtReader;
2855 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
2856 unsigned numObjects);
2858 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
2859 ArrayRef<CleanupObject> objects);
2861 ArrayRef<CleanupObject> getObjects() const {
2862 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2865 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2867 CleanupObject getObject(unsigned i) const {
2868 assert(i < getNumObjects() && "Index out of range");
2869 return getObjects()[i];
2872 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2873 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2875 /// setSubExpr - As with any mutator of the AST, be very careful
2876 /// when modifying an existing AST to preserve its invariants.
2877 void setSubExpr(Expr *E) { SubExpr = E; }
2879 SourceLocation getLocStart() const LLVM_READONLY {
2880 return SubExpr->getLocStart();
2882 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
2884 // Implement isa/cast/dyncast/etc.
2885 static bool classof(const Stmt *T) {
2886 return T->getStmtClass() == ExprWithCleanupsClass;
2890 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2893 /// \brief Describes an explicit type conversion that uses functional
2894 /// notion but could not be resolved because one or more arguments are
2897 /// The explicit type conversions expressed by
2898 /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
2899 /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
2900 /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2901 /// type-dependent. For example, this would occur in a template such
2905 /// template<typename T, typename A1>
2906 /// inline T make_a(const A1& a1) {
2911 /// When the returned expression is instantiated, it may resolve to a
2912 /// constructor call, conversion function call, or some kind of type
2914 class CXXUnresolvedConstructExpr : public Expr {
2915 /// \brief The type being constructed.
2916 TypeSourceInfo *Type;
2918 /// \brief The location of the left parentheses ('(').
2919 SourceLocation LParenLoc;
2921 /// \brief The location of the right parentheses (')').
2922 SourceLocation RParenLoc;
2924 /// \brief The number of arguments used to construct the type.
2927 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2928 SourceLocation LParenLoc,
2929 ArrayRef<Expr*> Args,
2930 SourceLocation RParenLoc);
2932 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2933 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2935 friend class ASTStmtReader;
2938 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2939 TypeSourceInfo *Type,
2940 SourceLocation LParenLoc,
2941 ArrayRef<Expr*> Args,
2942 SourceLocation RParenLoc);
2944 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2947 /// \brief Retrieve the type that is being constructed, as specified
2948 /// in the source code.
2949 QualType getTypeAsWritten() const { return Type->getType(); }
2951 /// \brief Retrieve the type source information for the type being
2953 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2955 /// \brief Retrieve the location of the left parentheses ('(') that
2956 /// precedes the argument list.
2957 SourceLocation getLParenLoc() const { return LParenLoc; }
2958 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2960 /// \brief Retrieve the location of the right parentheses (')') that
2961 /// follows the argument list.
2962 SourceLocation getRParenLoc() const { return RParenLoc; }
2963 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2965 /// \brief Retrieve the number of arguments.
2966 unsigned arg_size() const { return NumArgs; }
2968 typedef Expr** arg_iterator;
2969 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2970 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2972 typedef const Expr* const * const_arg_iterator;
2973 const_arg_iterator arg_begin() const {
2974 return reinterpret_cast<const Expr* const *>(this + 1);
2976 const_arg_iterator arg_end() const {
2977 return arg_begin() + NumArgs;
2980 Expr *getArg(unsigned I) {
2981 assert(I < NumArgs && "Argument index out-of-range");
2982 return *(arg_begin() + I);
2985 const Expr *getArg(unsigned I) const {
2986 assert(I < NumArgs && "Argument index out-of-range");
2987 return *(arg_begin() + I);
2990 void setArg(unsigned I, Expr *E) {
2991 assert(I < NumArgs && "Argument index out-of-range");
2992 *(arg_begin() + I) = E;
2995 SourceLocation getLocStart() const LLVM_READONLY;
2996 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2998 static bool classof(const Stmt *T) {
2999 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3003 child_range children() {
3004 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
3005 return child_range(begin, begin + NumArgs);
3009 /// \brief Represents a C++ member access expression where the actual
3010 /// member referenced could not be resolved because the base
3011 /// expression or the member name was dependent.
3013 /// Like UnresolvedMemberExprs, these can be either implicit or
3014 /// explicit accesses. It is only possible to get one of these with
3015 /// an implicit access if a qualifier is provided.
3016 class CXXDependentScopeMemberExpr : public Expr {
3017 /// \brief The expression for the base pointer or class reference,
3018 /// e.g., the \c x in x.f. Can be null in implicit accesses.
3021 /// \brief The type of the base expression. Never null, even for
3022 /// implicit accesses.
3025 /// \brief Whether this member expression used the '->' operator or
3026 /// the '.' operator.
3029 /// \brief Whether this member expression has info for explicit template
3030 /// keyword and arguments.
3031 bool HasTemplateKWAndArgsInfo : 1;
3033 /// \brief The location of the '->' or '.' operator.
3034 SourceLocation OperatorLoc;
3036 /// \brief The nested-name-specifier that precedes the member name, if any.
3037 NestedNameSpecifierLoc QualifierLoc;
3039 /// \brief In a qualified member access expression such as t->Base::f, this
3040 /// member stores the resolves of name lookup in the context of the member
3041 /// access expression, to be used at instantiation time.
3043 /// FIXME: This member, along with the QualifierLoc, could
3044 /// be stuck into a structure that is optionally allocated at the end of
3045 /// the CXXDependentScopeMemberExpr, to save space in the common case.
3046 NamedDecl *FirstQualifierFoundInScope;
3048 /// \brief The member to which this member expression refers, which
3049 /// can be name, overloaded operator, or destructor.
3050 /// FIXME: could also be a template-id
3051 DeclarationNameInfo MemberNameInfo;
3053 /// \brief Return the optional template keyword and arguments info.
3054 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
3055 if (!HasTemplateKWAndArgsInfo) return 0;
3056 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
3058 /// \brief Return the optional template keyword and arguments info.
3059 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
3060 return const_cast<CXXDependentScopeMemberExpr*>(this)
3061 ->getTemplateKWAndArgsInfo();
3064 CXXDependentScopeMemberExpr(ASTContext &C,
3065 Expr *Base, QualType BaseType, bool IsArrow,
3066 SourceLocation OperatorLoc,
3067 NestedNameSpecifierLoc QualifierLoc,
3068 SourceLocation TemplateKWLoc,
3069 NamedDecl *FirstQualifierFoundInScope,
3070 DeclarationNameInfo MemberNameInfo,
3071 const TemplateArgumentListInfo *TemplateArgs);
3074 CXXDependentScopeMemberExpr(ASTContext &C,
3075 Expr *Base, QualType BaseType,
3077 SourceLocation OperatorLoc,
3078 NestedNameSpecifierLoc QualifierLoc,
3079 NamedDecl *FirstQualifierFoundInScope,
3080 DeclarationNameInfo MemberNameInfo);
3082 static CXXDependentScopeMemberExpr *
3083 Create(ASTContext &C,
3084 Expr *Base, QualType BaseType, bool IsArrow,
3085 SourceLocation OperatorLoc,
3086 NestedNameSpecifierLoc QualifierLoc,
3087 SourceLocation TemplateKWLoc,
3088 NamedDecl *FirstQualifierFoundInScope,
3089 DeclarationNameInfo MemberNameInfo,
3090 const TemplateArgumentListInfo *TemplateArgs);
3092 static CXXDependentScopeMemberExpr *
3093 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3094 unsigned NumTemplateArgs);
3096 /// \brief True if this is an implicit access, i.e. one in which the
3097 /// member being accessed was not written in the source. The source
3098 /// location of the operator is invalid in this case.
3099 bool isImplicitAccess() const;
3101 /// \brief Retrieve the base object of this member expressions,
3102 /// e.g., the \c x in \c x.m.
3103 Expr *getBase() const {
3104 assert(!isImplicitAccess());
3105 return cast<Expr>(Base);
3108 QualType getBaseType() const { return BaseType; }
3110 /// \brief Determine whether this member expression used the '->'
3111 /// operator; otherwise, it used the '.' operator.
3112 bool isArrow() const { return IsArrow; }
3114 /// \brief Retrieve the location of the '->' or '.' operator.
3115 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3117 /// \brief Retrieve the nested-name-specifier that qualifies the member
3119 NestedNameSpecifier *getQualifier() const {
3120 return QualifierLoc.getNestedNameSpecifier();
3123 /// \brief Retrieve the nested-name-specifier that qualifies the member
3124 /// name, with source location information.
3125 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3128 /// \brief Retrieve the first part of the nested-name-specifier that was
3129 /// found in the scope of the member access expression when the member access
3130 /// was initially parsed.
3132 /// This function only returns a useful result when member access expression
3133 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
3134 /// returned by this function describes what was found by unqualified name
3135 /// lookup for the identifier "Base" within the scope of the member access
3136 /// expression itself. At template instantiation time, this information is
3137 /// combined with the results of name lookup into the type of the object
3138 /// expression itself (the class type of x).
3139 NamedDecl *getFirstQualifierFoundInScope() const {
3140 return FirstQualifierFoundInScope;
3143 /// \brief Retrieve the name of the member that this expression
3145 const DeclarationNameInfo &getMemberNameInfo() const {
3146 return MemberNameInfo;
3149 /// \brief Retrieve the name of the member that this expression
3151 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3153 // \brief Retrieve the location of the name of the member that this
3154 // expression refers to.
3155 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3157 /// \brief Retrieve the location of the template keyword preceding the
3158 /// member name, if any.
3159 SourceLocation getTemplateKeywordLoc() const {
3160 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3161 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3164 /// \brief Retrieve the location of the left angle bracket starting the
3165 /// explicit template argument list following the member name, if any.
3166 SourceLocation getLAngleLoc() const {
3167 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3168 return getTemplateKWAndArgsInfo()->LAngleLoc;
3171 /// \brief Retrieve the location of the right angle bracket ending the
3172 /// explicit template argument list following the member name, if any.
3173 SourceLocation getRAngleLoc() const {
3174 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3175 return getTemplateKWAndArgsInfo()->RAngleLoc;
3178 /// Determines whether the member name was preceded by the template keyword.
3179 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3181 /// \brief Determines whether this member expression actually had a C++
3182 /// template argument list explicitly specified, e.g., x.f<int>.
3183 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3185 /// \brief Retrieve the explicit template argument list that followed the
3186 /// member template name, if any.
3187 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3188 assert(hasExplicitTemplateArgs());
3189 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3192 /// \brief Retrieve the explicit template argument list that followed the
3193 /// member template name, if any.
3194 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3195 return const_cast<CXXDependentScopeMemberExpr *>(this)
3196 ->getExplicitTemplateArgs();
3199 /// \brief Retrieves the optional explicit template arguments.
3200 /// This points to the same data as getExplicitTemplateArgs(), but
3201 /// returns null if there are no explicit template arguments.
3202 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
3203 if (!hasExplicitTemplateArgs()) return 0;
3204 return &getExplicitTemplateArgs();
3207 /// \brief Copies the template arguments (if present) into the given
3209 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3210 getExplicitTemplateArgs().copyInto(List);
3213 /// \brief Initializes the template arguments using the given structure.
3214 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3215 getExplicitTemplateArgs().initializeFrom(List);
3218 /// \brief Retrieve the template arguments provided as part of this
3220 const TemplateArgumentLoc *getTemplateArgs() const {
3221 return getExplicitTemplateArgs().getTemplateArgs();
3224 /// \brief Retrieve the number of template arguments provided as part of this
3226 unsigned getNumTemplateArgs() const {
3227 return getExplicitTemplateArgs().NumTemplateArgs;
3230 SourceLocation getLocStart() const LLVM_READONLY {
3231 if (!isImplicitAccess())
3232 return Base->getLocStart();
3234 return getQualifierLoc().getBeginLoc();
3235 return MemberNameInfo.getBeginLoc();
3238 SourceLocation getLocEnd() const LLVM_READONLY {
3239 if (hasExplicitTemplateArgs())
3240 return getRAngleLoc();
3241 return MemberNameInfo.getEndLoc();
3244 static bool classof(const Stmt *T) {
3245 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3249 child_range children() {
3250 if (isImplicitAccess()) return child_range();
3251 return child_range(&Base, &Base + 1);
3254 friend class ASTStmtReader;
3255 friend class ASTStmtWriter;
3258 /// \brief Represents a C++ member access expression for which lookup
3259 /// produced a set of overloaded functions.
3261 /// The member access may be explicit or implicit:
3264 /// int explicitAccess() { return this->a + this->A::b; }
3265 /// int implicitAccess() { return a + A::b; }
3268 /// In the final AST, an explicit access always becomes a MemberExpr.
3269 /// An implicit access may become either a MemberExpr or a
3270 /// DeclRefExpr, depending on whether the member is static.
3271 class UnresolvedMemberExpr : public OverloadExpr {
3272 /// \brief Whether this member expression used the '->' operator or
3273 /// the '.' operator.
3276 /// \brief Whether the lookup results contain an unresolved using
3278 bool HasUnresolvedUsing : 1;
3280 /// \brief The expression for the base pointer or class reference,
3281 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
3282 /// member expression
3285 /// \brief The type of the base expression; never null.
3288 /// \brief The location of the '->' or '.' operator.
3289 SourceLocation OperatorLoc;
3291 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3292 Expr *Base, QualType BaseType, bool IsArrow,
3293 SourceLocation OperatorLoc,
3294 NestedNameSpecifierLoc QualifierLoc,
3295 SourceLocation TemplateKWLoc,
3296 const DeclarationNameInfo &MemberNameInfo,
3297 const TemplateArgumentListInfo *TemplateArgs,
3298 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3300 UnresolvedMemberExpr(EmptyShell Empty)
3301 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3302 HasUnresolvedUsing(false), Base(0) { }
3304 friend class ASTStmtReader;
3307 static UnresolvedMemberExpr *
3308 Create(ASTContext &C, bool HasUnresolvedUsing,
3309 Expr *Base, QualType BaseType, bool IsArrow,
3310 SourceLocation OperatorLoc,
3311 NestedNameSpecifierLoc QualifierLoc,
3312 SourceLocation TemplateKWLoc,
3313 const DeclarationNameInfo &MemberNameInfo,
3314 const TemplateArgumentListInfo *TemplateArgs,
3315 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3317 static UnresolvedMemberExpr *
3318 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3319 unsigned NumTemplateArgs);
3321 /// \brief True if this is an implicit access, i.e. one in which the
3322 /// member being accessed was not written in the source. The source
3323 /// location of the operator is invalid in this case.
3324 bool isImplicitAccess() const;
3326 /// \brief Retrieve the base object of this member expressions,
3327 /// e.g., the \c x in \c x.m.
3329 assert(!isImplicitAccess());
3330 return cast<Expr>(Base);
3332 const Expr *getBase() const {
3333 assert(!isImplicitAccess());
3334 return cast<Expr>(Base);
3337 QualType getBaseType() const { return BaseType; }
3339 /// \brief Determine whether the lookup results contain an unresolved using
3341 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3343 /// \brief Determine whether this member expression used the '->'
3344 /// operator; otherwise, it used the '.' operator.
3345 bool isArrow() const { return IsArrow; }
3347 /// \brief Retrieve the location of the '->' or '.' operator.
3348 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3350 /// \brief Retrieves the naming class of this lookup.
3351 CXXRecordDecl *getNamingClass() const;
3353 /// \brief Retrieve the full name info for the member that this expression
3355 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3357 /// \brief Retrieve the name of the member that this expression
3359 DeclarationName getMemberName() const { return getName(); }
3361 // \brief Retrieve the location of the name of the member that this
3362 // expression refers to.
3363 SourceLocation getMemberLoc() const { return getNameLoc(); }
3365 SourceLocation getLocStart() const LLVM_READONLY {
3366 if (!isImplicitAccess())
3367 return Base->getLocStart();
3368 if (NestedNameSpecifierLoc l = getQualifierLoc())
3369 return l.getBeginLoc();
3370 return getMemberNameInfo().getLocStart();
3372 SourceLocation getLocEnd() const LLVM_READONLY {
3373 if (hasExplicitTemplateArgs())
3374 return getRAngleLoc();
3375 return getMemberNameInfo().getLocEnd();
3378 static bool classof(const Stmt *T) {
3379 return T->getStmtClass() == UnresolvedMemberExprClass;
3383 child_range children() {
3384 if (isImplicitAccess()) return child_range();
3385 return child_range(&Base, &Base + 1);
3389 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
3391 /// The noexcept expression tests whether a given expression might throw. Its
3392 /// result is a boolean constant.
3393 class CXXNoexceptExpr : public Expr {
3398 friend class ASTStmtReader;
3401 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3402 SourceLocation Keyword, SourceLocation RParen)
3403 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3404 /*TypeDependent*/false,
3405 /*ValueDependent*/Val == CT_Dependent,
3406 Val == CT_Dependent || Operand->isInstantiationDependent(),
3407 Operand->containsUnexpandedParameterPack()),
3408 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3411 CXXNoexceptExpr(EmptyShell Empty)
3412 : Expr(CXXNoexceptExprClass, Empty)
3415 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3417 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
3418 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3419 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3421 bool getValue() const { return Value; }
3423 static bool classof(const Stmt *T) {
3424 return T->getStmtClass() == CXXNoexceptExprClass;
3428 child_range children() { return child_range(&Operand, &Operand + 1); }
3431 /// \brief Represents a C++0x pack expansion that produces a sequence of
3434 /// A pack expansion expression contains a pattern (which itself is an
3435 /// expression) followed by an ellipsis. For example:
3438 /// template<typename F, typename ...Types>
3439 /// void forward(F f, Types &&...args) {
3440 /// f(static_cast<Types&&>(args)...);
3444 /// Here, the argument to the function object \c f is a pack expansion whose
3445 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3446 /// template is instantiated, the pack expansion will instantiate to zero or
3447 /// or more function arguments to the function object \c f.
3448 class PackExpansionExpr : public Expr {
3449 SourceLocation EllipsisLoc;
3451 /// \brief The number of expansions that will be produced by this pack
3452 /// expansion expression, if known.
3454 /// When zero, the number of expansions is not known. Otherwise, this value
3455 /// is the number of expansions + 1.
3456 unsigned NumExpansions;
3460 friend class ASTStmtReader;
3461 friend class ASTStmtWriter;
3464 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3465 Optional<unsigned> NumExpansions)
3466 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3467 Pattern->getObjectKind(), /*TypeDependent=*/true,
3468 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3469 /*ContainsUnexpandedParameterPack=*/false),
3470 EllipsisLoc(EllipsisLoc),
3471 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3472 Pattern(Pattern) { }
3474 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3476 /// \brief Retrieve the pattern of the pack expansion.
3477 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3479 /// \brief Retrieve the pattern of the pack expansion.
3480 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3482 /// \brief Retrieve the location of the ellipsis that describes this pack
3484 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3486 /// \brief Determine the number of expansions that will be produced when
3487 /// this pack expansion is instantiated, if already known.
3488 Optional<unsigned> getNumExpansions() const {
3490 return NumExpansions - 1;
3495 SourceLocation getLocStart() const LLVM_READONLY {
3496 return Pattern->getLocStart();
3498 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3500 static bool classof(const Stmt *T) {
3501 return T->getStmtClass() == PackExpansionExprClass;
3505 child_range children() {
3506 return child_range(&Pattern, &Pattern + 1);
3510 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3511 if (!HasTemplateKWAndArgsInfo) return 0;
3512 if (isa<UnresolvedLookupExpr>(this))
3513 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3514 (cast<UnresolvedLookupExpr>(this) + 1);
3516 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3517 (cast<UnresolvedMemberExpr>(this) + 1);
3520 /// \brief Represents an expression that computes the length of a parameter
3524 /// template<typename ...Types>
3526 /// static const unsigned value = sizeof...(Types);
3529 class SizeOfPackExpr : public Expr {
3530 /// \brief The location of the 'sizeof' keyword.
3531 SourceLocation OperatorLoc;
3533 /// \brief The location of the name of the parameter pack.
3534 SourceLocation PackLoc;
3536 /// \brief The location of the closing parenthesis.
3537 SourceLocation RParenLoc;
3539 /// \brief The length of the parameter pack, if known.
3541 /// When this expression is value-dependent, the length of the parameter pack
3542 /// is unknown. When this expression is not value-dependent, the length is
3546 /// \brief The parameter pack itself.
3549 friend class ASTStmtReader;
3550 friend class ASTStmtWriter;
3553 /// \brief Creates a value-dependent expression that computes the length of
3554 /// the given parameter pack.
3555 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3556 SourceLocation PackLoc, SourceLocation RParenLoc)
3557 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3558 /*TypeDependent=*/false, /*ValueDependent=*/true,
3559 /*InstantiationDependent=*/true,
3560 /*ContainsUnexpandedParameterPack=*/false),
3561 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3562 Length(0), Pack(Pack) { }
3564 /// \brief Creates an expression that computes the length of
3565 /// the given parameter pack, which is already known.
3566 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3567 SourceLocation PackLoc, SourceLocation RParenLoc,
3569 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3570 /*TypeDependent=*/false, /*ValueDependent=*/false,
3571 /*InstantiationDependent=*/false,
3572 /*ContainsUnexpandedParameterPack=*/false),
3573 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3574 Length(Length), Pack(Pack) { }
3576 /// \brief Create an empty expression.
3577 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3579 /// \brief Determine the location of the 'sizeof' keyword.
3580 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3582 /// \brief Determine the location of the parameter pack.
3583 SourceLocation getPackLoc() const { return PackLoc; }
3585 /// \brief Determine the location of the right parenthesis.
3586 SourceLocation getRParenLoc() const { return RParenLoc; }
3588 /// \brief Retrieve the parameter pack.
3589 NamedDecl *getPack() const { return Pack; }
3591 /// \brief Retrieve the length of the parameter pack.
3593 /// This routine may only be invoked when the expression is not
3594 /// value-dependent.
3595 unsigned getPackLength() const {
3596 assert(!isValueDependent() &&
3597 "Cannot get the length of a value-dependent pack size expression");
3601 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
3602 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3604 static bool classof(const Stmt *T) {
3605 return T->getStmtClass() == SizeOfPackExprClass;
3609 child_range children() { return child_range(); }
3612 /// \brief Represents a reference to a non-type template parameter
3613 /// that has been substituted with a template argument.
3614 class SubstNonTypeTemplateParmExpr : public Expr {
3615 /// \brief The replaced parameter.
3616 NonTypeTemplateParmDecl *Param;
3618 /// \brief The replacement expression.
3621 /// \brief The location of the non-type template parameter reference.
3622 SourceLocation NameLoc;
3624 friend class ASTReader;
3625 friend class ASTStmtReader;
3626 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3627 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3630 SubstNonTypeTemplateParmExpr(QualType type,
3631 ExprValueKind valueKind,
3633 NonTypeTemplateParmDecl *param,
3635 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3636 replacement->isTypeDependent(), replacement->isValueDependent(),
3637 replacement->isInstantiationDependent(),
3638 replacement->containsUnexpandedParameterPack()),
3639 Param(param), Replacement(replacement), NameLoc(loc) {}
3641 SourceLocation getNameLoc() const { return NameLoc; }
3642 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3643 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3645 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3647 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3649 static bool classof(const Stmt *s) {
3650 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3654 child_range children() { return child_range(&Replacement, &Replacement+1); }
3657 /// \brief Represents a reference to a non-type template parameter pack that
3658 /// has been substituted with a non-template argument pack.
3660 /// When a pack expansion in the source code contains multiple parameter packs
3661 /// and those parameter packs correspond to different levels of template
3662 /// parameter lists, this node is used to represent a non-type template
3663 /// parameter pack from an outer level, which has already had its argument pack
3664 /// substituted but that still lives within a pack expansion that itself
3665 /// could not be instantiated. When actually performing a substitution into
3666 /// that pack expansion (e.g., when all template parameters have corresponding
3667 /// arguments), this type will be replaced with the appropriate underlying
3668 /// expression at the current pack substitution index.
3669 class SubstNonTypeTemplateParmPackExpr : public Expr {
3670 /// \brief The non-type template parameter pack itself.
3671 NonTypeTemplateParmDecl *Param;
3673 /// \brief A pointer to the set of template arguments that this
3674 /// parameter pack is instantiated with.
3675 const TemplateArgument *Arguments;
3677 /// \brief The number of template arguments in \c Arguments.
3678 unsigned NumArguments;
3680 /// \brief The location of the non-type template parameter pack reference.
3681 SourceLocation NameLoc;
3683 friend class ASTReader;
3684 friend class ASTStmtReader;
3685 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3686 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3689 SubstNonTypeTemplateParmPackExpr(QualType T,
3690 NonTypeTemplateParmDecl *Param,
3691 SourceLocation NameLoc,
3692 const TemplateArgument &ArgPack);
3694 /// \brief Retrieve the non-type template parameter pack being substituted.
3695 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3697 /// \brief Retrieve the location of the parameter pack name.
3698 SourceLocation getParameterPackLocation() const { return NameLoc; }
3700 /// \brief Retrieve the template argument pack containing the substituted
3701 /// template arguments.
3702 TemplateArgument getArgumentPack() const;
3704 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3705 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3707 static bool classof(const Stmt *T) {
3708 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3712 child_range children() { return child_range(); }
3715 /// \brief Represents a reference to a function parameter pack that has been
3716 /// substituted but not yet expanded.
3718 /// When a pack expansion contains multiple parameter packs at different levels,
3719 /// this node is used to represent a function parameter pack at an outer level
3720 /// which we have already substituted to refer to expanded parameters, but where
3721 /// the containing pack expansion cannot yet be expanded.
3724 /// template<typename...Ts> struct S {
3725 /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
3727 /// template struct S<int, int>;
3729 class FunctionParmPackExpr : public Expr {
3730 /// \brief The function parameter pack which was referenced.
3731 ParmVarDecl *ParamPack;
3733 /// \brief The location of the function parameter pack reference.
3734 SourceLocation NameLoc;
3736 /// \brief The number of expansions of this pack.
3737 unsigned NumParameters;
3739 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
3740 SourceLocation NameLoc, unsigned NumParams,
3741 Decl * const *Params);
3743 friend class ASTReader;
3744 friend class ASTStmtReader;
3747 static FunctionParmPackExpr *Create(ASTContext &Context, QualType T,
3748 ParmVarDecl *ParamPack,
3749 SourceLocation NameLoc,
3750 ArrayRef<Decl *> Params);
3751 static FunctionParmPackExpr *CreateEmpty(ASTContext &Context,
3752 unsigned NumParams);
3754 /// \brief Get the parameter pack which this expression refers to.
3755 ParmVarDecl *getParameterPack() const { return ParamPack; }
3757 /// \brief Get the location of the parameter pack.
3758 SourceLocation getParameterPackLocation() const { return NameLoc; }
3760 /// \brief Iterators over the parameters which the parameter pack expanded
3762 typedef ParmVarDecl * const *iterator;
3763 iterator begin() const { return reinterpret_cast<iterator>(this+1); }
3764 iterator end() const { return begin() + NumParameters; }
3766 /// \brief Get the number of parameters in this parameter pack.
3767 unsigned getNumExpansions() const { return NumParameters; }
3769 /// \brief Get an expansion of the parameter pack by index.
3770 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
3772 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
3773 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3775 static bool classof(const Stmt *T) {
3776 return T->getStmtClass() == FunctionParmPackExprClass;
3779 child_range children() { return child_range(); }
3782 /// \brief Represents a prvalue temporary that written into memory so that
3783 /// a reference can bind to it.
3785 /// Prvalue expressions are materialized when they need to have an address
3786 /// in memory for a reference to bind to. This happens when binding a
3787 /// reference to the result of a conversion, e.g.,
3790 /// const int &r = 1.0;
3793 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3794 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3795 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3796 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3797 /// to it), maintaining the invariant that references always bind to glvalues.
3798 class MaterializeTemporaryExpr : public Expr {
3799 /// \brief The temporary-generating expression whose value will be
3803 friend class ASTStmtReader;
3804 friend class ASTStmtWriter;
3807 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3808 bool BoundToLvalueReference)
3809 : Expr(MaterializeTemporaryExprClass, T,
3810 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3811 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3812 Temporary->isInstantiationDependent(),
3813 Temporary->containsUnexpandedParameterPack()),
3814 Temporary(Temporary) { }
3816 MaterializeTemporaryExpr(EmptyShell Empty)
3817 : Expr(MaterializeTemporaryExprClass, Empty) { }
3819 /// \brief Retrieve the temporary-generating subexpression whose value will
3820 /// be materialized into a glvalue.
3821 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3823 /// \brief Determine whether this materialized temporary is bound to an
3824 /// lvalue reference; otherwise, it's bound to an rvalue reference.
3825 bool isBoundToLvalueReference() const {
3826 return getValueKind() == VK_LValue;
3829 SourceLocation getLocStart() const LLVM_READONLY {
3830 return Temporary->getLocStart();
3832 SourceLocation getLocEnd() const LLVM_READONLY {
3833 return Temporary->getLocEnd();
3836 static bool classof(const Stmt *T) {
3837 return T->getStmtClass() == MaterializeTemporaryExprClass;
3841 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3844 } // end namespace clang