ExprCXX.h revision 32b5a1e82f535d43e94332183cd330f4a39b2dbd
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
9010bfc253050626435f006386c0bee4b55329687James Dennett///
10010bfc253050626435f006386c0bee4b55329687James Dennett/// \file
11010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Defines the clang::Expr interface and subclasses for C++ expressions.
12010bfc253050626435f006386c0bee4b55329687James Dennett///
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPRCXX_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPRCXX_H
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
20d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/UnresolvedSet.h"
2201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/ExpressionTraits.h"
2301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h"
2401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/TypeTraits.h"
25aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl;
30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl;
31aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl;
32aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary;
3376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallclass MSPropertyDecl;
34aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo;
352fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass UuidAttr;
364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
533fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
54b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
55063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
56063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
574548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange Range;
58063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
59be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Record the FP_CONTRACT state that applies to this operator call. Only
60be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // meaningful for floating point types. For other types this value can be
61be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // set to false.
62be9af1288881110e406b87914162eaa59f1e5918Lang Hames  unsigned FPContractable : 1;
63be9af1288881110e406b87914162eaa59f1e5918Lang Hames
644548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRangeImpl() const LLVM_READONLY;
65b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                      ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
68be9af1288881110e406b87914162eaa59f1e5918Lang Hames                      SourceLocation operatorloc, bool fpContractable)
693b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
70f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
71be9af1288881110e406b87914162eaa59f1e5918Lang Hames      Operator(Op), FPContractable(fpContractable) {
724548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis    Range = getSourceRangeImpl();
734548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  }
741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
75ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
78010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the kind of overloaded operator that this
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
80063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
82010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the location of the operator symbol in the expression.
83010bfc253050626435f006386c0bee4b55329687James Dennett  ///
84010bfc253050626435f006386c0bee4b55329687James Dennett  /// When \c getOperator()==OO_Call, this is the location of the right
85010bfc253050626435f006386c0bee4b55329687James Dennett  /// parentheses; when \c getOperator()==OO_Subscript, this is the location
86010bfc253050626435f006386c0bee4b55329687James Dennett  /// of the right bracket.
87b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
88b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
9065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
914548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRange() const { return Range; }
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
95b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
964548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis
97be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Set the FP contractability status of this operator. Only meaningful for
98be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
99be9af1288881110e406b87914162eaa59f1e5918Lang Hames  void setFPContractable(bool FPC) { FPContractable = FPC; }
100be9af1288881110e406b87914162eaa59f1e5918Lang Hames
101be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Get the FP contractability status of this operator. Only meaningful for
102be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
103be9af1288881110e406b87914162eaa59f1e5918Lang Hames  bool isFPContractable() const { return FPContractable; }
104be9af1288881110e406b87914162eaa59f1e5918Lang Hames
1054548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtReader;
1064548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtWriter;
107b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
108b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
109010bfc253050626435f006386c0bee4b55329687James Dennett/// Represents a call to a member function that
11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
11188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
11588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
1193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer  CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
120f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
1213b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
12288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
1231817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
1241817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
1251817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
126010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieves the implicit object argument for the member call.
127010bfc253050626435f006386c0bee4b55329687James Dennett  ///
128010bfc253050626435f006386c0bee4b55329687James Dennett  /// For example, in "x.f(5)", this returns the sub-expression "x".
129b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
130ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
131010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieves the declaration of the called method.
132b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
13388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
134010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieves the CXXRecordDecl for the underlying type of
135010bfc253050626435f006386c0bee4b55329687James Dennett  /// the implicit object argument.
136010bfc253050626435f006386c0bee4b55329687James Dennett  ///
137010bfc253050626435f006386c0bee4b55329687James Dennett  /// Note that this is may not be the same declaration as that of the class
138010bfc253050626435f006386c0bee4b55329687James Dennett  /// context of the CXXMethodDecl which this function is calling.
139007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
1400cf3c0eecbff007cea2750c113894b47d9e09f33David Blaikie  CXXRecordDecl *getRecordDecl() const;
141007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
14488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
14588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
14688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
147010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a call to a CUDA kernel function.
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
151e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
152e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
153e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
1543b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
1553b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     SourceLocation RP)
1563b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
157e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
158e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
159e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
160e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
161e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
162e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
163e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
164e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
165e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
166e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
167e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
168e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
169e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
170e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
171e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
172e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
173e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
174010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Abstract class common to all of the C++ "named"/"keyword" casts.
17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
177010bfc253050626435f006386c0bee4b55329687James Dennett/// representing "named" casts: CXXStaticCastExpr for \c static_cast,
178010bfc253050626435f006386c0bee4b55329687James Dennett/// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for
179010bfc253050626435f006386c0bee4b55329687James Dennett/// reinterpret_cast, and CXXConstCastExpr for \c const_cast.
18049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1831d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
184f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian  SourceRange AngleBrackets; // range for '<' '>'
185ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
187f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
188f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1891d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
190f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                   SourceLocation RParenLoc,
191f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                   SourceRange AngleBrackets)
1921d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
193f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian      RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {}
19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
196f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
197ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1981d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
199ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
203a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
204010bfc253050626435f006386c0bee4b55329687James Dennett  /// \c static_cast.
205a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
206a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
2071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
2081d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
209ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
21065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
21165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
212f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian  SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; }
21365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
2141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
21649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
21749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
21849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
21949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
22049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
22149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
22249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
22349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
2241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
227010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A C++ \c static_cast expression (C++ [expr.static.cast]).
2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
230010bfc253050626435f006386c0bee4b55329687James Dennett/// \c static_cast<int>(1.0).
23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
233f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
234f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                    SourceLocation l, SourceLocation RParenLoc,
235f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                    SourceRange AngleBrackets)
236f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
237f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                       writtenTy, l, RParenLoc, AngleBrackets) {}
23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
242f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
24332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXStaticCastExpr *Create(const ASTContext &Context, QualType T,
244f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
246ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   TypeSourceInfo *Written, SourceLocation L,
247f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                   SourceLocation RParenLoc,
248f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                   SourceRange AngleBrackets);
24932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context,
250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
251ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
25449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
25649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
257010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]).
2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
25949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
26080747a834cf8b0304b314ede9aba3d6ddb8e9520NAKAMURA Takumi/// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time
261010bfc253050626435f006386c0bee4b55329687James Dennett/// check to determine how to perform the type conversion.
26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
263f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
264f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
265f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                     SourceLocation l, SourceLocation RParenLoc,
266f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                     SourceRange AngleBrackets)
267f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
268f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                       writtenTy, l, RParenLoc, AngleBrackets) {}
26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
270f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
271f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
272f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
273f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
27432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T,
275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
276f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                    TypeSourceInfo *Written, SourceLocation L,
278f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                    SourceLocation RParenLoc,
279f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                    SourceRange AngleBrackets);
280ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context,
282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
283ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2840fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2850fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
28749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
28949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
29049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
291010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]).
2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
29349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
295010bfc253050626435f006386c0bee4b55329687James Dennett///
296010bfc253050626435f006386c0bee4b55329687James Dennett/// A reinterpret_cast provides a differently-typed view of a value but
297010bfc253050626435f006386c0bee4b55329687James Dennett/// (in Clang, as in most C++ implementations) performs no actual work at
298010bfc253050626435f006386c0bee4b55329687James Dennett/// run time.
29949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
301f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
302ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                         TypeSourceInfo *writtenTy, SourceLocation l,
303f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                         SourceLocation RParenLoc,
304f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                         SourceRange AngleBrackets)
305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
306f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                       pathSize, writtenTy, l, RParenLoc, AngleBrackets) {}
30749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
308f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
309f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
310f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
31232b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T,
313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
315ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                 TypeSourceInfo *WrittenTy, SourceLocation L,
316f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                        SourceLocation RParenLoc,
317f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                        SourceRange AngleBrackets);
31832b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context,
319f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
320ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
32549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
326010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A C++ \c const_cast expression (C++ [expr.const.cast]).
3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
32849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
329010bfc253050626435f006386c0bee4b55329687James Dennett/// \c const_cast<char*>(PtrToConstChar).
330010bfc253050626435f006386c0bee4b55329687James Dennett///
331010bfc253050626435f006386c0bee4b55329687James Dennett/// A const_cast can remove type qualifiers but does not change the underlying
332010bfc253050626435f006386c0bee4b55329687James Dennett/// value.
33349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
335ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   TypeSourceInfo *writtenTy, SourceLocation l,
336f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                   SourceLocation RParenLoc, SourceRange AngleBrackets)
337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
338f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                       0, writtenTy, l, RParenLoc, AngleBrackets) {}
33949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
340ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
341f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
342f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
343f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
34432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXConstCastExpr *Create(const ASTContext &Context, QualType T,
345f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  TypeSourceInfo *WrittenTy, SourceLocation L,
347f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                  SourceLocation RParenLoc,
348f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian                                  SourceRange AngleBrackets);
34932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXConstCastExpr *CreateEmpty(const ASTContext &Context);
350ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
35249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
35349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
3541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
356010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A call to a literal operator (C++11 [over.literal])
3579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]).
3589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
3609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better
3619fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal.
3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at
3649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent.
3659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr {
3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// \brief The location of a ud-suffix within the literal.
3679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  SourceLocation UDSuffixLoc;
3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic:
37032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  UserDefinedLiteral(const ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
3719fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     SourceLocation SuffixLoc)
3733b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
3743b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer      UDSuffixLoc(SuffixLoc) {}
37532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  explicit UserDefinedLiteral(const ASTContext &C, EmptyShell Empty)
3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    : CallExpr(C, UserDefinedLiteralClass, Empty) {}
3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// The kind of literal operator which is invoked.
3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  enum LiteralOperatorKind {
3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Raw,      ///< Raw form: operator "" X (const char *)
3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Template, ///< Raw form: operator "" X<cs...> ()
3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Integer,  ///< operator "" X (unsigned long long)
3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Floating, ///< operator "" X (long double)
3849fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_String,   ///< operator "" X (const CharT *, size_t)
3859fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Character ///< operator "" X (CharT)
3869fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  };
3879fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
388010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the kind of literal operator invocation
3899fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// which this expression represents.
3909fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  LiteralOperatorKind getLiteralOperatorKind() const;
3919fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
392010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief If this is not a raw user-defined literal, get the
3939fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// underlying cooked literal (representing the literal with the suffix
3949fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// removed).
3959fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  Expr *getCookedLiteral();
3969fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const Expr *getCookedLiteral() const {
3979fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
3989fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
3999fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4000265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocStart() const {
4010265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    if (getLiteralOperatorKind() == LOK_Template)
4020265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara      return getRParenLoc();
4030265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    return getArg(0)->getLocStart();
4040265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  }
4050265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocEnd() const { return getRParenLoc(); }
4060265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
4070265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
408010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the location of a ud-suffix in the expression.
409010bfc253050626435f006386c0bee4b55329687James Dennett  ///
4109fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// For a string literal, there may be multiple identical suffixes. This
4119fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// returns the first.
4120265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
4139fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
414010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the ud-suffix specified for this literal.
4159fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const IdentifierInfo *getUDSuffix() const;
4169fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4179fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const Stmt *S) {
4189fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return S->getStmtClass() == UserDefinedLiteralClass;
4199fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
4209fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4219fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtReader;
4229fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtWriter;
4239fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith};
4249fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
425010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A boolean literal, per ([C++ lex.bool] Boolean literals).
4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
4271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
4281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
4291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
4301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
433561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
434f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
4358b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
436eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
437eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
438eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
440eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
44265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
44365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
445eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
446eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
447eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
4501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
45363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
4551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
456010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief The null pointer literal (C++11 [lex.nullptr])
457010bfc253050626435f006386c0bee4b55329687James Dennett///
458010bfc253050626435f006386c0bee4b55329687James Dennett/// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
4596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
4606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
4616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
4626e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
463bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
464561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
465f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
4666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
467eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
468eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
469eb7f96141f754150a92433286fa385910a22f494Sam Weinig
47065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
47165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
4726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
473eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
474eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
475eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
4776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
4786e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
4796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
48063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4816e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
4826e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
4837c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith/// \brief Implicit construction of a std::initializer_list<T> object from an
4847c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith/// array temporary within list-initialization (C++11 [dcl.init.list]p5).
4857c3e615f01e8f9f587315800fdaf2305ed824568Richard Smithclass CXXStdInitializerListExpr : public Expr {
4867c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  Stmt *SubExpr;
4877c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
4887c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  CXXStdInitializerListExpr(EmptyShell Empty)
4897c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    : Expr(CXXStdInitializerListExprClass, Empty), SubExpr(0) {}
4907c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
4917c3e615f01e8f9f587315800fdaf2305ed824568Richard Smithpublic:
4927c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr)
4937c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    : Expr(CXXStdInitializerListExprClass, Ty, VK_RValue, OK_Ordinary,
4947c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith           Ty->isDependentType(), SubExpr->isValueDependent(),
4957c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith           SubExpr->isInstantiationDependent(),
4967c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith           SubExpr->containsUnexpandedParameterPack()),
4977c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith      SubExpr(SubExpr) {}
4987c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
4997c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); }
5007c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); }
5017c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
5027c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  SourceLocation getLocStart() const LLVM_READONLY {
5037c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    return SubExpr->getLocStart();
5047c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  }
5057c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  SourceLocation getLocEnd() const LLVM_READONLY {
5067c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    return SubExpr->getLocEnd();
5077c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  }
5087c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  SourceRange getSourceRange() const LLVM_READONLY {
5097c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    return SubExpr->getSourceRange();
5107c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  }
5117c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
5127c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  static bool classof(const Stmt *S) {
5137c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith    return S->getStmtClass() == CXXStdInitializerListExprClass;
5147c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  }
5157c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
5167c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
5177c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
5187c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  friend class ASTReader;
5197c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith  friend class ASTStmtReader;
5207c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith};
5217c3e615f01e8f9f587315800fdaf2305ed824568Richard Smith
522010bfc253050626435f006386c0bee4b55329687James Dennett/// A C++ \c typeid expression (C++ [expr.typeid]), which gets
523010bfc253050626435f006386c0bee4b55329687James Dennett/// the \c type_info that corresponds to the supplied type, or the (possibly
524c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
525c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
526010bfc253050626435f006386c0bee4b55329687James Dennett/// This represents code like \c typeid(int) or \c typeid(*objPtr)
527c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
528c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
52957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
530c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
531c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
532c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
53357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
534f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
53557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
53657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
53757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
538bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
539561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
540bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
54157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
54357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
544f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
5452850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
546bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
5472850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
549561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
550bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
55157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
552c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
55314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
55414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
55514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
55614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
55714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
55814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
55914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5610d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// Determine whether this typeid has a type operand which is potentially
5620d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// evaluated, per C++11 [expr.typeid]p3.
5630d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  bool isPotentiallyEvaluated() const;
5640d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith
56557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
56757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
56857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
56957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
57057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
57157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
57257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
573c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
57457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
575c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
57614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
57714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
57814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
57914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
58014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
581ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
58214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
583c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
58457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
585c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
586ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
587030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
588030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
589030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
590030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
591ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
59265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
59365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
594aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
59514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
596ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
597c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
598c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
599c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
600c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
601c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
60263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
60363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
60463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
60563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
60663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
607c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
608c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
609010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A member reference to an MSPropertyDecl.
610010bfc253050626435f006386c0bee4b55329687James Dennett///
611010bfc253050626435f006386c0bee4b55329687James Dennett/// This expression always has pseudo-object type, and therefore it is
612010bfc253050626435f006386c0bee4b55329687James Dennett/// typically not encountered in a fully-typechecked expression except
613010bfc253050626435f006386c0bee4b55329687James Dennett/// within the syntactic form of a PseudoObjectExpr.
61476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallclass MSPropertyRefExpr : public Expr {
61576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  Expr *BaseExpr;
61676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  MSPropertyDecl *TheDecl;
61776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  SourceLocation MemberLoc;
61876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  bool IsArrow;
61976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  NestedNameSpecifierLoc QualifierLoc;
62076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
62176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallpublic:
62276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow,
62376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall                    QualType ty, ExprValueKind VK,
62476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall                    NestedNameSpecifierLoc qualifierLoc,
62576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall                    SourceLocation nameLoc)
62676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary,
62776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall         /*type-dependent*/ false, baseExpr->isValueDependent(),
62876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall         baseExpr->isInstantiationDependent(),
62976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall         baseExpr->containsUnexpandedParameterPack()),
63076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    BaseExpr(baseExpr), TheDecl(decl),
63176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    MemberLoc(nameLoc), IsArrow(isArrow),
63276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    QualifierLoc(qualifierLoc) {}
63376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
63476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {}
63576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
63676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  SourceRange getSourceRange() const LLVM_READONLY {
63776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    return SourceRange(getLocStart(), getLocEnd());
63876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  }
63976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  bool isImplicitAccess() const {
64076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    return getBaseExpr() && getBaseExpr()->isImplicitCXXThis();
64176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  }
64276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  SourceLocation getLocStart() const {
64376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    if (!isImplicitAccess())
64476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall      return BaseExpr->getLocStart();
64576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    else if (QualifierLoc)
64676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall      return QualifierLoc.getBeginLoc();
64776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    else
64876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall        return MemberLoc;
64976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  }
65076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  SourceLocation getLocEnd() const { return getMemberLoc(); }
65176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
65276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  child_range children() {
65376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1);
65476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  }
65576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  static bool classof(const Stmt *T) {
65676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall    return T->getStmtClass() == MSPropertyRefExprClass;
65776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  }
65876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
65976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  Expr *getBaseExpr() const { return BaseExpr; }
66076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  MSPropertyDecl *getPropertyDecl() const { return TheDecl; }
66176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  bool isArrow() const { return IsArrow; }
66276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  SourceLocation getMemberLoc() const { return MemberLoc; }
66376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
66476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
66576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall  friend class ASTStmtReader;
66676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall};
66776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall
668010bfc253050626435f006386c0bee4b55329687James Dennett/// A Microsoft C++ @c __uuidof expression, which gets
66901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
67001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
67101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
67201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
67301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
67401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
67501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
67601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
67701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
67801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
6792e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
680bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
681561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
682bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
68301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
684ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
68501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
6862e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
687bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
688561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
689bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
69001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
69101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
69201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
69301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
69401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
69501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
69601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
69701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
69801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
70001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
70201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
70301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
70401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
70501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
70601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
70701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
70801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
70901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
71001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
71101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
71201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
71301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
71401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
71501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
716ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
71701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
71801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
71901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
72001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
721ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
72201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
72301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
72401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
72501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
72601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
727c80eb46a0f37bee9597f1b466013a0f6271f9318David Majnemer  StringRef getUuidAsStringRef(ASTContext &Context) const;
728c80eb46a0f37bee9597f1b466013a0f6271f9318David Majnemer
72965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
73065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
731aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
73201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
733ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
73401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
73501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
73601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
73701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
738c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none.
739c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  static UuidAttr *GetUuidAttrOfType(QualType QT);
740c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber
74101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
74263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
74363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
74463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
74563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
74663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
74701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
74801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
749010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents the \c this expression in C++.
750010bfc253050626435f006386c0bee4b55329687James Dennett///
751010bfc253050626435f006386c0bee4b55329687James Dennett/// This is a pointer to the object on which the current member function is
752796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
753796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
754010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
755796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
756796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
757796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
758796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
759796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
760010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
761796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
762796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
763828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
764ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
765796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
766828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
767f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
7682850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
7692850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
770bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
771561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Type->isInstantiationDependentType(),
772bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
773828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
774796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
7752fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
7762fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
7772fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
7782fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
7792fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
78065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
78165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
782796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
783828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
784828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
787796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
788796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
789796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
790796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
79163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
792796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
793796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
794010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A C++ throw-expression (C++ [except.throw]).
7951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
796010bfc253050626435f006386c0bee4b55329687James Dennett/// This handles 'throw' (for re-throwing the current exception) and
797010bfc253050626435f006386c0bee4b55329687James Dennett/// 'throw' assignment-expression.  When assignment-expression isn't
798010bfc253050626435f006386c0bee4b55329687James Dennett/// present, Op will be null.
7991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
8001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
8011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
802bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Whether the thrown variable (if any) is in scope.
803bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  unsigned IsThrownVariableInScope : 1;
804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
805bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  friend class ASTStmtReader;
806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
808010bfc253050626435f006386c0bee4b55329687James Dennett  // \p Ty is the void type which is used as the result type of the
809010bfc253050626435f006386c0bee4b55329687James Dennett  // expression.  The \p l is the location of the throw keyword.  \p expr
8101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
811bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
812bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor               bool IsThrownVariableInScope) :
813bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
814561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         expr && expr->isInstantiationDependent(),
815bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
816bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
8172fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
8182fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
8191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
8201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
82142e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
82242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
8231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
824bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Determines whether the variable thrown by this expression (if any!)
825bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// is within the innermost try block.
826bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ///
827bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// This information is required to determine whether the NRVO can apply to
828bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// this variable.
829bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
830ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
83165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
83265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
8331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
83465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return ThrowLoc;
83565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getSubExpr()->getLocEnd();
8361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
8371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
8391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
8401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
8411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
84363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
84463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
84563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
8461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
8471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
848010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A default argument (C++ [dcl.fct.default]).
849010bfc253050626435f006386c0bee4b55329687James Dennett///
850010bfc253050626435f006386c0bee4b55329687James Dennett/// This wraps up a function call argument that was created from the
851010bfc253050626435f006386c0bee4b55329687James Dennett/// corresponding parameter's default argument, when the call did not
852010bfc253050626435f006386c0bee4b55329687James Dennett/// explicitly supply arguments for all of the parameters.
8531060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
85465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
85565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// When the bit is set, the subexpression is stored after the
85765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
85865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
85965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
861036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
862036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
864036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
865ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(SC,
86665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
86765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
8682333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
869dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
870561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false, false),
871036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
87265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
874036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
875dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
876dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
877ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           false, false, false, false),
878bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
87965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
88065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
881ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
883030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
884030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
885010bfc253050626435f006386c0bee4b55329687James Dennett  // \p Param is the parameter whose default argument is used by this
8861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
88732b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
888036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
889036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
890f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
8911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
892010bfc253050626435f006386c0bee4b55329687James Dennett  // \p Param is the parameter whose default argument is used by this
893010bfc253050626435f006386c0bee4b55329687James Dennett  // expression, and \p SubExpr is the expression that will actually be used.
89432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
89532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                                   ParmVarDecl *Param, Expr *SubExpr);
896ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
89865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
89965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
900ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
902ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  const Expr *getExpr() const {
90365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
90465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
905ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
90665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
907ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getExpr() {
90865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
90965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
910ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
91165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
9121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
913ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the location where this default argument was actually
914036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
915036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
916ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
917010bfc253050626435f006386c0bee4b55329687James Dennett  /// Default argument expressions have no representation in the
918010bfc253050626435f006386c0bee4b55329687James Dennett  /// source, so they have an empty source range.
91965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
92065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
92163b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer
92263b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
9231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
9241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
9251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
9261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
9271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
9281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
92963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
9308a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
93160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
9323397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
9331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
934987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
935010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief A use of a default initializer in a constructor or in aggregate
936010bfc253050626435f006386c0bee4b55329687James Dennett/// initialization.
937010bfc253050626435f006386c0bee4b55329687James Dennett///
938010bfc253050626435f006386c0bee4b55329687James Dennett/// This wraps a use of a C++ default initializer (technically,
939c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith/// a brace-or-equal-initializer for a non-static data member) when it
940c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith/// is implicitly used in a mem-initializer-list in a constructor
941c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith/// (C++11 [class.base.init]p8) or in aggregate initialization
942c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith/// (C++1y [dcl.init.aggr]p7).
943c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithclass CXXDefaultInitExpr : public Expr {
944c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// \brief The field whose default is being used.
945c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  FieldDecl *Field;
946c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
947c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// \brief The location where the default initializer expression was used.
948c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  SourceLocation Loc;
949c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
95032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXDefaultInitExpr(const ASTContext &C, SourceLocation Loc, FieldDecl *Field,
951c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith                     QualType T);
952c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
953c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {}
954c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
955c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithpublic:
956010bfc253050626435f006386c0bee4b55329687James Dennett  /// \p Field is the non-static data member whose default initializer is used
957010bfc253050626435f006386c0bee4b55329687James Dennett  /// by this expression.
95832b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXDefaultInitExpr *Create(const ASTContext &C, SourceLocation Loc,
959c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith                                    FieldDecl *Field) {
960c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    return new (C) CXXDefaultInitExpr(C, Loc, Field, Field->getType());
961c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  }
962c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
963010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Get the field whose initializer will be used.
964c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  FieldDecl *getField() { return Field; }
965c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  const FieldDecl *getField() const { return Field; }
966c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
967010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Get the initialization expression that will be used.
968c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  const Expr *getExpr() const { return Field->getInClassInitializer(); }
969c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  Expr *getExpr() { return Field->getInClassInitializer(); }
970c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
971c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
972c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
973c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
974c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  static bool classof(const Stmt *T) {
975c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    return T->getStmtClass() == CXXDefaultInitExprClass;
976c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  }
977c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
978c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  // Iterators
979c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  child_range children() { return child_range(); }
980c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
981c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  friend class ASTReader;
982c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  friend class ASTStmtReader;
983c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith};
984c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
985010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a C++ temporary.
986c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
987010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The destructor that needs to be called.
988b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
990010bfc253050626435f006386c0bee4b55329687James Dennett  explicit CXXTemporary(const CXXDestructorDecl *destructor)
991c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
992c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
993c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
99432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXTemporary *Create(const ASTContext &C,
995b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
997f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
99876f3f69db1416425070177243e9f390122c553e0Richard Smith  void setDestructor(const CXXDestructorDecl *Dtor) {
99976f3f69db1416425070177243e9f390122c553e0Richard Smith    Destructor = Dtor;
100076f3f69db1416425070177243e9f390122c553e0Richard Smith  }
1001c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
1002fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
1003ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
1004ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
1005ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
1006ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
1007ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
1008ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
1009ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
1010ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
1011ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
1012ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
1013ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
1014ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
1015ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
1016ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
1017fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
1018fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1020fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
1021fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
1022bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
1023bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
1024ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
1025bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
1026561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          SubExpr->isInstantiationDependent(),
1027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
1028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
102988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
1030fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
1031d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
1032d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
1033ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
103432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp,
1035fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
103788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
1038f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
1039d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
1040f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
1041fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1042fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
104388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
1044fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
104565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
104665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExpr->getLocStart();
104796be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
104865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
1049fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
1050fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
1051fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
1052fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
1053fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
1054fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
1055fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
105663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
1057fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
1058fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
10590982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a call to a C++ constructor.
106015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
106172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
106272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
106372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
106472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
1065059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_VirtualBase,
1066059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_Delegating
106772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
1068ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
106972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
107015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
107115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
107299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
1073428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
1074a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor  unsigned NumArgs : 16;
107516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
10767cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool HadMultipleCandidates : 1;
10775b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool ListInitialization : 1;
107816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
107972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
108015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1082bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
108332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXConstructExpr(const ASTContext &C, StmtClass SC, QualType T,
108499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
1085bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
10863b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                   ArrayRef<Expr *> Args,
10877cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                   bool HadMultipleCandidates,
10885b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ListInitialization,
10895b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ZeroInitialization,
10905b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   ConstructionKind ConstructKind,
10915b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   SourceRange ParenRange);
1092bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
10936d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
10946d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
10955b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl    : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
10965b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      HadMultipleCandidates(false), ListInitialization(false),
10975b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ZeroInitialization(false), ConstructKind(0), Args(0)
10985b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
10996d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
110015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
11016d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
11026d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
11036d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
11045b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      NumArgs(0), Elidable(false), HadMultipleCandidates(false),
11055b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ListInitialization(false), ZeroInitialization(false),
11065b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ConstructKind(0), Args(0)
11075b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
11086d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
110932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXConstructExpr *Create(const ASTContext &C, QualType T,
111099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
11123b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                  ArrayRef<Expr *> Args,
11137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                  bool HadMultipleCandidates,
11145b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ListInitialization,
11155b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ZeroInitialization,
11165b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  ConstructionKind ConstructKind,
11175b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  SourceRange ParenRange);
11181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1119d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
112039da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
1121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
112299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
112399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
1124ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1125d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
1126d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
112739da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
11287cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
11297cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Whether the referred constructor was resolved from
11307cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// an overloaded set having size greater than 1.
11317cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
11327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
11337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
11345b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  /// \brief Whether this constructor call was written as list-initialization.
11355b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool isListInitialization() const { return ListInitialization; }
11365b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  void setListInitialization(bool V) { ListInitialization = V; }
11375b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
113816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
113916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
114016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
114116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
114216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
114316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
1144ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1145010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Determine whether this constructor is actually constructing
11469db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
114724eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
114824eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
114972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
1150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setConstructionKind(ConstructionKind CK) {
115172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
115272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
1153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
115415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
115515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
115715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
115815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
115915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
116015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
116115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
1162a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
116315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
116415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
1165010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Return the specified argument.
1166bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
1167bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1168bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1169bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
1170bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
1171bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1172bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1173bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1175010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Set the specified argument.
11762eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
11772eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
11782eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
11792eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
11802eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
118165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
118265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
1183428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
1184a770a4daf77037b5526dba1c447d61acf0aba01aDaniel Jasper  void setParenRange(SourceRange Range) { ParenRange = Range; }
118515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1187524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
1188524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
118915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
119115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
119263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
119363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
119463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11956d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
119660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
119715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
119815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
11990982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an explicit C++ type conversion that uses "functional"
12000982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// notation (C++ [expr.type.conv]).
12010982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
12020982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Example:
1203010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
12040982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   x = int(0.5);
1205010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
120649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
1207cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman  SourceLocation LParenLoc;
1208987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1209f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1210f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1211f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
1212cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman                        CastKind kind, Expr *castExpr, unsigned pathSize,
1213cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman                        SourceLocation lParenLoc, SourceLocation rParenLoc)
1214f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1215f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
1216cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman      LParenLoc(lParenLoc), RParenLoc(rParenLoc) {}
12170aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
1218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1220f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1221f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
122232b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXFunctionalCastExpr *Create(const ASTContext &Context, QualType T,
1223f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
1224f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
1225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
1226f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
1227cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman                                       SourceLocation LPLoc,
1228f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
122932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXFunctionalCastExpr *CreateEmpty(const ASTContext &Context,
1230f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
1231ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1232cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman  SourceLocation getLParenLoc() const { return LParenLoc; }
1233cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1234987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
1235ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1237cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman  SourceLocation getLocStart() const LLVM_READONLY;
1238cdd4b78583120222b82148626119b3e80ae1d291Eli Friedman  SourceLocation getLocEnd() const LLVM_READONLY;
123965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
1242987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1243987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1244987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1245506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
1246506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
1247506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
1249506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1250ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the
1251ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
1252506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
1253010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
1254506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
1255506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
1256506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
1257506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1258506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
1259010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
1260524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
1261ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
1262506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1263506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
126432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXTemporaryObjectExpr(const ASTContext &C, CXXConstructorDecl *Cons,
1265ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
12663b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                         ArrayRef<Expr *> Args,
1267428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
12687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                         bool HadMultipleCandidates,
1269c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith                         bool ListInitialization,
1270c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith                         bool ZeroInitialization);
12716d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1272ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1273506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1274ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1275ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
127665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
127765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
1278ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1280506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
1281506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
12826d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
128360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
1284506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
1285506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
128601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object
128701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later.
128801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
128901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example:
129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code
129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) {
129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///   values.erase(std::remove_if(values.begin(), values.end(),
1293d9ffa0c39ff9c71e2729eac4cdcf32b377c1d3b6Dmitri Gribenko///                               [=](double value) { return value > cutoff; });
129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// }
129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode
129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
1297ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett/// C++11 lambda expressions can capture local variables, either by copying
129801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function
129901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a
130001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either
130101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square
130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression.
1303ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett///
1304ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett/// C++1y introduces a new form of "capture" called an init-capture that
1305ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett/// includes an initializing expression (rather than capturing a variable),
1306ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett/// and which can never occur implicitly.
130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr {
130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  enum {
130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indicate that the given
131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture was implicit.
131101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_Implicit = 0x01,
131201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13130d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    /// \brief Flag used by the Capture class to indicate that the
131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// given capture was by-copy.
1315ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    ///
1316ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// This includes the case of a non-reference init-capture.
131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_ByCopy = 0x02
131801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
131901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The source range that covers the lambda introducer ([...]).
132101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange IntroducerRange;
132201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1323f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett  /// \brief The source location of this lambda's capture-default ('=' or '&').
1324f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett  SourceLocation CaptureDefaultLoc;
1325f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett
13267ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief The number of captures.
13277ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned NumCaptures : 16;
13287ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
132901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The default capture kind, which is a value of type
133001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// LambdaCaptureDefault.
133101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned CaptureDefault : 2;
133201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
133301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Whether this lambda had an explicit parameter list vs. an
133401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit (and empty) parameter list.
133501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned ExplicitParams : 1;
133601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1337dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had the result type explicitly specified.
1338dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  unsigned ExplicitResultType : 1;
1339dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
1340dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether there are any array index variables stored at the end of
1341dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// this lambda expression.
13427ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned HasArrayIndexVars : 1;
13437ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
134401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The location of the closing brace ('}') that completes
134501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// the lambda.
134601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  ///
134701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// The location of the brace is also available by looking up the
134801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// function call operator in the lambda class. However, it is
134901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stored here to improve the performance of getSourceRange(), and
135001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// to avoid having to deserialize the function call operator from a
135101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// module file just to determine the source range.
135201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceLocation ClosingBrace;
135301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13547ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // Note: The capture initializers are stored directly after the lambda
13557ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // expression, along with the index variables used to initialize by-copy
13567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // array captures.
13577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
135801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
1359ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett  /// \brief Describes the capture of a variable or of \c this, or of a
1360ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett  /// C++1y init-capture.
136101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  class Capture {
13620d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    llvm::PointerIntPair<Decl *, 2> DeclAndBits;
136301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation Loc;
136401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation EllipsisLoc;
13659daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
136601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtReader;
136701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtWriter;
13689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
136901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  public:
1370ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \brief Create a new capture of a variable or of \c this.
137101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
137201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Loc The source location associated with this capture.
137301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
1374ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \param Kind The kind of capture (this, byref, bycopy), which must
1375ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// not be init-capture.
137601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
137701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Implicit Whether the capture was implicit or explicit.
137801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
1379ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \param Var The local variable being captured, or null if capturing
1380ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \c this.
138101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
138201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param EllipsisLoc The location of the ellipsis (...) for a
138301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture that is a pack expansion, or an invalid source
138401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// location to indicate that this is not a pack expansion.
138501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture(SourceLocation Loc, bool Implicit,
138601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            LambdaCaptureKind Kind, VarDecl *Var = 0,
138701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            SourceLocation EllipsisLoc = SourceLocation());
138801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13890d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    /// \brief Create a new init-capture.
13900d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Capture(FieldDecl *Field);
13910d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
139201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine the kind of capture.
139301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    LambdaCaptureKind getCaptureKind() const;
139401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1395ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \brief Determine whether this capture handles the C++ \c this
139601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// pointer.
13970d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool capturesThis() const { return DeclAndBits.getPointer() == 0; }
139801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles a variable.
14000d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool capturesVariable() const {
14010d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return dyn_cast_or_null<VarDecl>(DeclAndBits.getPointer());
14020d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
14030d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
1404ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// \brief Determine whether this is an init-capture.
14050d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isInitCapture() const { return getCaptureKind() == LCK_Init; }
140601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
140701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the declaration of the local variable being
140801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// captured.
140901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
14100d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    /// This operation is only valid if this capture is a variable capture
1411ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// (other than a capture of \c this).
14120d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    VarDecl *getCapturedVar() const {
14130d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      assert(capturesVariable() && "No variable available for 'this' capture");
14140d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return cast<VarDecl>(DeclAndBits.getPointer());
14150d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
14160d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
14170d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    /// \brief Retrieve the field for an init-capture.
1418c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    ///
1419c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    /// This works only for an init-capture.  To retrieve the FieldDecl for
1420c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    /// a captured variable or for a capture of \c this, use
1421c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    /// LambdaExpr::getLambdaClass and CXXRecordDecl::getCaptureFields.
14220d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    FieldDecl *getInitCaptureField() const {
14230d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      assert(getCaptureKind() == LCK_Init && "no field for non-init-capture");
14240d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return cast<FieldDecl>(DeclAndBits.getPointer());
142501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
142601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
142701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an implicit capture (not
142801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// written between the square brackets introducing the lambda).
14290d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isImplicit() const { return DeclAndBits.getInt() & Capture_Implicit; }
143001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1431c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    /// \brief Determine whether this was an explicit capture (written
1432c65f03498f6c59b5ae5c14086f49ae6e7a173624James Dennett    /// between the square brackets introducing the lambda).
143301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isExplicit() const { return !isImplicit(); }
143401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
143501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the source location of the capture.
143601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
143701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// For an explicit capture, this returns the location of the
143801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// explicit capture in the source. For an implicit capture, this
1439ddcd660efccd7dcbe42cf1a5759b37ee5619bf9bJames Dennett    /// returns the location at which the variable or \c this was first
144001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// used.
144101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getLocation() const { return Loc; }
144201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
144301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture is a pack expansion,
144401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// which captures a function parameter pack.
144501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isPackExpansion() const { return EllipsisLoc.isValid(); }
144601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
144701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the location of the ellipsis for a capture
144801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// that is a pack expansion.
144901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getEllipsisLoc() const {
145001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(isPackExpansion() && "No ellipsis location for a non-expansion");
145101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return EllipsisLoc;
145201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
145301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
145401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
145501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate:
145601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a lambda expression.
145701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaExpr(QualType T, SourceRange IntroducerRange,
145801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             LambdaCaptureDefault CaptureDefault,
1459f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett             SourceLocation CaptureDefaultLoc,
146001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Capture> Captures,
146101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             bool ExplicitParams,
1462dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor             bool ExplicitResultType,
146301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Expr *> CaptureInits,
14649daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<VarDecl *> ArrayIndexVars,
14659daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<unsigned> ArrayIndexStarts,
1466612409ece080e814f79e06772c690d603f45fbd6Richard Smith             SourceLocation ClosingBrace,
1467612409ece080e814f79e06772c690d603f45fbd6Richard Smith             bool ContainsUnexpandedParameterPack);
146801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
14699d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct an empty lambda expression.
14709d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
14719d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    : Expr(LambdaExprClass, Empty),
14729d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
14739d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      ExplicitResultType(false), HasArrayIndexVars(true) {
14749d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    getStoredStmts()[NumCaptures] = 0;
14759d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  }
14769d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
14777ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  Stmt **getStoredStmts() const {
14787ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
14797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
14807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
14817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the mapping from captures to the first array index
14827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// variable.
14837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned *getArrayIndexStarts() const {
14847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
14857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
14867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
14877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the complete set of array-index variables.
14887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  VarDecl **getArrayIndexVars() const {
1489a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith    unsigned ArrayIndexSize =
1490a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith        llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1491a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith                                 llvm::alignOf<VarDecl*>());
14927ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<VarDecl **>(
149388d2f678e70ab9360f09f3534d9223e6ec20f129Richard Smith        reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
14947ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
14957ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
149601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
149701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a new lambda expression.
149832b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static LambdaExpr *Create(const ASTContext &C,
149901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            CXXRecordDecl *Class,
150001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            SourceRange IntroducerRange,
150101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            LambdaCaptureDefault CaptureDefault,
1502f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett                            SourceLocation CaptureDefaultLoc,
150301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Capture> Captures,
150401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            bool ExplicitParams,
1505dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                            bool ExplicitResultType,
150601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Expr *> CaptureInits,
15079daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<VarDecl *> ArrayIndexVars,
15089daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<unsigned> ArrayIndexStarts,
1509612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            SourceLocation ClosingBrace,
1510612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            bool ContainsUnexpandedParameterPack);
151101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
15129d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct a new lambda expression that will be deserialized from
15139d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// an external source.
151432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static LambdaExpr *CreateDeserialized(const ASTContext &C,
151532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                                        unsigned NumCaptures,
15169d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor                                        unsigned NumArrayIndexVars);
1517f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett
151801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine the default capture kind for this lambda.
151901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaCaptureDefault getCaptureDefault() const {
152001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return static_cast<LambdaCaptureDefault>(CaptureDefault);
152101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
152201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1523f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett  /// \brief Retrieve the location of this lambda's capture-default, if any.
1524f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett  SourceLocation getCaptureDefaultLoc() const {
1525f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett    return CaptureDefaultLoc;
1526f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett  }
1527f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett
152801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief An iterator that walks over the captures of the lambda,
152901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// both implicit and explicit.
153001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef const Capture *capture_iterator;
153101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
153201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first lambda capture.
1533da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_begin() const;
153401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
153501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the
153601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// sequence of lambda captures.
1537da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_end() const;
153801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
15397ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Determine the number of captures in this lambda.
15407ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned capture_size() const { return NumCaptures; }
15417ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
154201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first explicit
154301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1544da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_begin() const;
154501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
154601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
154701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// explicit lambda captures.
1548da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_end() const;
154901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
155001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first implicit
155101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1552da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_begin() const;
155301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
155401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
155501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit lambda captures.
1556da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_end() const;
155701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
155801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Iterator that walks over the capture initialization
155901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// arguments.
156001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef Expr **capture_init_iterator;
156101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
156201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the first initialization argument for this
156301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression (which initializes the first capture field).
15647ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_begin() const {
15657ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Expr **>(getStoredStmts());
15667ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
156701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
156801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the iterator pointing one past the last
156976e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  /// initialization argument for this lambda expression.
15707ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_end() const {
15717ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return capture_init_begin() + NumCaptures;
15727ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
157301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
15740d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  /// \brief Retrieve the initializer for an init-capture.
15750d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  Expr *getInitCaptureInit(capture_iterator Capture) {
15760d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    assert(Capture >= explicit_capture_begin() &&
15770d8e9646bc000bab521ce52ed294209a92298cefRichard Smith           Capture <= explicit_capture_end() && Capture->isInitCapture());
15780d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    return capture_init_begin()[Capture - capture_begin()];
15790d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  }
15800d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  const Expr *getInitCaptureInit(capture_iterator Capture) const {
15810d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    return const_cast<LambdaExpr*>(this)->getInitCaptureInit(Capture);
15820d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  }
15830d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
15849daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Retrieve the set of index variables used in the capture
15859daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// initializer of an array captured by copy.
15869daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ///
15879daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \param Iter The iterator that points at the capture initializer for
15889daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// which we are extracting the corresponding index variables.
15899daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
15909daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
159101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the source range covering the lambda introducer,
159201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// which contains the explicit capture list surrounded by square
159301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// brackets ([...]).
159401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange getIntroducerRange() const { return IntroducerRange; }
159501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1596010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieve the class that corresponds to the lambda.
1597010bfc253050626435f006386c0bee4b55329687James Dennett  ///
1598010bfc253050626435f006386c0bee4b55329687James Dennett  /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the
1599010bfc253050626435f006386c0bee4b55329687James Dennett  /// captures in its fields and provides the various operations permitted
1600010bfc253050626435f006386c0bee4b55329687James Dennett  /// on a lambda (copying, calling).
160101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXRecordDecl *getLambdaClass() const;
160201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
160301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the function call operator associated with this
160401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression.
160501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXMethodDecl *getCallOperator() const;
160601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1607ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali  /// \brief If this is a generic lambda expression, retrieve the template
1608ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali  /// parameter list associated with it, or else return null.
1609ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali  TemplateParameterList *getTemplateParameterList() const;
1610ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali
1611ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali  /// \brief Whether this is a generic lambda.
1612ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali  bool isGenericLambda() const { return !!getTemplateParameterList(); }
1613ecb5819a9e64fb654d46a3b270a286cc570c58ffFaisal Vali
161401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the body of the lambda.
16159d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  CompoundStmt *getBody() const;
161601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
161701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether the lambda is mutable, meaning that any
161801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// captures values can be modified.
161901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool isMutable() const;
162001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
162101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether this lambda has an explicit parameter
162201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// list vs. an implicit (empty) parameter list.
162301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool hasExplicitParameters() const { return ExplicitParams; }
162401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1625dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had its result type explicitly specified.
1626dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  bool hasExplicitResultType() const { return ExplicitResultType; }
16279e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor
162801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const Stmt *T) {
162901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return T->getStmtClass() == LambdaExprClass;
163001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
163101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
163265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
163365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return IntroducerRange.getBegin();
163401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
163565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
163601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
16377ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  child_range children() {
16387ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
16397ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
164001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
164101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtReader;
164201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtWriter;
164301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor};
164401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1645010bfc253050626435f006386c0bee4b55329687James Dennett/// An expression "T()" which creates a value-initialized rvalue of type
1646010bfc253050626435f006386c0bee4b55329687James Dennett/// T, which is a non-class type.  See (C++98 [5.2.3p2]).
1647ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
1648987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1649ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
1650987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1651ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
1652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1653987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
1654ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Create an explicitly-written scalar-value initialization
1655ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
1656ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
1657ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
1658ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
1659f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1660561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false, Type->isInstantiationDependentType(), false),
1661ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1662ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1663ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1664ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1666ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1667ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
16684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1670ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
16714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
167265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
167365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1676ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1677987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1679987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
168063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1681987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1682987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1683010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a new-expression for memory allocation and constructor
1684010bfc253050626435f006386c0bee4b55329687James Dennett/// calls, e.g: "new CXXNewExpr(foo)".
16854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
1686010bfc253050626435f006386c0bee4b55329687James Dennett  /// Contains an optional array size expression, an optional initialization
1687010bfc253050626435f006386c0bee4b55329687James Dennett  /// expression, and any number of optional placement arguments, in that order.
16884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
16890982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the allocation function used.
16904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
16910982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the deallocation function used in case of error. May be
16920982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// null.
16934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
16944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16951bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
16961bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
1697ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief If the allocated type was expressed as a parenthesized type-id,
16994bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
17004bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
1701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1702530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  /// \brief Range of the entire new expression.
1703530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceRange Range;
17042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
17052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Source-range of a paren-delimited initializer.
17062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange DirectInitRange;
17074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1708010bfc253050626435f006386c0bee4b55329687James Dennett  /// Was the usage ::new, i.e. is the global new to be used?
1709d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool GlobalNew : 1;
1710010bfc253050626435f006386c0bee4b55329687James Dennett  /// Do we allocate an array? If so, the first SubExpr is the size expression.
1711d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool Array : 1;
1712010bfc253050626435f006386c0bee4b55329687James Dennett  /// If this is an array allocation, does the usual deallocation
1713010bfc253050626435f006386c0bee4b55329687James Dennett  /// function for the allocated type want to know the allocated size?
1714d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool UsualArrayDeleteWantsSize : 1;
1715010bfc253050626435f006386c0bee4b55329687James Dennett  /// The number of placement new arguments.
1716d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned NumPlacementArgs : 13;
1717010bfc253050626435f006386c0bee4b55329687James Dennett  /// What kind of initializer do we have? Could be none, parens, or braces.
1718010bfc253050626435f006386c0bee4b55329687James Dennett  /// In storage, we distinguish between "none, and no initializer expr", and
1719010bfc253050626435f006386c0bee4b55329687James Dennett  /// "none, but an implicit initializer expr".
1720d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned StoredInitializationStyle : 2;
1721d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
172260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
17232aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  friend class ASTStmtWriter;
17244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
17252aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  enum InitializationStyle {
17262aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    NoInit,   ///< New-expression has no initializer as written.
17272aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    CallInit, ///< New-expression has a C++98 paren-delimited initializer.
17282aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    ListInit  ///< New-expression has a C++11 list-initializer.
17292aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  };
17302aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
173132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXNewExpr(const ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
17321548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
17333b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer             ArrayRef<Expr*> placementArgs,
17342aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceRange typeIdParens, Expr *arraySize,
17352aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             InitializationStyle initializationStyle, Expr *initializer,
17366ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1737530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie             SourceRange Range, SourceRange directInitRange);
17385921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
17395921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
17405921863d8f24084797863b5df37842113bac4352Chris Lattner
174132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  void AllocateArgsArray(const ASTContext &C, bool isArray,
174232b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                         unsigned numPlaceArgs, bool hasInitializer);
1743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1744cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1745cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
17466217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1747cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
17484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17491bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
17501bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
17511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1752c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1753c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1754010bfc253050626435f006386c0bee4b55329687James Dennett  ///
1755010bfc253050626435f006386c0bee4b55329687James Dennett  /// C++11 [expr.new]p13:
1756c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1757c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1758c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1759010bfc253050626435f006386c0bee4b55329687James Dennett  ///
1760c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1761c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1762c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1763c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
176432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  bool shouldNullCheckAllocation(const ASTContext &Ctx) const;
1765ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
17675921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
17684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
17695921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
17704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1771cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1772cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1773cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1774cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1775cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1776cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1777cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1778cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
17794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1780ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr **getPlacementArgs() {
17812aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1782aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
17854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
17862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return getPlacementArgs()[i];
17874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
17884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
17894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
17902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
17914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
17924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17934bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
17944bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
17954bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
17964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
17977cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
17982aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Whether this new-expression has any initializer at all.
17992aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool hasInitializer() const { return StoredInitializationStyle > 0; }
18001548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
18012aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The kind of initializer this new-expression has.
18022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  InitializationStyle getInitializationStyle() const {
18032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    if (StoredInitializationStyle == 0)
18042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl      return NoInit;
18052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return static_cast<InitializationStyle>(StoredInitializationStyle-1);
18061548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
18071548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
18082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The initializer of this new-expression.
18092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  Expr *getInitializer() {
18102aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
18111548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
18122aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const Expr *getInitializer() const {
18132aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
18141548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
18151548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
1816010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Returns the CXXConstructExpr from this new-expression, or null.
181788920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky  const CXXConstructExpr* getConstructExpr() const {
1818feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay    return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1819feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay  }
1820feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay
18212aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// Answers whether the usual array deallocation function for the
18222aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// allocated type expects the size of the allocation as a
18232aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// parameter.
18242aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool doesUsualArrayDeleteWantSize() const {
18252aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return UsualArrayDeleteWantsSize;
18262aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
18271548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
18284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
18294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
18304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
18314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
18322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
18334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
18344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
18352aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
18364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
18374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
18382aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
18394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
18404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
18412aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
18424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
1843ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18445921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
18455921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
18465921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
18472aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
18485921863d8f24084797863b5df37842113bac4352Chris Lattner  }
18495921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
18502aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const_arg_iterator raw_arg_end() const {
18512aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
18522aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
18534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1854530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceLocation getStartLoc() const { return Range.getBegin(); }
1855530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceLocation getEndLoc() const { return Range.getEnd(); }
1856428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
18572aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange getDirectInitRange() const { return DirectInitRange; }
1858428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1859aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1860530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie    return Range;
18614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
186265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
186365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
18644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
18654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
18664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
18674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
18684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
18694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
187063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
18712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return child_range(raw_arg_begin(), raw_arg_end());
187263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
18734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
18744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
18750982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a \c delete expression for memory deallocation and
18760982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// destructor calls, e.g. "delete[] pArray".
18774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
1878010bfc253050626435f006386c0bee4b55329687James Dennett  /// Points to the operator delete overload that is used. Could be a member.
1879d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  FunctionDecl *OperatorDelete;
1880010bfc253050626435f006386c0bee4b55329687James Dennett  /// The pointer expression to be deleted.
1881d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Argument;
1882010bfc253050626435f006386c0bee4b55329687James Dennett  /// Location of the expression.
1883d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  SourceLocation Loc;
1884010bfc253050626435f006386c0bee4b55329687James Dennett  /// Is this a forced global delete, i.e. "::delete"?
18854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
1886010bfc253050626435f006386c0bee4b55329687James Dennett  /// Is this the array form of delete, i.e. "delete[]"?
18874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
1888010bfc253050626435f006386c0bee4b55329687James Dennett  /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1889010bfc253050626435f006386c0bee4b55329687James Dennett  /// to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1890010bfc253050626435f006386c0bee4b55329687James Dennett  /// will be true).
18914076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
1892010bfc253050626435f006386c0bee4b55329687James Dennett  /// Does the usual deallocation function for the element type require
1893010bfc253050626435f006386c0bee4b55329687James Dennett  /// a size_t argument?
18946ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
18954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
18964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
18976ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
18986ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1899bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1900561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           arg->isInstantiationDependent(),
1901bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1902d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1903f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
19044076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1905d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
190695fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
190795fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
19084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
19104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
19114076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
19124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19136ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
19146ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
19156ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
19166ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
19176ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
19186ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
19196ec278d1a354517e20f13a877481453ee7940c78John McCall  }
19206ec278d1a354517e20f13a877481453ee7940c78John McCall
19214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
19224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
19244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
19254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1926010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieve the type being destroyed.
1927010bfc253050626435f006386c0bee4b55329687James Dennett  ///
1928010bfc253050626435f006386c0bee4b55329687James Dennett  /// If the type being destroyed is a dependent type which may or may not
1929010bfc253050626435f006386c0bee4b55329687James Dennett  /// be a pointer, return an invalid type.
19305833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
1931ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
193265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
193365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
19344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
19364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
19374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
19384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
194063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1941f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1942f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
19434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
19444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
19450982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Stores the type being destroyed by a pseudo-destructor expression.
1946a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Either the type source information or the name of the type, if
1948a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1949a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1950ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1951a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1952a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1953ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1954a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1955a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1957a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1958a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1959ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1960a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1961ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1962ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getTypeSourceInfo() const {
1963ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return Type.dyn_cast<TypeSourceInfo *>();
1964a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1965ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1966a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1967a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1968a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1969ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1970a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1971a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1972ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1973a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1974a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1975e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1976ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have
1977e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1978e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1979e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1980e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1981e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1982e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1983e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1984e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1985a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1986e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1987ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///
1988a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
19891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1990a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1991e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1992a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1993a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1994a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1995e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1996e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1997a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1998a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1999a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2001a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
2002a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
2003a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
20041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2005a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
2006a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
2007ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2008a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
2009f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2011e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
2012e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
2013e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
2014ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2015ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The location of the '::' in a qualified pseudo-destructor
2016e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
2017e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
2018ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2019fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
2020fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
2021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The type being destroyed, or its name if we were unable to
2023a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
2024a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2026f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
2027ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2028a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
202932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXPseudoDestructorExpr(const ASTContext &Context,
2030a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
2031f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
2032e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
2033e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
2034fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
2035e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
20361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2037de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
2038de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
2039f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
2040de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
2041a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
2044a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2045a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
20467247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
20471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2048f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
2049f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
2050f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2051ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
2053a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
2054010bfc253050626435f006386c0bee4b55329687James Dennett  /// null.
2055ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2056ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
2057f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2059a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
2060a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
2061a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
2062a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
2063a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
2064a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2066ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the scope type in a qualified pseudo-destructor
2067e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
2068e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
2069e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
2070e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
2071e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
2072ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \p T may also be a scalar type and, therefore, cannot be part of a
2073e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
2074e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
207526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
2076ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2077e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
2078e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
2079e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
2080ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2081fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
2082fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
2083ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
208426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
208526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
2086a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
2087ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This type-source information is available for non-dependent
2088a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
2089010bfc253050626435f006386c0bee4b55329687James Dennett  /// expressions. Returns null if we only have the identifier for a
2090a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
2091ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getDestroyedTypeInfo() const {
2092ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getTypeSourceInfo();
2093a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
2094ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2095a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
2096a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
2097a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
2098a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
2099a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
2100a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
2101ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2102a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
2103a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
2104ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2105a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
2106ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SourceLocation getDestroyedTypeLoc() const {
2107ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getLocation();
2108a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
21091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2110de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
2111de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
2112de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
2113de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
2114de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
2115de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
2116de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
2117de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
2118de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
2119de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
2120de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
212165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
212265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
21231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2125a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
2126a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2128a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
212963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
2130a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21320982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS unary type trait, as used in the
21330982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
21340982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
213564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
2136010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
21370982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_pod(int) == true
21380982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_enum(std::string) == false
2139010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
214064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
2141010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The trait. A UnaryTypeTrait enum in MSVC compatible unsigned.
21420dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
21430dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
21440dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
214564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
2146010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The location of the type trait keyword.
214764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
214864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
2149010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The location of the closing paren.
215064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
215164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
2152010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The type being queried.
21533d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
215464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
215564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
2156ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
21570dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
215864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
2159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2160bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
2161561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->getType()->isInstantiationDependentType(),
2162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
21630dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
216464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
21656d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
21660dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
21673d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
21686d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
216965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
217065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
217164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
21720dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
217364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
21743d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
217564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
21763d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2177ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
21780dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
217964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
218064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
218164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
218264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
218364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
218464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
218563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
21866d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
218760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
218864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
218964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
21900982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS binary type trait, as used in the
21910982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
21920982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
21936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
2194010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
21950982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_base_of(Base, Derived) == true
2196010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
21976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
2198010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The trait. A BinaryTypeTrait enum in MSVC compatible unsigned.
21996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
22006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
22026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
22036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
2204010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The location of the type trait keyword.
22056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
22066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
2207010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The location of the closing paren.
22086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
22096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
2210010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The lhs type being queried.
22116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
22126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
2213010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The rhs type being queried.
22146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
22156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
2217ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
2218ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
22196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
2220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
22216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
2222bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
2223561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhsType->getType()->isInstantiationDependentType() ||
2224561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhsType->getType()->isInstantiationDependentType()),
2225bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
2226bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
22276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
22286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
22296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
22326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
2233f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
22346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
223565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
223665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
22376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
22396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
22406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
22416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
22436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
22446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
22466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
2247ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
22486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
22496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
22516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
22526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
22536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
225563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
22566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
22586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
22596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
22604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and
22614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates.
22624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///
22634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code
22644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///   __is_trivially_constructible(vector<int>, int*, int*)
22654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode
22664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr {
22674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief The location of the type trait keyword.
22684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation Loc;
22694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief  The location of the closing parenthesis.
22714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation RParenLoc;
22724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Note: The TypeSourceInfos for the arguments are allocated after the
22744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // TypeTraitExpr.
22754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
22774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                ArrayRef<TypeSourceInfo *> Args,
22784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                SourceLocation RParenLoc,
22794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                bool Value);
22804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
22824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
22844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo **getTypeSourceInfos() {
22854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo **>(this+1);
22864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
22874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
22894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo * const *getTypeSourceInfos() const {
22904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo * const*>(this+1);
22914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
22924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
22934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic:
22944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Create a new type trait expression.
229532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static TypeTraitExpr *Create(const ASTContext &C, QualType T,
229632b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                               SourceLocation Loc, TypeTrait Kind,
22974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               ArrayRef<TypeSourceInfo *> Args,
22984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               SourceLocation RParenLoc,
22994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               bool Value);
23004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
230132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static TypeTraitExpr *CreateDeserialized(const ASTContext &C,
230232b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                                           unsigned NumArgs);
23034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine which type trait this expression uses.
23054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTrait getTrait() const {
23064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
23074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  bool getValue() const {
23104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(!isValueDependent());
23114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return TypeTraitExprBits.Value;
23124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine the number of arguments to this type trait.
23154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
23164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the Ith argument.
23184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo *getArg(unsigned I) const {
23194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(I < getNumArgs() && "Argument out-of-range");
23204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getArgs()[I];
23214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
23244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ArrayRef<TypeSourceInfo *> getArgs() const {
23254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
23264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo **arg_iterator;
23294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_begin() {
23304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos();
23314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_end() {
23334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
23344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo const * const *arg_const_iterator;
23374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
23384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_end() const {
23394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
23404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
234265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
234365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
234465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
23454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const Stmt *T) {
23464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return T->getStmtClass() == TypeTraitExprClass;
23474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
23484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Iterators
23504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  child_range children() { return child_range(); }
23514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtReader;
23534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
23544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor};
23564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
23570982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An Embarcadero array type trait, as used in the implementation of
23580982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank and __array_extent.
23590982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
236021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example:
2361010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
23620982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_rank(int[10][20]) == 2
23630982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_extent(int, 1)    == 20
2364010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
236521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr {
236699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
236799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
23680982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
236921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  unsigned ATT : 2;
237021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
23710982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
237221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t Value;
237321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
23740982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The array dimension being queried, or -1 if not used.
237521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *Dimension;
237621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
23770982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
237821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation Loc;
237921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
23800982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
238121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation RParen;
238221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
23830982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The type being queried.
238421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *QueriedType;
238521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
238621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic:
238721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
238821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     TypeSourceInfo *queried, uint64_t value,
238921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     Expr *dimension, SourceLocation rparen, QualType ty)
239021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
239121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           false, queried->getType()->isDependentType(),
2392561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (queried->getType()->isInstantiationDependentType() ||
2393561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            (dimension && dimension->isInstantiationDependent())),
239421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           queried->getType()->containsUnexpandedParameterPack()),
239521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      ATT(att), Value(value), Dimension(dimension),
239621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      Loc(loc), RParen(rparen), QueriedType(queried) { }
239721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
239821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
239921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  explicit ArrayTypeTraitExpr(EmptyShell Empty)
240021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
240121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      QueriedType() { }
240221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
240325aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek  virtual ~ArrayTypeTraitExpr() { }
240425aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek
240565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
240665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
240721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
240821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
240921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
241021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  QualType getQueriedType() const { return QueriedType->getType(); }
241121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
241221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
241321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
241421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
241521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
241621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *getDimensionExpression() const { return Dimension; }
241721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
241821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const Stmt *T) {
241921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return T->getStmtClass() == ArrayTypeTraitExprClass;
242021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
242121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
242221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Iterators
242321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  child_range children() { return child_range(); }
242421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
242521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  friend class ASTStmtReader;
242621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley};
242721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
24280982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An expression trait intrinsic.
24290982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
2430552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example:
2431010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
24320982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(std::cout) == true
24330982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(1) == false
2434010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
2435552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr {
2436010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The trait. A ExpressionTrait enum in MSVC compatible unsigned.
2437552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  unsigned ET : 31;
24380982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
2439552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool Value : 1;
2440552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
24410982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
2442552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation Loc;
2443552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
24440982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
2445552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation RParen;
2446552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
24470982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The expression being queried.
2448552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr* QueriedExpression;
2449552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic:
2450ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2451552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     Expr *queried, bool value,
2452552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     SourceLocation rparen, QualType resultType)
2453552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2454552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           false, // Not type-dependent
2455552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           // Value-dependent if the argument is type-dependent.
2456552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->isTypeDependent(),
2457561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->isInstantiationDependent(),
2458552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->containsUnexpandedParameterPack()),
2459ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      ET(et), Value(value), Loc(loc), RParen(rparen),
2460ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      QueriedExpression(queried) { }
2461552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2462552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  explicit ExpressionTraitExpr(EmptyShell Empty)
2463552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2464552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      QueriedExpression() { }
2465552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
246665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
246765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2468552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2469552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2470552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2471552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr *getQueriedExpression() const { return QueriedExpression; }
2472552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2473552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool getValue() const { return Value; }
2474552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2475552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const Stmt *T) {
2476552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return T->getStmtClass() == ExpressionTraitExprClass;
2477552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
2478552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2479552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  // Iterators
2480552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  child_range children() { return child_range(); }
2481552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2482552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  friend class ASTStmtReader;
2483552622067dc45013d240f73952fece703f5e63bdJohn Wiegley};
2484552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2485552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
24867bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
2487809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
24887bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
24890982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The common name of these declarations.
2490d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  DeclarationNameInfo NameInfo;
2491d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2492d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  /// \brief The nested-name-specifier that qualifies the name, if any.
2493d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  NestedNameSpecifierLoc QualifierLoc;
2494d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2495ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
24967bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
24977bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
2498928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
2499928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
2500928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
2501ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2502a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
2503e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2504e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2505e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2506e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2507e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2508e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2509e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2510e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2511e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2512e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2513e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
25147bb12da2b0749eeebb21854c77877736969e59f2John McCall
251532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  OverloadExpr(StmtClass K, const ASTContext &C,
25164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
2517e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara               SourceLocation TemplateKWLoc,
25182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
2519bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
2520bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2521561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownDependent,
2522561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownInstantiationDependent,
2523561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownContainsUnexpandedParameterPack);
25247bb12da2b0749eeebb21854c77877736969e59f2John McCall
2525a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
2526d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer    : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2527d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      HasTemplateKWAndArgsInfo(false) { }
2528a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
252932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  void initializeResults(const ASTContext &C,
2530bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
2531bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
25327bb12da2b0749eeebb21854c77877736969e59f2John McCall
2533bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
25349c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
25359c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
25369c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
25379c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
25389c72c6088d591ace8503b842d39448c2040f3033John McCall  };
25399c72c6088d591ace8503b842d39448c2040f3033John McCall
2540010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Finds the overloaded expression in the given expression \p E of
25417bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
25427bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
25439c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
25449c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
25459c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
25467bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
25477bb12da2b0749eeebb21854c77877736969e59f2John McCall
25489c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
25499c72c6088d591ace8503b842d39448c2040f3033John McCall
25507bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
25519c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
25529c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
25539c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
25549c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
25559c72c6088d591ace8503b842d39448c2040f3033John McCall
25569c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
25579c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
25589c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
25599c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
25609c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
25619c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
25629c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
25639c72c6088d591ace8503b842d39448c2040f3033John McCall    }
25649c72c6088d591ace8503b842d39448c2040f3033John McCall
25659c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
25667bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
25677bb12da2b0749eeebb21854c77877736969e59f2John McCall
25680982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the naming class of this lookup, if any.
2569e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
2570e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
25717bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
2572928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  decls_iterator decls_end() const {
2574928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
2575928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
2576ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
25770982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the number of declarations in the unresolved set.
2578928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
25797bb12da2b0749eeebb21854c77877736969e59f2John McCall
25800982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the full name info.
25812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
25822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
25830982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the name looked up.
25842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
25857bb12da2b0749eeebb21854c77877736969e59f2John McCall
25860982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the location of the name.
25872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
25887bb12da2b0749eeebb21854c77877736969e59f2John McCall
25890982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier, if one was given.
2590ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2591ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
25924c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
25937bb12da2b0749eeebb21854c77877736969e59f2John McCall
25940982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier with source-location
25950982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// information, if one was given.
25964c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
25977bb12da2b0749eeebb21854c77877736969e59f2John McCall
2598e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2599e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2600e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2601e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2602e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2603e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2604e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2605e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2606e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2607e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2608e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2609e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2610e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2611e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2612e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2613e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2614e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2615e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2616e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2617e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
26187bb12da2b0749eeebb21854c77877736969e59f2John McCall
26190982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether the name was preceded by the template keyword.
2620e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2621e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
26220982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether this expression had explicit template arguments.
2623e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2624e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2625e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // Note that, inconsistently with the explicit-template-argument AST
2626e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // nodes, users are *forbidden* from calling these methods on objects
2627e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // without explicit template arguments.
2628e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2629e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2630e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
2631e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
2632e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
26337bb12da2b0749eeebb21854c77877736969e59f2John McCall
2634b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
26357bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
26367bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
26377bb12da2b0749eeebb21854c77877736969e59f2John McCall
2638e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  TemplateArgumentLoc const *getTemplateArgs() const {
2639e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().getTemplateArgs();
2640e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2641e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2642e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  unsigned getNumTemplateArgs() const {
2643e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().NumTemplateArgs;
2644e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2645e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
26460982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Copies the template arguments into the given structure.
2647e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2648e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    getExplicitTemplateArgs().copyInto(List);
2649e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2650e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2651096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
26520982205bade2fb4fc984c27b2ab401e683963b10James Dennett  ///
2653096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2654096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
26557d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2656096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2657096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
26587bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
26597bb12da2b0749eeebb21854c77877736969e59f2John McCall
26607bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
26617bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
26627bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
26637bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
26644045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
26654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
26664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
26677bb12da2b0749eeebb21854c77877736969e59f2John McCall};
26687bb12da2b0749eeebb21854c77877736969e59f2John McCall
26697bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
26700982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// parsing but could not resolve to a specific declaration.
26710982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
26720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// This arises in several ways:
2673010bfc253050626435f006386c0bee4b55329687James Dennett///   * we might be waiting for argument-dependent lookup;
2674010bfc253050626435f006386c0bee4b55329687James Dennett///   * the name might resolve to an overloaded function;
26757bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
2676010bfc253050626435f006386c0bee4b55329687James Dennett///   * the lookup might have included a function template.
2677010bfc253050626435f006386c0bee4b55329687James Dennett///
26780982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// These never include UnresolvedUsingValueDecls, which are always class
26790982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// members and therefore appear only in UnresolvedMemberLookupExprs.
26807bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
2681ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
2682ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
2683ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
2684ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
2685ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
26867453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
26877453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
26887453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
26897453ed4cb2cab113de3378df371b1c6f1243d832John McCall
26907bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
26917bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
26927bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
26937bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
26947bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
26957bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
2696f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
269732b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  UnresolvedLookupExpr(const ASTContext &C,
2698928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
26994c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
2700e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
27012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
2702ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                       bool RequiresADL, bool Overloaded,
2703bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
2704b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2705e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2706e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                   NameInfo, TemplateArgs, Begin, End, false, false, false),
2707ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(RequiresADL),
2708ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Overloaded(Overloaded), NamingClass(NamingClass)
2709ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
2710ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2711bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
2712bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
2713b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith      RequiresADL(false), Overloaded(false), NamingClass(0)
2714bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
2715bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
27164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
2717ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2718ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
271932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static UnresolvedLookupExpr *Create(const ASTContext &C,
2720c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
27214c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
27222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
27235a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
2724ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
2725b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                                      UnresolvedSetIterator End) {
2726e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2727e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SourceLocation(), NameInfo,
2728b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                                       ADL, Overloaded, 0, Begin, End);
2729ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2730ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
273132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static UnresolvedLookupExpr *Create(const ASTContext &C,
2732c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
27334c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
2734e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                      SourceLocation TemplateKWLoc,
27352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
2736f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
27379d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                      const TemplateArgumentListInfo *Args,
2738ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
27395a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
2740f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
274132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static UnresolvedLookupExpr *CreateEmpty(const ASTContext &C,
2742e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           bool HasTemplateKWAndArgsInfo,
2743bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
2744bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
2745ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
2746ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
2747ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
2748ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
27497453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
27507453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
27517453ed4cb2cab113de3378df371b1c6f1243d832John McCall
2752c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
2753c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
2754c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
2755c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
2756c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
275765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
275865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (NestedNameSpecifierLoc l = getQualifierLoc())
275965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return l.getBeginLoc();
276065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getNameInfo().getLocStart();
276165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
276265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
2763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (hasExplicitTemplateArgs())
276465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
276565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getNameInfo().getLocEnd();
2766ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2767ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
276863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2769ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2770ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
2771ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
2772ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2773ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
2774ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
27755953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
27765953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
27775953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
2778ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2779a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
27805953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
2781865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
27825953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
27835953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
27845953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
2785865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2786ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
2787a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2788a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
2789865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
2790ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
2791ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
279200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
2793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2794010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The name of the entity we will be referencing.
279500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
27965953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
2797e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2798e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2799e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2800e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2801e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2802e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2803e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2804e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2805e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2806e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2807e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2808e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<DependentScopeDeclRefExpr*>(this)
2809e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2810e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2812f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
281300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
2814e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                            SourceLocation TemplateKWLoc,
28152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
2816bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
2817f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2818f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
281932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static DependentScopeDeclRefExpr *Create(const ASTContext &C,
282000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2821e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           SourceLocation TemplateKWLoc,
28222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
2823e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                              const TemplateArgumentListInfo *TemplateArgs);
28245953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
282532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &C,
2826e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                bool HasTemplateKWAndArgsInfo,
282712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
282812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
28295953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
28302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
28312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
28322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
28332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
28345953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
28355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
28362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
28375953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
283800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
283900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
284000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2841ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2842ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2843ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
2844ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
2845ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2846ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
284700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
28481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2849e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2850e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2851e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2852e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2853e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2854e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2855e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2856e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2857e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2858e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2859e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2860e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2861e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2862e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2863e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2864e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2865e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2866e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2867e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2868e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2869e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2870e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the name was preceded by the template keyword.
2871e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2872e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2873f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
2874e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
28751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2876f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
2877f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
2878f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2880b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
288112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
2882b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
288312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
288412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
2885f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
2886b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2887f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
2888b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2889f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2891096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2892010bfc253050626435f006386c0bee4b55329687James Dennett  ///
2893096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2894096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
28957d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2896096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2897096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2898096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2899096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2900f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
2901f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
2902f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2903f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
2904f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
2905ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2906f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
2907f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2908d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2909d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2910f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
2911f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2912f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
29131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
291465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
291565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return QualifierLoc.getBeginLoc();
291665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
291765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
2918f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
291965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
292065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getLocation();
2921edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
29221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2924f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2925edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
2926f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
292763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
29284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
29294045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
29304045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
2931edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2933010bfc253050626435f006386c0bee4b55329687James Dennett/// Represents an expression -- generally a full-expression -- that
29344765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
29354765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
293680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of
293780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every
293880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer.
293980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall///
294080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a
294180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal.  The lifetime of a block
294280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope.
29434765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
294480ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic:
294580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// The type of objects that are kept in the cleanup.
294680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// It's useful to remember the set of blocks;  we could also
294780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// remember the set of temporaries, but there's currently
294880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// no need.
294980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  typedef BlockDecl *CleanupObject;
295080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
295180ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate:
295202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
29531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
295480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(EmptyShell, unsigned NumObjects);
295580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
295602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
295780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject *getObjectsBuffer() {
295880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<CleanupObject*>(this + 1);
295980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
296080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  const CleanupObject *getObjectsBuffer() const {
296180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<const CleanupObject*>(this + 1);
296280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
296380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  friend class ASTStmtReader;
2964ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
296588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
296632b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty,
296780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  unsigned numObjects);
29681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
296932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr,
297080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  ArrayRef<CleanupObject> objects);
2971ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
297280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ArrayRef<CleanupObject> getObjects() const {
297380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2974f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
297580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
297680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
297780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
297880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject getObject(unsigned i) const {
297980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    assert(i < getNumObjects() && "Index out of range");
298080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return getObjects()[i];
2981d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
298302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2984f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
298580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
2986010bfc253050626435f006386c0bee4b55329687James Dennett  /// As with any mutator of the AST, be very careful
298780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// when modifying an existing AST to preserve its invariants.
298888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
298902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
299065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
299165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExpr->getLocStart();
299296be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
299365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
299402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
299502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
299602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
29974765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
299802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
299902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
300002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
300163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
300202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
300302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
3004d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
3005d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
3006d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
3007d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
3008d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
3009fe865f1f35d1b91f42f58f08a1399b961b71b3bcJames Dennett/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
30100982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
30110982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
3012d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
3013d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
3014d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
3015d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
3016d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
3017d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
3018d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
3019d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
3020d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
3021d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
3022d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
3023d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
3024d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
3025d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
3026d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
3027ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
3028ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3029d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
3030d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
3031d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3032d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
3033d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
3034d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3035d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
3036d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
30371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3038ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
3039d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
30403b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                             ArrayRef<Expr*> Args,
3041d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
3042d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
30438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
3044ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
30458dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
3046ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
3047ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3048d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
304932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXUnresolvedConstructExpr *Create(const ASTContext &C,
3050ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
3051d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
30523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                            ArrayRef<Expr*> Args,
3053d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
3054d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
305532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &C,
30568dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
30578dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
3058d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
3059d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
3060ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
3061d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3062ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the type source information for the type being
3063ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
3064ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
3065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3066d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
3067d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
3068d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
3069d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3070d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3071d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
3072d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
3073d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3074d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3075d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3076d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
3077d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
3078d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3079d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
3080d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
3081d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
3082d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
30831dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
30841dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
30851dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
30861dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
30871dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
30881dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
30891dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
30901dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
3091d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
3092d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
3093d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
3094d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
3095d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
30961dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
30971dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
30981dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
30991dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
31001dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
31018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
31028dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
31038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
31048dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
31058dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
310665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
3107bd9cbd22b832ce65a085801259cf2d3df77830e4Enea Zaffanella  SourceLocation getLocEnd() const LLVM_READONLY {
3108bd9cbd22b832ce65a085801259cf2d3df77830e4Enea Zaffanella    assert(RParenLoc.isValid() || NumArgs == 1);
3109bd9cbd22b832ce65a085801259cf2d3df77830e4Enea Zaffanella    return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd();
3110bd9cbd22b832ce65a085801259cf2d3df77830e4Enea Zaffanella  }
3111ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
31121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3113d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
3114d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
3115d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3116d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
311763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
311863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
311963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
312063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3121d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
3122d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
3123ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
3124ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
3125ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
3126aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3127aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
3128aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
3129aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
3130865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
31311c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
3132aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
31331c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
31341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3135aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
3136aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
3137aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
3138aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
31391c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
31401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
31413b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
31421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3143e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether this member expression has info for explicit template
3144e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
3145e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo : 1;
31461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31471c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
31481c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
31491c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3150a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
31517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
31521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3153c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
31541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
3155c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
3156c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
315746bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
3158c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
3159865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
3160c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
31611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
31631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
3164010bfc253050626435f006386c0bee4b55329687James Dennett  ///
3165a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
31662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
31671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3168e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
3169e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
3170e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
3171e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
3172e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3173e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
3174e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
3175e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<CXXDependentScopeMemberExpr*>(this)
3176e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
3177e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3178e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
317932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
318032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              QualType BaseType, bool IsArrow,
318132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              SourceLocation OperatorLoc,
318232b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              NestedNameSpecifierLoc QualifierLoc,
318332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              SourceLocation TemplateKWLoc,
318432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              NamedDecl *FirstQualifierFoundInScope,
318532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              DeclarationNameInfo MemberNameInfo,
318632b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              const TemplateArgumentListInfo *TemplateArgs);
31871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
318932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CXXDependentScopeMemberExpr(const ASTContext &C, Expr *Base,
319032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper                              QualType BaseType, bool IsArrow,
3191bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
31927c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
3193bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
3194bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
31951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3196865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
319732b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  Create(const ASTContext &C, Expr *Base, QualType BaseType, bool IsArrow,
319832b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper         SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
319932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper         SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
32002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
3201d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
320432b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3205def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
32068dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
3207aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
3208aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
3209aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
32104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3211aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
32121c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
32131c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
3214aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
3215aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3216aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3217aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
32181c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3219aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3220aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
32211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
32221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
32231c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
32241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
32251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
32261c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
32271c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3228a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
3229a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
3230ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
3231ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
32327c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
32331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32347c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
32357c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
32367c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3237ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3238ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3239c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
3240c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
3241c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
3242c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
3243c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
3246c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
3247c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
3248c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
3249c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
32501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
3251c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
3252c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
32531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32541c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
32551c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
32562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
32572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
32582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
32592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
32602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
32612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
32622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
32631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
32641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
32651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
32662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
32671c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3268e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding the
3269e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// member name, if any.
3270e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
3271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3272e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3273e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3274e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3275e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
3276e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3277e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
3278e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
3280e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3281e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3282e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
3283e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3284e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
3285e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3286e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
3287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the member name was preceded by the template keyword.
3290e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3291e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
32923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
32933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
3294e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
329636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
329736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3298b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3299e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
3300b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
330136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
330236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
330336c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
330436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3305b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
330636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
3307096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
3308096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
3309096832c5ed5b9106fa177ebc148489760c3bc496John McCall
3310096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
3311010bfc253050626435f006386c0bee4b55329687James Dennett  ///
3312096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
3313096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
33147d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
3315096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
3316096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
331736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
331836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
3319d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
3320d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
3321d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3322096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
3323d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
3324d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
33258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
33268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3327096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
33288dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
33298dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
33303b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
33313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
3332833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
3333096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
33343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
33351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33363b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
33373b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
33381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
3339096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
33403b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
33411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
334265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
3343aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
334465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return Base->getLocStart();
334565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (getQualifier())
334665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getQualifierLoc().getBeginLoc();
334765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return MemberNameInfo.getBeginLoc();
33481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
334965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
335065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
3351aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
335265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
335365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return MemberNameInfo.getEndLoc();
33541c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
33551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3357865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
33581c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
33591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
33601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
336163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
336263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
336363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
336463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
33654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
33664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
33674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
33681c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
33691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3370129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
3371aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
3372aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3373aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
3374010bfc253050626435f006386c0bee4b55329687James Dennett/// \code
3375aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
3376aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
3377aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
3378aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
3379aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
3380010bfc253050626435f006386c0bee4b55329687James Dennett/// \endcode
3381aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3382aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
3383aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
3384aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
33857bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
3386129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
3387129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
3388129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
3389129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3390129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
3391129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
3392129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
3393129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
33947bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
3395010bfc253050626435f006386c0bee4b55329687James Dennett  /// e.g., the \c x in x.f.
3396010bfc253050626435f006386c0bee4b55329687James Dennett  ///
3397010bfc253050626435f006386c0bee4b55329687James Dennett  /// This can be null if this is an 'unbased' member expression.
33987bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
33997bb12da2b0749eeebb21854c77877736969e59f2John McCall
3400010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The type of the base expression; never null.
34017bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
3402129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3403129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
3404129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
3405129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
340632b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  UnresolvedMemberExpr(const ASTContext &C, bool HasUnresolvedUsing,
3407aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
3408129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
34094c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
3410e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
34112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
34125a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
34135a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3415a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
3416a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3417a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
3418129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
34194c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
3420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3421129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
3422129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
342332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  Create(const ASTContext &C, bool HasUnresolvedUsing,
3424aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
3425129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
34264c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
3427e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
34282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
34295a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
34305a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3431129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3432a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
343332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  CreateEmpty(const ASTContext &C, bool HasTemplateKWAndArgsInfo,
3434def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
3435a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3436010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief True if this is an implicit access, i.e., one in which the
3437010bfc253050626435f006386c0bee4b55329687James Dennett  /// member being accessed was not written in the source.
3438010bfc253050626435f006386c0bee4b55329687James Dennett  ///
3439010bfc253050626435f006386c0bee4b55329687James Dennett  /// The source location of the operator is invalid in this case.
34404c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3441aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3442129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
3443129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
3444aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
3445aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3446aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3447aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
34482f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
34492f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
34502f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
34512f27bf854f0519810b34afd209089cc75536b757John McCall  }
3452129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3453aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3454a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3455a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
3456a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
3457a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3458aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3459129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
3460129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
3461129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
3462129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3463129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
3464129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3465129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3466010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Retrieve the naming class of this lookup.
3467c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
3468c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
34692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
34702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
34712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
34722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
3473129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
3474129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
34757bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
3476129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3477129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
3478129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
34797bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
3480129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
348116b0a310f5649d25849d84409841f401e7a9a0e5David Blaikie  // \brief Return the preferred location (the member name) for the arrow when
348216b0a310f5649d25849d84409841f401e7a9a0e5David Blaikie  // diagnosing a problem with this expression.
348316b0a310f5649d25849d84409841f401e7a9a0e5David Blaikie  SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); }
348416b0a310f5649d25849d84409841f401e7a9a0e5David Blaikie
348565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
3486aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
348765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return Base->getLocStart();
348865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (NestedNameSpecifierLoc l = getQualifierLoc())
348965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return l.getBeginLoc();
349065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getMemberNameInfo().getLocStart();
349165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
349265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
3493129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
349465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
349565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getMemberNameInfo().getLocEnd();
3496129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3497129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3498129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
3499129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
3500129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3501129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3502129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
350363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
350463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
350563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
350663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3507129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
3508129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3509010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
35102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
35112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
35122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
35132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
35142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
35152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
35162e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
35172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3518c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
3519c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
35202e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
35212e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
35222e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
3523f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3524f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
3525bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
3526561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Val == CT_Dependent || Operand->isInstantiationDependent(),
3527bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
35286b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
35296b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
35306b219d082434394c1ac401390ec1d1967727815aSebastian Redl
35316b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
35326b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
35332e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
35342e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
35352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
35362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
353765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
353865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3539aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
35402e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
35412e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
35422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
35432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
35442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
35452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
35462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
35472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
354863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
35492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
35502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3551010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a C++11 pack expansion that produces a sequence of
3552be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
3553be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3554be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
3555be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
3556be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3557be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
3558be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
3559be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
3560be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
3561be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
3562be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
3563be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3564be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
3565ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function
3566be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
3567be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
3568be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
3569be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
3570ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
357167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
357267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
357367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
357467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
357567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
357667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
3577ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3578be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
3579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3580be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
358167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
3582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3583be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
358467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3585dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie                    Optional<unsigned> NumExpansions)
3586ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3587ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           Pattern->getObjectKind(), /*TypeDependent=*/true,
3588561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3589561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3590be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
359167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3592be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
3593be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3594be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3596be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3597be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3598be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3599be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3600be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3601be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3602be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
3603be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
3604be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3605ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the number of expansions that will be produced when
360767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
3608dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie  Optional<unsigned> getNumExpansions() const {
360967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
361067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
3611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
361266874fb18afbffb8b2ca05576851a64534be3352David Blaikie    return None;
361367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
3614ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
361565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
361665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Pattern->getLocStart();
361763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
361865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3619be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3620be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
3621be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
3622be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
3623ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3624be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
362563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
362663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
362763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3628be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
3629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3630e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3631e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  if (!HasTemplateKWAndArgsInfo) return 0;
36327bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
3633e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3634e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedLookupExpr>(this) + 1);
36357bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
3636e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3637e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedMemberExpr>(this) + 1);
36387bb12da2b0749eeebb21854c77877736969e59f2John McCall}
36397bb12da2b0749eeebb21854c77877736969e59f2John McCall
3640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter
3641ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
3642ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
3643ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
3644ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
3645ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
3646ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
3647ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
3648ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
3649ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
3650010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief The location of the \c sizeof keyword.
3651ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
3652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3653ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
3654ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
3655ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3656ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
3657ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
3658ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3659ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
3660ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3661ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
3662ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
3663ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
3664ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
3665ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3666ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
3667ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
3668ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3669ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
3670ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
3671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3672ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
3673010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Create a value-dependent expression that computes the length of
3674ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
3675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3676ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
3677ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3678ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
3679561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3680ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3681ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3682ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
3683ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3684010bfc253050626435f006386c0bee4b55329687James Dennett  /// \brief Create an expression that computes the length of
3685ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
3686ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3687ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
3688ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
3689ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3690ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
3691561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         /*InstantiationDependent=*/false,
3692ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
3693ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3694ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
3695ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3696ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
3697ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3699ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
3700ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3701ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3702ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
3703ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
3704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3705ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
3706ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3708ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
3709ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
3710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3711ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
3712ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This routine may only be invoked when the expression is not
3714c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
3715ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
3716ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!isValueDependent() &&
3717ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
3718ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
3719ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3720ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
372165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
372265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3724ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
3725ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
3726ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3727ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3728ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
372963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3730ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
3731c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
373291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter
373391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument.
373491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr {
373591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replaced parameter.
373691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *Param;
373791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
373891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replacement expression.
373991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Stmt *Replacement;
374091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
374191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The location of the non-type template parameter reference.
374291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation NameLoc;
374391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
37447110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
37457110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
3746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
37477110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
37487110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
374991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic:
3750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmExpr(QualType type,
375191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               ExprValueKind valueKind,
375291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               SourceLocation loc,
375391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               NonTypeTemplateParmDecl *param,
375491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               Expr *replacement)
375591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
375691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isTypeDependent(), replacement->isValueDependent(),
375791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isInstantiationDependent(),
375891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->containsUnexpandedParameterPack()),
375991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall      Param(param), Replacement(replacement), NameLoc(loc) {}
376091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
376191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation getNameLoc() const { return NameLoc; }
376265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
376365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
376491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
376591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Expr *getReplacement() const { return cast<Expr>(Replacement); }
3766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
376791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *getParameter() const { return Param; }
376891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
376991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  static bool classof(const Stmt *s) {
377091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
377191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3772ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
377391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Iterators
377491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  child_range children() { return child_range(&Replacement, &Replacement+1); }
377591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall};
377691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
3777c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
3778c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
3779c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
3780c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3781c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
3782fb7669ee725ec699e2b49b8359c4652536949739Douglas Gregor/// parameter lists, this node is used to represent a non-type template
3783c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3784c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3785c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3786c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3787c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
3788c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
3789c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
3790c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
3791c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
3792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3793c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3794c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
3795c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
3796ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3797c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3798c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
3799ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3800c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
3801c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
3802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
38037110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
3804c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
3805ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
38067110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3807ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3808c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
3809ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmPackExpr(QualType T,
3810c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
3811c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
3812c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
3813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3814c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
3815c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3816c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3817c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
3818c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
3819ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3820c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
3821c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
3822c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
3823c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
382465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
382565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3827c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
3828c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3829c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3830ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3831c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
383263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3833c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
383403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
38359a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \brief Represents a reference to a function parameter pack that has been
38369a4db032ecd991626d236a502e770126db32bd31Richard Smith/// substituted but not yet expanded.
38379a4db032ecd991626d236a502e770126db32bd31Richard Smith///
38389a4db032ecd991626d236a502e770126db32bd31Richard Smith/// When a pack expansion contains multiple parameter packs at different levels,
38399a4db032ecd991626d236a502e770126db32bd31Richard Smith/// this node is used to represent a function parameter pack at an outer level
38409a4db032ecd991626d236a502e770126db32bd31Richard Smith/// which we have already substituted to refer to expanded parameters, but where
38419a4db032ecd991626d236a502e770126db32bd31Richard Smith/// the containing pack expansion cannot yet be expanded.
38429a4db032ecd991626d236a502e770126db32bd31Richard Smith///
38439a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \code
38449a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Ts> struct S {
38459a4db032ecd991626d236a502e770126db32bd31Richard Smith///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
38469a4db032ecd991626d236a502e770126db32bd31Richard Smith/// };
38479a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template struct S<int, int>;
38489a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \endcode
38499a4db032ecd991626d236a502e770126db32bd31Richard Smithclass FunctionParmPackExpr : public Expr {
38509a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The function parameter pack which was referenced.
38519a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *ParamPack;
38529a4db032ecd991626d236a502e770126db32bd31Richard Smith
38539a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The location of the function parameter pack reference.
38549a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation NameLoc;
38559a4db032ecd991626d236a502e770126db32bd31Richard Smith
38569a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The number of expansions of this pack.
38579a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned NumParameters;
38589a4db032ecd991626d236a502e770126db32bd31Richard Smith
38599a4db032ecd991626d236a502e770126db32bd31Richard Smith  FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
38609a4db032ecd991626d236a502e770126db32bd31Richard Smith                       SourceLocation NameLoc, unsigned NumParams,
38619a4db032ecd991626d236a502e770126db32bd31Richard Smith                       Decl * const *Params);
38629a4db032ecd991626d236a502e770126db32bd31Richard Smith
38639a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTReader;
38649a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTStmtReader;
38659a4db032ecd991626d236a502e770126db32bd31Richard Smith
38669a4db032ecd991626d236a502e770126db32bd31Richard Smithpublic:
386732b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T,
38689a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      ParmVarDecl *ParamPack,
38699a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      SourceLocation NameLoc,
3870cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko                                      ArrayRef<Decl *> Params);
387132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context,
38729a4db032ecd991626d236a502e770126db32bd31Richard Smith                                           unsigned NumParams);
38739a4db032ecd991626d236a502e770126db32bd31Richard Smith
38749a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the parameter pack which this expression refers to.
38759a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getParameterPack() const { return ParamPack; }
38769a4db032ecd991626d236a502e770126db32bd31Richard Smith
38779a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the location of the parameter pack.
38789a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation getParameterPackLocation() const { return NameLoc; }
38799a4db032ecd991626d236a502e770126db32bd31Richard Smith
38809a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Iterators over the parameters which the parameter pack expanded
38819a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// into.
38829a4db032ecd991626d236a502e770126db32bd31Richard Smith  typedef ParmVarDecl * const *iterator;
38839a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator begin() const { return reinterpret_cast<iterator>(this+1); }
38849a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator end() const { return begin() + NumParameters; }
38859a4db032ecd991626d236a502e770126db32bd31Richard Smith
38869a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the number of parameters in this parameter pack.
38879a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned getNumExpansions() const { return NumParameters; }
38889a4db032ecd991626d236a502e770126db32bd31Richard Smith
38899a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get an expansion of the parameter pack by index.
38909a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
38919a4db032ecd991626d236a502e770126db32bd31Richard Smith
389265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
389365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
38949a4db032ecd991626d236a502e770126db32bd31Richard Smith
38959a4db032ecd991626d236a502e770126db32bd31Richard Smith  static bool classof(const Stmt *T) {
38969a4db032ecd991626d236a502e770126db32bd31Richard Smith    return T->getStmtClass() == FunctionParmPackExprClass;
38979a4db032ecd991626d236a502e770126db32bd31Richard Smith  }
38989a4db032ecd991626d236a502e770126db32bd31Richard Smith
38999a4db032ecd991626d236a502e770126db32bd31Richard Smith  child_range children() { return child_range(); }
39009a4db032ecd991626d236a502e770126db32bd31Richard Smith};
39019a4db032ecd991626d236a502e770126db32bd31Richard Smith
3902010bfc253050626435f006386c0bee4b55329687James Dennett/// \brief Represents a prvalue temporary that is written into memory so that
390303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it.
390403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
390503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address
390603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a
390703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g.,
390803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
390903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code
391003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0;
391103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode
391203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
391303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
391403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference
391503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
391603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding
391703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues.
3918211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith///
3919211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith/// Reference binding and copy-elision can both extend the lifetime of a
3920211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith/// temporary. When either happens, the expression will also track the
3921211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith/// declaration which is responsible for the lifetime extension.
392203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr {
3923211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smithpublic:
392403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief The temporary-generating expression whose value will be
392503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// materialized.
3926d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Temporary;
3927ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3928211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// \brief The declaration which lifetime-extended this reference, if any.
3929211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3930211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  const ValueDecl *ExtendingDecl;
3931211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
393203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtReader;
393303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtWriter;
3934ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
393503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic:
3936ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3937211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith                           bool BoundToLvalueReference,
3938211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith                           const ValueDecl *ExtendedBy)
3939b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor    : Expr(MaterializeTemporaryExprClass, T,
394003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
394103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->isTypeDependent(), Temporary->isValueDependent(),
3942561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Temporary->isInstantiationDependent(),
394303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->containsUnexpandedParameterPack()),
3944211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith      Temporary(Temporary), ExtendingDecl(ExtendedBy) {
3945211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  }
3946ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(EmptyShell Empty)
394803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    : Expr(MaterializeTemporaryExprClass, Empty) { }
3949ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
395003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Retrieve the temporary-generating subexpression whose value will
395103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// be materialized into a glvalue.
3952211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  Expr *GetTemporaryExpr() const { return static_cast<Expr *>(Temporary); }
3953211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
3954211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// \brief Retrieve the storage duration for the materialized temporary.
3955211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  StorageDuration getStorageDuration() const {
3956211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    if (!ExtendingDecl)
3957211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith      return SD_FullExpression;
3958211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    // FIXME: This is not necessarily correct for a temporary materialized
3959211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    // within a default initializer.
3960211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    if (isa<FieldDecl>(ExtendingDecl))
3961211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith      return SD_Automatic;
3962211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3963211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  }
3964211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
3965211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// \brief Get the declaration which triggered the lifetime-extension of this
3966211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// temporary, if any.
3967211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  const ValueDecl *getExtendingDecl() const { return ExtendingDecl; }
3968211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
3969211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  void setExtendingDecl(const ValueDecl *ExtendedBy) {
3970211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith    ExtendingDecl = ExtendedBy;
3971211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  }
3972ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
397303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Determine whether this materialized temporary is bound to an
397403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// lvalue reference; otherwise, it's bound to an rvalue reference.
3975ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isBoundToLvalueReference() const {
397603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return getValueKind() == VK_LValue;
397703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3978ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
397965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
398065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Temporary->getLocStart();
398165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
398265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
398365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Temporary->getLocEnd();
3984aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  }
3985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
398603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  static bool classof(const Stmt *T) {
398703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return T->getStmtClass() == MaterializeTemporaryExprClass;
398803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3989ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
399003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  // Iterators
399103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  child_range children() { return child_range(&Temporary, &Temporary + 1); }
399203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor};
3993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
39945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
39955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
39965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3997