ExprCXX.h revision 4c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7
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
1764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl#include "clang/Basic/TypeTraits.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
19eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall#include "clang/AST/UnresolvedSet.h"
20d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl;
25aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl;
26aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl;
27aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary;
28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo;
294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
47b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
48063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
49063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
50063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
51b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr **args, unsigned numargs, QualType t,
54f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      ExprValueKind VK, SourceLocation operatorloc)
55cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
56f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
57063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor      Operator(Op) {}
581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
59ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
62b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
63b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
64063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
65ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
66b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
67b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
68b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
7463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
78b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
8388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
8488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
9188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
921817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
93f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
94cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
9588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
961817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
971817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
981817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
9988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
10088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
10188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  Expr *getImplicitObjectArgument();
10388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
104007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
105007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
106007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
107007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
108007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
109007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  CXXRecordDecl *getRecordDecl();
110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
11588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
117e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
118e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
119e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
120e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
121e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
122e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     Expr **args, unsigned numargs, QualType t,
125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     ExprValueKind VK, SourceLocation RP)
126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne               RP) {
128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const CUDAKernelCallExpr *) { return true; }
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
14649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
14749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
14849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
14949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
15049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1561d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
1571d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1611d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
1621d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
1631d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
1641d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor      RParenLoc(RParenLoc) {}
16549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
166f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
167f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
168ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1691d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
1701d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
1711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
17249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
17349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
174a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
175a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
176a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
177a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
1781d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
1791d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1801d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
18163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1821d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    return SourceRange(Loc, RParenLoc);
1831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
18549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
18649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
18749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
18849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
18949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
1941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
1991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
203f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
204f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2051d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
206f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
20849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
209f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
210f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
211f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
212f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
213f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
214f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
2161d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   TypeSourceInfo *Written, SourceLocation L,
2171d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
220ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
22349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
22449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
234f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
235f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2361d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
237f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2381d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
242f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
243f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
245f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
2471d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    TypeSourceInfo *Written, SourceLocation L,
2481d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
252ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
25649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
25749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
25849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
25949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
26049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
26149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
266f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
267f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
2681d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         TypeSourceInfo *writtenTy, SourceLocation l,
2691d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2711d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
27249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
273f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
274f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
275f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
276f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
277f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
278f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
279f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
2801d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                 TypeSourceInfo *WrittenTy, SourceLocation L,
2811d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
284ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
28649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
28749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
28949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
29049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
29149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
29249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
297f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
2981d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
2991d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3011d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
30249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
303ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
304f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
305f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
306f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
308f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
3091d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3101d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
312ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
31549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
31649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
3171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
3211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
3221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
3231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
3241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
326bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
327bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
328f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
3298b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
330eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
331eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
332eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
334eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
33663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
338eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
339eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
340eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
3431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
3441060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
34763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3506e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
3516e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
3526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
3536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
3546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
355bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
356bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
3586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
359eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
360eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
361eb7f96141f754150a92433286fa385910a22f494Sam Weinig
36263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
364eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
365eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
366eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3676e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
3686e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
3696e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
3706e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
3716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
37263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
3746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
375c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
376c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
377c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
378c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
379c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
380c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
381c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
38257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
383c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
384c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
385c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
38657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
387f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
38857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
38957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
39057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
391bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
392bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
39357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
39457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
39557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
396f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
3972850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
398bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
3992850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
400bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
401bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
40257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
403c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
40414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
40514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
40614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
40714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
40814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
40914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
41014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
41114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
41257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
41357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
41457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
41557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
41657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
41757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
41857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
41957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
420c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
42157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
422c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
42314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
42414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
42514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
42614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
42714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
42857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
42914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
430c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
43157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
432c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
43314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
434030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
435030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
436030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
437030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
438030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
43963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
44014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
44114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
442c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
443c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
444c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
445c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
446c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
447c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
44863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
44963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
45063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
45163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
45263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
454c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
45501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
45601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
45701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
45801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
45901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
46001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
46101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
46201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
46301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
46401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
46501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
4662e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
467bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
468bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
46901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
47001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
47101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
4722e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
474bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
47501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
47601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
47701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
47801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
47901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
48001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
48101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
48201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
48301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
48401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
48501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
48601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
48701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
48801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
48901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
49001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
49201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
49301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
49401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
49501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
49601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
49801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
49901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
50001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
50301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
50401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
50501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
50801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
50901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
51001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
51301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
51401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
51601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
51701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const CXXUuidofExpr *) { return true; }
51901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
52001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
52163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
52263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
52363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
52463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
52563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
52601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
52701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
528796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
529796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
530796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
531796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
532796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
533796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
534796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
535796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
536796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
537796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
538796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
539796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
540796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
541828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
542828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
543796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
544828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
545f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
5462850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
5472850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
550828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
551796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5522fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
5532fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5542fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
5552fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
5562fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
55763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
558796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
559828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
560828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
561828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
563796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
564796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
565796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
566796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
567796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
56863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
569796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
570796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
5721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
5731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
5741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
5751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
5761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
5771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
5781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
5791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
5801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
5811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
5821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
583bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
584bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
585f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Op(expr), ThrowLoc(l) {}
5862fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
5872fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
5891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
59042e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setSubExpr(Expr *E) { Op = E; }
59142e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
59242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
59342e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
5941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
59563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
5961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
5971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
5981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
5991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
6031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
6051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
60763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
60863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
60963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
6101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
6111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
6131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
6141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
6151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
6161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
61765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
61865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
61965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// When the bit is set, the subexpression is stored after the
62065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
62165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
62265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
624036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
625036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
626036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
627036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
62865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    : Expr(SC,
62965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
63065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
6312333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
632dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
633bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false),
634036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
63565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
636036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
637036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
638dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
639dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
640bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, false, false),
641bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
64265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
64365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
64465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
646030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
647030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
648030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
6501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
651036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
652036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
653036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
654f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
6551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
65665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
65765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
658036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C,
659036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
660036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param,
66165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
66265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6631060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
66465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
66565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
666030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6671060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
66865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const Expr *getExpr() const {
66965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
67065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
67165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
67265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
67365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  Expr *getExpr() {
67465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
67565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
67665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
67765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
6781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
679036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief Retrieve the location where this default argument was actually
680036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
681036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
682036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
68363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
6851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
6861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
6871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
6911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
6931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
69563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
6968a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
69760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
6983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
6991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
700987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
701c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
702c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
703c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
704b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
706b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
707c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
708c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
709c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
711b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
713f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
714c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
715fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
716ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
717ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
718ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
719ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
720ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
721ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
722ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
723ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
724ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
725ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
726ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
727ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
728ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
729ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
730fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
731fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
733fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
734fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
735bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
736bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
737bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
738bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
739bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
740bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
74188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
742fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
743d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
744d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
745d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
7461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
747fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
750f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
751d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
752f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
753fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
754fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
75588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
756fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
75763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
75896be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
75996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
760fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
761fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
762fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
763fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
764fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
765fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
766fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
767fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
76863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
769fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
770fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
77115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor.
77215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
77372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
77472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
77572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
77672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
77772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_VirtualBase
77872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
77972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson
78072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
78115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
78215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
78399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
784428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
78516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
78616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
78772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
78815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
78915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned NumArgs;
7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
791bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
79399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
794bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
79516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                   Expr **args, unsigned numargs,
7969db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                   bool ZeroInitialization = false,
797428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   ConstructionKind ConstructKind = CK_Complete,
798428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   SourceRange ParenRange = SourceRange());
799bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
8006d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8016d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
8026d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
8036d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8046d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
80515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
8066d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8076d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
8086d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
8096d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      Elidable(0), ZeroInitialization(0),
8106d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8116d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
8128e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
81399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
8141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
81516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                                  Expr **Args, unsigned NumArgs,
8169db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                                  bool ZeroInitialization = false,
817428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  ConstructionKind ConstructKind = CK_Complete,
818428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  SourceRange ParenRange = SourceRange());
8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
821d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
82239da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
82339da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
82499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
82599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
82699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
827d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
828d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
82939da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
83039da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
83116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
83216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
83316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
83416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
83516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
83616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
83716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor
8389db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
8399db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
84024eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
84124eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
84272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
84372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  void setConstructionKind(ConstructionKind CK) {
84472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
84572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
8469db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
84715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
84815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
85115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
85215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
85315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
85415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
855a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
85615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
85715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
858bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
859bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
860bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
861bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
862bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
863bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
864bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
865bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
866bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
8671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8682eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
8692eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
8702eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
8712eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
8722eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
8732eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
87463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
875428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
87615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
878524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
879524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
88015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
88115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
88463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
88563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
88663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
8876d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
88860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
88915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
89015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
89149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
89249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
89349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
89449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
895987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
896987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
897f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
898f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
899f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
9001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
901f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
90241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                        SourceLocation rParenLoc)
903f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
904f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
9050aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
9060aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
907f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
908f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
909f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
910f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
911f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
912f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
913f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
914f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
915f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
916f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
917f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
918f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
919f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
920ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
921987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
922ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
923987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
924ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
927987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
928987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
931987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
932987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
933987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
934987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
935506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
936506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
937506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
9381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
939506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
940ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// constructor to build a temporary object. With N == 1 arguments the
941ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
942506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
943506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
944506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
945506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
946506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
947506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
948506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
949506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
950524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
951ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
952506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
953506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
955ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         Expr **Args,unsigned NumArgs,
957428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
9581c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
9596d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
960ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
961506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
962ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
963ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
96463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
965ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
967506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
968506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
969506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
9706d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
97160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
972506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
973506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
974ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
975506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
976ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
977987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
978ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
979987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
980ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
981987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
982ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
983ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
984987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
985ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Create an explicitly-written scalar-value initialization
986ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
987ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
988ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
989ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
990f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
991bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false, false, false),
992ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
993ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
994ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
995ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
997ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
998ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
9994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1000ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1001ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
10024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
100363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1006ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1007987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1008ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  static bool classof(const CXXScalarValueInitExpr *) { return true; }
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1010987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
101163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1012987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1013987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
10144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls,
10154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)".
10164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
10174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Was the usage ::new, i.e. is the global new to be used?
10184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalNew : 1;
10194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is there an initializer? If not, built-ins are uninitialized, else they're
10204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // value-initialized.
10214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool Initializer : 1;
1022cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Do we allocate an array? If so, the first SubExpr is the size expression.
1023cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool Array : 1;
10246ec278d1a354517e20f13a877481453ee7940c78John McCall  // If this is an array allocation, does the usual deallocation
10256ec278d1a354517e20f13a877481453ee7940c78John McCall  // function for the allocated type want to know the allocated size?
10266ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
10274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of placement new arguments.
10286ec278d1a354517e20f13a877481453ee7940c78John McCall  unsigned NumPlacementArgs : 14;
10294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of constructor arguments. This may be 1 even for non-class
10304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // types; use the pseudo copy constructor.
1031cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  unsigned NumConstructorArgs : 14;
1032cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Contains an optional array size expression, any number of optional
1033cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // placement arguments, and any number of optional constructor arguments,
1034cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // in that order.
10354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
10364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the allocation function used.
10374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
10384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the deallocation function used in case of error. May be null.
10394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
10404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the constructor used. Cannot be null if AllocType is a record;
10414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // it would still point at the default constructor (even an implicit one).
10424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Must be null for all other types.
10434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *Constructor;
10444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10451bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
10461bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
10471bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
10484bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// \brief If the allocated type was expressed as a parenthesized type-id,
10494bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
10504bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
10514bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
10524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
10534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation EndLoc;
1054428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorLParen;
1055428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorRParen;
10564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
105760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
10584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
1059ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
10604bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             Expr **placementArgs, unsigned numPlaceArgs,
10614bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             SourceRange TypeIdParens,
1062ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
10634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             Expr **constructorArgs, unsigned numConsArgs,
10646ec278d1a354517e20f13a877481453ee7940c78John McCall             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
10656ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1066428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation startLoc, SourceLocation endLoc,
1067428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorLParen,
1068428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorRParen);
10695921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
10705921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
10715921863d8f24084797863b5df37842113bac4352Chris Lattner
10725921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
10735921863d8f24084797863b5df37842113bac4352Chris Lattner                         unsigned numConsArgs);
1074ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek
1075cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1076cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
10776217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1078cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
10794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10801bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
10811bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
10821bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
10831bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
10844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
10855921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
10864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
10875921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
10884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *getConstructor() const { return Constructor; }
10895921863d8f24084797863b5df37842113bac4352Chris Lattner  void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
10904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1091cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1092cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1093cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1094cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1095cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1096cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1097cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1098cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
10994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1100aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getPlacementArgs() {
1101aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array);
1102aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1103aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
11054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1106cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
11094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1110cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11134bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
11144bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
11154bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
11164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
11174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool hasInitializer() const { return Initializer; }
11186ec278d1a354517e20f13a877481453ee7940c78John McCall
11196ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
11206ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
11216ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.
11226ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
11236ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
11246ec278d1a354517e20f13a877481453ee7940c78John McCall  }
11254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1127aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
1128aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getConstructorArgs() {
1129aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1130aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1131aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getConstructorArg(unsigned i) {
11334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1134cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getConstructorArg(unsigned i) const {
11374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1138cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
11424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
11434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
1145cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
1148cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
1151cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
1154cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_begin() {
1158cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_end() {
1161cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_begin() const {
1164cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_end() const {
1167cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11695921863d8f24084797863b5df37842113bac4352Chris Lattner
11705921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
11715921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
11725921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
11735921863d8f24084797863b5df37842113bac4352Chris Lattner    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11745921863d8f24084797863b5df37842113bac4352Chris Lattner  }
11755921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
11765921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
11774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11785921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
11795921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
1180428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1181428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1182428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1183428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
118463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
11854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(StartLoc, EndLoc);
11864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
11894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
11904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
11924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
119463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
119563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0],
119663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       &SubExprs[0] + Array + getNumPlacementArgs()
119763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                         + getNumConstructorArgs());
119863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
11994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
12024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray".
12034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
12044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
12054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
12064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
12074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
12084076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
12094076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
12104076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
12114076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
12126ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
12136ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
12146ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
12154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the operator delete overload that is used. Could be a member.
12164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
12174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The pointer expression to be deleted.
12184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt *Argument;
12194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Location of the expression.
12204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation Loc;
12214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
12224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
12236ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
12246ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1225bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1226bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1227f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
12284076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
12296ec278d1a354517e20f13a877481453ee7940c78John McCall      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
12304076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
123195fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
123295fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
12334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
12354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
12364076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
12374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12386ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
12396ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
12406ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
12416ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
12426ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
12436ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
12446ec278d1a354517e20f13a877481453ee7940c78John McCall  }
12456ec278d1a354517e20f13a877481453ee7940c78John McCall
12464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
12474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
12494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
12504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1251a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1252a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1253a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
12545833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
12555833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
125663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
12584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
12614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
12624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
12644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
126663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1267f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1268f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
12694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1271a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// \brief Structure used to store the type being destroyed by a
1272a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression.
1273a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1274a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Either the type source information or the name of the type, if
1275a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1276a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1277a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1278a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1279a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1280a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1281a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1282a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1283a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1284a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1285a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1286a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1287a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1288a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1289a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1290a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<TypeSourceInfo *>();
1291a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1292a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1293a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1294a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1295a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1296a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1297a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1298a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1299a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1300a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1301a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1302e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1303e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructor of a scalar type, except that scalar types don't have
1304e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1305e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1306e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1307e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1308e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1309e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1310e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1311e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1312a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1313e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1314e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1315a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1317a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1318e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1319a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1320a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1321a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1322e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1323e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1324a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1325a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1326a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1328a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1329a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1330a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1332a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1333a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1334f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1335a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1336f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
13371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1338e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1339e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1340e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1341e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1342e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The location of the '::' in a qualified pseudo-destructor
1343e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1344e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1345e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1346fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1347fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1348fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
1349a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The type being destroyed, or its name if we were unable to
1350a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1351a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1353f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1354f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1355a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1356a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1357a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1358f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1359e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1360e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1361fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1362e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1364de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1365de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1366f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1367de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1368a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1371a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1372a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1373f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1375f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1376f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1377f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1378f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1380a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1381a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1382f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifier *getQualifier() const {
1383f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
1384f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1386a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1387a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1388a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1389a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1390a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1391a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1393e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1394e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1395e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1396e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1397e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1398e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1399e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \p T may also be a scalar type and, therefore, cannot be part of a
1400e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1401e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
140226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1403e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1404e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1405e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1406e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1407e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1408fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1409fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1410fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
141126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
141226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1413a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1414a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// This type-source information is available for non-dependent
1415a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1416a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1417a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1418a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getDestroyedTypeInfo() const {
1419a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getTypeSourceInfo();
1420a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1421a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1422a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1423a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1424a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1425a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1426a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1427a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1428a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1429a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1430a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1431a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1432a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1433a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getDestroyedTypeLoc() const {
1434a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getLocation();
1435a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1437de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1438de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1439de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1440de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1441de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1442de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1443de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1444de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1445de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1446de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1447de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
144863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1451a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1452a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1453a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1455a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
145663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1457a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
146064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates.
146164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
146264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true
146364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false
146464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
14650dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
14660dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
14670dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
14680dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
146964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
147064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
147164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
147264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
147364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
147464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
147564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14760dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
14773d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
147864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
147964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
14803d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
14810dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
148264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1483f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1485bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
14860dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
148764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14886d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
14890dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
14903d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
14916d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
149263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
149364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14940dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
149564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14963d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
149764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14983d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
14993d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor
15000dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
150164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
150264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
150364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
150464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
150564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
150664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
150764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
150863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15096d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
151060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
151164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
151264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
15146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates.
15156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
15166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true
15176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
15186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
15196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
15206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
15226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
15236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
15256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
15266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
15286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
15296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
15316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
15326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
15346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
15356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
15376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
15386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
15396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
15406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
15416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
1542bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
1543bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
1544bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
15456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
15466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
15476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
15506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1551f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
15526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
155363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
15546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SourceRange(Loc, RParen);
15556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
15586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
15596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
15626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
15636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
15656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
15666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
15686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
15706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
15716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const BinaryTypeTraitExpr *) { return true; }
15736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
157563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
15786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
15796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15807bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
15817bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
15827bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
1583ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
15847bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
15857bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
1586928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
1587928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
1588928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
1589ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
15907bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The common name of these declarations.
15912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo;
1592ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
15934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// \brief The nested-name-specifier that qualifies the name, if any.
15944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
1595ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1596a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
15977bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// True if the name was a template-id.
15987bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool HasExplicitTemplateArgs;
15997bb12da2b0749eeebb21854c77877736969e59f2John McCall
1600bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
16014c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
16022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
1603bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
1604bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1605bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownDependent = false,
1606bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownContainsUnexpandedParameterPack = false);
16077bb12da2b0749eeebb21854c77877736969e59f2John McCall
1608a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
1609a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : Expr(K, Empty), Results(0), NumResults(0),
16104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      QualifierLoc(), HasExplicitTemplateArgs(false) { }
1611a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
1612bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
1613bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
1614bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
16157bb12da2b0749eeebb21854c77877736969e59f2John McCall
1616bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
16179c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
16189c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
16199c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
16209c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
16219c72c6088d591ace8503b842d39448c2040f3033John McCall  };
16229c72c6088d591ace8503b842d39448c2040f3033John McCall
16237bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
16247bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
16257bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
16269c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
16279c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
16289c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
16297bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
16307bb12da2b0749eeebb21854c77877736969e59f2John McCall
16319c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
16329c72c6088d591ace8503b842d39448c2040f3033John McCall
16337bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
16349c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
16359c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
16369c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
16379c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
16389c72c6088d591ace8503b842d39448c2040f3033John McCall
16399c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
16409c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
16419c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
16429c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
16439c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
16449c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
16459c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
16469c72c6088d591ace8503b842d39448c2040f3033John McCall    }
16479c72c6088d591ace8503b842d39448c2040f3033John McCall
16489c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
16497bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
16507bb12da2b0749eeebb21854c77877736969e59f2John McCall
1651e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  /// Gets the naming class of this lookup, if any.
1652e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
1653e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
16547bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
1655928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1656928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_end() const {
1657928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
1658928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
1659a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
16607bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the number of declarations in the unresolved set.
1661928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
16627bb12da2b0749eeebb21854c77877736969e59f2John McCall
16632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Gets the full name info.
16642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
16652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
16667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the name looked up.
16672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
16687bb12da2b0749eeebb21854c77877736969e59f2John McCall
16697bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the location of the name.
16702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
16717bb12da2b0749eeebb21854c77877736969e59f2John McCall
16727bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the nested-name qualifier, if one was given.
16734c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifier *getQualifier() const {
16744c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
16754c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
16767bb12da2b0749eeebb21854c77877736969e59f2John McCall
16774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// Fetches the nested-name qualifier with source-location information, if
16784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// one was given.
16794c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
16807bb12da2b0749eeebb21854c77877736969e59f2John McCall
16817bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Determines whether this expression had an explicit
16827bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// template argument list, e.g. f<int>.
16837bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
16847bb12da2b0749eeebb21854c77877736969e59f2John McCall
16857bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
16867bb12da2b0749eeebb21854c77877736969e59f2John McCall
16877bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
16887bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
16897bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
16907bb12da2b0749eeebb21854c77877736969e59f2John McCall
1691096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1692096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1693096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1694096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1695096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1696096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
16977bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
16987bb12da2b0749eeebb21854c77877736969e59f2John McCall
16997bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
17007bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
17017bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
17027bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
17037bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
17044045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
17054045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
17064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
17077bb12da2b0749eeebb21854c77877736969e59f2John McCall};
17087bb12da2b0749eeebb21854c77877736969e59f2John McCall
17097bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
17107bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration.  This
17117bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways:
17127bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
17137bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
17147bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
17157bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
17167bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always
17177bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in
17187bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs.
17197bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
1720ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
1721ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
1722ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
1723ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
1724ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
17257453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
17267453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
17277453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
17287453ed4cb2cab113de3378df371b1c6f1243d832John McCall
17297bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
17307bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
17317bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
17327bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
17337bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
17347bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
1735f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1736bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedLookupExpr(ASTContext &C,
1737928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
17384c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
17392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
1740bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       bool RequiresADL, bool Overloaded,
1741bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
17425a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
17434c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1744bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                   TemplateArgs, Begin, End),
17457bb12da2b0749eeebb21854c77877736969e59f2John McCall      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1746ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
1747ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1748bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
1749bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
1750bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis      RequiresADL(false), Overloaded(false), NamingClass(0)
1751bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
1752bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
17534c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
17544c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
1755ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
1756ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1757c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
17584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
17592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
17605a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
17615a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
17625a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End) {
17634c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
17644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                       ADL, Overloaded, 0, Begin, End);
1765ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1766ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1767f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1768c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
17694c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
17702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
1771f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
17725a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      const TemplateArgumentListInfo &Args,
17735a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
17745a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
1775f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1776bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1777def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                           bool HasExplicitTemplateArgs,
1778bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
1779bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
1780ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
1781ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
1782ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
1783ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
17847453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
17857453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
17867453ed4cb2cab113de3378df371b1c6f1243d832John McCall
1787c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
1788c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
1789c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
1790c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1791c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
1792f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1793f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1794f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
1795f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
17967bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
17977bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
17987bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
17997bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
18007bb12da2b0749eeebb21854c77877736969e59f2John McCall
1801f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1802f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1803f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1804f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1805f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1806f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1807096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1808096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1809096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1810096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1811096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1812096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1813096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1814096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1815f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1816f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1817f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1818f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1819f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1820ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1821f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1822f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1823f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1824f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1825f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1826f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1827f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1828f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1829f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1830f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1831f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1832f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1833f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1834f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1835f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1836ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
183763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
18382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range(getNameInfo().getSourceRange());
18394c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (getQualifierLoc())
18404c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
18414c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (hasExplicitTemplateArgs())
18424c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setEnd(getRAngleLoc());
1843f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1844ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1845ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
184663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1847ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1848ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
1849ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
1850ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1851ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
1852ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
1853ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
18545953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
18555953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
18565953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
1857ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1858a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
18595953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
1860865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
18615953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
18625953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
18635953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
1864865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1865ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
1866a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1867a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
1868865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
1869ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
1870ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
187100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
187200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
187300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
187400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
18755953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
1876f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Whether the name includes explicit template arguments.
1877f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool HasExplicitTemplateArgs;
18781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1879f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
188000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
18812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
1882bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
1883f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1884f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
1885f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
188600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
18872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
1888f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs = 0);
18895953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
189012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1891def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                                bool HasExplicitTemplateArgs,
189212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
189312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
18945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
18952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
18962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
18982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
18995953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
19005953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
19012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
19025953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
190300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
190400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
190500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
190600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
190700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
1908ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
1909ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
191000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifier *getQualifier() const {
191100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return QualifierLoc.getNestedNameSpecifier();
191200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1914f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
1915f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
19161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1917f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1918f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1919f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
192112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
192212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
192312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
192412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
192512dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
1926f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1927f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1928f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1929f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1930f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1932096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1933096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1934096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1935096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1936096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1937096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1938096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1939096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1940f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1941f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1942f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1943f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1944f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1945f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1946f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1947f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1948edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
19491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1950f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1951f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1952f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1954f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1955f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1956d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1957d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1958f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1959f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1960f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
196263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
196300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
1964f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
1965f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
1966f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1967edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1970f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1971edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
1972f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1973f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
197463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19754045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
19764045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
19774045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
1978edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19804765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
19814765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
19824765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
19834765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// cleanups is temporary objects in C++, but several other C++
19844765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// expressions can create cleanups.
19854765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
198602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1988ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  CXXTemporary **Temps;
1989ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  unsigned NumTemps;
199002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
19914765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(ASTContext &C, Expr *SubExpr,
19924765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall                   CXXTemporary **Temps, unsigned NumTemps);
19934765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall
199488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
19954765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(EmptyShell Empty)
19964765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    : Expr(ExprWithCleanupsClass, Empty),
1997d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner      SubExpr(0), Temps(0), NumTemps(0) {}
1998d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
19994765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
20000ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        CXXTemporary **Temps,
20010ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        unsigned NumTemps);
20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  unsigned getNumTemporaries() const { return NumTemps; }
2004d04ed416be7c55bddddab1fa3fd38a0113a6b3daTed Kremenek  void setNumTemporaries(ASTContext &C, unsigned N);
2005d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
200688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary(unsigned i) {
200788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    assert(i < NumTemps && "Index out of range");
200888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    return Temps[i];
200988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  }
2010f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary(unsigned i) const {
20114765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2012f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
2013d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(unsigned i, CXXTemporary *T) {
2014d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    assert(i < NumTemps && "Index out of range");
2015d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    Temps[i] = T;
2016d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2019f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
202088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
202102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
202263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
202396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
202496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
202502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
202602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
202702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
20284765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
202902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
20304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static bool classof(const ExprWithCleanups *) { return true; }
203102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
203202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
203363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
203402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
203502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2036d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2037d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2038d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2039d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2040d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2041d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2042d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and
2043d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is
2044d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2045d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2046d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2047d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2048d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2049d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2050d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2051d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2052d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2053d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2054d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2055d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2056d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2057d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2058d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2059ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2060ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2061d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2062d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2063d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2064d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2065d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2066d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2067d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2068d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
20691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2070ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2071d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
2072d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             Expr **Args,
2073d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             unsigned NumArgs,
2074d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2075d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
20768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2077ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
20788dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2079ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2080ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2081d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2083ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2084d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
2085d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            Expr **Args,
2086d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            unsigned NumArgs,
2087d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2088d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
20898dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
20908dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
20918dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2092d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2093d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2094ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2095d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2096ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Retrieve the type source information for the type being
2097ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2098ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2099ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2100d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2101d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2102d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2103d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2104d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2105d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2106d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2107d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2108d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2109d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2110d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2111d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2112d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2113d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2114d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2115d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2116d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
21171dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
21181dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
21191dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
21201dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21211dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
21221dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
21231dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21241dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2125d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2126d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2127d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2128d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2129d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
21301dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
21311dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
21321dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
21331dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21341dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
21358dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
21368dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
21378dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
21388dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
21398dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
214063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
2141ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
21421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2143d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2144d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2145d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2146d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2147d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
214863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
214963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
215063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
215163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2152d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2153d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2154ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2155ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2156ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2157aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2158aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2159aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2160aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2161865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
21621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2163aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
21641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2166aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2167aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2168aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2169aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
21701c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
21711c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
21723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
21731c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
21743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Whether this member expression has explicitly-specified template
21753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// arguments.
2176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool HasExplicitTemplateArgs : 1;
21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21781c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
21791c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
21801c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2181a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
21827c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2184c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2186c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2187c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
2188c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// FIXME: This member, along with the Qualifier and QualifierRange, could
2189c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2190865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2191c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21931c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
21941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2195a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
21962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2198865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2199aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
22003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
22017c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
22023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
22032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2204d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
22051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22061c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2207865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2208bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2209bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2210bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
22117c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2212bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2213bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
22141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2215865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2217aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
22183b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
22197c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
22203b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
22212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2222d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22248dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
2225def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2226def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
22278dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2228aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2229aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2230aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
22314c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2232aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
22331c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
22341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
2235aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
2236aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2237aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2238aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
22391c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2240aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2241aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
22421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
22431c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
22441c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
22451c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
22461c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
22471c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
22481c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2249a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
2250a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
22517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifier *getQualifier() const {
22527c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
22537c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22557c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
22567c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
22577c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
22587c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
22597c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
2260c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
2261c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
2262c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
2263c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
2264c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
22651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
2267c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
2268c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
2269c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
2270c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
22711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
2272c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
2273c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22751c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
22761c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
22772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
22782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
22792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
22802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
22812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
22822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
22832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
22841c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
22851c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
22861c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
22872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
22881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
22893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
22903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
2291aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool hasExplicitTemplateArgs() const {
2292aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return HasExplicitTemplateArgs;
22933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
22941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
229536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
229636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2297096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
229836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    assert(HasExplicitTemplateArgs);
2299096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
230036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
230136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
230236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
230336c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2304096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
230536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
2306096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
2307096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2308096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2309096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2310096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2311096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2312096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2313096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2314096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
231536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
231636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
2317d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
2318d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
2319d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2320096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
2321d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2322d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
23238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
23248dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2325096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
23268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
23278dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
23293b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member name ('<'), if any.
23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
2331096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().LAngleLoc;
23323b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
23353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
2336833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
2337096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
23383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23403b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
23413b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
2343096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
23443b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
23473b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template arguments ('>').
23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
2349096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().RAngleLoc;
23503b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
235263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
2353aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
2354aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2355aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
2356aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
23577c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2358aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
23592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setBegin(MemberNameInfo.getBeginLoc());
23601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2361aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
2362aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
2363aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
23642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setEnd(MemberNameInfo.getEndLoc());
2365aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
23661c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2369865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
23701c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
2371865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
23721c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23731c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
237463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
237563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
237663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
237763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
23784045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
23794045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
23804045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
23811c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
23821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2383129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
2384aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
2385aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2386aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
2387aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
2388aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
2389aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
2390aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
2391aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
2392aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2393aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
2394aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
2395aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
23967bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
2397129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
2398129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
2399129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
2400129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2401129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
2402129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
2403129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
2404129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
24057bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
24067bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
24077bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
24087bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
24097bb12da2b0749eeebb21854c77877736969e59f2John McCall
24107bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
24117bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
2412129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2413129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
2414129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
2415129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2416bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2417aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
2418129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
24194c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
24202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
24215a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
24225a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2423a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2424a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
2425a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2426a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
2427129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
24284c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
24294c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
2430129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
2431129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
2432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
2433aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
2434129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
24354c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
24362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
24375a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
24385a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2439129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2440a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
2441def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2442def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
2443a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2444aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2445aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2446aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
24474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2448aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2449129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
2450129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
2451aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
2452aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2453aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2454aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
24552f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
24562f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
24572f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
24582f27bf854f0519810b34afd209089cc75536b757John McCall  }
2459129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2460aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2461a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2462a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
2463a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
2464a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2465aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2466129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
2467129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
2468129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
2469129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2470129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
2471129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2472129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2473c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
2474c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
2475c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
24762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
24772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
24782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
24792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2480129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
2481129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
24827bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
2483129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2484129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
2485129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
24867bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
2487129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
24887bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
24897bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name.
24907bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
24917bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
24927bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
24937bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
24947bb12da2b0749eeebb21854c77877736969e59f2John McCall
24957bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
24967bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name, if any.
24977bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
24987bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
24997bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2500129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2501129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2502096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2503096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2504096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2505096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2506096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2507096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2508096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2509096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2510129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Copies the template arguments into the given structure.
2511129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
25127bb12da2b0749eeebb21854c77877736969e59f2John McCall    getExplicitTemplateArgs().copyInto(List);
2513129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2514129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2515129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the left angle bracket following
2516129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the member name ('<').
2517129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getLAngleLoc() const {
25187bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().LAngleLoc;
2519129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2520129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2521129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the template arguments provided as part of this
2522129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// template-id.
2523129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
25247bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2525129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2526129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2527129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the number of template arguments provided as
2528129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// part of this template-id.
2529129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  unsigned getNumTemplateArgs() const {
25307bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2531129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2532129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2533129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the right angle bracket
2534129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// following the template arguments ('>').
2535129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getRAngleLoc() const {
25367bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().RAngleLoc;
2537129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2538129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
253963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
25402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range = getMemberNameInfo().getSourceRange();
2541aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2542aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
25434c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    else if (getQualifierLoc())
25444c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2545aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2546129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
2547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
2548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
2549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
2552129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
2553129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2554129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
2555129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2556129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
255763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
255863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
255963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
256063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2561129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
2562129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
25632e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
25642e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
25652e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
25662e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
25672e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
25682e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
25692e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
25702e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
25712e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2572c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
2573c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
25742e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
25752e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
25762e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
2577f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2578f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
2579bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
2580bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
25816b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
25826b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
25836b219d082434394c1ac401390ec1d1967727815aSebastian Redl
25846b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
25856b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
25862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
25872e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
25882e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
25892e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
259063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
25912e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
25922e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
25932e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
25942e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
25952e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
25962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
25972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const CXXNoexceptExpr *) { return true; }
25982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
25992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
260063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
26012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
26022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2603be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \brief Represents a C++0x pack expansion that produces a sequence of
2604be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
2605be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2606be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
2607be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
2608be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2609be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
2610be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
2611be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
2612be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
2613be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
2614be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
2615be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2616be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
2617be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// pattern is \c static_cast<Types&&>(args). When the \c forward function
2618be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
2619be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
2620be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
2621be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
262267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
262367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
262467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
262567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
262667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
262767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
262867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
262967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
2630be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
2631be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2632be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
263367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
2634be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2635be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
263667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
263767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                    llvm::Optional<unsigned> NumExpansions)
2638be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2639be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           Pattern->getObjectKind(), /*TypeDependent=*/true,
2640be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2641be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
264267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2643be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
2644be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2645be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2646be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2647be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2648be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2649be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2650be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2651be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2652be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2653be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
2654be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
2655be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2656be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
265767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief Determine the number of expansions that will be produced when
265867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
265967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
266067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
266167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
266267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
266367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return llvm::Optional<unsigned>();
266467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
266567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
266663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
266763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
266863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2669be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2670be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
2671be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
2672be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
2673be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const PackExpansionExpr *) { return true; }
2674be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2675be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
267663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
267763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
267863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2679be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
2680be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
26817bb12da2b0749eeebb21854c77877736969e59f2John McCallinline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
26827bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
26837bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
26847bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
26857bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
26867bb12da2b0749eeebb21854c77877736969e59f2John McCall}
26877bb12da2b0749eeebb21854c77877736969e59f2John McCall
2688ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \brief Represents an expression that computes the length of a parameter
2689ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
2690ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
2691ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
2692ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
2693ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
2694ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
2695ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
2696ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
2697ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
2698ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
2699ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
2700ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2701ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
2702ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
2703ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2704ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
2705ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
2706ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2707ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
2708ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2709ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
2710ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
2711ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
2712ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
2713ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2714ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
2715ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
2716ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2717ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
2718ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
2719ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2720ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
2721ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
2722ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
2723ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2724ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
2725ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2726ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
2727ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
2728ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2729ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
2730ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2731ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
2732ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
2733ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2734ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
2735ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
2736ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2737ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
2738ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
2739ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2740ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
2741ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2742ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
2743ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2744ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2745ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
2746ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2747ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2748ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
2749ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
2750ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2751ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
2752ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2753ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2754ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
2755ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
2756ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2757ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
2758ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2759c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// This routine may only be invoked when the expression is not
2760c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
2761ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
2762ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    assert(!isValueDependent() &&
2763ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
2764ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
2765ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2766ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
276763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
276863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(OperatorLoc, RParenLoc);
276963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2770ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2771ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
2772ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
2773ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2774ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const SizeOfPackExpr *) { return true; }
2775ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2776ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
277763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2778ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
2779c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2780c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
2781c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
2782c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
2783c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
2784c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
2785c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter lists, this node node is used to represent a non-type template
2786c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
2787c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
2788c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
2789c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
2790c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
2791c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
2792c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
2793c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
2794c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
2795c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2796c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
2797c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
2798c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
2799c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2800c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
2801c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
2802c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2803c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
2804c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
2805c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2806c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
2807c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtWriter;
2808c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2809c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
2810c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(QualType T,
2811c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
2812c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
2813c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
2814c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2815c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2816c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2817c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2818c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
2819c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2820c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2821c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
2822c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
2823c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2824c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
2825c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
2826c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
2827c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
282863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return NameLoc; }
2829c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2830c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
2831c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2832c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2833c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2834c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return true;
2835c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2836c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2837c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
283863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2839c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
2840ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
28415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
28425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2844