ExprCXX.h revision d2598368876cfe40bc8465540033bc5b5e58d8af
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
244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  class CXXConstructorDecl;
25c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  class CXXDestructorDecl;
26e9f42087aabfdb6b2afc35c7e38ac65da063b409Fariborz Jahanian  class CXXMethodDecl;
27ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  class CXXTemporary;
28d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class 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,
54063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor                      SourceLocation operatorloc)
55063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
56063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor      Operator(Op) {}
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
58ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
60b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
61b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
62b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
63063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
64ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
65b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
66b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
67b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
68b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  virtual SourceRange getSourceRange() const;
741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
77b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
78b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
8288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
8388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
8488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
911817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
92668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek                    QualType t, SourceLocation rparenloc)
93668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek    : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
9488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
951817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
961817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
971817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
9888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
9988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
10088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
10188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  Expr *getImplicitObjectArgument();
10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
10300b98c229ef28a5e82943bb23d09fb46d24ca381Douglas Gregor  virtual SourceRange getSourceRange() const;
10400b98c229ef28a5e82943bb23d09fb46d24ca381Douglas Gregor
1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
10788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
11149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
11249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
11349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
11449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
11549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
11649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
11749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
11849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
12149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
12249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
123c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op,
12441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
12541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   SourceLocation l)
12641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : ExplicitCastExpr(SC, ty, kind, op, BasePath, writtenTy), Loc(l) {}
12749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
128ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell)
129ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : ExplicitCastExpr(SC, Shell) { }
130ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
13249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
13349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
134a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
135a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
136a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
137a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
138a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
1391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
1401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
1411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
14449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
14549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
14649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
14749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
14849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
14949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
15049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
1521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
1571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
15949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
16049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
16149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
16241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op,
16341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                    CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
16441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                    SourceLocation l)
16541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, BasePath, writtenTy, l) {}
16649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
167ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXStaticCastExpr(EmptyShell Empty)
168ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { }
169ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
17149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
17249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
17349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
17449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
18049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
18149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
18249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
18349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
18441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op,
18541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                     CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
18641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                     SourceLocation l)
18741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, BasePath,
18841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy, l) {}
18949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
190ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXDynamicCastExpr(EmptyShell Empty)
191ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { }
192ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
19949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
20349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
20449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
20549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
20649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
2077f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson  CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
20841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                         CXXBaseSpecifierArray BasePath,
2099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall                         TypeSourceInfo *writtenTy, SourceLocation l)
21041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, BasePath,
211cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson                       writtenTy, l) {}
21249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
213ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXReinterpretCastExpr(EmptyShell Empty)
214ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { }
215ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
21849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
21949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
22049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
22149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
22249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
22349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
2241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
2299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                   SourceLocation l)
23141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op,
23241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       CXXBaseSpecifierArray(), writtenTy, l) {}
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
234ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
235ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { }
236ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
24049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
2411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
2421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
2451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
2461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
2471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
2481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
2502333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
2518b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
252eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
253eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
254eb7f96141f754150a92433286fa385910a22f494Sam Weinig
2551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
256eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
260eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
261eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
262eb7f96141f754150a92433286fa385910a22f494Sam Weinig
2631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2641060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
2651060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
2661060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
2671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2681060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
2691060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
2701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
2711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
2721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
2736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
2746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
2756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
2766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
2776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
2782333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
2796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
280eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
281eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
282eb7f96141f754150a92433286fa385910a22f494Sam Weinig
2836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2846e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
285eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
286eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
287eb7f96141f754150a92433286fa385910a22f494Sam Weinig
2886e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
2896e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
2906e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
2916e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
2926e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
2936e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  virtual child_iterator child_begin();
2946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  virtual child_iterator child_end();
2956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
2966e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
297c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
298c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
299c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
300c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
301c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
302c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
303c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
30457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
305c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
306c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
307c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
30857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
30957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    : Expr(CXXTypeidExprClass, Ty,
31057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
31157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
31257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
31357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           Operand->getType()->isDependentType()),
31457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
31557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
31657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
31757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    : Expr(CXXTypeidExprClass, Ty,
3182850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
3192850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        false,
3202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
32157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor        Operand->isTypeDependent() || Operand->isValueDependent()),
32257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
323c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
32414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
32514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
32614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
32714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
32814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
32914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
33014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
33114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
33257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
33357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
33457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
33557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
33657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
33757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
33857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
33957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
340c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
34157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
342c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
34314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
34414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
34514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
34614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
34714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
34857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
34914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
350c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
35157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
352c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
35314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
354030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
355030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
356030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
357030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
358030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
35914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  virtual SourceRange getSourceRange() const { return Range; }
36014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
36114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
362c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
363c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
364c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
365c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
366c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
367c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
368c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  virtual child_iterator child_begin();
369c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  virtual child_iterator child_end();
370c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
371c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
372796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
373796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
374796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
375796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
376796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
377796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
378796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
379796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
380796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
381796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
382796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
383796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
384796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
385828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
386828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
387796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
388828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
3892850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    : Expr(CXXThisExprClass, Type,
3902850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
3912850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
3922850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           Type->isDependentType(), Type->isDependentType()),
393828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
394796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
3952fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
3962fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
3972fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
3982fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
3992fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
400796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
401796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
402828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
403828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
404828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
406796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
407796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
408796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
409796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
410796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
411796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  virtual child_iterator child_begin();
412796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  virtual child_iterator child_end();
413796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
414796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
4151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
4161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
4171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
4181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
4191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
4201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
4211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
4221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
4231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
4241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
4251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
4261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
4272850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
4282fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
4292fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
4301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
4311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
43242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setSubExpr(Expr *E) { Op = E; }
43342e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
43442e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
43542e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
4361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
4381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
4391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
4401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
4411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
4441060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
4451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
4471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
4491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
4501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
4511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
4521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4531060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
4541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
4551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
4561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
4571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
45865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
45965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
46065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// When the bit is set, the subexpression is stored after the
46165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
46265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
46365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
465036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
466036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
467036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
468f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlssonprotected:
469036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
47065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    : Expr(SC,
47165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
47265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
4732333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
4742333f7727f97018d6742e1e0938133bcfad967abEli Friedman           false, false),
475036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
47665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
477036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
478036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
479030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) {
48065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
48165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
48265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
48365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregorprotected:
48465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  virtual void DoDestroy(ASTContext &C);
48565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
4861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
487030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
488030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
489030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
4901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
4911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
492036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
493036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
494036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
495f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
4961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
49765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
49865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
499036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C,
500036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
501036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param,
50265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
50365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
5041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
50565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
50665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
5071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
508030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  /// isExprStored - Return true if this expression owns the expression.
509030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  bool isExprStored() const { return Param.getInt(); }
510030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
5111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
51265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const Expr *getExpr() const {
51365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
51465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
51565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
51665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
51765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  Expr *getExpr() {
51865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
51965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
52065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
52165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
522030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
523030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExpr(Expr *E) {
524030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Param.setInt(true);
525030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Param.setPointer((ParmVarDecl*)E);
526030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
5271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
528036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief Retrieve the location where this default argument was actually
529036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
530036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
531030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setUsedLocation(SourceLocation L) { Loc = L; }
532036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
5331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual SourceRange getSourceRange() const {
5341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
5351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
5361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
5371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
5381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
5391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
5401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
5411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
5421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
5431060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
5441060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
5451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_begin();
5461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  virtual child_iterator child_end();
5471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
548987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
549c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
550c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
551c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
552b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
554b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
555c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
55688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  ~CXXTemporary() { }
557c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
558c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
5591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
560b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
5611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
56242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  void Destroy(ASTContext &Ctx);
5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
564f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
565c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
566fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CXXBindTemporaryExpr - Represents binding an expression to a temporary,
568fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson/// so its destructor can be called later.
569fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
570fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
572fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
573fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
5752333f7727f97018d6742e1e0938133bcfad967abEli Friedman   : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
5762333f7727f97018d6742e1e0938133bcfad967abEli Friedman     Temp(temp), SubExpr(subexpr) { }
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ~CXXBindTemporaryExpr() { }
57888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
57942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
58042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
58142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
582fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
583d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
584d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
585d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
587fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
5881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
590f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
591d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
592f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
593fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
594fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
59588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
596fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
59796be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  virtual SourceRange getSourceRange() const {
59896be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
59996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
600fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
601fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
602fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
603fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
604fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
605fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
606fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
607fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
608fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  virtual child_iterator child_begin();
609fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  virtual child_iterator child_end();
610fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
611fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
612eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson/// CXXBindReferenceExpr - Represents binding an expression to a reference.
613eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson/// In the example:
614eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson///
615eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson/// const int &i = 10;
616eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson///
617eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson/// a bind reference expression is inserted to indicate that 10 is bound to
618d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner/// a reference, and that a temporary needs to be created to hold the
619d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner/// value.
620eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlssonclass CXXBindReferenceExpr : public Expr {
621eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  // SubExpr - The expression being bound.
622eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  Stmt *SubExpr;
623eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
624eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  // ExtendsLifetime - Whether binding this reference extends the lifetime of
625eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  // the expression being bound. FIXME: Add C++ reference.
626eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  bool ExtendsLifetime;
627eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
628eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  /// RequiresTemporaryCopy - Whether binding the subexpression requires a
629eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  /// temporary copy.
630eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  bool RequiresTemporaryCopy;
631eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
632eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  CXXBindReferenceExpr(Expr *subexpr, bool ExtendsLifetime,
633eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson                       bool RequiresTemporaryCopy)
634eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  : Expr(CXXBindReferenceExprClass, subexpr->getType(), false, false),
635eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    SubExpr(subexpr), ExtendsLifetime(ExtendsLifetime),
636eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    RequiresTemporaryCopy(RequiresTemporaryCopy) { }
637eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  ~CXXBindReferenceExpr() { }
638eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
639eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlssonprotected:
640eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  virtual void DoDestroy(ASTContext &C);
641eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
642eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlssonpublic:
643eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  static CXXBindReferenceExpr *Create(ASTContext &C, Expr *SubExpr,
644eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson                                      bool ExtendsLifetime,
645eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson                                      bool RequiresTemporaryCopy);
646eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
647eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
648eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
649eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
650eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
651eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  virtual SourceRange getSourceRange() const {
652eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    return SubExpr->getSourceRange();
653eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  }
654eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
6554e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  /// requiresTemporaryCopy - Whether binding the subexpression requires a
6564e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  /// temporary copy.
6574e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  bool requiresTemporaryCopy() const { return RequiresTemporaryCopy; }
6584e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson
6594e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  // extendsLifetime - Whether binding this reference extends the lifetime of
6604e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  // the expression being bound. FIXME: Add C++ reference.
6614e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson  bool extendsLifetime() { return ExtendsLifetime; }
6624e1c181e2bb378dad55dd25c18611e3a0fb6c22aAnders Carlsson
663eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  // Implement isa/cast/dyncast/etc.
664eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  static bool classof(const Stmt *T) {
665eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson    return T->getStmtClass() == CXXBindReferenceExprClass;
666eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  }
667eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  static bool classof(const CXXBindReferenceExpr *) { return true; }
668eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
669eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  // Iterators
670eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  virtual child_iterator child_begin();
671eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson  virtual child_iterator child_end();
672eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson};
673eb60edffa147e061278c436e513b0df9b4c4e7f6Anders Carlsson
67415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor.
67515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
67672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
67772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
67872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
67972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
68072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_VirtualBase
68172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
68272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson
68372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
68415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
68515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
68699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
68716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
68816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
68972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
69015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
69115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned NumArgs;
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
693bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
69599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
696bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
69716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                   Expr **args, unsigned numargs,
6989db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                   bool ZeroInitialization = false,
69972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson                   ConstructionKind ConstructKind = CK_Complete);
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ~CXXConstructExpr() { }
701bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
70242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
70342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
70415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
70539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  /// \brief Construct an empty C++ construction expression that will store
70639da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  /// \p numargs arguments.
70739da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs);
70839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
7098e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
71099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
71216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                                  Expr **Args, unsigned NumArgs,
7139db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                                  bool ZeroInitialization = false,
714fcaeef2ae00ec643eb024e0aca2c98701cf5627cAnders Carlsson                                  ConstructionKind ConstructKind = CK_Complete);
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
717d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
71839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
71939da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
72099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
72199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
72299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
723d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
724d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
72539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
72639da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
72716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
72816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
72916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
73016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
73116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
73216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
73316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor
7349db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
7359db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
73624eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
73724eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
73872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
73972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  void setConstructionKind(ConstructionKind CK) {
74072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
74172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
7429db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
74315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
74415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
74715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
74815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
74915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
75015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
751a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
75215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
75315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
754bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
755bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
756bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
757bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
758bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
759bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
760bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
761bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
762bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7642eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
7652eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
7662eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
7672eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
7682eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
7692eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
770e383768f7f5d45ca4af0b1c11cbf072de18bce98Ted Kremenek  virtual SourceRange getSourceRange() const;
77115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
773524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
774524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
77515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
77615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
77815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
77915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  virtual child_iterator child_begin();
78015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  virtual child_iterator child_end();
78115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
78215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
78349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
78449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
78549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
78649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
787987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
788987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
789987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
7909d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
79241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                        Expr *castExpr, CXXBaseSpecifierArray BasePath,
79341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                        SourceLocation rParenLoc)
7940aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr,
79541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       BasePath, writtenTy),
7960aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
7970aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
798ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXFunctionalCastExpr(EmptyShell Shell)
799ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { }
800ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
801987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
802ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
803987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
804ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
806987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
807987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
808987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
811987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
812987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
813987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
814987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
815506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
816506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
817506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
8181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
819506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
820506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// constructor to build a temporary object. If N == 0 but no
821506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// constructor will be called (because the functional cast is
822506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// performing a value-initialized an object whose class type has no
823506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// user-declared constructors), CXXZeroInitValueExpr will represent
824506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// the functional cast. Finally, with N == 1 arguments the functional
825506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// cast expression will be represented by CXXFunctionalCastExpr.
826506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
827506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
828506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
829506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
830506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
831506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
832506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
833506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
834524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
835506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  SourceLocation TyBeginLoc;
836506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  SourceLocation RParenLoc;
837506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
838506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
8401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         QualType writtenTy, SourceLocation tyBeginLoc,
8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         Expr **Args,unsigned NumArgs,
8421c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         SourceLocation rParenLoc,
8431c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
844506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ~CXXTemporaryObjectExpr() { }
846506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
847506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
848506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
849ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
850506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  virtual SourceRange getSourceRange() const {
851506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return SourceRange(TyBeginLoc, RParenLoc);
852506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
854506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
855506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
856506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
857506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
858506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
859987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
860506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
861506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// T, which is either a non-class type or a class type without any
862506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// user-defined constructors.
863987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
864987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidisclass CXXZeroInitValueExpr : public Expr {
865987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
866987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
867987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
868987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
869987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
8701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       SourceLocation rParenLoc ) :
871d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor    Expr(CXXZeroInitValueExprClass, ty, false, false),
872987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
874987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
875987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
876987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
8774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Whether this initialization expression was
8784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// implicitly-generated.
8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isImplicit() const {
8801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return TyBeginLoc.isInvalid() && RParenLoc.isInvalid();
8814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
8824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
883987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
884987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
885987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
888987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return T->getStmtClass() == CXXZeroInitValueExprClass;
889987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
890987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXZeroInitValueExpr *) { return true; }
8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
892987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
893987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual child_iterator child_begin();
894987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  virtual child_iterator child_end();
895987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
896987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
8974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls,
8984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)".
8994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
9004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Was the usage ::new, i.e. is the global new to be used?
9014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalNew : 1;
9024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Was the form (type-id) used? Otherwise, it was new-type-id.
9034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ParenTypeId : 1;
9044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is there an initializer? If not, built-ins are uninitialized, else they're
9054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // value-initialized.
9064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool Initializer : 1;
907cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Do we allocate an array? If so, the first SubExpr is the size expression.
908cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool Array : 1;
9094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of placement new arguments.
9104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned NumPlacementArgs : 14;
9114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of constructor arguments. This may be 1 even for non-class
9124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // types; use the pseudo copy constructor.
913cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  unsigned NumConstructorArgs : 14;
914cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Contains an optional array size expression, any number of optional
915cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // placement arguments, and any number of optional constructor arguments,
916cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // in that order.
9174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
9184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the allocation function used.
9194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
9204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the deallocation function used in case of error. May be null.
9214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
9224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the constructor used. Cannot be null if AllocType is a record;
9234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // it would still point at the default constructor (even an implicit one).
9244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Must be null for all other types.
9254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *Constructor;
9264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
9284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation EndLoc;
9294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
931ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
932ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek             Expr **placementArgs, unsigned numPlaceArgs, bool ParenTypeId,
933ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
9344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             Expr **constructorArgs, unsigned numConsArgs,
9354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             FunctionDecl *operatorDelete, QualType ty,
9364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             SourceLocation startLoc, SourceLocation endLoc);
937ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek
938ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  virtual void DoDestroy(ASTContext &C);
9394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
940cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
941cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
9426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
943cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
9444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
9464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
9474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *getConstructor() const { return Constructor; }
9484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
949cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
950cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
951cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
952cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
953cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
954cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
955cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
956cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
9574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
9584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
9594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
960cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
9614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
9634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
964cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
9654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
9684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isParenTypeId() const { return ParenTypeId; }
9694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool hasInitializer() const { return Initializer; }
9704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
9724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getConstructorArg(unsigned i) {
9734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
974cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
9754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getConstructorArg(unsigned i) const {
9774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
978cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
9794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
9824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
9834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
985cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
9864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
988cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
9894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
991cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
9924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
994cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
9954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
9964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
9974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_begin() {
998cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
9994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_end() {
1001cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
10024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_begin() const {
1004cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
10054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_end() const {
1007cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
10084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual SourceRange getSourceRange() const {
10114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(StartLoc, EndLoc);
10124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
10154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
10164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
10184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
10204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual child_iterator child_begin();
10214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual child_iterator child_end();
10224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
10234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
10254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray".
10264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
10274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
10284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
10294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
10304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
10314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the operator delete overload that is used. Could be a member.
10324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
10334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The pointer expression to be deleted.
10344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt *Argument;
10354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Location of the expression.
10364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation Loc;
10374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
10384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
10394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
10402850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
10414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl      ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg),
10424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl      Loc(loc) { }
10434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
10454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
10464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
10484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
10504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
10514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual SourceRange getSourceRange() const {
10534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
10544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
10574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
10584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
10594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
10604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
10624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual child_iterator child_begin();
10634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  virtual child_iterator child_end();
10644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
10654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1066a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// \brief Structure used to store the type being destroyed by a
1067a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression.
1068a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1069a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Either the type source information or the name of the type, if
1070a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1071a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1072a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1073a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1074a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1075a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1076a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1077a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1078a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1079a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1080a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1081a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1082a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1083a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1084a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1085a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<TypeSourceInfo *>();
1086a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1087a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1088a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1089a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1090a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1091a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1092a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1093a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1094a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1095a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1096a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1097e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1098e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructor of a scalar type, except that scalar types don't have
1099e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1100e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1101e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1102e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1103e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1104e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1105e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1106e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1107a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1108e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1109e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1110a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
11111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1112a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1113e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1114a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1115a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1116a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1117e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1118e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1119a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1120a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1121a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1123a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1124a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1125a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1127a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1128a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
11291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1130a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1131a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  NestedNameSpecifier *Qualifier;
11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The source range that covers the nested-name-specifier, if
1134a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// present.
1135a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceRange QualifierRange;
11361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1137e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1138e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1139e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1140e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1141e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The location of the '::' in a qualified pseudo-destructor
1142e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1143e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1144e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1145fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1146fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1147fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
1148a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The type being destroyed, or its name if we were unable to
1149a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1150a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1152a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1153a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1154a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1155a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          NestedNameSpecifier *Qualifier,
1156a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          SourceRange QualifierRange,
1157e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1158e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1159fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1160a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor                          PseudoDestructorTypeStorage DestroyedType)
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(CXXPseudoDestructorExprClass,
1162a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1163ce056bcaa1c97b89a4b2de2112c62d060863be2bDouglas Gregor                                                          false, 0, false,
1164264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                                                          false, 0, 0,
1165264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                                                      FunctionType::ExtInfo())),
116626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor           /*isTypeDependent=*/(Base->isTypeDependent() ||
1167a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor            (DestroyedType.getTypeSourceInfo() &&
1168a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor              DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1169a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor           /*isValueDependent=*/Base->isValueDependent()),
11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1171a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1172e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor      QualifierRange(QualifierRange),
1173fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor      ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
117426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor      DestroyedType(DestroyedType) { }
11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1176a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  void setBase(Expr *E) { Base = E; }
1177a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1180a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1181a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1182a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool hasQualifier() const { return Qualifier != 0; }
11831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1184a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
1185a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
1186a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// returns an empty source range.
1187a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceRange getQualifierRange() const { return QualifierRange; }
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1190a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1191a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1192a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  NestedNameSpecifier *getQualifier() const { return Qualifier; }
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1194a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1195a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1196a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1197a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  void setArrow(bool A) { IsArrow = A; }
1198a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1199a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1200a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1202e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1203e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1204e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1205e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1206e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1207e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1208e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \p T may also be a scalar type and, therefore, cannot be part of a
1209e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1210e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
121126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1212e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1213e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1214e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1215e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1216e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1217fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1218fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1219fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
122026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
122126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1222a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1223a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// This type-source information is available for non-dependent
1224a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1225a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1226a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1227a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getDestroyedTypeInfo() const {
1228a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getTypeSourceInfo();
1229a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1230a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1231a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1232a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1233a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1234a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1235a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1236a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1237a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1238a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1239a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1240a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1241a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1242a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getDestroyedTypeLoc() const {
1243a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getLocation();
1244a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
124626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  virtual SourceRange getSourceRange() const;
12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1249a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1250a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1251a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1253a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
1254a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  virtual child_iterator child_begin();
12551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
1256a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
125864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
125964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates.
126064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
126164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true
126264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false
126364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
126464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// UTT - The trait.
126564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  UnaryTypeTrait UTT;
126664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
126764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
126864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
126964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
127064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
127164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
127264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
127364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// QueriedType - The type we're testing.
127464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  QualType QueriedType;
127564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
127664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
127764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried,
127864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
127964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()),
128064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
128164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
128264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
128364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
128464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  UnaryTypeTrait getTrait() const { return UTT; }
128564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
128664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  QualType getQueriedType() const { return QueriedType; }
128764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
12885e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor  bool EvaluateTrait(ASTContext&) const;
128964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
129064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
129164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
129264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
129364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
129464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
129564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
129664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  virtual child_iterator child_begin();
129764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  virtual child_iterator child_end();
129864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
129964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
13007bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
13017bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
13027bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
1303ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
13047bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
13057bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
1306eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall  UnresolvedSet<4> Results;
1307ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
13087bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The common name of these declarations.
1309ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  DeclarationName Name;
1310ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
13117bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The scope specifier, if any.
1312ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  NestedNameSpecifier *Qualifier;
13137bb12da2b0749eeebb21854c77877736969e59f2John McCall
13147bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The source range of the scope specifier.
1315ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  SourceRange QualifierRange;
1316ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1317ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The location of the name.
1318ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  SourceLocation NameLoc;
1319ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
13207bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// True if the name was a template-id.
13217bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool HasExplicitTemplateArgs;
13227bb12da2b0749eeebb21854c77877736969e59f2John McCall
13237bb12da2b0749eeebb21854c77877736969e59f2John McCallprotected:
13247bb12da2b0749eeebb21854c77877736969e59f2John McCall  OverloadExpr(StmtClass K, QualType T, bool Dependent,
13257bb12da2b0749eeebb21854c77877736969e59f2John McCall               NestedNameSpecifier *Qualifier, SourceRange QRange,
13267bb12da2b0749eeebb21854c77877736969e59f2John McCall               DeclarationName Name, SourceLocation NameLoc,
13277bb12da2b0749eeebb21854c77877736969e59f2John McCall               bool HasTemplateArgs)
13287bb12da2b0749eeebb21854c77877736969e59f2John McCall    : Expr(K, T, Dependent, Dependent),
13297bb12da2b0749eeebb21854c77877736969e59f2John McCall      Name(Name), Qualifier(Qualifier), QualifierRange(QRange),
13307bb12da2b0749eeebb21854c77877736969e59f2John McCall      NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs)
13317bb12da2b0749eeebb21854c77877736969e59f2John McCall  {}
13327bb12da2b0749eeebb21854c77877736969e59f2John McCall
13337bb12da2b0749eeebb21854c77877736969e59f2John McCallpublic:
13347bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Computes whether an unresolved lookup on the given declarations
13357bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// and optional template arguments is type- and value-dependent.
13367bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool ComputeDependence(UnresolvedSetIterator Begin,
13377bb12da2b0749eeebb21854c77877736969e59f2John McCall                                UnresolvedSetIterator End,
13387bb12da2b0749eeebb21854c77877736969e59f2John McCall                                const TemplateArgumentListInfo *Args);
13397bb12da2b0749eeebb21854c77877736969e59f2John McCall
13407bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
13417bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
13427bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
13437bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \return the expression (which must be there) and true if it is
13447bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// within an address-of operator.
13457bb12da2b0749eeebb21854c77877736969e59f2John McCall  static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) {
13467bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
13477bb12da2b0749eeebb21854c77877736969e59f2John McCall
13487bb12da2b0749eeebb21854c77877736969e59f2John McCall    bool op = false;
13497bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
13507bb12da2b0749eeebb21854c77877736969e59f2John McCall    if (isa<UnaryOperator>(E))
13517bb12da2b0749eeebb21854c77877736969e59f2John McCall      op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
13527bb12da2b0749eeebb21854c77877736969e59f2John McCall    return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op);
13537bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
13547bb12da2b0749eeebb21854c77877736969e59f2John McCall
13557bb12da2b0749eeebb21854c77877736969e59f2John McCall  void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) {
13567bb12da2b0749eeebb21854c77877736969e59f2John McCall    Results.append(Begin, End);
13577bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
13587bb12da2b0749eeebb21854c77877736969e59f2John McCall
1359e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  /// Gets the naming class of this lookup, if any.
1360e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
1361e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
13627bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
13637bb12da2b0749eeebb21854c77877736969e59f2John McCall  decls_iterator decls_begin() const { return Results.begin(); }
13647bb12da2b0749eeebb21854c77877736969e59f2John McCall  decls_iterator decls_end() const { return Results.end(); }
13657bb12da2b0749eeebb21854c77877736969e59f2John McCall
13667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the decls as an unresolved set.
13677bb12da2b0749eeebb21854c77877736969e59f2John McCall  const UnresolvedSetImpl &getDecls() { return Results; }
13687bb12da2b0749eeebb21854c77877736969e59f2John McCall
13697bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the number of declarations in the unresolved set.
13707bb12da2b0749eeebb21854c77877736969e59f2John McCall  unsigned getNumDecls() const { return Results.size(); }
13717bb12da2b0749eeebb21854c77877736969e59f2John McCall
13727bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the name looked up.
13737bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getName() const { return Name; }
13747bb12da2b0749eeebb21854c77877736969e59f2John McCall  void setName(DeclarationName N) { Name = N; }
13757bb12da2b0749eeebb21854c77877736969e59f2John McCall
13767bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the location of the name.
13777bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getNameLoc() const { return NameLoc; }
13787bb12da2b0749eeebb21854c77877736969e59f2John McCall  void setNameLoc(SourceLocation Loc) { NameLoc = Loc; }
13797bb12da2b0749eeebb21854c77877736969e59f2John McCall
13807bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the nested-name qualifier, if one was given.
13817bb12da2b0749eeebb21854c77877736969e59f2John McCall  NestedNameSpecifier *getQualifier() const { return Qualifier; }
13827bb12da2b0749eeebb21854c77877736969e59f2John McCall
13837bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the range of the nested-name qualifier.
13847bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceRange getQualifierRange() const { return QualifierRange; }
13857bb12da2b0749eeebb21854c77877736969e59f2John McCall
13867bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Determines whether this expression had an explicit
13877bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// template argument list, e.g. f<int>.
13887bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
13897bb12da2b0749eeebb21854c77877736969e59f2John McCall
13907bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
13917bb12da2b0749eeebb21854c77877736969e59f2John McCall
13927bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
13937bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
13947bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
13957bb12da2b0749eeebb21854c77877736969e59f2John McCall
13967bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
13977bb12da2b0749eeebb21854c77877736969e59f2John McCall    if (hasExplicitTemplateArgs())
13987bb12da2b0749eeebb21854c77877736969e59f2John McCall      return &getExplicitTemplateArgs();
13997bb12da2b0749eeebb21854c77877736969e59f2John McCall    return 0;
14007bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
14017bb12da2b0749eeebb21854c77877736969e59f2John McCall
14027bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
14037bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
14047bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
14057bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
14067bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
14077bb12da2b0749eeebb21854c77877736969e59f2John McCall};
14087bb12da2b0749eeebb21854c77877736969e59f2John McCall
14097bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
14107bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration.  This
14117bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways:
14127bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
14137bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
14147bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
14157bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
14167bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always
14177bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in
14187bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs.
14197bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
1420ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
1421ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
1422ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
1423ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
1424ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
14257453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
14267453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
14277453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
14287453ed4cb2cab113de3378df371b1c6f1243d832John McCall
14297bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
14307bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
14317bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
14327bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
14337bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
14347bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
1435f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1436c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass,
1437ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                       NestedNameSpecifier *Qualifier, SourceRange QRange,
1438ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                       DeclarationName Name, SourceLocation NameLoc,
1439f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                       bool RequiresADL, bool Overloaded, bool HasTemplateArgs)
14407bb12da2b0749eeebb21854c77877736969e59f2John McCall    : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange,
14417bb12da2b0749eeebb21854c77877736969e59f2John McCall                   Name, NameLoc, HasTemplateArgs),
14427bb12da2b0749eeebb21854c77877736969e59f2John McCall      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1443ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
1444ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1445ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
1446ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1447f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool Dependent,
1448c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
1449ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                      NestedNameSpecifier *Qualifier,
1450ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                      SourceRange QualifierRange,
1451ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                      DeclarationName Name,
1452ba13543329afac4a0d01304ec2ec4924d99306a6John McCall                                      SourceLocation NameLoc,
14537453ed4cb2cab113de3378df371b1c6f1243d832John McCall                                      bool ADL, bool Overloaded) {
1454f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy,
1455c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                       Dependent, NamingClass,
1456c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                       Qualifier, QualifierRange,
1457f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                       Name, NameLoc, ADL, Overloaded, false);
1458ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1459ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1460f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1461f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool Dependent,
1462c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
1463f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      NestedNameSpecifier *Qualifier,
1464f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      SourceRange QualifierRange,
1465f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      DeclarationName Name,
1466f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      SourceLocation NameLoc,
1467f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
1468f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      const TemplateArgumentListInfo &Args);
1469f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1470ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
1471ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
1472ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
1473ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
14747453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
14757453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
14767453ed4cb2cab113de3378df371b1c6f1243d832John McCall
1477c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
1478c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
1479c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
1480c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1481c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
1482f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1483f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1484f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
1485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
14867bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
14877bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
14887bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
14897bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
14907bb12da2b0749eeebb21854c77877736969e59f2John McCall
1491f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1492f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1493f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1494f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1495f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1496f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1497f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1498f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1499f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1500f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1501f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1502ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1503f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1504f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1505f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1506f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1507f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1508f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1509f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1510f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1511f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1512f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1513f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1514f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1515f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1516f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1517f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1518ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1519ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  virtual SourceRange getSourceRange() const {
15207bb12da2b0749eeebb21854c77877736969e59f2John McCall    SourceRange Range(getNameLoc());
15217bb12da2b0749eeebb21854c77877736969e59f2John McCall    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1522f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1523f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1524ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1525ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1526ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  virtual StmtIterator child_begin();
1527ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  virtual StmtIterator child_end();
1528ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1529ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
1530ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
1531ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1532ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
1533ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
1534ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
15355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
15365953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
15375953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
1538ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
15405953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
1541865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
15425953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
15435953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
15445953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
1545865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1546ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
1547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
1549865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
15505953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// The name of the entity we will be referencing.
15515953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  DeclarationName Name;
15525953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
15535953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// Location of the name of the declaration we're referencing.
15545953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  SourceLocation Loc;
15555953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
15565953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// QualifierRange - The source range that covers the
15575953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// nested-name-specifier.
15585953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  SourceRange QualifierRange;
15595953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
1560ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
1561ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
1562f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  NestedNameSpecifier *Qualifier;
15635953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
1564f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Whether the name includes explicit template arguments.
1565f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool HasExplicitTemplateArgs;
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1567f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
1568f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                            NestedNameSpecifier *Qualifier,
1569f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                            SourceRange QualifierRange,
1570f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                            DeclarationName Name,
1571f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                            SourceLocation NameLoc,
1572f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                            bool HasExplicitTemplateArgs)
1573865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    : Expr(DependentScopeDeclRefExprClass, T, true, true),
1574f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Name(Name), Loc(NameLoc),
1575f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      QualifierRange(QualifierRange), Qualifier(Qualifier),
1576f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1577f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  {}
1578f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1579f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
1580f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1581f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                           NestedNameSpecifier *Qualifier,
1582f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                           SourceRange QualifierRange,
1583f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                           DeclarationName Name,
1584f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                           SourceLocation NameLoc,
1585f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs = 0);
15865953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
15875953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
15885953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  DeclarationName getDeclName() const { return Name; }
15895953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
15905953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
15915953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  SourceLocation getLocation() const { return Loc; }
15925953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
15935953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the source range of the nested-name-specifier.
15945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  SourceRange getQualifierRange() const { return QualifierRange; }
15955953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
1596ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
1597ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
1598edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  NestedNameSpecifier *getQualifier() const { return Qualifier; }
15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1600f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
1601f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1604f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1605f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1607f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1608f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1609f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1610f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1611f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
16121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1613f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1614f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1615f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1616f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1617f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1618f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1619f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1620f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1621edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1623f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1624f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1625f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1627f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1628f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1629d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1630d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1631f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1632f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1633f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1635edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  virtual SourceRange getSourceRange() const {
1636f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    SourceRange Range(QualifierRange.getBegin(), getLocation());
1637f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
1638f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
1639f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1640edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1643f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1644edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
1645f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1646f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1647f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  virtual StmtIterator child_begin();
1648f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  virtual StmtIterator child_end();
1649edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16512d44e8a41de8a33c0f04ac198714f71dc841bab0Anders Carlssonclass CXXExprWithTemporaries : public Expr {
165202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1654ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  CXXTemporary **Temps;
1655ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  unsigned NumTemps;
165602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps,
16580ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                         unsigned NumTemps);
16592d44e8a41de8a33c0f04ac198714f71dc841bab0Anders Carlsson  ~CXXExprWithTemporaries();
166042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
166142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
166242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
166342602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
166488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
1665d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXExprWithTemporaries(EmptyShell Empty)
1666d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXExprWithTemporariesClass, Empty),
1667d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner      SubExpr(0), Temps(0), NumTemps(0) {}
1668d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
166988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
16700ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        CXXTemporary **Temps,
16710ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        unsigned NumTemps);
16721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
167388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  unsigned getNumTemporaries() const { return NumTemps; }
1674d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setNumTemporaries(unsigned N);
1675d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
167688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary(unsigned i) {
167788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    assert(i < NumTemps && "Index out of range");
167888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    return Temps[i];
167988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  }
1680f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary(unsigned i) const {
16810ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson    return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1682f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
1683d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(unsigned i, CXXTemporary *T) {
1684d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    assert(i < NumTemps && "Index out of range");
1685d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    Temps[i] = T;
1686d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1689f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
169088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
169102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
169296be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  virtual SourceRange getSourceRange() const {
169396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
169496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
169502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
169602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
169702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
16982d44e8a41de8a33c0f04ac198714f71dc841bab0Anders Carlsson    return T->getStmtClass() == CXXExprWithTemporariesClass;
169902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
17002d44e8a41de8a33c0f04ac198714f71dc841bab0Anders Carlsson  static bool classof(const CXXExprWithTemporaries *) { return true; }
170102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
170202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
170302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  virtual child_iterator child_begin();
170402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  virtual child_iterator child_end();
170502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
170602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
1707d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
1708d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
1709d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
1710d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
1711d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
1712d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1713d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and
1714d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is
1715d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
1716d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
1717d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
1718d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
1719d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
1720d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
1721d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
1722d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
1723d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
1724d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
1725d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
1726d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
1727d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
1728d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
1729d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The starting location of the type
1730d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation TyBeginLoc;
1731d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1732d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
1733d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  QualType Type;
1734d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1735d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
1736d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
1737d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1738d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
1739d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
1740d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1741d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
1742d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1744d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  CXXUnresolvedConstructExpr(SourceLocation TyBegin,
1745d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             QualType T,
1746d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
1747d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             Expr **Args,
1748d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             unsigned NumArgs,
1749d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
1750d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1751d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
17521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1753d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation TyBegin,
1754d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            QualType T,
1755d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
1756d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            Expr **Args,
1757d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            unsigned NumArgs,
1758d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
1759d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1760d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the source location where the type begins.
1761d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1762d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1763d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1764d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
1765d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
1766d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  QualType getTypeAsWritten() const { return Type; }
1767d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setTypeAsWritten(QualType T) { Type = T; }
1768d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1769d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
1770d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
1771d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
1772d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1773d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1774d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
1775d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
1776d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1777d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1778d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1779d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
1780d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
1781d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1782d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
1783d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1784d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1785d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
17861dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
17871dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
17881dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
17891dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
17901dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
17911dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
17921dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
17931dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
1794d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
1795d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
1796d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
1797d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
1798d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
17991dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
18001dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
18011dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
18021dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
18031dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
1804d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  virtual SourceRange getSourceRange() const {
1805d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return SourceRange(TyBeginLoc, RParenLoc);
1806d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
18071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1808d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1809d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
1810d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
1811d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1812d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
1813d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  virtual child_iterator child_begin();
1814d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  virtual child_iterator child_end();
1815d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
1816d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
1817ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
1818ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
1819ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
1820aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
1821aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
1822aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
1823aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
1824865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
18251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
1826aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
18271c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1829aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
1830aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
1831aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
1832aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
18331c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
18341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
18353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
18361c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
18373b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Whether this member expression has explicitly-specified template
18383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// arguments.
1839aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool HasExplicitTemplateArgs : 1;
18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18411c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
18421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
18431c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
1844a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
1845a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *Qualifier;
18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1847a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The source range covering the nested name specifier.
1848a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  SourceRange QualifierRange;
18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1850c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
1852c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
1853c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
1854c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// FIXME: This member, along with the Qualifier and QualifierRange, could
1855c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
1856865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
1857c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
18581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
18601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
1861a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
18621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  DeclarationName Member;
18631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
18641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the member name.
18651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation MemberLoc;
18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18673b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
18683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member template name, if any.
18693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1870aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
18713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
18723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
18731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
18753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member template name, if any.
18763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1877865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return const_cast<CXXDependentScopeMemberExpr *>(this)
18783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor             ->getExplicitTemplateArgumentList();
18793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1881865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
1882aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
18833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
18843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NestedNameSpecifier *Qualifier,
18853b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceRange QualifierRange,
18863b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
18873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          DeclarationName Member,
18883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation MemberLoc,
1889d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18911c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
1892865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
1893aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType,
1894aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          bool IsArrow,
18951c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor                          SourceLocation OperatorLoc,
1896a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                          NestedNameSpecifier *Qualifier,
1897a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor                          SourceRange QualifierRange,
1898c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
18991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor                          DeclarationName Member,
19001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor                          SourceLocation MemberLoc)
1901865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
1902aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    Base(Base), BaseType(BaseType), IsArrow(IsArrow),
1903aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
19043b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    Qualifier(Qualifier), QualifierRange(QualifierRange),
19053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    FirstQualifierFoundInScope(FirstQualifierFoundInScope),
19063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    Member(Member), MemberLoc(MemberLoc) { }
19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1908865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
19091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
1910aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
19113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
19123b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NestedNameSpecifier *Qualifier,
19133b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceRange QualifierRange,
19143b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
19153b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         DeclarationName Member,
19163b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation MemberLoc,
1917d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
19181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1919aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
1920aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
1921aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
1922aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool isImplicitAccess() const { return Base == 0; }
1923aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
19241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
19251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
1926aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
1927aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
1928aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
1929aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
19301c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  void setBase(Expr *E) { Base = E; }
19311c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
1932aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
1933aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
19341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
19351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
19361c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
19371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  void setArrow(bool A) { IsArrow = A; }
19381c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
19391c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
19401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
19411c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
19421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
1943a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
1944a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
1945a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  NestedNameSpecifier *getQualifier() const { return Qualifier; }
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1947a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the source range covering the nested-name-specifier
1948a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// that qualifies the member name.
1949a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  SourceRange getQualifierRange() const { return QualifierRange; }
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1951c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
1952c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
1953c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
1954c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
1955c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
1958c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
1959c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
1960c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
1961c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
1963c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
1964c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19661c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
19671c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
19681c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  DeclarationName getMember() const { return Member; }
19691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  void setMember(DeclarationName N) { Member = N; }
19701c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
19711c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
19721c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
19731c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getMemberLoc() const { return MemberLoc; }
19741c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
19751c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
19763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
19773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
1978aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool hasExplicitTemplateArgs() const {
1979aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return HasExplicitTemplateArgs;
19803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1982d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1983d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1984d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1985aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
1986aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    getExplicitTemplateArgumentList()->copyInto(List);
1987d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1988d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
19891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
19903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member name ('<'), if any.
19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1992aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
19933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
19943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
19973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
1998833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1999aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
20003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
20013b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20033b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
20043b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
20051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
2006aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
20073b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
20083b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
20091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
20113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template arguments ('>').
20121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
2013aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(HasExplicitTemplateArgs);
20143b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
20153b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20171c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  virtual SourceRange getSourceRange() const {
2018aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
2019aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2020aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
2021aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
2022aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(getQualifierRange().getBegin());
2023aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
2024aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(MemberLoc);
20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2026aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
2027aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
2028aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
2029aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(MemberLoc);
2030aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
20311c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
20321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2034865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
20351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
2036865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
20371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
20381c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
20391c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  virtual child_iterator child_begin();
20401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  virtual child_iterator child_end();
20411c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
20421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2043129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
2044aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
2045aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2046aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
2047aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
2048aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
2049aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
2050aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
2051aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
2052aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2053aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
2054aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
2055aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
20567bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
2057129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
2058129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
2059129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
2060129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2061129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
2062129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
2063129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
2064129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
20657bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
20667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
20677bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
20687bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
20697bb12da2b0749eeebb21854c77877736969e59f2John McCall
20707bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
20717bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
2072129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2073129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
2074129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
2075129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2076129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  UnresolvedMemberExpr(QualType T, bool Dependent,
2077129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       bool HasUnresolvedUsing,
2078aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
2079129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
2080129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       NestedNameSpecifier *Qualifier,
2081129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceRange QualifierRange,
2082129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       DeclarationName Member,
2083129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation MemberLoc,
2084129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       const TemplateArgumentListInfo *TemplateArgs);
2085129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2086129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
2087129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
2088129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2089aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
2090129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
2091129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         NestedNameSpecifier *Qualifier,
2092129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceRange QualifierRange,
2093129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         DeclarationName Member,
2094129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation MemberLoc,
2095129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         const TemplateArgumentListInfo *TemplateArgs);
2096129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2097aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2098aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2099aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
2100aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool isImplicitAccess() const { return Base == 0; }
2101aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2102129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
2103129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
2104aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
2105aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2106aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2107aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
21082f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
21092f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
21102f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
21112f27bf854f0519810b34afd209089cc75536b757John McCall  }
2112129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void setBase(Expr *E) { Base = E; }
2113129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2114aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2115aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2116129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
2117129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
2118129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
2119129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void setArrow(bool A) { IsArrow = A; }
2120129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2121129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
2122129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2123129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2124129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2125c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
2126c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
2127c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
2128129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
2129129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
21307bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
21317bb12da2b0749eeebb21854c77877736969e59f2John McCall  void setMemberName(DeclarationName N) { setName(N); }
2132129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2133129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
2134129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
21357bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
21367bb12da2b0749eeebb21854c77877736969e59f2John McCall  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2137129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
21387bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
21397bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name.
21407bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
21417bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
21427bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
21437bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
21447bb12da2b0749eeebb21854c77877736969e59f2John McCall
21457bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
21467bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name, if any.
21477bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
21487bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
21497bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2150129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2151129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2152129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Copies the template arguments into the given structure.
2153129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
21547bb12da2b0749eeebb21854c77877736969e59f2John McCall    getExplicitTemplateArgs().copyInto(List);
2155129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2157129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the left angle bracket following
2158129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the member name ('<').
2159129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getLAngleLoc() const {
21607bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().LAngleLoc;
2161129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2162129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2163129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the template arguments provided as part of this
2164129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// template-id.
2165129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
21667bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2167129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2168129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2169129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the number of template arguments provided as
2170129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// part of this template-id.
2171129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  unsigned getNumTemplateArgs() const {
21727bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2173129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2174129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2175129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the right angle bracket
2176129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// following the template arguments ('>').
2177129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getRAngleLoc() const {
21787bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().RAngleLoc;
2179129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2180129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2181129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  virtual SourceRange getSourceRange() const {
2182aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
2183aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2184aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
2185aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
2186aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(getQualifierRange().getBegin());
2187aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
21887bb12da2b0749eeebb21854c77877736969e59f2John McCall      Range.setBegin(getMemberLoc());
2189aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
2191129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
2192129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    else
21937bb12da2b0749eeebb21854c77877736969e59f2John McCall      Range.setEnd(getMemberLoc());
2194129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
2195129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2196129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2197129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
2198129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
2199129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
2201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2202129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
2203129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  virtual child_iterator child_begin();
2204129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  virtual child_iterator child_end();
2205129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
2206129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
22077bb12da2b0749eeebb21854c77877736969e59f2John McCallinline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
22087bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
22097bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
22107bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
22117bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
22127bb12da2b0749eeebb21854c77877736969e59f2John McCall}
22137bb12da2b0749eeebb21854c77877736969e59f2John McCall
22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2217