ExprCXX.h revision 66874fb18afbffb8b2ca05576851a64534be3352
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"
19d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/UnresolvedSet.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;
332fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass UuidAttr;
344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
52b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
53063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
54063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
554548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange Range;
56063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
57be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Record the FP_CONTRACT state that applies to this operator call. Only
58be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // meaningful for floating point types. For other types this value can be
59be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // set to false.
60be9af1288881110e406b87914162eaa59f1e5918Lang Hames  unsigned FPContractable : 1;
61be9af1288881110e406b87914162eaa59f1e5918Lang Hames
624548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRangeImpl() const LLVM_READONLY;
63b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                      ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
66be9af1288881110e406b87914162eaa59f1e5918Lang Hames                      SourceLocation operatorloc, bool fpContractable)
673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK,
68f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
69be9af1288881110e406b87914162eaa59f1e5918Lang Hames      Operator(Op), FPContractable(fpContractable) {
704548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis    Range = getSourceRangeImpl();
714548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  }
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
73ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
76b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
77b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
78063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
84b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
85b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
86b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
8865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
894548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  SourceRange getSourceRange() const { return Range; }
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
93b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
944548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis
95be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Set the FP contractability status of this operator. Only meaningful for
96be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
97be9af1288881110e406b87914162eaa59f1e5918Lang Hames  void setFPContractable(bool FPC) { FPContractable = FPC; }
98be9af1288881110e406b87914162eaa59f1e5918Lang Hames
99be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // Get the FP contractability status of this operator. Only meaningful for
100be9af1288881110e406b87914162eaa59f1e5918Lang Hames  // operations on floating point types.
101be9af1288881110e406b87914162eaa59f1e5918Lang Hames  bool isFPContractable() const { return FPContractable; }
102be9af1288881110e406b87914162eaa59f1e5918Lang Hames
1034548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtReader;
1044548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis  friend class ASTStmtWriter;
105b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
106b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
10788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
11188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
11588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
1173b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer  CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args,
118f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
1193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {}
12088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
1211817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
1221817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
1231817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
12488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
12588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
12688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
127b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
129b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  /// Retrieves the declaration of the called method.
130b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
13188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
132007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
133007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
134007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
135007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
136007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
1370cf3c0eecbff007cea2750c113894b47d9e09f33David Blaikie  CXXRecordDecl *getRecordDecl() const;
138007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
14188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
14288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
14388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
1513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
1523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                     SourceLocation RP)
1533b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) {
154e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
155e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
156e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
157e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
158e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
159e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
160e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
161e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
162e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
163e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
164e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
165e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
166e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
167e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
168e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
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
20665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
20765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
20865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
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};
22149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
222ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression
223ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]).
2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
228f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
229f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2301d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
231f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2321d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
234f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
235f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
239f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
241ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   TypeSourceInfo *Written, SourceLocation L,
2421d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
243f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
245ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
24749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
24849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
24949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
25049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
25149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
25349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
25649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
25749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
258f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
259f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2601d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
261f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2621d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
264f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
265f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
266f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
267f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
268f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
269f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
270f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                    TypeSourceInfo *Written, SourceLocation L,
2721d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
273ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
274f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
275f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
276ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2770fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2780fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
28049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
28149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
28249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
28349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
28449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
28549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
28649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
28949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
29049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
291f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
292f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
293ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                         TypeSourceInfo *writtenTy, SourceLocation l,
2941d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
295f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2961d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
298f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
299f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
300f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
301f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
302f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
303f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
304f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
305ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                 TypeSourceInfo *WrittenTy, SourceLocation L,
3061d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
307f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
308f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
309ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
31249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
31349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
31449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
31549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
31649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
31849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
31949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
32049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
322ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   TypeSourceInfo *writtenTy, SourceLocation l,
3231d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3251d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
32649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
327ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
328f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
329f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
330f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
331f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
332f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
333ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3341d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
335f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
336ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
33949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
3401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3429fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
3439fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]).
3449fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3459fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
3469fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better
3479fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal.
3489fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3499fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at
3509fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent.
3519fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr {
3529fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// \brief The location of a ud-suffix within the literal.
3539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  SourceLocation UDSuffixLoc;
3549fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic:
3563b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer  UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args,
3579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
3589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     SourceLocation SuffixLoc)
3593b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer    : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc),
3603b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer      UDSuffixLoc(SuffixLoc) {}
3619fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    : CallExpr(C, UserDefinedLiteralClass, Empty) {}
3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// The kind of literal operator which is invoked.
3659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  enum LiteralOperatorKind {
3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Raw,      ///< Raw form: operator "" X (const char *)
3679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Template, ///< Raw form: operator "" X<cs...> ()
3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Integer,  ///< operator "" X (unsigned long long)
3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Floating, ///< operator "" X (long double)
3709fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_String,   ///< operator "" X (const CharT *, size_t)
3719fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Character ///< operator "" X (CharT)
3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  };
3739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3749fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getLiteralOperatorKind - Returns the kind of literal operator invocation
3759fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// which this expression represents.
3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  LiteralOperatorKind getLiteralOperatorKind() const;
3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getCookedLiteral - If this is not a raw user-defined literal, get the
3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// underlying cooked literal (representing the literal with the suffix
3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// removed).
3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  Expr *getCookedLiteral();
3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const Expr *getCookedLiteral() const {
3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
3849fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
3859fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3860265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocStart() const {
3870265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    if (getLiteralOperatorKind() == LOK_Template)
3880265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara      return getRParenLoc();
3890265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara    return getArg(0)->getLocStart();
3900265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  }
3910265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getLocEnd() const { return getRParenLoc(); }
3920265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
3930265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara
3949fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
3959fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// For a string literal, there may be multiple identical suffixes. This
3969fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// returns the first.
3970265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara  SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; }
3989fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3999fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffix - Returns the ud-suffix specified for this literal.
4009fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const IdentifierInfo *getUDSuffix() const;
4019fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4029fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const Stmt *S) {
4039fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return S->getStmtClass() == UserDefinedLiteralClass;
4049fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
4059fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4069fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtReader;
4079fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtWriter;
4089fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith};
4099fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
4101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
4121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
4131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
4141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
4151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
417bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
418561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
419f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
4208b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
421eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
422eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
423eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
425eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
42765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
42865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
430eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
431eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
432eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
4351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
43863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
4401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4416e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
4426e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
4436e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
4446e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
4456e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
446bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
447561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
448f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
4496e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
450eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
451eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
452eb7f96141f754150a92433286fa385910a22f494Sam Weinig
45365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
45465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
4556e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
456eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
457eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
458eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
4606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
4616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
4626e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
46363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
4656e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
466c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
467c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
468c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
469c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
470c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
471c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
472c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
47357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
474c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
475c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
476c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
47757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
478f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
47957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
48057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
48157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
482bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
483561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
48557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
486ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
48757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
488f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
4892850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
490bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
4912850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
492bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
493561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
494bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
49557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
496c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
49714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
49814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
49914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
50014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
50114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
50214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
50314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
504ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5050d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// Determine whether this typeid has a type operand which is potentially
5060d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  /// evaluated, per C++11 [expr.typeid]p3.
5070d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith  bool isPotentiallyEvaluated() const;
5080d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith
50957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
51157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
51257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
51357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
51457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
51557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
51657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
517c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
51857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
519c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
52014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
52114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
52214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
52314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
52414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
525ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
52614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
527c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
52857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
529c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
531030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
532030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
533030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
534030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
535ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
53665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
53765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
538aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
53914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
540ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
541c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
542c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
543c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
544c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
545c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
54663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
54763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
54863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
54963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
55063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
551c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
552c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
55301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
55401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
55501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
55601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
55701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
55801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
55901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
56001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
56101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
56201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
56301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
5642e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
566561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
567bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
56801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
57001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
5712e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
572bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
573561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
574bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
57501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
57601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
57701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
57801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
57901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
58001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
58101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
58201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
58301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
584ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
58501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
586ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
58701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
58801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
58901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
59001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
59101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
59201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
59301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
59401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
59501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
59601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
59701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
59801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
59901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
60001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
601ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
60201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
60301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
60401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
60501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
60701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
60801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
60901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
61001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
61101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
61265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
61365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
614aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
61501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
616ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
61701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
61801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
61901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
62001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
621c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none.
622c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  static UuidAttr *GetUuidAttrOfType(QualType QT);
623c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber
62401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
62563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
62663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
62763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
62863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
62963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
63001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
63101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
632796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
633796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
634796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
635796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
636796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
637796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
638796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
639796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
640796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
641796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
642796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
643796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
644796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
645828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
647796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
648828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
649f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
6502850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
6512850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
652bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
653561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Type->isInstantiationDependentType(),
654bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
655828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
656796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6572fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
6582fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
6592fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
6602fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
6612fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
66265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
66365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
664796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
665828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
666828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
669796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
670796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
671796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
672796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
67363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
674796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
675796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
6771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
6781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
6791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
6801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
6811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
6821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
683bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Whether the thrown variable (if any) is in scope.
684bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  unsigned IsThrownVariableInScope : 1;
685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
686bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  friend class ASTStmtReader;
687ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
6891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
6901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
6911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
692bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
693bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor               bool IsThrownVariableInScope) :
694bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
695561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         expr && expr->isInstantiationDependent(),
696bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
697bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
6982fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
6992fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
7001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
7011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
70242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
70342e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
7041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
705bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Determines whether the variable thrown by this expression (if any!)
706bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// is within the innermost try block.
707bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ///
708bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// This information is required to determine whether the NRVO can apply to
709bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// this variable.
710bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
71265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; }
71365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
7141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
71565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return ThrowLoc;
71665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getSubExpr()->getLocEnd();
7171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
7201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
7211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
72463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
72563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
72663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
7271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
7281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
7301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
7311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
7321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
7331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
73465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
73565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// When the bit is set, the subexpression is stored after the
73765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
73865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
73965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
741036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
742036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
744036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(SC,
74665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
74765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
7482333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
749dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
750561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false, false),
751036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
75265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
754036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
755dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
756dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           false, false, false, false),
758bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
75965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
76065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
761ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7621060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
763030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
764030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
765ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7661060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
7671060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
768036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
769036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
770036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
771f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
7721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
77365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
77465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
775ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static CXXDefaultArgExpr *Create(ASTContext &C,
776036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
777ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   ParmVarDecl *Param,
77865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
779ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
78165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
78265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  const Expr *getExpr() const {
78665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
78765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
78965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
790ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getExpr() {
79165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
79265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
79465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
7951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
796ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the location where this default argument was actually
797036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
798036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
799ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
80065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  // Default argument expressions have no representation in the
80165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  // source, so they have an empty source range.
80265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
80365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
80463b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer
80563b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
8061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
8081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
8091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
8101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
8111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
81263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
8138a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
81460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
8153397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
8161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
817987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
818c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
819c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
820c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
821b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
823b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
824c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
825c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
826c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
828b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
830f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
83176f3f69db1416425070177243e9f390122c553e0Richard Smith  void setDestructor(const CXXDestructorDecl *Dtor) {
83276f3f69db1416425070177243e9f390122c553e0Richard Smith    Destructor = Dtor;
83376f3f69db1416425070177243e9f390122c553e0Richard Smith  }
834c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
835fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
836ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
837ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
838ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
839ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
840ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
841ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
842ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
843ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
844ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
845ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
846ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
847ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
848ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
849ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
850fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
851fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
853fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
854fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
855bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
856bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
857ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
858bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
859561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          SubExpr->isInstantiationDependent(),
860bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
861bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
86288eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
863fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
864d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
865d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
868fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
87088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
871f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
872d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
873f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
874fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
875fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
87688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
877fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
87865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
87965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExpr->getLocStart();
88096be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
88165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
882fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
883fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
884fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
885fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
886fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
887fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
888fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
88963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
890fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
891fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
8920982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a call to a C++ constructor.
89315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
89472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
89572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
89672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
89772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
898059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_VirtualBase,
899059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_Delegating
90072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
901ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
90272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
90315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
90415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
90599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
906428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
907a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor  unsigned NumArgs : 16;
90816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
9097cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool HadMultipleCandidates : 1;
9105b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool ListInitialization : 1;
91116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
91272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
91315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
915bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
91799a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
918bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
9193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                   ArrayRef<Expr *> Args,
9207cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                   bool HadMultipleCandidates,
9215b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ListInitialization,
9225b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ZeroInitialization,
9235b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   ConstructionKind ConstructKind,
9245b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   SourceRange ParenRange);
925bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
9266d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
9276d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
9285b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl    : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
9295b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      HadMultipleCandidates(false), ListInitialization(false),
9305b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ZeroInitialization(false), ConstructKind(0), Args(0)
9315b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
93315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
9346d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
9356d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
9366d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
9375b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      NumArgs(0), Elidable(false), HadMultipleCandidates(false),
9385b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ListInitialization(false), ZeroInitialization(false),
9395b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ConstructKind(0), Args(0)
9405b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9416d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
9428e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
94399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
9453b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                  ArrayRef<Expr *> Args,
9467cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                  bool HadMultipleCandidates,
9475b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ListInitialization,
9485b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ZeroInitialization,
9495b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  ConstructionKind ConstructKind,
9505b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  SourceRange ParenRange);
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
952d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
95339da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
954ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
95599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
95699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
957ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
958d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
959d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
96039da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
9617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Whether the referred constructor was resolved from
9637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// an overloaded set having size greater than 1.
9647cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
9657cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
9667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9675b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  /// \brief Whether this constructor call was written as list-initialization.
9685b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool isListInitialization() const { return ListInitialization; }
9695b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  void setListInitialization(bool V) { ListInitialization = V; }
9705b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
97116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
97216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
97316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
97416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
97516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
97616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
977ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9789db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
9799db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
98024eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
98124eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
98272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
983ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setConstructionKind(ConstructionKind CK) {
98472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
98572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
986ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
98715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
98815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
99115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
99215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
99315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
99415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
995a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
99615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
99715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
998bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
999bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
1000bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1001bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1002bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
1003bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
1004bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
1005bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
1006bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
10071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10082eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
10092eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
10102eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
10112eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
10122eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
10132eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
101465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
101565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
1016428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
1017a770a4daf77037b5526dba1c447d61acf0aba01aDaniel Jasper  void setParenRange(SourceRange Range) { ParenRange = Range; }
101815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1020524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
1021524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
102215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
10231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
102563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
102663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
102763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
10286d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
102960adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
103015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
103115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
10320982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an explicit C++ type conversion that uses "functional"
10330982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// notation (C++ [expr.type.conv]).
10340982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
10350982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Example:
10360982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
10370982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   x = int(0.5);
10380982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
103949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
1040987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
1041987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1042f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1043f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1044f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
1046f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
1047ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                        SourceLocation rParenLoc)
1048f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1049f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
10500aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
10510aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
1052f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1053f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1054f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1055f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
1056f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1057f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
1058f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
1059f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
1060f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
1061f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
1062f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
1063f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1064f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
1065ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1066987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1067ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1068987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
1069ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
107165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; }
107265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
107365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
1076987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1077987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1078987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1079506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
1080506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
1081506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
1083506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1084ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the
1085ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
1086506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
1087506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
1088506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
1089506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
1090506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
1091506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1092506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
1093506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
1094524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
1095ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
1096506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1097506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1099ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
11003b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                         ArrayRef<Expr *> Args,
1101428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
11027cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                         bool HadMultipleCandidates,
1103c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith                         bool ListInitialization,
1104c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith                         bool ZeroInitialization);
11056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1106ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1107506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1108ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1109ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
111065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
111165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
1112ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1114506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
1115506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
11166d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
111760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
1118506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
1119506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
112001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object
112101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later.
112201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
112301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example:
112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code
112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) {
112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///   values.erase(std::remove_if(values.begin(), values.end(),
1127d9ffa0c39ff9c71e2729eac4cdcf32b377c1d3b6Dmitri Gribenko///                               [=](double value) { return value > cutoff; });
112801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// }
112901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode
113001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
113101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying
113201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function
113301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a
113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either
113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square
113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression.
113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr {
113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  enum {
113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indicate that the given
114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture was implicit.
114101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_Implicit = 0x01,
114201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
114301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indciate that the
114401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// given capture was by-copy.
114501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_ByCopy = 0x02
114601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
114701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The source range that covers the lambda introducer ([...]).
114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange IntroducerRange;
115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief The number of captures.
11527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned NumCaptures : 16;
11537ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
115401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The default capture kind, which is a value of type
115501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// LambdaCaptureDefault.
115601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned CaptureDefault : 2;
115701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
115801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Whether this lambda had an explicit parameter list vs. an
115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit (and empty) parameter list.
116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned ExplicitParams : 1;
116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1162dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had the result type explicitly specified.
1163dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  unsigned ExplicitResultType : 1;
1164dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
1165dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether there are any array index variables stored at the end of
1166dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// this lambda expression.
11677ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned HasArrayIndexVars : 1;
11687ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
116901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The location of the closing brace ('}') that completes
117001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// the lambda.
117101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  ///
117201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// The location of the brace is also available by looking up the
117301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// function call operator in the lambda class. However, it is
117401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stored here to improve the performance of getSourceRange(), and
117501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// to avoid having to deserialize the function call operator from a
117601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// module file just to determine the source range.
117701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceLocation ClosingBrace;
117801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // Note: The capture initializers are stored directly after the lambda
11807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // expression, along with the index variables used to initialize by-copy
11817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // array captures.
11827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
118301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
118401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Describes the capture of either a variable or 'this'.
118501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  class Capture {
118601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
118701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation Loc;
118801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation EllipsisLoc;
11899daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
119001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtReader;
119101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtWriter;
11929daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
119301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  public:
119401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Create a new capture.
119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
119601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Loc The source location associated with this capture.
119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Kind The kind of capture (this, byref, bycopy).
119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Implicit Whether the capture was implicit or explicit.
120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Var The local variable being captured, or null if capturing this.
120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param EllipsisLoc The location of the ellipsis (...) for a
120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture that is a pack expansion, or an invalid source
120601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// location to indicate that this is not a pack expansion.
120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture(SourceLocation Loc, bool Implicit,
120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            LambdaCaptureKind Kind, VarDecl *Var = 0,
120901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            SourceLocation EllipsisLoc = SourceLocation());
121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine the kind of capture.
121201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    LambdaCaptureKind getCaptureKind() const;
121301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles the C++ 'this'
121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// pointer.
121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesThis() const { return VarAndBits.getPointer() == 0; }
121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles a variable.
121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the declaration of the local variable being
122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// captured.
122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// This operation is only valid if this capture does not capture
122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// 'this'.
122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    VarDecl *getCapturedVar() const {
122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(!capturesThis() && "No variable available for 'this' capture");
122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return VarAndBits.getPointer();
122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
123001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
123101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an implicit capture (not
123201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// written between the square brackets introducing the lambda).
123301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
123401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
123501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an explicit capture, written
123601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// between the square brackets introducing the lambda.
123701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isExplicit() const { return !isImplicit(); }
123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
123901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the source location of the capture.
124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
124101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// For an explicit capture, this returns the location of the
124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// explicit capture in the source. For an implicit capture, this
124301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// returns the location at which the variable or 'this' was first
124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// used.
124501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getLocation() const { return Loc; }
124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
124701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture is a pack expansion,
124801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// which captures a function parameter pack.
124901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isPackExpansion() const { return EllipsisLoc.isValid(); }
125001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
125101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the location of the ellipsis for a capture
125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// that is a pack expansion.
125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getEllipsisLoc() const {
125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(isPackExpansion() && "No ellipsis location for a non-expansion");
125501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return EllipsisLoc;
125601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
125701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
125801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
125901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate:
126001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a lambda expression.
126101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaExpr(QualType T, SourceRange IntroducerRange,
126201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             LambdaCaptureDefault CaptureDefault,
126301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Capture> Captures,
126401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             bool ExplicitParams,
1265dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor             bool ExplicitResultType,
126601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Expr *> CaptureInits,
12679daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<VarDecl *> ArrayIndexVars,
12689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<unsigned> ArrayIndexStarts,
1269612409ece080e814f79e06772c690d603f45fbd6Richard Smith             SourceLocation ClosingBrace,
1270612409ece080e814f79e06772c690d603f45fbd6Richard Smith             bool ContainsUnexpandedParameterPack);
127101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
12729d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct an empty lambda expression.
12739d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
12749d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    : Expr(LambdaExprClass, Empty),
12759d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
12769d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      ExplicitResultType(false), HasArrayIndexVars(true) {
12779d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    getStoredStmts()[NumCaptures] = 0;
12789d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  }
12799d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
12807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  Stmt **getStoredStmts() const {
12817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
12827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the mapping from captures to the first array index
12857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// variable.
12867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned *getArrayIndexStarts() const {
12877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
12887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12897ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12907ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the complete set of array-index variables.
12917ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  VarDecl **getArrayIndexVars() const {
1292a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith    unsigned ArrayIndexSize =
1293a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith        llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
1294a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith                                 llvm::alignOf<VarDecl*>());
12957ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<VarDecl **>(
129688d2f678e70ab9360f09f3534d9223e6ec20f129Richard Smith        reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
12977ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12987ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
129901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
130001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a new lambda expression.
130101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static LambdaExpr *Create(ASTContext &C,
130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            CXXRecordDecl *Class,
130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            SourceRange IntroducerRange,
130401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            LambdaCaptureDefault CaptureDefault,
130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Capture> Captures,
130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            bool ExplicitParams,
1307dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                            bool ExplicitResultType,
130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Expr *> CaptureInits,
13099daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<VarDecl *> ArrayIndexVars,
13109daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<unsigned> ArrayIndexStarts,
1311612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            SourceLocation ClosingBrace,
1312612409ece080e814f79e06772c690d603f45fbd6Richard Smith                            bool ContainsUnexpandedParameterPack);
131301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13149d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct a new lambda expression that will be deserialized from
13159d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// an external source.
13169d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
13179d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor                                        unsigned NumArrayIndexVars);
13189d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
131901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine the default capture kind for this lambda.
132001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaCaptureDefault getCaptureDefault() const {
132101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return static_cast<LambdaCaptureDefault>(CaptureDefault);
132201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
132301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief An iterator that walks over the captures of the lambda,
132501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// both implicit and explicit.
132601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef const Capture *capture_iterator;
132701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first lambda capture.
1329da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_begin() const;
133001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
133101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the
133201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// sequence of lambda captures.
1333da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_end() const;
133401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13357ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Determine the number of captures in this lambda.
13367ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned capture_size() const { return NumCaptures; }
13377ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
133801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first explicit
133901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1340da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_begin() const;
134101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
134201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
134301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// explicit lambda captures.
1344da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_end() const;
134501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
134601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first implicit
134701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1348da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_begin() const;
134901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
135101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit lambda captures.
1352da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_end() const;
135301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Iterator that walks over the capture initialization
135501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// arguments.
135601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef Expr **capture_init_iterator;
135701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the first initialization argument for this
135901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression (which initializes the first capture field).
13607ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_begin() const {
13617ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Expr **>(getStoredStmts());
13627ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
136301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
136401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the iterator pointing one past the last
136576e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  /// initialization argument for this lambda expression.
13667ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_end() const {
13677ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return capture_init_begin() + NumCaptures;
13687ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
136901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13709daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Retrieve the set of index variables used in the capture
13719daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// initializer of an array captured by copy.
13729daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ///
13739daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \param Iter The iterator that points at the capture initializer for
13749daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// which we are extracting the corresponding index variables.
13759daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
13769daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
137701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the source range covering the lambda introducer,
137801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// which contains the explicit capture list surrounded by square
137901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// brackets ([...]).
138001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange getIntroducerRange() const { return IntroducerRange; }
138101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
138201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the class that corresponds to the lambda, which
138301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stores the captures in its fields and provides the various
138401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// operations permitted on a lambda (copying, calling).
138501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXRecordDecl *getLambdaClass() const;
138601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
138701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the function call operator associated with this
138801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression.
138901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXMethodDecl *getCallOperator() const;
139001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the body of the lambda.
13929d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  CompoundStmt *getBody() const;
139301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether the lambda is mutable, meaning that any
139501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// captures values can be modified.
139601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool isMutable() const;
139701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
139801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether this lambda has an explicit parameter
139901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// list vs. an implicit (empty) parameter list.
140001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool hasExplicitParameters() const { return ExplicitParams; }
140101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1402dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had its result type explicitly specified.
1403dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  bool hasExplicitResultType() const { return ExplicitResultType; }
14049e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor
140501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const Stmt *T) {
140601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return T->getStmtClass() == LambdaExprClass;
140701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
140801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
140965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
141065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return IntroducerRange.getBegin();
141101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
141265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; }
141301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
14147ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  child_range children() {
14157ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
14167ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
141701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
141801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtReader;
141901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtWriter;
142001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor};
142101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1422ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1423506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
1424ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
1425987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
1426ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
1427987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1428ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
1429987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1430ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
1431ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1432987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
1433ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Create an explicitly-written scalar-value initialization
1434ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
1435ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
1436ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
1437ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
1438f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1439561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false, Type->isInstantiationDependentType(), false),
1440ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1441ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1442ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1443ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1445ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1446ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
14474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1448ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1449ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
14504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
145165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
145265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1455ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1456987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1458987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
145963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1460987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1461987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14620982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @brief Represents a new-expression for memory allocation and constructor
14630982205bade2fb4fc984c27b2ab401e683963b10James Dennett// calls, e.g: "new CXXNewExpr(foo)".
14644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
14652aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // Contains an optional array size expression, an optional initialization
14662aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // expression, and any number of optional placement arguments, in that order.
14674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
14680982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the allocation function used.
14694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
14700982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Points to the deallocation function used in case of error. May be
14710982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// null.
14724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
14734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14741bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
14751bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
1476ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1477ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief If the allocated type was expressed as a parenthesized type-id,
14784bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
14794bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
1480ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1481530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  /// \brief Range of the entire new expression.
1482530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceRange Range;
14832aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
14842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Source-range of a paren-delimited initializer.
14852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange DirectInitRange;
14864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1487d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Was the usage ::new, i.e. is the global new to be used?
1488d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool GlobalNew : 1;
1489d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Do we allocate an array? If so, the first SubExpr is the size expression.
1490d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool Array : 1;
1491d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // If this is an array allocation, does the usual deallocation
1492d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // function for the allocated type want to know the allocated size?
1493d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool UsualArrayDeleteWantsSize : 1;
1494d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The number of placement new arguments.
1495d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned NumPlacementArgs : 13;
1496d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // What kind of initializer do we have? Could be none, parens, or braces.
1497d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // In storage, we distinguish between "none, and no initializer expr", and
1498d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // "none, but an implicit initializer expr".
1499d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned StoredInitializationStyle : 2;
1500d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
150160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
15022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  friend class ASTStmtWriter;
15034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
15042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  enum InitializationStyle {
15052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    NoInit,   ///< New-expression has no initializer as written.
15062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    CallInit, ///< New-expression has a C++98 paren-delimited initializer.
15072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    ListInit  ///< New-expression has a C++11 list-initializer.
15082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  };
15092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
1510ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
15111548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
15123b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer             ArrayRef<Expr*> placementArgs,
15132aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceRange typeIdParens, Expr *arraySize,
15142aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             InitializationStyle initializationStyle, Expr *initializer,
15156ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1516530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie             SourceRange Range, SourceRange directInitRange);
15175921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
15185921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
15195921863d8f24084797863b5df37842113bac4352Chris Lattner
15205921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
15212aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                         bool hasInitializer);
1522ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1523cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1524cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
15256217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1526cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
15274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15281bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
15291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
15301bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1531c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1532c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1533c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// C++0x [expr.new]p13:
1534c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1535c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1536c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1537c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1538c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1539c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1540c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
15418026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
15445921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
15454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
15465921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
15474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1548cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1549cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1550cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1551cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1552cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1553cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1554cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1555cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
15564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1557ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr **getPlacementArgs() {
15582aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1559aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
15624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15632aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return getPlacementArgs()[i];
15644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
15664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
15684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15704bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
15714bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
15724bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
15734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
15747cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
15752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Whether this new-expression has any initializer at all.
15762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool hasInitializer() const { return StoredInitializationStyle > 0; }
15771548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15782aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The kind of initializer this new-expression has.
15792aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  InitializationStyle getInitializationStyle() const {
15802aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    if (StoredInitializationStyle == 0)
15812aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl      return NoInit;
15822aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return static_cast<InitializationStyle>(StoredInitializationStyle-1);
15831548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15841548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The initializer of this new-expression.
15862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  Expr *getInitializer() {
15872aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15881548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15892aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const Expr *getInitializer() const {
15902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15911548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15921548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
1593feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay  /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
159488920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky  const CXXConstructExpr* getConstructExpr() const {
1595feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay    return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1596feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay  }
1597feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay
15982aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// Answers whether the usual array deallocation function for the
15992aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// allocated type expects the size of the allocation as a
16002aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// parameter.
16012aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool doesUsualArrayDeleteWantSize() const {
16022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return UsualArrayDeleteWantsSize;
16032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
16041548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
16054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
16064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
16074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
16092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
16104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
16122aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
16152aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
16164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
16182aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
1620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16215921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
16225921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
16235921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
16242aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16255921863d8f24084797863b5df37842113bac4352Chris Lattner  }
16265921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
16272aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const_arg_iterator raw_arg_end() const {
16282aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
16292aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
16304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1631530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceLocation getStartLoc() const { return Range.getBegin(); }
1632530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie  SourceLocation getEndLoc() const { return Range.getEnd(); }
1633428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
16342aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange getDirectInitRange() const { return DirectInitRange; }
1635428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1636aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1637530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie    return Range;
16384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
163965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); }
164065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
16414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
16434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
16444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
164763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
16482aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return child_range(raw_arg_begin(), raw_arg_end());
164963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
16504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
16514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16520982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a \c delete expression for memory deallocation and
16530982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// destructor calls, e.g. "delete[] pArray".
16544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
1655d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Points to the operator delete overload that is used. Could be a member.
1656d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  FunctionDecl *OperatorDelete;
1657d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The pointer expression to be deleted.
1658d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Argument;
1659d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Location of the expression.
1660d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  SourceLocation Loc;
16614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
16624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
16634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
16644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
16654076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
16664076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
16674076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
16684076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
16696ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
16706ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
16716ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
16724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
16734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
16746ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
16756ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1676bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1677561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           arg->isInstantiationDependent(),
1678bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1679d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1680f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
16814076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1682d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
168395fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
168495fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
16854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
16874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
16884076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
16894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16906ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
16916ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
16926ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
16936ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
16946ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
16956ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
16966ec278d1a354517e20f13a877481453ee7940c78John McCall  }
16976ec278d1a354517e20f13a877481453ee7940c78John McCall
16984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
16994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
17014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
17024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1703a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1704a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1705a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
17065833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
1707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
170865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
170965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();}
17104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
17124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
17134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
17144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
171663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1717f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1718f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
17194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
17204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
17210982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Stores the type being destroyed by a pseudo-destructor expression.
1722a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Either the type source information or the name of the type, if
1724a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1725a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1726ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1727a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1728a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1729ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1730a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1731a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1733a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1734a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1736a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1737ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1738ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getTypeSourceInfo() const {
1739ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return Type.dyn_cast<TypeSourceInfo *>();
1740a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1741ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1742a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1743a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1744a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1746a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1747a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1748ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1749a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1750a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1751e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1752ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have
1753e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1754e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1755e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1756e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1757e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1758e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1759e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1760e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1761a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1762e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///
1764a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1766a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1767e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1768a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1769a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1770a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1771e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1772e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1773a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1774a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1775a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1777a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1778a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1779a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1781a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1782a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1784a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1785f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1787e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1788e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1789e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1790ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The location of the '::' in a qualified pseudo-destructor
1792e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1793e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1794ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1795fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1796fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1798ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The type being destroyed, or its name if we were unable to
1799a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1800a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1802f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1804a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1805a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1806a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1807f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1808e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1809e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1810fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1811e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
18121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1813de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1814de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1815f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1816de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1817a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1820a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1821a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1822f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1824f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1825f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1826f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1827ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1829a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1830a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1831ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
1832ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
1833f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1835a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1836a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1837a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1838a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1839a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1840a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1842ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1843e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1844e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1845e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1846e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1847e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1848ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \p T may also be a scalar type and, therefore, cannot be part of a
1849e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1850e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
185126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1853e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1854e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1855e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1857fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1858fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
186026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
186126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1862a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This type-source information is available for non-dependent
1864a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1865a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1866a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1867ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getDestroyedTypeInfo() const {
1868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getTypeSourceInfo();
1869a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1871a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1872a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1873a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1874a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1875a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1876a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1877ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1878a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1879a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1880ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1881a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SourceLocation getDestroyedTypeLoc() const {
1883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getLocation();
1884a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
18851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1886de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1887de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1888de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1889de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1890de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1891de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1892de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1893de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1894de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1895de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1896de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
189765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();}
189865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY;
18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1901a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1902a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1904a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
190563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1906a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19080982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS unary type trait, as used in the
19090982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
19100982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
191164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
19120982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
19130982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_pod(int) == true
19140982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_enum(std::string) == false
19150982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
191664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
19170dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
19180dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
19190dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
19200dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
192164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
192264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
192364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
192464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
192564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
192664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
192764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19280dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
19293d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
193064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
193164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
1932ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
19330dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
193464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1935f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1936bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1937561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->getType()->isInstantiationDependentType(),
1938bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
19390dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
194064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19416d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
19420dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
19433d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
19446d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
194565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
194665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
194764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19480dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
194964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19503d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
195164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19523d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1953ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19540dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
195564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
195664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
195764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
195864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
195964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
196064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
196163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19626d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
196360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
196464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
196564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19660982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS binary type trait, as used in the
19670982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates.
19680982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
19696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
19700982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
19710982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_base_of(Base, Derived) == true
19720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
19736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
19746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
19756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
19766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
19786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
19796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
19816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
19826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
19846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
19856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
19876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
1993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
19956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
1996ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
19976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
1998bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
1999561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhsType->getType()->isInstantiationDependentType() ||
2000561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhsType->getType()->isInstantiationDependentType()),
2001bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
2002bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
20036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
20046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
20056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
20086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
2009f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
20106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
201165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
201265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
20136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
20156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
20166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
20196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
20206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
20226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
2023ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
20256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
20276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
20286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
20296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
203163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
20326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
20346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
20356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
20364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and
20374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates.
20384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///
20394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code
20404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///   __is_trivially_constructible(vector<int>, int*, int*)
20414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode
20424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr {
20434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief The location of the type trait keyword.
20444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation Loc;
20454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief  The location of the closing parenthesis.
20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation RParenLoc;
20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Note: The TypeSourceInfos for the arguments are allocated after the
20504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // TypeTraitExpr.
20514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
20534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                ArrayRef<TypeSourceInfo *> Args,
20544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                SourceLocation RParenLoc,
20554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                bool Value);
20564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
20584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo **getTypeSourceInfos() {
20614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo **>(this+1);
20624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo * const *getTypeSourceInfos() const {
20664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo * const*>(this+1);
20674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic:
20704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Create a new type trait expression.
20714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
20724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               TypeTrait Kind,
20734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               ArrayRef<TypeSourceInfo *> Args,
20744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               SourceLocation RParenLoc,
20754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               bool Value);
20764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
20784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine which type trait this expression uses.
20804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTrait getTrait() const {
20814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
20824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  bool getValue() const {
20854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(!isValueDependent());
20864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return TypeTraitExprBits.Value;
20874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine the number of arguments to this type trait.
20904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
20914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the Ith argument.
20934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo *getArg(unsigned I) const {
20944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(I < getNumArgs() && "Argument out-of-range");
20954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getArgs()[I];
20964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ArrayRef<TypeSourceInfo *> getArgs() const {
21004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
21014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo **arg_iterator;
21044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_begin() {
21054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos();
21064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_end() {
21084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
21094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo const * const *arg_const_iterator;
21124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
21134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_end() const {
21144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
21154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
211765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
211865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
211965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen
21204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const Stmt *T) {
21214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return T->getStmtClass() == TypeTraitExprClass;
21224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
21234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Iterators
21254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  child_range children() { return child_range(); }
21264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtReader;
21284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
21294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor};
21314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
21320982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An Embarcadero array type trait, as used in the implementation of
21330982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank and __array_extent.
21340982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
213521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example:
21360982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
21370982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_rank(int[10][20]) == 2
21380982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __array_extent(int, 1)    == 20
21390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
214021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr {
214199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
214299ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
21430982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
214421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  unsigned ATT : 2;
214521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21460982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
214721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t Value;
214821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21490982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The array dimension being queried, or -1 if not used.
215021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *Dimension;
215121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21520982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
215321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation Loc;
215421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21550982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
215621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation RParen;
215721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
21580982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The type being queried.
215921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *QueriedType;
216021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
216121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic:
216221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
216321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     TypeSourceInfo *queried, uint64_t value,
216421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     Expr *dimension, SourceLocation rparen, QualType ty)
216521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
216621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           false, queried->getType()->isDependentType(),
2167561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (queried->getType()->isInstantiationDependentType() ||
2168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            (dimension && dimension->isInstantiationDependent())),
216921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           queried->getType()->containsUnexpandedParameterPack()),
217021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      ATT(att), Value(value), Dimension(dimension),
217121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      Loc(loc), RParen(rparen), QueriedType(queried) { }
217221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
217321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
217421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  explicit ArrayTypeTraitExpr(EmptyShell Empty)
217521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
217621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      QueriedType() { }
217721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
217825aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek  virtual ~ArrayTypeTraitExpr() { }
217925aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek
218065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
218165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
218221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
218421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  QualType getQueriedType() const { return QueriedType->getType(); }
218621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
218821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
218921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
219021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *getDimensionExpression() const { return Dimension; }
219221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const Stmt *T) {
219421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return T->getStmtClass() == ArrayTypeTraitExprClass;
219521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
219621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
219721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Iterators
219821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  child_range children() { return child_range(); }
219921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
220021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  friend class ASTStmtReader;
220121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley};
220221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
22030982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An expression trait intrinsic.
22040982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
2205552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example:
22060982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code
22070982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(std::cout) == true
22080982205bade2fb4fc984c27b2ab401e683963b10James Dennett///   __is_lvalue_expr(1) == false
22090982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode
2210552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr {
22110982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned.
2212552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  unsigned ET : 31;
22130982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The value of the type trait. Unspecified if dependent.
2214552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool Value : 1;
2215552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22160982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the type trait keyword.
2217552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation Loc;
2218552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22190982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The location of the closing paren.
2220552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation RParen;
2221552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22220982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The expression being queried.
2223552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr* QueriedExpression;
2224552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic:
2225ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2226552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     Expr *queried, bool value,
2227552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     SourceLocation rparen, QualType resultType)
2228552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2229552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           false, // Not type-dependent
2230552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           // Value-dependent if the argument is type-dependent.
2231552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->isTypeDependent(),
2232561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->isInstantiationDependent(),
2233552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->containsUnexpandedParameterPack()),
2234ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      ET(et), Value(value), Loc(loc), RParen(rparen),
2235ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      QueriedExpression(queried) { }
2236552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2237552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  explicit ExpressionTraitExpr(EmptyShell Empty)
2238552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2239552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      QueriedExpression() { }
2240552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
224165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
224265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParen; }
2243552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2244552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2245552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2246552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr *getQueriedExpression() const { return QueriedExpression; }
2247552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2248552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool getValue() const { return Value; }
2249552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2250552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const Stmt *T) {
2251552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return T->getStmtClass() == ExpressionTraitExprClass;
2252552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
2253552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2254552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  // Iterators
2255552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  child_range children() { return child_range(); }
2256552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2257552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  friend class ASTStmtReader;
2258552622067dc45013d240f73952fece703f5e63bdJohn Wiegley};
2259552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2260552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22617bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
2262809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
22637bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
22640982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief The common name of these declarations.
2265d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  DeclarationNameInfo NameInfo;
2266d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2267d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  /// \brief The nested-name-specifier that qualifies the name, if any.
2268d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  NestedNameSpecifierLoc QualifierLoc;
2269d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2270ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
22717bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
22727bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
2273928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
2274928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
2275928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
2276ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2277a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
2278e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2280e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2281e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2282e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2283e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2284e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2285e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2286e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
22897bb12da2b0749eeebb21854c77877736969e59f2John McCall
2290bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
22914c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
2292e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara               SourceLocation TemplateKWLoc,
22932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
2294bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
2295bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2296561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownDependent,
2297561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownInstantiationDependent,
2298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownContainsUnexpandedParameterPack);
22997bb12da2b0749eeebb21854c77877736969e59f2John McCall
2300a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
2301d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer    : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2302d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      HasTemplateKWAndArgsInfo(false) { }
2303a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2304bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
2305bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
2306bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
23077bb12da2b0749eeebb21854c77877736969e59f2John McCall
2308bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
23099c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
23109c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
23119c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
23129c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
23139c72c6088d591ace8503b842d39448c2040f3033John McCall  };
23149c72c6088d591ace8503b842d39448c2040f3033John McCall
23157bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
23167bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
23177bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
23189c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
23199c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
23209c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
23217bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
23227bb12da2b0749eeebb21854c77877736969e59f2John McCall
23239c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
23249c72c6088d591ace8503b842d39448c2040f3033John McCall
23257bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
23269c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
23279c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
23289c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
23299c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
23309c72c6088d591ace8503b842d39448c2040f3033John McCall
23319c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
23329c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
23339c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
23349c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
23359c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
23369c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
23379c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
23389c72c6088d591ace8503b842d39448c2040f3033John McCall    }
23399c72c6088d591ace8503b842d39448c2040f3033John McCall
23409c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
23417bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
23427bb12da2b0749eeebb21854c77877736969e59f2John McCall
23430982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the naming class of this lookup, if any.
2344e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
2345e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
23467bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
2347928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2348ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  decls_iterator decls_end() const {
2349928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
2350928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
2351ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
23520982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the number of declarations in the unresolved set.
2353928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
23547bb12da2b0749eeebb21854c77877736969e59f2John McCall
23550982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the full name info.
23562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
23572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
23580982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the name looked up.
23592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
23607bb12da2b0749eeebb21854c77877736969e59f2John McCall
23610982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Gets the location of the name.
23622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
23637bb12da2b0749eeebb21854c77877736969e59f2John McCall
23640982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier, if one was given.
2365ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2366ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
23674c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
23687bb12da2b0749eeebb21854c77877736969e59f2John McCall
23690982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Fetches the nested-name qualifier with source-location
23700982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// information, if one was given.
23714c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
23727bb12da2b0749eeebb21854c77877736969e59f2John McCall
2373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2380e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2381e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2382e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2383e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2384e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2385e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2386e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2387e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2388e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2389e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2390e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2391e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2392e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
23937bb12da2b0749eeebb21854c77877736969e59f2John McCall
23940982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether the name was preceded by the template keyword.
2395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
23970982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Determines whether this expression had explicit template arguments.
2398e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2399e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2400e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // Note that, inconsistently with the explicit-template-argument AST
2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // nodes, users are *forbidden* from calling these methods on objects
2402e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // without explicit template arguments.
2403e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2404e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2405e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
2406e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
24087bb12da2b0749eeebb21854c77877736969e59f2John McCall
2409b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
24107bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
24117bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24127bb12da2b0749eeebb21854c77877736969e59f2John McCall
2413e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  TemplateArgumentLoc const *getTemplateArgs() const {
2414e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().getTemplateArgs();
2415e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2416e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2417e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  unsigned getNumTemplateArgs() const {
2418e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().NumTemplateArgs;
2419e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2420e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
24210982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// \brief Copies the template arguments into the given structure.
2422e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2423e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    getExplicitTemplateArgs().copyInto(List);
2424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2425e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2426096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
24270982205bade2fb4fc984c27b2ab401e683963b10James Dennett  ///
2428096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2429096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
24307d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2431096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2432096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
24337bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24347bb12da2b0749eeebb21854c77877736969e59f2John McCall
24357bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
24367bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
24377bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
24387bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24394045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
24404045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
24414045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
24427bb12da2b0749eeebb21854c77877736969e59f2John McCall};
24437bb12da2b0749eeebb21854c77877736969e59f2John McCall
24447bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
24450982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// parsing but could not resolve to a specific declaration.
24460982205bade2fb4fc984c27b2ab401e683963b10James Dennett///
24470982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// This arises in several ways:
24487bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
24497bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
24507bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
24517bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
24520982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// These never include UnresolvedUsingValueDecls, which are always class
24530982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// members and therefore appear only in UnresolvedMemberLookupExprs.
24547bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
2455ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
2456ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
2457ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
2458ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
2459ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
24607453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
24617453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
24627453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
24637453ed4cb2cab113de3378df371b1c6f1243d832John McCall
24647bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
24657bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
24667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
24677bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
24687bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
24697bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
2470f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2471ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnresolvedLookupExpr(ASTContext &C,
2472928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
24734c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
2474e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
24752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
2476ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                       bool RequiresADL, bool Overloaded,
2477bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
2478b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
2479e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2480e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                   NameInfo, TemplateArgs, Begin, End, false, false, false),
2481ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(RequiresADL),
2482ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Overloaded(Overloaded), NamingClass(NamingClass)
2483ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
2484ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2485bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
2486bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
2487b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith      RequiresADL(false), Overloaded(false), NamingClass(0)
2488bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
2489bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
24904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
2491ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2492ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
2493ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2494c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
24954c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
24962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
24975a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
2498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
2499b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                                      UnresolvedSetIterator End) {
2500e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2501e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SourceLocation(), NameInfo,
2502b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith                                       ADL, Overloaded, 0, Begin, End);
2503ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2504ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2505f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2506c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
25074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
2508e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                      SourceLocation TemplateKWLoc,
25092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
2510f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
25119d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                      const TemplateArgumentListInfo *Args,
2512ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
25135a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
2514f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2515bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2516e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           bool HasTemplateKWAndArgsInfo,
2517bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
2518bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
2519ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
2520ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
2521ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
2522ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
25237453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
25247453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
25257453ed4cb2cab113de3378df371b1c6f1243d832John McCall
2526c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
2527c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
2528c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
2529c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
2530c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
253165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
253265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (NestedNameSpecifierLoc l = getQualifierLoc())
253365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return l.getBeginLoc();
253465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getNameInfo().getLocStart();
253565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
253665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
2537ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (hasExplicitTemplateArgs())
253865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
253965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getNameInfo().getLocEnd();
2540ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2541ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
254263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2543ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2544ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
2545ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
2546ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2547ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
2548ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
25495953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
25505953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
25515953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
2552ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2553a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
25545953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
2555865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
25565953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
25575953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
25585953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
2559865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2560ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
2561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2562a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
2563865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
2564ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
2565ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
256600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
2567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
256800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
256900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
25705953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
2571e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2572e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2573e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2574e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2575e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2576e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2577e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2578e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2579e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2580e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2581e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2582e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<DependentScopeDeclRefExpr*>(this)
2583e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2584e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2586f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
258700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
2588e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                            SourceLocation TemplateKWLoc,
25892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
2590bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
2591f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2592f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
2593f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
259400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2595e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           SourceLocation TemplateKWLoc,
25962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
2597e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                              const TemplateArgumentListInfo *TemplateArgs);
25985953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
259912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2600e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                bool HasTemplateKWAndArgsInfo,
260112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
260212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
26035953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
26042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
26052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
26062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
26072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
26085953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
26095953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
26102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
26115953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
261200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
261300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
261400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2616ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2617ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
2618ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
2619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
262100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2623e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2624e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2625e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2626e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2627e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2628e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2629e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2630e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2631e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2632e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2633e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2634e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2635e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2636e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2637e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2638e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2639e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2640e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2641e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2642e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2643e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2644e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the name was preceded by the template keyword.
2645e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2646e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2647f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
2648e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
26491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2650f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
2651f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
2652f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
26531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2654b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
265512dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
2656b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
265712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
265812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
2659f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
2660b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2661f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
2662b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2663f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2665096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2666096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2667096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
26687d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2669096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2670096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2671096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2672096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2673f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
2674f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
2675f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2676f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
2677f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
2678ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2679f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
2680f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2681d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2682d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2683f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
2684f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2685f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
26861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
268765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
268865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return QualifierLoc.getBeginLoc();
268965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
269065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
2691f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
269265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
269365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getLocation();
2694edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2697f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2698edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
2699f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
270063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
27014045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
27024045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
27034045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
2704edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27064765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
27074765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
27084765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
270980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of
271080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every
271180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer.
271280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall///
271380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a
271480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal.  The lifetime of a block
271580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope.
27164765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
271780ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic:
271880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// The type of objects that are kept in the cleanup.
271980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// It's useful to remember the set of blocks;  we could also
272080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// remember the set of temporaries, but there's currently
272180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// no need.
272280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  typedef BlockDecl *CleanupObject;
272380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
272480ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate:
272502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
272780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(EmptyShell, unsigned NumObjects);
272880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
272902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
273080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject *getObjectsBuffer() {
273180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<CleanupObject*>(this + 1);
273280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
273380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  const CleanupObject *getObjectsBuffer() const {
273480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<const CleanupObject*>(this + 1);
273580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
273680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  friend class ASTStmtReader;
2737ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
273888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
273980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
274080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  unsigned numObjects);
27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
274280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
274380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  ArrayRef<CleanupObject> objects);
2744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
274580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ArrayRef<CleanupObject> getObjects() const {
274680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2747f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
274880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
274980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
275080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
275180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject getObject(unsigned i) const {
275280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    assert(i < getNumObjects() && "Index out of range");
275380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return getObjects()[i];
2754d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
275602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2757f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
275880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
275980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// setSubExpr - As with any mutator of the AST, be very careful
276080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// when modifying an existing AST to preserve its invariants.
276188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
276202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
276365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
276465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return SubExpr->getLocStart();
276596be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
276665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();}
276702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
276802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
276902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
27704765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
277102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
277202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
277302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
277463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
277502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
277602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2777d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2778d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2779d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2780d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2781d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2782fe865f1f35d1b91f42f58f08a1399b961b71b3bcJames Dennett/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>,
27830982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and
27840982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is
2785d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2786d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2787d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2788d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2789d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2790d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2791d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2792d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2793d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2794d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2795d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2796d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2797d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2798d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2799d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2800ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2802d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2803d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2804d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2805d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2806d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2807d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2808d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2809d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
28101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2811ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2812d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
28133b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                             ArrayRef<Expr*> Args,
2814d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2815d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28168dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2817ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
28188dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2819ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2820ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2821d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
28221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2823ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2824d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
28253b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer                                            ArrayRef<Expr*> Args,
2826d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2827d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28288dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
28298dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
28308dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2831d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2832d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2833ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2834d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2835ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the type source information for the type being
2836ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2837ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2838ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2839d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2840d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2841d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2842d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2843d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2844d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2845d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2846d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2847d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2848d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2849d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2850d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2851d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2852d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2853d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2854d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2855d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28561dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
28571dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
28581dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
28591dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28601dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
28611dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
28621dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28631dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2864d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2865d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2866d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2867d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2868d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28691dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
28701dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
28711dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
28721dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28731dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
28748dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
28758dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
28768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
28778dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
28788dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
287965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY;
288065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2881ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2883d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2884d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2885d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2886d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
288763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
288863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
288963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
289063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2891d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2892d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2893ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2894ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2895ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2896aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2897aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2898aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2899aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2900865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
29011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2902aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
29031c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
29041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2905aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2906aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2907aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2908aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
29101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
29113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
29121c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2913e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether this member expression has info for explicit template
2914e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2915e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo : 1;
29161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29171c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
29181c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
29191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2920a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
29217c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
29221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2923c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
29241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2925c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2926c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
292746bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
2928c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2929865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2930c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
29311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29321c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
29331c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2934a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
29352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
29361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2937e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2938e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2939e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2940e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2941e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2942e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2943e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2944e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<CXXDependentScopeMemberExpr*>(this)
2945e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2946e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2947e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2948865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2949aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
29503b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
29517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
2952e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                          SourceLocation TemplateKWLoc,
29533b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
29542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2955d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2958865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2959bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2960bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2961bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
29627c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2963bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2964bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
29651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2966865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
29671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2968aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
29693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
29707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
2971e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
29723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
29732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2974d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
29751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
2977e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2978def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
29798dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2980aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2981aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2982aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
29834c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2984aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29851c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
29861c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
2987aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
2988aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2989aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2990aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
29911c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2992aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2993aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
29951c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
29961c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
29971c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
29981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
29991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
30001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3001a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
3002a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
3003ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
3004ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
30057c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
30087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
30097c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3010ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3011ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3012c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
3013c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
3014c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
3015c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
3016c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
30171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
3019c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
3020c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
3021c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
3022c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
30231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
3024c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
3025c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30271c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
30281c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
30292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
30302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
30312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
30322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
30332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
30342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
30352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
30361c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
30371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
30381c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
30392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
30401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3041e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding the
3042e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// member name, if any.
3043e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
3044e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3045e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3046e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3047e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
3049e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3050e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
3051e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3052e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
3053e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3054e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3055e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
3056e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3057e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
3058e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3059e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
3060e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3061e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3062e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the member name was preceded by the template keyword.
3063e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3064e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
30653b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
30663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
3067e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
30681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
306936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
307036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3071b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3072e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
3073b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
307436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
307536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
307636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
307736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3078b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
307936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
3080096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
3081096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
3082096832c5ed5b9106fa177ebc148489760c3bc496John McCall
3083096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
3084096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
3085096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
30867d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
3087096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
3088096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
308936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
309036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
3091d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
3092d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
3093d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3094096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
3095d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
3096d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
30978dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
30988dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3099096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
31008dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
31018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
31023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
31033b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
3104833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
3105096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
31063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
31071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31083b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
31093b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
3111096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
31123b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
31131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
311465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
3115aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
311665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return Base->getLocStart();
311765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (getQualifier())
311865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getQualifierLoc().getBeginLoc();
311965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return MemberNameInfo.getBeginLoc();
31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
312165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
312265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
3123aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
312465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
312565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return MemberNameInfo.getEndLoc();
31261c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
31271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3129865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
31301c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
31311c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
31321c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
313363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
313463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
313563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
313663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
31374045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
31384045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
31394045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
31401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
31411c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3142129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
3143aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
3144aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3145aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
3146aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
3147aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
3148aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
3149aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
3150aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
3151aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3152aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
3153aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
3154aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
31557bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
3156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
3157129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
3158129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
3159129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3160129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
3161129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
3162129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
3163129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
31647bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
31657bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
31667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
31677bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
31687bb12da2b0749eeebb21854c77877736969e59f2John McCall
31697bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
31707bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
3171129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3172129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
3173129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
3174129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
3177129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
31784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
3179e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
31802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
31815a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
31825a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3183ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3184a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
3185a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3186a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
3187129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
31884c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
3189ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
3191129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
3192bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
3193aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
3194129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
31954c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
3196e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
31972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
31985a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
31995a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3201a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
3202e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3203def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
3204a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3205aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
3206aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
3207aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
32084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3209aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3210129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
3211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
3212aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
3213aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3214aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3215aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
32162f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
32172f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
32182f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
32192f27bf854f0519810b34afd209089cc75536b757John McCall  }
3220129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3221aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3222a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3223a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
3224a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
3225a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3226aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3227129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
3228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
3229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
3230129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
3232129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3233129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3234c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
3235c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
3236c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
32372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
32382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
32392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
32402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
3241129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
3242129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
32437bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
3244129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3245129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
3246129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
32477bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
3248129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
324965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
3250aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
325165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return Base->getLocStart();
325265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    if (NestedNameSpecifierLoc l = getQualifierLoc())
325365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return l.getBeginLoc();
325465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getMemberNameInfo().getLocStart();
325565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
325665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
3257129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
325865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen      return getRAngleLoc();
325965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return getMemberNameInfo().getLocEnd();
3260129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3261129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3262129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
3263129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
3264129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3265129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3266129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
326763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
326863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
326963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
327063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3271129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
3272129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
32732e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
32742e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
32752e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
32762e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
32772e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
32782e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
32792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
32802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
32812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3282c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
3283c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
32842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
32852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
32862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
3287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
3289bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
3290561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Val == CT_Dependent || Operand->isInstantiationDependent(),
3291bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
32926b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
32936b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
32946b219d082434394c1ac401390ec1d1967727815aSebastian Redl
32956b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
32966b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
32972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
32982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
32992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
33002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
330165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
330265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
3303aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
33042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
33062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
33082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
33092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
33102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
33112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
331263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
33132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
33142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3315ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of
3316be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
3317be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3318be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
3319be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
3320be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3321be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
3322be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
3323be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
3324be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
3325be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
3326be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
3327be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3328be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
3329ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function
3330be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
3331be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
3332be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
3333be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
3334ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
333567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
333667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
333767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
333867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
333967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
334067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
3341ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3342be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
3343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3344be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
334567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
3346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3347be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
334867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3349dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie                    Optional<unsigned> NumExpansions)
3350ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3351ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           Pattern->getObjectKind(), /*TypeDependent=*/true,
3352561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3353561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3354be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
335567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3356be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
3357be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3358be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3359ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3360be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3361be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3362be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3363be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3364be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3365be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3366be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
3367be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
3368be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3369ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3370ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the number of expansions that will be produced when
337167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
3372dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie  Optional<unsigned> getNumExpansions() const {
337367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
337467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
3375ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
337666874fb18afbffb8b2ca05576851a64534be3352David Blaikie    return None;
337767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
3378ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
337965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
338065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Pattern->getLocStart();
338163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
338265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; }
3383be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3384be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
3385be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
3386be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
3387ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3388be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
338963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
339063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
339163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3392be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
3393ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3394e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  if (!HasTemplateKWAndArgsInfo) return 0;
33967bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
3397e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3398e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedLookupExpr>(this) + 1);
33997bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
3400e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedMemberExpr>(this) + 1);
34027bb12da2b0749eeebb21854c77877736969e59f2John McCall}
34037bb12da2b0749eeebb21854c77877736969e59f2John McCall
3404ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter
3405ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
3406ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
3407ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
3408ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
3409ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
3410ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
3411ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
3412ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
3413ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
3414ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
3415ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
3416ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3417ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
3418ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
3419ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3420ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
3421ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
3422ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3423ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
3424ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3425ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
3426ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
3427ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
3428ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
3429ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3430ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
3431ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
3432ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3433ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
3434ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
3435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3436ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
3437ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
3438ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
3439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3440ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
3441ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3442ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
3443561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3444ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3445ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3446ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
3447ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3448ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
3449ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
3450ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3451ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
3452ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
3453ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3454ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
3455561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         /*InstantiationDependent=*/false,
3456ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
3457ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3458ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
3459ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3460ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
3461ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3462ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3463ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
3464ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3465ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3466ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
3467ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
3468ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3469ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
3470ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3471ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3472ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
3473ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
3474ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3475ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
3476ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3477ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This routine may only be invoked when the expression is not
3478c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
3479ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
3480ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!isValueDependent() &&
3481ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
3482ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
3483ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3484ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
348565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
348665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3487ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3488ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
3489ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
3490ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3491ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3492ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
349363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3494ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
3495c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
349691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter
349791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument.
349891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr {
349991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replaced parameter.
350091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *Param;
350191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
350291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replacement expression.
350391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Stmt *Replacement;
350491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
350591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The location of the non-type template parameter reference.
350691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation NameLoc;
350791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
35087110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
35097110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
3510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
35117110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
35127110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
351391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic:
3514ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmExpr(QualType type,
351591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               ExprValueKind valueKind,
351691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               SourceLocation loc,
351791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               NonTypeTemplateParmDecl *param,
351891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               Expr *replacement)
351991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
352091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isTypeDependent(), replacement->isValueDependent(),
352191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isInstantiationDependent(),
352291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->containsUnexpandedParameterPack()),
352391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall      Param(param), Replacement(replacement), NameLoc(loc) {}
352491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
352591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation getNameLoc() const { return NameLoc; }
352665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
352765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
352891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
352991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Expr *getReplacement() const { return cast<Expr>(Replacement); }
3530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
353191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *getParameter() const { return Param; }
353291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
353391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  static bool classof(const Stmt *s) {
353491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
353591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3536ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
353791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Iterators
353891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  child_range children() { return child_range(&Replacement, &Replacement+1); }
353991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall};
354091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
3541c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
3542c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
3543c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
3544c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3545c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
3546fb7669ee725ec699e2b49b8359c4652536949739Douglas Gregor/// parameter lists, this node is used to represent a non-type template
3547c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3548c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3549c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3550c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3551c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
3552c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
3553c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
3554c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
3555c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
3556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3557c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3558c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
3559c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
3560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3561c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3562c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
3563ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3564c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
3565c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
3566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
35677110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
3568c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
3569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
35707110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3571ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3572c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
3573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmPackExpr(QualType T,
3574c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
3575c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
3576c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
3577ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3578c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
3579c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3580c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3581c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
3582c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
3583ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3584c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
3585c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
3586c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
3587c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
358865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
358965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
3590ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3591c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
3592c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3593c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3594ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3595c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
359663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3597c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
359803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
35999a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \brief Represents a reference to a function parameter pack that has been
36009a4db032ecd991626d236a502e770126db32bd31Richard Smith/// substituted but not yet expanded.
36019a4db032ecd991626d236a502e770126db32bd31Richard Smith///
36029a4db032ecd991626d236a502e770126db32bd31Richard Smith/// When a pack expansion contains multiple parameter packs at different levels,
36039a4db032ecd991626d236a502e770126db32bd31Richard Smith/// this node is used to represent a function parameter pack at an outer level
36049a4db032ecd991626d236a502e770126db32bd31Richard Smith/// which we have already substituted to refer to expanded parameters, but where
36059a4db032ecd991626d236a502e770126db32bd31Richard Smith/// the containing pack expansion cannot yet be expanded.
36069a4db032ecd991626d236a502e770126db32bd31Richard Smith///
36079a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \code
36089a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Ts> struct S {
36099a4db032ecd991626d236a502e770126db32bd31Richard Smith///   template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...));
36109a4db032ecd991626d236a502e770126db32bd31Richard Smith/// };
36119a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template struct S<int, int>;
36129a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \endcode
36139a4db032ecd991626d236a502e770126db32bd31Richard Smithclass FunctionParmPackExpr : public Expr {
36149a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The function parameter pack which was referenced.
36159a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *ParamPack;
36169a4db032ecd991626d236a502e770126db32bd31Richard Smith
36179a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The location of the function parameter pack reference.
36189a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation NameLoc;
36199a4db032ecd991626d236a502e770126db32bd31Richard Smith
36209a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief The number of expansions of this pack.
36219a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned NumParameters;
36229a4db032ecd991626d236a502e770126db32bd31Richard Smith
36239a4db032ecd991626d236a502e770126db32bd31Richard Smith  FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack,
36249a4db032ecd991626d236a502e770126db32bd31Richard Smith                       SourceLocation NameLoc, unsigned NumParams,
36259a4db032ecd991626d236a502e770126db32bd31Richard Smith                       Decl * const *Params);
36269a4db032ecd991626d236a502e770126db32bd31Richard Smith
36279a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTReader;
36289a4db032ecd991626d236a502e770126db32bd31Richard Smith  friend class ASTStmtReader;
36299a4db032ecd991626d236a502e770126db32bd31Richard Smith
36309a4db032ecd991626d236a502e770126db32bd31Richard Smithpublic:
36319a4db032ecd991626d236a502e770126db32bd31Richard Smith  static FunctionParmPackExpr *Create(ASTContext &Context, QualType T,
36329a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      ParmVarDecl *ParamPack,
36339a4db032ecd991626d236a502e770126db32bd31Richard Smith                                      SourceLocation NameLoc,
3634cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko                                      ArrayRef<Decl *> Params);
36359a4db032ecd991626d236a502e770126db32bd31Richard Smith  static FunctionParmPackExpr *CreateEmpty(ASTContext &Context,
36369a4db032ecd991626d236a502e770126db32bd31Richard Smith                                           unsigned NumParams);
36379a4db032ecd991626d236a502e770126db32bd31Richard Smith
36389a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the parameter pack which this expression refers to.
36399a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getParameterPack() const { return ParamPack; }
36409a4db032ecd991626d236a502e770126db32bd31Richard Smith
36419a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the location of the parameter pack.
36429a4db032ecd991626d236a502e770126db32bd31Richard Smith  SourceLocation getParameterPackLocation() const { return NameLoc; }
36439a4db032ecd991626d236a502e770126db32bd31Richard Smith
36449a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Iterators over the parameters which the parameter pack expanded
36459a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// into.
36469a4db032ecd991626d236a502e770126db32bd31Richard Smith  typedef ParmVarDecl * const *iterator;
36479a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator begin() const { return reinterpret_cast<iterator>(this+1); }
36489a4db032ecd991626d236a502e770126db32bd31Richard Smith  iterator end() const { return begin() + NumParameters; }
36499a4db032ecd991626d236a502e770126db32bd31Richard Smith
36509a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get the number of parameters in this parameter pack.
36519a4db032ecd991626d236a502e770126db32bd31Richard Smith  unsigned getNumExpansions() const { return NumParameters; }
36529a4db032ecd991626d236a502e770126db32bd31Richard Smith
36539a4db032ecd991626d236a502e770126db32bd31Richard Smith  /// \brief Get an expansion of the parameter pack by index.
36549a4db032ecd991626d236a502e770126db32bd31Richard Smith  ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; }
36559a4db032ecd991626d236a502e770126db32bd31Richard Smith
365665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; }
365765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; }
36589a4db032ecd991626d236a502e770126db32bd31Richard Smith
36599a4db032ecd991626d236a502e770126db32bd31Richard Smith  static bool classof(const Stmt *T) {
36609a4db032ecd991626d236a502e770126db32bd31Richard Smith    return T->getStmtClass() == FunctionParmPackExprClass;
36619a4db032ecd991626d236a502e770126db32bd31Richard Smith  }
36629a4db032ecd991626d236a502e770126db32bd31Richard Smith
36639a4db032ecd991626d236a502e770126db32bd31Richard Smith  child_range children() { return child_range(); }
36649a4db032ecd991626d236a502e770126db32bd31Richard Smith};
36659a4db032ecd991626d236a502e770126db32bd31Richard Smith
366603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that
366703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it.
366803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
366903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address
367003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a
367103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g.,
367203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
367303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code
367403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0;
367503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode
367603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
367703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
367803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference
367903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
368003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding
368103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues.
368203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr {
368303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief The temporary-generating expression whose value will be
368403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// materialized.
3685d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Temporary;
3686ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
368703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtReader;
368803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtWriter;
3689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
369003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic:
3691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3692b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor                           bool BoundToLvalueReference)
3693b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor    : Expr(MaterializeTemporaryExprClass, T,
369403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
369503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->isTypeDependent(), Temporary->isValueDependent(),
3696561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Temporary->isInstantiationDependent(),
369703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->containsUnexpandedParameterPack()),
369803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor      Temporary(Temporary) { }
3699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3700ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(EmptyShell Empty)
370103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    : Expr(MaterializeTemporaryExprClass, Empty) { }
3702ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
370303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Retrieve the temporary-generating subexpression whose value will
370403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// be materialized into a glvalue.
370503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3706ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
370703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Determine whether this materialized temporary is bound to an
370803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// lvalue reference; otherwise, it's bound to an rvalue reference.
3709ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isBoundToLvalueReference() const {
371003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return getValueKind() == VK_LValue;
371103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
371365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocStart() const LLVM_READONLY {
371465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Temporary->getLocStart();
371565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  }
371665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen  SourceLocation getLocEnd() const LLVM_READONLY {
371765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen    return Temporary->getLocEnd();
3718aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  }
3719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
372003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  static bool classof(const Stmt *T) {
372103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return T->getStmtClass() == MaterializeTemporaryExprClass;
372203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
372403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  // Iterators
372503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  child_range children() { return child_range(&Temporary, &Temporary + 1); }
372603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor};
3727ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
37285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
37295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
37305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3731