ExprCXX.h revision be9af1288881110e406b87914162eaa59f1e5918
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//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses for C++ expressions.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPRCXX_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPRCXX_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
19eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall#include "clang/AST/UnresolvedSet.h"
20d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
2101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/ExpressionTraits.h"
2201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h"
2301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/TypeTraits.h"
24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl;
29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl;
30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl;
31aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary;
32aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo;
334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
51b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
52063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
53063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
544548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange Range;
55063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
56be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Record the FP_CONTRACT state that applies to this operator call. Only
57be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // meaningful for floating point types. For other types this value can be
58be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // set to false.
59be9af1288881110e406b87914162eaa59f1e5918Lang Hames  unsigned FPContractable : 1;
60be9af1288881110e406b87914162eaa59f1e5918Lang Hames
614548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRangeImpl() const LLVM_READONLY;
62b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
643b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                      ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
65be9af1288881110e406b87914162eaa59f1e5918Lang Hames                      SourceLocation operatorloc, bool fpContractable)
663b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
67f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
68be9af1288881110e406b87914162eaa59f1e5918Lang Hames      Operator(Op), FPContractable(fpContractable) {
694548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis    Range = getSourceRangeImpl();
704548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  }
711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
72ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
76b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
77063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
78b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
84b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
85b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
864548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRange() const { return Range; }
871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
90b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
91b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
924548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis
93be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Set the FP contractability status of this operator. Only meaningful for
94be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
95be9af1288881110e406b87914162eaa59f1e5918Lang Hames  void setFPContractable(bool FPC) { FPContractable = FPC; }
96be9af1288881110e406b87914162eaa59f1e5918Lang Hames
97be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Get the FP contractability status of this operator. Only meaningful for
98be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
99be9af1288881110e406b87914162eaa59f1e5918Lang Hames  bool isFPContractable() const { return FPContractable; }
100be9af1288881110e406b87914162eaa59f1e5918Lang Hames
1014548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtReader;
1024548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtWriter;
103b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
104b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
10588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
10688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
10788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
11188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
1153b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer  CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
116f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
1173b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
1191817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
1201817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
1211817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
12288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
12388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
12488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
125b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
126ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
127b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  /// Retrieves the declaration of the called method.
128b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
12988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
130007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
131007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
132007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
133007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
134007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
1350cf3c0eecbff007cea2750c113894b47d9e09f33David Blaikie  CXXRecordDecl *getRecordDecl() const;
136007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
13988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
14088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
14188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
14288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
1503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
1513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     SourceLocation RP)
1523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
153e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
154e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
155e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
156e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
157e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
158e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
159e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
160e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
161e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
162e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
163e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
164e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
165e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
166e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
167e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
168e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const CUDAKernelCallExpr *) { return true; }
169e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
170e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
17149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
17249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
17349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
17449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
17749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1811d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
182ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
184f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
185f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1861d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
1871d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
1881d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
1891d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor      RParenLoc(RParenLoc) {}
19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
191f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
193ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1941d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
195ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
199a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
200a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
201a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
202a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
2031d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
2041d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
205ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
206aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
2071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    return SourceRange(Loc, RParenLoc);
2081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
21149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
21249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
21349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
21449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
21549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
21649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
21749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
21849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
2191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
22049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
22149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
22249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
223ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression
224ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]).
2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
229f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
230f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2311d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2331d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
23449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
235f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
240f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
242ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   TypeSourceInfo *Written, SourceLocation L,
2431d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
246ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
24849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
24949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
25049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
25149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
25249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
25349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
25749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
25849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
25949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
260f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
261f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2621d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
263f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2641d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
266f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
267f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
268f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
269f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
270f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
271f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
272f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
273ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                    TypeSourceInfo *Written, SourceLocation L,
2741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
275ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
276f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
277f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
278ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2790fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2800fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
28249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
28349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
28449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
28549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
28649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
28749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
28949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
29149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
29249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
29349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
295f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
296ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                         TypeSourceInfo *writtenTy, SourceLocation l,
2971d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
298f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2991d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
301f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
302f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
303f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
304f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
305f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
308ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                 TypeSourceInfo *WrittenTy, SourceLocation L,
3091d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
310f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
312ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
31549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
31649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
31749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
31849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
31949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
32049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
326ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   TypeSourceInfo *writtenTy, SourceLocation l,
3271d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
328ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3291d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
33049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
331ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
332f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
334f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
335f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3381d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
339f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
340ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
34249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
34349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
34449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
3451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3479fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
3489fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]).
3499fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3509fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
3519fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better
3529fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal.
3539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3549fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at
3559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent.
3569fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr {
3579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// \brief The location of a ud-suffix within the literal.
3589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  SourceLocation UDSuffixLoc;
3599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic:
3613b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer  UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     SourceLocation SuffixLoc)
3643b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
3653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer      UDSuffixLoc(SuffixLoc) {}
3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
3679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    : CallExpr(C, UserDefinedLiteralClass, Empty) {}
3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// The kind of literal operator which is invoked.
3709fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  enum LiteralOperatorKind {
3719fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Raw,      ///< Raw form: operator "" X (const char *)
3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Template, ///< Raw form: operator "" X<cs...> ()
3739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Integer,  ///< operator "" X (unsigned long long)
3749fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Floating, ///< operator "" X (long double)
3759fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_String,   ///< operator "" X (const CharT *, size_t)
3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Character ///< operator "" X (CharT)
3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  };
3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getLiteralOperatorKind - Returns the kind of literal operator invocation
3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// which this expression represents.
3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  LiteralOperatorKind getLiteralOperatorKind() const;
3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getCookedLiteral - If this is not a raw user-defined literal, get the
3849fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// underlying cooked literal (representing the literal with the suffix
3859fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// removed).
3869fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  Expr *getCookedLiteral();
3879fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const Expr *getCookedLiteral() const {
3889fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
3899fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
3909fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3910265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocStart() const {
3920265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    if (getLiteralOperatorKind() == LOK_Template)
3930265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara      return getRParenLoc();
3940265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    return getArg(0)->getLocStart();
3950265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  }
3960265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocEnd() const { return getRParenLoc(); }
3970265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceRange getSourceRange() const {
3980265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    return SourceRange(getLocStart(), getLocEnd());
3990265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  }
4000265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
4010265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
4029fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
4039fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// For a string literal, there may be multiple identical suffixes. This
4049fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// returns the first.
4050265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
4069fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4079fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffix - Returns the ud-suffix specified for this literal.
4089fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const IdentifierInfo *getUDSuffix() const;
4099fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4109fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const Stmt *S) {
4119fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return S->getStmtClass() == UserDefinedLiteralClass;
4129fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
4139fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const UserDefinedLiteral *) { return true; }
4149fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4159fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtReader;
4169fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtWriter;
4179fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith};
4189fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
4211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
4221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
4231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
4241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
426bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
427561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
428f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
4298b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
430eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
431eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
432eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
434eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
436aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
438eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
439eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
440eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
4431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4441060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
44763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
4491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4506e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
4516e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
4526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
4536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
4546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
455bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
456561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
457f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
4586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
459eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
460eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
461eb7f96141f754150a92433286fa385910a22f494Sam Weinig
462aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
4636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
464eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
465eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
466eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4676e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
4686e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
4696e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
4706e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
4716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
47263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
4746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
475c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
476c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
477c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
478c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
479c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
480c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
481c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
48257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
483c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
484c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
485c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
48657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
487f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
48857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
48957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
49057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
491bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
492561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
493bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
49457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
495ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
49657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
497f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
4982850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
499bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
5002850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
501bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
502561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
503bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
50457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
505c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
50614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
50714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
50814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
50914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
51014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
51114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
51214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
513ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5140d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// Determine whether this typeid has a type operand which is potentially
5150d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// evaluated, per C++11 [expr.typeid]p3.
5160d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  bool isPotentiallyEvaluated() const;
5170d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith
51857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
519ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
52057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
52157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
52257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
52357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
52457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
52557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
526c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
52757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
528c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
52914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
53014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
53114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
53214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
53314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
534ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
53514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
536c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
53757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
538c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
539ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
540030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
541030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
542030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
543030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
544ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
545aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
54614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
547ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
548c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
549c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
550c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
551c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
552c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
553c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
55463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
55563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
55663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
55763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
55863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
559c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
560c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
56101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
56201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
56301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
56401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
56501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
56601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
56701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
56801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
56901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
57001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
57101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
5722e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
573bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
574561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
575bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
57601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
577ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
57801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
5792e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
580bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
581561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
582bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
58301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
58401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
58501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
58601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
58701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
58801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
58901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
59001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
59101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
592ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
59301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
594ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
59501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
59601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
59701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
59801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
59901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
60001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
60101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
60201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
60301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
60401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
60501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
60601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
60701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
60801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
61001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
61101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
61201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
61301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
614ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
61501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
61601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
61701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
61801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
61901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
620aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
62101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
622ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
62301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
62401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
62501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
62601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const CXXUuidofExpr *) { return true; }
62701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
62801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
62963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
63063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
63163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
63263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
63401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
63501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
636796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
637796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
638796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
639796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
640796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
641796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
642796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
643796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
644796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
645796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
646796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
647796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
648796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
649828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
650ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
651796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
652828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
653f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
6542850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
6552850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
656bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
657561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Type->isInstantiationDependentType(),
658bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
659828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
660796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6612fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
6622fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
6632fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
6642fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
6652fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
666aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
667796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
668828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
669828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
670ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
672796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
673796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
674796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
675796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
676796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
67763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
678796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
679796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
6811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
6821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
6831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
6841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
6851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
6861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
687bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Whether the thrown variable (if any) is in scope.
688bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  unsigned IsThrownVariableInScope : 1;
689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
690bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  friend class ASTStmtReader;
691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
6931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
6941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
6951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
696bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
697bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor               bool IsThrownVariableInScope) :
698bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
699561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         expr && expr->isInstantiationDependent(),
700bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
701bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
7022fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
7032fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
7041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
7051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
70642e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
70742e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
7081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
709bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Determines whether the variable thrown by this expression (if any!)
710bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// is within the innermost try block.
711bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ///
712bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// This information is required to determine whether the NRVO can apply to
713bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// this variable.
714bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
715ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
716aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
7181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
7191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
7201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
7231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
7241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
7261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
72863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
73063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
7321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
7341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
7351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
7361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
7371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
73865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
73965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
740ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// When the bit is set, the subexpression is stored after the
74165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
74265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
74365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
7441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
745036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
746036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
748036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(SC,
75065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
75165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
7522333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
753dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
754561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false, false),
755036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
75665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
758036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
759dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
760dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
761ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           false, false, false, false),
762bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
76365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
76465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
765ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7661060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
767030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
768030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
7711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
772036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
773036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
774036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
775f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
7761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
77765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
77865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
779ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static CXXDefaultArgExpr *Create(ASTContext &C,
780036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   ParmVarDecl *Param,
78265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
78565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
78665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
787ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
789ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  const Expr *getExpr() const {
79065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
79165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
79365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
794ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getExpr() {
79565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
79665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
79865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
7991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the location where this default argument was actually
801036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
802036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
804aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
8051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
8061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
8071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
8081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
8091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
8111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
8121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
8131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
8141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
81663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
8178a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
81860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
8193397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
8201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
821987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
822c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
823c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
824c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
825b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
827b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
828c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
829c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
830c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
832b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
834f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
83576f3f69db1416425070177243e9f390122c553e0Richard Smith  void setDestructor(const CXXDestructorDecl *Dtor) {
83676f3f69db1416425070177243e9f390122c553e0Richard Smith    Destructor = Dtor;
83776f3f69db1416425070177243e9f390122c553e0Richard Smith  }
838c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
839fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
840ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
841ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
842ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
843ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
844ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
845ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
846ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
847ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
848ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
849ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
850ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
851ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
852ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
853ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
854fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
855fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
857fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
858fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
859bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
860bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
861ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
862bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
863561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          SubExpr->isInstantiationDependent(),
864bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
865bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
86688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
867fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
868d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
869d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
872fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
875f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
876d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
877f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
878fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
879fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
88088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
881fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
882aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
88396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
88496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
885fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
886fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
887fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
888fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
889fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
890fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
891fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
892fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
89363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
894fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
895fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
8960982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a call to a C++ constructor.
89715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
89872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
89972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
90072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
90172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
902059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_VirtualBase,
903059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_Delegating
90472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
905ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
90672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
90715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
90815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
90999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
910428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
911a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor  unsigned NumArgs : 16;
91216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
9137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool HadMultipleCandidates : 1;
9145b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool ListInitialization : 1;
91516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
91672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
91715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
9181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
919bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
92199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
922bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
9233b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                   ArrayRef<Expr *> Args,
9247cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                   bool HadMultipleCandidates,
9255b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ListInitialization,
9265b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ZeroInitialization,
9275b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   ConstructionKind ConstructKind,
9285b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   SourceRange ParenRange);
929bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
9306d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
9316d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
9325b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl    : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
9335b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      HadMultipleCandidates(false), ListInitialization(false),
9345b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ZeroInitialization(false), ConstructKind(0), Args(0)
9355b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9366d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
93715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
9386d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
9396d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
9406d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
9415b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      NumArgs(0), Elidable(false), HadMultipleCandidates(false),
9425b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ListInitialization(false), ZeroInitialization(false),
9435b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ConstructKind(0), Args(0)
9445b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9456d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
9468e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
94799a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
9481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
9493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                  ArrayRef<Expr *> Args,
9507cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                  bool HadMultipleCandidates,
9515b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ListInitialization,
9525b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ZeroInitialization,
9535b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  ConstructionKind ConstructKind,
9545b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  SourceRange ParenRange);
9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
956d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
95739da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
958ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
95999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
96099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
961ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
962d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
963d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
96439da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
9657cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Whether the referred constructor was resolved from
9677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// an overloaded set having size greater than 1.
9687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
9697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
9707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9715b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  /// \brief Whether this constructor call was written as list-initialization.
9725b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool isListInitialization() const { return ListInitialization; }
9735b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  void setListInitialization(bool V) { ListInitialization = V; }
9745b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
97516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
97616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
97716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
97816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
97916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
98016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
981ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9829db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
9839db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
98424eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
98524eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
98672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
987ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setConstructionKind(ConstructionKind CK) {
98872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
98972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
990ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
99115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
99215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
99515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
99615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
99715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
99815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
999a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
100015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
100115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
1002bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
1003bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
1004bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1005bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1006bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
1007bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
1008bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1009bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1010bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10122eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
10132eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
10142eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
10152eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
10162eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
10172eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
1018aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
1019428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
1020a770a4daf77037b5526dba1c447d61acf0aba01aDaniel Jasper  void setParenRange(SourceRange Range) { ParenRange = Range; }
102115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1023524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
1024524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
102515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
102615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
102963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
103063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
103163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
103360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
103415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
103515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
10360982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an explicit C++ type conversion that uses "functional"
10370982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// notation (C++ [expr.type.conv]).
10380982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
10390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Example:
10400982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
10410982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   x = int(0.5);
10420982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
104349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
1044987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
1045987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1046f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1047f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1048f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
1050f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
1051ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                        SourceLocation rParenLoc)
1052f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1053f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
10540aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
10550aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
1056f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1057f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1058f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1059f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
1060f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1061f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
1062f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
1063f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
1064f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
1065f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
1066f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
1067f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1068f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
1069ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1070987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1071ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1072987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
1073ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1075aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1076987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
1077987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
1080987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1081987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
1082987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1083987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1084506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
1085506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
1086506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
1088506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1089ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the
1090ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
1091506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
1092506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
1093506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
1094506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
1095506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
1096506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1097506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
1098506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
1099524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
1100ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
1101506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1102506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1104ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
11053b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                         ArrayRef<Expr *> Args,
1106428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
11077cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                         bool HadMultipleCandidates,
11081c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
11096d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1110ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1111506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1112ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1113ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1114aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
1115ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1117506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
1118506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
1119506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
11206d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
112160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
1122506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
1123506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object
112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later.
112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
112701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example:
112801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code
112901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) {
113001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///   values.erase(std::remove_if(values.begin(), values.end(),
113101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor//                                [=](double value) { return value > cutoff; });
113201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// }
113301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode
113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying
113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function
113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a
113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either
113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square
114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression.
114101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr {
114201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  enum {
114301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indicate that the given
114401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture was implicit.
114501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_Implicit = 0x01,
114601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
114701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indciate that the
114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// given capture was by-copy.
114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_ByCopy = 0x02
115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
115101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
115201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The source range that covers the lambda introducer ([...]).
115301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange IntroducerRange;
115401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11557ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief The number of captures.
11567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned NumCaptures : 16;
11577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
115801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The default capture kind, which is a value of type
115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// LambdaCaptureDefault.
116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned CaptureDefault : 2;
116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
116201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Whether this lambda had an explicit parameter list vs. an
116301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit (and empty) parameter list.
116401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned ExplicitParams : 1;
116501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1166dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had the result type explicitly specified.
1167dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  unsigned ExplicitResultType : 1;
1168dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
1169dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether there are any array index variables stored at the end of
1170dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// this lambda expression.
11717ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned HasArrayIndexVars : 1;
11727ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
117301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The location of the closing brace ('}') that completes
117401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// the lambda.
117501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  ///
117601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// The location of the brace is also available by looking up the
117701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// function call operator in the lambda class. However, it is
117801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stored here to improve the performance of getSourceRange(), and
117901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// to avoid having to deserialize the function call operator from a
118001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// module file just to determine the source range.
118101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceLocation ClosingBrace;
118201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // Note: The capture initializers are stored directly after the lambda
11847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // expression, along with the index variables used to initialize by-copy
11857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // array captures.
11867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
118701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
118801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Describes the capture of either a variable or 'this'.
118901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  class Capture {
119001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
119101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation Loc;
119201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation EllipsisLoc;
11939daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
119401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtReader;
119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtWriter;
11969daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  public:
119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Create a new capture.
119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Loc The source location associated with this capture.
120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Kind The kind of capture (this, byref, bycopy).
120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Implicit Whether the capture was implicit or explicit.
120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Var The local variable being captured, or null if capturing this.
120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param EllipsisLoc The location of the ellipsis (...) for a
120901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture that is a pack expansion, or an invalid source
121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// location to indicate that this is not a pack expansion.
121101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture(SourceLocation Loc, bool Implicit,
121201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            LambdaCaptureKind Kind, VarDecl *Var = 0,
121301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            SourceLocation EllipsisLoc = SourceLocation());
121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine the kind of capture.
121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    LambdaCaptureKind getCaptureKind() const;
121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles the C++ 'this'
121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// pointer.
122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesThis() const { return VarAndBits.getPointer() == 0; }
122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles a variable.
122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the declaration of the local variable being
122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// captured.
122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// This operation is only valid if this capture does not capture
122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// 'this'.
123001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    VarDecl *getCapturedVar() const {
123101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(!capturesThis() && "No variable available for 'this' capture");
123201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return VarAndBits.getPointer();
123301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
123401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
123501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an implicit capture (not
123601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// written between the square brackets introducing the lambda).
123701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
123901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an explicit capture, written
124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// between the square brackets introducing the lambda.
124101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isExplicit() const { return !isImplicit(); }
124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
124301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the source location of the capture.
124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
124501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// For an explicit capture, this returns the location of the
124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// explicit capture in the source. For an implicit capture, this
124701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// returns the location at which the variable or 'this' was first
124801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// used.
124901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getLocation() const { return Loc; }
125001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
125101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture is a pack expansion,
125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// which captures a function parameter pack.
125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isPackExpansion() const { return EllipsisLoc.isValid(); }
125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
125501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the location of the ellipsis for a capture
125601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// that is a pack expansion.
125701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getEllipsisLoc() const {
125801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(isPackExpansion() && "No ellipsis location for a non-expansion");
125901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return EllipsisLoc;
126001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
126101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
126201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
126301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate:
126401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a lambda expression.
126501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaExpr(QualType T, SourceRange IntroducerRange,
126601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             LambdaCaptureDefault CaptureDefault,
126701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Capture> Captures,
126801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             bool ExplicitParams,
1269dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor             bool ExplicitResultType,
127001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Expr *> CaptureInits,
12719daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<VarDecl *> ArrayIndexVars,
12729daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<unsigned> ArrayIndexStarts,
1273612409ece080e814f79e06772c690d603f45fbd6Richard Smith             SourceLocation ClosingBrace,
1274612409ece080e814f79e06772c690d603f45fbd6Richard Smith             bool ContainsUnexpandedParameterPack);
127501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
12769d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct an empty lambda expression.
12779d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
12789d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    : Expr(LambdaExprClass, Empty),
12799d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
12809d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      ExplicitResultType(false), HasArrayIndexVars(true) {
12819d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    getStoredStmts()[NumCaptures] = 0;
12829d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  }
12839d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
12847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  Stmt **getStoredStmts() const {
12857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
12867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the mapping from captures to the first array index
12897ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// variable.
12907ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned *getArrayIndexStarts() const {
12917ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
12927ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12937ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12947ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the complete set of array-index variables.
12957ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  VarDecl **getArrayIndexVars() const {
1296a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith    unsigned ArrayIndexSize =
1297a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith        llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1298a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith                                 llvm::alignOf<VarDecl*>());
12997ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<VarDecl **>(
130088d2f678e70ab9360f09f3534d9223e6ec20f129Richard Smith        reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
13017ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
13027ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
130401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a new lambda expression.
130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static LambdaExpr *Create(ASTContext &C,
130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            CXXRecordDecl *Class,
130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            SourceRange IntroducerRange,
130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            LambdaCaptureDefault CaptureDefault,
130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Capture> Captures,
131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            bool ExplicitParams,
1311dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                            bool ExplicitResultType,
131201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Expr *> CaptureInits,
13139daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<VarDecl *> ArrayIndexVars,
13149daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<unsigned> ArrayIndexStarts,
1315612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            SourceLocation ClosingBrace,
1316612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            bool ContainsUnexpandedParameterPack);
131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13189d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct a new lambda expression that will be deserialized from
13199d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// an external source.
13209d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
13219d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor                                        unsigned NumArrayIndexVars);
13229d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
132301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine the default capture kind for this lambda.
132401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaCaptureDefault getCaptureDefault() const {
132501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return static_cast<LambdaCaptureDefault>(CaptureDefault);
132601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
132701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief An iterator that walks over the captures of the lambda,
132901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// both implicit and explicit.
133001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef const Capture *capture_iterator;
133101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
133201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first lambda capture.
1333da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_begin() const;
133401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
133501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the
133601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// sequence of lambda captures.
1337da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_end() const;
133801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13397ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Determine the number of captures in this lambda.
13407ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned capture_size() const { return NumCaptures; }
13417ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
134201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first explicit
134301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1344da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_begin() const;
134501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
134601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
134701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// explicit lambda captures.
1348da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_end() const;
134901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first implicit
135101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1352da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_begin() const;
135301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
135501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit lambda captures.
1356da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_end() const;
135701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Iterator that walks over the capture initialization
135901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// arguments.
136001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef Expr **capture_init_iterator;
136101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
136201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the first initialization argument for this
136301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression (which initializes the first capture field).
13647ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_begin() const {
13657ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Expr **>(getStoredStmts());
13667ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
136701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
136801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the iterator pointing one past the last
136976e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  /// initialization argument for this lambda expression.
13707ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_end() const {
13717ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return capture_init_begin() + NumCaptures;
13727ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
137301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13749daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Retrieve the set of index variables used in the capture
13759daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// initializer of an array captured by copy.
13769daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ///
13779daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \param Iter The iterator that points at the capture initializer for
13789daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// which we are extracting the corresponding index variables.
13799daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
13809daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
138101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the source range covering the lambda introducer,
138201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// which contains the explicit capture list surrounded by square
138301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// brackets ([...]).
138401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange getIntroducerRange() const { return IntroducerRange; }
138501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
138601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the class that corresponds to the lambda, which
138701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stores the captures in its fields and provides the various
138801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// operations permitted on a lambda (copying, calling).
138901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXRecordDecl *getLambdaClass() const;
139001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the function call operator associated with this
139201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression.
139301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXMethodDecl *getCallOperator() const;
139401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the body of the lambda.
13969d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  CompoundStmt *getBody() const;
139701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether the lambda is mutable, meaning that any
139901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// captures values can be modified.
140001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool isMutable() const;
140101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
140201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether this lambda has an explicit parameter
140301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// list vs. an implicit (empty) parameter list.
140401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool hasExplicitParameters() const { return ExplicitParams; }
140501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1406dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had its result type explicitly specified.
1407dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  bool hasExplicitResultType() const { return ExplicitResultType; }
14089e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor
140901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const Stmt *T) {
141001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return T->getStmtClass() == LambdaExprClass;
141101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
141201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const LambdaExpr *) { return true; }
141301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1414aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
141501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
141601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
141701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
14187ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  child_range children() {
14197ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
14207ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
142101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
142201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtReader;
142301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtWriter;
142401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor};
142501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1426ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1427506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
1428ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
1429987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
1430ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
1431987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1432ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
1433987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1434ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
1435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1436987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
1437ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Create an explicitly-written scalar-value initialization
1438ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
1439ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
1440ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
1441ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
1442f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1443561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false, Type->isInstantiationDependentType(), false),
1444ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1445ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1446ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1447ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1449ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1450ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
14514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1453ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
14544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1455aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1458ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1459987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1460ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  static bool classof(const CXXScalarValueInitExpr *) { return true; }
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1462987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
146363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1464987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1465987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14660982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @brief Represents a new-expression for memory allocation and constructor
14670982205bade2fb4fc984c27b2ab401e683963b10James Dennett// calls, e.g: "new CXXNewExpr(foo)".
14684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
14692aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // Contains an optional array size expression, an optional initialization
14702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // expression, and any number of optional placement arguments, in that order.
14714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
14720982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the allocation function used.
14734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
14740982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the deallocation function used in case of error. May be
14750982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// null.
14764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
14774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14781bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
14791bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
1480ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1481ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief If the allocated type was expressed as a parenthesized type-id,
14824bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
14834bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
1484ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Location of the first token.
14864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
14872aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
14882aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Source-range of a paren-delimited initializer.
14892aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange DirectInitRange;
14904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1491d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Was the usage ::new, i.e. is the global new to be used?
1492d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool GlobalNew : 1;
1493d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Do we allocate an array? If so, the first SubExpr is the size expression.
1494d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool Array : 1;
1495d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // If this is an array allocation, does the usual deallocation
1496d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // function for the allocated type want to know the allocated size?
1497d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool UsualArrayDeleteWantsSize : 1;
1498d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The number of placement new arguments.
1499d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned NumPlacementArgs : 13;
1500d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // What kind of initializer do we have? Could be none, parens, or braces.
1501d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // In storage, we distinguish between "none, and no initializer expr", and
1502d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // "none, but an implicit initializer expr".
1503d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned StoredInitializationStyle : 2;
1504d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
150560adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
15062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  friend class ASTStmtWriter;
15074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
15082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  enum InitializationStyle {
15092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    NoInit,   ///< New-expression has no initializer as written.
15102aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    CallInit, ///< New-expression has a C++98 paren-delimited initializer.
15112aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    ListInit  ///< New-expression has a C++11 list-initializer.
15122aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  };
15132aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
1514ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
15151548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
15163b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer             ArrayRef<Expr*> placementArgs,
15172aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceRange typeIdParens, Expr *arraySize,
15182aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             InitializationStyle initializationStyle, Expr *initializer,
15196ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
15202aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceLocation startLoc, SourceRange directInitRange);
15215921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
15225921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
15235921863d8f24084797863b5df37842113bac4352Chris Lattner
15245921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
15252aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                         bool hasInitializer);
1526ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1527cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1528cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
15296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1530cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15321bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
15331bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
15341bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1535c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1536c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1537c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// C++0x [expr.new]p13:
1538c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1539c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1540c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1541c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1542c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1543c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1544c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
15458026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1546ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
15485921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
15494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
15505921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
15514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1552cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1553cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1554cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1555cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1556cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1557cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1558cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1559cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
15604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1561ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr **getPlacementArgs() {
15622aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1563aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
15664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return getPlacementArgs()[i];
15684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
15704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
15724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15744bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
15754bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
15764bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
15774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
15787cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
15792aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Whether this new-expression has any initializer at all.
15802aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool hasInitializer() const { return StoredInitializationStyle > 0; }
15811548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15822aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The kind of initializer this new-expression has.
15832aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  InitializationStyle getInitializationStyle() const {
15842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    if (StoredInitializationStyle == 0)
15852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl      return NoInit;
15862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return static_cast<InitializationStyle>(StoredInitializationStyle-1);
15871548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15881548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15892aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The initializer of this new-expression.
15902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  Expr *getInitializer() {
15912aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15921548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const Expr *getInitializer() const {
15942aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15951548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15961548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
1597feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay  /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
159888920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky  const CXXConstructExpr* getConstructExpr() const {
1599feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay    return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1600feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay  }
1601feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay
16022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// Answers whether the usual array deallocation function for the
16032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// allocated type expects the size of the allocation as a
16042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// parameter.
16052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool doesUsualArrayDeleteWantSize() const {
16062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return UsualArrayDeleteWantsSize;
16072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
16081548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
16094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
16104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
16114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
16132aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
16144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
16162aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
16192aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
16204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
16222aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
1624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16255921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
16265921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
16275921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
16282aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16295921863d8f24084797863b5df37842113bac4352Chris Lattner  }
16305921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
16312aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const_arg_iterator raw_arg_end() const {
16322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16332aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
16344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16355921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
16362aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceLocation getEndLoc() const;
1637428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
16382aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange getDirectInitRange() const { return DirectInitRange; }
1639428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1640aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
16412aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SourceRange(getStartLoc(), getEndLoc());
16424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
16454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
16464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
16484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
165063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
16512aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return child_range(raw_arg_begin(), raw_arg_end());
165263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
16534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
16544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16550982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a \c delete expression for memory deallocation and
16560982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// destructor calls, e.g. "delete[] pArray".
16574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
1658d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Points to the operator delete overload that is used. Could be a member.
1659d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  FunctionDecl *OperatorDelete;
1660d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The pointer expression to be deleted.
1661d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Argument;
1662d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Location of the expression.
1663d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  SourceLocation Loc;
16644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
16654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
16664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
16674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
16684076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
16694076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
16704076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
16714076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
16726ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
16736ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
16746ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
16754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
16764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
16776ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
16786ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1679bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1680561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           arg->isInstantiationDependent(),
1681bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1682d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1683f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
16844076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1685d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
168695fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
168795fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
16884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
16904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
16914076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
16924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16936ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
16946ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
16956ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
16966ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
16976ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
16986ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
16996ec278d1a354517e20f13a877481453ee7940c78John McCall  }
17006ec278d1a354517e20f13a877481453ee7940c78John McCall
17014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
17024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
17044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
17054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1706a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1707a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1708a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
17095833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1711aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
17124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
17134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
17144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
17164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
17174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
17184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
17194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
172163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1722f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1723f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
17244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
17254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17260982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Stores the type being destroyed by a pseudo-destructor expression.
1727a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1728ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Either the type source information or the name of the type, if
1729a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1730a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1731ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1732a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1733a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1734ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1735a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1736a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1737ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1738a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1739a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1740ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1741a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getTypeSourceInfo() const {
1744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return Type.dyn_cast<TypeSourceInfo *>();
1745a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1747a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1748a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1749a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1751a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1752a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1754a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1755a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1756e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have
1758e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1759e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1760e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1761e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1762e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1763e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1764e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1765e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1766a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1767e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1768ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///
1769a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1771a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1772e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1773a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1774a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1775a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1776e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1777e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1778a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1779a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1780a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1782a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1783a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1784a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1786a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1787a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1789a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1790f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1792e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1793e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1794e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1795ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1796ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The location of the '::' in a qualified pseudo-destructor
1797e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1798e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1799ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1800fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1801fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The type being destroyed, or its name if we were unable to
1804a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1805a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1807f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1808ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1809a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1810a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1811a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1812f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1813e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1814e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1815fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1816e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1818de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1819de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1820f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1821de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1822a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1825a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1826a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1827f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1829f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1830f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1831f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1832ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1834a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1835a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1836ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
1837ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
1838f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1840a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1841a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1842a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1843a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1844a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1845a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1847ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1848e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1849e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1850e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1851e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1852e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1853ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \p T may also be a scalar type and, therefore, cannot be part of a
1854e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1855e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
185626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1857ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1858e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1859e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1860e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1861ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1862fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1863fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
186526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
186626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1867a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This type-source information is available for non-dependent
1869a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1870a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1871a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1872ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getDestroyedTypeInfo() const {
1873ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getTypeSourceInfo();
1874a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1875ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1876a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1877a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1878a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1879a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1880a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1881a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1883a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1884a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1885ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1886a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1887ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SourceLocation getDestroyedTypeLoc() const {
1888ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getLocation();
1889a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1891de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1892de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1893de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1894de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1895de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1896de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1897de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1898de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1899de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1900de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1901de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1902aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1905a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1906a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1907a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1909a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
191063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1911a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19130982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS unary type trait, as used in the
19140982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
19150982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
191664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
19170982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
19180982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_pod(int) == true
19190982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_enum(std::string) == false
19200982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
192164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
19220dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
19230dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
19240dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
19250dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
192664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
192764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
192864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
192964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
193064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
193164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
193264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19330dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
19343d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
193564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
193664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
1937ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
19380dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
193964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1940f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1941bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1942561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->getType()->isInstantiationDependentType(),
1943bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
19440dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
194564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19466d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
19470dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
19483d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
19496d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
1950aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
195164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19520dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
195364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19543d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
195564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19563d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1957ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19580dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
195964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
196064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
196164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
196264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
196364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
196464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
196564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
196663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19676d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
196860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
196964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
197064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19710982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS binary type trait, as used in the
19720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
19730982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
19746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
19750982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
19760982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_base_of(Base, Derived) == true
19770982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
19786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
19796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
19806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
19816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
19836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
19846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
19866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
19876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
19936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
19956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
19966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
1998ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1999ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
20006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
2001ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
20026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
2003bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
2004561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhsType->getType()->isInstantiationDependentType() ||
2005561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhsType->getType()->isInstantiationDependentType()),
2006bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
2007bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
20086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
20096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
20106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
20136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
2014f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
20156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
2016aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
20176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SourceRange(Loc, RParen);
20186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
20216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
20226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
20256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
20266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
20286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
2029ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
20316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
20336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
20346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const BinaryTypeTraitExpr *) { return true; }
20366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
203863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
20396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
20416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
20426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and
20444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates.
20454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///
20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code
20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///   __is_trivially_constructible(vector<int>, int*, int*)
20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode
20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr {
20504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief The location of the type trait keyword.
20514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation Loc;
20524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief  The location of the closing parenthesis.
20544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation RParenLoc;
20554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Note: The TypeSourceInfos for the arguments are allocated after the
20574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // TypeTraitExpr.
20584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
20604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                ArrayRef<TypeSourceInfo *> Args,
20614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                SourceLocation RParenLoc,
20624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                bool Value);
20634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
20654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo **getTypeSourceInfos() {
20684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo **>(this+1);
20694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo * const *getTypeSourceInfos() const {
20734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo * const*>(this+1);
20744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic:
20774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Create a new type trait expression.
20784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
20794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               TypeTrait Kind,
20804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               ArrayRef<TypeSourceInfo *> Args,
20814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               SourceLocation RParenLoc,
20824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               bool Value);
20834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
20854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine which type trait this expression uses.
20874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTrait getTrait() const {
20884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
20894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  bool getValue() const {
20924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(!isValueDependent());
20934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return TypeTraitExprBits.Value;
20944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine the number of arguments to this type trait.
20974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
20984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the Ith argument.
21004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo *getArg(unsigned I) const {
21014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(I < getNumArgs() && "Argument out-of-range");
21024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getArgs()[I];
21034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
21064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ArrayRef<TypeSourceInfo *> getArgs() const {
21074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
21084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo **arg_iterator;
21114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_begin() {
21124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos();
21134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_end() {
21154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
21164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo const * const *arg_const_iterator;
21194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
21204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_end() const {
21214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
21224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2124aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); }
21254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const Stmt *T) {
21274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return T->getStmtClass() == TypeTraitExprClass;
21284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const TypeTraitExpr *) { return true; }
21304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Iterators
21324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  child_range children() { return child_range(); }
21334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtReader;
21354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
21364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor};
21384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An Embarcadero array type trait, as used in the implementation of
21400982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank and __array_extent.
21410982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
214221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example:
21430982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
21440982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_rank(int[10][20]) == 2
21450982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_extent(int, 1)    == 20
21460982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
214721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr {
214899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
214999ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
21500982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
215121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  unsigned ATT : 2;
215221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21530982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
215421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t Value;
215521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21560982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The array dimension being queried, or -1 if not used.
215721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *Dimension;
215821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21590982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
216021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation Loc;
216121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21620982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
216321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation RParen;
216421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21650982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The type being queried.
216621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *QueriedType;
216721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
216821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic:
216921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
217021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     TypeSourceInfo *queried, uint64_t value,
217121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     Expr *dimension, SourceLocation rparen, QualType ty)
217221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
217321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           false, queried->getType()->isDependentType(),
2174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (queried->getType()->isInstantiationDependentType() ||
2175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            (dimension && dimension->isInstantiationDependent())),
217621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           queried->getType()->containsUnexpandedParameterPack()),
217721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      ATT(att), Value(value), Dimension(dimension),
217821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      Loc(loc), RParen(rparen), QueriedType(queried) { }
217921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  explicit ArrayTypeTraitExpr(EmptyShell Empty)
218221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
218321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      QueriedType() { }
218421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218525aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek  virtual ~ArrayTypeTraitExpr() { }
218625aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek
2187aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
2188ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return SourceRange(Loc, RParen);
2189ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
219021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
219221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  QualType getQueriedType() const { return QueriedType->getType(); }
219421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
219621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
219821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *getDimensionExpression() const { return Dimension; }
220021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
220121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const Stmt *T) {
220221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return T->getStmtClass() == ArrayTypeTraitExprClass;
220321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
220421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const ArrayTypeTraitExpr *) { return true; }
220521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
220621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Iterators
220721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  child_range children() { return child_range(); }
220821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
220921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  friend class ASTStmtReader;
221021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley};
221121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
22120982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An expression trait intrinsic.
22130982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
2214552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example:
22150982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
22160982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(std::cout) == true
22170982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(1) == false
22180982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
2219552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr {
22200982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned.
2221552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  unsigned ET : 31;
22220982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
2223552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool Value : 1;
2224552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22250982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
2226552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation Loc;
2227552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22280982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
2229552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation RParen;
2230552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22310982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The expression being queried.
2232552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr* QueriedExpression;
2233552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic:
2234ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2235552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     Expr *queried, bool value,
2236552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     SourceLocation rparen, QualType resultType)
2237552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2238552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           false, // Not type-dependent
2239552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           // Value-dependent if the argument is type-dependent.
2240552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->isTypeDependent(),
2241561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->isInstantiationDependent(),
2242552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->containsUnexpandedParameterPack()),
2243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      ET(et), Value(value), Loc(loc), RParen(rparen),
2244ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      QueriedExpression(queried) { }
2245552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2246552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  explicit ExpressionTraitExpr(EmptyShell Empty)
2247552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2248552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      QueriedExpression() { }
2249552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22500982205bade2fb4fc984c27b2ab401e683963b10James Dennett  SourceRange getSourceRange() const LLVM_READONLY {
22510982205bade2fb4fc984c27b2ab401e683963b10James Dennett    return SourceRange(Loc, RParen);
22520982205bade2fb4fc984c27b2ab401e683963b10James Dennett  }
2253552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2254552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2255552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2256552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr *getQueriedExpression() const { return QueriedExpression; }
2257552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2258552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool getValue() const { return Value; }
2259552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2260552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const Stmt *T) {
2261552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return T->getStmtClass() == ExpressionTraitExprClass;
2262552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
2263552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const ExpressionTraitExpr *) { return true; }
2264552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2265552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  // Iterators
2266552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  child_range children() { return child_range(); }
2267552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2268552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  friend class ASTStmtReader;
2269552622067dc45013d240f73952fece703f5e63bdJohn Wiegley};
2270552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2271552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22727bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
2273809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
22747bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
22750982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The common name of these declarations.
2276d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  DeclarationNameInfo NameInfo;
2277d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2278d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  /// \brief The nested-name-specifier that qualifies the name, if any.
2279d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  NestedNameSpecifierLoc QualifierLoc;
2280d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2281ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
22827bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
22837bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
2284928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
2285928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
2286928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
2287ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2288a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
2289e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2290e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2291e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2292e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2293e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2294e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2295e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2296e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2297e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2298e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2299e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
23007bb12da2b0749eeebb21854c77877736969e59f2John McCall
2301bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
23024c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
2303e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara               SourceLocation TemplateKWLoc,
23042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
2305bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
2306bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2307561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownDependent,
2308561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownInstantiationDependent,
2309561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownContainsUnexpandedParameterPack);
23107bb12da2b0749eeebb21854c77877736969e59f2John McCall
2311a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
2312d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer    : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2313d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      HasTemplateKWAndArgsInfo(false) { }
2314a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2315bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
2316bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
2317bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
23187bb12da2b0749eeebb21854c77877736969e59f2John McCall
2319bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
23209c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
23219c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
23229c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
23239c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
23249c72c6088d591ace8503b842d39448c2040f3033John McCall  };
23259c72c6088d591ace8503b842d39448c2040f3033John McCall
23267bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
23277bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
23287bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
23299c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
23309c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
23319c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
23327bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
23337bb12da2b0749eeebb21854c77877736969e59f2John McCall
23349c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
23359c72c6088d591ace8503b842d39448c2040f3033John McCall
23367bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
23379c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
23389c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
23399c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
23409c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
23419c72c6088d591ace8503b842d39448c2040f3033John McCall
23429c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
23439c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
23449c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
23459c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
23469c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
23479c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
23489c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
23499c72c6088d591ace8503b842d39448c2040f3033John McCall    }
23509c72c6088d591ace8503b842d39448c2040f3033John McCall
23519c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
23527bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
23537bb12da2b0749eeebb21854c77877736969e59f2John McCall
23540982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the naming class of this lookup, if any.
2355e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
2356e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
23577bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
2358928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2359ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  decls_iterator decls_end() const {
2360928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
2361928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
2362ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
23630982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the number of declarations in the unresolved set.
2364928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
23657bb12da2b0749eeebb21854c77877736969e59f2John McCall
23660982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the full name info.
23672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
23682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
23690982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the name looked up.
23702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
23717bb12da2b0749eeebb21854c77877736969e59f2John McCall
23720982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the location of the name.
23732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
23747bb12da2b0749eeebb21854c77877736969e59f2John McCall
23750982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier, if one was given.
2376ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
23784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
23797bb12da2b0749eeebb21854c77877736969e59f2John McCall
23800982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier with source-location
23810982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// information, if one was given.
23824c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
23837bb12da2b0749eeebb21854c77877736969e59f2John McCall
2384e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2385e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2386e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2387e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2388e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2389e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2390e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2391e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2392e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2393e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2394e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2397e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2398e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2399e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2400e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2402e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2403e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
24047bb12da2b0749eeebb21854c77877736969e59f2John McCall
24050982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether the name was preceded by the template keyword.
2406e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
24080982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether this expression had explicit template arguments.
2409e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2410e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2411e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // Note that, inconsistently with the explicit-template-argument AST
2412e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // nodes, users are *forbidden* from calling these methods on objects
2413e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // without explicit template arguments.
2414e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2415e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2416e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
2417e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
2418e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
24197bb12da2b0749eeebb21854c77877736969e59f2John McCall
2420b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
24217bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
24227bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24237bb12da2b0749eeebb21854c77877736969e59f2John McCall
2424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  TemplateArgumentLoc const *getTemplateArgs() const {
2425e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().getTemplateArgs();
2426e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2427e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2428e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  unsigned getNumTemplateArgs() const {
2429e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().NumTemplateArgs;
2430e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2431e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
24320982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Copies the template arguments into the given structure.
2433e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2434e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    getExplicitTemplateArgs().copyInto(List);
2435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2436e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2437096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
24380982205bade2fb4fc984c27b2ab401e683963b10James Dennett  ///
2439096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2440096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2441b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2442096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2443096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
24447bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24457bb12da2b0749eeebb21854c77877736969e59f2John McCall
24467bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
24477bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
24487bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
24497bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24507bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
24514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
24524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
24534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
24547bb12da2b0749eeebb21854c77877736969e59f2John McCall};
24557bb12da2b0749eeebb21854c77877736969e59f2John McCall
24567bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
24570982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// parsing but could not resolve to a specific declaration.
24580982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
24590982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// This arises in several ways:
24607bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
24617bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
24627bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
24637bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
24640982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// These never include UnresolvedUsingValueDecls, which are always class
24650982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// members and therefore appear only in UnresolvedMemberLookupExprs.
24667bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
2467ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
2468ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
2469ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
2470ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
2471ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2472ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// True if namespace ::std should be considered an associated namespace
2473ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
2474ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool StdIsAssociatedNamespace;
2475ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
24767453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
24777453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
24787453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
24797453ed4cb2cab113de3378df371b1c6f1243d832John McCall
24807bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
24817bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
24827bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
24837bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
24847bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
24857bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
2486f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2487ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnresolvedLookupExpr(ASTContext &C,
2488928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
24894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
2490e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
24912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
2492ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                       bool RequiresADL, bool Overloaded,
2493bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
2494ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2495ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       bool StdIsAssociatedNamespace)
2496e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2497e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                   NameInfo, TemplateArgs, Begin, End, false, false, false),
2498ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(RequiresADL),
2499ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      StdIsAssociatedNamespace(StdIsAssociatedNamespace),
2500ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Overloaded(Overloaded), NamingClass(NamingClass)
2501ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
2502ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2503bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
2504bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
2505ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
2506ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      NamingClass(0)
2507bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
2508bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
25094c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
2510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2511ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
2512ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2513c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
25144c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
25152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
25165a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
2517ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
2518ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      UnresolvedSetIterator End,
2519ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      bool StdIsAssociatedNamespace = false) {
2520ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    assert((ADL || !StdIsAssociatedNamespace) &&
2521ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith           "std considered associated namespace when not performing ADL");
2522e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2523e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SourceLocation(), NameInfo,
2524ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       ADL, Overloaded, 0, Begin, End,
2525ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       StdIsAssociatedNamespace);
2526ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2527ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2528f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2529c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
25304c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
2531e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                      SourceLocation TemplateKWLoc,
25322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
2533f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
25349d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                      const TemplateArgumentListInfo *Args,
2535ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
25365a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
2537f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2538bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2539e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           bool HasTemplateKWAndArgsInfo,
2540bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
2541bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
2542ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
2543ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
2544ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
2545ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2546f977848850a2f8785dc2b37c735afe0cd223b8bbJames Dennett  /// True if namespace \::std should be artificially added to the set of
2547f977848850a2f8785dc2b37c735afe0cd223b8bbJames Dennett  /// associated namespaces for argument-dependent lookup purposes.
2548ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
2549ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
25507453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
25517453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
25527453ed4cb2cab113de3378df371b1c6f1243d832John McCall
2553c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
2554c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
2555c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
2556c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
2557c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
2558aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
25592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range(getNameInfo().getSourceRange());
2560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (getQualifierLoc())
25614c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2562ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (hasExplicitTemplateArgs())
25634c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setEnd(getRAngleLoc());
2564f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
2565ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2566ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
256763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2568ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2569ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
2570ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
2571ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2572ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
2573ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
2574ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
25755953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
25765953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
25775953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
2578ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
25805953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
2581865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
25825953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
25835953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
25845953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
2585865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2586ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
2587a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2588a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
2589865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
2590ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
2591ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
259200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
2593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
259400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
259500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
25965953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
2597e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2598e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2599e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2600e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2601e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2602e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2603e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2604e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2605e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2606e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2607e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2608e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<DependentScopeDeclRefExpr*>(this)
2609e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2610e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
26111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2612f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
261300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
2614e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                            SourceLocation TemplateKWLoc,
26152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
2616bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
2617f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2618f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
2619f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
262000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2621e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           SourceLocation TemplateKWLoc,
26222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
2623e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                              const TemplateArgumentListInfo *TemplateArgs);
26245953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
262512dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2626e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                bool HasTemplateKWAndArgsInfo,
262712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
262812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
26295953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
26302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
26312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
26322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
26332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
26345953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
26355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
26362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
26375953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
263800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
263900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
264000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2643ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
2644ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
2645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
264700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
26481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2649e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2650e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2651e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2652e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2653e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2654e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2655e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2656e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2657e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2658e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2659e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2660e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2661e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2662e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2663e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2664e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2665e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2666e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2667e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2668e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2669e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2670e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the name was preceded by the template keyword.
2671e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2672e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2673f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
2674e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
26751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2676f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
2677f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
2678f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2680b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
268112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
2682b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
268312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
268412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
2685f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
2686b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2687f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
2688b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2689f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
26901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2691096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2692096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2693096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2694b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2695096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2696096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2697096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2698096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2699f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
2700f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
2701f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2702f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
2703f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
2704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2705f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
2706f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2707d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2708d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2709f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
2710f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2711f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
27121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2713aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
271400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2715f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
2716f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
2717f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
2718edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2721f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2722edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
2723f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2724f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
272563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
27264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
27274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
27284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
2729edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
27301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27314765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
27324765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
27334765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
273480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of
273580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every
273680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer.
273780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall///
273880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a
273980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal.  The lifetime of a block
274080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope.
27414765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
274280ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic:
274380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// The type of objects that are kept in the cleanup.
274480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// It's useful to remember the set of blocks;  we could also
274580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// remember the set of temporaries, but there's currently
274680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// no need.
274780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  typedef BlockDecl *CleanupObject;
274880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
274980ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate:
275002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
27511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
275280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(EmptyShell, unsigned NumObjects);
275380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
275402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
275580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject *getObjectsBuffer() {
275680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<CleanupObject*>(this + 1);
275780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
275880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  const CleanupObject *getObjectsBuffer() const {
275980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<const CleanupObject*>(this + 1);
276080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
276180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  friend class ASTStmtReader;
2762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
276388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
276480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
276580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  unsigned numObjects);
27661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
276780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
276880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  ArrayRef<CleanupObject> objects);
2769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
277080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ArrayRef<CleanupObject> getObjects() const {
277180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2772f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
277380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
277480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
277580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
277680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject getObject(unsigned i) const {
277780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    assert(i < getNumObjects() && "Index out of range");
277880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return getObjects()[i];
2779d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
27801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
278102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2782f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
278380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
278480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// setSubExpr - As with any mutator of the AST, be very careful
278580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// when modifying an existing AST to preserve its invariants.
278688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
278702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2788aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
278996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
279096be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
279102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
279202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
279302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
27944765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
279502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
27964765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static bool classof(const ExprWithCleanups *) { return true; }
279702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
279802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
279963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
280002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
280102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2802d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2803d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2804d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2805d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2806d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2807fe865f1f35d1b91f42f58f08a1399b961b71b3bcJames Dennett/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
28080982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
28090982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2810d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2811d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2812d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2813d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2814d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2815d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2816d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2817d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2818d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2819d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2820d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2821d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2822d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2823d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2824d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2825ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2827d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2828d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2829d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2830d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2831d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2832d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2833d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2834d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2836ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2837d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
28383b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                             ArrayRef<Expr*> Args,
2839d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2840d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28418dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2842ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
28438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2844ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2845ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2846d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2848ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2849d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
28503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                            ArrayRef<Expr*> Args,
2851d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2852d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28538dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
28548dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
28558dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2856d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2857d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2858ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2859d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the type source information for the type being
2861ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2862ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2864d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2865d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2866d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2867d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2868d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2869d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2870d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2871d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2872d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2873d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2874d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2875d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2876d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2877d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2878d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2879d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2880d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28811dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
28821dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
28831dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
28841dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28851dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
28861dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
28871dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28881dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2889d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2890d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2891d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2892d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2893d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28941dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
28951dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
28961dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
28971dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28981dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
28998dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
29008dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
29018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
29028dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
29038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2904aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
2905ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
29061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2907d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2908d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2909d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2910d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2911d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
291263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
291363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
291463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
291563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2916d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2917d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2918ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2919ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2920ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2921aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2922aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2923aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2924aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2925865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
29261c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2927aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
29281c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
29291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2930aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2931aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2932aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2933aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
29351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
29363b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
29371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2938e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether this member expression has info for explicit template
2939e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2940e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo : 1;
29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
29431c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
29441c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2945a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
29467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2948c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
29491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2950c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2951c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
295246bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
2953c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2954865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2955c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
29581c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2959a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
29602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
29611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2962e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2963e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2964e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2965e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2966e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2967e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2968e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2969e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<CXXDependentScopeMemberExpr*>(this)
2970e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2971e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2972e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2973865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
29753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
29767c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
2977e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                          SourceLocation TemplateKWLoc,
29783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
29792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2980d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
29811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2983865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2984bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2985bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2986bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
29877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2988bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2989bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
29901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2991865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
29921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2993aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
29943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
29957c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
2996e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
29973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
29982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2999d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
30001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
3002e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3003def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
30048dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
3005aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
3006aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
3007aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
30084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3009aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
30101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
30111c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
3012aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
3013aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3014aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3015aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
30161c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3017aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3018aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
30191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
30201c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
30211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
30221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
30231c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
30241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
30251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3026a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
3027a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
3028ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
3029ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
30307c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
30311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30327c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
30337c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
30347c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3035ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3036ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3037c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
3038c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
3039c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
3040c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
3041c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
30421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
30431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
3044c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
3045c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
3046c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
3047c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
30481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
3049c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
3050c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30521c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
30531c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
30542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
30552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
30562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
30572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
30582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
30592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
30602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
30611c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
30621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
30631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
30642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
30651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3066e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding the
3067e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// member name, if any.
3068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
3069e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3070e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3071e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3072e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3073e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
3074e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3075e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
3076e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3077e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
3078e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3079e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3080e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
3081e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3082e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
3083e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3084e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
3085e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3086e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3087e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the member name was preceded by the template keyword.
3088e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3089e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
30903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
30913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
3092e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
30931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
309436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
309536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3096b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3097e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
3098b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
309936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
310036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
310136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
310236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3103b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
310436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
3105096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
3106096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
3107096832c5ed5b9106fa177ebc148489760c3bc496John McCall
3108096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
3109096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
3110096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
3111b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
3112096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
3113096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
311436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
311536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
3116d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
3117d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
3118d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3119096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
3120d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
3121d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
31228dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
31238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3124096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
31258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
31268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
31273b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
31283b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
3129833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
3130096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
31313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
31321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31333b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
31343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
31351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
3136096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
31373b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3139aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3140aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
3141aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
3142aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
3143aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
31447c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
3145aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
31462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setBegin(MemberNameInfo.getBeginLoc());
31471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3148aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
3149aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
3150aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
31512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setEnd(MemberNameInfo.getEndLoc());
3152aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
31531c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
31541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3156865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
31571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
3158865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
31591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
31601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
316163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
316263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
316363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
316463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
31654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
31664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
31674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
31681c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
31691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3170129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
3171aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
3172aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3173aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
3174aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
3175aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
3176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
3177aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
3178aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
3179aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3180aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
3181aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
3182aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
31837bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
3184129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
3185129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
3186129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
3187129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3188129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
3189129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
3190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
3191129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
31927bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
31937bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
31947bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
31957bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
31967bb12da2b0749eeebb21854c77877736969e59f2John McCall
31977bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
31987bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
3199129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
3201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
3202129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3203bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3204aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
3205129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
32064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
3207e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
32082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
32095a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
32105a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3211ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3212a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
3213a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3214a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
3215129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
32164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
3217ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3218129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
3219129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
3220bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
3221aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
3222129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
32234c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
3224e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
32252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
32265a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
32275a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3229a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
3230e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3231def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
3232a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3233aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
3234aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
3235aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
32364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3237aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3238129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
3239129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
3240aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
3241aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3242aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3243aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
32442f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
32452f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
32462f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
32472f27bf854f0519810b34afd209089cc75536b757John McCall  }
3248129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3249aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3250a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3251a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
3252a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
3253a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3254aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3255129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
3256129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
3257129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
3258129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3259129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
3260129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3261129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3262c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
3263c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
3264c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
32652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
32662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
32672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
32682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
3269129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
3270129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
32717bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
3272129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3273129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
3274129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
32757bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
3276129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3277aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
32782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range = getMemberNameInfo().getSourceRange();
3279aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
3280aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
32814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    else if (getQualifierLoc())
32824c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
3283aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3284129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
3285129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
3286129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
3287129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3288129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3289129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
3290129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
3291129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3292129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
3293129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3294129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
329563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
329663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
329763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
329863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3299129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
3300129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
33012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
33022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
33032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
33042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
33052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
33062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
33072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
33082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
33092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3310c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
3311c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
33122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
33132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
33142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
3315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
3317bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
3318561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Val == CT_Dependent || Operand->isInstantiationDependent(),
3319bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
33206b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
33216b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
33226b219d082434394c1ac401390ec1d1967727815aSebastian Redl
33236b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
33246b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
33252e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
33262e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33272e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
33282e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3329aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
33302e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33312e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
33322e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33332e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
33342e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
33352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
33362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const CXXNoexceptExpr *) { return true; }
33372e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33382e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
333963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
33402e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
33412e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3342ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of
3343be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
3344be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3345be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
3346be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
3347be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3348be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
3349be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
3350be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
3351be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
3352be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
3353be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
3354be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3355be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
3356ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function
3357be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
3358be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
3359be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
3360be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
3361ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
336267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
336367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
336467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
336567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
336667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
336767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
3368ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3369be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
3370ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3371be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
337267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
3373ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3374be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
337567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
337667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                    llvm::Optional<unsigned> NumExpansions)
3377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3378ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           Pattern->getObjectKind(), /*TypeDependent=*/true,
3379561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3380561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3381be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
338267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3383be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
3384be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3385be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3387be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3388be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3389be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3390be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3391be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3392be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3393be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
3394be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
3395be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3396ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the number of expansions that will be produced when
339867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
339967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
340067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
340167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
3402ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
340367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return llvm::Optional<unsigned>();
340467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
3405ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3406aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
340763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
340863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3409be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3410be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
3411be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
3412be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
3413be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const PackExpansionExpr *) { return true; }
3414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3415be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
341663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
341763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
341863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3419be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
3420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3421e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3422e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  if (!HasTemplateKWAndArgsInfo) return 0;
34237bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
3424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3425e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedLookupExpr>(this) + 1);
34267bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
3427e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3428e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedMemberExpr>(this) + 1);
34297bb12da2b0749eeebb21854c77877736969e59f2John McCall}
34307bb12da2b0749eeebb21854c77877736969e59f2John McCall
3431ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter
3432ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
3433ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
3434ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
3435ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
3436ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
3437ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
3438ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
3439ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
3440ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
3441ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
3442ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
3443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3444ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
3445ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
3446ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3447ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
3448ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
3449ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3450ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
3451ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3452ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
3453ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
3454ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
3455ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
3456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3457ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
3458ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
3459ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3460ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
3461ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
3462ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3463ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
3464ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
3465ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
3466ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3467ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
3468ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3469ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
3470561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3471ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3472ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3473ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
3474ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3475ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
3476ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
3477ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3478ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
3479ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
3480ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3481ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
3482561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         /*InstantiationDependent=*/false,
3483ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
3484ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3485ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
3486ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3487ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
3488ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3489ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3490ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
3491ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3492ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3493ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
3494ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
3495ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3496ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
3497ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3499ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
3500ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
3501ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3502ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
3503ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3504ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This routine may only be invoked when the expression is not
3505c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
3506ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
3507ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!isValueDependent() &&
3508ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
3509ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
3510ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3511ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3512aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
351363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(OperatorLoc, RParenLoc);
351463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3515ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3516ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
3517ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
3518ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3519ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const SizeOfPackExpr *) { return true; }
3520ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3521ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
352263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3523ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
3524c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
352591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter
352691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument.
352791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr {
352891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replaced parameter.
352991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *Param;
353091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
353191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replacement expression.
353291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Stmt *Replacement;
353391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
353491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The location of the non-type template parameter reference.
353591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation NameLoc;
353691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
35377110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
35387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
3539ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
35407110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
35417110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
354291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic:
3543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmExpr(QualType type,
354491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               ExprValueKind valueKind,
354591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               SourceLocation loc,
354691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               NonTypeTemplateParmDecl *param,
354791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               Expr *replacement)
354891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
354991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isTypeDependent(), replacement->isValueDependent(),
355091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isInstantiationDependent(),
355191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->containsUnexpandedParameterPack()),
355291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall      Param(param), Replacement(replacement), NameLoc(loc) {}
355391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
355491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation getNameLoc() const { return NameLoc; }
3555aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
355691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
355791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Expr *getReplacement() const { return cast<Expr>(Replacement); }
3558ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
355991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *getParameter() const { return Param; }
356091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
356191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  static bool classof(const Stmt *s) {
356291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
356391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const SubstNonTypeTemplateParmExpr *) {
3565ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
356691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
356891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Iterators
356991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  child_range children() { return child_range(&Replacement, &Replacement+1); }
357091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall};
357191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
3572c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
3573c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
3574c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
3575c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3576c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
3577fb7669ee725ec699e2b49b8359c4652536949739Douglas Gregor/// parameter lists, this node is used to represent a non-type template
3578c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3579c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3580c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3581c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3582c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
3583c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
3584c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
3585c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
3586c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
3587ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3588c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3589c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
3590c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
3591ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3592c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3593c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
3594ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3595c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
3596c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
3597ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
35987110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
3599c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
3600ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
36017110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3602ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3603c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
3604ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmPackExpr(QualType T,
3605c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
3606c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
3607c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
3608ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3609c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
3610c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3611c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3612c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
3613c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
3614ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3615c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
3616c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
3617c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
3618c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3619aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3621c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
3622c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3623c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
3626c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3628c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
362963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3630c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
363103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
36329a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \brief Represents a reference to a function parameter pack that has been
36339a4db032ecd991626d236a502e770126db32bd31Richard Smith/// substituted but not yet expanded.
36349a4db032ecd991626d236a502e770126db32bd31Richard Smith///
36359a4db032ecd991626d236a502e770126db32bd31Richard Smith/// When a pack expansion contains multiple parameter packs at different levels,
36369a4db032ecd991626d236a502e770126db32bd31Richard Smith/// this node is used to represent a function parameter pack at an outer level
36379a4db032ecd991626d236a502e770126db32bd31Richard Smith/// which we have already substituted to refer to expanded parameters, but where
36389a4db032ecd991626d236a502e770126db32bd31Richard Smith/// the containing pack expansion cannot yet be expanded.
36399a4db032ecd991626d236a502e770126db32bd31Richard Smith///
36409a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \code
36419a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Ts> struct S {
36429a4db032ecd991626d236a502e770126db32bd31Richard Smith///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
36439a4db032ecd991626d236a502e770126db32bd31Richard Smith/// };
36449a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template struct S<int, int>;
36459a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \endcode
36469a4db032ecd991626d236a502e770126db32bd31Richard Smithclass FunctionParmPackExpr : public Expr {
36479a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The function parameter pack which was referenced.
36489a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *ParamPack;
36499a4db032ecd991626d236a502e770126db32bd31Richard Smith
36509a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The location of the function parameter pack reference.
36519a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation NameLoc;
36529a4db032ecd991626d236a502e770126db32bd31Richard Smith
36539a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The number of expansions of this pack.
36549a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned NumParameters;
36559a4db032ecd991626d236a502e770126db32bd31Richard Smith
36569a4db032ecd991626d236a502e770126db32bd31Richard Smith  FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
36579a4db032ecd991626d236a502e770126db32bd31Richard Smith                       SourceLocation NameLoc, unsigned NumParams,
36589a4db032ecd991626d236a502e770126db32bd31Richard Smith                       Decl * const *Params);
36599a4db032ecd991626d236a502e770126db32bd31Richard Smith
36609a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTReader;
36619a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTStmtReader;
36629a4db032ecd991626d236a502e770126db32bd31Richard Smith
36639a4db032ecd991626d236a502e770126db32bd31Richard Smithpublic:
36649a4db032ecd991626d236a502e770126db32bd31Richard Smith  static FunctionParmPackExpr *Create(ASTContext &Context, QualType T,
36659a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      ParmVarDecl *ParamPack,
36669a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      SourceLocation NameLoc,
36679a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      llvm::ArrayRef<Decl*> Params);
36689a4db032ecd991626d236a502e770126db32bd31Richard Smith  static FunctionParmPackExpr *CreateEmpty(ASTContext &Context,
36699a4db032ecd991626d236a502e770126db32bd31Richard Smith                                           unsigned NumParams);
36709a4db032ecd991626d236a502e770126db32bd31Richard Smith
36719a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the parameter pack which this expression refers to.
36729a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getParameterPack() const { return ParamPack; }
36739a4db032ecd991626d236a502e770126db32bd31Richard Smith
36749a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the location of the parameter pack.
36759a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation getParameterPackLocation() const { return NameLoc; }
36769a4db032ecd991626d236a502e770126db32bd31Richard Smith
36779a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Iterators over the parameters which the parameter pack expanded
36789a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// into.
36799a4db032ecd991626d236a502e770126db32bd31Richard Smith  typedef ParmVarDecl * const *iterator;
36809a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator begin() const { return reinterpret_cast<iterator>(this+1); }
36819a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator end() const { return begin() + NumParameters; }
36829a4db032ecd991626d236a502e770126db32bd31Richard Smith
36839a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the number of parameters in this parameter pack.
36849a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned getNumExpansions() const { return NumParameters; }
36859a4db032ecd991626d236a502e770126db32bd31Richard Smith
36869a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get an expansion of the parameter pack by index.
36879a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
36889a4db032ecd991626d236a502e770126db32bd31Richard Smith
36899a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
36909a4db032ecd991626d236a502e770126db32bd31Richard Smith
36919a4db032ecd991626d236a502e770126db32bd31Richard Smith  static bool classof(const Stmt *T) {
36929a4db032ecd991626d236a502e770126db32bd31Richard Smith    return T->getStmtClass() == FunctionParmPackExprClass;
36939a4db032ecd991626d236a502e770126db32bd31Richard Smith  }
36949a4db032ecd991626d236a502e770126db32bd31Richard Smith  static bool classof(const FunctionParmPackExpr *) { return true; }
36959a4db032ecd991626d236a502e770126db32bd31Richard Smith
36969a4db032ecd991626d236a502e770126db32bd31Richard Smith  child_range children() { return child_range(); }
36979a4db032ecd991626d236a502e770126db32bd31Richard Smith};
36989a4db032ecd991626d236a502e770126db32bd31Richard Smith
369903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that
370003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it.
370103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
370203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address
370303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a
370403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g.,
370503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
370603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code
370703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0;
370803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode
370903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
371003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
371103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference
371203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
371303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding
371403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues.
371503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr {
371603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief The temporary-generating expression whose value will be
371703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// materialized.
3718d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Temporary;
3719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
372003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtReader;
372103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtWriter;
3722ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
372303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic:
3724ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3725b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor                           bool BoundToLvalueReference)
3726b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor    : Expr(MaterializeTemporaryExprClass, T,
372703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
372803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->isTypeDependent(), Temporary->isValueDependent(),
3729561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Temporary->isInstantiationDependent(),
373003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->containsUnexpandedParameterPack()),
373103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor      Temporary(Temporary) { }
3732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3733ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(EmptyShell Empty)
373403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    : Expr(MaterializeTemporaryExprClass, Empty) { }
3735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
373603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Retrieve the temporary-generating subexpression whose value will
373703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// be materialized into a glvalue.
373803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3739ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
374003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Determine whether this materialized temporary is bound to an
374103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// lvalue reference; otherwise, it's bound to an rvalue reference.
3742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isBoundToLvalueReference() const {
374303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return getValueKind() == VK_LValue;
374403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3746aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3747aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar    return Temporary->getSourceRange();
3748aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  }
3749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
375003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  static bool classof(const Stmt *T) {
375103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return T->getStmtClass() == MaterializeTemporaryExprClass;
375203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const MaterializeTemporaryExpr *) {
3754ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
375503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
375703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  // Iterators
375803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  child_range children() { return child_range(&Temporary, &Temporary + 1); }
375903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor};
3760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
37615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
37625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
37635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3764