ExprCXX.h revision aa49a7d70e58dac2aeb40664ba16d2ea571b8c95
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
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
18eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall#include "clang/AST/UnresolvedSet.h"
19d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h"
2001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/ExpressionTraits.h"
2101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h"
2201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/TypeTraits.h"
23aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
27aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl;
28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl;
29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl;
30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary;
31aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo;
324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions.
351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===//
361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator
383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax.
393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator
413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the
433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call.
443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever
463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the
473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and
483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template
493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time.
50b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr {
51063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief The overloaded operator.
52063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind Operator;
53063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
54b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic:
551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr **args, unsigned numargs, QualType t,
57f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      ExprValueKind VK, SourceLocation operatorloc)
58cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall               operatorloc),
60063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor      Operator(Op) {}
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
62ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
64b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
65b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator - Returns the kind of overloaded operator that this
66b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// expression refers to.
67063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  OverloadedOperatorKind getOperator() const { return Operator; }
68ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperatorLoc - Returns the location of the operator symbol in
71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// the expression. When @c getOperator()==OO_Call, this is the
72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// location of the right parentheses; when @c
73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// getOperator()==OO_Subscript, this is the location of the right
74b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  /// bracket.
75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
76b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
77aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXOperatorCallExprClass;
81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  }
82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor};
84b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that
8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()"
8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax
8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member
8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains
9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the
9188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including
9288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument).
9388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr {
9488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic:
951817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
96f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                    QualType t, ExprValueKind VK, SourceLocation RP)
97cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
9888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
991817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
1001817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
1011817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner
10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// getImplicitObjectArgument - Retrieves the implicit object
10388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// argument for the member call. For example, in "x.f(5)", this
10488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  /// operation would return "x".
105b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  Expr *getImplicitObjectArgument() const;
106ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
107b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  /// Retrieves the declaration of the called method.
108b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek  CXXMethodDecl *getMethodDecl() const;
10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
111007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// the implicit object argument. Note that this is may not be the same
112007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// declaration as that of the class context of the CXXMethodDecl which this
113007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// function is calling.
114007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  /// FIXME: Returns 0 for member pointer call exprs.
115007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth  CXXRecordDecl *getRecordDecl();
116007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth
1171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor    return T->getStmtClass() == CXXMemberCallExprClass;
11988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
12088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
12188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor};
12288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr {
125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate:
126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  enum { CONFIG, END_PREARG };
127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic:
129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     Expr **args, unsigned numargs, QualType t,
131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne                     ExprValueKind VK, SourceLocation RP)
132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne               RP) {
134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    setConfig(Config);
135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  const CallExpr *getConfig() const {
141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return cast_or_null<CallExpr>(getPreArg(CONFIG));
142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const Stmt *T) {
147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne    return T->getStmtClass() == CUDAKernelCallExprClass;
148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  }
149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  static bool classof(const CUDAKernelCallExpr *) { return true; }
150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne};
151e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne
15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast.
15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes
15749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr,
15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
15949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr {
1601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate:
1611060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc; // the location of the casting op
1621d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation RParenLoc; // the location of the right parenthesis
163ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
166f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
1671d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   TypeSourceInfo *writtenTy, SourceLocation l,
1681d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
1691d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
1701d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor      RParenLoc(RParenLoc) {}
17149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
172f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
173f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(SC, Shell, PathSize) { }
174ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1751d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  friend class ASTStmtReader;
176ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const char *getCastName() const;
17949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
180a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// \brief Retrieve the location of the cast operator keyword, e.g.,
181a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  /// "static_cast".
182a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
183a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor
1841d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  /// \brief Retrieve the location of the closing parenthesis.
1851d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
186ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
187aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1881d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor    return SourceRange(Loc, RParenLoc);
1891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    switch (T->getStmtClass()) {
19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXStaticCastExprClass:
19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXDynamicCastExprClass:
19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXReinterpretCastExprClass:
19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    case CXXConstCastExprClass:
19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    default:
19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return false;
19949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    }
2001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXNamedCastExpr *) { return true; }
20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
20349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
204ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression
205ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]).
2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
20749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g.,
20849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0).
20949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr {
210f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
211f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                    unsigned pathSize, TypeSourceInfo *writtenTy,
2121d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                    SourceLocation l, SourceLocation RParenLoc)
213f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
2141d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
21549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
216f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
217f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
220f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
221f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                   ExprValueKind VK, CastKind K, Expr *Op,
222f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                   const CXXCastPath *Path,
223ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   TypeSourceInfo *Written, SourceLocation L,
2241d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                   SourceLocation RParenLoc);
225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
226f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        unsigned PathSize);
227ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXStaticCastExprClass;
23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXStaticCastExpr *) { return true; }
23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
23449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
23649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast.
2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g.,
23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr).
24049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr {
241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
242f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
2431d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                     SourceLocation l, SourceLocation RParenLoc)
244f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
2451d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       writtenTy, l, RParenLoc) {}
24649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
252f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                    ExprValueKind VK, CastKind Kind, Expr *Op,
253f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                    const CXXCastPath *Path,
254ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                    TypeSourceInfo *Written, SourceLocation L,
2551d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                    SourceLocation RParenLoc);
256ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
257f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
258f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                         unsigned pathSize);
259ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2600fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson  bool isAlwaysNull() const;
2610fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson
2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXDynamicCastExprClass;
26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXDynamicCastExpr *) { return true; }
26649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
26749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
26849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view
27049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time.
2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
27249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g.,
27349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr).
27449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         Expr *op, unsigned pathSize,
277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                         TypeSourceInfo *writtenTy, SourceLocation l,
2781d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                         SourceLocation RParenLoc)
279f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
2801d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       pathSize, writtenTy, l, RParenLoc) {}
28149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
284f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
285f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
286f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        ExprValueKind VK, CastKind Kind,
288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                        Expr *Op, const CXXCastPath *Path,
289ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                 TypeSourceInfo *WrittenTy, SourceLocation L,
2901d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                        SourceLocation RParenLoc);
291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
292f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                             unsigned pathSize);
293ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXReinterpretCastExprClass;
29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXReinterpretCastExpr *) { return true; }
29849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
29949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
30149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value.
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
30349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g.,
30449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar).
30549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr {
306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
307ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   TypeSourceInfo *writtenTy, SourceLocation l,
3081d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                   SourceLocation RParenLoc)
309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
3101d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                       0, writtenTy, l, RParenLoc) {}
31149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
312ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  explicit CXXConstCastExpr(EmptyShell Empty)
313f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
314f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
315f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  ExprValueKind VK, Expr *Op,
318ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                  TypeSourceInfo *WrittenTy, SourceLocation L,
3191d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor                                  SourceLocation RParenLoc);
320f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
321ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return T->getStmtClass() == CXXConstCastExprClass;
32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
32549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const CXXConstCastExpr *) { return true; }
3261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
3271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
3289fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
3299fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]).
3309fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3319fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
3329fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better
3339fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal.
3349fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith///
3359fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at
3369fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent.
3379fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr {
3389fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// \brief The location of a ud-suffix within the literal.
3399fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  SourceLocation UDSuffixLoc;
3409fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3419fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic:
3429fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  UserDefinedLiteral(ASTContext &C, Expr *Fn, Expr **Args, unsigned NumArgs,
3439fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
3449fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith                     SourceLocation SuffixLoc)
3459fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, NumArgs, T, VK,
3469fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith               LitEndLoc), UDSuffixLoc(SuffixLoc) {}
3479fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
3489fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    : CallExpr(C, UserDefinedLiteralClass, Empty) {}
3499fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3509fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// The kind of literal operator which is invoked.
3519fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  enum LiteralOperatorKind {
3529fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Raw,      ///< Raw form: operator "" X (const char *)
3539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Template, ///< Raw form: operator "" X<cs...> ()
3549fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Integer,  ///< operator "" X (unsigned long long)
3559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Floating, ///< operator "" X (long double)
3569fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_String,   ///< operator "" X (const CharT *, size_t)
3579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    LOK_Character ///< operator "" X (CharT)
3589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  };
3599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getLiteralOperatorKind - Returns the kind of literal operator invocation
3619fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// which this expression represents.
3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  LiteralOperatorKind getLiteralOperatorKind() const;
3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getCookedLiteral - If this is not a raw user-defined literal, get the
3659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// underlying cooked literal (representing the literal with the suffix
3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// removed).
3679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  Expr *getCookedLiteral();
3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const Expr *getCookedLiteral() const {
3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
3709fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
3719fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
3739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// For a string literal, there may be multiple identical suffixes. This
3749fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// returns the first.
3759fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  SourceLocation getUDSuffixLoc() const { return getRParenLoc(); }
3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  /// getUDSuffix - Returns the ud-suffix specified for this literal.
3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  const IdentifierInfo *getUDSuffix() const;
3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const Stmt *S) {
3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith    return S->getStmtClass() == UserDefinedLiteralClass;
3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  }
3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  static bool classof(const UserDefinedLiteral *) { return true; }
3849fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3859fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtReader;
3869fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith  friend class ASTStmtWriter;
3879fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith};
3889fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith
3891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
3911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr {
3921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool Value;
3931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation Loc;
3941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
396bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
397561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
398f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Value(val), Loc(l) {}
3998b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl
400eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXBoolLiteralExpr(EmptyShell Empty)
401eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXBoolLiteralExprClass, Empty) { }
402eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  bool getValue() const { return Value; }
404eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setValue(bool V) { Value = V; }
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
406aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
4071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
408eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
409eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
410eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
4121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXBoolLiteralExprClass;
4131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
4141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXBoolLiteralExpr *) { return true; }
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
41763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
4191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
4206e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
4216e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr {
4226e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  SourceLocation Loc;
4236e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic:
4246e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
425bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
426561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false),
427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Loc(l) {}
4286e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
429eb7f96141f754150a92433286fa385910a22f494Sam Weinig  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
430eb7f96141f754150a92433286fa385910a22f494Sam Weinig    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
431eb7f96141f754150a92433286fa385910a22f494Sam Weinig
432aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
4336e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
434eb7f96141f754150a92433286fa385910a22f494Sam Weinig  SourceLocation getLocation() const { return Loc; }
435eb7f96141f754150a92433286fa385910a22f494Sam Weinig  void setLocation(SourceLocation L) { Loc = L; }
436eb7f96141f754150a92433286fa385910a22f494Sam Weinig
4376e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const Stmt *T) {
4386e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
4396e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  }
4406e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
4416e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
44263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
4436e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl};
4446e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
445c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
446c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly
447c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression.
448c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl///
449c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr)
450c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr {
451c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate:
45257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  SourceRange Range;
454c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
455c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic:
45657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
457f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
45857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
45957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           false,
46057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor           // typeid is value-dependent if the type or expression are dependent
461bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->isDependentType(),
462561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
463bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
46457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
465ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
46657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
4682850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
469bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,
4702850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl        // typeid is value-dependent if the type or expression are dependent
471bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->isTypeDependent() || Operand->isValueDependent(),
472561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
47457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor      Operand(Operand), Range(R) { }
475c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
47614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
47714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    : Expr(CXXTypeidExprClass, Empty) {
47814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    if (isExpr)
47914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (Expr*)0;
48014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    else
48114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner      Operand = (TypeSourceInfo*)0;
48214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
483ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
48457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
48657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieves the type operand of this typeid() expression after
48757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// various required adjustments (removing reference types, cv-qualifiers).
48857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  QualType getTypeOperand() const;
48957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor
49057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  /// \brief Retrieve source information for the type operand.
49157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor  TypeSourceInfo *getTypeOperandSourceInfo() const {
492c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
49357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return Operand.get<TypeSourceInfo *>();
494c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
49514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner
49614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
49714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
49814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner    Operand = TSI;
49914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  }
500ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
50114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  Expr *getExprOperand() const {
502c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
50357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor    return static_cast<Expr*>(Operand.get<Stmt *>());
504c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
505ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
506030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  void setExprOperand(Expr *E) {
507030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
508030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner    Operand = E;
509030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  }
510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
511aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
51214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner  void setSourceRange(SourceRange R) { Range = R; }
513ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
514c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const Stmt *T) {
515c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl    return T->getStmtClass() == CXXTypeidExprClass;
516c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  }
517c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  static bool classof(const CXXTypeidExpr *) { return true; }
518c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
519c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl  // Iterators
52063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
52163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
52263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
52363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
52463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
525c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl};
526c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl
52701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
52801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression.
52901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet///
53001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
53101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr {
53201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate:
53301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
53401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  SourceRange Range;
53501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
53601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic:
53701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
5382e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
539bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->getType()->isDependentType(),
540561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->getType()->isInstantiationDependentType(),
541bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->getType()->containsUnexpandedParameterPack()),
54201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
54401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
5452e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet    : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
546bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false, Operand->isTypeDependent(),
547561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Operand->isInstantiationDependent(),
548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
54901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand(Operand), Range(R) { }
55001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
55101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
55201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    : Expr(CXXUuidofExprClass, Empty) {
55301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    if (isExpr)
55401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (Expr*)0;
55501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    else
55601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet      Operand = (TypeSourceInfo*)0;
55701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
558ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
55901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
56101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieves the type operand of this __uuidof() expression after
56201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// various required adjustments (removing reference types, cv-qualifiers).
56301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  QualType getTypeOperand() const;
56401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
56501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  /// \brief Retrieve source information for the type operand.
56601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  TypeSourceInfo *getTypeOperandSourceInfo() const {
56701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
56801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return Operand.get<TypeSourceInfo *>();
56901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
57001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
57101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
57201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
57301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = TSI;
57401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
575ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
57601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  Expr *getExprOperand() const {
57701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
57801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return static_cast<Expr*>(Operand.get<Stmt *>());
57901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
58101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setExprOperand(Expr *E) {
58201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
58301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    Operand = E;
58401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
58501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
586aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
58701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  void setSourceRange(SourceRange R) { Range = R; }
588ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
58901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const Stmt *T) {
59001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet    return T->getStmtClass() == CXXUuidofExprClass;
59101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  }
59201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  static bool classof(const CXXUuidofExpr *) { return true; }
59301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
59401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet  // Iterators
59563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
59663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isTypeOperand()) return child_range();
59763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
59863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + 1);
59963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
60001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet};
60101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet
602796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a
603796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is
604796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example:
605796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///
606796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code
607796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo {
608796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public:
609796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void bar();
610796da18402f286b897782a298ae3b20c459c102eDouglas Gregor///   void test() { this->bar(); }
611796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// };
612796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode
613796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr {
614796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  SourceLocation Loc;
615828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool Implicit : 1;
616ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
617796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic:
618828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
619f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
6202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // 'this' is type-dependent if the class type of the enclosing
6212850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // member function is dependent (C++ [temp.dep.expr]p2)
622bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Type->isDependentType(), Type->isDependentType(),
623561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Type->isInstantiationDependentType(),
624bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
625828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor      Loc(L), Implicit(isImplicit) { }
626796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6272fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
6282fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
6292fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  SourceLocation getLocation() const { return Loc; }
6302fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  void setLocation(SourceLocation L) { Loc = L; }
6312fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
632aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
633796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
634828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  bool isImplicit() const { return Implicit; }
635828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor  void setImplicit(bool I) { Implicit = I; }
636ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
638796da18402f286b897782a298ae3b20c459c102eDouglas Gregor    return T->getStmtClass() == CXXThisExprClass;
639796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  }
640796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  static bool classof(const CXXThisExpr *) { return true; }
641796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
642796da18402f286b897782a298ae3b20c459c102eDouglas Gregor  // Iterators
64363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
644796da18402f286b897782a298ae3b20c459c102eDouglas Gregor};
645796da18402f286b897782a298ae3b20c459c102eDouglas Gregor
6461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
6471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  'throw' and 'throw' assignment-expression.  When
6481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///  assignment-expression isn't present, Op will be null.
6491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek///
6501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr {
6511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Stmt *Op;
6521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  SourceLocation ThrowLoc;
653bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Whether the thrown variable (if any) is in scope.
654bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  unsigned IsThrownVariableInScope : 1;
655ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
656bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  friend class ASTStmtReader;
657ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
6591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Ty is the void type which is used as the result type of the
6601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // exepression.  The l is the location of the throw keyword.  expr
6611060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // can by null, if the optional expression to throw isn't present.
662bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
663bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor               bool IsThrownVariableInScope) :
664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
665561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         expr && expr->isInstantiationDependent(),
666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         expr && expr->containsUnexpandedParameterPack()),
667bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor    Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
6682fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
6692fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner
6701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
6711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
67242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor
67342e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor  SourceLocation getThrowLoc() const { return ThrowLoc; }
6741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
675bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// \brief Determines whether the variable thrown by this expression (if any!)
676bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// is within the innermost try block.
677bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  ///
678bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// This information is required to determine whether the NRVO can apply to
679bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  /// this variable.
680bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor  bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
682aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
6831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    if (getSubExpr() == 0)
6841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek      return SourceRange(ThrowLoc, ThrowLoc);
6851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
6861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
6891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXThrowExprClass;
6901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
6911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXThrowExpr *) { return true; }
6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6931060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
69463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
69563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Op, Op ? &Op+1 : &Op);
69663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
6971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
6981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
6991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
7001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding
7011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly
7021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters.
7031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr {
70465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// \brief The parameter whose default is being used.
70565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ///
706ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// When the bit is set, the subexpression is stored after the
70765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
70865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  /// actual default expression is the subexpression.
70965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
711036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// \brief The location where the default argument expression was used.
712036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation Loc;
713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
714036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
715ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(SC,
71665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor           param->hasUnparsedDefaultArg()
71765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor             ? param->getType().getNonReferenceType()
7182333f7727f97018d6742e1e0938133bcfad967abEli Friedman             : param->getDefaultArg()->getType(),
719dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           param->getDefaultArg()->getValueKind(),
720561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           param->getDefaultArg()->getObjectKind(), false, false, false, false),
721036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor      Param(param, false), Loc(Loc) { }
72265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor
723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
724036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                    Expr *SubExpr)
725dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall    : Expr(SC, SubExpr->getType(),
726dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall           SubExpr->getValueKind(), SubExpr->getObjectKind(),
727ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           false, false, false, false),
728bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      Param(param, true), Loc(Loc) {
72965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
73065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
731ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic:
733030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
734030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner
735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Param is the parameter whose default argument is used by this
7371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // expression.
738036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
739036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   ParmVarDecl *Param) {
740036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
741f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson  }
7421060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
74365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // Param is the parameter whose default argument is used by this
74465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  // expression, and SubExpr is the expression that will actually be used.
745ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static CXXDefaultArgExpr *Create(ASTContext &C,
746036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor                                   SourceLocation Loc,
747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                   ParmVarDecl *Param,
74865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor                                   Expr *SubExpr);
749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the parameter that the argument was created from.
75165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  const ParmVarDecl *getParam() const { return Param.getPointer(); }
75265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  ParmVarDecl *getParam() { return Param.getPointer(); }
753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Retrieve the actual argument to the function call.
755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  const Expr *getExpr() const {
75665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
75765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr const * const*> (this + 1);
758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
75965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr *getExpr() {
76165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor    if (Param.getInt())
76265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor      return *reinterpret_cast<Expr **> (this + 1);
763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return getParam()->getDefaultArg();
76465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor  }
7651060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the location where this default argument was actually
767036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  /// used.
768036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor  SourceLocation getUsedLocation() const { return Loc; }
769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
770aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
7711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // Default argument expressions have no representation in the
7721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    // source, so they have an empty source range.
7731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return SourceRange();
7741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const Stmt *T) {
7771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek    return T->getStmtClass() == CXXDefaultArgExprClass;
7781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  }
7791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  static bool classof(const CXXDefaultArgExpr *) { return true; }
7801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek
7811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek  // Iterators
78263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
7838a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis
78460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
7853397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
7861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek};
787987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
788c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary.
789c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary {
790c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson  /// Destructor - The destructor that needs to be called.
791b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  const CXXDestructorDecl *Destructor;
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
793b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson  CXXTemporary(const CXXDestructorDecl *destructor)
794c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson    : Destructor(destructor) { }
795c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson
796c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic:
7971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXTemporary *Create(ASTContext &C,
798b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson                              const CXXDestructorDecl *Destructor);
7991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
800f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXDestructorDecl *getDestructor() const { return Destructor; }
80176f3f69db1416425070177243e9f390122c553e0Richard Smith  void setDestructor(const CXXDestructorDecl *Dtor) {
80276f3f69db1416425070177243e9f390122c553e0Richard Smith    Destructor = Dtor;
80376f3f69db1416425070177243e9f390122c553e0Richard Smith  }
804c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson};
805fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
806ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary.
807ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
808ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be
809ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example:
810ddfe960d252a93525692b547945236d361d1929fChandler Carruth///
811ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code
812ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   struct S {
813ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     S() { }  // User defined constructor makes S non-POD.
814ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     ~S() { } // User defined destructor makes it non-trivial.
815ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   };
816ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   void test() {
817ddfe960d252a93525692b547945236d361d1929fChandler Carruth///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
818ddfe960d252a93525692b547945236d361d1929fChandler Carruth///   }
819ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode
820fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr {
821fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  CXXTemporary *Temp;
8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
823fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Stmt *SubExpr;
824fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
825bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
826bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor   : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
827ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie          VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
828bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->isValueDependent(),
829561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          SubExpr->isInstantiationDependent(),
830bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          SubExpr->containsUnexpandedParameterPack()),
831bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     Temp(temp), SubExpr(SubExpr) { }
83288eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson
833fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic:
834d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  CXXBindTemporaryExpr(EmptyShell Empty)
835d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
836ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
838fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson                                      Expr* SubExpr);
8391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  CXXTemporary *getTemporary() { return Temp; }
841f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const CXXTemporary *getTemporary() const { return Temp; }
842d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  void setTemporary(CXXTemporary *T) { Temp = T; }
843f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson
844fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
845fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
84688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
847fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
848aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
84996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
85096be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
851fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
852fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Implement isa/cast/dyncast/etc.
853fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const Stmt *T) {
854fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson    return T->getStmtClass() == CXXBindTemporaryExprClass;
855fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  }
856fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  static bool classof(const CXXBindTemporaryExpr *) { return true; }
857fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
858fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson  // Iterators
85963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
860fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson};
861fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson
86215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor.
86315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr {
86472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic:
86572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  enum ConstructionKind {
86672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_Complete,
86772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    CK_NonVirtualBase,
868059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_VirtualBase,
869059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt    CK_Delegating
87072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  };
871ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
87272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate:
87315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  CXXConstructorDecl *Constructor;
87415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
87599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation Loc;
876428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange ParenRange;
877a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor  unsigned NumArgs : 16;
87816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool Elidable : 1;
8797cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool HadMultipleCandidates : 1;
8805b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool ListInitialization : 1;
88116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool ZeroInitialization : 1;
88272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  unsigned ConstructKind : 2;
88315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  Stmt **Args;
8841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
885bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected:
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
88799a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                   SourceLocation Loc,
888bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson                   CXXConstructorDecl *d, bool elidable,
88916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                   Expr **args, unsigned numargs,
8907cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                   bool HadMultipleCandidates,
8915b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ListInitialization,
8925b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   bool ZeroInitialization,
8935b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   ConstructionKind ConstructKind,
8945b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                   SourceRange ParenRange);
895bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson
8966d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
8976d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
8985b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl    : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
8995b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      HadMultipleCandidates(false), ListInitialization(false),
9005b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ZeroInitialization(false), ConstructKind(0), Args(0)
9015b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9026d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
90315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic:
9046d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  /// \brief Construct an empty C++ construction expression.
9056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXConstructExpr(EmptyShell Empty)
9066d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis    : Expr(CXXConstructExprClass, Empty), Constructor(0),
9075b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      NumArgs(0), Elidable(false), HadMultipleCandidates(false),
9085b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ListInitialization(false), ZeroInitialization(false),
9095b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl      ConstructKind(0), Args(0)
9105b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  { }
9116d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
9128e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson  static CXXConstructExpr *Create(ASTContext &C, QualType T,
91399a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor                                  SourceLocation Loc,
9141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  CXXConstructorDecl *D, bool Elidable,
91516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor                                  Expr **Args, unsigned NumArgs,
9167cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                                  bool HadMultipleCandidates,
9175b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ListInitialization,
9185b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  bool ZeroInitialization,
9195b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  ConstructionKind ConstructKind,
9205b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                                  SourceRange ParenRange);
9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
922d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  CXXConstructorDecl* getConstructor() const { return Constructor; }
92339da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
924ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
92599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  SourceLocation getLocation() const { return Loc; }
92699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
927ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
928d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  /// \brief Whether this construction is elidable.
929d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor  bool isElidable() const { return Elidable; }
93039da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor  void setElidable(bool E) { Elidable = E; }
9317cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Whether the referred constructor was resolved from
9337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// an overloaded set having size greater than 1.
9347cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const { return HadMultipleCandidates; }
9357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
9367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
9375b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  /// \brief Whether this constructor call was written as list-initialization.
9385b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  bool isListInitialization() const { return ListInitialization; }
9395b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl  void setListInitialization(bool V) { ListInitialization = V; }
9405b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl
94116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// \brief Whether this construction first requires
94216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  /// zero-initialization before the initializer is called.
94316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  bool requiresZeroInitialization() const { return ZeroInitialization; }
94416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  void setRequiresZeroInitialization(bool ZeroInit) {
94516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor    ZeroInitialization = ZeroInit;
94616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor  }
947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9489db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// \brief Determines whether this constructor is actually constructing
9499db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor  /// a base class (rather than a complete object).
95024eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson  ConstructionKind getConstructionKind() const {
95124eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson    return (ConstructionKind)ConstructKind;
95272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
953ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setConstructionKind(ConstructionKind CK) {
95472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson    ConstructKind = CK;
95572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson  }
956ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
95715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ExprIterator arg_iterator;
95815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  typedef ConstExprIterator const_arg_iterator;
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_begin() { return Args; }
96115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  arg_iterator arg_end() { return Args + NumArgs; }
96215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_begin() const { return Args; }
96315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  const_arg_iterator arg_end() const { return Args + NumArgs; }
96415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
965a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
96615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  unsigned getNumArgs() const { return NumArgs; }
96715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
968bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  /// getArg - Return the specified argument.
969bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  Expr *getArg(unsigned Arg) {
970bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
971bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
972bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
973bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  const Expr *getArg(unsigned Arg) const {
974bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
975bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson    return cast<Expr>(Args[Arg]);
976bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson  }
9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9782eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  /// setArg - Set the specified argument.
9792eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  void setArg(unsigned Arg, Expr *ArgExpr) {
9802eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    assert(Arg < NumArgs && "Arg access out of range!");
9812eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian    Args[Arg] = ArgExpr;
9822eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian  }
9832eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian
984aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
985428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth  SourceRange getParenRange() const { return ParenRange; }
98615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
988524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson    return T->getStmtClass() == CXXConstructExprClass ||
989524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson      T->getStmtClass() == CXXTemporaryObjectExprClass;
99015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  }
99115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  static bool classof(const CXXConstructExpr *) { return true; }
9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson  // Iterators
99463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
99563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Args[0], &Args[0]+NumArgs);
99663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
9976d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
99860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
99915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson};
100015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson
100149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
100249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
100349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5);
100449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr {
1005987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation TyBeginLoc;
1006987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1007f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1008f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1009f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                        TypeSourceInfo *writtenTy,
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                        SourceLocation tyBeginLoc, CastKind kind,
1011f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                        Expr *castExpr, unsigned pathSize,
1012ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                        SourceLocation rParenLoc)
1013f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1014f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       castExpr, pathSize, writtenTy),
10150aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
10160aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson
1017f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1018f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1019f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
1020f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
1021f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1022f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                       ExprValueKind VK,
1023f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       TypeSourceInfo *Written,
1024f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation TyBeginLoc,
1025f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       CastKind Kind, Expr *Op,
1026f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       const CXXCastPath *Path,
1027f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                       SourceLocation RPLoc);
1028f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1029f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                            unsigned PathSize);
1030ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig
1031987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
1032ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
1033987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation getRParenLoc() const { return RParenLoc; }
1034ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1036aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1037987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis    return SourceRange(TyBeginLoc, RParenLoc);
1038987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CXXFunctionalCastExprClass;
1041987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1042987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  static bool classof(const CXXFunctionalCastExpr *) { return true; }
1043987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1044987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1045506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a
1046506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object.
1047506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast
1049506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1050ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the
1051ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr.
1052506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example:
1053506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code
1054506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); }
1055506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///
1056506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() {
1057506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1058506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// };
1059506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode
1060524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr {
1061ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
1062506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1063506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic:
10641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1065ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *Type,
10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         Expr **Args,unsigned NumArgs,
1067428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth                         SourceRange parenRange,
10687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara                         bool HadMultipleCandidates,
10691c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor                         bool ZeroInitialization = false);
10706d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1071ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1072506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
1073ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1074ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1075aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
1076ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1078506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor    return T->getStmtClass() == CXXTemporaryObjectExprClass;
1079506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  }
1080506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
10816d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
108260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
1083506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor};
1084506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor
108501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object
108601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later.
108701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
108801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example:
108901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code
109001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) {
109101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///   values.erase(std::remove_if(values.begin(), values.end(),
109201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor//                                [=](double value) { return value > cutoff; });
109301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// }
109401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode
109501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor///
109601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying
109701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function
109801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a
109901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either
110001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square
110101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression.
110201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr {
110301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  enum {
110401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indicate that the given
110501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture was implicit.
110601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_Implicit = 0x01,
110701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
110801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Flag used by the Capture class to indciate that the
110901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// given capture was by-copy.
111001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture_ByCopy = 0x02
111101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
111201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
111301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The source range that covers the lambda introducer ([...]).
111401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange IntroducerRange;
111501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11167ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief The number of captures.
11177ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned NumCaptures : 16;
11187ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
111901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The default capture kind, which is a value of type
112001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// LambdaCaptureDefault.
112101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned CaptureDefault : 2;
112201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
112301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Whether this lambda had an explicit parameter list vs. an
112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit (and empty) parameter list.
112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  unsigned ExplicitParams : 1;
112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1127dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had the result type explicitly specified.
1128dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  unsigned ExplicitResultType : 1;
1129dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor
1130dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether there are any array index variables stored at the end of
1131dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// this lambda expression.
11327ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned HasArrayIndexVars : 1;
11337ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief The location of the closing brace ('}') that completes
113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// the lambda.
113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  ///
113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// The location of the brace is also available by looking up the
113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// function call operator in the lambda class. However, it is
113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stored here to improve the performance of getSourceRange(), and
114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// to avoid having to deserialize the function call operator from a
114101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// module file just to determine the source range.
114201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceLocation ClosingBrace;
114301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
11447ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // Note: The capture initializers are stored directly after the lambda
11457ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // expression, along with the index variables used to initialize by-copy
11467ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  // array captures.
11477ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Describes the capture of either a variable or 'this'.
115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  class Capture {
115101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
115201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation Loc;
115301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation EllipsisLoc;
11549daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
115501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtReader;
115601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    friend class ASTStmtWriter;
11579daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
115801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  public:
115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Create a new capture.
116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Loc The source location associated with this capture.
116201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
116301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Kind The kind of capture (this, byref, bycopy).
116401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
116501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Implicit Whether the capture was implicit or explicit.
116601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
116701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param Var The local variable being captured, or null if capturing this.
116801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
116901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \param EllipsisLoc The location of the ellipsis (...) for a
117001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// capture that is a pack expansion, or an invalid source
117101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// location to indicate that this is not a pack expansion.
117201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    Capture(SourceLocation Loc, bool Implicit,
117301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            LambdaCaptureKind Kind, VarDecl *Var = 0,
117401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor            SourceLocation EllipsisLoc = SourceLocation());
117501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
117601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine the kind of capture.
117701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    LambdaCaptureKind getCaptureKind() const;
117801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
117901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles the C++ 'this'
118001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// pointer.
118101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesThis() const { return VarAndBits.getPointer() == 0; }
118201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
118301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture handles a variable.
118401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
118501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
118601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the declaration of the local variable being
118701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// captured.
118801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
118901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// This operation is only valid if this capture does not capture
119001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// 'this'.
119101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    VarDecl *getCapturedVar() const {
119201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(!capturesThis() && "No variable available for 'this' capture");
119301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return VarAndBits.getPointer();
119401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
119601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an implicit capture (not
119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// written between the square brackets introducing the lambda).
119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this was an explicit capture, written
120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// between the square brackets introducing the lambda.
120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isExplicit() const { return !isImplicit(); }
120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the source location of the capture.
120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    ///
120601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// For an explicit capture, this returns the location of the
120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// explicit capture in the source. For an implicit capture, this
120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// returns the location at which the variable or 'this' was first
120901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// used.
121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getLocation() const { return Loc; }
121101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Determine whether this capture is a pack expansion,
121301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// which captures a function parameter pack.
121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    bool isPackExpansion() const { return EllipsisLoc.isValid(); }
121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// \brief Retrieve the location of the ellipsis for a capture
121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    /// that is a pack expansion.
121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    SourceLocation getEllipsisLoc() const {
121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      assert(isPackExpansion() && "No ellipsis location for a non-expansion");
122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor      return EllipsisLoc;
122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    }
122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  };
122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate:
122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a lambda expression.
122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaExpr(QualType T, SourceRange IntroducerRange,
122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             LambdaCaptureDefault CaptureDefault,
122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Capture> Captures,
122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             bool ExplicitParams,
1230dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor             bool ExplicitResultType,
123101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor             ArrayRef<Expr *> CaptureInits,
12329daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<VarDecl *> ArrayIndexVars,
12339daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor             ArrayRef<unsigned> ArrayIndexStarts,
12349e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor             SourceLocation ClosingBrace,
1235ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor             unsigned ManglingNumber,
1236ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor             Decl *ContextDecl);
123701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
12389d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct an empty lambda expression.
12399d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
12409d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    : Expr(LambdaExprClass, Empty),
12419d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
12429d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor      ExplicitResultType(false), HasArrayIndexVars(true) {
12439d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor    getStoredStmts()[NumCaptures] = 0;
12449d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  }
12459d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
12467ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  Stmt **getStoredStmts() const {
12477ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
12487ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12497ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12507ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the mapping from captures to the first array index
12517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// variable.
12527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned *getArrayIndexStarts() const {
12537ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
12547ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12557ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
12567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Retrieve the complete set of array-index variables.
12577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  VarDecl **getArrayIndexVars() const {
12587ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<VarDecl **>(
12597ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor             getArrayIndexStarts() + NumCaptures + 1);
12607ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
12617ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
126201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic:
126301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Construct a new lambda expression.
126401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static LambdaExpr *Create(ASTContext &C,
126501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            CXXRecordDecl *Class,
126601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            SourceRange IntroducerRange,
126701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            LambdaCaptureDefault CaptureDefault,
126801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Capture> Captures,
126901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            bool ExplicitParams,
1270dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor                            bool ExplicitResultType,
127101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                            ArrayRef<Expr *> CaptureInits,
12729daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<VarDecl *> ArrayIndexVars,
12739daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor                            ArrayRef<unsigned> ArrayIndexStarts,
12749e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor                            SourceLocation ClosingBrace,
1275ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor                            unsigned ManglingNumber,
1276ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor                            Decl *ContextDecl);
127701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
12789d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// \brief Construct a new lambda expression that will be deserialized from
12799d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  /// an external source.
12809d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
12819d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor                                        unsigned NumArrayIndexVars);
12829d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor
128301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine the default capture kind for this lambda.
128401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  LambdaCaptureDefault getCaptureDefault() const {
128501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return static_cast<LambdaCaptureDefault>(CaptureDefault);
128601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
128701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
128801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief An iterator that walks over the captures of the lambda,
128901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// both implicit and explicit.
129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef const Capture *capture_iterator;
129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first lambda capture.
1293da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_begin() const;
129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the
129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// sequence of lambda captures.
1297da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator capture_end() const;
129801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
12997ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  /// \brief Determine the number of captures in this lambda.
13007ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  unsigned capture_size() const { return NumCaptures; }
13017ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor
130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first explicit
130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1304da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_begin() const;
130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// explicit lambda captures.
1308da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator explicit_capture_end() const;
130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing to the first implicit
131101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda capture.
1312da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_begin() const;
131301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve an iterator pointing past the end of the sequence of
131501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// implicit lambda captures.
1316da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor  capture_iterator implicit_capture_end() const;
131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
131801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Iterator that walks over the capture initialization
131901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// arguments.
132001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  typedef Expr **capture_init_iterator;
132101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the first initialization argument for this
132301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression (which initializes the first capture field).
13247ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_begin() const {
13257ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return reinterpret_cast<Expr **>(getStoredStmts());
13267ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
132701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
132801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the iterator pointing one past the last
132976e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  /// initialization argument for this lambda expression.
13307ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  capture_init_iterator capture_init_end() const {
13317ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return capture_init_begin() + NumCaptures;
13327ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
133301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13349daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Retrieve the set of index variables used in the capture
13359daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// initializer of an array captured by copy.
13369daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ///
13379daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \param Iter The iterator that points at the capture initializer for
13389daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// which we are extracting the corresponding index variables.
13399daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
13409daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
134101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the source range covering the lambda introducer,
134201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// which contains the explicit capture list surrounded by square
134301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// brackets ([...]).
134401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange getIntroducerRange() const { return IntroducerRange; }
134501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
134601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the class that corresponds to the lambda, which
134701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// stores the captures in its fields and provides the various
134801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// operations permitted on a lambda (copying, calling).
134901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXRecordDecl *getLambdaClass() const;
135001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the function call operator associated with this
135201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// lambda expression.
135301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  CXXMethodDecl *getCallOperator() const;
135401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Retrieve the body of the lambda.
13569d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor  CompoundStmt *getBody() const;
135701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
135801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether the lambda is mutable, meaning that any
135901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// captures values can be modified.
136001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool isMutable() const;
136101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
136201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Determine whether this lambda has an explicit parameter
136301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// list vs. an implicit (empty) parameter list.
136401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool hasExplicitParameters() const { return ExplicitParams; }
136501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1366dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  /// \brief Whether this lambda had its result type explicitly specified.
1367dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor  bool hasExplicitResultType() const { return ExplicitResultType; }
13689e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor
136901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const Stmt *T) {
137001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return T->getStmtClass() == LambdaExprClass;
137101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
137201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  static bool classof(const LambdaExpr *) { return true; }
137301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1374aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
137501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor    return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
137601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  }
137701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
13787ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  child_range children() {
13797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor    return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
13807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor  }
138101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
138201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtReader;
138301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  friend class ASTStmtWriter;
138401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor};
138501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
1386ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1387506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type
1388ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type.
1389987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis///
1390ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr {
1391987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  SourceLocation RParenLoc;
1392ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *TypeInfo;
1393987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
1394ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
1395ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1396987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic:
1397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Create an explicitly-written scalar-value initialization
1398ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// expression.
1399ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXScalarValueInitExpr(QualType Type,
1400ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         TypeSourceInfo *TypeInfo,
1401ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                         SourceLocation rParenLoc ) :
1402f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1403561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false, false, Type->isInstantiationDependentType(), false),
1404ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1405ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor
1406ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  explicit CXXScalarValueInitExpr(EmptyShell Shell)
1407ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    : Expr(CXXScalarValueInitExprClass, Shell) { }
14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1409ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
1410ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    return TypeInfo;
14114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
1412ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1413ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
14144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1415aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1418ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor    return T->getStmtClass() == CXXScalarValueInitExprClass;
1419987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  }
1420ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  static bool classof(const CXXScalarValueInitExpr *) { return true; }
14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1422987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  // Iterators
142363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1424987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis};
1425987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis
14264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls,
14274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)".
14284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr {
14292aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // Contains an optional array size expression, an optional initialization
14302aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  // expression, and any number of optional placement arguments, in that order.
14314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Stmt **SubExprs;
14324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the allocation function used.
14334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorNew;
14344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Points to the deallocation function used in case of error. May be null.
14354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *OperatorDelete;
14364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  /// \brief The allocated type-source information, as written in the source.
14381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *AllocatedTypeInfo;
1439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1440ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief If the allocated type was expressed as a parenthesized type-id,
14414bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  /// the source range covering the parenthesized type-id.
14424bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange TypeIdParens;
1443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14442aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Location of the first token.
14454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  SourceLocation StartLoc;
14462aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
14472aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Source-range of a paren-delimited initializer.
14482aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange DirectInitRange;
14494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1450d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Was the usage ::new, i.e. is the global new to be used?
1451d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool GlobalNew : 1;
1452d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Do we allocate an array? If so, the first SubExpr is the size expression.
1453d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool Array : 1;
1454d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // If this is an array allocation, does the usual deallocation
1455d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // function for the allocated type want to know the allocated size?
1456d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  bool UsualArrayDeleteWantsSize : 1;
1457d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The number of placement new arguments.
1458d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned NumPlacementArgs : 13;
1459d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // What kind of initializer do we have? Could be none, parens, or braces.
1460d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // In storage, we distinguish between "none, and no initializer expr", and
1461d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // "none, but an implicit initializer expr".
1462d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  unsigned StoredInitializationStyle : 2;
1463d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
146460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
14652aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  friend class ASTStmtWriter;
14664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
14672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  enum InitializationStyle {
14682aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    NoInit,   ///< New-expression has no initializer as written.
14692aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    CallInit, ///< New-expression has a C++98 paren-delimited initializer.
14702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    ListInit  ///< New-expression has a C++11 list-initializer.
14712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  };
14722aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl
1473ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
14741548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl             FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
14752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             Expr **placementArgs, unsigned numPlaceArgs,
14762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceRange typeIdParens, Expr *arraySize,
14772aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             InitializationStyle initializationStyle, Expr *initializer,
14786ec278d1a354517e20f13a877481453ee7940c78John McCall             QualType ty, TypeSourceInfo *AllocatedTypeInfo,
14792aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl             SourceLocation startLoc, SourceRange directInitRange);
14805921863d8f24084797863b5df37842113bac4352Chris Lattner  explicit CXXNewExpr(EmptyShell Shell)
14815921863d8f24084797863b5df37842113bac4352Chris Lattner    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
14825921863d8f24084797863b5df37842113bac4352Chris Lattner
14835921863d8f24084797863b5df37842113bac4352Chris Lattner  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
14842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl                         bool hasInitializer);
1485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1486cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  QualType getAllocatedType() const {
1487cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    assert(getType()->isPointerType());
14886217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    return getType()->getAs<PointerType>()->getPointeeType();
1489cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
14904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
14911bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
14921bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor    return AllocatedTypeInfo;
14931bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor  }
1494c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
1495c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// \brief True if the allocation result needs to be null-checked.
1496c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// C++0x [expr.new]p13:
1497c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   If the allocation function returns null, initialization shall
1498c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   not be done, the deallocation function shall not be called,
1499c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  ///   and the value of the new-expression shall be null.
1500c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// An allocation function is not allowed to return null unless it
1501c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// has a non-throwing exception-specification.  The '03 rule is
1502c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// identical except that the definition of a non-throwing
1503c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  /// exception specification is just "is it throw()?".
15048026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1505ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorNew() const { return OperatorNew; }
15075921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
15084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
15095921863d8f24084797863b5df37842113bac4352Chris Lattner  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
15104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1511cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  bool isArray() const { return Array; }
1512cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  Expr *getArraySize() {
1513cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1514cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1515cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  const Expr *getArraySize() const {
1516cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl    return Array ? cast<Expr>(SubExprs[0]) : 0;
1517cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl  }
1518cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl
15194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1520ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Expr **getPlacementArgs() {
15212aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1522aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
1523ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getPlacementArg(unsigned i) {
15254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15262aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return getPlacementArgs()[i];
15274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getPlacementArg(unsigned i) const {
15294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    assert(i < NumPlacementArgs && "Index out of range");
15302aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15334bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  bool isParenTypeId() const { return TypeIdParens.isValid(); }
15344bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor  SourceRange getTypeIdParens() const { return TypeIdParens; }
15354bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor
15364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalNew() const { return GlobalNew; }
15377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
15382aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief Whether this new-expression has any initializer at all.
15392aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool hasInitializer() const { return StoredInitializationStyle > 0; }
15401548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15412aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The kind of initializer this new-expression has.
15422aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  InitializationStyle getInitializationStyle() const {
15432aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    if (StoredInitializationStyle == 0)
15442aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl      return NoInit;
15452aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return static_cast<InitializationStyle>(StoredInitializationStyle-1);
15461548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15471548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15482aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// \brief The initializer of this new-expression.
15492aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  Expr *getInitializer() {
15502aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15511548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15522aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const Expr *getInitializer() const {
15532aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
15541548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl  }
15551548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15562aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// Answers whether the usual array deallocation function for the
15572aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// allocated type expects the size of the allocation as a
15582aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  /// parameter.
15592aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  bool doesUsualArrayDeleteWantSize() const {
15602aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return UsualArrayDeleteWantsSize;
15612aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
15621548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl
15634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ExprIterator arg_iterator;
15644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  typedef ConstExprIterator const_arg_iterator;
15654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_begin() {
15672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
15684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  arg_iterator placement_arg_end() {
15702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
15714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_begin() const {
15732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer();
15744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const_arg_iterator placement_arg_end() const {
15762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
15774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
1578ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15795921863d8f24084797863b5df37842113bac4352Chris Lattner  typedef Stmt **raw_arg_iterator;
15805921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_begin() { return SubExprs; }
15815921863d8f24084797863b5df37842113bac4352Chris Lattner  raw_arg_iterator raw_arg_end() {
15822aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
15835921863d8f24084797863b5df37842113bac4352Chris Lattner  }
15845921863d8f24084797863b5df37842113bac4352Chris Lattner  const_arg_iterator raw_arg_begin() const { return SubExprs; }
15852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  const_arg_iterator raw_arg_end() const {
15862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
15872aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  }
15884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15895921863d8f24084797863b5df37842113bac4352Chris Lattner  SourceLocation getStartLoc() const { return StartLoc; }
15902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceLocation getEndLoc() const;
1591428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
15922aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl  SourceRange getDirectInitRange() const { return DirectInitRange; }
1593428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth
1594aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
15952aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return SourceRange(getStartLoc(), getEndLoc());
15964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
15974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
15984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
15994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXNewExprClass;
16004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXNewExpr *) { return true; }
16024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
160463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
16052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl    return child_range(raw_arg_begin(), raw_arg_end());
160663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
16074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
16084c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
16104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray".
16114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr {
1612d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Points to the operator delete overload that is used. Could be a member.
1613d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  FunctionDecl *OperatorDelete;
1614d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // The pointer expression to be deleted.
1615d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Argument;
1616d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  // Location of the expression.
1617d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  SourceLocation Loc;
16184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this a forced global delete, i.e. "::delete"?
16194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool GlobalDelete : 1;
16204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Is this the array form of delete, i.e. "delete[]"?
16214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool ArrayForm : 1;
16224076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
16234076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
16244076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  // will be true).
16254076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool ArrayFormAsWritten : 1;
16266ec278d1a354517e20f13a877481453ee7940c78John McCall  // Does the usual deallocation function for the element type require
16276ec278d1a354517e20f13a877481453ee7940c78John McCall  // a size_t argument?
16286ec278d1a354517e20f13a877481453ee7940c78John McCall  bool UsualArrayDeleteWantsSize : 1;
16294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic:
16304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
16316ec278d1a354517e20f13a877481453ee7940c78John McCall                bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
16326ec278d1a354517e20f13a877481453ee7940c78John McCall                FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1633bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1634561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           arg->isInstantiationDependent(),
1635bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           arg->containsUnexpandedParameterPack()),
1636d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1637f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      GlobalDelete(globalDelete),
16384076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1639d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
164095fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis  explicit CXXDeleteExpr(EmptyShell Shell)
164195fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
16424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isGlobalDelete() const { return GlobalDelete; }
16444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  bool isArrayForm() const { return ArrayForm; }
16454076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
16464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16476ec278d1a354517e20f13a877481453ee7940c78John McCall  /// Answers whether the usual array deallocation function for the
16486ec278d1a354517e20f13a877481453ee7940c78John McCall  /// allocated type expects the size of the allocation as a
16496ec278d1a354517e20f13a877481453ee7940c78John McCall  /// parameter.  This can be true even if the actual deallocation
16506ec278d1a354517e20f13a877481453ee7940c78John McCall  /// function that we're using doesn't want a size.
16516ec278d1a354517e20f13a877481453ee7940c78John McCall  bool doesUsualArrayDeleteWantSize() const {
16526ec278d1a354517e20f13a877481453ee7940c78John McCall    return UsualArrayDeleteWantsSize;
16536ec278d1a354517e20f13a877481453ee7940c78John McCall  }
16546ec278d1a354517e20f13a877481453ee7940c78John McCall
16554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
16564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  Expr *getArgument() { return cast<Expr>(Argument); }
16584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  const Expr *getArgument() const { return cast<Expr>(Argument); }
16594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1660a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// \brief Retrieve the type being destroyed.  If the type being
1661a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// destroyed is a dependent type which may or may not be a pointer,
1662a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein  /// return an invalid type.
16635833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor  QualType getDestroyedType() const;
1664ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1665aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
16664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return SourceRange(Loc, Argument->getLocEnd());
16674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const Stmt *T) {
16704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl    return T->getStmtClass() == CXXDeleteExprClass;
16714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  }
16724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  static bool classof(const CXXDeleteExpr *) { return true; }
16734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
16744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl  // Iterators
167563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Argument, &Argument+1); }
1676f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis
1677f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis  friend class ASTStmtReader;
16784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl};
16794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl
1680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Structure used to store the type being destroyed by a
1681a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression.
1682a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage {
1683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Either the type source information or the name of the type, if
1684a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// it couldn't be resolved due to type-dependence.
1685a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1686ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1687a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief The starting source location of the pseudo-destructor type.
1688a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation Location;
1689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1690a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic:
1691a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage() { }
1692ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1693a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1694a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    : Type(II), Location(Loc) { }
1695ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1696a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1697ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getTypeSourceInfo() const {
1699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return Type.dyn_cast<TypeSourceInfo *>();
1700a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1702a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getIdentifier() const {
1703a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return Type.dyn_cast<IdentifierInfo *>();
1704a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1706a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  SourceLocation getLocation() const { return Location; }
1707a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor};
1708ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1709a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1710a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1711e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a
1712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have
1713e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example:
1714e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///
1715e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code
1716e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T;
1717e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) {
1718e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   p->T::~T();
1719e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// }
1720e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode
1721a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1722e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as:
1723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///
1724a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code
17251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T>
1726a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) {
1727e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor///   ptr->T::~T();
1728a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// }
1729a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode
1730a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor///
1731e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics
1732e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression.
1733a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr {
1734a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The base expression (that is being destroyed).
1735a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Stmt *Base;
17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1737a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1738a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// period ('.').
1739a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool IsArrow : 1;
17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1741a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The location of the '.' or '->' operator.
1742a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation OperatorLoc;
1743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1744a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief The nested-name-specifier that follows the operator, if present.
1745f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1747e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1748e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1749e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  TypeSourceInfo *ScopeType;
1750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1751ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The location of the '::' in a qualified pseudo-destructor
1752e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1753e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation ColonColonLoc;
1754ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1755fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief The location of the '~'.
1756fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation TildeLoc;
1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief The type being destroyed, or its name if we were unable to
1759a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// resolve the name.
1760a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  PseudoDestructorTypeStorage DestroyedType;
17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1762f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  friend class ASTStmtReader;
1763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1764a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic:
1765a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  CXXPseudoDestructorExpr(ASTContext &Context,
1766a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1767f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
1768e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          TypeSourceInfo *ScopeType,
1769e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor                          SourceLocation ColonColonLoc,
1770fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor                          SourceLocation TildeLoc,
1771e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                          PseudoDestructorTypeStorage DestroyedType);
17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1773de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1774de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    : Expr(CXXPseudoDestructorExprClass, Shell),
1775f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor      Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1776de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1777a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  Expr *getBase() const { return cast<Expr>(Base); }
17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
1780a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1781a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// x->Base::foo.
1782f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  bool hasQualifier() const { return QualifierLoc; }
17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1784f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1785f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  /// with source-location information.
1786f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1787ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
1789a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
1790a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// NULL.
1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
1792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
1793f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor  }
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1795a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Determine whether this pseudo-destructor expression was written
1796a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// using an '->' (otherwise, it used a '.').
1797a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  bool isArrow() const { return IsArrow; }
1798a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor
1799a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  /// \brief Retrieve the location of the '.' or '->' operator.
1800a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1803e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1804e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  ///
1805e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Pseudo-destructor expressions can have extra qualification within them
1806e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1807e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// Here, if the object type of the expression is (or may be) a scalar type,
1808ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \p T may also be a scalar type and, therefore, cannot be part of a
1809e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1810e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// destructor expression.
181126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1812ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1813e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1814e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  /// expression.
1815e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1817fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  /// \brief Retrieve the location of the '~'.
1818fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor  SourceLocation getTildeLoc() const { return TildeLoc; }
1819ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
182026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// \brief Retrieve the source location information for the type
182126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor  /// being destroyed.
1822a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  ///
1823ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This type-source information is available for non-dependent
1824a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// pseudo-destructor expressions and some dependent pseudo-destructor
1825a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// expressions. Returns NULL if we only have the identifier for a
1826a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// dependent pseudo-destructor expression.
1827ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  TypeSourceInfo *getDestroyedTypeInfo() const {
1828ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getTypeSourceInfo();
1829a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1830ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1831a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief In a dependent pseudo-destructor expression for which we do not
1832a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// have full type information on the destroyed type, provides the name
1833a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// of the destroyed type.
1834a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  IdentifierInfo *getDestroyedTypeIdentifier() const {
1835a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor    return DestroyedType.getIdentifier();
1836a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
1837ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1838a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the type being destroyed.
1839a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  QualType getDestroyedType() const;
1840ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1841a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  /// \brief Retrieve the starting location of the type being destroyed.
1842ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SourceLocation getDestroyedTypeLoc() const {
1843ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return DestroyedType.getLocation();
1844a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor  }
18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1846de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1847de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// expression.
1848de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1849de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1850de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1851de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1852de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  /// \brief Set the destroyed type.
1853de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  void setDestroyedType(TypeSourceInfo *Info) {
1854de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis    DestroyedType = PseudoDestructorTypeStorage(Info);
1855de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis  }
1856de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis
1857aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
18581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1860a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1861a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  }
1862a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1864a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor  // Iterators
186563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base + 1); }
1866a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor};
18671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
186864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
186964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates.
187064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example:
187164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true
187264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false
187364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr {
18740dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
18750dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  unsigned UTT : 31;
18760dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The value of the type trait. Unspecified if dependent.
18770dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool Value : 1;
187864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
187964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// Loc - The location of the type trait keyword.
188064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation Loc;
188164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
188264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// RParen - The location of the closing paren.
188364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  SourceLocation RParen;
188464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
18850dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  /// The type being queried.
18863d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *QueriedType;
188764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
188864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic:
1889ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
18900dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl                     TypeSourceInfo *queried, bool value,
189164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl                     SourceLocation rparen, QualType ty)
1892f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1893bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           false,  queried->getType()->isDependentType(),
1894561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->getType()->isInstantiationDependentType(),
1895bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           queried->getType()->containsUnexpandedParameterPack()),
18960dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl      UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
189764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
18986d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis  explicit UnaryTypeTraitExpr(EmptyShell Empty)
18990dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl    : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
19003d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor      QueriedType() { }
19016d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
1902aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
190364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19040dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
190564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19063d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  QualType getQueriedType() const { return QueriedType->getType(); }
190764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19083d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1909ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19100dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl  bool getValue() const { return Value; }
191164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
191264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const Stmt *T) {
191364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return T->getStmtClass() == UnaryTypeTraitExprClass;
191464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
191564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  static bool classof(const UnaryTypeTraitExpr *) { return true; }
191664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
191764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // Iterators
191863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19196d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis
192060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
192164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl};
192264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
19236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
19246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates.
19256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example:
19266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true
19276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr {
19286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
19296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  unsigned BTT : 8;
19306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The value of the type trait. Unspecified if dependent.
19326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool Value : 1;
19336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// Loc - The location of the type trait keyword.
19356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation Loc;
19366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// RParen - The location of the closing paren.
19386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  SourceLocation RParen;
19396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The lhs type being queried.
19416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *LhsType;
19426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  /// The rhs type being queried.
19446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *RhsType;
19456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic:
1947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1948ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                     TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
19496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet                     bool value, SourceLocation rparen, QualType ty)
1950ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
19516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet           lhsType->getType()->isDependentType() ||
1952bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           rhsType->getType()->isDependentType(),
1953561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhsType->getType()->isInstantiationDependentType() ||
1954561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhsType->getType()->isInstantiationDependentType()),
1955bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhsType->getType()->containsUnexpandedParameterPack() ||
1956bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhsType->getType()->containsUnexpandedParameterPack())),
19576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      BTT(btt), Value(value), Loc(loc), RParen(rparen),
19586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet      LhsType(lhsType), RhsType(rhsType) { }
19596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  explicit BinaryTypeTraitExpr(EmptyShell Empty)
19626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1963f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet      LhsType(), RhsType() { }
19646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
1965aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
19666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return SourceRange(Loc, RParen);
19676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
19686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  BinaryTypeTrait getTrait() const {
19706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return static_cast<BinaryTypeTrait>(BTT);
19716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
19726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getLhsType() const { return LhsType->getType(); }
19746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  QualType getRhsType() const { return RhsType->getType(); }
19756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
19776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1978ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  bool getValue() const { assert(!isTypeDependent()); return Value; }
19806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const Stmt *T) {
19826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet    return T->getStmtClass() == BinaryTypeTraitExprClass;
19836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  }
19846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  static bool classof(const BinaryTypeTraitExpr *) { return true; }
19856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  // Iterators
198763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet  friend class ASTStmtReader;
19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet};
19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet
19924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and
19934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates.
19944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///
19954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code
19964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor///   __is_trivially_constructible(vector<int>, int*, int*)
19974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode
19984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr {
19994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief The location of the type trait keyword.
20004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation Loc;
20014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief  The location of the closing parenthesis.
20034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  SourceLocation RParenLoc;
20044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Note: The TypeSourceInfos for the arguments are allocated after the
20064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // TypeTraitExpr.
20074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
20094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                ArrayRef<TypeSourceInfo *> Args,
20104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                SourceLocation RParenLoc,
20114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                bool Value);
20124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
20144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo **getTypeSourceInfos() {
20174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo **>(this+1);
20184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo * const *getTypeSourceInfos() const {
20224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return reinterpret_cast<TypeSourceInfo * const*>(this+1);
20234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic:
20264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Create a new type trait expression.
20274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
20284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               TypeTrait Kind,
20294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               ArrayRef<TypeSourceInfo *> Args,
20304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               SourceLocation RParenLoc,
20314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor                               bool Value);
20324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
20344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine which type trait this expression uses.
20364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeTrait getTrait() const {
20374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
20384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  bool getValue() const {
20414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(!isValueDependent());
20424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return TypeTraitExprBits.Value;
20434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Determine the number of arguments to this type trait.
20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the Ith argument.
20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  TypeSourceInfo *getArg(unsigned I) const {
20504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    assert(I < getNumArgs() && "Argument out-of-range");
20514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getArgs()[I];
20524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  /// \brief Retrieve the argument types.
20554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  ArrayRef<TypeSourceInfo *> getArgs() const {
20564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
20574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo **arg_iterator;
20604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_begin() {
20614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos();
20624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_iterator arg_end() {
20644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
20654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  typedef TypeSourceInfo const * const *arg_const_iterator;
20684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
20694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  arg_const_iterator arg_end() const {
20704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return getTypeSourceInfos() + getNumArgs();
20714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
2073aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); }
20744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const Stmt *T) {
20764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor    return T->getStmtClass() == TypeTraitExprClass;
20774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  }
20784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  static bool classof(const TypeTraitExpr *) { return true; }
20794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  // Iterators
20814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  child_range children() { return child_range(); }
20824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtReader;
20844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor  friend class ASTStmtWriter;
20854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
20864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor};
20874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor
208821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
208921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// implementation of __array_rank and __array_extent.
209021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example:
209121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_rank(int[10][20]) == 2
209221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_extent(int, 1)    == 20
209321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr {
209499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
209599ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie
209621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
209721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  unsigned ATT : 2;
209821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
209921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The value of the type trait. Unspecified if dependent.
210021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t Value;
210121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
210221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The array dimension being queried, or -1 if not used
210321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *Dimension;
210421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
210521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// Loc - The location of the type trait keyword.
210621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation Loc;
210721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
210821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// RParen - The location of the closing paren.
210921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  SourceLocation RParen;
211021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
211121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  /// The type being queried.
211221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *QueriedType;
211321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
211421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic:
211521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
211621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     TypeSourceInfo *queried, uint64_t value,
211721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley                     Expr *dimension, SourceLocation rparen, QualType ty)
211821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
211921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           false, queried->getType()->isDependentType(),
2120561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (queried->getType()->isInstantiationDependentType() ||
2121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            (dimension && dimension->isInstantiationDependent())),
212221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley           queried->getType()->containsUnexpandedParameterPack()),
212321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      ATT(att), Value(value), Dimension(dimension),
212421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      Loc(loc), RParen(rparen), QueriedType(queried) { }
212521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
212621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
212721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  explicit ArrayTypeTraitExpr(EmptyShell Empty)
212821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
212921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley      QueriedType() { }
213021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
213125aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek  virtual ~ArrayTypeTraitExpr() { }
213225aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek
2133aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  virtual SourceRange getSourceRange() const LLVM_READONLY {
2134ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return SourceRange(Loc, RParen);
2135ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
213621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
213721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
213821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
213921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  QualType getQueriedType() const { return QueriedType->getType(); }
214021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
214121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
214221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
214321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
214421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
214521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  Expr *getDimensionExpression() const { return Dimension; }
214621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
214721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const Stmt *T) {
214821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley    return T->getStmtClass() == ArrayTypeTraitExprClass;
214921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  }
215021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  static bool classof(const ArrayTypeTraitExpr *) { return true; }
215121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
215221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  // Iterators
215321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  child_range children() { return child_range(); }
215421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
215521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley  friend class ASTStmtReader;
215621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley};
215721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley
2158552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// ExpressionTraitExpr - An expression trait intrinsic
2159552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example:
2160552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(std::cout) == true
2161552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(1) == false
2162552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr {
2163552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
2164552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  unsigned ET : 31;
2165552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// The value of the type trait. Unspecified if dependent.
2166552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool Value : 1;
2167552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2168552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// Loc - The location of the type trait keyword.
2169552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation Loc;
2170552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2171552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  /// RParen - The location of the closing paren.
2172552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  SourceLocation RParen;
2173552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2174552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr* QueriedExpression;
2175552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic:
2176ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2177552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     Expr *queried, bool value,
2178552622067dc45013d240f73952fece703f5e63bdJohn Wiegley                     SourceLocation rparen, QualType resultType)
2179552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2180552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           false, // Not type-dependent
2181552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           // Value-dependent if the argument is type-dependent.
2182552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->isTypeDependent(),
2183561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           queried->isInstantiationDependent(),
2184552622067dc45013d240f73952fece703f5e63bdJohn Wiegley           queried->containsUnexpandedParameterPack()),
2185ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      ET(et), Value(value), Loc(loc), RParen(rparen),
2186ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      QueriedExpression(queried) { }
2187552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2188552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  explicit ExpressionTraitExpr(EmptyShell Empty)
2189552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2190552622067dc45013d240f73952fece703f5e63bdJohn Wiegley      QueriedExpression() { }
2191552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2192aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
2193552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2194552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2195552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2196552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  Expr *getQueriedExpression() const { return QueriedExpression; }
2197552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2198552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  bool getValue() const { return Value; }
2199552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2200552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const Stmt *T) {
2201552622067dc45013d240f73952fece703f5e63bdJohn Wiegley    return T->getStmtClass() == ExpressionTraitExprClass;
2202552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  }
2203552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  static bool classof(const ExpressionTraitExpr *) { return true; }
2204552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2205552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  // Iterators
2206552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  child_range children() { return child_range(); }
2207552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2208552622067dc45013d240f73952fece703f5e63bdJohn Wiegley  friend class ASTStmtReader;
2209552622067dc45013d240f73952fece703f5e63bdJohn Wiegley};
2210552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
2211552622067dc45013d240f73952fece703f5e63bdJohn Wiegley
22127bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an
22137bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
22147bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr {
2215d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  /// The common name of these declarations.
2216d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  DeclarationNameInfo NameInfo;
2217d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2218d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  /// \brief The nested-name-specifier that qualifies the name, if any.
2219d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  NestedNameSpecifierLoc QualifierLoc;
2220d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer
2221ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// The results.  These are undesugared, which is to say, they may
22227bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// include UsingShadowDecls.  Access is relative to the naming
22237bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// class.
2224928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  // FIXME: Allocate this data after the OverloadExpr subclass.
2225928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  DeclAccessPair *Results;
2226928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned NumResults;
2227ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2228a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected:
2229e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2230e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2231e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2232e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2233e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2234e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2235e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2236e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2237e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2238e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2239e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
22407bb12da2b0749eeebb21854c77877736969e59f2John McCall
2241bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  OverloadExpr(StmtClass K, ASTContext &C,
22424c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor               NestedNameSpecifierLoc QualifierLoc,
2243e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara               SourceLocation TemplateKWLoc,
22442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara               const DeclarationNameInfo &NameInfo,
2245bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               const TemplateArgumentListInfo *TemplateArgs,
2246bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor               UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownDependent,
2248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownInstantiationDependent,
2249561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool KnownContainsUnexpandedParameterPack);
22507bb12da2b0749eeebb21854c77877736969e59f2John McCall
2251a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  OverloadExpr(StmtClass K, EmptyShell Empty)
2252d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer    : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2253d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer      HasTemplateKWAndArgsInfo(false) { }
2254a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
2255bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void initializeResults(ASTContext &C,
2256bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator Begin,
2257bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                         UnresolvedSetIterator End);
22587bb12da2b0749eeebb21854c77877736969e59f2John McCall
2259bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
22609c72c6088d591ace8503b842d39448c2040f3033John McCall  struct FindResult {
22619c72c6088d591ace8503b842d39448c2040f3033John McCall    OverloadExpr *Expression;
22629c72c6088d591ace8503b842d39448c2040f3033John McCall    bool IsAddressOfOperand;
22639c72c6088d591ace8503b842d39448c2040f3033John McCall    bool HasFormOfMemberPointer;
22649c72c6088d591ace8503b842d39448c2040f3033John McCall  };
22659c72c6088d591ace8503b842d39448c2040f3033John McCall
22667bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Finds the overloaded expression in the given expression of
22677bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// OverloadTy.
22687bb12da2b0749eeebb21854c77877736969e59f2John McCall  ///
22699c72c6088d591ace8503b842d39448c2040f3033John McCall  /// \return the expression (which must be there) and true if it has
22709c72c6088d591ace8503b842d39448c2040f3033John McCall  /// the particular form of a member pointer expression
22719c72c6088d591ace8503b842d39448c2040f3033John McCall  static FindResult find(Expr *E) {
22727bb12da2b0749eeebb21854c77877736969e59f2John McCall    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
22737bb12da2b0749eeebb21854c77877736969e59f2John McCall
22749c72c6088d591ace8503b842d39448c2040f3033John McCall    FindResult Result;
22759c72c6088d591ace8503b842d39448c2040f3033John McCall
22767bb12da2b0749eeebb21854c77877736969e59f2John McCall    E = E->IgnoreParens();
22779c72c6088d591ace8503b842d39448c2040f3033John McCall    if (isa<UnaryOperator>(E)) {
22789c72c6088d591ace8503b842d39448c2040f3033John McCall      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
22799c72c6088d591ace8503b842d39448c2040f3033John McCall      E = cast<UnaryOperator>(E)->getSubExpr();
22809c72c6088d591ace8503b842d39448c2040f3033John McCall      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
22819c72c6088d591ace8503b842d39448c2040f3033John McCall
22829c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
22839c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = true;
22849c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = Ovl;
22859c72c6088d591ace8503b842d39448c2040f3033John McCall    } else {
22869c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.HasFormOfMemberPointer = false;
22879c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.IsAddressOfOperand = false;
22889c72c6088d591ace8503b842d39448c2040f3033John McCall      Result.Expression = cast<OverloadExpr>(E);
22899c72c6088d591ace8503b842d39448c2040f3033John McCall    }
22909c72c6088d591ace8503b842d39448c2040f3033John McCall
22919c72c6088d591ace8503b842d39448c2040f3033John McCall    return Result;
22927bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
22937bb12da2b0749eeebb21854c77877736969e59f2John McCall
2294e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  /// Gets the naming class of this lookup, if any.
2295e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall  CXXRecordDecl *getNamingClass() const;
2296e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall
22977bb12da2b0749eeebb21854c77877736969e59f2John McCall  typedef UnresolvedSetImpl::iterator decls_iterator;
2298928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
2299ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  decls_iterator decls_end() const {
2300928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor    return UnresolvedSetIterator(Results + NumResults);
2301928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  }
2302ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
23037bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the number of declarations in the unresolved set.
2304928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor  unsigned getNumDecls() const { return NumResults; }
23057bb12da2b0749eeebb21854c77877736969e59f2John McCall
23062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Gets the full name info.
23072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
23082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
23097bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the name looked up.
23102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return NameInfo.getName(); }
23117bb12da2b0749eeebb21854c77877736969e59f2John McCall
23127bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Gets the location of the name.
23132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
23147bb12da2b0749eeebb21854c77877736969e59f2John McCall
23157bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// Fetches the nested-name qualifier, if one was given.
2316ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2317ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
23184c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  }
23197bb12da2b0749eeebb21854c77877736969e59f2John McCall
2320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Fetches the nested-name qualifier with source-location information, if
23214c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  /// one was given.
23224c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
23237bb12da2b0749eeebb21854c77877736969e59f2John McCall
2324e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2325e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2326e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2327e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2328e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2329e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2330e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2331e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2332e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2333e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2334e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2335e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2336e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2337e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2338e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2339e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2340e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2341e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2342e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2343e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
23447bb12da2b0749eeebb21854c77877736969e59f2John McCall
2345e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the name was preceded by the template keyword.
2346e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2347e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2348e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether this expression had explicit template arguments.
2349e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2350e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // Note that, inconsistently with the explicit-template-argument AST
2352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // nodes, users are *forbidden* from calling these methods on objects
2353e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // without explicit template arguments.
2354e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2355e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2356e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
2357e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
2358e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
23597bb12da2b0749eeebb21854c77877736969e59f2John McCall
2360b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
23617bb12da2b0749eeebb21854c77877736969e59f2John McCall    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
23627bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
23637bb12da2b0749eeebb21854c77877736969e59f2John McCall
2364e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  TemplateArgumentLoc const *getTemplateArgs() const {
2365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().getTemplateArgs();
2366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2367e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2368e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  unsigned getNumTemplateArgs() const {
2369e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getExplicitTemplateArgs().NumTemplateArgs;
2370e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Copies the template arguments into the given structure.
2373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    getExplicitTemplateArgs().copyInto(List);
2375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2377096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2378096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2379096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2380b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2381096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2382096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
23837bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
23847bb12da2b0749eeebb21854c77877736969e59f2John McCall
23857bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const Stmt *T) {
23867bb12da2b0749eeebb21854c77877736969e59f2John McCall    return T->getStmtClass() == UnresolvedLookupExprClass ||
23877bb12da2b0749eeebb21854c77877736969e59f2John McCall           T->getStmtClass() == UnresolvedMemberExprClass;
23887bb12da2b0749eeebb21854c77877736969e59f2John McCall  }
23897bb12da2b0749eeebb21854c77877736969e59f2John McCall  static bool classof(const OverloadExpr *) { return true; }
23904045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
23914045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
23924045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
23937bb12da2b0749eeebb21854c77877736969e59f2John McCall};
23947bb12da2b0749eeebb21854c77877736969e59f2John McCall
23957bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during
23967bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration.  This
23977bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways:
23987bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * we might be waiting for argument-dependent lookup
23997bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the name might resolve to an overloaded function
24007bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually:
24017bb12da2b0749eeebb21854c77877736969e59f2John McCall///   * the lookup might have included a function template
24027bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always
24037bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in
24047bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs.
24057bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr {
2406ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if these lookup results should be extended by
2407ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup if this is the operand of a function
2408ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// call.
2409ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool RequiresADL;
2410ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2411ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// True if namespace ::std should be considered an associated namespace
2412ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
2413ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool StdIsAssociatedNamespace;
2414ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
24157453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if these lookup results are overloaded.  This is pretty
24167453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// trivially rederivable if we urgently need to kill this field.
24177453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool Overloaded;
24187453ed4cb2cab113de3378df371b1c6f1243d832John McCall
24197bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// The naming class (C++ [class.access.base]p5) of the lookup, if
24207bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// any.  This can generally be recalculated from the context chain,
24217bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// but that can be fairly expensive for unqualified lookups.  If we
24227bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// want to improve memory use here, this could go in a union
24237bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// against the qualified-lookup bits.
24247bb12da2b0749eeebb21854c77877736969e59f2John McCall  CXXRecordDecl *NamingClass;
2425f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2426ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  UnresolvedLookupExpr(ASTContext &C,
2427928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor                       CXXRecordDecl *NamingClass,
24284c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
2429e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
24302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &NameInfo,
2431ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                       bool RequiresADL, bool Overloaded,
2432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
2433ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2434ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                       bool StdIsAssociatedNamespace)
2435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2436e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                   NameInfo, TemplateArgs, Begin, End, false, false, false),
2437ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(RequiresADL),
2438ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      StdIsAssociatedNamespace(StdIsAssociatedNamespace),
2439ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      Overloaded(Overloaded), NamingClass(NamingClass)
2440ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  {}
2441ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2442bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  UnresolvedLookupExpr(EmptyShell Empty)
2443bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis    : OverloadExpr(UnresolvedLookupExprClass, Empty),
2444ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
2445ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith      NamingClass(0)
2446bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  {}
2447bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
24484c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
2449ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2450ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic:
2451ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2452c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
24534c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
24542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
24555a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      bool ADL, bool Overloaded,
2456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
2457ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      UnresolvedSetIterator End,
2458ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                      bool StdIsAssociatedNamespace = false) {
2459ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    assert((ADL || !StdIsAssociatedNamespace) &&
2460ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith           "std considered associated namespace when not performing ADL");
2461e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2462e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                       SourceLocation(), NameInfo,
2463ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       ADL, Overloaded, 0, Begin, End,
2464ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith                                       StdIsAssociatedNamespace);
2465ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2466ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2467f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static UnresolvedLookupExpr *Create(ASTContext &C,
2468c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall                                      CXXRecordDecl *NamingClass,
24694c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                                      NestedNameSpecifierLoc QualifierLoc,
2470e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                      SourceLocation TemplateKWLoc,
24712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                      const DeclarationNameInfo &NameInfo,
2472f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall                                      bool ADL,
24739d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara                                      const TemplateArgumentListInfo *Args,
2474ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                                      UnresolvedSetIterator Begin,
24755a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                                      UnresolvedSetIterator End);
2476f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2477bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2478e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           bool HasTemplateKWAndArgsInfo,
2479bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis                                           unsigned NumTemplateArgs);
2480bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis
2481ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// True if this declaration should be extended by
2482ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  /// argument-dependent lookup.
2483ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  bool requiresADL() const { return RequiresADL; }
2484ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2485ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// True if namespace ::std should be artificially added to the set of
2486ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  /// associated namespaecs for argument-dependent lookup purposes.
2487ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
2488ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
24897453ed4cb2cab113de3378df371b1c6f1243d832John McCall  /// True if this lookup is overloaded.
24907453ed4cb2cab113de3378df371b1c6f1243d832John McCall  bool isOverloaded() const { return Overloaded; }
24917453ed4cb2cab113de3378df371b1c6f1243d832John McCall
2492c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// Gets the 'naming class' (in the sense of C++0x
2493c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// [class.access.base]p5) of the lookup.  This is the scope
2494c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// that was looked in to find these results.
2495c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const { return NamingClass; }
2496c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
2497aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
24982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range(getNameInfo().getSourceRange());
2499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (getQualifierLoc())
25004c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
2501ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    if (hasExplicitTemplateArgs())
25024c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setEnd(getRAngleLoc());
2503f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
2504ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2505ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
250663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
2507ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
2508ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const Stmt *T) {
2509ba13543329afac4a0d01304ec2ec4924d99306a6John McCall    return T->getStmtClass() == UnresolvedLookupExprClass;
2510ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  }
2511ba13543329afac4a0d01304ec2ec4924d99306a6John McCall  static bool classof(const UnresolvedLookupExpr *) { return true; }
2512ba13543329afac4a0d01304ec2ec4924d99306a6John McCall};
2513ba13543329afac4a0d01304ec2ec4924d99306a6John McCall
25145953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot
25155953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved.
25165953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor///
2517ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as
25195953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an
2520865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when
25215953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In
25225953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the
25235953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the
2524865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2525ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced
2526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found.
2528865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr {
2529ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested-name-specifier that qualifies this unresolved
2530ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration name.
253100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc QualifierLoc;
2532ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
253300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// The name of the entity we will be referencing.
253400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  DeclarationNameInfo NameInfo;
25355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
2536e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether the name includes info for explicit template
2537e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2538e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo;
2539e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2540e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2541e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2542e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2543e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2544e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2545e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2546e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2547e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<DependentScopeDeclRefExpr*>(this)
2548e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2549e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
25501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2551f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  DependentScopeDeclRefExpr(QualType T,
255200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
2553e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                            SourceLocation TemplateKWLoc,
25542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            const DeclarationNameInfo &NameInfo,
2555bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                            const TemplateArgumentListInfo *Args);
2556f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
2557f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic:
2558f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static DependentScopeDeclRefExpr *Create(ASTContext &C,
255900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor                                           NestedNameSpecifierLoc QualifierLoc,
2560e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                           SourceLocation TemplateKWLoc,
25612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                                           const DeclarationNameInfo &NameInfo,
2562e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                              const TemplateArgumentListInfo *TemplateArgs);
25635953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
256412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2565e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                bool HasTemplateKWAndArgsInfo,
256612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis                                                unsigned NumTemplateArgs);
256712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
25685953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the name that this expression refers to.
25692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
25702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
25712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name that this expression refers to.
25722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getDeclName() const { return NameInfo.getName(); }
25735953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
25745953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor  /// \brief Retrieve the location of the name within the expression.
25752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLocation() const { return NameInfo.getLoc(); }
25765953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor
257700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the
257800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  /// name, with source location information.
257900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2581ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2582ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies this
2583ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// declaration.
2584ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2585ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
258600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor  }
25871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2588e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2589e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
2590e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2591e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2592e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2593e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2594e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2595e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2596e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2597e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2598e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2599e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2600e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2601e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2602e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2603e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
2604e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2605e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2606e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2607e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2608e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2609e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the name was preceded by the template keyword.
2610e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2611e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2612f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Determines whether this lookup had explicit template arguments.
2613e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
26141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2615f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // Note that, inconsistently with the explicit-template-argument AST
2616f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // nodes, users are *forbidden* from calling these methods on objects
2617f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  // without explicit template arguments.
26181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2619b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
262012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis    assert(hasExplicitTemplateArgs());
2621b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
262212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis  }
262312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis
2624f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// Gets a reference to the explicit template argument list.
2625b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2626f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    assert(hasExplicitTemplateArgs());
2627b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2628f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
26291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2630096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2631096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2632096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2633b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2634096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2635096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2636096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2637096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2638f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// \brief Copies the template arguments (if present) into the given
2639f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  /// structure.
2640f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2641f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    getExplicitTemplateArgs().copyInto(List);
2642f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
2643ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2644f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  TemplateArgumentLoc const *getTemplateArgs() const {
2645f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2646d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2647d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2648f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  unsigned getNumTemplateArgs() const {
2649f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2650f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  }
26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2652aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
265300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor    SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2654f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    if (hasExplicitTemplateArgs())
2655f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall      Range.setEnd(getRAngleLoc());
2656f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return Range;
2657edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
26581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2660f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall    return T->getStmtClass() == DependentScopeDeclRefExprClass;
2661edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor  }
2662f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2663f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall
266463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
26654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
26664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
26674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
2668edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor};
26691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26704765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which
26714765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's
26724765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation.  The most common source of expression-introduced
267380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of
267480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every
267580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer.
267680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall///
267780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a
267880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal.  The lifetime of a block
267980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope.
26804765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr {
268180ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic:
268280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// The type of objects that are kept in the cleanup.
268380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// It's useful to remember the set of blocks;  we could also
268480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// remember the set of temporaries, but there's currently
268580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// no need.
268680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  typedef BlockDecl *CleanupObject;
268780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
268880ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate:
268902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Stmt *SubExpr;
26901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
269180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(EmptyShell, unsigned NumObjects);
269280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
269302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
269480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject *getObjectsBuffer() {
269580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<CleanupObject*>(this + 1);
269680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
269780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  const CleanupObject *getObjectsBuffer() const {
269880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return reinterpret_cast<const CleanupObject*>(this + 1);
269980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  }
270080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  friend class ASTStmtReader;
2701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
270288eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic:
270380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
270480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  unsigned numObjects);
27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
270680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
270780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall                                  ArrayRef<CleanupObject> objects);
2708ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
270980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  ArrayRef<CleanupObject> getObjects() const {
271080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2711f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  }
271280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
271380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
271480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
271580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  CleanupObject getObject(unsigned i) const {
271680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    assert(i < getNumObjects() && "Index out of range");
271780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall    return getObjects()[i];
2718d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  }
27191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
272002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
2721f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
272280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall
272380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// setSubExpr - As with any mutator of the AST, be very careful
272480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall  /// when modifying an existing AST to preserve its invariants.
272588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson  void setSubExpr(Expr *E) { SubExpr = E; }
272602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2727aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
272896be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor    return SubExpr->getSourceRange();
272996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor  }
273002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
273102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Implement isa/cast/dyncast/etc.
273202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  static bool classof(const Stmt *T) {
27334765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall    return T->getStmtClass() == ExprWithCleanupsClass;
273402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  }
27354765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall  static bool classof(const ExprWithCleanups *) { return true; }
273602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
273702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson  // Iterators
273863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
273902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson};
274002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson
2741d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional
2742d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are
2743d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent.
2744d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2745d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by
2746d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2747d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and
2748d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is
2749d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such
2750d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as:
2751d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2752d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code
2753d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   template<typename T, typename A1>
2754d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   inline T make_a(const A1& a1) {
2755d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///     return T(a1);
2756d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///   }
2757d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode
2758d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor///
2759d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a
2760d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type
2761d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion.
2762d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr {
2763d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The type being constructed.
2764ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *Type;
2765ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2766d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the left parentheses ('(').
2767d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation LParenLoc;
2768d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2769d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The location of the right parentheses (')').
2770d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation RParenLoc;
2771d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2772d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief The number of arguments used to construct the type.
2773d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned NumArgs;
27741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2775ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2776d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation LParenLoc,
2777d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             Expr **Args,
2778d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             unsigned NumArgs,
2779d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                             SourceLocation RParenLoc);
2780d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
27818dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2782ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
27838dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2784ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  friend class ASTStmtReader;
2785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2786d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic:
27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2788ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor                                            TypeSourceInfo *Type,
2789d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation LParenLoc,
2790d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            Expr **Args,
2791d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            unsigned NumArgs,
2792d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor                                            SourceLocation RParenLoc);
2793d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
27948dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
27958dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis                                                 unsigned NumArgs);
27968dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2797d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the type that is being constructed, as specified
2798d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// in the source code.
2799ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  QualType getTypeAsWritten() const { return Type->getType(); }
2800d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the type source information for the type being
2802ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  /// constructed.
2803ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2805d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the left parentheses ('(') that
2806d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// precedes the argument list.
2807d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
2808d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2809d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2810d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the location of the right parentheses (')') that
2811d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// follows the argument list.
2812d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2813d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2814d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2815d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  /// \brief Retrieve the number of arguments.
2816d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  unsigned arg_size() const { return NumArgs; }
2817d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2818d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  typedef Expr** arg_iterator;
2819d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
2820d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  arg_iterator arg_end() { return arg_begin() + NumArgs; }
2821d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28221dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  typedef const Expr* const * const_arg_iterator;
28231dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_begin() const {
28241dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return reinterpret_cast<const Expr* const *>(this + 1);
28251dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28261dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const_arg_iterator arg_end() const {
28271dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return arg_begin() + NumArgs;
28281dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28291dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
2830d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  Expr *getArg(unsigned I) {
2831d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    assert(I < NumArgs && "Argument index out-of-range");
2832d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return *(arg_begin() + I);
2833d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2834d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
28351dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  const Expr *getArg(unsigned I) const {
28361dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    assert(I < NumArgs && "Argument index out-of-range");
28371dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall    return *(arg_begin() + I);
28381dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall  }
28391dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall
28408dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void setArg(unsigned I, Expr *E) {
28418dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    assert(I < NumArgs && "Argument index out-of-range");
28428dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    *(arg_begin() + I) = E;
28438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
28448dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2845aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
2846ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
2848d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2849d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  }
2850d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2851d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2852d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor  // Iterators
285363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
285463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this+1);
285563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumArgs);
285663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
2857d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor};
2858d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor
2859ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual
2860ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base
2861ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent.
2862aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
2863aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or
2864aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses.  It is only possible to get one of these with
2865aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided.
2866865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr {
28671c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The expression for the base pointer or class reference,
2868aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
28691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  Stmt *Base;
28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2871aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief The type of the base expression.  Never null, even for
2872aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// implicit accesses.
2873aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType BaseType;
2874aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
28751c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Whether this member expression used the '->' operator or
28761c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// the '.' operator.
28773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  bool IsArrow : 1;
28781c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2879e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Whether this member expression has info for explicit template
2880e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// keyword and arguments.
2881e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo : 1;
28821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28831c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The location of the '->' or '.' operator.
28841c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation OperatorLoc;
28851c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2886a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief The nested-name-specifier that precedes the member name, if any.
28877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc QualifierLoc;
28881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2889c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief In a qualified member access expression such as t->Base::f, this
28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member stores the resolves of name lookup in the context of the member
2891c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// access expression, to be used at instantiation time.
2892c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
289346bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor  /// FIXME: This member, along with the QualifierLoc, could
2894c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// be stuck into a structure that is optionally allocated at the end of
2895865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2896c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  NamedDecl *FirstQualifierFoundInScope;
28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief The member to which this member expression refers, which
28991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// can be name, overloaded operator, or destructor.
2900a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// FIXME: could also be a template-id
29012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo MemberNameInfo;
29021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2903e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2904e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2905e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return 0;
2906e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2907e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2908e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2909e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2910e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<CXXDependentScopeMemberExpr*>(this)
2911e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      ->getTemplateKWAndArgsInfo();
2912e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2913e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2914865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2915aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                          Expr *Base, QualType BaseType, bool IsArrow,
29163b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          SourceLocation OperatorLoc,
29177c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                          NestedNameSpecifierLoc QualifierLoc,
2918e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                          SourceLocation TemplateKWLoc,
29193b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor                          NamedDecl *FirstQualifierFoundInScope,
29202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                          DeclarationNameInfo MemberNameInfo,
2921d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          const TemplateArgumentListInfo *TemplateArgs);
29221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29231c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic:
2924865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  CXXDependentScopeMemberExpr(ASTContext &C,
2925bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              Expr *Base, QualType BaseType,
2926bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              bool IsArrow,
2927bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              SourceLocation OperatorLoc,
29287c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor                              NestedNameSpecifierLoc QualifierLoc,
2929bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              NamedDecl *FirstQualifierFoundInScope,
2930bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                              DeclarationNameInfo MemberNameInfo);
29311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2932865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static CXXDependentScopeMemberExpr *
29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Create(ASTContext &C,
2934aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
29353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         SourceLocation OperatorLoc,
29367c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
2937e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
29383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor         NamedDecl *FirstQualifierFoundInScope,
29392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         DeclarationNameInfo MemberNameInfo,
2940d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         const TemplateArgumentListInfo *TemplateArgs);
29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29428dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  static CXXDependentScopeMemberExpr *
2943e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2944def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
29458dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
2946aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
2947aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
2948aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
29494c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
2950aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29511c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the base object of this member expressions,
29521c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// e.g., the \c x in \c x.m.
2953aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() const {
2954aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
2955aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
2956aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
29571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2958aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
2959aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
29601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Determine whether this member expression used the '->'
29611c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// operator; otherwise, it used the '.' operator.
29621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  bool isArrow() const { return IsArrow; }
29631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
29641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the location of the '->' or '.' operator.
29651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
29661c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
2967a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
2968a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor  /// name.
2969ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  NestedNameSpecifier *getQualifier() const {
2970ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return QualifierLoc.getNestedNameSpecifier();
29717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  }
29721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// \brief Retrieve the nested-name-specifier that qualifies the member
29747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  /// name, with source location information.
29757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2976ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2977ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2978c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// \brief Retrieve the first part of the nested-name-specifier that was
2979c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// found in the scope of the member access expression when the member access
2980c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// was initially parsed.
2981c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  ///
2982c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// This function only returns a useful result when member access expression
29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
29841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// returned by this function describes what was found by unqualified name
2985c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// lookup for the identifier "Base" within the scope of the member access
2986c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself. At template instantiation time, this information is
2987c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// combined with the results of name lookup into the type of the object
2988c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  /// expression itself (the class type of x).
29891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFirstQualifierFoundInScope() const {
2990c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor    return FirstQualifierFoundInScope;
2991c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor  }
29921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29931c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// \brief Retrieve the name of the member that this expression
29941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  /// refers to.
29952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const {
29962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return MemberNameInfo;
29972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
29982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
29992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the name of the member that this expression
30002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
30012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getMember() const { return MemberNameInfo.getName(); }
30021c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
30031c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // \brief Retrieve the location of the name of the member that this
30041c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // expression refers to.
30052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
30061c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3007e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding the
3008e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// member name, if any.
3009e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
3010e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3011e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3012e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3013e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3014e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
3015e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3016e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
3017e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3018e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
3019e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3020e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3021e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
3022e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
3023e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
3024e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3025e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
3026e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
3027e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
3028e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the member name was preceded by the template keyword.
3029e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3030e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
30313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
30323b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
3033e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
30341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
303536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
303636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3037b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3038e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
3039b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis    return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
304036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
304136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
304236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
304336c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  /// member template name, if any.
3044b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
304536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis    return const_cast<CXXDependentScopeMemberExpr *>(this)
3046096832c5ed5b9106fa177ebc148489760c3bc496John McCall             ->getExplicitTemplateArgs();
3047096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
3048096832c5ed5b9106fa177ebc148489760c3bc496John McCall
3049096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
3050096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
3051096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
3052b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
3053096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
3054096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
305536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis  }
305636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis
3057d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
3058d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
3059d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3060096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().copyInto(List);
3061d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
3062d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
30638dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  /// \brief Initializes the template arguments using the given structure.
30648dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3065096832c5ed5b9106fa177ebc148489760c3bc496John McCall    getExplicitTemplateArgs().initializeFrom(List);
30668dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  }
30678dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis
30683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
30693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
3070833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
3071096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
30723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
30731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
30753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  /// template-id.
30761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
3077096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
30783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor  }
30791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3080aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3081aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    SourceRange Range;
3082aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
3083aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
3084aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else if (getQualifier())
30857c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
3086aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
30872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setBegin(MemberNameInfo.getBeginLoc());
30881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3089aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (hasExplicitTemplateArgs())
3090aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setEnd(getRAngleLoc());
3091aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    else
30922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Range.setEnd(MemberNameInfo.getEndLoc());
3093aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return Range;
30941c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3097865d447ac6a4721ab58e898d014a21f2eff74b06John McCall    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
30981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  }
3099865d447ac6a4721ab58e898d014a21f2eff74b06John McCall  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
31001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
31011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor  // Iterators
310263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
310363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
310463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
310563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
31064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
31074045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtReader;
31084045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
31091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor};
31101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor
3111129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup
3112aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions.
3113aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3114aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit:
3115aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    struct A {
3116aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int a, b;
3117aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int explicitAccess() { return this->a + this->A::b; }
3118aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///      int implicitAccess() { return a + A::b; }
3119aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///    };
3120aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall///
3121aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr.
3122aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a
3123aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static.
31247bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr {
3125129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether this member expression used the '->' operator or
3126129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// the '.' operator.
3127129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool IsArrow : 1;
3128129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3129129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Whether the lookup results contain an unresolved using
3130129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// declaration.
3131129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool HasUnresolvedUsing : 1;
3132129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
31337bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The expression for the base pointer or class reference,
31347bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
31357bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// member expression
31367bb12da2b0749eeebb21854c77877736969e59f2John McCall  Stmt *Base;
31377bb12da2b0749eeebb21854c77877736969e59f2John McCall
31387bb12da2b0749eeebb21854c77877736969e59f2John McCall  /// \brief The type of the base expression;  never null.
31397bb12da2b0749eeebb21854c77877736969e59f2John McCall  QualType BaseType;
3140129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3141129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief The location of the '->' or '.' operator.
3142129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation OperatorLoc;
3143129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3144bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3145aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall                       Expr *Base, QualType BaseType, bool IsArrow,
3146129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall                       SourceLocation OperatorLoc,
31474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor                       NestedNameSpecifierLoc QualifierLoc,
3148e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                       SourceLocation TemplateKWLoc,
31492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       const DeclarationNameInfo &MemberNameInfo,
31505a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       const TemplateArgumentListInfo *TemplateArgs,
31515a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3153a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  UnresolvedMemberExpr(EmptyShell Empty)
3154a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3155a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis      HasUnresolvedUsing(false), Base(0) { }
3156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
31574c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  friend class ASTStmtReader;
3158ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3159129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic:
3160129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static UnresolvedMemberExpr *
3161bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  Create(ASTContext &C, bool HasUnresolvedUsing,
3162aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall         Expr *Base, QualType BaseType, bool IsArrow,
3163129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall         SourceLocation OperatorLoc,
31644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor         NestedNameSpecifierLoc QualifierLoc,
3165e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara         SourceLocation TemplateKWLoc,
31662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara         const DeclarationNameInfo &MemberNameInfo,
31675a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         const TemplateArgumentListInfo *TemplateArgs,
31685a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3169129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3170a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  static UnresolvedMemberExpr *
3171e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3172def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor              unsigned NumTemplateArgs);
3173a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3174aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// \brief True if this is an implicit access, i.e. one in which the
3175aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// member being accessed was not written in the source.  The source
3176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  /// location of the operator is invalid in this case.
31774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor  bool isImplicitAccess() const;
3178aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3179129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the base object of this member expressions,
3180129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// e.g., the \c x in \c x.m.
3181aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  Expr *getBase() {
3182aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    assert(!isImplicitAccess());
3183aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    return cast<Expr>(Base);
3184aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  }
31852f27bf854f0519810b34afd209089cc75536b757John McCall  const Expr *getBase() const {
31862f27bf854f0519810b34afd209089cc75536b757John McCall    assert(!isImplicitAccess());
31872f27bf854f0519810b34afd209089cc75536b757John McCall    return cast<Expr>(Base);
31882f27bf854f0519810b34afd209089cc75536b757John McCall  }
3189129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3190aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall  QualType getBaseType() const { return BaseType; }
3191a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis
3192a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// \brief Determine whether the lookup results contain an unresolved using
3193a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  /// declaration.
3194a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3195aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3196129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Determine whether this member expression used the '->'
3197129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// operator; otherwise, it used the '.' operator.
3198129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  bool isArrow() const { return IsArrow; }
3199129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the location of the '->' or '.' operator.
3201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3202129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3203c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  /// \brief Retrieves the naming class of this lookup.
3204c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall  CXXRecordDecl *getNamingClass() const;
3205c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall
32062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the full name info for the member that this expression
32072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// refers to.
32082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
32092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
3210129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// \brief Retrieve the name of the member that this expression
3211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  /// refers to.
32127bb12da2b0749eeebb21854c77877736969e59f2John McCall  DeclarationName getMemberName() const { return getName(); }
3213129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3214129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // \brief Retrieve the location of the name of the member that this
3215129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // expression refers to.
32167bb12da2b0749eeebb21854c77877736969e59f2John McCall  SourceLocation getMemberLoc() const { return getNameLoc(); }
3217129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3218aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
32192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    SourceRange Range = getMemberNameInfo().getSourceRange();
3220aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall    if (!isImplicitAccess())
3221aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall      Range.setBegin(Base->getSourceRange().getBegin());
32224c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor    else if (getQualifierLoc())
32234c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor      Range.setBegin(getQualifierLoc().getBeginLoc());
3224aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall
3225129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    if (hasExplicitTemplateArgs())
3226129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall      Range.setEnd(getRAngleLoc());
3227129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return Range;
3228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3230129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const Stmt *T) {
3231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall    return T->getStmtClass() == UnresolvedMemberExprClass;
3232129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  }
3233129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  static bool classof(const UnresolvedMemberExpr *) { return true; }
3234129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
3235129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall  // Iterators
323663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
323763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (isImplicitAccess()) return child_range();
323863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Base, &Base + 1);
323963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3240129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall};
3241129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall
32422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
32432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl///
32442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its
32452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant.
32462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr {
32472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool Value : 1;
32482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Stmt *Operand;
32492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  SourceRange Range;
32502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3251c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl  friend class ASTStmtReader;
3252c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl
32532e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic:
32542e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
32552e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl                  SourceLocation Keyword, SourceLocation RParen)
3256f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3257f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           /*TypeDependent*/false,
3258bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ValueDependent*/Val == CT_Dependent,
3259561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Val == CT_Dependent || Operand->isInstantiationDependent(),
3260bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           Operand->containsUnexpandedParameterPack()),
32616b219d082434394c1ac401390ec1d1967727815aSebastian Redl      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
32626b219d082434394c1ac401390ec1d1967727815aSebastian Redl  { }
32636b219d082434394c1ac401390ec1d1967727815aSebastian Redl
32646b219d082434394c1ac401390ec1d1967727815aSebastian Redl  CXXNoexceptExpr(EmptyShell Empty)
32656b219d082434394c1ac401390ec1d1967727815aSebastian Redl    : Expr(CXXNoexceptExprClass, Empty)
32662e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  { }
32672e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
32682e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
32692e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3270aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
32712e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
32722e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  bool getValue() const { return Value; }
32732e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
32742e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const Stmt *T) {
32752e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl    return T->getStmtClass() == CXXNoexceptExprClass;
32762e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  }
32772e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  static bool classof(const CXXNoexceptExpr *) { return true; }
32782e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
32792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl  // Iterators
328063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Operand, &Operand + 1); }
32812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl};
32822e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl
3283ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of
3284be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions.
3285be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3286be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an
3287be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example:
3288be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3289be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code
3290be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types>
3291be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) {
3292be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///   f(static_cast<Types&&>(args)...);
3293be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// }
3294be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode
3295be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor///
3296be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose
3297ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function
3298be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or
3299be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f.
3300be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr {
3301be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation EllipsisLoc;
3302ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
330367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// \brief The number of expansions that will be produced by this pack
330467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// expansion expression, if known.
330567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  ///
330667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// When zero, the number of expansions is not known. Otherwise, this value
330767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// is the number of expansions + 1.
330867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  unsigned NumExpansions;
3309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3310be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Stmt *Pattern;
3311ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3312be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  friend class ASTStmtReader;
331367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  friend class ASTStmtWriter;
3314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3315be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic:
331667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
331767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor                    llvm::Optional<unsigned> NumExpansions)
3318ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3319ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           Pattern->getObjectKind(), /*TypeDependent=*/true,
3320561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3321561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3322be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      EllipsisLoc(EllipsisLoc),
332367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3324be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor      Pattern(Pattern) { }
3325be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3326be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3327ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3328be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3329be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3330be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3331be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the pattern of the pack expansion.
3332be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3333be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3334be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// \brief Retrieve the location of the ellipsis that describes this pack
3335be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  /// expansion.
3336be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3338ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine the number of expansions that will be produced when
333967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  /// this pack expansion is instantiated, if already known.
334067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
334167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    if (NumExpansions)
334267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor      return NumExpansions - 1;
3343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
334467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor    return llvm::Optional<unsigned>();
334567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor  }
3346ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3347aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
334863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(Pattern->getLocStart(), EllipsisLoc);
334963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3350be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor
3351be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const Stmt *T) {
3352be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor    return T->getStmtClass() == PackExpansionExprClass;
3353be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  }
3354be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  static bool classof(const PackExpansionExpr *) { return true; }
3355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3356be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  // Iterators
335763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
335863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Pattern, &Pattern + 1);
335963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3360be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor};
3361ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3362e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3363e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  if (!HasTemplateKWAndArgsInfo) return 0;
33647bb12da2b0749eeebb21854c77877736969e59f2John McCall  if (isa<UnresolvedLookupExpr>(this))
3365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedLookupExpr>(this) + 1);
33677bb12da2b0749eeebb21854c77877736969e59f2John McCall  else
3368e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3369e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      (cast<UnresolvedMemberExpr>(this) + 1);
33707bb12da2b0749eeebb21854c77877736969e59f2John McCall}
33717bb12da2b0749eeebb21854c77877736969e59f2John McCall
3372ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter
3373ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack.
3374ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///
3375ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code
3376ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types>
3377ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count {
3378ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor///   static const unsigned value = sizeof...(Types);
3379ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// };
3380ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode
3381ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr {
3382ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the 'sizeof' keyword.
3383ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation OperatorLoc;
3384ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3385ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the name of the parameter pack.
3386ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation PackLoc;
3387ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3388ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The location of the closing parenthesis.
3389ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation RParenLoc;
3390ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3391ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The length of the parameter pack, if known.
3392ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3393ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// When this expression is value-dependent, the length of the parameter pack
3394ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// is unknown. When this expression is not value-dependent, the length is
3395ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// known.
3396ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned Length;
3397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3398ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief The parameter pack itself.
3399ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *Pack;
3400ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3401ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtReader;
3402ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  friend class ASTStmtWriter;
3403ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3404ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic:
3405ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates a value-dependent expression that computes the length of
3406ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack.
3407ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3408ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc)
3409ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3410ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*TypeDependent=*/false, /*ValueDependent=*/true,
3411561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3412ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3413ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3414ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor      Length(0), Pack(Pack) { }
3415ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3416ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Creates an expression that computes the length of
3417ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// the given parameter pack, which is already known.
3418ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3419ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 SourceLocation PackLoc, SourceLocation RParenLoc,
3420ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor                 unsigned Length)
3421ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3422ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*TypeDependent=*/false, /*ValueDependent=*/false,
3423561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         /*InstantiationDependent=*/false,
3424ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor         /*ContainsUnexpandedParameterPack=*/false),
3425ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3426ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    Length(Length), Pack(Pack) { }
3427ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3428ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Create an empty expression.
3429ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3430ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3431ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the 'sizeof' keyword.
3432ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
3433ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor
3434ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the parameter pack.
3435ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getPackLoc() const { return PackLoc; }
3436ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3437ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Determine the location of the right parenthesis.
3438ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3440ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the parameter pack.
3441ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  NamedDecl *getPack() const { return Pack; }
3442ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3443ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  /// \brief Retrieve the length of the parameter pack.
3444ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  ///
3445ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This routine may only be invoked when the expression is not
3446c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// value-dependent.
3447ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  unsigned getPackLength() const {
3448ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    assert(!isValueDependent() &&
3449ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor           "Cannot get the length of a value-dependent pack size expression");
3450ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return Length;
3451ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3453aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
345463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return SourceRange(OperatorLoc, RParenLoc);
345563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3457ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const Stmt *T) {
3458ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor    return T->getStmtClass() == SizeOfPackExprClass;
3459ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  }
3460ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  static bool classof(const SizeOfPackExpr *) { return true; }
3461ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3462ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  // Iterators
346363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3464ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor};
3465c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
346691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter
346791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument.
346891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr {
346991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replaced parameter.
347091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *Param;
347191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
347291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The replacement expression.
347391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Stmt *Replacement;
347491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
347591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// \brief The location of the non-type template parameter reference.
347691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation NameLoc;
347791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
34787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
34797110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTStmtReader;
3480ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
34817110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
34827110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall
348391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic:
3484ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmExpr(QualType type,
348591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               ExprValueKind valueKind,
348691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               SourceLocation loc,
348791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               NonTypeTemplateParmDecl *param,
348891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall                               Expr *replacement)
348991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
349091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isTypeDependent(), replacement->isValueDependent(),
349191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->isInstantiationDependent(),
349291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall           replacement->containsUnexpandedParameterPack()),
349391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall      Param(param), Replacement(replacement), NameLoc(loc) {}
349491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
349591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  SourceLocation getNameLoc() const { return NameLoc; }
3496aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
349791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
349891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Expr *getReplacement() const { return cast<Expr>(Replacement); }
3499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
350091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  NonTypeTemplateParmDecl *getParameter() const { return Param; }
350191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
350291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  static bool classof(const Stmt *s) {
350391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
350491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3505ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const SubstNonTypeTemplateParmExpr *) {
3506ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
350791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
3508ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
350991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  // Iterators
351091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  child_range children() { return child_range(&Replacement, &Replacement+1); }
351191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall};
351291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
3513c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that
3514c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack.
3515c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor///
3516c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3517c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template
3518ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this node node is used to represent a non-type template
3519c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3520c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3521c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3522c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3523c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying
3524c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index.
3525c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr {
3526c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The non-type template parameter pack itself.
3527c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *Param;
3528ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3529c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3530c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// parameter pack is instantiated with.
3531c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  const TemplateArgument *Arguments;
3532ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3533c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3534c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  unsigned NumArguments;
3535ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3536c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief The location of the non-type template parameter pack reference.
3537c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation NameLoc;
3538ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
35397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall  friend class ASTReader;
3540c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  friend class ASTStmtReader;
3541ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
35427110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall    : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3544c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic:
3545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstNonTypeTemplateParmPackExpr(QualType T,
3546c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   NonTypeTemplateParmDecl *Param,
3547c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   SourceLocation NameLoc,
3548c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor                                   const TemplateArgument &ArgPack);
3549ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3550c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the non-type template parameter pack being substituted.
3551c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3552c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3553c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the location of the parameter pack name.
3554c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  SourceLocation getParameterPackLocation() const { return NameLoc; }
3555ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3556c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// \brief Retrieve the template argument pack containing the substituted
3557c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  /// template arguments.
3558c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  TemplateArgument getArgumentPack() const;
3559c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor
3560aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3561ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3562c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  static bool classof(const Stmt *T) {
3563c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor    return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3564c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3565ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
3567c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  }
3568ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3569c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  // Iterators
357063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
3571c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor};
357203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor
357303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that
357403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it.
357503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
357603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address
357703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a
357803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g.,
357903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
358003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code
358103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0;
358203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode
358303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor///
358403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
358503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference
358603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
358703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding
358803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues.
358903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr {
359003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief The temporary-generating expression whose value will be
359103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// materialized.
3592d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer  Stmt *Temporary;
3593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
359403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtReader;
359503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  friend class ASTStmtWriter;
3596ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
359703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic:
3598ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3599b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor                           bool BoundToLvalueReference)
3600b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor    : Expr(MaterializeTemporaryExprClass, T,
360103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
360203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->isTypeDependent(), Temporary->isValueDependent(),
3603561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Temporary->isInstantiationDependent(),
360403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor           Temporary->containsUnexpandedParameterPack()),
360503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor      Temporary(Temporary) { }
3606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3607ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  MaterializeTemporaryExpr(EmptyShell Empty)
360803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    : Expr(MaterializeTemporaryExprClass, Empty) { }
3609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
361003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Retrieve the temporary-generating subexpression whose value will
361103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// be materialized into a glvalue.
361203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3613ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
361403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// \brief Determine whether this materialized temporary is bound to an
361503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  /// lvalue reference; otherwise, it's bound to an rvalue reference.
3616ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isBoundToLvalueReference() const {
361703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return getValueKind() == VK_LValue;
361803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3620aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3621aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar    return Temporary->getSourceRange();
3622aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  }
3623ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
362403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  static bool classof(const Stmt *T) {
362503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor    return T->getStmtClass() == MaterializeTemporaryExprClass;
362603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool classof(const MaterializeTemporaryExpr *) {
3628ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return true;
362903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  }
3630ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
363103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  // Iterators
363203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  child_range children() { return child_range(&Temporary, &Temporary + 1); }
363303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor};
3634ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
36355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
36365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
36375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3638