ExprCXX.h revision 0fee330f5754ca4b248e5bb7363e834668aff06d
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".
102b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
103b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek
104b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  /// Retrieves the declaration of the called method.
105b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
10688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
107007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
108007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
109007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
111007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
112007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  CXXRecordDecl *getRecordDecl();
113007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
11988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
120e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
121e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
122e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     Expr **args, unsigned numargs, QualType t,
128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     ExprValueKind VK, SourceLocation RP)
129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne               RP) {
131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const CUDAKernelCallExpr *) { return true; }
147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
14949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
15049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1591d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
1601d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
16149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
162f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
163f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1641d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
1651d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
1661d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
1671d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor      RParenLoc(RParenLoc) {}
16849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
169f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
170f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
171ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1721d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
1731d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
1741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
177a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
178a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
179a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
180a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
1811d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
1821d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1831d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
18463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1851d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    return SourceRange(Loc, RParenLoc);
1861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
18849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
18949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
1971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
19949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
20349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
20449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
20549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
206f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
207f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2081d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
209f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2101d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
21149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
212f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
213f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
214f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
216f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
2191d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   TypeSourceInfo *Written, SourceLocation L,
2201d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
221f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
222f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
223ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
23449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
23549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
23649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
237f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
238f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2391d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
240f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2411d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
24249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
243f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
248f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
2501d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    TypeSourceInfo *Written, SourceLocation L,
2511d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
252f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
253f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
254f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
255ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2560fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2570fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
26049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
26149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
26649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
26849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
27049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
271f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
2731d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         TypeSourceInfo *writtenTy, SourceLocation l,
2741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2761d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
27749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
278f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
279f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
280f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
281f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
283f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
284f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
2851d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                 TypeSourceInfo *WrittenTy, SourceLocation L,
2861d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
287f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
288f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
289ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
29149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
29249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
29349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
29949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
30149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
302f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
3031d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
3041d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3061d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
30749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
308ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
309f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
310f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
3141d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3151d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
316f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
317ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
32049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
32149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
3221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
3261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
3271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
3281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
3291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
3301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
331bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
332bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
3348b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
335eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
336eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
337eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
339eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
34163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
343eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
344eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
345eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
3481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
3491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
35263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3531060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3556e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
3566e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
3576e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
3586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
3596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
360bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
361bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
3636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
364eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
365eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
366eb7f96141f754150a92433286fa385910a22f494Sam Weinig
36763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3686e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
369eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
370eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
371eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
3736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
3746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
3756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
3766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
37763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3786e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
3796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
380c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
381c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
382c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
383c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
384c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
385c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
386c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
38757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
388c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
389c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
390c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
39157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
392f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
39357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
39457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
39557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
396bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
397bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
39857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
39957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
40057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
401f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
4022850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
403bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
4042850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
405bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
406bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
40757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
408c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
40914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
41014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
41114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
41214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
41314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
41414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
41514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
41614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
41757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
41857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
41957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
42057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
42157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
42257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
42357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
42457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
425c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
42657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
427c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
42814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
42914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
43014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
43114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
43214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
43357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
43414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
435c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
43657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
437c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
43814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
439030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
440030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
441030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
442030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
443030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
44463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
44514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
44614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
447c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
448c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
449c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
450c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
451c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
452c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
45363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
45463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
45563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
45663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
45763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
458c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
459c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
46001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
46101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
46201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
46301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
46401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
46501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
46601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
46701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
46801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
46901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
47001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
4712e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
472bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
47401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
47501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
47601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
4772e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
478bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
48001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
48101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
48201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
48301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
48401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
48501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
48601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
48701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
48801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
48901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
49101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
49301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
49401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
49501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
49701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
49801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
49901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
50001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
50301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
50401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
50501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
50801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
50901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
51001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
51301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
51401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
51501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
51801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
51901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
52001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
52101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
52201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
52301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const CXXUuidofExpr *) { return true; }
52401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
52501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
52663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
52763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
52863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
52963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
53063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
53101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
53201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
533796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
534796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
535796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
536796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
537796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
538796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
539796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
540796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
541796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
542796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
543796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
544796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
545796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
546828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
547828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
548796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
549828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
550f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
5512850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
5522850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
553bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
555828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
556796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5572fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
5582fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5592fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
5602fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
5612fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
56263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
563796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
564828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
565828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
566828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
568796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
569796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
570796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
571796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
572796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
57363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
574796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
575796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
5771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
5781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
5791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
5801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
5811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
5821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
5831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
5841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
5851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
5861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
5871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
588bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
589bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
590f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Op(expr), ThrowLoc(l) {}
5912fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
5922fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
5941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
59542e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setSubExpr(Expr *E) { Op = E; }
59642e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
59742e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
59842e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
5991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
60063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
6021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
6031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
6041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
6081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
6101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
61263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
61363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
61463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
6151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
6161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
6181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
6191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
6201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
6211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
62265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
62365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
62465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// When the bit is set, the subexpression is stored after the
62565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
62665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
62765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
629036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
630036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
631036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
632036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
63365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    : Expr(SC,
63465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
63565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
6362333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
637dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
638bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false),
639036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
64065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
641036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
642036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
643dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
644dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
645bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, false, false),
646bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
64765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
64865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
64965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
651030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
652030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
653030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
6551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
656036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
657036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
658036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
659f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
6601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
66165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
66265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
663036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C,
664036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
665036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param,
66665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
66765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6681060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
66965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
67065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
671030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
67365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const Expr *getExpr() const {
67465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
67565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
67665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
67765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
67865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  Expr *getExpr() {
67965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
68065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
68165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
68265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
6831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
684036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief Retrieve the location where this default argument was actually
685036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
686036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
687036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
68863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
6901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
6911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
6961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
6981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
70063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
7018a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
70260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
7033397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
7041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
705987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
706c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
707c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
708c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
709b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
711b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
712c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
713c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
714c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
716b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
7171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
718f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
719c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
720fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
721ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
722ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
723ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
724ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
725ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
726ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
727ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
728ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
729ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
730ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
731ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
732ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
733ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
734ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
735fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
736fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
738fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
739fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
740bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
741bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
742bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
743bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
744bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
745bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
74688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
747fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
748d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
749d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
750d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
752fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
755f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
756d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
757f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
758fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
759fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
76088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
761fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
76263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
76396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
76496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
765fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
766fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
767fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
768fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
769fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
770fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
771fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
772fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
77363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
774fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
775fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
77615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor.
77715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
77872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
77972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
78072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
78172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
78272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_VirtualBase
78372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
78472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson
78572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
78615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
78715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
78899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
789428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
79016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
79116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
79272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
79315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
79415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned NumArgs;
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
796bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
7971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
79899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
799bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
80016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                   Expr **args, unsigned numargs,
8019db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                   bool ZeroInitialization = false,
802428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   ConstructionKind ConstructKind = CK_Complete,
803428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   SourceRange ParenRange = SourceRange());
804bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
8056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8066d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
8076d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
8086d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8096d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
81015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
8116d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8126d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
8136d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
8146d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      Elidable(0), ZeroInitialization(0),
8156d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8166d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
8178e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
81899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
82016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                                  Expr **Args, unsigned NumArgs,
8219db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                                  bool ZeroInitialization = false,
822428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  ConstructionKind ConstructKind = CK_Complete,
823428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  SourceRange ParenRange = SourceRange());
8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
826d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
82739da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
82839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
82999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
83099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
83199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
832d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
833d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
83439da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
83539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
83616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
83716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
83816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
83916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
84016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
84116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
84216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor
8439db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
8449db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
84524eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
84624eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
84772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
84872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  void setConstructionKind(ConstructionKind CK) {
84972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
85072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
8519db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
85215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
85315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
85615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
85715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
85815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
85915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
860a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
86115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
86215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
863bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
864bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
865bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
866bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
867bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
868bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
869bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
870bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
871bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8732eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
8742eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
8752eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
8762eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
8772eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
8782eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
87963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
880428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
88115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
883524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
884524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
88515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
88615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
88963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
89063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
89163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
8926d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
89360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
89415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
89515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
89649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
89749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
89849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
89949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
900987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
901987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
902f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
903f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
904f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
9051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
906f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
90741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                        SourceLocation rParenLoc)
908f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
909f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
9100aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
9110aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
912f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
913f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
914f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
915f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
916f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
917f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
918f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
919f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
920f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
921f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
922f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
923f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
924f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
925ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
926987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
927ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
928987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
929ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
932987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
933987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
9341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
936987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
937987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
938987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
939987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
940506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
941506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
942506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
9431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
944506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
945ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// constructor to build a temporary object. With N == 1 arguments the
946ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
947506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
948506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
949506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
950506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
951506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
952506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
953506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
954506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
955524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
956ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
957506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
958506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
960ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         Expr **Args,unsigned NumArgs,
962428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
9631c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
9646d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
965ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
966506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
967ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
968ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
96963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
970ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
9711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
972506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
973506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
974506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
9756d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
97660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
977506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
978506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
979ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
980506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
981ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
982987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
983ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
984987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
985ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
986987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
987ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
988ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
989987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
990ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Create an explicitly-written scalar-value initialization
991ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
992ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
993ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
994ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
995f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
996bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false, false, false),
997ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
998ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
999ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1000ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1002ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1003ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
10044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1005ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1006ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
10074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1011ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1012987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1013ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  static bool classof(const CXXScalarValueInitExpr *) { return true; }
10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1015987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
101663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1017987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1018987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
10194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls,
10204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)".
10214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
10224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Was the usage ::new, i.e. is the global new to be used?
10234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalNew : 1;
10244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is there an initializer? If not, built-ins are uninitialized, else they're
10254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // value-initialized.
10264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool Initializer : 1;
1027cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Do we allocate an array? If so, the first SubExpr is the size expression.
1028cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool Array : 1;
10296ec278d1a354517e20f13a877481453ee7940c78John McCall  // If this is an array allocation, does the usual deallocation
10306ec278d1a354517e20f13a877481453ee7940c78John McCall  // function for the allocated type want to know the allocated size?
10316ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
10324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of placement new arguments.
10336ec278d1a354517e20f13a877481453ee7940c78John McCall  unsigned NumPlacementArgs : 14;
10344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of constructor arguments. This may be 1 even for non-class
10354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // types; use the pseudo copy constructor.
1036cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  unsigned NumConstructorArgs : 14;
1037cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Contains an optional array size expression, any number of optional
1038cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // placement arguments, and any number of optional constructor arguments,
1039cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // in that order.
10404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
10414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the allocation function used.
10424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
10434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the deallocation function used in case of error. May be null.
10444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
10454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the constructor used. Cannot be null if AllocType is a record;
10464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // it would still point at the default constructor (even an implicit one).
10474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Must be null for all other types.
10484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *Constructor;
10494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10501bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
10511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
10521bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
10534bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// \brief If the allocated type was expressed as a parenthesized type-id,
10544bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
10554bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
10564bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
10574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
10584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation EndLoc;
1059428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorLParen;
1060428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorRParen;
10614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
106260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
10634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
1064ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
10654bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             Expr **placementArgs, unsigned numPlaceArgs,
10664bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             SourceRange TypeIdParens,
1067ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
10684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             Expr **constructorArgs, unsigned numConsArgs,
10696ec278d1a354517e20f13a877481453ee7940c78John McCall             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
10706ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1071428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation startLoc, SourceLocation endLoc,
1072428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorLParen,
1073428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorRParen);
10745921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
10755921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
10765921863d8f24084797863b5df37842113bac4352Chris Lattner
10775921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
10785921863d8f24084797863b5df37842113bac4352Chris Lattner                         unsigned numConsArgs);
1079ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek
1080cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1081cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
10826217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1083cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
10844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10851bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
10861bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
10871bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1088c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1089c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1090c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// C++0x [expr.new]p13:
1091c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1092c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1093c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1094c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1095c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1096c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1097c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
10988026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
10991bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
11004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
11015921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
11024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
11035921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
11044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *getConstructor() const { return Constructor; }
11055921863d8f24084797863b5df37842113bac4352Chris Lattner  void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
11064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1107cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1108cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1109cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1110cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1111cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1112cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1113cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1114cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
11154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1116aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getPlacementArgs() {
1117aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array);
1118aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1119aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
11214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1122cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
11254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1126cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11294bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
11304bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
11314bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
11324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
11334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool hasInitializer() const { return Initializer; }
11346ec278d1a354517e20f13a877481453ee7940c78John McCall
11356ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
11366ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
11376ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.
11386ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
11396ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
11406ec278d1a354517e20f13a877481453ee7940c78John McCall  }
11414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1143aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
1144aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getConstructorArgs() {
1145aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1146aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1147aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getConstructorArg(unsigned i) {
11494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1150cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getConstructorArg(unsigned i) const {
11534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1154cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
11584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
11594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
1161cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
1164cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
1167cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
1170cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_begin() {
1174cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_end() {
1177cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_begin() const {
1180cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_end() const {
1183cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11855921863d8f24084797863b5df37842113bac4352Chris Lattner
11865921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
11875921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
11885921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
11895921863d8f24084797863b5df37842113bac4352Chris Lattner    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11905921863d8f24084797863b5df37842113bac4352Chris Lattner  }
11915921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
11925921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
11934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11945921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
11955921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
1196428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1197428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1198428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1199428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
120063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(StartLoc, EndLoc);
12024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
12054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
12064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
12084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
121063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
121163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0],
121263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       &SubExprs[0] + Array + getNumPlacementArgs()
121363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                         + getNumConstructorArgs());
121463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
12154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
12184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray".
12194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
12204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
12214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
12224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
12234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
12244076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
12254076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
12264076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
12274076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
12286ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
12296ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
12306ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
12314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the operator delete overload that is used. Could be a member.
12324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
12334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The pointer expression to be deleted.
12344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt *Argument;
12354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Location of the expression.
12364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation Loc;
12374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
12384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
12396ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
12406ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1241bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1242bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
12444076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
12456ec278d1a354517e20f13a877481453ee7940c78John McCall      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
12464076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
124795fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
124895fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
12494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
12514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
12524076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
12534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12546ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
12556ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
12566ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
12576ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
12586ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
12596ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
12606ec278d1a354517e20f13a877481453ee7940c78John McCall  }
12616ec278d1a354517e20f13a877481453ee7940c78John McCall
12624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
12634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
12654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
12664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1267a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1268a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1269a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
12705833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
12715833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
127263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
12744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
12774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
12784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
12804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
128263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1283f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1284f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
12854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1287a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// \brief Structure used to store the type being destroyed by a
1288a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression.
1289a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1290a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Either the type source information or the name of the type, if
1291a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1292a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1293a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1294a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1295a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1296a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1297a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1298a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1299a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1300a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1301a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1302a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1303a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1304a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1305a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1306a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<TypeSourceInfo *>();
1307a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1308a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1309a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1310a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1311a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1312a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1313a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1314a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1315a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1316a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1317a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1318e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1319e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructor of a scalar type, except that scalar types don't have
1320e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1321e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1322e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1323e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1324e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1325e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1326e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1327e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1328a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1329e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1330e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1331a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1333a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1334e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1335a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1336a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1337a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1338e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1339e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1340a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1341a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1342a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
13431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1344a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1345a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1346a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1348a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1349a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1350f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1351a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1352f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1354e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1355e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1356e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1357e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1358e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The location of the '::' in a qualified pseudo-destructor
1359e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1360e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1361e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1362fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1363fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1364fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
1365a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The type being destroyed, or its name if we were unable to
1366a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1367a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1369f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1370f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1371a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1372a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1373a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1374f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1375e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1376e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1377fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1378e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1380de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1381de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1382f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1383de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1384a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1387a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1388a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1389f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
13901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1391f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1392f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1393f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1394f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1396a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1397a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1398f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifier *getQualifier() const {
1399f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
1400f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1402a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1403a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1404a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1405a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1406a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1407a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1409e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1410e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1411e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1412e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1413e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1414e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1415e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \p T may also be a scalar type and, therefore, cannot be part of a
1416e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1417e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
141826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1419e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1420e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1421e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1422e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1423e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1424fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1425fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1426fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
142726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
142826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1429a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1430a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// This type-source information is available for non-dependent
1431a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1432a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1433a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1434a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getDestroyedTypeInfo() const {
1435a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getTypeSourceInfo();
1436a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1437a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1438a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1439a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1440a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1441a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1442a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1443a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1444a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1445a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1446a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1447a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1448a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1449a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getDestroyedTypeLoc() const {
1450a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getLocation();
1451a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1453de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1454de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1455de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1456de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1457de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1458de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1459de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1460de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1461de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1462de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1463de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
146463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
14651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1467a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1468a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1469a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1471a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
147263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1473a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
147564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
147664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates.
147764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
147864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true
147964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false
148064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
14810dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
14820dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
14830dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
14840dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
148564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
148664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
148764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
148864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
148964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
149064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
149164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14920dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
14933d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
149464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
149564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
14963d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
14970dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
149864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1499f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1500bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1501bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
15020dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
150364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15046d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
15050dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
15063d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
15076d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
150863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
150964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15100dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
151164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15123d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
151364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15143d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
15153d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor
15160dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
151764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
151864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
151964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
152064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
152164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
152264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
152364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
152463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15256d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
152660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
152764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
152864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
15306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates.
15316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
15326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true
15336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
15346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
15356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
15366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
15386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
15396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
15416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
15426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
15446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
15456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
15476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
15486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
15506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
15516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
15536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
15546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
15556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
15566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
15576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
1558bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
1559bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
1560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
15616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
15626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
15636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
15666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1567f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
15686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
156963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
15706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SourceRange(Loc, RParen);
15716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
15746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
15756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
15786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
15796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
15816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
15826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
15846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
15866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
15876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const BinaryTypeTraitExpr *) { return true; }
15896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
159163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
15946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
15956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15967bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
15977bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
15987bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
1599ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
16007bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
16017bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
1602928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
1603928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
1604928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
1605ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
16067bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The common name of these declarations.
16072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo;
1608ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
16094c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// \brief The nested-name-specifier that qualifies the name, if any.
16104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
1611ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1612a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
16137bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// True if the name was a template-id.
16147bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool HasExplicitTemplateArgs;
16157bb12da2b0749eeebb21854c77877736969e59f2John McCall
1616bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
16174c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
16182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
1619bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
1620bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1621bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownDependent = false,
1622bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownContainsUnexpandedParameterPack = false);
16237bb12da2b0749eeebb21854c77877736969e59f2John McCall
1624a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
1625a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : Expr(K, Empty), Results(0), NumResults(0),
16264c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      QualifierLoc(), HasExplicitTemplateArgs(false) { }
1627a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
1628bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
1629bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
1630bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
16317bb12da2b0749eeebb21854c77877736969e59f2John McCall
1632bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
16339c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
16349c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
16359c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
16369c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
16379c72c6088d591ace8503b842d39448c2040f3033John McCall  };
16389c72c6088d591ace8503b842d39448c2040f3033John McCall
16397bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
16407bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
16417bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
16429c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
16439c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
16449c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
16457bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
16467bb12da2b0749eeebb21854c77877736969e59f2John McCall
16479c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
16489c72c6088d591ace8503b842d39448c2040f3033John McCall
16497bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
16509c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
16519c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
16529c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
16539c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
16549c72c6088d591ace8503b842d39448c2040f3033John McCall
16559c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
16569c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
16579c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
16589c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
16599c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
16609c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
16619c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
16629c72c6088d591ace8503b842d39448c2040f3033John McCall    }
16639c72c6088d591ace8503b842d39448c2040f3033John McCall
16649c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
16657bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
16667bb12da2b0749eeebb21854c77877736969e59f2John McCall
1667e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  /// Gets the naming class of this lookup, if any.
1668e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
1669e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
16707bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
1671928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1672928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_end() const {
1673928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
1674928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
1675a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
16767bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the number of declarations in the unresolved set.
1677928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
16787bb12da2b0749eeebb21854c77877736969e59f2John McCall
16792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Gets the full name info.
16802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
16812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
16827bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the name looked up.
16832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
16847bb12da2b0749eeebb21854c77877736969e59f2John McCall
16857bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the location of the name.
16862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
16877bb12da2b0749eeebb21854c77877736969e59f2John McCall
16887bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the nested-name qualifier, if one was given.
16894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifier *getQualifier() const {
16904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
16914c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
16927bb12da2b0749eeebb21854c77877736969e59f2John McCall
16934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// Fetches the nested-name qualifier with source-location information, if
16944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// one was given.
16954c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
16967bb12da2b0749eeebb21854c77877736969e59f2John McCall
16977bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Determines whether this expression had an explicit
16987bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// template argument list, e.g. f<int>.
16997bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
17007bb12da2b0749eeebb21854c77877736969e59f2John McCall
17017bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
17027bb12da2b0749eeebb21854c77877736969e59f2John McCall
17037bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
17047bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
17057bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
17067bb12da2b0749eeebb21854c77877736969e59f2John McCall
1707096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1708096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1709096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1710096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1711096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1712096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
17137bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
17147bb12da2b0749eeebb21854c77877736969e59f2John McCall
17157bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
17167bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
17177bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
17187bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
17197bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
17204045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
17214045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
17224045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
17237bb12da2b0749eeebb21854c77877736969e59f2John McCall};
17247bb12da2b0749eeebb21854c77877736969e59f2John McCall
17257bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
17267bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration.  This
17277bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways:
17287bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
17297bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
17307bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
17317bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
17327bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always
17337bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in
17347bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs.
17357bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
1736ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
1737ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
1738ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
1739ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
1740ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
17417453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
17427453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
17437453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
17447453ed4cb2cab113de3378df371b1c6f1243d832John McCall
17457bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
17467bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
17477bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
17487bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
17497bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
17507bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
1751f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1752bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedLookupExpr(ASTContext &C,
1753928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
17544c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
17552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
1756bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       bool RequiresADL, bool Overloaded,
1757bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
17585a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
17594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1760bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                   TemplateArgs, Begin, End),
17617bb12da2b0749eeebb21854c77877736969e59f2John McCall      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1762ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
1763ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1764bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
1765bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
1766bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis      RequiresADL(false), Overloaded(false), NamingClass(0)
1767bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
1768bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
17694c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
17704c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
1771ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
1772ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1773c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
17744c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
17752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
17765a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
17775a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
17785a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End) {
17794c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
17804c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                       ADL, Overloaded, 0, Begin, End);
1781ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1782ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1783f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1784c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
17854c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
17862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
1787f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
17885a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      const TemplateArgumentListInfo &Args,
17895a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
17905a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
1791f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1792bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1793def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                           bool HasExplicitTemplateArgs,
1794bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
1795bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
1796ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
1797ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
1798ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
1799ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
18007453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
18017453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
18027453ed4cb2cab113de3378df371b1c6f1243d832John McCall
1803c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
1804c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
1805c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
1806c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1807c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
1808f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1809f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1810f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
1811f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
18127bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
18137bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
18147bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
18157bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
18167bb12da2b0749eeebb21854c77877736969e59f2John McCall
1817f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1818f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1819f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1820f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1821f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1822f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1823096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1824096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1825096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1826096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1827096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1828096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1829096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1830096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1831f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1832f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1833f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1834f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1835f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1836ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1837f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1838f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1839f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1840f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1841f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1842f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1843f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1844f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1845f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1846f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1847f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1848f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1849f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1850f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1851f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1852ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
185363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
18542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range(getNameInfo().getSourceRange());
18554c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (getQualifierLoc())
18564c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
18574c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (hasExplicitTemplateArgs())
18584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setEnd(getRAngleLoc());
1859f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1860ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1861ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
186263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1863ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1864ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
1865ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
1866ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1867ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
1868ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
1869ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
18705953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
18715953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
18725953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
1873ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1874a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
18755953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
1876865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
18775953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
18785953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
18795953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
1880865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1881ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
1882a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1883a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
1884865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
1885ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
1886ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
188700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
188800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
188900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
189000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
18915953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
1892f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Whether the name includes explicit template arguments.
1893f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool HasExplicitTemplateArgs;
18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1895f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
189600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
18972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
1898bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
1899f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1900f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
1901f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
190200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
19032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
1904f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs = 0);
19055953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
190612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1907def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                                bool HasExplicitTemplateArgs,
190812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
190912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
19105953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
19112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
19122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
19132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
19142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
19155953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
19165953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
19172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
19185953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
191900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
192000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
192100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
192200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
192300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
1924ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
1925ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
192600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifier *getQualifier() const {
192700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return QualifierLoc.getNestedNameSpecifier();
192800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1930f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
1931f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1933f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1934f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1935f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
193712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
193812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
193912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
194012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
194112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
1942f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1943f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1944f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1945f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1946f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1948096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1949096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1950096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1951096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1952096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1953096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1954096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1955096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1956f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1957f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1958f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1959f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1960f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1961f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1962f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1963f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1964edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1966f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1967f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1968f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1970f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1971f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1972d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1973d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1974f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1975f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1976f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
197863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
197900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
1980f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
1981f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
1982f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1983edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1986f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1987edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
1988f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1989f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
199063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19914045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
19924045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
19934045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
1994edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19964765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
19974765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
19984765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
19994765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// cleanups is temporary objects in C++, but several other C++
20004765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// expressions can create cleanups.
20014765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
200202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2004ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  CXXTemporary **Temps;
2005ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  unsigned NumTemps;
200602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
20074765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(ASTContext &C, Expr *SubExpr,
20084765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall                   CXXTemporary **Temps, unsigned NumTemps);
20094765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall
201088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
20114765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(EmptyShell Empty)
20124765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    : Expr(ExprWithCleanupsClass, Empty),
2013d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner      SubExpr(0), Temps(0), NumTemps(0) {}
2014d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
20154765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
20160ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        CXXTemporary **Temps,
20170ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        unsigned NumTemps);
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  unsigned getNumTemporaries() const { return NumTemps; }
2020d04ed416be7c55bddddab1fa3fd38a0113a6b3daTed Kremenek  void setNumTemporaries(ASTContext &C, unsigned N);
2021d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
202288eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary(unsigned i) {
202388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    assert(i < NumTemps && "Index out of range");
202488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    return Temps[i];
202588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  }
2026f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary(unsigned i) const {
20274765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2028f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
2029d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(unsigned i, CXXTemporary *T) {
2030d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    assert(i < NumTemps && "Index out of range");
2031d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    Temps[i] = T;
2032d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
20331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
203402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2035f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
203688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
203702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
203863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
203996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
204096be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
204102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
204202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
204302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
20444765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
204502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
20464765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static bool classof(const ExprWithCleanups *) { return true; }
204702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
204802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
204963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
205002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
205102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2052d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2053d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2054d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2055d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2056d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2057d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2058d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and
2059d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is
2060d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2061d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2062d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2063d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2064d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2065d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2066d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2067d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2068d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2069d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2070d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2071d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2072d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2073d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2074d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2075ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2076ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2077d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2078d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2079d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2080d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2081d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2082d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2083d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2084d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
20851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2086ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2087d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
2088d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             Expr **Args,
2089d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             unsigned NumArgs,
2090d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2091d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
20928dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2093ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
20948dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2095ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2096ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2097d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2099ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2100d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
2101d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            Expr **Args,
2102d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            unsigned NumArgs,
2103d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2104d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
21058dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
21068dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
21078dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2108d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2109d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2110ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2111d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2112ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Retrieve the type source information for the type being
2113ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2114ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2115ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2116d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2117d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2118d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2119d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2120d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2121d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2122d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2123d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2124d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2125d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2126d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2127d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2128d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2129d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2130d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2131d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2132d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
21331dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
21341dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
21351dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
21361dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21371dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
21381dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
21391dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21401dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2141d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2142d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2143d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2144d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2145d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
21461dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
21471dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
21481dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
21491dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
21501dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
21518dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
21528dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
21538dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
21548dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
21558dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
215663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
2157ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2159d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2160d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2161d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2162d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2163d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
216463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
216563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
216663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
216763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2168d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2169d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2170ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2171ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2172ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2173aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2174aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2175aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2177865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
21781c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2179aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
21801c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2182aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2183aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2184aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2185aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
21861c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
21871c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
21883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
21891c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
21903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Whether this member expression has explicitly-specified template
21913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// arguments.
2192aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool HasExplicitTemplateArgs : 1;
21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
21951c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
21961c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2197a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
21987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
21991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2200c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2202c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2203c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
220446bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
2205c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2206865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2207c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
22101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2211a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
22122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2214865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2215aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
22163b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
22177c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
22183b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
22192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2220d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2223865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2224bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2225bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2226bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
22277c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2228bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2229bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
22301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2231865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
22321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2233aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
22343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
22357c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
22363b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
22372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2238d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
22391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22408dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
2241def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2242def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
22438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2244aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2245aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2246aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
22474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2248aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
22491c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
22501c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
2251aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
2252aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2253aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2254aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
22551c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2256aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2257aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
22581c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
22591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
22601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
22611c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
22621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
22631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
22641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2265a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
2266a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
22677c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifier *getQualifier() const {
22687c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
22697c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
22701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
22727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
22737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
22747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
22757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
2276c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
2277c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
2278c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
2279c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
2280c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
22811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
22821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
2283c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
2284c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
2285c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
2286c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
2288c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
2289c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
22901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22911c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
22921c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
22932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
22942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
22952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
22962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
22972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
22982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
22992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
23001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
23021c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
23032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
23041c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
23063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
2307aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool hasExplicitTemplateArgs() const {
2308aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return HasExplicitTemplateArgs;
23093b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
231136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
231236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2313096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
231436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    assert(HasExplicitTemplateArgs);
2315096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
231636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
231736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
231836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
231936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2320096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
232136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
2322096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
2323096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2324096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2325096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2326096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2327096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2328096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2329096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2330096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
233136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
233236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
2333d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
2334d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
2335d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2336096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
2337d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2338d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
23398dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
23408dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2341096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
23428dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
23438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
23453b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member name ('<'), if any.
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
2347096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().LAngleLoc;
23483b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23503b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
23513b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
2352833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
2353096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
23543b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23563b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
23573b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
2359096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
23603b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
23633b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template arguments ('>').
23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
2365096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().RAngleLoc;
23663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
236863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
2369aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
2370aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2371aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
2372aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
23737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2374aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
23752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setBegin(MemberNameInfo.getBeginLoc());
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2377aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
2378aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
2379aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
23802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setEnd(MemberNameInfo.getEndLoc());
2381aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
23821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
23831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2385865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
23861c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
2387865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
23881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23891c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
239063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
239163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
239263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
239363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
23944045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
23954045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
23964045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
23971c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
23981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2399129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
2400aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
2401aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2402aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
2403aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
2404aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
2405aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
2406aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
2407aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
2408aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2409aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
2410aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
2411aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
24127bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
2413129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
2414129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
2415129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
2416129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2417129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
2418129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
2419129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
2420129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
24217bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
24227bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
24237bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
24247bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
24257bb12da2b0749eeebb21854c77877736969e59f2John McCall
24267bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
24277bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
2428129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2429129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
2430129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
2431129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(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);
2439a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2440a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
2441a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2442a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
2443129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
24444c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
24454c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
2446129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
2447129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
2448bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
2449aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
2450129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
24514c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
24522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
24535a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
24545a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2455129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2456a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
2457def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2458def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
2459a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2460aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2461aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2462aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
24634c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2464aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2465129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
2466129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
2467aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
2468aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2469aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2470aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
24712f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
24722f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
24732f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
24742f27bf854f0519810b34afd209089cc75536b757John McCall  }
2475129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2476aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2477a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2478a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
2479a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
2480a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2481aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2482129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
2483129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
2484129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
2485129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2486129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
2487129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2488129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2489c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
2490c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
2491c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
24922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
24932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
24942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
24952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2496129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
2497129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
24987bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
2499129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2500129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
2501129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
25027bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
2503129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
25047bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
25057bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name.
25067bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
25077bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
25087bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
25097bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
25107bb12da2b0749eeebb21854c77877736969e59f2John McCall
25117bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
25127bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name, if any.
25137bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
25147bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
25157bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2516129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2517129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2518096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2519096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2520096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2521096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2522096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2523096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2524096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2525096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2526129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Copies the template arguments into the given structure.
2527129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
25287bb12da2b0749eeebb21854c77877736969e59f2John McCall    getExplicitTemplateArgs().copyInto(List);
2529129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2530129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2531129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the left angle bracket following
2532129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the member name ('<').
2533129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getLAngleLoc() const {
25347bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().LAngleLoc;
2535129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2536129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2537129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the template arguments provided as part of this
2538129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// template-id.
2539129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
25407bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2541129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2542129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2543129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the number of template arguments provided as
2544129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// part of this template-id.
2545129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  unsigned getNumTemplateArgs() const {
25467bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the right angle bracket
2550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// following the template arguments ('>').
2551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getRAngleLoc() const {
25527bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().RAngleLoc;
2553129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2554129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
255563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
25562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range = getMemberNameInfo().getSourceRange();
2557aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2558aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
25594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    else if (getQualifierLoc())
25604c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2561aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2562129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
2563129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
2564129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
2565129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2566129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2567129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
2568129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
2569129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2570129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
2571129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2572129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
257363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
257463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
257563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
257663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2577129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
2578129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
25792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
25802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
25812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
25822e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
25832e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
25842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
25852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
25862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
25872e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2588c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
2589c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
25902e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
25912e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
25922e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
2593f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2594f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
2595bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
2596bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
25976b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
25986b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
25996b219d082434394c1ac401390ec1d1967727815aSebastian Redl
26006b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
26016b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
26022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
26032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
26042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
26052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
260663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
26072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
26082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
26092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
26102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
26112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
26122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
26132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const CXXNoexceptExpr *) { return true; }
26142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
26152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
261663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
26172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
26182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2619be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \brief Represents a C++0x pack expansion that produces a sequence of
2620be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
2621be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2622be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
2623be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
2624be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2625be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
2626be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
2627be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
2628be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
2629be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
2630be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
2631be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2632be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
2633be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// pattern is \c static_cast<Types&&>(args). When the \c forward function
2634be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
2635be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
2636be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
2637be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
263867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
263967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
264067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
264167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
264267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
264367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
264467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
264567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
2646be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
2647be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2648be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
264967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
2650be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2651be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
265267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
265367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                    llvm::Optional<unsigned> NumExpansions)
2654be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2655be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           Pattern->getObjectKind(), /*TypeDependent=*/true,
2656be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2657be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
265867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2659be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
2660be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2661be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2662be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2663be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2664be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2665be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2666be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2667be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2668be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2669be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
2670be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
2671be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2672be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
267367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief Determine the number of expansions that will be produced when
267467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
267567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
267667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
267767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
267867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
267967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return llvm::Optional<unsigned>();
268067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
268167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
268263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
268363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
268463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2685be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2686be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
2687be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
2688be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
2689be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const PackExpansionExpr *) { return true; }
2690be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2691be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
269263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
269363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
269463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2695be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
2696be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
26977bb12da2b0749eeebb21854c77877736969e59f2John McCallinline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
26987bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
26997bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
27007bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
27017bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
27027bb12da2b0749eeebb21854c77877736969e59f2John McCall}
27037bb12da2b0749eeebb21854c77877736969e59f2John McCall
2704ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \brief Represents an expression that computes the length of a parameter
2705ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
2706ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
2707ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
2708ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
2709ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
2710ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
2711ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
2712ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
2713ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
2714ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
2715ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
2716ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2717ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
2718ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
2719ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2720ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
2721ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
2722ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2723ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
2724ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2725ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
2726ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
2727ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
2728ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
2729ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2730ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
2731ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
2732ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2733ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
2734ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
2735ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2736ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
2737ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
2738ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
2739ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2740ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
2741ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2742ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
2743ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
2744ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2745ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
2746ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2747ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
2748ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
2749ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2750ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
2751ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
2752ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2753ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
2754ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
2755ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2756ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
2757ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2758ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
2759ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2760ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2761ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
2762ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2763ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2764ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
2765ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
2766ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2767ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
2768ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2769ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2770ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
2771ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
2772ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2773ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
2774ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2775c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// This routine may only be invoked when the expression is not
2776c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
2777ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
2778ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    assert(!isValueDependent() &&
2779ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
2780ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
2781ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2782ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
278363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
278463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(OperatorLoc, RParenLoc);
278563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2786ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2787ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
2788ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
2789ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2790ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const SizeOfPackExpr *) { return true; }
2791ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2792ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
279363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2794ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
2795c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2796c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
2797c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
2798c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
2799c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
2800c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
2801c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter lists, this node node is used to represent a non-type template
2802c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
2803c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
2804c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
2805c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
2806c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
2807c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
2808c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
2809c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
2810c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
2811c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2812c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
2813c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
2814c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
2815c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2816c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
2817c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
2818c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2819c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
2820c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
2821c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2822c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
2823c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtWriter;
2824c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2825c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
2826c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(QualType T,
2827c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
2828c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
2829c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
2830c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2831c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2832c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2833c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2834c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
2835c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2836c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2837c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
2838c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
2839c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2840c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
2841c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
2842c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
2843c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
284463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return NameLoc; }
2845c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2846c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
2847c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2848c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2849c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2850c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return true;
2851c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2852c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2853c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
285463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2855c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
2856ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
28575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
28585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2860