ExprCXX.h revision 25aaf28c5bec71d5d005df67ee78b908ba5940f4
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"
18552622067dc45013d240f73952fece703f5e63bdJohn Wiegley#include "clang/Basic/ExpressionTraits.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
20eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall#include "clang/AST/UnresolvedSet.h"
21d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl;
26aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl;
27aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl;
28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary;
29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo;
304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
48b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
49063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
50063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
51063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
52b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr **args, unsigned numargs, QualType t,
55f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      ExprValueKind VK, SourceLocation operatorloc)
56cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
57f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
58063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor      Operator(Op) {}
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
60ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
62b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
63b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
64b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
65063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
66ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
67b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
68b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
74b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
7563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
8488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
9188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
9288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
931817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
94f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
95cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
9688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
971817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
981817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
991817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
10088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
10188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
103b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
104b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek
105b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  /// Retrieves the declaration of the called method.
106b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
10788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
108007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
109007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
111007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
112007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
113007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  CXXRecordDecl *getRecordDecl();
114007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
11988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
12088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
121e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
122e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     Expr **args, unsigned numargs, QualType t,
129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     ExprValueKind VK, SourceLocation RP)
130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne               RP) {
132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const CUDAKernelCallExpr *) { return true; }
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
15049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
15749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1601d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
1611d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
16249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
163f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1651d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
1661d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
1671d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
1681d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor      RParenLoc(RParenLoc) {}
16949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
170f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
171f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
172ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1731d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
1741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
1751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
17749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
178a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
179a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
180a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
181a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
1821d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
1831d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
1841d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor
18563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
1861d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    return SourceRange(Loc, RParenLoc);
1871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
18949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
1981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
19949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
20449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
20549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
20649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
207f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
208f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2091d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
210f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2111d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
21249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
213f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
214f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
216f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
217f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
218f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
2201d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   TypeSourceInfo *Written, SourceLocation L,
2211d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
222f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
223f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
224ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
22749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
23549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
23649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
23749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
238f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
239f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2401d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2421d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
24349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
244f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
249f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
2511d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    TypeSourceInfo *Written, SourceLocation L,
2521d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
253f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
254f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
255f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
256ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2570fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2580fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
26049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
26149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
26649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
26749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
27049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
27149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
273f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
2741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         TypeSourceInfo *writtenTy, SourceLocation l,
2751d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2771d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
27849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
279f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
280f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
281f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
284f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
2861d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                 TypeSourceInfo *WrittenTy, SourceLocation L,
2871d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
288f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
289f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
290ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
29249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
29349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
29849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
2991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
30149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
30249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
303f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
3041d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
3051d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
30849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
309ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
310f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
312f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
3151d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3161d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
317f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
318ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
32149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
3231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
3271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
3281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
3291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
3301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
332bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
333bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
3358b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
336eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
337eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
338eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
340eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
34263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
344eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
345eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
346eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
3491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
3501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
35363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3566e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
3576e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
3586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
3596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
3606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
361bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
362bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false),
363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
3646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
365eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
366eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
367eb7f96141f754150a92433286fa385910a22f494Sam Weinig
36863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
3696e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
370eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
371eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
372eb7f96141f754150a92433286fa385910a22f494Sam Weinig
3736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
3746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
3756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
3766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
3776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
37863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
3806e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
381c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
382c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
383c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
384c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
385c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
386c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
387c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
38857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
389c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
390c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
391c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
39257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
393f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
39457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
39557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
39657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
397bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
398bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
39957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
40057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
40157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
402f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
4032850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
404bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
4052850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
406bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
407bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
40857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
409c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
41014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
41114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
41214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
41314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
41414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
41514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
41614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
41714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
41857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
41957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
42057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
42157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
42257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
42357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
42457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
42557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
426c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
42757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
428c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
42914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
43014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
43114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
43214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
43314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
43457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
43514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
436c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
43757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
438c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
43914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
440030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
441030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
442030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
443030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
444030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
44563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
44614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
44714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
448c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
449c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
450c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
451c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
452c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
45463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
45563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
45663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
45763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
45863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
459c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
460c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
46101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
46201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
46301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
46401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
46501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
46601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
46701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
46801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
46901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
47001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
47101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
4722e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
474bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
47501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
47601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
47701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
4782e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
480bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
48101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
48201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
48301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
48401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
48501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
48601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
48701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
48801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
48901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
49001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
49201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
49401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
49501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
49601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
49701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
49801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
49901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
50001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
50101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
50401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
50501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
50601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
50701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
50801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
50901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
51001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
51101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
51401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
51501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
51601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
51701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
51863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
51901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
52001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
52101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
52201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
52301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
52401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const CXXUuidofExpr *) { return true; }
52501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
52601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
52763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
52863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
52963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
53063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
53163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
53201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
53301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
534796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
535796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
536796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
537796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
538796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
539796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
540796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
541796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
542796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
543796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
544796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
545796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
546796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
547828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
548828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
549796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
550828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
551f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
5522850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
5532850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
555bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
556828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
557796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5582fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
5592fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5602fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
5612fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
5622fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
56363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
564796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
565828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
566828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
567828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor
5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
569796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
570796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
571796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
572796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
573796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
57463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
575796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
576796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
5771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
5781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
5791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
5801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
5811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
5821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
5831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
5841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
5851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
5861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
5871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
5881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
589bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
590bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
591f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Op(expr), ThrowLoc(l) {}
5922fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
5932fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
5941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
5951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
59642e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setSubExpr(Expr *E) { Op = E; }
59742e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
59842e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
59942e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
6001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
60163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
6031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
6041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
6051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
6091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
6111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
61363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
61463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
61563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
6161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
6171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
6191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
6201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
6211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
6221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
62365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
62465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
62565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// When the bit is set, the subexpression is stored after the
62665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
62765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
62865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
630036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
631036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
632036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
633036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
63465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    : Expr(SC,
63565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
63665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
6372333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
638dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
639bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false),
640036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
64165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
642036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
643036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
644dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
645dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
646bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, false, false),
647bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
64865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
64965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
65065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
652030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
653030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
654030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
6561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
657036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
658036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
659036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
660f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
6611060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
66265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
66365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
664036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C,
665036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
666036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param,
66765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
66865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
6691060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
67065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
67165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
672030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
6731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
67465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const Expr *getExpr() const {
67565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
67665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
67765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
67865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
67965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  Expr *getExpr() {
68065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
68165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
68265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    return getParam()->getDefaultArg();
68365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
6841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
685036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief Retrieve the location where this default argument was actually
686036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
687036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
688036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor
68963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
6901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
6911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
6931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
6971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
6991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
70163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
7028a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
70360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
7043397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
7051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
706987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
707c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
708c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
709c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
710b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
712b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
713c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
714c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
715c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
717b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
7181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
719f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
720c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
721fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
722ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
723ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
724ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
725ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
726ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
727ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
728ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
729ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
730ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
731ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
732ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
733ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
734ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
735ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
736fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
737fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
739fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
740fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
741bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
742bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
743bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
744bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
745bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
746bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
74788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
748fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
749d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
750d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
751d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
753fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
756f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
757d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
758f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
759fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
760fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
76188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
762fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
76363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
76496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
76596be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
766fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
767fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
768fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
769fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
770fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
771fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
772fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
773fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
77463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
775fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
776fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
77715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor.
77815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
77972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
78072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
78172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
78272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
78372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_VirtualBase
78472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
78572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson
78672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
78715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
78815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
78999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
790428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
79116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
79216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
79372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
79415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
79515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned NumArgs;
7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
797bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
79999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
800bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
80116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                   Expr **args, unsigned numargs,
8029db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                   bool ZeroInitialization = false,
803428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   ConstructionKind ConstructKind = CK_Complete,
804428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                   SourceRange ParenRange = SourceRange());
805bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
8066d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8076d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
8086d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
8096d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8106d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
81115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
8126d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8136d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
8146d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
8156d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      Elidable(0), ZeroInitialization(0),
8166d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis      ConstructKind(0), Args(0), NumArgs(0) { }
8176d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
8188e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
81999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
82116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                                  Expr **Args, unsigned NumArgs,
8229db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor                                  bool ZeroInitialization = false,
823428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  ConstructionKind ConstructKind = CK_Complete,
824428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                                  SourceRange ParenRange = SourceRange());
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
827d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
82839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
82939da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
83099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
83199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
83299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor
833d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
834d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
83539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
83639da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor
83716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
83816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
83916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
84016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
84116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
84216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
84316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor
8449db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
8459db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
84624eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
84724eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
84872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
84972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  void setConstructionKind(ConstructionKind CK) {
85072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
85172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
8529db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor
85315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
85415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
85715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
85815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
85915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
86015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
861a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
86215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
86315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
864bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
865bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
866bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
867bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
868bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
869bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
870bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
871bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
872bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
8731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8742eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
8752eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
8762eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
8772eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
8782eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
8792eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
88063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
881428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
88215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
8831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
884524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
885524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
88615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
88715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
88915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
89063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
89163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
89263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
8936d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
89460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
89515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
89615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
89749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
89849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
89949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
90049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
901987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
902987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
903f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
904f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
905f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
907f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
90841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                        SourceLocation rParenLoc)
909f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
910f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
9110aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
9120aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
913f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
914f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
915f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
916f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
917f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
918f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
919f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
920f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
921f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
922f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
923f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
924f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
925f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
926ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
927987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
928ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
929987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
930ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
9311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
933987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
934987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
9351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
937987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
938987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
939987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
940987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
941506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
942506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
943506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
945506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
946ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// constructor to build a temporary object. With N == 1 arguments the
947ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
948506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
949506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
950506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
951506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
952506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
953506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
954506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
955506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
956524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
957ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
958506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
959506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
961ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         Expr **Args,unsigned NumArgs,
963428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
9641c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
9656d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
966ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
967506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
968ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
969ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
97063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
971ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
973506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
974506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
975506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
9766d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
97760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
978506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
979506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
980ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
981506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
982ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
983987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
984ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
985987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
986ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
987987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
988ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
989ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
990987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
991ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Create an explicitly-written scalar-value initialization
992ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
993ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
994ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
995ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
996f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
997bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         false, false, false),
998ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
999ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1000ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1001ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1003ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1004ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
10054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1006ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1007ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
10084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
100963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1012ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1013987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1014ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  static bool classof(const CXXScalarValueInitExpr *) { return true; }
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1016987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
101763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1018987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1019987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
10204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls,
10214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)".
10224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
10234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Was the usage ::new, i.e. is the global new to be used?
10244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalNew : 1;
10254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is there an initializer? If not, built-ins are uninitialized, else they're
10264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // value-initialized.
10274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool Initializer : 1;
1028cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Do we allocate an array? If so, the first SubExpr is the size expression.
1029cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool Array : 1;
10306ec278d1a354517e20f13a877481453ee7940c78John McCall  // If this is an array allocation, does the usual deallocation
10316ec278d1a354517e20f13a877481453ee7940c78John McCall  // function for the allocated type want to know the allocated size?
10326ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
10334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of placement new arguments.
10346ec278d1a354517e20f13a877481453ee7940c78John McCall  unsigned NumPlacementArgs : 14;
10354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The number of constructor arguments. This may be 1 even for non-class
10364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // types; use the pseudo copy constructor.
1037cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  unsigned NumConstructorArgs : 14;
1038cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // Contains an optional array size expression, any number of optional
1039cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // placement arguments, and any number of optional constructor arguments,
1040cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  // in that order.
10414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
10424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the allocation function used.
10434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
10444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the deallocation function used in case of error. May be null.
10454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
10464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the constructor used. Cannot be null if AllocType is a record;
10474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // it would still point at the default constructor (even an implicit one).
10484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Must be null for all other types.
10494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *Constructor;
10504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
10521bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
10531bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
10544bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// \brief If the allocated type was expressed as a parenthesized type-id,
10554bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
10564bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
10574bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
10584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
10594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation EndLoc;
1060428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorLParen;
1061428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation ConstructorRParen;
10624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
106360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
10644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
1065ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
10664bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             Expr **placementArgs, unsigned numPlaceArgs,
10674bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor             SourceRange TypeIdParens,
1068ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
10694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl             Expr **constructorArgs, unsigned numConsArgs,
10706ec278d1a354517e20f13a877481453ee7940c78John McCall             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
10716ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1072428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation startLoc, SourceLocation endLoc,
1073428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorLParen,
1074428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth             SourceLocation constructorRParen);
10755921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
10765921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
10775921863d8f24084797863b5df37842113bac4352Chris Lattner
10785921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
10795921863d8f24084797863b5df37842113bac4352Chris Lattner                         unsigned numConsArgs);
1080ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek
1081cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1082cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
10836217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1084cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
10854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
10861bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
10871bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
10881bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1089c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1090c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1091c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// C++0x [expr.new]p13:
1092c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1093c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1094c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1095c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1096c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1097c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1098c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
10998026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
11001bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor
11014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
11025921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
11034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
11045921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
11054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXConstructorDecl *getConstructor() const { return Constructor; }
11065921863d8f24084797863b5df37842113bac4352Chris Lattner  void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
11074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1108cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1109cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1110cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1111cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1112cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1113cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1114cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1115cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
11164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1117aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getPlacementArgs() {
1118aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array);
1119aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1120aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
11224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1123cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
11264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
1127cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + i]);
11284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11304bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
11314bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
11324bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
11334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
11344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool hasInitializer() const { return Initializer; }
11356ec278d1a354517e20f13a877481453ee7940c78John McCall
11366ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
11376ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
11386ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.
11396ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
11406ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
11416ec278d1a354517e20f13a877481453ee7940c78John McCall  }
11424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1144aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
1145aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getConstructorArgs() {
1146aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs);
1147aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1148aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
11494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getConstructorArg(unsigned i) {
11504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1151cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getConstructorArg(unsigned i) const {
11544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumConstructorArgs && "Index out of range");
1155cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
11564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
11594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
11604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
1162cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
1165cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
1168cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array;
11694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
1171cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_begin() {
1175cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator constructor_arg_end() {
1178cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_begin() const {
1181cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs();
11824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator constructor_arg_end() const {
1184cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
11865921863d8f24084797863b5df37842113bac4352Chris Lattner
11875921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
11885921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
11895921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
11905921863d8f24084797863b5df37842113bac4352Chris Lattner    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
11915921863d8f24084797863b5df37842113bac4352Chris Lattner  }
11925921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
11935921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
11944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
11955921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
11965921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getEndLoc() const { return EndLoc; }
1197428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1198428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorLParen() const { return ConstructorLParen; }
1199428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceLocation getConstructorRParen() const { return ConstructorRParen; }
1200428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
120163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(StartLoc, EndLoc);
12034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
12064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
12074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
12094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
121163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
121263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0],
121363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       &SubExprs[0] + Array + getNumPlacementArgs()
121463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                         + getNumConstructorArgs());
121563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
12164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
12194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray".
12204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
12214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
12224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
12234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
12244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
12254076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
12264076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
12274076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
12284076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
12296ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
12306ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
12316ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
12324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the operator delete overload that is used. Could be a member.
12334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
12344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // The pointer expression to be deleted.
12354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt *Argument;
12364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Location of the expression.
12374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation Loc;
12384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
12394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
12406ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
12416ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1242bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1243bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1244f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
12454076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
12466ec278d1a354517e20f13a877481453ee7940c78John McCall      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize),
12474076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
124895fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
124995fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
12504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
12524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
12534076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
12544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12556ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
12566ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
12576ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
12586ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
12596ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
12606ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
12616ec278d1a354517e20f13a877481453ee7940c78John McCall  }
12626ec278d1a354517e20f13a877481453ee7940c78John McCall
12634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
12644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
12664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
12674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1268a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1269a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1270a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
12715833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
12725833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor
127363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
12744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
12754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
12784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
12794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
12804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
12814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
12824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
128363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1284f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1285f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
12864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
12874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1288a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// \brief Structure used to store the type being destroyed by a
1289a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression.
1290a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1291a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Either the type source information or the name of the type, if
1292a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1293a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1294a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1295a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1296a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1297a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1298a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1299a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1300a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1301a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1302a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1303a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1304a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1305a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1306a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1307a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<TypeSourceInfo *>();
1308a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1309a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1310a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1311a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1312a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1313a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1314a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1315a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1316a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1317a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1318a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1319e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1320e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructor of a scalar type, except that scalar types don't have
1321e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1322e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1323e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1324e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1325e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1326e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1327e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1328e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1329a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1330e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1331e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1332a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1334a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1335e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1336a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1337a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1338a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1339e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1340e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1341a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1342a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1343a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
13441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1345a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1346a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1347a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1349a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1350a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1351f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1352a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1353f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1355e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1356e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1357e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1358e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1359e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The location of the '::' in a qualified pseudo-destructor
1360e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1361e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1362e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1363fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1364fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1365fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
1366a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The type being destroyed, or its name if we were unable to
1367a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1368a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1370f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1371f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
1372a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1373a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1374a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1375f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1376e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1377e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1378fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1379e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1381de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1382de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1383f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1384de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1385a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1388a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1389a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1390f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1392f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1393f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1394f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1395f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor
13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1397a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1398a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1399f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifier *getQualifier() const {
1400f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
1401f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1403a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1404a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1405a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1406a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1407a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1408a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1410e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1411e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1412e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1413e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1414e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1415e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1416e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \p T may also be a scalar type and, therefore, cannot be part of a
1417e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1418e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
141926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1420e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1421e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1422e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1423e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1424e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor
1425fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1426fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1427fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor
142826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
142926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1430a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1431a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// This type-source information is available for non-dependent
1432a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1433a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1434a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1435a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  TypeSourceInfo *getDestroyedTypeInfo() const {
1436a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getTypeSourceInfo();
1437a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1438a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1439a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1440a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1441a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1442a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1443a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1444a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1445a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1446a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1447a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1448a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor
1449a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1450a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getDestroyedTypeLoc() const {
1451a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getLocation();
1452a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1454de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1455de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1456de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1457de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1458de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1459de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1460de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1461de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1462de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1463de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1464de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
146563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1468a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1469a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1470a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
14711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1472a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
147363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1474a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
147664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
147764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates.
147864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
147964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true
148064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false
148164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
14820dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
14830dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
14840dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
14850dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
148664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
148764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
148864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
148964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
149064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
149164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
149264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
14930dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
14943d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
149564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
149664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
14973d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
14980dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
149964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1500f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1501bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1502bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
15030dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
150464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
15060dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
15073d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
15086d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
150963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
151064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15110dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
151264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15133d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
151464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15153d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
15163d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor
15170dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
151864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
151964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
152064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
152164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
152264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
152364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
152464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
152563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15266d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
152760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
152864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
152964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
15306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
15316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates.
15326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
15336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true
15346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
15356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
15366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
15376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
15396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
15406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
15426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
15436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
15456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
15466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
15486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
15496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
15516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
15526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
15546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
15556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
15566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
15576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
15586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
1559bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
1560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
1561bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
15626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
15636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
15646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
15676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1568f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
15696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
157063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
15716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SourceRange(Loc, RParen);
15726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
15756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
15766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
15796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
15806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
15826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
15836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
15856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
15876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
15886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
15896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const BinaryTypeTraitExpr *) { return true; }
15906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
159263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
15936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
15946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
15956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
15966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
159721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
159821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// implementation of __array_rank and __array_extent.
159921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example:
160021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_rank(int[10][20]) == 2
160121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_extent(int, 1)    == 20
160221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr {
160321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
160421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  unsigned ATT : 2;
160521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
160621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The value of the type trait. Unspecified if dependent.
160721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t Value;
160821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
160921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The array dimension being queried, or -1 if not used
161021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *Dimension;
161121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
161221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// Loc - The location of the type trait keyword.
161321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation Loc;
161421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
161521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// RParen - The location of the closing paren.
161621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation RParen;
161721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
161821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The type being queried.
161921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *QueriedType;
162021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
162121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic:
162221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
162321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     TypeSourceInfo *queried, uint64_t value,
162421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     Expr *dimension, SourceLocation rparen, QualType ty)
162521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
162621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           false, queried->getType()->isDependentType(),
162721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           queried->getType()->containsUnexpandedParameterPack()),
162821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      ATT(att), Value(value), Dimension(dimension),
162921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      Loc(loc), RParen(rparen), QueriedType(queried) { }
163021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
163121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
163221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  explicit ArrayTypeTraitExpr(EmptyShell Empty)
163321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
163421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      QueriedType() { }
163521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
163625aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek  virtual ~ArrayTypeTraitExpr() { }
163725aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek
163821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen); }
163921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
164021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
164121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
164221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  QualType getQueriedType() const { return QueriedType->getType(); }
164321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
164421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
164521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
164621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
164721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
164821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *getDimensionExpression() const { return Dimension; }
164921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
165021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const Stmt *T) {
165121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return T->getStmtClass() == ArrayTypeTraitExprClass;
165221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
165321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const ArrayTypeTraitExpr *) { return true; }
165421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
165521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Iterators
165621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  child_range children() { return child_range(); }
165721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
165821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  friend class ASTStmtReader;
165921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley};
166021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
1661552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// ExpressionTraitExpr - An expression trait intrinsic
1662552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example:
1663552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(std::cout) == true
1664552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(1) == false
1665552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr {
1666552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
1667552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  unsigned ET : 31;
1668552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// The value of the type trait. Unspecified if dependent.
1669552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool Value : 1;
1670552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1671552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// Loc - The location of the type trait keyword.
1672552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation Loc;
1673552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1674552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// RParen - The location of the closing paren.
1675552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation RParen;
1676552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1677552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr* QueriedExpression;
1678552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic:
1679552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
1680552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     Expr *queried, bool value,
1681552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     SourceLocation rparen, QualType resultType)
1682552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1683552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           false, // Not type-dependent
1684552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           // Value-dependent if the argument is type-dependent.
1685552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->isTypeDependent(),
1686552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->containsUnexpandedParameterPack()),
1687552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      ET(et), Value(value), Loc(loc), RParen(rparen), QueriedExpression(queried) { }
1688552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1689552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  explicit ExpressionTraitExpr(EmptyShell Empty)
1690552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
1691552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      QueriedExpression() { }
1692552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1693552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1694552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1695552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
1696552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1697552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr *getQueriedExpression() const { return QueriedExpression; }
1698552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1699552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool getValue() const { return Value; }
1700552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1701552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const Stmt *T) {
1702552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return T->getStmtClass() == ExpressionTraitExprClass;
1703552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
1704552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const ExpressionTraitExpr *) { return true; }
1705552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1706552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  // Iterators
1707552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  child_range children() { return child_range(); }
1708552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1709552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  friend class ASTStmtReader;
1710552622067dc45013d240f73952fece703f5e63bdJohn Wiegley};
1711552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
1712552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
17137bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
17147bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
17157bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
1716ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
17177bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
17187bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
1719928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
1720928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
1721928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
1722ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
17237bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The common name of these declarations.
17242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo NameInfo;
1725ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
17264c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// \brief The nested-name-specifier that qualifies the name, if any.
17274c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
1728ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1729a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
17307bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// True if the name was a template-id.
17317bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool HasExplicitTemplateArgs;
17327bb12da2b0749eeebb21854c77877736969e59f2John McCall
1733bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
17344c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
17352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
1736bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
1737bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1738bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownDependent = false,
1739bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               bool KnownContainsUnexpandedParameterPack = false);
17407bb12da2b0749eeebb21854c77877736969e59f2John McCall
1741a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
1742a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : Expr(K, Empty), Results(0), NumResults(0),
17434c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      QualifierLoc(), HasExplicitTemplateArgs(false) { }
1744a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
1745bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
1746bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
1747bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
17487bb12da2b0749eeebb21854c77877736969e59f2John McCall
1749bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
17509c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
17519c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
17529c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
17539c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
17549c72c6088d591ace8503b842d39448c2040f3033John McCall  };
17559c72c6088d591ace8503b842d39448c2040f3033John McCall
17567bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
17577bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
17587bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
17599c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
17609c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
17619c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
17627bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
17637bb12da2b0749eeebb21854c77877736969e59f2John McCall
17649c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
17659c72c6088d591ace8503b842d39448c2040f3033John McCall
17667bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
17679c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
17689c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
17699c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
17709c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
17719c72c6088d591ace8503b842d39448c2040f3033John McCall
17729c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
17739c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
17749c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
17759c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
17769c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
17779c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
17789c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
17799c72c6088d591ace8503b842d39448c2040f3033John McCall    }
17809c72c6088d591ace8503b842d39448c2040f3033John McCall
17819c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
17827bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
17837bb12da2b0749eeebb21854c77877736969e59f2John McCall
1784e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  /// Gets the naming class of this lookup, if any.
1785e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
1786e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
17877bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
1788928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1789928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_end() const {
1790928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
1791928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
1792a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
17937bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the number of declarations in the unresolved set.
1794928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
17957bb12da2b0749eeebb21854c77877736969e59f2John McCall
17962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Gets the full name info.
17972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
17982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
17997bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the name looked up.
18002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
18017bb12da2b0749eeebb21854c77877736969e59f2John McCall
18027bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the location of the name.
18032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
18047bb12da2b0749eeebb21854c77877736969e59f2John McCall
18057bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the nested-name qualifier, if one was given.
18064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifier *getQualifier() const {
18074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
18084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
18097bb12da2b0749eeebb21854c77877736969e59f2John McCall
18104c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// Fetches the nested-name qualifier with source-location information, if
18114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// one was given.
18124c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
18137bb12da2b0749eeebb21854c77877736969e59f2John McCall
18147bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Determines whether this expression had an explicit
18157bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// template argument list, e.g. f<int>.
18167bb12da2b0749eeebb21854c77877736969e59f2John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
18177bb12da2b0749eeebb21854c77877736969e59f2John McCall
18187bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
18197bb12da2b0749eeebb21854c77877736969e59f2John McCall
18207bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
18217bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
18227bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
18237bb12da2b0749eeebb21854c77877736969e59f2John McCall
1824096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1825096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1826096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1827096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1828096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1829096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
18307bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
18317bb12da2b0749eeebb21854c77877736969e59f2John McCall
18327bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
18337bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
18347bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
18357bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
18367bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
18374045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
18384045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
18394045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
18407bb12da2b0749eeebb21854c77877736969e59f2John McCall};
18417bb12da2b0749eeebb21854c77877736969e59f2John McCall
18427bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
18437bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration.  This
18447bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways:
18457bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
18467bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
18477bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
18487bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
18497bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always
18507bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in
18517bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs.
18527bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
1853ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
1854ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
1855ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
1856ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
1857ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1858ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// True if namespace ::std should be considered an associated namespace
1859ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
1860ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool StdIsAssociatedNamespace;
1861ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
18627453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
18637453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
18647453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
18657453ed4cb2cab113de3378df371b1c6f1243d832John McCall
18667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
18677bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
18687bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
18697bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
18707bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
18717bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
1872f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1873bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedLookupExpr(ASTContext &C,
1874928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
18754c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
18762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
1877bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       bool RequiresADL, bool Overloaded,
1878bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
1879ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       UnresolvedSetIterator Begin, UnresolvedSetIterator End,
1880ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       bool StdIsAssociatedNamespace)
18814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, NameInfo,
1882bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                   TemplateArgs, Begin, End),
1883ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(RequiresADL),
1884ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      StdIsAssociatedNamespace(StdIsAssociatedNamespace),
1885ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Overloaded(Overloaded), NamingClass(NamingClass)
1886ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
1887ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1888bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
1889bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
1890ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
1891ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      NamingClass(0)
1892bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
1893bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
18944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
18954c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
1896ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
1897ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1898c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
18994c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
19002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
19015a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
19025a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
1903ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      UnresolvedSetIterator End,
1904ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      bool StdIsAssociatedNamespace = false) {
1905ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    assert((ADL || !StdIsAssociatedNamespace) &&
1906ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith           "std considered associated namespace when not performing ADL");
19074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, NameInfo,
1908ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       ADL, Overloaded, 0, Begin, End,
1909ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       StdIsAssociatedNamespace);
1910ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1911ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1912f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
1913c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
19144c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
19152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
1916f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
19175a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      const TemplateArgumentListInfo &Args,
19185a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator Begin,
19195a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
1920f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1921bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1922def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                           bool HasExplicitTemplateArgs,
1923bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
1924bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
1925ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
1926ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
1927ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
1928ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1929ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// True if namespace ::std should be artificially added to the set of
1930ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// associated namespaecs for argument-dependent lookup purposes.
1931ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
1932ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
19337453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
19347453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
19357453ed4cb2cab113de3378df371b1c6f1243d832John McCall
1936c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
1937c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
1938c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
1939c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1940c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
1941f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
1942f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
1943f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
1944f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
19457bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
19467bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
19477bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
19487bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
19497bb12da2b0749eeebb21854c77877736969e59f2John McCall
1950f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
1951f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1952f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
1953f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1954f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1955f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1956096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1957096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1958096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1959096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1960096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1961096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1962096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1963096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1964f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
1965f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
1966f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1967f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
1968f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1969ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1970f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
1971f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
1972f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1973f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1974f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
1975f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
1976f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1977f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1978f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
1979f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1980f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1981f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
1982f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
1983f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1984f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
1985ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
198663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
19872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range(getNameInfo().getSourceRange());
19884c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (getQualifierLoc())
19894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
19904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    if (hasExplicitTemplateArgs())
19914c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setEnd(getRAngleLoc());
1992f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
1993ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
1994ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
199563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1996ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
1997ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
1998ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
1999ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2000ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
2001ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
2002ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
20035953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
20045953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
20055953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
2006ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2007a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
20085953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
2009865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
20105953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
20115953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
20125953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
2013865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2014ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
2015a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2016a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
2017865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
2018ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
2019ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
202000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
202100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
202200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
202300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
20245953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
2025f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Whether the name includes explicit template arguments.
2026f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool HasExplicitTemplateArgs;
20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2028f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
202900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
20302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
2031bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
2032f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2033f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
2034f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
203500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
20362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
2037f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                              const TemplateArgumentListInfo *TemplateArgs = 0);
20385953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
203912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2040def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                                bool HasExplicitTemplateArgs,
204112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
204212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
20435953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
20442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
20452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
20462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
20472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
20485953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
20495953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
20502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
20515953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
205200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
205300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
205400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
205500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
205600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor
2057ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
2058ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
205900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifier *getQualifier() const {
206000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    return QualifierLoc.getNestedNameSpecifier();
206100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2063f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
2064f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2066f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
2067f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
2068f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
20691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
207012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
207112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
207212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
207312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
207412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
2075f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
2076f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2077f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
2078f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
2079f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2081096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2082096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2083096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2084096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2085096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2086096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2087096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2088096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2089f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
2090f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
2091f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2092f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
2093f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
2094f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2095f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getLAngleLoc() const {
2096f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().LAngleLoc;
2097edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2099f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  SourceLocation getRAngleLoc() const {
2100f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().RAngleLoc;
2101f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
21021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2103f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
2104f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2105d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2106d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2107f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
2108f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2109f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
211163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
211200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2113f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
2114f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
2115f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
2116edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
21171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2119f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2120edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
2121f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2122f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
212363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
21244045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
21254045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
21264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
2127edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
21281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21294765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
21304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
21314765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
21324765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// cleanups is temporary objects in C++, but several other C++
21334765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// expressions can create cleanups.
21344765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
213502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2137ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  CXXTemporary **Temps;
2138ff6b3d64c9f07155f1414411b8451d7bf8937c62Anders Carlsson  unsigned NumTemps;
213902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
21404765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(ASTContext &C, Expr *SubExpr,
21414765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall                   CXXTemporary **Temps, unsigned NumTemps);
21424765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall
214388eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
21444765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  ExprWithCleanups(EmptyShell Empty)
21454765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    : Expr(ExprWithCleanupsClass, Empty),
2146d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner      SubExpr(0), Temps(0), NumTemps(0) {}
2147d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
21484765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr,
21490ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        CXXTemporary **Temps,
21500ece491d8f62ce67f047491a6703fac0d3bd4ff4Anders Carlsson                                        unsigned NumTemps);
21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
215288eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  unsigned getNumTemporaries() const { return NumTemps; }
2153d04ed416be7c55bddddab1fa3fd38a0113a6b3daTed Kremenek  void setNumTemporaries(ASTContext &C, unsigned N);
2154d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner
215588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary(unsigned i) {
215688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    assert(i < NumTemps && "Index out of range");
215788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson    return Temps[i];
215888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  }
2159f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary(unsigned i) const {
21604765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return const_cast<ExprWithCleanups*>(this)->getTemporary(i);
2161f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
2162d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(unsigned i, CXXTemporary *T) {
2163d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    assert(i < NumTemps && "Index out of range");
2164d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    Temps[i] = T;
2165d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
216702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2168f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
216988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
217002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
217163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
217296be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
217396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
217402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
217502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
217602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
21774765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
217802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
21794765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static bool classof(const ExprWithCleanups *) { return true; }
218002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
218102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
218263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
218302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
218402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2185d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2186d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2187d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2188d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2189d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2190d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2191d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and
2192d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is
2193d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2194d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2195d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2196d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2197d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2198d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2199d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2200d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2201d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2202d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2203d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2204d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2205d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2206d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2207d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2208ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2209ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2210d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2211d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2212d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2213d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2214d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2215d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2216d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2217d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2219ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2220d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
2221d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             Expr **Args,
2222d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             unsigned NumArgs,
2223d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2224d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
22258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2226ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
22278dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2228ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2229ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2230d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
22311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2232ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2233d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
2234d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            Expr **Args,
2235d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            unsigned NumArgs,
2236d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2237d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
22388dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
22398dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
22408dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2241d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2242d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2243ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2244d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2245ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// \brief Retrieve the type source information for the type being
2246ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2247ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2248ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
2249d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2250d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2251d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2252d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2253d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2254d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2255d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2256d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2257d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2258d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2259d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2260d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2261d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2262d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2263d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2264d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2265d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
22661dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
22671dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
22681dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
22691dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
22701dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
22711dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
22721dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
22731dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2274d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2275d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2276d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2277d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2278d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
22791dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
22801dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
22811dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
22821dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
22831dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
22848dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
22858dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
22868dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
22878dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
22888dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
228963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const;
2290ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
22911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2292d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2293d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2294d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2295d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2296d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
229763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
229863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
229963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
230063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2301d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2302d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2303ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2304ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2305ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2306aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2307aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2308aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2309aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2310865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
23111c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2312aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
23131c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
23141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2315aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2316aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2317aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2318aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
23191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
23201c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
23213b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
23221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23233b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Whether this member expression has explicitly-specified template
23243b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// arguments.
2325aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool HasExplicitTemplateArgs : 1;
23261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23271c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
23281c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
23291c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2330a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
23317c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
23321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2333c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2335c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2336c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
233746bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
2338c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2339865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2340c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
23411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
23431c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2344a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
23452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2347865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2348aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
23493b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
23507c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
23513b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
23522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2353d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23551c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2356865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2357bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2358bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2359bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
23607c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2361bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2362bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2364865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
23651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2366aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
23673b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
23687c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
23693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
23702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2371d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
23721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23738dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
2374def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2375def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
23768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2377aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2378aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2379aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
23804c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2381aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
23821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
23831c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
2384aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
2385aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2386aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2387aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
23881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2389aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2390aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
23911c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
23921c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
23931c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
23941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
23951c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
23961c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
23971c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2398a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
2399a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
24007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifier *getQualifier() const {
24017c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor    return QualifierLoc.getNestedNameSpecifier();
24027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24047c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
24057c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
24067c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
24077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
24087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor
2409c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
2410c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
2411c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
2412c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
2413c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
24141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
2416c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
2417c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
2418c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
2419c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
2421c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
2422c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
24251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
24262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
24272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
24282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
24292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
24302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
24312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
24322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
24331c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
24341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
24351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
24362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
24371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
24383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
24393b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
2440aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  bool hasExplicitTemplateArgs() const {
2441aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return HasExplicitTemplateArgs;
24423b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
244436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
244536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2446096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
244736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    assert(HasExplicitTemplateArgs);
2448096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
244936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
245036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
245136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
245236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
2453096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
245436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
2455096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
2456096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2457096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2458096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2459096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2460096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2461096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2462096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2463096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
246436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
246536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
2466d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
2467d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
2468d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2469096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
2470d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2471d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
24728dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
24738dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2474096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
24758dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
24768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
24783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// member name ('<'), if any.
24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
2480096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().LAngleLoc;
24813b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
24821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
24843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
2485833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
2486096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
24873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
24881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
24903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
2492096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
24933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
24941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
24963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template arguments ('>').
24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
2498096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().RAngleLoc;
24993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
250163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
2502aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
2503aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2504aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
2505aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
25067c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2507aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
25082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setBegin(MemberNameInfo.getBeginLoc());
25091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2510aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
2511aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
2512aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
25132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setEnd(MemberNameInfo.getEndLoc());
2514aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
25151c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
25161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2518865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
25191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
2520865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
25211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
25221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
252363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
252463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
252563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
252663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
25274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
25284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
25294045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
25301c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
25311c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2532129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
2533aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
2534aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2535aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
2536aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
2537aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
2538aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
2539aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
2540aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
2541aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2542aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
2543aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
2544aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
25457bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
2546129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
2547129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
2548129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
2549129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2550129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
2551129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
2552129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
2553129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
25547bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
25557bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
25567bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
25577bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
25587bb12da2b0749eeebb21854c77877736969e59f2John McCall
25597bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
25607bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
2561129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2562129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
2563129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
2564129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
2566aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
2567129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
25684c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
25692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
25705a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
25715a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2572a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2573a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
2574a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2575a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
2576129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
25774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
25784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor
2579129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
2580129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
2581bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
2582aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
2583129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
25844c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
25852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
25865a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
25875a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2588129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2589a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
2590def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor  CreateEmpty(ASTContext &C, bool HasExplicitTemplateArgs,
2591def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
2592a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2593aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2594aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2595aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
25964c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2597aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2598129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
2599129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
2600aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
2601aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2602aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2603aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
26042f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
26052f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
26062f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
26072f27bf854f0519810b34afd209089cc75536b757John McCall  }
2608129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2609aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2610a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2611a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
2612a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
2613a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2614aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2615129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
2616129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
2617129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
2618129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2619129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
2620129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2621129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2622c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
2623c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
2624c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
26252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
26262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
26272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
26282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2629129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
2630129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
26317bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
2632129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2633129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
2634129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
26357bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
2636129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
26377bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
26387bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name.
26397bb12da2b0749eeebb21854c77877736969e59f2John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
26407bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
26417bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
26427bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
26437bb12da2b0749eeebb21854c77877736969e59f2John McCall
26447bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief Retrieve the explicit template argument list that followed the
26457bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member template name, if any.
26467bb12da2b0749eeebb21854c77877736969e59f2John McCall  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
26477bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(hasExplicitTemplateArgs());
26487bb12da2b0749eeebb21854c77877736969e59f2John McCall    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2649129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2650129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2651096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2652096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2653096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2654096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2655096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2656096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2657096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2658096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2659129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Copies the template arguments into the given structure.
2660129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
26617bb12da2b0749eeebb21854c77877736969e59f2John McCall    getExplicitTemplateArgs().copyInto(List);
2662129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2663129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2664129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the left angle bracket following
2665129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the member name ('<').
2666129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getLAngleLoc() const {
26677bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().LAngleLoc;
2668129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2669129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2670129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the template arguments provided as part of this
2671129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// template-id.
2672129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
26737bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2674129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2675129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2676129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the number of template arguments provided as
2677129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// part of this template-id.
2678129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  unsigned getNumTemplateArgs() const {
26797bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2680129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2681129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2682129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the right angle bracket
2683129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// following the template arguments ('>').
2684129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getRAngleLoc() const {
26857bb12da2b0749eeebb21854c77877736969e59f2John McCall    return getExplicitTemplateArgs().RAngleLoc;
2686129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2687129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
268863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
26892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range = getMemberNameInfo().getSourceRange();
2690aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
2691aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
26924c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    else if (getQualifierLoc())
26934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2694aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
2695129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
2696129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
2697129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
2698129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2699129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2700129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
2701129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
2702129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
2703129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
2704129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
2705129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
270663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
270763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
270863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
270963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2710129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
2711129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
27122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
27132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
27142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
27152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
27162e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
27172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
27182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
27192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
27202e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2721c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
2722c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
27232e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
27242e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
27252e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
2726f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
2727f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
2728bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
2729bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
27306b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
27316b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
27326b219d082434394c1ac401390ec1d1967727815aSebastian Redl
27336b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
27346b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
27352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
27362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
27372e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
27382e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
273963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return Range; }
27402e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
27412e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
27422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
27432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
27442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
27452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
27462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const CXXNoexceptExpr *) { return true; }
27472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
27482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
274963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
27502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
27512e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
2752be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \brief Represents a C++0x pack expansion that produces a sequence of
2753be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
2754be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2755be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
2756be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
2757be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2758be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
2759be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
2760be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
2761be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
2762be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
2763be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
2764be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
2765be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
2766be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// pattern is \c static_cast<Types&&>(args). When the \c forward function
2767be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
2768be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
2769be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
2770be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
277167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
277267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
277367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
277467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
277567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
277667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
277767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
277867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
2779be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
2780be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2781be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
278267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
2783be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2784be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
278567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
278667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                    llvm::Optional<unsigned> NumExpansions)
2787be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
2788be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           Pattern->getObjectKind(), /*TypeDependent=*/true,
2789be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor           /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false),
2790be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
279167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
2792be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
2793be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2794be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
2795be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2796be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2797be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
2798be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2799be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
2800be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
2801be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2802be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
2803be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
2804be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
2805be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
280667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief Determine the number of expansions that will be produced when
280767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
280867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
280967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
281067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
281167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
281267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return llvm::Optional<unsigned>();
281367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
281467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor
281563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
281663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
281763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2818be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2819be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
2820be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
2821be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
2822be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const PackExpansionExpr *) { return true; }
2823be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
2824be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
282563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
282663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
282763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2828be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
2829be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
28307bb12da2b0749eeebb21854c77877736969e59f2John McCallinline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
28317bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
28327bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
28337bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
28347bb12da2b0749eeebb21854c77877736969e59f2John McCall    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
28357bb12da2b0749eeebb21854c77877736969e59f2John McCall}
28367bb12da2b0749eeebb21854c77877736969e59f2John McCall
2837ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \brief Represents an expression that computes the length of a parameter
2838ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
2839ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
2840ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
2841ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
2842ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
2843ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
2844ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
2845ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
2846ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
2847ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
2848ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
2849ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2850ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
2851ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
2852ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2853ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
2854ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
2855ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2856ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
2857ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2858ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
2859ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
2860ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
2861ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
2862ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2863ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
2864ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
2865ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2866ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
2867ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
2868ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2869ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
2870ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
2871ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
2872ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2873ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
2874ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2875ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
2876ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
2877ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2878ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
2879ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2880ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
2881ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
2882ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
2883ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
2884ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
2885ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
2886ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
2887ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
2888ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
2889ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
2890ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2891ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
2892ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
2893ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2894ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
2895ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2896ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2897ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
2898ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
2899ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2900ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
2901ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2902ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2903ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
2904ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
2905ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2906ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
2907ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
2908c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// This routine may only be invoked when the expression is not
2909c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
2910ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
2911ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    assert(!isValueDependent() &&
2912ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
2913ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
2914ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2915ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
291663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const {
291763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(OperatorLoc, RParenLoc);
291863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2919ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2920ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
2921ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
2922ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
2923ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const SizeOfPackExpr *) { return true; }
2924ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
2925ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
292663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2927ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
2928c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2929c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
2930c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
2931c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
2932c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
2933c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
2934c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter lists, this node node is used to represent a non-type template
2935c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
2936c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
2937c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
2938c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
2939c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
2940c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
2941c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
2942c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
2943c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
2944c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2945c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
2946c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
2947c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
2948c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2949c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
2950c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
2951c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2952c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
2953c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
2954c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2955c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
2956c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtWriter;
2957c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2958c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
2959c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(QualType T,
2960c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
2961c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
2962c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
2963c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2964c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
2965c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
2966c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2967c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
2968c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
2969c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2970c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
2971c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
2972c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2973c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
2974c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
2975c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
2976c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
297763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  SourceRange getSourceRange() const { return NameLoc; }
2978c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2979c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
2980c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
2981c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2982c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
2983c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return true;
2984c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
2985c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
2986c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
298763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2988c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
2989ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
29905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
29915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
29925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2993