ExprCXX.h revision 9e8c92a9c9b949bbb0408fbbd9a58e34894b6efc
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" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl; 27aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl; 28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl; 29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary; 30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo; 314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions. 341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator 373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax. 383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator 403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the 423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call. 433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever 453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the 463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and 473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template 483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time. 49b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr { 50063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief The overloaded operator. 51063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind Operator; 52063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 53b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic: 541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **args, unsigned numargs, QualType t, 56f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation operatorloc) 57cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK, 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall operatorloc), 59063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor Operator(Op) {} 601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 61ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(C, CXXOperatorCallExprClass, Empty) { } 621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 64b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator - Returns the kind of overloaded operator that this 65b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// expression refers to. 66063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind getOperator() const { return Operator; } 67ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 68b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperatorLoc - Returns the location of the operator symbol in 70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// the expression. When @c getOperator()==OO_Call, this is the 71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// location of the right parentheses; when @c 72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator()==OO_Subscript, this is the location of the right 73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// bracket. 74b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SourceLocation getOperatorLoc() const { return getRParenLoc(); } 75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 7663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXOperatorCallExprClass; 80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor } 81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}; 83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 8488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that 8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()" 8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax 8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member 8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains 8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the 9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including 9188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument). 9288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr { 9388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic: 941817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs, 95f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation RP) 96cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {} 9788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 981817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 991817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1001817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner 10188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// getImplicitObjectArgument - Retrieves the implicit object 10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// argument for the member call. For example, in "x.f(5)", this 10388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// operation would return "x". 104b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek Expr *getImplicitObjectArgument() const; 105ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 106b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek /// Retrieves the declaration of the called method. 107b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek CXXMethodDecl *getMethodDecl() const; 10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 109007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// the implicit object argument. Note that this is may not be the same 111007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// declaration as that of the class context of the CXXMethodDecl which this 112007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// function is calling. 113007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// FIXME: Returns 0 for member pointer call exprs. 114007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth CXXRecordDecl *getRecordDecl(); 115007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth 1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor return T->getStmtClass() == CXXMemberCallExprClass; 11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor } 11988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 12088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor}; 12188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 122e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr { 124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate: 125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne enum { CONFIG, END_PREARG }; 126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic: 128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr **args, unsigned numargs, QualType t, 130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprValueKind VK, SourceLocation RP) 131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK, 132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne RP) { 133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne setConfig(Config); 134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne const CallExpr *getConfig() const { 140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return cast_or_null<CallExpr>(getPreArg(CONFIG)); 141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const Stmt *T) { 146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return T->getStmtClass() == CUDAKernelCallExprClass; 147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const CUDAKernelCallExpr *) { return true; } 149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}; 150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast. 15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes 15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr, 15749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr { 1591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate: 1601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; // the location of the casting op 1611d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc; // the location of the right parenthesis 162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 1661d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 1671d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 1681d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 1691d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor RParenLoc(RParenLoc) {} 17049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 171f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 172f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(SC, Shell, PathSize) { } 173ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor friend class ASTStmtReader; 175ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 17749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor const char *getCastName() const; 17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 179a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// \brief Retrieve the location of the cast operator keyword, e.g., 180a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// "static_cast". 181a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor SourceLocation getOperatorLoc() const { return Loc; } 182a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor 1831d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor /// \brief Retrieve the location of the closing parenthesis. 1841d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 185ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1871d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor return SourceRange(Loc, RParenLoc); 1881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor switch (T->getStmtClass()) { 19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXStaticCastExprClass: 19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXDynamicCastExprClass: 19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXReinterpretCastExprClass: 19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXConstCastExprClass: 19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor default: 19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return false; 19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 1991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXNamedCastExpr *) { return true; } 20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 203ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression 204ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]). 2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 20649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g., 20749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0). 20849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr { 209f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 210f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize, TypeSourceInfo *writtenTy, 2111d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 212f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 2131d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 21449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 216f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 217f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 220f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 221f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 222ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2231d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 224f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 226ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXStaticCastExprClass; 22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXStaticCastExpr *) { return true; } 23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 23549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast. 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 23749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g., 23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr). 23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr { 240f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 2421d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 2441d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 24549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 251f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, Expr *Op, 252f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 253ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2541d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 255ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 256f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 257f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 258ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2590fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson bool isAlwaysNull() const; 2600fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson 2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXDynamicCastExprClass; 26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXDynamicCastExpr *) { return true; } 26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 26649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 26849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view 26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time. 2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 27149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g., 27249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr). 27349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 274f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, 276ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 2771d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 278f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 2791d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor pathSize, writtenTy, l, RParenLoc) {} 28049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 281f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 284f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 285f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 286f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, 287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *Op, const CXXCastPath *Path, 288ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 2891d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 290f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 292ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXReinterpretCastExprClass; 29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXReinterpretCastExpr *) { return true; } 29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 29849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 29949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value. 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 30249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g., 30349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar). 30449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr { 305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 306ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 3071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 308ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 3091d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor 0, writtenTy, l, RParenLoc) {} 31049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 311ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig explicit CXXConstCastExpr(EmptyShell Empty) 312f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 313f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 314f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, Expr *Op, 317ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 3181d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 319f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 320ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXConstCastExprClass; 32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXConstCastExpr *) { return true; } 3251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 3291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr { 3301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool Value; 3311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; 3321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 3331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 334bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 335561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(val), Loc(l) {} 3378b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 338eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXBoolLiteralExpr(EmptyShell Empty) 339eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXBoolLiteralExprClass, Empty) { } 340eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool getValue() const { return Value; } 342eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setValue(bool V) { Value = V; } 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 347eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 348eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXBoolLiteralExprClass; 3511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 3521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXBoolLiteralExpr *) { return true; } 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 35563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 3596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr { 3606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl SourceLocation Loc; 3616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic: 3626e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 363bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 364561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) {} 3666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 367eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 368eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXNullPtrLiteralExprClass, Empty) { } 369eb7f96141f754150a92433286fa385910a22f494Sam Weinig 37063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 3716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 372eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 373eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 374eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const Stmt *T) { 3766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return T->getStmtClass() == CXXNullPtrLiteralExprClass; 3776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl } 3786e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 3796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 38063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3816e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl}; 3826e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 383c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 384c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly 385c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression. 386c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 387c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr) 388c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr { 389c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate: 39057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 391c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SourceRange Range; 392c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 393c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic: 39457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 395f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 39657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 39757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor false, 39857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is value-dependent if the type or expression are dependent 399bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->isDependentType(), 400561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 401bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 40257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 403ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 40457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 4062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is never type-dependent (C++ [temp.dep.expr]p4) 407bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, 4082850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is value-dependent if the type or expression are dependent 409bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->isTypeDependent() || Operand->isValueDependent(), 410561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 411bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 41257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 413c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 41414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner CXXTypeidExpr(EmptyShell Empty, bool isExpr) 41514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner : Expr(CXXTypeidExprClass, Empty) { 41614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner if (isExpr) 41714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (Expr*)0; 41814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner else 41914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (TypeSourceInfo*)0; 42014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 421ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 423ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieves the type operand of this typeid() expression after 42557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 42657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor QualType getTypeOperand() const; 42757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor 42857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieve source information for the type operand. 42957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *getTypeOperandSourceInfo() const { 430c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 43157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return Operand.get<TypeSourceInfo *>(); 432c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 43314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner 43414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 43514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 43614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = TSI; 43714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 43914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Expr *getExprOperand() const { 440c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 44157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 442c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 444030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner void setExprOperand(Expr *E) { 445030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 446030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner Operand = E; 447030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner } 448ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 44963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 45014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setSourceRange(SourceRange R) { Range = R; } 451ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 452c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const Stmt *T) { 453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return T->getStmtClass() == CXXTypeidExprClass; 454c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 455c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const CXXTypeidExpr *) { return true; } 456c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 457c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Iterators 45863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 45963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 46063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 46163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 46263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 463c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl}; 464c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 46501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 46601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression. 46701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 46801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 46901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr { 47001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate: 47101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 47201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceRange Range; 47301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 47401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic: 47501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 4762e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 477bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->getType()->isDependentType(), 478561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 48001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 481ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 48201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 4832e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->isTypeDependent(), 485561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 486bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 48701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 48801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 48901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(EmptyShell Empty, bool isExpr) 49001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet : Expr(CXXUuidofExprClass, Empty) { 49101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (isExpr) 49201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (Expr*)0; 49301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet else 49401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (TypeSourceInfo*)0; 49501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 496ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 49701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 49901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieves the type operand of this __uuidof() expression after 50001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// various required adjustments (removing reference types, cv-qualifiers). 50101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet QualType getTypeOperand() const; 50201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 50301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieve source information for the type operand. 50401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *getTypeOperandSourceInfo() const { 50501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 50601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return Operand.get<TypeSourceInfo *>(); 50701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 50801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 50901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 51001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 51101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = TSI; 51201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 513ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 51401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *getExprOperand() const { 51501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 51601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return static_cast<Expr*>(Operand.get<Stmt *>()); 51701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 518ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 51901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setExprOperand(Expr *E) { 52001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 52101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = E; 52201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 52301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 52463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 52501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setSourceRange(SourceRange R) { Range = R; } 526ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 52701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const Stmt *T) { 52801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return T->getStmtClass() == CXXUuidofExprClass; 52901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 53001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const CXXUuidofExpr *) { return true; } 53101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 53201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Iterators 53363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 53463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 53563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 53663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 53763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 53801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}; 53901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 540796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a 541796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is 542796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example: 543796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// 544796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code 545796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo { 546796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public: 547796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void bar(); 548796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void test() { this->bar(); } 549796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// }; 550796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode 551796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr { 552796da18402f286b897782a298ae3b20c459c102eDouglas Gregor SourceLocation Loc; 553828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool Implicit : 1; 554ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 555796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic: 556828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 557f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 5582850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // 'this' is type-dependent if the class type of the enclosing 5592850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // member function is dependent (C++ [temp.dep.expr]p2) 560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 561561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 563828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor Loc(L), Implicit(isImplicit) { } 564796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 5652fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 5662fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 5672fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner SourceLocation getLocation() const { return Loc; } 5682fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 5692fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 57063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 571796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 572828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool isImplicit() const { return Implicit; } 573828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor void setImplicit(bool I) { Implicit = I; } 574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 576796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return T->getStmtClass() == CXXThisExprClass; 577796da18402f286b897782a298ae3b20c459c102eDouglas Gregor } 578796da18402f286b897782a298ae3b20c459c102eDouglas Gregor static bool classof(const CXXThisExpr *) { return true; } 579796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 580796da18402f286b897782a298ae3b20c459c102eDouglas Gregor // Iterators 58163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 582796da18402f286b897782a298ae3b20c459c102eDouglas Gregor}; 583796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 5841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 5851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 'throw' and 'throw' assignment-expression. When 5861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// assignment-expression isn't present, Op will be null. 5871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 5881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr { 5891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Op; 5901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation ThrowLoc; 591bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Whether the thrown variable (if any) is in scope. 592bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned IsThrownVariableInScope : 1; 593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 594bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor friend class ASTStmtReader; 595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 5971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Ty is the void type which is used as the result type of the 5981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // exepression. The l is the location of the throw keyword. expr 5991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // can by null, if the optional expression to throw isn't present. 600bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 601bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) : 602bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 603561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor expr && expr->isInstantiationDependent(), 604bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor expr && expr->containsUnexpandedParameterPack()), 605bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 6062fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 6072fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 6081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 6091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 61042e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor 61142e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor SourceLocation getThrowLoc() const { return ThrowLoc; } 6121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 613bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Determines whether the variable thrown by this expression (if any!) 614bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// is within the innermost try block. 615bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// 616bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// This information is required to determine whether the NRVO can apply to 617bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// this variable. 618bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 62063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 6211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek if (getSubExpr() == 0) 6221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, ThrowLoc); 6231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 6241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 6251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 6271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXThrowExprClass; 6281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 6291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXThrowExpr *) { return true; } 6301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 63263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Op, Op ? &Op+1 : &Op); 63463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 6351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 6361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 6381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding 6391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly 6401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters. 6411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr { 64265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// \brief The parameter whose default is being used. 64365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// 644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// When the bit is set, the subexpression is stored after the 64565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 64665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// actual default expression is the subexpression. 64765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 649036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// \brief The location where the default argument expression was used. 650036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc; 651ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 652036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(SC, 65465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor param->hasUnparsedDefaultArg() 65565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ? param->getType().getNonReferenceType() 6562333f7727f97018d6742e1e0938133bcfad967abEli Friedman : param->getDefaultArg()->getType(), 657dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall param->getDefaultArg()->getValueKind(), 658561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor param->getDefaultArg()->getObjectKind(), false, false, false, false), 659036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param(param, false), Loc(Loc) { } 66065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor 661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 662036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Expr *SubExpr) 663dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall : Expr(SC, SubExpr->getType(), 664dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall SubExpr->getValueKind(), SubExpr->getObjectKind(), 665ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false, false, false, false), 666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Param(param, true), Loc(Loc) { 66765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor *reinterpret_cast<Expr **>(this + 1) = SubExpr; 66865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 671030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 672030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner 673ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Param is the parameter whose default argument is used by this 6751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // expression. 676036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 677036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 678036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 679f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson } 6801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 68165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // Param is the parameter whose default argument is used by this 68265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // expression, and SubExpr is the expression that will actually be used. 683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static CXXDefaultArgExpr *Create(ASTContext &C, 684036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc, 685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ParmVarDecl *Param, 68665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor Expr *SubExpr); 687ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the parameter that the argument was created from. 68965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor const ParmVarDecl *getParam() const { return Param.getPointer(); } 69065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ParmVarDecl *getParam() { return Param.getPointer(); } 691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the actual argument to the function call. 693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const Expr *getExpr() const { 69465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 69565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr const * const*> (this + 1); 696ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 69765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getExpr() { 69965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 70065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr **> (this + 1); 701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 70265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 7031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the location where this default argument was actually 705036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// used. 706036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation getUsedLocation() const { return Loc; } 707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 70863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 7091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Default argument expressions have no representation in the 7101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // source, so they have an empty source range. 7111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(); 7121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 7151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXDefaultArgExprClass; 7161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXDefaultArgExpr *) { return true; } 7181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 7218a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis 72260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 7233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 7241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 725987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 726c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary. 727c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary { 728c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson /// Destructor - The destructor that needs to be called. 729b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor; 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 731b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson CXXTemporary(const CXXDestructorDecl *destructor) 732c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson : Destructor(destructor) { } 733c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson 734c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic: 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXTemporary *Create(ASTContext &C, 736b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor); 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 738f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXDestructorDecl *getDestructor() const { return Destructor; } 739c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson}; 740fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 741ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary. 742ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 743ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be 744ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example: 745ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 746ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code 747ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// struct S { 748ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// S() { } // User defined constructor makes S non-POD. 749ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// ~S() { } // User defined destructor makes it non-trivial. 750ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// }; 751ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// void test() { 752ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 753ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// } 754ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode 755fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr { 756fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson CXXTemporary *Temp; 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 758fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Stmt *SubExpr; 759fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 760bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 761bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 763bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->isValueDependent(), 764561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SubExpr->isInstantiationDependent(), 765bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->containsUnexpandedParameterPack()), 766bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Temp(temp), SubExpr(SubExpr) { } 76788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson 768fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic: 769d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner CXXBindTemporaryExpr(EmptyShell Empty) 770d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 773fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr* SubExpr); 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson CXXTemporary *getTemporary() { return Temp; } 776f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXTemporary *getTemporary() const { return Temp; } 777d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner void setTemporary(CXXTemporary *T) { Temp = T; } 778f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson 779fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 780fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 78188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 782fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceRange getSourceRange() const { 78496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 78596be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 786fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 787fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Implement isa/cast/dyncast/etc. 788fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const Stmt *T) { 789fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson return T->getStmtClass() == CXXBindTemporaryExprClass; 790fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson } 791fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const CXXBindTemporaryExpr *) { return true; } 792fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 793fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Iterators 79463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 795fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson}; 796fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 79715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor. 79815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr { 79972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic: 80072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson enum ConstructionKind { 80172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_Complete, 80272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_NonVirtualBase, 803059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_VirtualBase, 804059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_Delegating 80572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson }; 806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 80772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate: 80815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson CXXConstructorDecl *Constructor; 80915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 81099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc; 811428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange; 812a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor unsigned NumArgs : 16; 81316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool Elidable : 1; 8147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 8155b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization : 1; 81616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool ZeroInitialization : 1; 81772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson unsigned ConstructKind : 2; 81815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson Stmt **Args; 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 820bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected: 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 82299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 823bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson CXXConstructorDecl *d, bool elidable, 82416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor Expr **args, unsigned numargs, 8257cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 8265b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 8275b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 8285b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 8295b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 830bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson 8316d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 8326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis CXXConstructExpr(StmtClass SC, EmptyShell Empty) 8335b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 8345b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl HadMultipleCandidates(false), ListInitialization(false), 8355b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ZeroInitialization(false), ConstructKind(0), Args(0) 8365b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 8376d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 83815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic: 8396d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 8406d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXConstructExpr(EmptyShell Empty) 8416d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis : Expr(CXXConstructExprClass, Empty), Constructor(0), 8425b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl NumArgs(0), Elidable(false), HadMultipleCandidates(false), 8435b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ListInitialization(false), ZeroInitialization(false), 8445b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructKind(0), Args(0) 8455b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 8466d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 8478e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson static CXXConstructExpr *Create(ASTContext &C, QualType T, 84899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructorDecl *D, bool Elidable, 85016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor Expr **Args, unsigned NumArgs, 8517cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 8525b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 8535b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 8545b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 8555b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 857d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor CXXConstructorDecl* getConstructor() const { return Constructor; } 85839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 86099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation getLocation() const { return Loc; } 86199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor void setLocation(SourceLocation Loc) { this->Loc = Loc; } 862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 863d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor /// \brief Whether this construction is elidable. 864d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor bool isElidable() const { return Elidable; } 86539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setElidable(bool E) { Elidable = E; } 8667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 8677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Whether the referred constructor was resolved from 8687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// an overloaded set having size greater than 1. 8697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { return HadMultipleCandidates; } 8707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 8717cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 8725b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl /// \brief Whether this constructor call was written as list-initialization. 8735b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool isListInitialization() const { return ListInitialization; } 8745b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl void setListInitialization(bool V) { ListInitialization = V; } 8755b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl 87616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// \brief Whether this construction first requires 87716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// zero-initialization before the initializer is called. 87816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool requiresZeroInitialization() const { return ZeroInitialization; } 87916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor void setRequiresZeroInitialization(bool ZeroInit) { 88016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor ZeroInitialization = ZeroInit; 88116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor } 882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8839db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// \brief Determines whether this constructor is actually constructing 8849db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// a base class (rather than a complete object). 88524eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson ConstructionKind getConstructionKind() const { 88624eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson return (ConstructionKind)ConstructKind; 88772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 888ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setConstructionKind(ConstructionKind CK) { 88972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson ConstructKind = CK; 89072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 891ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 89215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ExprIterator arg_iterator; 89315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ConstExprIterator const_arg_iterator; 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_begin() { return Args; } 89615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_end() { return Args + NumArgs; } 89715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_begin() const { return Args; } 89815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_end() const { return Args + NumArgs; } 89915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 900a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 90115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson unsigned getNumArgs() const { return NumArgs; } 90215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 903bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson /// getArg - Return the specified argument. 904bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson Expr *getArg(unsigned Arg) { 905bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 906bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 907bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 908bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson const Expr *getArg(unsigned Arg) const { 909bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 910bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 911bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9132eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian /// setArg - Set the specified argument. 9142eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian void setArg(unsigned Arg, Expr *ArgExpr) { 9152eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian assert(Arg < NumArgs && "Arg access out of range!"); 9162eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian Args[Arg] = ArgExpr; 9172eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian } 9182eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian 91963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 920428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange getParenRange() const { return ParenRange; } 92115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 923524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson return T->getStmtClass() == CXXConstructExprClass || 924524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson T->getStmtClass() == CXXTemporaryObjectExprClass; 92515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson } 92615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson static bool classof(const CXXConstructExpr *) { return true; } 9271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson // Iterators 92963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 93063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Args[0], &Args[0]+NumArgs); 93163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 9326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 93360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 93415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson}; 93515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 93649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 93749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 93849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5); 93949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr { 940987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation TyBeginLoc; 941987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 942f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 943f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 944f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy, 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation tyBeginLoc, CastKind kind, 946f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *castExpr, unsigned pathSize, 947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation rParenLoc) 948f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 949f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall castExpr, pathSize, writtenTy), 9500aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 9510aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson 952f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 953f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 954f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 955f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 956f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 957f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 958f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *Written, 959f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation TyBeginLoc, 960f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Op, 961f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 962f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation RPLoc); 963f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 964f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 965ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 966987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 967ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 968987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getRParenLoc() const { return RParenLoc; } 969ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setRParenLoc(SourceLocation L) { RParenLoc = L; } 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 972987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis return SourceRange(TyBeginLoc, RParenLoc); 973987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXFunctionalCastExprClass; 976987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 977987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis static bool classof(const CXXFunctionalCastExpr *) { return true; } 978987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 979987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 980506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a 981506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object. 982506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast 984506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the 986ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr. 987506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example: 988506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code 989506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); } 990506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 991506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() { 992506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 993506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// }; 994506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode 995524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr { 996ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 997506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 998506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic: 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1000ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **Args,unsigned NumArgs, 1002428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange parenRange, 10037cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 10041c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor bool ZeroInitialization = false); 10056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1006ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1007506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1008ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1009ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 101063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 1011ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1013506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor return T->getStmtClass() == CXXTemporaryObjectExprClass; 1014506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor } 1015506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor static bool classof(const CXXTemporaryObjectExpr *) { return true; } 10166d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 101760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 1018506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor}; 1019506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 102001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object 102101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later. 102201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 102301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example: 102401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code 102501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) { 102601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// values.erase(std::remove_if(values.begin(), values.end(), 102701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor// [=](double value) { return value > cutoff; }); 102801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// } 102901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode 103001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 103101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying 103201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function 103301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a 103401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either 103501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square 103601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression. 103701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr { 103801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor enum { 103901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indicate that the given 104001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture was implicit. 104101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_Implicit = 0x01, 104201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 104301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indciate that the 104401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// given capture was by-copy. 104501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_ByCopy = 0x02 104601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 104701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 104801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The source range that covers the lambda introducer ([...]). 104901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange; 105001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 10517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief The number of captures. 10527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned NumCaptures : 16; 10537ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 105401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The default capture kind, which is a value of type 105501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// LambdaCaptureDefault. 105601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned CaptureDefault : 2; 105701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 105801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Whether this lambda had an explicit parameter list vs. an 105901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit (and empty) parameter list. 106001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned ExplicitParams : 1; 106101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1062dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had the result type explicitly specified. 1063dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor unsigned ExplicitResultType : 1; 1064dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 1065dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether there are any array index variables stored at the end of 1066dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// this lambda expression. 10677ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned HasArrayIndexVars : 1; 10687ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 106901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The location of the closing brace ('}') that completes 107001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// the lambda. 107101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 107201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// The location of the brace is also available by looking up the 107301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// function call operator in the lambda class. However, it is 107401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stored here to improve the performance of getSourceRange(), and 107501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// to avoid having to deserialize the function call operator from a 107601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// module file just to determine the source range. 107701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace; 107801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 10797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // Note: The capture initializers are stored directly after the lambda 10807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // expression, along with the index variables used to initialize by-copy 10817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // array captures. 10827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 108301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 108401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Describes the capture of either a variable or 'this'. 108501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor class Capture { 108601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 108701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation Loc; 108801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc; 10899daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 109001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 109101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 10929daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 109301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor public: 109401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Create a new capture. 109501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 109601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Loc The source location associated with this capture. 109701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 109801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Kind The kind of capture (this, byref, bycopy). 109901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Implicit Whether the capture was implicit or explicit. 110101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Var The local variable being captured, or null if capturing this. 110301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param EllipsisLoc The location of the ellipsis (...) for a 110501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture that is a pack expansion, or an invalid source 110601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// location to indicate that this is not a pack expansion. 110701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture(SourceLocation Loc, bool Implicit, 110801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind Kind, VarDecl *Var = 0, 110901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc = SourceLocation()); 111001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the kind of capture. 111201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind getCaptureKind() const; 111301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles the C++ 'this' 111501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// pointer. 111601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesThis() const { return VarAndBits.getPointer() == 0; } 111701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles a variable. 111901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 112001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 112101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the declaration of the local variable being 112201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captured. 112301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// This operation is only valid if this capture does not capture 112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 'this'. 112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor VarDecl *getCapturedVar() const { 112701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(!capturesThis() && "No variable available for 'this' capture"); 112801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return VarAndBits.getPointer(); 112901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 113001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an implicit capture (not 113201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// written between the square brackets introducing the lambda). 113301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an explicit capture, written 113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// between the square brackets introducing the lambda. 113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isExplicit() const { return !isImplicit(); } 113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source location of the capture. 114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 114101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// For an explicit capture, this returns the location of the 114201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit capture in the source. For an implicit capture, this 114301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// returns the location at which the variable or 'this' was first 114401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// used. 114501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getLocation() const { return Loc; } 114601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 114701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture is a pack expansion, 114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which captures a function parameter pack. 114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isPackExpansion() const { return EllipsisLoc.isValid(); } 115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 115101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the location of the ellipsis for a capture 115201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// that is a pack expansion. 115301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getEllipsisLoc() const { 115401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 115501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return EllipsisLoc; 115601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 115701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 115801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate: 116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a lambda expression. 116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaExpr(QualType T, SourceRange IntroducerRange, 116201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 116301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 116401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1165dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 116601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 11679daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 11689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 11699e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor SourceLocation ClosingBrace, 11709e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor unsigned ManglingNumber); 117101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 11729d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct an empty lambda expression. 11739d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 11749d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor : Expr(LambdaExprClass, Empty), 11759d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 11769d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor ExplicitResultType(false), HasArrayIndexVars(true) { 11779d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor getStoredStmts()[NumCaptures] = 0; 11789d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 11799d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 11807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor Stmt **getStoredStmts() const { 11817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 11827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 11847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the mapping from captures to the first array index 11857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// variable. 11867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned *getArrayIndexStarts() const { 11877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 11887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11897ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 11907ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the complete set of array-index variables. 11917ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor VarDecl **getArrayIndexVars() const { 11927ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<VarDecl **>( 11937ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor getArrayIndexStarts() + NumCaptures + 1); 11947ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11957ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 119601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a new lambda expression. 119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static LambdaExpr *Create(ASTContext &C, 119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *Class, 120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange, 120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1204dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 12069daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 12079daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 12089e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor SourceLocation ClosingBrace, 12099e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor unsigned ManglingNumber); 121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12119d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct a new lambda expression that will be deserialized from 12129d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// an external source. 12139d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 12149d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor unsigned NumArrayIndexVars); 12159d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the default capture kind for this lambda. 121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault getCaptureDefault() const { 121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return static_cast<LambdaCaptureDefault>(CaptureDefault); 121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief An iterator that walks over the captures of the lambda, 122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// both implicit and explicit. 122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef const Capture *capture_iterator; 122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first lambda capture. 1226da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_begin() const; 122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the 122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// sequence of lambda captures. 1230da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_end() const; 123101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12327ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Determine the number of captures in this lambda. 12337ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned capture_size() const { return NumCaptures; } 12347ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 123501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first explicit 123601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1237da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_begin() const; 123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 123901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit lambda captures. 1241da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_end() const; 124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first implicit 124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1245da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_begin() const; 124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 124801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit lambda captures. 1249da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_end() const; 125001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 125101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Iterator that walks over the capture initialization 125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// arguments. 125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef Expr **capture_init_iterator; 125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 125501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the first initialization argument for this 125601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression (which initializes the first capture field). 12577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_begin() const { 12587ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Expr **>(getStoredStmts()); 12597ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 126001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 126101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the iterator pointing one past the last 126276e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor /// initialization argument for this lambda expression. 12637ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_end() const { 12647ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return capture_init_begin() + NumCaptures; 12657ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 126601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12679daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Retrieve the set of index variables used in the capture 12689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// initializer of an array captured by copy. 12699daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// 12709daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \param Iter The iterator that points at the capture initializer for 12719daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// which we are extracting the corresponding index variables. 12729daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 12739daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 127401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source range covering the lambda introducer, 127501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which contains the explicit capture list surrounded by square 127601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// brackets ([...]). 127701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getIntroducerRange() const { return IntroducerRange; } 127801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 127901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the class that corresponds to the lambda, which 128001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stores the captures in its fields and provides the various 128101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// operations permitted on a lambda (copying, calling). 128201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *getLambdaClass() const; 128301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the function call operator associated with this 128501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression. 128601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXMethodDecl *getCallOperator() const; 128701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the body of the lambda. 12899d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor CompoundStmt *getBody() const; 129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether the lambda is mutable, meaning that any 129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captures values can be modified. 129301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isMutable() const; 129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this lambda has an explicit parameter 129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// list vs. an implicit (empty) parameter list. 129701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool hasExplicitParameters() const { return ExplicitParams; } 129801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1299dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had its result type explicitly specified. 1300dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool hasExplicitResultType() const { return ExplicitResultType; } 13019e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const Stmt *T) { 130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return T->getStmtClass() == LambdaExprClass; 130401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const LambdaExpr *) { return true; } 130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getSourceRange() const { 130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return SourceRange(IntroducerRange.getBegin(), ClosingBrace); 130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13117ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor child_range children() { 13127ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 13137ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 131501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 131601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor}; 131801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1319ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1320506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type 1321ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type. 1322987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1323ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr { 1324987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1325ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo; 1326987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1327ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 1328ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1329987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic: 1330ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Create an explicitly-written scalar-value initialization 1331ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// expression. 1332ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr(QualType Type, 1333ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo, 1334ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation rParenLoc ) : 1335f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1336561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, Type->isInstantiationDependentType(), false), 1337ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1338ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 1339ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor explicit CXXScalarValueInitExpr(EmptyShell Shell) 1340ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor : Expr(CXXScalarValueInitExprClass, Shell) { } 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1342ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 1343ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return TypeInfo; 13444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 1345ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1346ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 13474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 134863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1351ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor return T->getStmtClass() == CXXScalarValueInitExprClass; 1352987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1353ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor static bool classof(const CXXScalarValueInitExpr *) { return true; } 13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1355987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // Iterators 135663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1357987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1358987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 13594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls, 13604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)". 13614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr { 13624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Was the usage ::new, i.e. is the global new to be used? 13634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalNew : 1; 1364cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl // Do we allocate an array? If so, the first SubExpr is the size expression. 1365cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool Array : 1; 13666ec278d1a354517e20f13a877481453ee7940c78John McCall // If this is an array allocation, does the usual deallocation 13676ec278d1a354517e20f13a877481453ee7940c78John McCall // function for the allocated type want to know the allocated size? 13686ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 13694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // The number of placement new arguments. 13707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara unsigned NumPlacementArgs : 13; 13712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // What kind of initializer do we have? Could be none, parens, or braces. 13722aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // In storage, we distinguish between "none, and no initializer expr", and 13732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // "none, but an implicit initializer expr". 13742aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl unsigned StoredInitializationStyle : 2; 13752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Contains an optional array size expression, an optional initialization 13762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // expression, and any number of optional placement arguments, in that order. 13774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt **SubExprs; 13784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the allocation function used. 13794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorNew; 13804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the deallocation function used in case of error. May be null. 13814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 13824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 13831bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor /// \brief The allocated type-source information, as written in the source. 13841bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo; 1385ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the allocated type was expressed as a parenthesized type-id, 13874bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor /// the source range covering the parenthesized type-id. 13884bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange TypeIdParens; 1389ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Location of the first token. 13914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SourceLocation StartLoc; 13922aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 13932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Source-range of a paren-delimited initializer. 13942aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange DirectInitRange; 13954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 139660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 13972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl friend class ASTStmtWriter; 13984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 13992aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl enum InitializationStyle { 14002aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NoInit, ///< New-expression has no initializer as written. 14012aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl CallInit, ///< New-expression has a C++98 paren-delimited initializer. 14022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ListInit ///< New-expression has a C++11 list-initializer. 14032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl }; 14042aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 1405ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 14061548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 14072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr **placementArgs, unsigned numPlaceArgs, 14082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange typeIdParens, Expr *arraySize, 14092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle initializationStyle, Expr *initializer, 14106ec278d1a354517e20f13a877481453ee7940c78John McCall QualType ty, TypeSourceInfo *AllocatedTypeInfo, 14112aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceLocation startLoc, SourceRange directInitRange); 14125921863d8f24084797863b5df37842113bac4352Chris Lattner explicit CXXNewExpr(EmptyShell Shell) 14135921863d8f24084797863b5df37842113bac4352Chris Lattner : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 14145921863d8f24084797863b5df37842113bac4352Chris Lattner 14155921863d8f24084797863b5df37842113bac4352Chris Lattner void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 14162aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer); 1417ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1418cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl QualType getAllocatedType() const { 1419cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl assert(getType()->isPointerType()); 14206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<PointerType>()->getPointeeType(); 1421cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 14224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14231bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *getAllocatedTypeSourceInfo() const { 14241bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor return AllocatedTypeInfo; 14251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor } 1426c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 1427c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// \brief True if the allocation result needs to be null-checked. 1428c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// C++0x [expr.new]p13: 1429c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// If the allocation function returns null, initialization shall 1430c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// not be done, the deallocation function shall not be called, 1431c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// and the value of the new-expression shall be null. 1432c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// An allocation function is not allowed to return null unless it 1433c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// has a non-throwing exception-specification. The '03 rule is 1434c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// identical except that the definition of a non-throwing 1435c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// exception specification is just "is it throw()?". 14368026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1437ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorNew() const { return OperatorNew; } 14395921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 14404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 14415921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 14424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1443cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool isArray() const { return Array; } 1444cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl Expr *getArraySize() { 1445cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1446cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1447cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl const Expr *getArraySize() const { 1448cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1449cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1450cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl 14514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr **getPlacementArgs() { 14532aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1454aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1455ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getPlacementArg(unsigned i) { 14574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 14582aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return getPlacementArgs()[i]; 14594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 14604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getPlacementArg(unsigned i) const { 14614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 14622aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 14634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 14644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14654bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor bool isParenTypeId() const { return TypeIdParens.isValid(); } 14664bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange getTypeIdParens() const { return TypeIdParens; } 14674bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor 14684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalNew() const { return GlobalNew; } 14697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 14702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Whether this new-expression has any initializer at all. 14712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer() const { return StoredInitializationStyle > 0; } 14721548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The kind of initializer this new-expression has. 14742aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle getInitializationStyle() const { 14752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (StoredInitializationStyle == 0) 14762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return NoInit; 14772aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return static_cast<InitializationStyle>(StoredInitializationStyle-1); 14781548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14791548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14802aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The initializer of this new-expression. 14812aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *getInitializer() { 14822aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 14831548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const Expr *getInitializer() const { 14852aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 14861548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14871548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14882aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// Answers whether the usual array deallocation function for the 14892aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// allocated type expects the size of the allocation as a 14902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// parameter. 14912aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool doesUsualArrayDeleteWantSize() const { 14922aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return UsualArrayDeleteWantsSize; 14932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 14941548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ExprIterator arg_iterator; 14964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ConstExprIterator const_arg_iterator; 14974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_begin() { 14992aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 15004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_end() { 15022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 15034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_begin() const { 15052aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 15064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_end() const { 15082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 15094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 1510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15115921863d8f24084797863b5df37842113bac4352Chris Lattner typedef Stmt **raw_arg_iterator; 15125921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_begin() { return SubExprs; } 15135921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_end() { 15142aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 15155921863d8f24084797863b5df37842113bac4352Chris Lattner } 15165921863d8f24084797863b5df37842113bac4352Chris Lattner const_arg_iterator raw_arg_begin() const { return SubExprs; } 15172aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const_arg_iterator raw_arg_end() const { 15182aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 15192aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 15204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15215921863d8f24084797863b5df37842113bac4352Chris Lattner SourceLocation getStartLoc() const { return StartLoc; } 15222aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceLocation getEndLoc() const; 1523428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 15242aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange getDirectInitRange() const { return DirectInitRange; } 1525428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 152663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15272aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SourceRange(getStartLoc(), getEndLoc()); 15284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXNewExprClass; 15324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const CXXNewExpr *) { return true; } 15344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 153663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 15372aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return child_range(raw_arg_begin(), raw_arg_end()); 153863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 15394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 15404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 15424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray". 15434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr { 15444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this a forced global delete, i.e. "::delete"? 15454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalDelete : 1; 15464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this the array form of delete, i.e. "delete[]"? 15474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool ArrayForm : 1; 15484076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 15494076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 15504076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // will be true). 15514076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool ArrayFormAsWritten : 1; 15526ec278d1a354517e20f13a877481453ee7940c78John McCall // Does the usual deallocation function for the element type require 15536ec278d1a354517e20f13a877481453ee7940c78John McCall // a size_t argument? 15546ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 15554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the operator delete overload that is used. Could be a member. 15564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 15574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // The pointer expression to be deleted. 15584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt *Argument; 15594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Location of the expression. 15604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SourceLocation Loc; 15614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 15624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 15636ec278d1a354517e20f13a877481453ee7940c78John McCall bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 15646ec278d1a354517e20f13a877481453ee7940c78John McCall FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1566561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor arg->isInstantiationDependent(), 1567bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor arg->containsUnexpandedParameterPack()), 1568f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall GlobalDelete(globalDelete), 15694076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 15706ec278d1a354517e20f13a877481453ee7940c78John McCall UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), 15714076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 157295fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis explicit CXXDeleteExpr(EmptyShell Shell) 157395fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 15744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalDelete() const { return GlobalDelete; } 15764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isArrayForm() const { return ArrayForm; } 15774076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 15784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15796ec278d1a354517e20f13a877481453ee7940c78John McCall /// Answers whether the usual array deallocation function for the 15806ec278d1a354517e20f13a877481453ee7940c78John McCall /// allocated type expects the size of the allocation as a 15816ec278d1a354517e20f13a877481453ee7940c78John McCall /// parameter. This can be true even if the actual deallocation 15826ec278d1a354517e20f13a877481453ee7940c78John McCall /// function that we're using doesn't want a size. 15836ec278d1a354517e20f13a877481453ee7940c78John McCall bool doesUsualArrayDeleteWantSize() const { 15846ec278d1a354517e20f13a877481453ee7940c78John McCall return UsualArrayDeleteWantsSize; 15856ec278d1a354517e20f13a877481453ee7940c78John McCall } 15866ec278d1a354517e20f13a877481453ee7940c78John McCall 15874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 15884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getArgument() { return cast<Expr>(Argument); } 15904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getArgument() const { return cast<Expr>(Argument); } 15914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1592a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// \brief Retrieve the type being destroyed. If the type being 1593a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// destroyed is a dependent type which may or may not be a pointer, 1594a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// return an invalid type. 15955833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType getDestroyedType() const; 1596ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 159763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return SourceRange(Loc, Argument->getLocEnd()); 15994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 16024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXDeleteExprClass; 16034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const CXXDeleteExpr *) { return true; } 16054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 160763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Argument, &Argument+1); } 1608f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis 1609f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis friend class ASTStmtReader; 16104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 16114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1612ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Structure used to store the type being destroyed by a 1613a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression. 1614a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage { 1615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Either the type source information or the name of the type, if 1616a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// it couldn't be resolved due to type-dependence. 1617a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1618ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1619a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief The starting source location of the pseudo-destructor type. 1620a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation Location; 1621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1622a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic: 1623a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage() { } 1624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1625a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1626a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor : Type(II), Location(Loc) { } 1627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1628a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1630ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getTypeSourceInfo() const { 1631ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return Type.dyn_cast<TypeSourceInfo *>(); 1632a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1633ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1634a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getIdentifier() const { 1635a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return Type.dyn_cast<IdentifierInfo *>(); 1636a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1637ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1638a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation getLocation() const { return Location; } 1639a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor}; 1640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1641a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1642a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1643e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a 1644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have 1645e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example: 1646e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// 1647e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code 1648e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T; 1649e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) { 1650e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// p->T::~T(); 1651e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// } 1652e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode 1653a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1654e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as: 1655ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// 1656a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code 16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T> 1658a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) { 1659e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// ptr->T::~T(); 1660a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// } 1661a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode 1662a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1663e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics 1664e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression. 1665a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr { 1666a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The base expression (that is being destroyed). 1667a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Stmt *Base; 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1669a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1670a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// period ('.'). 1671a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool IsArrow : 1; 16721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1673a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The location of the '.' or '->' operator. 1674a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation OperatorLoc; 1675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1676a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The nested-name-specifier that follows the operator, if present. 1677f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1679e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1680e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1681e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType; 1682ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The location of the '::' in a qualified pseudo-destructor 1684e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1685e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc; 1686ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1687fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief The location of the '~'. 1688fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc; 1689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1690ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The type being destroyed, or its name if we were unable to 1691a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// resolve the name. 1692a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage DestroyedType; 16931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1694f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor friend class ASTStmtReader; 1695ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1696a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic: 1697a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor CXXPseudoDestructorExpr(ASTContext &Context, 1698a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1699f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1700e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType, 1701e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc, 1702fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 1703e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall PseudoDestructorTypeStorage DestroyedType); 17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1705de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1706de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis : Expr(CXXPseudoDestructorExprClass, Shell), 1707f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1708de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1709a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *getBase() const { return cast<Expr>(Base); } 17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 1712a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 1713a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// x->Base::foo. 1714f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool hasQualifier() const { return QualifierLoc; } 17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1716f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1717f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// with source-location information. 1718f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 1721a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 1722a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// NULL. 1723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 1724ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 1725f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor } 17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1727a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Determine whether this pseudo-destructor expression was written 1728a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// using an '->' (otherwise, it used a '.'). 1729a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool isArrow() const { return IsArrow; } 1730a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor 1731a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Retrieve the location of the '.' or '->' operator. 1732a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 17331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1734ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the scope type in a qualified pseudo-destructor 1735e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1736e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// 1737e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Pseudo-destructor expressions can have extra qualification within them 1738e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1739e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Here, if the object type of the expression is (or may be) a scalar type, 1740ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \p T may also be a scalar type and, therefore, cannot be part of a 1741e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1742e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// destructor expression. 174326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1745e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1746e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1747e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1748ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1749fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief Retrieve the location of the '~'. 1750fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation getTildeLoc() const { return TildeLoc; } 1751ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 175226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// \brief Retrieve the source location information for the type 175326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// being destroyed. 1754a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// 1755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This type-source information is available for non-dependent 1756a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// pseudo-destructor expressions and some dependent pseudo-destructor 1757a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// expressions. Returns NULL if we only have the identifier for a 1758a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// dependent pseudo-destructor expression. 1759ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getDestroyedTypeInfo() const { 1760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getTypeSourceInfo(); 1761a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1763a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief In a dependent pseudo-destructor expression for which we do not 1764a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// have full type information on the destroyed type, provides the name 1765a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// of the destroyed type. 1766a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getDestroyedTypeIdentifier() const { 1767a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return DestroyedType.getIdentifier(); 1768a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1770a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the type being destroyed. 1771a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor QualType getDestroyedType() const; 1772ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1773a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the starting location of the type being destroyed. 1774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation getDestroyedTypeLoc() const { 1775ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getLocation(); 1776a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1778de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1779de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// expression. 1780de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1781de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1782de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1783de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1784de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the destroyed type. 1785de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(TypeSourceInfo *Info) { 1786de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(Info); 1787de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1788de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 178963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1792a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor return T->getStmtClass() == CXXPseudoDestructorExprClass; 1793a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 1794a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor static bool classof(const CXXPseudoDestructorExpr *) { return true; } 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1796a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor // Iterators 179763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base + 1); } 1798a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}; 17991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 180064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 180164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates. 180264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example: 180364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true 180464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false 180564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr { 18060dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 18070dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl unsigned UTT : 31; 18080dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The value of the type trait. Unspecified if dependent. 18090dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool Value : 1; 181064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 181164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// Loc - The location of the type trait keyword. 181264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation Loc; 181364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 181464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// RParen - The location of the closing paren. 181564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation RParen; 181664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18170dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The type being queried. 18183d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *QueriedType; 181964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 182064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic: 1821ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 18220dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl TypeSourceInfo *queried, bool value, 182364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation rparen, QualType ty) 1824f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1825bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, queried->getType()->isDependentType(), 1826561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->getType()->isInstantiationDependentType(), 1827bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor queried->getType()->containsUnexpandedParameterPack()), 18280dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 182964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18306d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit UnaryTypeTraitExpr(EmptyShell Empty) 18310dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 18323d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QueriedType() { } 18336d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 183463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 183564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18360dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 183764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18383d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QualType getQueriedType() const { return QueriedType->getType(); } 183964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18403d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1841ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18420dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool getValue() const { return Value; } 184364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 184464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const Stmt *T) { 184564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return T->getStmtClass() == UnaryTypeTraitExprClass; 184664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 184764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const UnaryTypeTraitExpr *) { return true; } 184864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 184964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Iterators 185063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 18516d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 185260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 185364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl}; 185464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the 18566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates. 18576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example: 18586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true 18596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr { 18606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 18616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet unsigned BTT : 8; 18626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The value of the type trait. Unspecified if dependent. 18646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool Value : 1; 18656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Loc - The location of the type trait keyword. 18676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation Loc; 18686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// RParen - The location of the closing paren. 18706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParen; 18716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The lhs type being queried. 18736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsType; 18746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The rhs type being queried. 18766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsType; 18776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic: 1879ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1880ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 18816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool value, SourceLocation rparen, QualType ty) 1882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 18836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet lhsType->getType()->isDependentType() || 1884bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->isDependentType(), 1885561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhsType->getType()->isInstantiationDependentType() || 1886561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhsType->getType()->isInstantiationDependentType()), 1887bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhsType->getType()->containsUnexpandedParameterPack() || 1888bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->containsUnexpandedParameterPack())), 18896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BTT(btt), Value(value), Loc(loc), RParen(rparen), 18906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsType(lhsType), RhsType(rhsType) { } 18916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet explicit BinaryTypeTraitExpr(EmptyShell Empty) 18946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1895f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet LhsType(), RhsType() { } 18966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 189763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 18986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SourceRange(Loc, RParen); 18996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BinaryTypeTrait getTrait() const { 19026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return static_cast<BinaryTypeTrait>(BTT); 19036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getLhsType() const { return LhsType->getType(); } 19066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getRhsType() const { return RhsType->getType(); } 19076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 19096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 1910ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool getValue() const { assert(!isTypeDependent()); return Value; } 19126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const Stmt *T) { 19146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return T->getStmtClass() == BinaryTypeTraitExprClass; 19156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const BinaryTypeTraitExpr *) { return true; } 19176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet // Iterators 191963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 19206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet friend class ASTStmtReader; 19226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}; 19236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 192421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the 192521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// implementation of __array_rank and __array_extent. 192621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example: 192721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_rank(int[10][20]) == 2 192821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_extent(int, 1) == 20 192921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr { 193099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 193199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 193221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 193321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley unsigned ATT : 2; 193421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 193521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The value of the type trait. Unspecified if dependent. 193621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t Value; 193721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 193821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The array dimension being queried, or -1 if not used 193921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *Dimension; 194021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 194121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Loc - The location of the type trait keyword. 194221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation Loc; 194321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 194421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// RParen - The location of the closing paren. 194521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParen; 194621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 194721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The type being queried. 194821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *QueriedType; 194921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 195021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic: 195121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 195221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *queried, uint64_t value, 195321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *dimension, SourceLocation rparen, QualType ty) 195421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 195521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley false, queried->getType()->isDependentType(), 1956561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (queried->getType()->isInstantiationDependentType() || 1957561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (dimension && dimension->isInstantiationDependent())), 195821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley queried->getType()->containsUnexpandedParameterPack()), 195921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ATT(att), Value(value), Dimension(dimension), 196021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Loc(loc), RParen(rparen), QueriedType(queried) { } 196121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley explicit ArrayTypeTraitExpr(EmptyShell Empty) 196421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 196521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QueriedType() { } 196621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196725aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek virtual ~ArrayTypeTraitExpr() { } 196825aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek 1969ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie virtual SourceRange getSourceRange() const { 1970ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return SourceRange(Loc, RParen); 1971ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 197221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 197421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QualType getQueriedType() const { return QueriedType->getType(); } 197621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 197821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 198021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 198121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *getDimensionExpression() const { return Dimension; } 198221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 198321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const Stmt *T) { 198421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return T->getStmtClass() == ArrayTypeTraitExprClass; 198521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 198621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const ArrayTypeTraitExpr *) { return true; } 198721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 198821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Iterators 198921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley child_range children() { return child_range(); } 199021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 199121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley friend class ASTStmtReader; 199221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}; 199321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 1994552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// ExpressionTraitExpr - An expression trait intrinsic 1995552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example: 1996552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(std::cout) == true 1997552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(1) == false 1998552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr { 1999552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned. 2000552622067dc45013d240f73952fece703f5e63bdJohn Wiegley unsigned ET : 31; 2001552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// The value of the type trait. Unspecified if dependent. 2002552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool Value : 1; 2003552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2004552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Loc - The location of the type trait keyword. 2005552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation Loc; 2006552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2007552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// RParen - The location of the closing paren. 2008552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParen; 2009552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2010552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr* QueriedExpression; 2011552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic: 2012ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2013552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *queried, bool value, 2014552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation rparen, QualType resultType) 2015552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2016552622067dc45013d240f73952fece703f5e63bdJohn Wiegley false, // Not type-dependent 2017552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Value-dependent if the argument is type-dependent. 2018552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->isTypeDependent(), 2019561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->isInstantiationDependent(), 2020552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->containsUnexpandedParameterPack()), 2021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ET(et), Value(value), Loc(loc), RParen(rparen), 2022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QueriedExpression(queried) { } 2023552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2024552622067dc45013d240f73952fece703f5e63bdJohn Wiegley explicit ExpressionTraitExpr(EmptyShell Empty) 2025552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2026552622067dc45013d240f73952fece703f5e63bdJohn Wiegley QueriedExpression() { } 2027552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2028552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 2029552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2030552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2031552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2032552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *getQueriedExpression() const { return QueriedExpression; } 2033552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2034552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool getValue() const { return Value; } 2035552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2036552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const Stmt *T) { 2037552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return T->getStmtClass() == ExpressionTraitExprClass; 2038552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2039552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const ExpressionTraitExpr *) { return true; } 2040552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2041552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Iterators 2042552622067dc45013d240f73952fece703f5e63bdJohn Wiegley child_range children() { return child_range(); } 2043552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2044552622067dc45013d240f73952fece703f5e63bdJohn Wiegley friend class ASTStmtReader; 2045552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}; 2046552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2047552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20487bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an 20497bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 20507bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr { 2051ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// The results. These are undesugared, which is to say, they may 20527bb12da2b0749eeebb21854c77877736969e59f2John McCall /// include UsingShadowDecls. Access is relative to the naming 20537bb12da2b0749eeebb21854c77877736969e59f2John McCall /// class. 2054928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor // FIXME: Allocate this data after the OverloadExpr subclass. 2055928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor DeclAccessPair *Results; 2056928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned NumResults; 2057ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 20587bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The common name of these declarations. 20592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo; 2060ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 20614c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor /// \brief The nested-name-specifier that qualifies the name, if any. 20624c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 2063ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2064a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected: 2065e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2066e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2067e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2069e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2070e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2071e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2072e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2073e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2074e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2075e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 20767bb12da2b0749eeebb21854c77877736969e59f2John McCall 2077bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor OverloadExpr(StmtClass K, ASTContext &C, 20784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2079e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2081bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2082bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2083561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownDependent, 2084561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownInstantiationDependent, 2085561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownContainsUnexpandedParameterPack); 20867bb12da2b0749eeebb21854c77877736969e59f2John McCall 2087a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis OverloadExpr(StmtClass K, EmptyShell Empty) 2088a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : Expr(K, Empty), Results(0), NumResults(0), 2089e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara QualifierLoc(), HasTemplateKWAndArgsInfo(false) { } 2090a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 2091bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeResults(ASTContext &C, 2092bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, 2093bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator End); 20947bb12da2b0749eeebb21854c77877736969e59f2John McCall 2095bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic: 20969c72c6088d591ace8503b842d39448c2040f3033John McCall struct FindResult { 20979c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Expression; 20989c72c6088d591ace8503b842d39448c2040f3033John McCall bool IsAddressOfOperand; 20999c72c6088d591ace8503b842d39448c2040f3033John McCall bool HasFormOfMemberPointer; 21009c72c6088d591ace8503b842d39448c2040f3033John McCall }; 21019c72c6088d591ace8503b842d39448c2040f3033John McCall 21027bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Finds the overloaded expression in the given expression of 21037bb12da2b0749eeebb21854c77877736969e59f2John McCall /// OverloadTy. 21047bb12da2b0749eeebb21854c77877736969e59f2John McCall /// 21059c72c6088d591ace8503b842d39448c2040f3033John McCall /// \return the expression (which must be there) and true if it has 21069c72c6088d591ace8503b842d39448c2040f3033John McCall /// the particular form of a member pointer expression 21079c72c6088d591ace8503b842d39448c2040f3033John McCall static FindResult find(Expr *E) { 21087bb12da2b0749eeebb21854c77877736969e59f2John McCall assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 21097bb12da2b0749eeebb21854c77877736969e59f2John McCall 21109c72c6088d591ace8503b842d39448c2040f3033John McCall FindResult Result; 21119c72c6088d591ace8503b842d39448c2040f3033John McCall 21127bb12da2b0749eeebb21854c77877736969e59f2John McCall E = E->IgnoreParens(); 21139c72c6088d591ace8503b842d39448c2040f3033John McCall if (isa<UnaryOperator>(E)) { 21149c72c6088d591ace8503b842d39448c2040f3033John McCall assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 21159c72c6088d591ace8503b842d39448c2040f3033John McCall E = cast<UnaryOperator>(E)->getSubExpr(); 21169c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 21179c72c6088d591ace8503b842d39448c2040f3033John McCall 21189c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 21199c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = true; 21209c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = Ovl; 21219c72c6088d591ace8503b842d39448c2040f3033John McCall } else { 21229c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = false; 21239c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = false; 21249c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = cast<OverloadExpr>(E); 21259c72c6088d591ace8503b842d39448c2040f3033John McCall } 21269c72c6088d591ace8503b842d39448c2040f3033John McCall 21279c72c6088d591ace8503b842d39448c2040f3033John McCall return Result; 21287bb12da2b0749eeebb21854c77877736969e59f2John McCall } 21297bb12da2b0749eeebb21854c77877736969e59f2John McCall 2130e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall /// Gets the naming class of this lookup, if any. 2131e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall CXXRecordDecl *getNamingClass() const; 2132e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall 21337bb12da2b0749eeebb21854c77877736969e59f2John McCall typedef UnresolvedSetImpl::iterator decls_iterator; 2134928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2135ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie decls_iterator decls_end() const { 2136928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor return UnresolvedSetIterator(Results + NumResults); 2137928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor } 2138ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21397bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the number of declarations in the unresolved set. 2140928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned getNumDecls() const { return NumResults; } 21417bb12da2b0749eeebb21854c77877736969e59f2John McCall 21422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Gets the full name info. 21432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 21442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 21457bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the name looked up. 21462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return NameInfo.getName(); } 21477bb12da2b0749eeebb21854c77877736969e59f2John McCall 21487bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the location of the name. 21492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 21507bb12da2b0749eeebb21854c77877736969e59f2John McCall 21517bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Fetches the nested-name qualifier, if one was given. 2152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 21544c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor } 21557bb12da2b0749eeebb21854c77877736969e59f2John McCall 2156ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// Fetches the nested-name qualifier with source-location information, if 21574c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor /// one was given. 21584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 21597bb12da2b0749eeebb21854c77877736969e59f2John McCall 2160e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2161e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2162e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2163e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2164e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2165e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2166e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2167e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2168e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2169e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2170e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2171e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2172e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2173e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2174e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2175e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2176e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2177e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2178e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2179e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 21807bb12da2b0749eeebb21854c77877736969e59f2John McCall 2181e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2182e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2183e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2184e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether this expression had explicit template arguments. 2185e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2186e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2187e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // Note that, inconsistently with the explicit-template-argument AST 2188e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // nodes, users are *forbidden* from calling these methods on objects 2189e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // without explicit template arguments. 2190e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2191e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2192e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2193e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2194e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 21957bb12da2b0749eeebb21854c77877736969e59f2John McCall 2196b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 21977bb12da2b0749eeebb21854c77877736969e59f2John McCall return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 21987bb12da2b0749eeebb21854c77877736969e59f2John McCall } 21997bb12da2b0749eeebb21854c77877736969e59f2John McCall 2200e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgumentLoc const *getTemplateArgs() const { 2201e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().getTemplateArgs(); 2202e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2203e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2204e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned getNumTemplateArgs() const { 2205e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().NumTemplateArgs; 2206e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2207e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2208e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Copies the template arguments into the given structure. 2209e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2210e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getExplicitTemplateArgs().copyInto(List); 2211e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2212e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2213096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2214096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2215096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2216b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2217096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2218096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 22197bb12da2b0749eeebb21854c77877736969e59f2John McCall } 22207bb12da2b0749eeebb21854c77877736969e59f2John McCall 22217bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const Stmt *T) { 22227bb12da2b0749eeebb21854c77877736969e59f2John McCall return T->getStmtClass() == UnresolvedLookupExprClass || 22237bb12da2b0749eeebb21854c77877736969e59f2John McCall T->getStmtClass() == UnresolvedMemberExprClass; 22247bb12da2b0749eeebb21854c77877736969e59f2John McCall } 22257bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const OverloadExpr *) { return true; } 22264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 22274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 22284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 22297bb12da2b0749eeebb21854c77877736969e59f2John McCall}; 22307bb12da2b0749eeebb21854c77877736969e59f2John McCall 22317bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during 22327bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration. This 22337bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways: 22347bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * we might be waiting for argument-dependent lookup 22357bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the name might resolve to an overloaded function 22367bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually: 22377bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the lookup might have included a function template 22387bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always 22397bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in 22407bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs. 22417bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr { 2242ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if these lookup results should be extended by 2243ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup if this is the operand of a function 2244ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// call. 2245ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool RequiresADL; 2246ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2247ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// True if namespace ::std should be considered an associated namespace 2248ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1. 2249ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace; 2250ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 22517453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if these lookup results are overloaded. This is pretty 22527453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// trivially rederivable if we urgently need to kill this field. 22537453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool Overloaded; 22547453ed4cb2cab113de3378df371b1c6f1243d832John McCall 22557bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The naming class (C++ [class.access.base]p5) of the lookup, if 22567bb12da2b0749eeebb21854c77877736969e59f2John McCall /// any. This can generally be recalculated from the context chain, 22577bb12da2b0749eeebb21854c77877736969e59f2John McCall /// but that can be fairly expensive for unqualified lookups. If we 22587bb12da2b0749eeebb21854c77877736969e59f2John McCall /// want to improve memory use here, this could go in a union 22597bb12da2b0749eeebb21854c77877736969e59f2John McCall /// against the qualified-lookup bits. 22607bb12da2b0749eeebb21854c77877736969e59f2John McCall CXXRecordDecl *NamingClass; 2261f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2262ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedLookupExpr(ASTContext &C, 2263928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor CXXRecordDecl *NamingClass, 22644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2265e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 22662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2267ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool RequiresADL, bool Overloaded, 2268bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2269ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2270ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace) 2271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2272e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara NameInfo, TemplateArgs, Begin, End, false, false, false), 2273ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(RequiresADL), 2274ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StdIsAssociatedNamespace(StdIsAssociatedNamespace), 2275ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Overloaded(Overloaded), NamingClass(NamingClass) 2276ba13543329afac4a0d01304ec2ec4924d99306a6John McCall {} 2277ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2278bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis UnresolvedLookupExpr(EmptyShell Empty) 2279bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis : OverloadExpr(UnresolvedLookupExprClass, Empty), 2280ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false), 2281ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NamingClass(0) 2282bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis {} 2283bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 22844c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 2285ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2286ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic: 2287ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2288c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 22894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 22902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 22915a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor bool ADL, bool Overloaded, 2292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 2293ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith UnresolvedSetIterator End, 2294ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace = false) { 2295ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert((ADL || !StdIsAssociatedNamespace) && 2296ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith "std considered associated namespace when not performing ADL"); 2297e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2298e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation(), NameInfo, 2299ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ADL, Overloaded, 0, Begin, End, 2300ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StdIsAssociatedNamespace); 2301ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2302ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2303f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2304c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 23054c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2306e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2308f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool ADL, 23099d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *Args, 2310ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 23115a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator End); 2312f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2313bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2314e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 2315bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis unsigned NumTemplateArgs); 2316bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 2317ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if this declaration should be extended by 2318ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup. 2319ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool requiresADL() const { return RequiresADL; } 2320ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2321ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// True if namespace ::std should be artificially added to the set of 2322ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// associated namespaecs for argument-dependent lookup purposes. 2323ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; } 2324ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 23257453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if this lookup is overloaded. 23267453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool isOverloaded() const { return Overloaded; } 23277453ed4cb2cab113de3378df371b1c6f1243d832John McCall 2328c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// Gets the 'naming class' (in the sense of C++0x 2329c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// [class.access.base]p5) of the lookup. This is the scope 2330c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// that was looked in to find these results. 2331c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const { return NamingClass; } 2332c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 233363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range(getNameInfo().getSourceRange()); 2335ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (getQualifierLoc()) 23364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 2337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (hasExplicitTemplateArgs()) 23384c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setEnd(getRAngleLoc()); 2339f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2340ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2341ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 234263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 2343ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2344ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const Stmt *T) { 2345ba13543329afac4a0d01304ec2ec4924d99306a6John McCall return T->getStmtClass() == UnresolvedLookupExprClass; 2346ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2347ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const UnresolvedLookupExpr *) { return true; } 2348ba13543329afac4a0d01304ec2ec4924d99306a6John McCall}; 2349ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 23505953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot 23515953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved. 23525953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// 2353ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2354a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as 23555953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an 2356865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when 23575953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In 23585953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the 23595953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the 2360865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2361ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced 2362a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2363a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found. 2364865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr { 2365ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested-name-specifier that qualifies this unresolved 2366ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration name. 236700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 2368ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 236900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// The name of the entity we will be referencing. 237000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor DeclarationNameInfo NameInfo; 23715953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 2372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2380e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2381e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2382e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2383e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DependentScopeDeclRefExpr*>(this) 2384e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2385e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 23861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2387f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall DependentScopeDeclRefExpr(QualType T, 238800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2389e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2391bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *Args); 2392f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2393f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic: 2394f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static DependentScopeDeclRefExpr *Create(ASTContext &C, 239500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2398e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs); 23995953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 240012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 240212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis unsigned NumTemplateArgs); 240312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 24045953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the name that this expression refers to. 24052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 24062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 24072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name that this expression refers to. 24082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getDeclName() const { return NameInfo.getName(); } 24095953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 24105953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the location of the name within the expression. 24112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLocation() const { return NameInfo.getLoc(); } 24125953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 241300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the 241400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// name, with source location information. 241500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2416ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2417ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2418ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies this 2419ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration. 2420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2421ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 242200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor } 24231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2425e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2426e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2427e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2428e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2429e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2430e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2431e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2432e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2433e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2434e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2436e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2437e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2438e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2439e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2440e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2441e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2442e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2443e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2444e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2445e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2446e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2447e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2448f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Determines whether this lookup had explicit template arguments. 2449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 24501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2451f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Note that, inconsistently with the explicit-template-argument AST 2452f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // nodes, users are *forbidden* from calling these methods on objects 2453f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // without explicit template arguments. 24541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2455b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 245612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis assert(hasExplicitTemplateArgs()); 2457b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 245812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis } 245912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 2460f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Gets a reference to the explicit template argument list. 2461b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2462f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall assert(hasExplicitTemplateArgs()); 2463b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2464f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 24651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2466096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2467096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2468096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2469b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2470096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2471096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2472096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2473096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2474f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Copies the template arguments (if present) into the given 2475f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// structure. 2476f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2477f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall getExplicitTemplateArgs().copyInto(List); 2478f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 2479ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2480f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentLoc const *getTemplateArgs() const { 2481f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2482d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2483d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2484f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall unsigned getNumTemplateArgs() const { 2485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2486f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 24871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 248863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 248900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 2490f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (hasExplicitTemplateArgs()) 2491f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Range.setEnd(getRAngleLoc()); 2492f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2493edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 24941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2496f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return T->getStmtClass() == DependentScopeDeclRefExprClass; 2497edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 2498f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static bool classof(const DependentScopeDeclRefExpr *) { return true; } 2499f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 250063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 25014045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 25024045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 25034045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 2504edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor}; 25051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25064765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which 25074765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's 25084765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation. The most common source of expression-introduced 250980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of 251080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every 251180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer. 251280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// 251380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a 251480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal. The lifetime of a block 251580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope. 25164765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr { 251780ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic: 251880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// The type of objects that are kept in the cleanup. 251980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// It's useful to remember the set of blocks; we could also 252080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// remember the set of temporaries, but there's currently 252180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// no need. 252280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall typedef BlockDecl *CleanupObject; 252380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 252480ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate: 252502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Stmt *SubExpr; 25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 252780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(EmptyShell, unsigned NumObjects); 252880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 252902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 253080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject *getObjectsBuffer() { 253180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<CleanupObject*>(this + 1); 253280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 253380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall const CleanupObject *getObjectsBuffer() const { 253480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<const CleanupObject*>(this + 1); 253580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 253680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; 2537ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 253888eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic: 253980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 254080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned numObjects); 25411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 254380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> objects); 2544ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 254580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> getObjects() const { 254680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2547f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson } 254880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 254980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 255080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 255180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject getObject(unsigned i) const { 255280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall assert(i < getNumObjects() && "Index out of range"); 255380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return getObjects()[i]; 2554d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner } 25551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 255602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2557f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 255880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 255980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// setSubExpr - As with any mutator of the AST, be very careful 256080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// when modifying an existing AST to preserve its invariants. 256188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 256202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2563ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceRange getSourceRange() const { 256496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 256596be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 256602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 256702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Implement isa/cast/dyncast/etc. 256802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson static bool classof(const Stmt *T) { 25694765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return T->getStmtClass() == ExprWithCleanupsClass; 257002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson } 25714765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall static bool classof(const ExprWithCleanups *) { return true; } 257202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 257302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Iterators 257463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 257502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson}; 257602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2577d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional 2578d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are 2579d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. 2580d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2581d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by 2582d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 2583d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and 2584d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is 2585d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such 2586d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as: 2587d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2588d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code 2589d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// template<typename T, typename A1> 2590d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// inline T make_a(const A1& a1) { 2591d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// return T(a1); 2592d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// } 2593d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode 2594d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2595d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a 2596d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type 2597d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion. 2598d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr { 2599d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The type being constructed. 2600ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 2601ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2602d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the left parentheses ('('). 2603d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc; 2604d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2605d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the right parentheses (')'). 2606d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc; 2607d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2608d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The number of arguments used to construct the type. 2609d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs; 26101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2611ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2612d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 2613d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr **Args, 2614d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs, 2615d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2616d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26178dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2618ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 26198dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2620ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 2621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2622d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic: 26231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2624ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 2625d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 2626d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr **Args, 2627d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs, 2628d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2629d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26308dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 26318dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis unsigned NumArgs); 26328dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2633d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the type that is being constructed, as specified 2634d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// in the source code. 2635ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor QualType getTypeAsWritten() const { return Type->getType(); } 2636d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2637ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the type source information for the type being 2638ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// constructed. 2639ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2641d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the left parentheses ('(') that 2642d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// precedes the argument list. 2643d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 2644d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2645d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2646d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the right parentheses (')') that 2647d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// follows the argument list. 2648d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2649d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2650d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2651d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the number of arguments. 2652d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned arg_size() const { return NumArgs; } 2653d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2654d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor typedef Expr** arg_iterator; 2655d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2656d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_end() { return arg_begin() + NumArgs; } 2657d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26581dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall typedef const Expr* const * const_arg_iterator; 26591dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_begin() const { 26601dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return reinterpret_cast<const Expr* const *>(this + 1); 26611dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26621dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_end() const { 26631dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return arg_begin() + NumArgs; 26641dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26651dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 2666d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr *getArg(unsigned I) { 2667d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor assert(I < NumArgs && "Argument index out-of-range"); 2668d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return *(arg_begin() + I); 2669d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2670d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26711dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const Expr *getArg(unsigned I) const { 26721dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall assert(I < NumArgs && "Argument index out-of-range"); 26731dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return *(arg_begin() + I); 26741dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26751dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 26768dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void setArg(unsigned I, Expr *E) { 26778dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis assert(I < NumArgs && "Argument index out-of-range"); 26788dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis *(arg_begin() + I) = E; 26798dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 26808dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 268163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 2682ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2684d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2685d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2686d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2687d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2688d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor // Iterators 268963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 269063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this+1); 269163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumArgs); 269263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2693d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor}; 2694d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2695ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual 2696ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base 2697ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent. 2698aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2699aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or 2700aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses. It is only possible to get one of these with 2701aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided. 2702865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr { 27031c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The expression for the base pointer or class reference, 2704aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// e.g., the \c x in x.f. Can be null in implicit accesses. 27051c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor Stmt *Base; 27061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2707aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief The type of the base expression. Never null, even for 2708aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// implicit accesses. 2709aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 2710aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 27111c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Whether this member expression used the '->' operator or 27121c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// the '.' operator. 27133b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor bool IsArrow : 1; 27141c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2715e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether this member expression has info for explicit template 2716e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2717e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 27181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The location of the '->' or '.' operator. 27201c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation OperatorLoc; 27211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2722a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief The nested-name-specifier that precedes the member name, if any. 27237c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2725c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief In a qualified member access expression such as t->Base::f, this 27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// member stores the resolves of name lookup in the context of the member 2727c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// access expression, to be used at instantiation time. 2728c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 272946bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor /// FIXME: This member, along with the QualifierLoc, could 2730c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// be stuck into a structure that is optionally allocated at the end of 2731865d447ac6a4721ab58e898d014a21f2eff74b06John McCall /// the CXXDependentScopeMemberExpr, to save space in the common case. 2732c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierFoundInScope; 27331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The member to which this member expression refers, which 27351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// can be name, overloaded operator, or destructor. 2736a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// FIXME: could also be a template-id 27372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo; 27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2739e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2740e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2741e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2742e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2743e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2744e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2745e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2746e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<CXXDependentScopeMemberExpr*>(this) 2747e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2748e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2749e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2750865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2751aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 27523b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 27537c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2754e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 27553b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 27562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2757d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 27581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic: 2760865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2761bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr *Base, QualType BaseType, 2762bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool IsArrow, 2763bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation OperatorLoc, 27647c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2765bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 2766bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor DeclarationNameInfo MemberNameInfo); 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2768865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static CXXDependentScopeMemberExpr * 27691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Create(ASTContext &C, 2770aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 27713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 27727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2773e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 27743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 27752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2776d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 27771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27788dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXDependentScopeMemberExpr * 2779e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2780def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 27818dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2782aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 2783aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 2784aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 27854c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 2786aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 27871c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the base object of this member expressions, 27881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// e.g., the \c x in \c x.m. 2789aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() const { 2790aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 2791aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 2792aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 27931c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2794aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 2795aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 27961c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Determine whether this member expression used the '->' 27971c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// operator; otherwise, it used the '.' operator. 27981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor bool isArrow() const { return IsArrow; } 27991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 28001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the location of the '->' or '.' operator. 28011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 28021c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2803a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 2804a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// name. 2805ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 28077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 28081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28097c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 28107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// name, with source location information. 28117c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2812ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2814c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief Retrieve the first part of the nested-name-specifier that was 2815c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// found in the scope of the member access expression when the member access 2816c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// was initially parsed. 2817c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 2818c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// This function only returns a useful result when member access expression 28191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returned by this function describes what was found by unqualified name 2821c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// lookup for the identifier "Base" within the scope of the member access 2822c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself. At template instantiation time, this information is 2823c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// combined with the results of name lookup into the type of the object 2824c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself (the class type of x). 28251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamedDecl *getFirstQualifierFoundInScope() const { 2826c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor return FirstQualifierFoundInScope; 2827c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor } 28281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28291c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the name of the member that this expression 28301c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// refers to. 28312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { 28322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return MemberNameInfo; 28332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 28352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name of the member that this expression 28362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 28372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getMember() const { return MemberNameInfo.getName(); } 28381c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 28391c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // \brief Retrieve the location of the name of the member that this 28401c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // expression refers to. 28412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 28421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2843e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding the 2844e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member name, if any. 2845e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2846e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2847e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2848e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2849e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2850e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2851e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2852e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2853e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2854e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2855e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2856e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2857e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2858e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2859e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2860e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2861e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2862e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2863e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2864e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 2865e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2866e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 28673b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 28683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2869e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 287236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 2873b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2874e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2875b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 287636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 287736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 287836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 287936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 2880b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 288136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis return const_cast<CXXDependentScopeMemberExpr *>(this) 2882096832c5ed5b9106fa177ebc148489760c3bc496John McCall ->getExplicitTemplateArgs(); 2883096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2884096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2885096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2886096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2887096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2888b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2889096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2890096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 289136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 289236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 2893d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2894d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2895d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2896096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2897d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2898d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 28998dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis /// \brief Initializes the template arguments using the given structure. 29008dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2901096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(List); 29028dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 29038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 29043b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 29053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 2906833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2907096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 29083b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29103b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 29113b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 29121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2913096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 29143b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 29151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 291663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2917aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall SourceRange Range; 2918aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 2919aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 2920aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else if (getQualifier()) 29217c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 2922aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 29232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setBegin(MemberNameInfo.getBeginLoc()); 29241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2925aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (hasExplicitTemplateArgs()) 2926aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setEnd(getRAngleLoc()); 2927aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 29282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setEnd(MemberNameInfo.getEndLoc()); 2929aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return Range; 29301c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 29311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2933865d447ac6a4721ab58e898d014a21f2eff74b06John McCall return T->getStmtClass() == CXXDependentScopeMemberExprClass; 29341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 2935865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 29361c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 29371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // Iterators 293863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 293963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 294063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 294163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 29424045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 29434045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 29444045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 29451c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor}; 29461c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2947129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup 2948aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions. 2949aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2950aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit: 2951aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// struct A { 2952aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int a, b; 2953aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int explicitAccess() { return this->a + this->A::b; } 2954aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int implicitAccess() { return a + A::b; } 2955aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// }; 2956aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2957aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr. 2958aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a 2959aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static. 29607bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr { 2961129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether this member expression used the '->' operator or 2962129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// the '.' operator. 2963129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow : 1; 2964129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 2965129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether the lookup results contain an unresolved using 2966129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// declaration. 2967129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool HasUnresolvedUsing : 1; 2968129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 29697bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The expression for the base pointer or class reference, 29707bb12da2b0749eeebb21854c77877736969e59f2John McCall /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 29717bb12da2b0749eeebb21854c77877736969e59f2John McCall /// member expression 29727bb12da2b0749eeebb21854c77877736969e59f2John McCall Stmt *Base; 29737bb12da2b0749eeebb21854c77877736969e59f2John McCall 29747bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The type of the base expression; never null. 29757bb12da2b0749eeebb21854c77877736969e59f2John McCall QualType BaseType; 2976129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 2977129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief The location of the '->' or '.' operator. 2978129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc; 2979129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 2980bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 2981aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 2982129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 29834c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2984e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 29852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 29865a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 29875a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2988ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2989a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis UnresolvedMemberExpr(EmptyShell Empty) 2990a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2991a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis HasUnresolvedUsing(false), Base(0) { } 2992129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 29934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 2994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2995129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic: 2996129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static UnresolvedMemberExpr * 2997bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Create(ASTContext &C, bool HasUnresolvedUsing, 2998aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 2999129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 30004c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3001e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 30022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 30035a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 30045a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3005129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3006a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis static UnresolvedMemberExpr * 3007e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3008def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 3009a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3010aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 3011aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 3012aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 30134c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 3014aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3015129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the base object of this member expressions, 3016129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// e.g., the \c x in \c x.m. 3017aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() { 3018aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 3019aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 3020aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 30212f27bf854f0519810b34afd209089cc75536b757John McCall const Expr *getBase() const { 30222f27bf854f0519810b34afd209089cc75536b757John McCall assert(!isImplicitAccess()); 30232f27bf854f0519810b34afd209089cc75536b757John McCall return cast<Expr>(Base); 30242f27bf854f0519810b34afd209089cc75536b757John McCall } 3025129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3026aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 3027a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3028a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// \brief Determine whether the lookup results contain an unresolved using 3029a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// declaration. 3030a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3031aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3032129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Determine whether this member expression used the '->' 3033129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// operator; otherwise, it used the '.' operator. 3034129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool isArrow() const { return IsArrow; } 3035129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3036129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the location of the '->' or '.' operator. 3037129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation getOperatorLoc() const { return OperatorLoc; } 3038129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3039c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// \brief Retrieves the naming class of this lookup. 3040c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const; 3041c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 30422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the full name info for the member that this expression 30432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 30442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 30452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3046129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the name of the member that this expression 3047129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// refers to. 30487bb12da2b0749eeebb21854c77877736969e59f2John McCall DeclarationName getMemberName() const { return getName(); } 3049129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3050129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // \brief Retrieve the location of the name of the member that this 3051129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // expression refers to. 30527bb12da2b0749eeebb21854c77877736969e59f2John McCall SourceLocation getMemberLoc() const { return getNameLoc(); } 3053129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 305463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range = getMemberNameInfo().getSourceRange(); 3056aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 3057aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 30584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor else if (getQualifierLoc()) 30594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 3060aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3061129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (hasExplicitTemplateArgs()) 3062129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Range.setEnd(getRAngleLoc()); 3063129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return Range; 3064129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3065129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3066129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const Stmt *T) { 3067129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return T->getStmtClass() == UnresolvedMemberExprClass; 3068129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3069129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const UnresolvedMemberExpr *) { return true; } 3070129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3071129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Iterators 307263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 307363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 307463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 307563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3076129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}; 3077129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 30782e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 30792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// 30802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its 30812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant. 30822e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr { 30832e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool Value : 1; 30842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Stmt *Operand; 30852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceRange Range; 30862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3087c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl friend class ASTStmtReader; 3088c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl 30892e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic: 30902e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 30912e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceLocation Keyword, SourceLocation RParen) 3092f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3093f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent*/false, 3094bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent*/Val == CT_Dependent, 3095561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Val == CT_Dependent || Operand->isInstantiationDependent(), 3096bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 30976b219d082434394c1ac401390ec1d1967727815aSebastian Redl Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 30986b219d082434394c1ac401390ec1d1967727815aSebastian Redl { } 30996b219d082434394c1ac401390ec1d1967727815aSebastian Redl 31006b219d082434394c1ac401390ec1d1967727815aSebastian Redl CXXNoexceptExpr(EmptyShell Empty) 31016b219d082434394c1ac401390ec1d1967727815aSebastian Redl : Expr(CXXNoexceptExprClass, Empty) 31022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl { } 31032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Expr *getOperand() const { return static_cast<Expr*>(Operand); } 31052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 310663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 31072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool getValue() const { return Value; } 31092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const Stmt *T) { 31112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return T->getStmtClass() == CXXNoexceptExprClass; 31122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 31132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const CXXNoexceptExpr *) { return true; } 31142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl // Iterators 311663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Operand, &Operand + 1); } 31172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}; 31182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3119ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of 3120be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions. 3121be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3122be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an 3123be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example: 3124be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3125be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code 3126be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types> 3127be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) { 3128be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// f(static_cast<Types&&>(args)...); 3129be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// } 3130be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode 3131be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3132be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose 3133ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3134be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or 3135be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f. 3136be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr { 3137be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation EllipsisLoc; 3138ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 313967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// \brief The number of expansions that will be produced by this pack 314067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// expansion expression, if known. 314167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// 314267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// When zero, the number of expansions is not known. Otherwise, this value 314367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// is the number of expansions + 1. 314467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor unsigned NumExpansions; 3145ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3146be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Stmt *Pattern; 3147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3148be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor friend class ASTStmtReader; 314967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor friend class ASTStmtWriter; 3150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3151be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic: 315267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 315367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) 3154ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3155ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pattern->getObjectKind(), /*TypeDependent=*/true, 3156561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3158be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor EllipsisLoc(EllipsisLoc), 315967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3160be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Pattern(Pattern) { } 3161be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3162be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3163ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3164be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3165be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3166be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3167be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3168be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3169be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3170be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the location of the ellipsis that describes this pack 3171be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// expansion. 3172be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3173ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3174ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine the number of expansions that will be produced when 317567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// this pack expansion is instantiated, if already known. 317667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 317767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor if (NumExpansions) 317867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return NumExpansions - 1; 3179ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 318067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return llvm::Optional<unsigned>(); 318167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor } 3182ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 318363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 318463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(Pattern->getLocStart(), EllipsisLoc); 318563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3186be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3187be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const Stmt *T) { 3188be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor return T->getStmtClass() == PackExpansionExprClass; 3189be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor } 3190be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const PackExpansionExpr *) { return true; } 3191ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3192be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor // Iterators 319363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 319463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Pattern, &Pattern + 1); 319563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3196be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}; 3197ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3198e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3199e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 32007bb12da2b0749eeebb21854c77877736969e59f2John McCall if (isa<UnresolvedLookupExpr>(this)) 3201e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3202e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedLookupExpr>(this) + 1); 32037bb12da2b0749eeebb21854c77877736969e59f2John McCall else 3204e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3205e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedMemberExpr>(this) + 1); 32067bb12da2b0749eeebb21854c77877736969e59f2John McCall} 32077bb12da2b0749eeebb21854c77877736969e59f2John McCall 3208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter 3209ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack. 3210ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// 3211ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code 3212ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types> 3213ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count { 3214ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// static const unsigned value = sizeof...(Types); 3215ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// }; 3216ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode 3217ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr { 3218ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the 'sizeof' keyword. 3219ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation OperatorLoc; 3220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3221ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the name of the parameter pack. 3222ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc; 3223ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3224ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the closing parenthesis. 3225ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc; 3226ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3227ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The length of the parameter pack, if known. 3228ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3229ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// When this expression is value-dependent, the length of the parameter pack 3230ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// is unknown. When this expression is not value-dependent, the length is 3231ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// known. 3232ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length; 3233ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3234ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The parameter pack itself. 3235ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *Pack; 3236ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3237ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtReader; 3238ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtWriter; 3239ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3240ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic: 3241ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates a value-dependent expression that computes the length of 3242ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack. 3243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3244ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc) 3245ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3246ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/true, 3247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3248ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3249ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3250ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(0), Pack(Pack) { } 3251ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3252ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates an expression that computes the length of 3253ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack, which is already known. 3254ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3255ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc, 3256ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) 3257ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3258ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3259561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3260ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3261ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3262ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(Length), Pack(Pack) { } 3263ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3264ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Create an empty expression. 3265ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3266ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3267ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the 'sizeof' keyword. 3268ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 3269ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3270ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the parameter pack. 3271ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getPackLoc() const { return PackLoc; } 3272ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3273ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the right parenthesis. 3274ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3275ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3276ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the parameter pack. 3277ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *getPack() const { return Pack; } 3278ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3279ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the length of the parameter pack. 3280ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3281ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This routine may only be invoked when the expression is not 3282c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// value-dependent. 3283ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned getPackLength() const { 3284ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!isValueDependent() && 3285ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor "Cannot get the length of a value-dependent pack size expression"); 3286ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return Length; 3287ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3288ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 328963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 329063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(OperatorLoc, RParenLoc); 329163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3293ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const Stmt *T) { 3294ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return T->getStmtClass() == SizeOfPackExprClass; 3295ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3296ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const SizeOfPackExpr *) { return true; } 3297ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3298ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Iterators 329963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3300ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 3301c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 330291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter 330391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument. 330491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr { 330591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replaced parameter. 330691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *Param; 330791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 330891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replacement expression. 330991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Stmt *Replacement; 331091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 331191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The location of the non-type template parameter reference. 331291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation NameLoc; 331391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 33147110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 33157110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 3316ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 33177110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 33187110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 331991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic: 3320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmExpr(QualType type, 332191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall ExprValueKind valueKind, 332291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation loc, 332391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *param, 332491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *replacement) 332591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 332691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isTypeDependent(), replacement->isValueDependent(), 332791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isInstantiationDependent(), 332891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->containsUnexpandedParameterPack()), 332991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Param(param), Replacement(replacement), NameLoc(loc) {} 333091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 333191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation getNameLoc() const { return NameLoc; } 333291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceRange getSourceRange() const { return NameLoc; } 333391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 333491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *getReplacement() const { return cast<Expr>(Replacement); } 3335ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 333691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *getParameter() const { return Param; } 333791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 333891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall static bool classof(const Stmt *s) { 333991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 334091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3341ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const SubstNonTypeTemplateParmExpr *) { 3342ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 334391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3344ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 334591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Iterators 334691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall child_range children() { return child_range(&Replacement, &Replacement+1); } 334791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}; 334891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 3349c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that 3350c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack. 3351c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// 3352c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3353c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template 3354ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this node node is used to represent a non-type template 3355c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3356c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3357c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3358c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3359c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying 3360c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index. 3361c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr { 3362c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The non-type template parameter pack itself. 3363c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param; 3364ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3365c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief A pointer to the set of template arguments that this 3366c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// parameter pack is instantiated with. 3367c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument *Arguments; 3368ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3369c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3370c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor unsigned NumArguments; 3371ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3372c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The location of the non-type template parameter pack reference. 3373c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc; 3374ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 33757110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 3376c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor friend class ASTStmtReader; 3377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 33787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3379ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3380c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic: 3381ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmPackExpr(QualType T, 3382c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param, 3383c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc, 3384c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument &ArgPack); 3385ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3386c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the non-type template parameter pack being substituted. 3387c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3388c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 3389c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the location of the parameter pack name. 3390c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation getParameterPackLocation() const { return NameLoc; } 3391ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3392c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the template argument pack containing the substituted 3393c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// template arguments. 3394c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor TemplateArgument getArgumentPack() const; 3395c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 339663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return NameLoc; } 3397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3398c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor static bool classof(const Stmt *T) { 3399c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3400c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3401ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const SubstNonTypeTemplateParmPackExpr *) { 3402ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 3403c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3404ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3405c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Iterators 340663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3407c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}; 340803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 340903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that 341003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it. 341103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 341203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address 341303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a 341403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g., 341503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 341603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code 341703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0; 341803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode 341903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 342003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 342103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference 342203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 342303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding 342403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues. 342503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr { 342603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief The temporary-generating expression whose value will be 342703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// materialized. 342803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Stmt *Temporary; 3429ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 343003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtReader; 343103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtWriter; 3432ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 343303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic: 3434ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3435b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor bool BoundToLvalueReference) 3436b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor : Expr(MaterializeTemporaryExprClass, T, 343703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 343803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->isTypeDependent(), Temporary->isValueDependent(), 3439561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Temporary->isInstantiationDependent(), 344003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->containsUnexpandedParameterPack()), 344103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary(Temporary) { } 3442ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(EmptyShell Empty) 344403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor : Expr(MaterializeTemporaryExprClass, Empty) { } 3445ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 344603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Retrieve the temporary-generating subexpression whose value will 344703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// be materialized into a glvalue. 344803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3449ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 345003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Determine whether this materialized temporary is bound to an 345103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// lvalue reference; otherwise, it's bound to an rvalue reference. 3452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isBoundToLvalueReference() const { 345303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getValueKind() == VK_LValue; 345403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3455ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 345603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SourceRange getSourceRange() const { return Temporary->getSourceRange(); } 3457ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 345803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor static bool classof(const Stmt *T) { 345903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return T->getStmtClass() == MaterializeTemporaryExprClass; 346003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3461ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const MaterializeTemporaryExpr *) { 3462ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 346303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3464ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 346503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Iterators 346603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor child_range children() { return child_range(&Temporary, &Temporary + 1); } 346703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}; 3468ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 34695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 34705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3472