ExprCXX.h revision 30a2e16f6c27f888dd11eba6bbbae1e980078fcb
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 17478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h" 19d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h" 2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/UnresolvedSet.h" 2101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/ExpressionTraits.h" 2201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h" 2301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/TypeTraits.h" 24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl; 29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl; 30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl; 31aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary; 32aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo; 332fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass UuidAttr; 344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions. 371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator 403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax. 413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator 433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the 453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call. 463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever 483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the 493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and 503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template 513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time. 52b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr { 53063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief The overloaded operator. 54063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind Operator; 554548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange Range; 56063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 57be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Record the FP_CONTRACT state that applies to this operator call. Only 58be9af1288881110e406b87914162eaa59f1e5918Lang Hames // meaningful for floating point types. For other types this value can be 59be9af1288881110e406b87914162eaa59f1e5918Lang Hames // set to false. 60be9af1288881110e406b87914162eaa59f1e5918Lang Hames unsigned FPContractable : 1; 61be9af1288881110e406b87914162eaa59f1e5918Lang Hames 624548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange getSourceRangeImpl() const LLVM_READONLY; 63b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic: 641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 66be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation operatorloc, bool fpContractable) 673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK, 68f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall operatorloc), 69be9af1288881110e406b87914162eaa59f1e5918Lang Hames Operator(Op), FPContractable(fpContractable) { 704548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis Range = getSourceRangeImpl(); 714548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis } 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 73ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(C, CXXOperatorCallExprClass, Empty) { } 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 76b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator - Returns the kind of overloaded operator that this 77b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// expression refers to. 78063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind getOperator() const { return Operator; } 79b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperatorLoc - Returns the location of the operator symbol in 81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// the expression. When @c getOperator()==OO_Call, this is the 82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// location of the right parentheses; when @c 83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator()==OO_Subscript, this is the location of the right 84b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// bracket. 85b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SourceLocation getOperatorLoc() const { return getRParenLoc(); } 86b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 874548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange getSourceRange() const { return Range; } 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXOperatorCallExprClass; 91b4609806e9232593ece09ce08b630836e825865cDouglas Gregor } 924548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis 93be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Set the FP contractability status of this operator. Only meaningful for 94be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 95be9af1288881110e406b87914162eaa59f1e5918Lang Hames void setFPContractable(bool FPC) { FPContractable = FPC; } 96be9af1288881110e406b87914162eaa59f1e5918Lang Hames 97be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Get the FP contractability status of this operator. Only meaningful for 98be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 99be9af1288881110e406b87914162eaa59f1e5918Lang Hames bool isFPContractable() const { return FPContractable; } 100be9af1288881110e406b87914162eaa59f1e5918Lang Hames 1014548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis friend class ASTStmtReader; 1024548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis friend class ASTStmtWriter; 103b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}; 104b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 10588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that 10688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()" 10788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax 10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member 10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains 11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the 11188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including 11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument). 11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr { 11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic: 1153b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args, 116f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation RP) 1173b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {} 11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 1191817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 1201817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1211817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner 12288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// getImplicitObjectArgument - Retrieves the implicit object 12388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// argument for the member call. For example, in "x.f(5)", this 12488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// operation would return "x". 125b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek Expr *getImplicitObjectArgument() const; 126ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 127b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek /// Retrieves the declaration of the called method. 128b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek CXXMethodDecl *getMethodDecl() const; 12988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 130007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 131007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// the implicit object argument. Note that this is may not be the same 132007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// declaration as that of the class context of the CXXMethodDecl which this 133007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// function is calling. 134007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// FIXME: Returns 0 for member pointer call exprs. 1350cf3c0eecbff007cea2750c113894b47d9e09f33David Blaikie CXXRecordDecl *getRecordDecl() const; 136007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth 1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor return T->getStmtClass() == CXXMemberCallExprClass; 13988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor } 14088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor}; 14188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr { 144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate: 145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne enum { CONFIG, END_PREARG }; 146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic: 148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 1493b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 1503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation RP) 1513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) { 152e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne setConfig(Config); 153e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 154e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 155e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 156e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 157e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 158e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne const CallExpr *getConfig() const { 159e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return cast_or_null<CallExpr>(getPreArg(CONFIG)); 160e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 161e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 162e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 163e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 164e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const Stmt *T) { 165e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return T->getStmtClass() == CUDAKernelCallExprClass; 166e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 167e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}; 168e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 16949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 17049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 17149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast. 17249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 17349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes 17449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr, 17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr { 1771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate: 1781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; // the location of the casting op 1791d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc; // the location of the right parenthesis 180ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 182f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 183f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 1841d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 1851d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 1861d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 1871d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor RParenLoc(RParenLoc) {} 18849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 189f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 190f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(SC, Shell, PathSize) { } 191ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1921d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor friend class ASTStmtReader; 193ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor const char *getCastName() const; 19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 197a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// \brief Retrieve the location of the cast operator keyword, e.g., 198a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// "static_cast". 199a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor SourceLocation getOperatorLoc() const { return Loc; } 200a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor 2011d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor /// \brief Retrieve the location of the closing parenthesis. 2021d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 203ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 204aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 2051d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor return SourceRange(Loc, RParenLoc); 2061060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor switch (T->getStmtClass()) { 20949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXStaticCastExprClass: 21049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXDynamicCastExprClass: 21149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXReinterpretCastExprClass: 21249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXConstCastExprClass: 21349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 21449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor default: 21549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return false; 21649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 2171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 21849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 21949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression 221ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]). 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 22349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g., 22449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0). 22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr { 226f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 227f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize, TypeSourceInfo *writtenTy, 2281d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 229f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 2301d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 232f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 233f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 234f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 235f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 237f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 239ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2401d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 242f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 243ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXStaticCastExprClass; 24649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 24749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 24849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 2501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 25149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast. 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 25349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g., 25449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr). 25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr { 256f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 257f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 2581d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 259f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 2601d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 26149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 262f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 263f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 264f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 265f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 266f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 267f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, Expr *Op, 268f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 269ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2701d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 272f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 273f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 274ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2750fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson bool isAlwaysNull() const; 2760fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson 2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXDynamicCastExprClass; 27949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 28049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 28149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 28249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 28349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view 28449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time. 2851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 28649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g., 28749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr). 28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 289f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 290f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, 291ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 2921d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 293f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 2941d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor pathSize, writtenTy, l, RParenLoc) {} 29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 296f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 297f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 298f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 299f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 300f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 301f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, 302f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *Op, const CXXCastPath *Path, 303ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 3041d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 305f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 306f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 307ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 30949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXReinterpretCastExprClass; 31049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 31149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 31249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 31349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 31449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value. 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 31649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g., 31749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar). 31849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr { 319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 3211d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 322ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 3231d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor 0, writtenTy, l, RParenLoc) {} 32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 325ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig explicit CXXConstCastExpr(EmptyShell Empty) 326f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 327f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 328f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, Expr *Op, 331ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 3321d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 334ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 33649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXConstCastExprClass; 33749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 3381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3409fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal]) 3419fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]). 3429fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// 3439fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this 3449fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better 3459fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal. 3469fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// 3479fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at 3489fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent. 3499fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr { 3509fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// \brief The location of a ud-suffix within the literal. 3519fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith SourceLocation UDSuffixLoc; 3529fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic: 3543b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args, 3559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith QualType T, ExprValueKind VK, SourceLocation LitEndLoc, 3569fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith SourceLocation SuffixLoc) 3573b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc), 3583b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer UDSuffixLoc(SuffixLoc) {} 3599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty) 3609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith : CallExpr(C, UserDefinedLiteralClass, Empty) {} 3619fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// The kind of literal operator which is invoked. 3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith enum LiteralOperatorKind { 3649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Raw, ///< Raw form: operator "" X (const char *) 3659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Template, ///< Raw form: operator "" X<cs...> () 3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Integer, ///< operator "" X (unsigned long long) 3679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Floating, ///< operator "" X (long double) 3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_String, ///< operator "" X (const CharT *, size_t) 3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Character ///< operator "" X (CharT) 3709fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith }; 3719fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getLiteralOperatorKind - Returns the kind of literal operator invocation 3739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// which this expression represents. 3749fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LiteralOperatorKind getLiteralOperatorKind() const; 3759fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getCookedLiteral - If this is not a raw user-defined literal, get the 3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// underlying cooked literal (representing the literal with the suffix 3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// removed). 3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith Expr *getCookedLiteral(); 3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith const Expr *getCookedLiteral() const { 3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); 3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith } 3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3840265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getLocStart() const { 3850265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara if (getLiteralOperatorKind() == LOK_Template) 3860265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara return getRParenLoc(); 3870265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara return getArg(0)->getLocStart(); 3880265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara } 3890265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getLocEnd() const { return getRParenLoc(); } 3900265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceRange getSourceRange() const { 3910265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara return SourceRange(getLocStart(), getLocEnd()); 3920265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara } 3930265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara 3940265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara 3959fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression. 3969fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// For a string literal, there may be multiple identical suffixes. This 3979fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// returns the first. 3980265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } 3999fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4009fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getUDSuffix - Returns the ud-suffix specified for this literal. 4019fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith const IdentifierInfo *getUDSuffix() const; 4029fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4039fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith static bool classof(const Stmt *S) { 4049fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return S->getStmtClass() == UserDefinedLiteralClass; 4059fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith } 4069fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4079fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith friend class ASTStmtReader; 4089fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith friend class ASTStmtWriter; 4099fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith}; 4109fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 4131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr { 4141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool Value; 4151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; 4161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 4171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 418bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 419561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 420f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(val), Loc(l) {} 4218b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 422eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXBoolLiteralExpr(EmptyShell Empty) 423eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXBoolLiteralExprClass, Empty) { } 424eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool getValue() const { return Value; } 426eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setValue(bool V) { Value = V; } 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 428aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 430eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 431eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 432eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXBoolLiteralExprClass; 4351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 43863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 4401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 4416e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 4426e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr { 4436e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl SourceLocation Loc; 4446e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic: 4456e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 446bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 447561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 448f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) {} 4496e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 450eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 451eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXNullPtrLiteralExprClass, Empty) { } 452eb7f96141f754150a92433286fa385910a22f494Sam Weinig 453aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 4546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 455eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 456eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 457eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const Stmt *T) { 4596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return T->getStmtClass() == CXXNullPtrLiteralExprClass; 4606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl } 4616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 46263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl}; 4646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 465c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 466c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly 467c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression. 468c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 469c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr) 470c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr { 471c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate: 47257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 473c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SourceRange Range; 474c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 475c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic: 47657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 477f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 47857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 47957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor false, 48057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is value-dependent if the type or expression are dependent 481bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->isDependentType(), 482561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 483bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 48457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 48657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 487f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 4882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is never type-dependent (C++ [temp.dep.expr]p4) 489bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, 4902850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is value-dependent if the type or expression are dependent 491bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->isTypeDependent() || Operand->isValueDependent(), 492561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 493bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 49457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 495c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 49614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner CXXTypeidExpr(EmptyShell Empty, bool isExpr) 49714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner : Expr(CXXTypeidExprClass, Empty) { 49814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner if (isExpr) 49914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (Expr*)0; 50014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner else 50114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (TypeSourceInfo*)0; 50214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 503ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5040d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith /// Determine whether this typeid has a type operand which is potentially 5050d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith /// evaluated, per C++11 [expr.typeid]p3. 5060d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith bool isPotentiallyEvaluated() const; 5070d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith 50857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 509ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 51057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieves the type operand of this typeid() expression after 51157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 51257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor QualType getTypeOperand() const; 51357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor 51457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieve source information for the type operand. 51557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *getTypeOperandSourceInfo() const { 516c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 51757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return Operand.get<TypeSourceInfo *>(); 518c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 51914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner 52014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 52114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 52214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = TSI; 52314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 524ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 52514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Expr *getExprOperand() const { 526c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 52757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 528c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 529ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 530030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner void setExprOperand(Expr *E) { 531030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 532030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner Operand = E; 533030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner } 534ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 535aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 53614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setSourceRange(SourceRange R) { Range = R; } 537ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 538c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const Stmt *T) { 539c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return T->getStmtClass() == CXXTypeidExprClass; 540c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 541c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 542c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Iterators 54363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 54463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 54563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 54663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 54763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 548c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl}; 549c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 55001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 55101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression. 55201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 55301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 55401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr { 55501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate: 55601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 55701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceRange Range; 55801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 55901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic: 56001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 5612e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->getType()->isDependentType(), 563561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 564bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 56501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 56701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 5682e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 569bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->isTypeDependent(), 570561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 571bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 57201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 57301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 57401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(EmptyShell Empty, bool isExpr) 57501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet : Expr(CXXUuidofExprClass, Empty) { 57601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (isExpr) 57701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (Expr*)0; 57801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet else 57901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (TypeSourceInfo*)0; 58001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 581ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 58201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 583ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 58401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieves the type operand of this __uuidof() expression after 58501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// various required adjustments (removing reference types, cv-qualifiers). 58601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet QualType getTypeOperand() const; 58701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 58801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieve source information for the type operand. 58901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *getTypeOperandSourceInfo() const { 59001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 59101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return Operand.get<TypeSourceInfo *>(); 59201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 59301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 59401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 59501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 59601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = TSI; 59701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 598ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 59901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *getExprOperand() const { 60001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 60101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return static_cast<Expr*>(Operand.get<Stmt *>()); 60201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 603ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 60401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setExprOperand(Expr *E) { 60501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 60601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = E; 60701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 60801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 609aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 61001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setSourceRange(SourceRange R) { Range = R; } 611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 61201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const Stmt *T) { 61301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return T->getStmtClass() == CXXUuidofExprClass; 61401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 61501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 616c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none. 617c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber static UuidAttr *GetUuidAttrOfType(QualType QT); 618c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber 61901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Iterators 62063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 62163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 62263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 62363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 62463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 62501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}; 62601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 627796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a 628796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is 629796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example: 630796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// 631796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code 632796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo { 633796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public: 634796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void bar(); 635796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void test() { this->bar(); } 636796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// }; 637796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode 638796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr { 639796da18402f286b897782a298ae3b20c459c102eDouglas Gregor SourceLocation Loc; 640828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool Implicit : 1; 641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 642796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic: 643828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 644f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 6452850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // 'this' is type-dependent if the class type of the enclosing 6462850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // member function is dependent (C++ [temp.dep.expr]p2) 647bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 648561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 649bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 650828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor Loc(L), Implicit(isImplicit) { } 651796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 6522fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 6532fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 6542fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner SourceLocation getLocation() const { return Loc; } 6552fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 6562fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 657aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 658796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 659828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool isImplicit() const { return Implicit; } 660828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor void setImplicit(bool I) { Implicit = I; } 661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 663796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return T->getStmtClass() == CXXThisExprClass; 664796da18402f286b897782a298ae3b20c459c102eDouglas Gregor } 665796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 666796da18402f286b897782a298ae3b20c459c102eDouglas Gregor // Iterators 66763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 668796da18402f286b897782a298ae3b20c459c102eDouglas Gregor}; 669796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 6701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 6711060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 'throw' and 'throw' assignment-expression. When 6721060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// assignment-expression isn't present, Op will be null. 6731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 6741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr { 6751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Op; 6761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation ThrowLoc; 677bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Whether the thrown variable (if any) is in scope. 678bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned IsThrownVariableInScope : 1; 679ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 680bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor friend class ASTStmtReader; 681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6821060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 6831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Ty is the void type which is used as the result type of the 6841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // exepression. The l is the location of the throw keyword. expr 6851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // can by null, if the optional expression to throw isn't present. 686bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 687bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) : 688bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 689561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor expr && expr->isInstantiationDependent(), 690bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor expr && expr->containsUnexpandedParameterPack()), 691bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 6922fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 6932fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 6941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 6951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 69642e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor 69742e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor SourceLocation getThrowLoc() const { return ThrowLoc; } 6981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 699bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Determines whether the variable thrown by this expression (if any!) 700bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// is within the innermost try block. 701bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// 702bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// This information is required to determine whether the NRVO can apply to 703bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// this variable. 704bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 706aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 7071060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek if (getSubExpr() == 0) 7081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, ThrowLoc); 7091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 7101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 7131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXThrowExprClass; 7141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 71763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 71863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Op, Op ? &Op+1 : &Op); 71963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7201060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 7211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 7231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding 7241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly 7251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters. 7261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr { 72765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// \brief The parameter whose default is being used. 72865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// 729ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// When the bit is set, the subexpression is stored after the 73065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 73165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// actual default expression is the subexpression. 73265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 734036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// \brief The location where the default argument expression was used. 735036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc; 736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 737036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 738ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(SC, 73965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor param->hasUnparsedDefaultArg() 74065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ? param->getType().getNonReferenceType() 7412333f7727f97018d6742e1e0938133bcfad967abEli Friedman : param->getDefaultArg()->getType(), 742dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall param->getDefaultArg()->getValueKind(), 743561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor param->getDefaultArg()->getObjectKind(), false, false, false, false), 744036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param(param, false), Loc(Loc) { } 74565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor 746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 747036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Expr *SubExpr) 748dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall : Expr(SC, SubExpr->getType(), 749dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall SubExpr->getValueKind(), SubExpr->getObjectKind(), 750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false, false, false, false), 751bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Param(param, true), Loc(Loc) { 75265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor *reinterpret_cast<Expr **>(this + 1) = SubExpr; 75365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 754ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7551060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 756030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 757030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner 758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Param is the parameter whose default argument is used by this 7601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // expression. 761036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 762036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 763036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 764f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson } 7651060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 76665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // Param is the parameter whose default argument is used by this 76765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // expression, and SubExpr is the expression that will actually be used. 768ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static CXXDefaultArgExpr *Create(ASTContext &C, 769036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc, 770ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ParmVarDecl *Param, 77165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor Expr *SubExpr); 772ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the parameter that the argument was created from. 77465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor const ParmVarDecl *getParam() const { return Param.getPointer(); } 77565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ParmVarDecl *getParam() { return Param.getPointer(); } 776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the actual argument to the function call. 778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const Expr *getExpr() const { 77965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 78065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr const * const*> (this + 1); 781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 78265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getExpr() { 78465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 78565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr **> (this + 1); 786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 78765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 7881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 789ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the location where this default argument was actually 790036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// used. 791036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation getUsedLocation() const { return Loc; } 792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 793aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 7941060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Default argument expressions have no representation in the 7951060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // source, so they have an empty source range. 7961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(); 7971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 79863b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer 79963b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 8001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 8011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 8021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXDefaultArgExprClass; 8031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 8041060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 8051060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 80663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 8078a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis 80860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 8093397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 8101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 811987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 812c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary. 813c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary { 814c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson /// Destructor - The destructor that needs to be called. 815b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor; 8161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 817b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson CXXTemporary(const CXXDestructorDecl *destructor) 818c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson : Destructor(destructor) { } 819c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson 820c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic: 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXTemporary *Create(ASTContext &C, 822b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor); 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 824f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXDestructorDecl *getDestructor() const { return Destructor; } 82576f3f69db1416425070177243e9f390122c553e0Richard Smith void setDestructor(const CXXDestructorDecl *Dtor) { 82676f3f69db1416425070177243e9f390122c553e0Richard Smith Destructor = Dtor; 82776f3f69db1416425070177243e9f390122c553e0Richard Smith } 828c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson}; 829fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 830ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary. 831ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 832ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be 833ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example: 834ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 835ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code 836ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// struct S { 837ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// S() { } // User defined constructor makes S non-POD. 838ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// ~S() { } // User defined destructor makes it non-trivial. 839ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// }; 840ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// void test() { 841ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 842ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// } 843ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode 844fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr { 845fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson CXXTemporary *Temp; 8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 847fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Stmt *SubExpr; 848fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 849bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 850bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 851ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 852bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->isValueDependent(), 853561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SubExpr->isInstantiationDependent(), 854bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->containsUnexpandedParameterPack()), 855bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Temp(temp), SubExpr(SubExpr) { } 85688eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson 857fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic: 858d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner CXXBindTemporaryExpr(EmptyShell Empty) 859d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 862fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr* SubExpr); 8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson CXXTemporary *getTemporary() { return Temp; } 865f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXTemporary *getTemporary() const { return Temp; } 866d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner void setTemporary(CXXTemporary *T) { Temp = T; } 867f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson 868fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 869fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 87088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 871fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 872aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 87396be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 87496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 875fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 876fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Implement isa/cast/dyncast/etc. 877fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const Stmt *T) { 878fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson return T->getStmtClass() == CXXBindTemporaryExprClass; 879fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson } 880fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 881fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Iterators 88263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 883fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson}; 884fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 8850982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a call to a C++ constructor. 88615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr { 88772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic: 88872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson enum ConstructionKind { 88972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_Complete, 89072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_NonVirtualBase, 891059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_VirtualBase, 892059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_Delegating 89372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson }; 894ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 89572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate: 89615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson CXXConstructorDecl *Constructor; 89715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 89899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc; 899428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange; 900a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor unsigned NumArgs : 16; 90116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool Elidable : 1; 9027cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 9035b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization : 1; 90416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool ZeroInitialization : 1; 90572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson unsigned ConstructKind : 2; 90615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson Stmt **Args; 9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 908bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected: 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 91099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 911bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson CXXConstructorDecl *d, bool elidable, 9123b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 9137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 9145b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 9155b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 9165b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 9175b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 918bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson 9196d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 9206d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis CXXConstructExpr(StmtClass SC, EmptyShell Empty) 9215b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 9225b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl HadMultipleCandidates(false), ListInitialization(false), 9235b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ZeroInitialization(false), ConstructKind(0), Args(0) 9245b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 9256d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 92615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic: 9276d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 9286d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXConstructExpr(EmptyShell Empty) 9296d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis : Expr(CXXConstructExprClass, Empty), Constructor(0), 9305b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl NumArgs(0), Elidable(false), HadMultipleCandidates(false), 9315b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ListInitialization(false), ZeroInitialization(false), 9325b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructKind(0), Args(0) 9335b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 9346d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 9358e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson static CXXConstructExpr *Create(ASTContext &C, QualType T, 93699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructorDecl *D, bool Elidable, 9383b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 9397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 9405b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 9415b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 9425b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 9435b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor CXXConstructorDecl* getConstructor() const { return Constructor; } 94639da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 94899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation getLocation() const { return Loc; } 94999a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor void setLocation(SourceLocation Loc) { this->Loc = Loc; } 950ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 951d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor /// \brief Whether this construction is elidable. 952d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor bool isElidable() const { return Elidable; } 95339da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setElidable(bool E) { Elidable = E; } 9547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 9557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Whether the referred constructor was resolved from 9567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// an overloaded set having size greater than 1. 9577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { return HadMultipleCandidates; } 9587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 9597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 9605b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl /// \brief Whether this constructor call was written as list-initialization. 9615b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool isListInitialization() const { return ListInitialization; } 9625b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl void setListInitialization(bool V) { ListInitialization = V; } 9635b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl 96416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// \brief Whether this construction first requires 96516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// zero-initialization before the initializer is called. 96616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool requiresZeroInitialization() const { return ZeroInitialization; } 96716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor void setRequiresZeroInitialization(bool ZeroInit) { 96816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor ZeroInitialization = ZeroInit; 96916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor } 970ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 9719db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// \brief Determines whether this constructor is actually constructing 9729db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// a base class (rather than a complete object). 97324eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson ConstructionKind getConstructionKind() const { 97424eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson return (ConstructionKind)ConstructKind; 97572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 976ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setConstructionKind(ConstructionKind CK) { 97772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson ConstructKind = CK; 97872e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 979ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 98015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ExprIterator arg_iterator; 98115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ConstExprIterator const_arg_iterator; 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_begin() { return Args; } 98415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_end() { return Args + NumArgs; } 98515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_begin() const { return Args; } 98615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_end() const { return Args + NumArgs; } 98715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 988a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 98915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson unsigned getNumArgs() const { return NumArgs; } 99015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 991bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson /// getArg - Return the specified argument. 992bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson Expr *getArg(unsigned Arg) { 993bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 994bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 995bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 996bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson const Expr *getArg(unsigned Arg) const { 997bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 998bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 999bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10012eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian /// setArg - Set the specified argument. 10022eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian void setArg(unsigned Arg, Expr *ArgExpr) { 10032eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian assert(Arg < NumArgs && "Arg access out of range!"); 10042eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian Args[Arg] = ArgExpr; 10052eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian } 10062eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian 1007aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 1008428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange getParenRange() const { return ParenRange; } 1009a770a4daf77037b5526dba1c447d61acf0aba01aDaniel Jasper void setParenRange(SourceRange Range) { ParenRange = Range; } 101015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1012524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson return T->getStmtClass() == CXXConstructExprClass || 1013524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson T->getStmtClass() == CXXTemporaryObjectExprClass; 101415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson } 10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson // Iterators 101763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 101863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Args[0], &Args[0]+NumArgs); 101963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10206d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 102160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 102215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson}; 102315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 10240982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an explicit C++ type conversion that uses "functional" 10250982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// notation (C++ [expr.type.conv]). 10260982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 10270982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Example: 10280982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 10290982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// x = int(0.5); 10300982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 103149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr { 1032987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation TyBeginLoc; 1033987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1034f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1035f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1036f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy, 10371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation tyBeginLoc, CastKind kind, 1038f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *castExpr, unsigned pathSize, 1039ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation rParenLoc) 1040f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1041f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall castExpr, pathSize, writtenTy), 10420aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 10430aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson 1044f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1045f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1046f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1047f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 1048f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 1049f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 1050f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *Written, 1051f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation TyBeginLoc, 1052f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Op, 1053f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 1054f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation RPLoc); 1055f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 1056f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 1057ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1058987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1059ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1060987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getRParenLoc() const { return RParenLoc; } 1061ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setRParenLoc(SourceLocation L) { RParenLoc = L; } 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1063aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1064987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis return SourceRange(TyBeginLoc, RParenLoc); 1065987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXFunctionalCastExprClass; 1068987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1069987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1070987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1071506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a 1072506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object. 1073506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast 1075506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1076ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the 1077ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr. 1078506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example: 1079506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code 1080506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); } 1081506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 1082506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() { 1083506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1084506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// }; 1085506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode 1086524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr { 1087ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 1088506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1089506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic: 10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1091ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 10923b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 1093428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange parenRange, 10947cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 10951c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor bool ZeroInitialization = false); 10966d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1097ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1098506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1099ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1100ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1101aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 1102ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1104506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor return T->getStmtClass() == CXXTemporaryObjectExprClass; 1105506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor } 11066d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 110760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 1108506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor}; 1109506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 111001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object 111101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later. 111201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 111301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example: 111401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code 111501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) { 111601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// values.erase(std::remove_if(values.begin(), values.end(), 1117d9ffa0c39ff9c71e2729eac4cdcf32b377c1d3b6Dmitri Gribenko/// [=](double value) { return value > cutoff; }); 111801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// } 111901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode 112001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 112101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying 112201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function 112301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a 112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either 112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square 112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression. 112701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr { 112801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor enum { 112901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indicate that the given 113001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture was implicit. 113101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_Implicit = 0x01, 113201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indciate that the 113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// given capture was by-copy. 113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_ByCopy = 0x02 113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The source range that covers the lambda introducer ([...]). 113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange; 114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 11417ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief The number of captures. 11427ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned NumCaptures : 16; 11437ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 114401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The default capture kind, which is a value of type 114501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// LambdaCaptureDefault. 114601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned CaptureDefault : 2; 114701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Whether this lambda had an explicit parameter list vs. an 114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit (and empty) parameter list. 115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned ExplicitParams : 1; 115101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1152dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had the result type explicitly specified. 1153dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor unsigned ExplicitResultType : 1; 1154dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 1155dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether there are any array index variables stored at the end of 1156dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// this lambda expression. 11577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned HasArrayIndexVars : 1; 11587ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The location of the closing brace ('}') that completes 116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// the lambda. 116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 116201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// The location of the brace is also available by looking up the 116301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// function call operator in the lambda class. However, it is 116401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stored here to improve the performance of getSourceRange(), and 116501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// to avoid having to deserialize the function call operator from a 116601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// module file just to determine the source range. 116701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace; 116801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 11697ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // Note: The capture initializers are stored directly after the lambda 11707ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // expression, along with the index variables used to initialize by-copy 11717ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // array captures. 11727ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 117301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 117401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Describes the capture of either a variable or 'this'. 117501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor class Capture { 117601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 117701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation Loc; 117801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc; 11799daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 118001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 118101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 11829daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 118301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor public: 118401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Create a new capture. 118501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 118601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Loc The source location associated with this capture. 118701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 118801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Kind The kind of capture (this, byref, bycopy). 118901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 119001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Implicit Whether the capture was implicit or explicit. 119101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 119201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Var The local variable being captured, or null if capturing this. 119301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 119401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param EllipsisLoc The location of the ellipsis (...) for a 119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture that is a pack expansion, or an invalid source 119601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// location to indicate that this is not a pack expansion. 119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture(SourceLocation Loc, bool Implicit, 119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind Kind, VarDecl *Var = 0, 119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc = SourceLocation()); 120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the kind of capture. 120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind getCaptureKind() const; 120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles the C++ 'this' 120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// pointer. 120601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesThis() const { return VarAndBits.getPointer() == 0; } 120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles a variable. 120901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 121101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the declaration of the local variable being 121201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captured. 121301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// This operation is only valid if this capture does not capture 121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 'this'. 121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor VarDecl *getCapturedVar() const { 121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(!capturesThis() && "No variable available for 'this' capture"); 121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return VarAndBits.getPointer(); 121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an implicit capture (not 122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// written between the square brackets introducing the lambda). 122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an explicit capture, written 122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// between the square brackets introducing the lambda. 122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isExplicit() const { return !isImplicit(); } 122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source location of the capture. 123001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 123101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// For an explicit capture, this returns the location of the 123201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit capture in the source. For an implicit capture, this 123301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// returns the location at which the variable or 'this' was first 123401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// used. 123501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getLocation() const { return Loc; } 123601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 123701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture is a pack expansion, 123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which captures a function parameter pack. 123901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isPackExpansion() const { return EllipsisLoc.isValid(); } 124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the location of the ellipsis for a capture 124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// that is a pack expansion. 124301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getEllipsisLoc() const { 124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 124501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return EllipsisLoc; 124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 124701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 124801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate: 125001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a lambda expression. 125101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaExpr(QualType T, SourceRange IntroducerRange, 125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1255dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 125601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 12579daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 12589daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 1259612409ece080e814f79e06772c690d603f45fbd6Richard Smith SourceLocation ClosingBrace, 1260612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool ContainsUnexpandedParameterPack); 126101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12629d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct an empty lambda expression. 12639d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 12649d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor : Expr(LambdaExprClass, Empty), 12659d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 12669d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor ExplicitResultType(false), HasArrayIndexVars(true) { 12679d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor getStoredStmts()[NumCaptures] = 0; 12689d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 12699d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 12707ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor Stmt **getStoredStmts() const { 12717ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 12727ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 12737ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 12747ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the mapping from captures to the first array index 12757ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// variable. 12767ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned *getArrayIndexStarts() const { 12777ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 12787ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 12797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 12807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the complete set of array-index variables. 12817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor VarDecl **getArrayIndexVars() const { 1282a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith unsigned ArrayIndexSize = 1283a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1284a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith llvm::alignOf<VarDecl*>()); 12857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<VarDecl **>( 128688d2f678e70ab9360f09f3534d9223e6ec20f129Richard Smith reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 12877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 12887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 128901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a new lambda expression. 129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static LambdaExpr *Create(ASTContext &C, 129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *Class, 129301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange, 129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1297dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 129801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 12999daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 13009daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 1301612409ece080e814f79e06772c690d603f45fbd6Richard Smith SourceLocation ClosingBrace, 1302612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool ContainsUnexpandedParameterPack); 130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13049d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct a new lambda expression that will be deserialized from 13059d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// an external source. 13069d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 13079d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor unsigned NumArrayIndexVars); 13089d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the default capture kind for this lambda. 131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault getCaptureDefault() const { 131101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return static_cast<LambdaCaptureDefault>(CaptureDefault); 131201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 131301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief An iterator that walks over the captures of the lambda, 131501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// both implicit and explicit. 131601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef const Capture *capture_iterator; 131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 131801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first lambda capture. 1319da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_begin() const; 132001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 132101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the 132201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// sequence of lambda captures. 1323da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_end() const; 132401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13257ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Determine the number of captures in this lambda. 13267ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned capture_size() const { return NumCaptures; } 13277ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 132801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first explicit 132901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1330da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_begin() const; 133101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 133201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 133301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit lambda captures. 1334da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_end() const; 133501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 133601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first implicit 133701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1338da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_begin() const; 133901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 134001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 134101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit lambda captures. 1342da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_end() const; 134301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 134401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Iterator that walks over the capture initialization 134501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// arguments. 134601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef Expr **capture_init_iterator; 134701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 134801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the first initialization argument for this 134901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression (which initializes the first capture field). 13507ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_begin() const { 13517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Expr **>(getStoredStmts()); 13527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 135301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 135401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the iterator pointing one past the last 135576e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor /// initialization argument for this lambda expression. 13567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_end() const { 13577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return capture_init_begin() + NumCaptures; 13587ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 135901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13609daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Retrieve the set of index variables used in the capture 13619daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// initializer of an array captured by copy. 13629daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// 13639daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \param Iter The iterator that points at the capture initializer for 13649daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// which we are extracting the corresponding index variables. 13659daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 13669daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 136701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source range covering the lambda introducer, 136801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which contains the explicit capture list surrounded by square 136901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// brackets ([...]). 137001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getIntroducerRange() const { return IntroducerRange; } 137101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 137201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the class that corresponds to the lambda, which 137301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stores the captures in its fields and provides the various 137401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// operations permitted on a lambda (copying, calling). 137501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *getLambdaClass() const; 137601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 137701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the function call operator associated with this 137801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression. 137901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXMethodDecl *getCallOperator() const; 138001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 138101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the body of the lambda. 13829d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor CompoundStmt *getBody() const; 138301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 138401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether the lambda is mutable, meaning that any 138501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captures values can be modified. 138601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isMutable() const; 138701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 138801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this lambda has an explicit parameter 138901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// list vs. an implicit (empty) parameter list. 139001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool hasExplicitParameters() const { return ExplicitParams; } 139101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1392dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had its result type explicitly specified. 1393dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool hasExplicitResultType() const { return ExplicitResultType; } 13949e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 139501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const Stmt *T) { 139601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return T->getStmtClass() == LambdaExprClass; 139701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 139801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1399aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 140001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return SourceRange(IntroducerRange.getBegin(), ClosingBrace); 140101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 140201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 14037ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor child_range children() { 14047ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 14057ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 140601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 140701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 140801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 140901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor}; 141001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1411ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1412506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type 1413ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type. 1414987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1415ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr { 1416987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1417ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo; 1418987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1419ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 1420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1421987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic: 1422ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Create an explicitly-written scalar-value initialization 1423ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// expression. 1424ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr(QualType Type, 1425ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo, 1426ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation rParenLoc ) : 1427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1428561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, Type->isInstantiationDependentType(), false), 1429ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1430ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 1431ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor explicit CXXScalarValueInitExpr(EmptyShell Shell) 1432ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor : Expr(CXXScalarValueInitExprClass, Shell) { } 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1434ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 1435ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return TypeInfo; 14364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 1437ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1438ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 14394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 1440aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1443ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor return T->getStmtClass() == CXXScalarValueInitExprClass; 1444987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1446987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // Iterators 144763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1448987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1449987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 14500982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @brief Represents a new-expression for memory allocation and constructor 14510982205bade2fb4fc984c27b2ab401e683963b10James Dennett// calls, e.g: "new CXXNewExpr(foo)". 14524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr { 14532aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Contains an optional array size expression, an optional initialization 14542aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // expression, and any number of optional placement arguments, in that order. 14554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt **SubExprs; 14560982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Points to the allocation function used. 14574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorNew; 14580982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Points to the deallocation function used in case of error. May be 14590982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// null. 14604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 14614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14621bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor /// \brief The allocated type-source information, as written in the source. 14631bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo; 1464ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1465ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the allocated type was expressed as a parenthesized type-id, 14664bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor /// the source range covering the parenthesized type-id. 14674bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange TypeIdParens; 1468ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1469530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie /// \brief Range of the entire new expression. 1470530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceRange Range; 14712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 14722aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Source-range of a paren-delimited initializer. 14732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange DirectInitRange; 14744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1475d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Was the usage ::new, i.e. is the global new to be used? 1476d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool GlobalNew : 1; 1477d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Do we allocate an array? If so, the first SubExpr is the size expression. 1478d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool Array : 1; 1479d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // If this is an array allocation, does the usual deallocation 1480d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // function for the allocated type want to know the allocated size? 1481d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool UsualArrayDeleteWantsSize : 1; 1482d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // The number of placement new arguments. 1483d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer unsigned NumPlacementArgs : 13; 1484d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // What kind of initializer do we have? Could be none, parens, or braces. 1485d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // In storage, we distinguish between "none, and no initializer expr", and 1486d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // "none, but an implicit initializer expr". 1487d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer unsigned StoredInitializationStyle : 2; 1488d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 148960adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 14902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl friend class ASTStmtWriter; 14914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 14922aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl enum InitializationStyle { 14932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NoInit, ///< New-expression has no initializer as written. 14942aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl CallInit, ///< New-expression has a C++98 paren-delimited initializer. 14952aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ListInit ///< New-expression has a C++11 list-initializer. 14962aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl }; 14972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 1498ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 14991548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 15003b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> placementArgs, 15012aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange typeIdParens, Expr *arraySize, 15022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle initializationStyle, Expr *initializer, 15036ec278d1a354517e20f13a877481453ee7940c78John McCall QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1504530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceRange Range, SourceRange directInitRange); 15055921863d8f24084797863b5df37842113bac4352Chris Lattner explicit CXXNewExpr(EmptyShell Shell) 15065921863d8f24084797863b5df37842113bac4352Chris Lattner : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 15075921863d8f24084797863b5df37842113bac4352Chris Lattner 15085921863d8f24084797863b5df37842113bac4352Chris Lattner void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 15092aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer); 1510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1511cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl QualType getAllocatedType() const { 1512cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl assert(getType()->isPointerType()); 15136217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<PointerType>()->getPointeeType(); 1514cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 15154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *getAllocatedTypeSourceInfo() const { 15171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor return AllocatedTypeInfo; 15181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor } 1519c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 1520c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// \brief True if the allocation result needs to be null-checked. 1521c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// C++0x [expr.new]p13: 1522c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// If the allocation function returns null, initialization shall 1523c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// not be done, the deallocation function shall not be called, 1524c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// and the value of the new-expression shall be null. 1525c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// An allocation function is not allowed to return null unless it 1526c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// has a non-throwing exception-specification. The '03 rule is 1527c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// identical except that the definition of a non-throwing 1528c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// exception specification is just "is it throw()?". 15298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorNew() const { return OperatorNew; } 15325921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 15334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 15345921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 15354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1536cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool isArray() const { return Array; } 1537cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl Expr *getArraySize() { 1538cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1539cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1540cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl const Expr *getArraySize() const { 1541cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1542cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1543cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl 15444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr **getPlacementArgs() { 15462aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1547aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1548ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getPlacementArg(unsigned i) { 15504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 15512aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return getPlacementArgs()[i]; 15524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getPlacementArg(unsigned i) const { 15544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 15552aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 15564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15584bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor bool isParenTypeId() const { return TypeIdParens.isValid(); } 15594bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange getTypeIdParens() const { return TypeIdParens; } 15604bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor 15614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalNew() const { return GlobalNew; } 15627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 15632aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Whether this new-expression has any initializer at all. 15642aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer() const { return StoredInitializationStyle > 0; } 15651548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 15662aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The kind of initializer this new-expression has. 15672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle getInitializationStyle() const { 15682aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (StoredInitializationStyle == 0) 15692aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return NoInit; 15702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return static_cast<InitializationStyle>(StoredInitializationStyle-1); 15711548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15721548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 15732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The initializer of this new-expression. 15742aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *getInitializer() { 15752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 15761548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15772aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const Expr *getInitializer() const { 15782aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 15791548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15801548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 1581feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay /// \brief Returns the CXXConstructExpr from this new-expression, or NULL. 158288920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky const CXXConstructExpr* getConstructExpr() const { 1583feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1584feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay } 1585feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay 15862aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// Answers whether the usual array deallocation function for the 15872aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// allocated type expects the size of the allocation as a 15882aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// parameter. 15892aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool doesUsualArrayDeleteWantSize() const { 15902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return UsualArrayDeleteWantsSize; 15912aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 15921548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 15934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ExprIterator arg_iterator; 15944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ConstExprIterator const_arg_iterator; 15954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_begin() { 15972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 15984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_end() { 16002aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_begin() const { 16032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 16044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_end() const { 16062aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 1608ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16095921863d8f24084797863b5df37842113bac4352Chris Lattner typedef Stmt **raw_arg_iterator; 16105921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_begin() { return SubExprs; } 16115921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_end() { 16122aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16135921863d8f24084797863b5df37842113bac4352Chris Lattner } 16145921863d8f24084797863b5df37842113bac4352Chris Lattner const_arg_iterator raw_arg_begin() const { return SubExprs; } 16152aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const_arg_iterator raw_arg_end() const { 16162aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16172aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 16184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1619530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceLocation getStartLoc() const { return Range.getBegin(); } 1620530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceLocation getEndLoc() const { return Range.getEnd(); } 1621428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 16222aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange getDirectInitRange() const { return DirectInitRange; } 1623428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 1624aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1625530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie return Range; 16264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 16294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXNewExprClass; 16304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 163363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 16342aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return child_range(raw_arg_begin(), raw_arg_end()); 163563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 16364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 16374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16380982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a \c delete expression for memory deallocation and 16390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// destructor calls, e.g. "delete[] pArray". 16404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr { 1641d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Points to the operator delete overload that is used. Could be a member. 1642d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer FunctionDecl *OperatorDelete; 1643d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // The pointer expression to be deleted. 1644d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer Stmt *Argument; 1645d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Location of the expression. 1646d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer SourceLocation Loc; 16474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this a forced global delete, i.e. "::delete"? 16484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalDelete : 1; 16494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this the array form of delete, i.e. "delete[]"? 16504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool ArrayForm : 1; 16514076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 16524076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 16534076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // will be true). 16544076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool ArrayFormAsWritten : 1; 16556ec278d1a354517e20f13a877481453ee7940c78John McCall // Does the usual deallocation function for the element type require 16566ec278d1a354517e20f13a877481453ee7940c78John McCall // a size_t argument? 16576ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 16584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 16594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 16606ec278d1a354517e20f13a877481453ee7940c78John McCall bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 16616ec278d1a354517e20f13a877481453ee7940c78John McCall FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1662bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1663561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor arg->isInstantiationDependent(), 1664bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor arg->containsUnexpandedParameterPack()), 1665d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1666f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall GlobalDelete(globalDelete), 16674076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1668d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 166995fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis explicit CXXDeleteExpr(EmptyShell Shell) 167095fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 16714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalDelete() const { return GlobalDelete; } 16734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isArrayForm() const { return ArrayForm; } 16744076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 16754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16766ec278d1a354517e20f13a877481453ee7940c78John McCall /// Answers whether the usual array deallocation function for the 16776ec278d1a354517e20f13a877481453ee7940c78John McCall /// allocated type expects the size of the allocation as a 16786ec278d1a354517e20f13a877481453ee7940c78John McCall /// parameter. This can be true even if the actual deallocation 16796ec278d1a354517e20f13a877481453ee7940c78John McCall /// function that we're using doesn't want a size. 16806ec278d1a354517e20f13a877481453ee7940c78John McCall bool doesUsualArrayDeleteWantSize() const { 16816ec278d1a354517e20f13a877481453ee7940c78John McCall return UsualArrayDeleteWantsSize; 16826ec278d1a354517e20f13a877481453ee7940c78John McCall } 16836ec278d1a354517e20f13a877481453ee7940c78John McCall 16844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 16854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getArgument() { return cast<Expr>(Argument); } 16874c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getArgument() const { return cast<Expr>(Argument); } 16884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1689a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// \brief Retrieve the type being destroyed. If the type being 1690a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// destroyed is a dependent type which may or may not be a pointer, 1691a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// return an invalid type. 16925833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType getDestroyedType() const; 1693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1694aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 16954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return SourceRange(Loc, Argument->getLocEnd()); 16964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 16994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXDeleteExprClass; 17004c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 17014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 170363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Argument, &Argument+1); } 1704f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis 1705f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis friend class ASTStmtReader; 17064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 17074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17080982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1709a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage { 1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Either the type source information or the name of the type, if 1711a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// it couldn't be resolved due to type-dependence. 1712a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1714a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief The starting source location of the pseudo-destructor type. 1715a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation Location; 1716ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1717a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic: 1718a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage() { } 1719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1720a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1721a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor : Type(II), Location(Loc) { } 1722ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1723a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1724ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1725ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getTypeSourceInfo() const { 1726ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return Type.dyn_cast<TypeSourceInfo *>(); 1727a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1728ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1729a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getIdentifier() const { 1730a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return Type.dyn_cast<IdentifierInfo *>(); 1731a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1733a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation getLocation() const { return Location; } 1734a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor}; 1735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1736a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1737a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1738e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a 1739ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have 1740e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example: 1741e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// 1742e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code 1743e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T; 1744e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) { 1745e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// p->T::~T(); 1746e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// } 1747e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode 1748a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1749e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as: 1750ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// 1751a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code 17521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T> 1753a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) { 1754e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// ptr->T::~T(); 1755a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// } 1756a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode 1757a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1758e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics 1759e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression. 1760a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr { 1761a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The base expression (that is being destroyed). 1762a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Stmt *Base; 17631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1764a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1765a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// period ('.'). 1766a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool IsArrow : 1; 17671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1768a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The location of the '.' or '->' operator. 1769a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation OperatorLoc; 1770ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1771a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The nested-name-specifier that follows the operator, if present. 1772f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1774e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1775e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1776e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType; 1777ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The location of the '::' in a qualified pseudo-destructor 1779e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1780e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc; 1781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1782fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief The location of the '~'. 1783fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc; 1784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The type being destroyed, or its name if we were unable to 1786a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// resolve the name. 1787a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage DestroyedType; 17881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1789f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor friend class ASTStmtReader; 1790ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1791a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic: 1792a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor CXXPseudoDestructorExpr(ASTContext &Context, 1793a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1794f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1795e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType, 1796e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc, 1797fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 1798e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall PseudoDestructorTypeStorage DestroyedType); 17991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1800de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1801de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis : Expr(CXXPseudoDestructorExprClass, Shell), 1802f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1803de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1804a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *getBase() const { return cast<Expr>(Base); } 18051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 1807a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 1808a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// x->Base::foo. 1809f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool hasQualifier() const { return QualifierLoc; } 18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1811f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1812f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// with source-location information. 1813f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 1816a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 1817a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// NULL. 1818ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 1819ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 1820f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor } 18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1822a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Determine whether this pseudo-destructor expression was written 1823a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// using an '->' (otherwise, it used a '.'). 1824a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool isArrow() const { return IsArrow; } 1825a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor 1826a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Retrieve the location of the '.' or '->' operator. 1827a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1829ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the scope type in a qualified pseudo-destructor 1830e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1831e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// 1832e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Pseudo-destructor expressions can have extra qualification within them 1833e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1834e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Here, if the object type of the expression is (or may be) a scalar type, 1835ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \p T may also be a scalar type and, therefore, cannot be part of a 1836e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1837e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// destructor expression. 183826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1839ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1840e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1841e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1842e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1843ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1844fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief Retrieve the location of the '~'. 1845fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation getTildeLoc() const { return TildeLoc; } 1846ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 184726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// \brief Retrieve the source location information for the type 184826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// being destroyed. 1849a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// 1850ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This type-source information is available for non-dependent 1851a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// pseudo-destructor expressions and some dependent pseudo-destructor 1852a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// expressions. Returns NULL if we only have the identifier for a 1853a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// dependent pseudo-destructor expression. 1854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getDestroyedTypeInfo() const { 1855ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getTypeSourceInfo(); 1856a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1857ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1858a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief In a dependent pseudo-destructor expression for which we do not 1859a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// have full type information on the destroyed type, provides the name 1860a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// of the destroyed type. 1861a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getDestroyedTypeIdentifier() const { 1862a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return DestroyedType.getIdentifier(); 1863a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1865a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the type being destroyed. 1866a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor QualType getDestroyedType() const; 1867ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1868a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the starting location of the type being destroyed. 1869ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation getDestroyedTypeLoc() const { 1870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getLocation(); 1871a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1873de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1874de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// expression. 1875de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1876de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1877de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1878de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1879de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the destroyed type. 1880de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(TypeSourceInfo *Info) { 1881de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(Info); 1882de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1883de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1884aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 18851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1887a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor return T->getStmtClass() == CXXPseudoDestructorExprClass; 1888a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1890a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor // Iterators 189163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base + 1); } 1892a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}; 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18940982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS unary type trait, as used in the 18950982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates. 18960982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 189764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example: 18980982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 18990982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_pod(int) == true 19000982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_enum(std::string) == false 19010982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 190264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr { 19030dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 19040dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl unsigned UTT : 31; 19050dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The value of the type trait. Unspecified if dependent. 19060dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool Value : 1; 190764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 190864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// Loc - The location of the type trait keyword. 190964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation Loc; 191064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 191164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// RParen - The location of the closing paren. 191264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation RParen; 191364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19140dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The type being queried. 19153d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *QueriedType; 191664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 191764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic: 1918ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 19190dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl TypeSourceInfo *queried, bool value, 192064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation rparen, QualType ty) 1921f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1922bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, queried->getType()->isDependentType(), 1923561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->getType()->isInstantiationDependentType(), 1924bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor queried->getType()->containsUnexpandedParameterPack()), 19250dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 192664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19276d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit UnaryTypeTraitExpr(EmptyShell Empty) 19280dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 19293d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QueriedType() { } 19306d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 1931aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);} 193264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19330dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 193464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19353d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QualType getQueriedType() const { return QueriedType->getType(); } 193664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19373d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1938ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19390dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool getValue() const { return Value; } 194064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 194164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const Stmt *T) { 194264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return T->getStmtClass() == UnaryTypeTraitExprClass; 194364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 194464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 194564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Iterators 194663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 19476d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 194860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 194964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl}; 195064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19510982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS binary type trait, as used in the 19520982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates. 19530982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 19546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example: 19550982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 19560982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_base_of(Base, Derived) == true 19570982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 19586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr { 19596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 19606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet unsigned BTT : 8; 19616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The value of the type trait. Unspecified if dependent. 19636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool Value : 1; 19646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Loc - The location of the type trait keyword. 19666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation Loc; 19676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// RParen - The location of the closing paren. 19696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParen; 19706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The lhs type being queried. 19726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsType; 19736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The rhs type being queried. 19756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsType; 19766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic: 1978ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1979ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 19806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool value, SourceLocation rparen, QualType ty) 1981ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 19826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet lhsType->getType()->isDependentType() || 1983bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->isDependentType(), 1984561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhsType->getType()->isInstantiationDependentType() || 1985561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhsType->getType()->isInstantiationDependentType()), 1986bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhsType->getType()->containsUnexpandedParameterPack() || 1987bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->containsUnexpandedParameterPack())), 19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BTT(btt), Value(value), Loc(loc), RParen(rparen), 19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsType(lhsType), RhsType(rhsType) { } 19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet explicit BinaryTypeTraitExpr(EmptyShell Empty) 19936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1994f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet LhsType(), RhsType() { } 19956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 1996aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 19976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SourceRange(Loc, RParen); 19986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BinaryTypeTrait getTrait() const { 20016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return static_cast<BinaryTypeTrait>(BTT); 20026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getLhsType() const { return LhsType->getType(); } 20056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getRhsType() const { return RhsType->getType(); } 20066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 20086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2009ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool getValue() const { assert(!isTypeDependent()); return Value; } 20116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const Stmt *T) { 20136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return T->getStmtClass() == BinaryTypeTraitExprClass; 20146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet // Iterators 201763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 20186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet friend class ASTStmtReader; 20206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}; 20216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and 20234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates. 20244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// 20254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code 20264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// __is_trivially_constructible(vector<int>, int*, int*) 20274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode 20284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr { 20294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The location of the type trait keyword. 20304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation Loc; 20314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The location of the closing parenthesis. 20334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc; 20344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Note: The TypeSourceInfos for the arguments are allocated after the 20364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // TypeTraitExpr. 20374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 20394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 20404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc, 20414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Value); 20424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 20444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo **getTypeSourceInfos() { 20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return reinterpret_cast<TypeSourceInfo **>(this+1); 20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 20514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo * const *getTypeSourceInfos() const { 20524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return reinterpret_cast<TypeSourceInfo * const*>(this+1); 20534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic: 20564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Create a new type trait expression. 20574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc, 20584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTrait Kind, 20594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 20604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc, 20614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Value); 20624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs); 20644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Determine which type trait this expression uses. 20664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTrait getTrait() const { 20674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 20684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool getValue() const { 20714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor assert(!isValueDependent()); 20724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return TypeTraitExprBits.Value; 20734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Determine the number of arguments to this type trait. 20764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 20774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the Ith argument. 20794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo *getArg(unsigned I) const { 20804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor assert(I < getNumArgs() && "Argument out-of-range"); 20814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getArgs()[I]; 20824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 20854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> getArgs() const { 20864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 20874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor typedef TypeSourceInfo **arg_iterator; 20904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_iterator arg_begin() { 20914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos(); 20924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_iterator arg_end() { 20944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos() + getNumArgs(); 20954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 20974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor typedef TypeSourceInfo const * const *arg_const_iterator; 20984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 20994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_const_iterator arg_end() const { 21004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos() + getNumArgs(); 21014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 2103aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); } 21044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static bool classof(const Stmt *T) { 21064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return T->getStmtClass() == TypeTraitExprClass; 21074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Iterators 21104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor child_range children() { return child_range(); } 21114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtReader; 21134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 21144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor}; 21164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21170982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An Embarcadero array type trait, as used in the implementation of 21180982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank and __array_extent. 21190982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 212021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example: 21210982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 21220982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank(int[10][20]) == 2 21230982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_extent(int, 1) == 20 21240982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 212521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr { 212699ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 212799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 21280982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 212921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley unsigned ATT : 2; 213021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21310982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The value of the type trait. Unspecified if dependent. 213221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t Value; 213321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21340982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The array dimension being queried, or -1 if not used. 213521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *Dimension; 213621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21370982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the type trait keyword. 213821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation Loc; 213921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21400982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the closing paren. 214121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParen; 214221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21430982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The type being queried. 214421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *QueriedType; 214521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 214621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic: 214721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 214821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *queried, uint64_t value, 214921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *dimension, SourceLocation rparen, QualType ty) 215021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 215121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley false, queried->getType()->isDependentType(), 2152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (queried->getType()->isInstantiationDependentType() || 2153561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (dimension && dimension->isInstantiationDependent())), 215421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley queried->getType()->containsUnexpandedParameterPack()), 215521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ATT(att), Value(value), Dimension(dimension), 215621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Loc(loc), RParen(rparen), QueriedType(queried) { } 215721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 215821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 215921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley explicit ArrayTypeTraitExpr(EmptyShell Empty) 216021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 216121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QueriedType() { } 216221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 216325aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek virtual ~ArrayTypeTraitExpr() { } 216425aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek 2165aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar virtual SourceRange getSourceRange() const LLVM_READONLY { 2166ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return SourceRange(Loc, RParen); 2167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 216821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 216921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 217021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 217121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QualType getQueriedType() const { return QueriedType->getType(); } 217221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 217321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 217421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 217521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 217621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 217721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *getDimensionExpression() const { return Dimension; } 217821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 217921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const Stmt *T) { 218021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return T->getStmtClass() == ArrayTypeTraitExprClass; 218121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 218221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 218321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Iterators 218421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley child_range children() { return child_range(); } 218521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 218621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley friend class ASTStmtReader; 218721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}; 218821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 21890982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An expression trait intrinsic. 21900982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 2191552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example: 21920982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 21930982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_lvalue_expr(std::cout) == true 21940982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_lvalue_expr(1) == false 21950982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 2196552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr { 21970982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned. 2198552622067dc45013d240f73952fece703f5e63bdJohn Wiegley unsigned ET : 31; 21990982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The value of the type trait. Unspecified if dependent. 2200552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool Value : 1; 2201552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22020982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the type trait keyword. 2203552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation Loc; 2204552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22050982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the closing paren. 2206552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParen; 2207552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22080982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The expression being queried. 2209552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr* QueriedExpression; 2210552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic: 2211ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2212552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *queried, bool value, 2213552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation rparen, QualType resultType) 2214552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2215552622067dc45013d240f73952fece703f5e63bdJohn Wiegley false, // Not type-dependent 2216552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Value-dependent if the argument is type-dependent. 2217552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->isTypeDependent(), 2218561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->isInstantiationDependent(), 2219552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->containsUnexpandedParameterPack()), 2220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ET(et), Value(value), Loc(loc), RParen(rparen), 2221ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QueriedExpression(queried) { } 2222552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2223552622067dc45013d240f73952fece703f5e63bdJohn Wiegley explicit ExpressionTraitExpr(EmptyShell Empty) 2224552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2225552622067dc45013d240f73952fece703f5e63bdJohn Wiegley QueriedExpression() { } 2226552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22270982205bade2fb4fc984c27b2ab401e683963b10James Dennett SourceRange getSourceRange() const LLVM_READONLY { 22280982205bade2fb4fc984c27b2ab401e683963b10James Dennett return SourceRange(Loc, RParen); 22290982205bade2fb4fc984c27b2ab401e683963b10James Dennett } 2230552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2231552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2232552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2233552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *getQueriedExpression() const { return QueriedExpression; } 2234552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2235552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool getValue() const { return Value; } 2236552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2237552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const Stmt *T) { 2238552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return T->getStmtClass() == ExpressionTraitExprClass; 2239552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2240552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2241552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Iterators 2242552622067dc45013d240f73952fece703f5e63bdJohn Wiegley child_range children() { return child_range(); } 2243552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2244552622067dc45013d240f73952fece703f5e63bdJohn Wiegley friend class ASTStmtReader; 2245552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}; 2246552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2247552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22487bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an 2249809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 22507bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr { 22510982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The common name of these declarations. 2252d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer DeclarationNameInfo NameInfo; 2253d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 2254d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer /// \brief The nested-name-specifier that qualifies the name, if any. 2255d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer NestedNameSpecifierLoc QualifierLoc; 2256d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 2257ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// The results. These are undesugared, which is to say, they may 22587bb12da2b0749eeebb21854c77877736969e59f2John McCall /// include UsingShadowDecls. Access is relative to the naming 22597bb12da2b0749eeebb21854c77877736969e59f2John McCall /// class. 2260928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor // FIXME: Allocate this data after the OverloadExpr subclass. 2261928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor DeclAccessPair *Results; 2262928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned NumResults; 2263ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2264a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected: 2265e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2266e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2267e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2268e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2269e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2270e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2272e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2273e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2274e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2275e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 22767bb12da2b0749eeebb21854c77877736969e59f2John McCall 2277bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor OverloadExpr(StmtClass K, ASTContext &C, 22784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 22802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2281bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2282bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2283561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownDependent, 2284561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownInstantiationDependent, 2285561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownContainsUnexpandedParameterPack); 22867bb12da2b0749eeebb21854c77877736969e59f2John McCall 2287a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis OverloadExpr(StmtClass K, EmptyShell Empty) 2288d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2289d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer HasTemplateKWAndArgsInfo(false) { } 2290a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 2291bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeResults(ASTContext &C, 2292bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, 2293bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator End); 22947bb12da2b0749eeebb21854c77877736969e59f2John McCall 2295bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic: 22969c72c6088d591ace8503b842d39448c2040f3033John McCall struct FindResult { 22979c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Expression; 22989c72c6088d591ace8503b842d39448c2040f3033John McCall bool IsAddressOfOperand; 22999c72c6088d591ace8503b842d39448c2040f3033John McCall bool HasFormOfMemberPointer; 23009c72c6088d591ace8503b842d39448c2040f3033John McCall }; 23019c72c6088d591ace8503b842d39448c2040f3033John McCall 23027bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Finds the overloaded expression in the given expression of 23037bb12da2b0749eeebb21854c77877736969e59f2John McCall /// OverloadTy. 23047bb12da2b0749eeebb21854c77877736969e59f2John McCall /// 23059c72c6088d591ace8503b842d39448c2040f3033John McCall /// \return the expression (which must be there) and true if it has 23069c72c6088d591ace8503b842d39448c2040f3033John McCall /// the particular form of a member pointer expression 23079c72c6088d591ace8503b842d39448c2040f3033John McCall static FindResult find(Expr *E) { 23087bb12da2b0749eeebb21854c77877736969e59f2John McCall assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 23097bb12da2b0749eeebb21854c77877736969e59f2John McCall 23109c72c6088d591ace8503b842d39448c2040f3033John McCall FindResult Result; 23119c72c6088d591ace8503b842d39448c2040f3033John McCall 23127bb12da2b0749eeebb21854c77877736969e59f2John McCall E = E->IgnoreParens(); 23139c72c6088d591ace8503b842d39448c2040f3033John McCall if (isa<UnaryOperator>(E)) { 23149c72c6088d591ace8503b842d39448c2040f3033John McCall assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 23159c72c6088d591ace8503b842d39448c2040f3033John McCall E = cast<UnaryOperator>(E)->getSubExpr(); 23169c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 23179c72c6088d591ace8503b842d39448c2040f3033John McCall 23189c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 23199c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = true; 23209c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = Ovl; 23219c72c6088d591ace8503b842d39448c2040f3033John McCall } else { 23229c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = false; 23239c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = false; 23249c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = cast<OverloadExpr>(E); 23259c72c6088d591ace8503b842d39448c2040f3033John McCall } 23269c72c6088d591ace8503b842d39448c2040f3033John McCall 23279c72c6088d591ace8503b842d39448c2040f3033John McCall return Result; 23287bb12da2b0749eeebb21854c77877736969e59f2John McCall } 23297bb12da2b0749eeebb21854c77877736969e59f2John McCall 23300982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the naming class of this lookup, if any. 2331e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall CXXRecordDecl *getNamingClass() const; 2332e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall 23337bb12da2b0749eeebb21854c77877736969e59f2John McCall typedef UnresolvedSetImpl::iterator decls_iterator; 2334928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2335ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie decls_iterator decls_end() const { 2336928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor return UnresolvedSetIterator(Results + NumResults); 2337928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor } 2338ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 23390982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the number of declarations in the unresolved set. 2340928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned getNumDecls() const { return NumResults; } 23417bb12da2b0749eeebb21854c77877736969e59f2John McCall 23420982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the full name info. 23432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 23442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 23450982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the name looked up. 23462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return NameInfo.getName(); } 23477bb12da2b0749eeebb21854c77877736969e59f2John McCall 23480982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the location of the name. 23492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 23507bb12da2b0749eeebb21854c77877736969e59f2John McCall 23510982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Fetches the nested-name qualifier, if one was given. 2352ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 23544c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor } 23557bb12da2b0749eeebb21854c77877736969e59f2John McCall 23560982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Fetches the nested-name qualifier with source-location 23570982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// information, if one was given. 23584c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 23597bb12da2b0749eeebb21854c77877736969e59f2John McCall 2360e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2361e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2362e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2363e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2364e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2367e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2368e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2369e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2370e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 23807bb12da2b0749eeebb21854c77877736969e59f2John McCall 23810982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Determines whether the name was preceded by the template keyword. 2382e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2383e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 23840982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Determines whether this expression had explicit template arguments. 2385e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2386e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2387e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // Note that, inconsistently with the explicit-template-argument AST 2388e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // nodes, users are *forbidden* from calling these methods on objects 2389e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // without explicit template arguments. 2390e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2391e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2392e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2393e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2394e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 23957bb12da2b0749eeebb21854c77877736969e59f2John McCall 2396b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 23977bb12da2b0749eeebb21854c77877736969e59f2John McCall return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 23987bb12da2b0749eeebb21854c77877736969e59f2John McCall } 23997bb12da2b0749eeebb21854c77877736969e59f2John McCall 2400e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgumentLoc const *getTemplateArgs() const { 2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().getTemplateArgs(); 2402e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2403e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2404e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned getNumTemplateArgs() const { 2405e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().NumTemplateArgs; 2406e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 24080982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Copies the template arguments into the given structure. 2409e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2410e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getExplicitTemplateArgs().copyInto(List); 2411e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2412e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2413096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 24140982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// 2415096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2416096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2417b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2418096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2419096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 24207bb12da2b0749eeebb21854c77877736969e59f2John McCall } 24217bb12da2b0749eeebb21854c77877736969e59f2John McCall 24227bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const Stmt *T) { 24237bb12da2b0749eeebb21854c77877736969e59f2John McCall return T->getStmtClass() == UnresolvedLookupExprClass || 24247bb12da2b0749eeebb21854c77877736969e59f2John McCall T->getStmtClass() == UnresolvedMemberExprClass; 24257bb12da2b0749eeebb21854c77877736969e59f2John McCall } 24264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 24274045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 24284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 24297bb12da2b0749eeebb21854c77877736969e59f2John McCall}; 24307bb12da2b0749eeebb21854c77877736969e59f2John McCall 24317bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during 24320982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// parsing but could not resolve to a specific declaration. 24330982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 24340982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// This arises in several ways: 24357bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * we might be waiting for argument-dependent lookup 24367bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the name might resolve to an overloaded function 24377bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually: 24387bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the lookup might have included a function template 24390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// These never include UnresolvedUsingValueDecls, which are always class 24400982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// members and therefore appear only in UnresolvedMemberLookupExprs. 24417bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr { 2442ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if these lookup results should be extended by 2443ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup if this is the operand of a function 2444ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// call. 2445ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool RequiresADL; 2446ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 24477453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if these lookup results are overloaded. This is pretty 24487453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// trivially rederivable if we urgently need to kill this field. 24497453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool Overloaded; 24507453ed4cb2cab113de3378df371b1c6f1243d832John McCall 24517bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The naming class (C++ [class.access.base]p5) of the lookup, if 24527bb12da2b0749eeebb21854c77877736969e59f2John McCall /// any. This can generally be recalculated from the context chain, 24537bb12da2b0749eeebb21854c77877736969e59f2John McCall /// but that can be fairly expensive for unqualified lookups. If we 24547bb12da2b0749eeebb21854c77877736969e59f2John McCall /// want to improve memory use here, this could go in a union 24557bb12da2b0749eeebb21854c77877736969e59f2John McCall /// against the qualified-lookup bits. 24567bb12da2b0749eeebb21854c77877736969e59f2John McCall CXXRecordDecl *NamingClass; 2457f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2458ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedLookupExpr(ASTContext &C, 2459928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor CXXRecordDecl *NamingClass, 24604c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2461e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 24622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2463ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool RequiresADL, bool Overloaded, 2464bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2465b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2466e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2467e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara NameInfo, TemplateArgs, Begin, End, false, false, false), 2468ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(RequiresADL), 2469ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Overloaded(Overloaded), NamingClass(NamingClass) 2470ba13543329afac4a0d01304ec2ec4924d99306a6John McCall {} 2471ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2472bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis UnresolvedLookupExpr(EmptyShell Empty) 2473bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis : OverloadExpr(UnresolvedLookupExprClass, Empty), 2474b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith RequiresADL(false), Overloaded(false), NamingClass(0) 2475bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis {} 2476bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 24774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 2478ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2479ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic: 2480ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2481c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 24824c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 24832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 24845a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor bool ADL, bool Overloaded, 2485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 2486b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith UnresolvedSetIterator End) { 2487e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2488e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation(), NameInfo, 2489b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith ADL, Overloaded, 0, Begin, End); 2490ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2491ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2492f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2493c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 24944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2495e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 24962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2497f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool ADL, 24989d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *Args, 2499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 25005a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator End); 2501f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2502bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2503e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 2504bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis unsigned NumTemplateArgs); 2505bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 2506ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if this declaration should be extended by 2507ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup. 2508ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool requiresADL() const { return RequiresADL; } 2509ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 25107453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if this lookup is overloaded. 25117453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool isOverloaded() const { return Overloaded; } 25127453ed4cb2cab113de3378df371b1c6f1243d832John McCall 2513c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// Gets the 'naming class' (in the sense of C++0x 2514c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// [class.access.base]p5) of the lookup. This is the scope 2515c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// that was looked in to find these results. 2516c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const { return NamingClass; } 2517c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 2518aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 25192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range(getNameInfo().getSourceRange()); 2520ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (getQualifierLoc()) 25214c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 2522ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (hasExplicitTemplateArgs()) 25234c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setEnd(getRAngleLoc()); 2524f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2525ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2526ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 252763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 2528ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2529ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const Stmt *T) { 2530ba13543329afac4a0d01304ec2ec4924d99306a6John McCall return T->getStmtClass() == UnresolvedLookupExprClass; 2531ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2532ba13543329afac4a0d01304ec2ec4924d99306a6John McCall}; 2533ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 25345953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot 25355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved. 25365953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// 2537ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as 25395953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an 2540865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when 25415953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In 25425953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the 25435953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the 2544865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2545ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced 2546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found. 2548865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr { 2549ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested-name-specifier that qualifies this unresolved 2550ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration name. 255100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 2552ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 255300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// The name of the entity we will be referencing. 255400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor DeclarationNameInfo NameInfo; 25555953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 2556e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2557e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2558e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2559e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2560e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2561e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2562e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2563e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2564e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2565e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2566e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2567e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DependentScopeDeclRefExpr*>(this) 2568e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2569e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 25701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2571f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall DependentScopeDeclRefExpr(QualType T, 257200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2573e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 25742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2575bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *Args); 2576f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2577f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic: 2578f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static DependentScopeDeclRefExpr *Create(ASTContext &C, 257900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2580e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 25812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2582e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs); 25835953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 258412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2585e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 258612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis unsigned NumTemplateArgs); 258712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 25885953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the name that this expression refers to. 25892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 25902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 25912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name that this expression refers to. 25922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getDeclName() const { return NameInfo.getName(); } 25935953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 25945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the location of the name within the expression. 25952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLocation() const { return NameInfo.getLoc(); } 25965953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 259700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the 259800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// name, with source location information. 259900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2600ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2601ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2602ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies this 2603ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration. 2604ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2605ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 260600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor } 26071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2608e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2609e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2610e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2611e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2612e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2613e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2614e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2615e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2616e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2617e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2618e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2619e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2620e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2621e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2622e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2623e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2624e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2625e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2626e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2627e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2628e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2629e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2630e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2631e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2632f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Determines whether this lookup had explicit template arguments. 2633e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2635f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Note that, inconsistently with the explicit-template-argument AST 2636f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // nodes, users are *forbidden* from calling these methods on objects 2637f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // without explicit template arguments. 26381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2639b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 264012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis assert(hasExplicitTemplateArgs()); 2641b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 264212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis } 264312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 2644f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Gets a reference to the explicit template argument list. 2645b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2646f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall assert(hasExplicitTemplateArgs()); 2647b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2648f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 26491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2650096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2651096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2652096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2653b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2654096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2655096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2656096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2657096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2658f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Copies the template arguments (if present) into the given 2659f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// structure. 2660f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2661f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall getExplicitTemplateArgs().copyInto(List); 2662f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 2663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2664f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentLoc const *getTemplateArgs() const { 2665f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2666d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2667d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2668f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall unsigned getNumTemplateArgs() const { 2669f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2670f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 26711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2672aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 267300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 2674f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (hasExplicitTemplateArgs()) 2675f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Range.setEnd(getRAngleLoc()); 2676f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2677edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 26781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2680f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return T->getStmtClass() == DependentScopeDeclRefExprClass; 2681edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 2682f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 268363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 26844045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 26854045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 26864045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 2687edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor}; 26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26894765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which 26904765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's 26914765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation. The most common source of expression-introduced 269280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of 269380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every 269480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer. 269580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// 269680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a 269780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal. The lifetime of a block 269880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope. 26994765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr { 270080ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic: 270180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// The type of objects that are kept in the cleanup. 270280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// It's useful to remember the set of blocks; we could also 270380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// remember the set of temporaries, but there's currently 270480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// no need. 270580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall typedef BlockDecl *CleanupObject; 270680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 270780ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate: 270802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Stmt *SubExpr; 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 271080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(EmptyShell, unsigned NumObjects); 271180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 271202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 271380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject *getObjectsBuffer() { 271480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<CleanupObject*>(this + 1); 271580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 271680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall const CleanupObject *getObjectsBuffer() const { 271780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<const CleanupObject*>(this + 1); 271880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 271980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; 2720ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 272188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic: 272280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 272380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned numObjects); 27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 272580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 272680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> objects); 2727ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 272880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> getObjects() const { 272980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2730f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson } 273180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 273280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 273380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 273480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject getObject(unsigned i) const { 273580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall assert(i < getNumObjects() && "Index out of range"); 273680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return getObjects()[i]; 2737d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner } 27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 273902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2740f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 274180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 274280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// setSubExpr - As with any mutator of the AST, be very careful 274380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// when modifying an existing AST to preserve its invariants. 274488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 274502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2746aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 274796be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 274896be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 274902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 275002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Implement isa/cast/dyncast/etc. 275102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson static bool classof(const Stmt *T) { 27524765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return T->getStmtClass() == ExprWithCleanupsClass; 275302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson } 275402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 275502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Iterators 275663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 275702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson}; 275802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2759d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional 2760d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are 2761d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. 2762d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2763d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by 2764fe865f1f35d1b91f42f58f08a1399b961b71b3bcJames Dennett/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 27650982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 27660982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2767d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such 2768d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as: 2769d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2770d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code 2771d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// template<typename T, typename A1> 2772d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// inline T make_a(const A1& a1) { 2773d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// return T(a1); 2774d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// } 2775d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode 2776d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2777d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a 2778d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type 2779d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion. 2780d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr { 2781d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The type being constructed. 2782ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 2783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2784d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the left parentheses ('('). 2785d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc; 2786d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2787d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the right parentheses (')'). 2788d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc; 2789d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2790d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The number of arguments used to construct the type. 2791d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs; 27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2793ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2794d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 27953b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> Args, 2796d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2797d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 27988dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2799ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 28008dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2801ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 2802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2803d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic: 28041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2805ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 2806d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 28073b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> Args, 2808d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2809d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 28108dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 28118dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis unsigned NumArgs); 28128dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2813d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the type that is being constructed, as specified 2814d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// in the source code. 2815ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor QualType getTypeAsWritten() const { return Type->getType(); } 2816d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the type source information for the type being 2818ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// constructed. 2819ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2820ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2821d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the left parentheses ('(') that 2822d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// precedes the argument list. 2823d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 2824d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2825d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2826d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the right parentheses (')') that 2827d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// follows the argument list. 2828d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2829d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2830d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2831d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the number of arguments. 2832d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned arg_size() const { return NumArgs; } 2833d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2834d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor typedef Expr** arg_iterator; 2835d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2836d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_end() { return arg_begin() + NumArgs; } 2837d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 28381dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall typedef const Expr* const * const_arg_iterator; 28391dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_begin() const { 28401dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return reinterpret_cast<const Expr* const *>(this + 1); 28411dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 28421dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_end() const { 28431dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return arg_begin() + NumArgs; 28441dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 28451dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 2846d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr *getArg(unsigned I) { 2847d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor assert(I < NumArgs && "Argument index out-of-range"); 2848d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return *(arg_begin() + I); 2849d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2850d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 28511dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const Expr *getArg(unsigned I) const { 28521dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall assert(I < NumArgs && "Argument index out-of-range"); 28531dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return *(arg_begin() + I); 28541dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 28551dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 28568dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void setArg(unsigned I, Expr *E) { 28578dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis assert(I < NumArgs && "Argument index out-of-range"); 28588dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis *(arg_begin() + I) = E; 28598dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 28608dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2861aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 2862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 28631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2864d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2865d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2866d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2867d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor // Iterators 286863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 286963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this+1); 287063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumArgs); 287163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2872d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor}; 2873d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2874ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual 2875ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base 2876ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent. 2877aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2878aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or 2879aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses. It is only possible to get one of these with 2880aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided. 2881865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr { 28821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The expression for the base pointer or class reference, 2883aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// e.g., the \c x in x.f. Can be null in implicit accesses. 28841c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor Stmt *Base; 28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2886aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief The type of the base expression. Never null, even for 2887aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// implicit accesses. 2888aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 2889aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 28901c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Whether this member expression used the '->' operator or 28911c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// the '.' operator. 28923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor bool IsArrow : 1; 28931c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2894e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether this member expression has info for explicit template 2895e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2896e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28981c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The location of the '->' or '.' operator. 28991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation OperatorLoc; 29001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2901a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief The nested-name-specifier that precedes the member name, if any. 29027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2904c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief In a qualified member access expression such as t->Base::f, this 29051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// member stores the resolves of name lookup in the context of the member 2906c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// access expression, to be used at instantiation time. 2907c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 290846bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor /// FIXME: This member, along with the QualifierLoc, could 2909c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// be stuck into a structure that is optionally allocated at the end of 2910865d447ac6a4721ab58e898d014a21f2eff74b06John McCall /// the CXXDependentScopeMemberExpr, to save space in the common case. 2911c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierFoundInScope; 29121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29131c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The member to which this member expression refers, which 29141c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// can be name, overloaded operator, or destructor. 2915a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// FIXME: could also be a template-id 29162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo; 29171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2918e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2919e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2920e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2921e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2922e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2923e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2924e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2925e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<CXXDependentScopeMemberExpr*>(this) 2926e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2927e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2928e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2929865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2930aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 29313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 29327c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2933e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 29343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 29352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2936d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 29371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29381c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic: 2939865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2940bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr *Base, QualType BaseType, 2941bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool IsArrow, 2942bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation OperatorLoc, 29437c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2944bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 2945bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor DeclarationNameInfo MemberNameInfo); 29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2947865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static CXXDependentScopeMemberExpr * 29481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Create(ASTContext &C, 2949aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 29503b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 29517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2952e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 29533b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 29542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2955d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29578dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXDependentScopeMemberExpr * 2958e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2959def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 29608dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2961aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 2962aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 2963aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 29644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 2965aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 29661c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the base object of this member expressions, 29671c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// e.g., the \c x in \c x.m. 2968aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() const { 2969aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 2970aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 2971aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 29721c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2973aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 2974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 29751c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Determine whether this member expression used the '->' 29761c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// operator; otherwise, it used the '.' operator. 29771c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor bool isArrow() const { return IsArrow; } 29781c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 29791c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the location of the '->' or '.' operator. 29801c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 29811c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2982a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 2983a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// name. 2984ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 29867c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 29871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29887c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 29897c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// name, with source location information. 29907c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2991ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2992ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2993c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief Retrieve the first part of the nested-name-specifier that was 2994c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// found in the scope of the member access expression when the member access 2995c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// was initially parsed. 2996c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 2997c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// This function only returns a useful result when member access expression 29981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returned by this function describes what was found by unqualified name 3000c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// lookup for the identifier "Base" within the scope of the member access 3001c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself. At template instantiation time, this information is 3002c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// combined with the results of name lookup into the type of the object 3003c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself (the class type of x). 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamedDecl *getFirstQualifierFoundInScope() const { 3005c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor return FirstQualifierFoundInScope; 3006c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor } 30071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30081c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the name of the member that this expression 30091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// refers to. 30102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { 30112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return MemberNameInfo; 30122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 30132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 30142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name of the member that this expression 30152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 30162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getMember() const { return MemberNameInfo.getName(); } 30171c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 30181c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // \brief Retrieve the location of the name of the member that this 30191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // expression refers to. 30202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 30211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3022e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding the 3023e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member name, if any. 3024e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 3025e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3026e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3027e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3028e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3029e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 3030e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 3031e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 3032e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3033e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 3034e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3035e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3036e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 3037e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 3038e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 3039e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3040e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 3041e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3042e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3043e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 3044e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3045e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 30463b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 30473b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 3048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 30491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 305036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 305136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 3052b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3053e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 3054b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 305536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 305636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 305736c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 305836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 3059b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 306036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis return const_cast<CXXDependentScopeMemberExpr *>(this) 3061096832c5ed5b9106fa177ebc148489760c3bc496John McCall ->getExplicitTemplateArgs(); 3062096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 3063096832c5ed5b9106fa177ebc148489760c3bc496John McCall 3064096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 3065096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 3066096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 3067b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 3068096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 3069096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 307036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 307136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 3072d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 3073d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 3074d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3075096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 3076d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 3077d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 30788dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis /// \brief Initializes the template arguments using the given structure. 30798dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3080096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(List); 30818dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 30828dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 30833b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 30843b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 3085833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 3086096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 30873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 30881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30893b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 30903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 30911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 3092096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 30933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 30941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3095aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 3096aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall SourceRange Range; 3097aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 3098aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 3099aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else if (getQualifier()) 31007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 3101aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 31022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setBegin(MemberNameInfo.getBeginLoc()); 31031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3104aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (hasExplicitTemplateArgs()) 3105aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setEnd(getRAngleLoc()); 3106aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 31072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setEnd(MemberNameInfo.getEndLoc()); 3108aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return Range; 31091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3112865d447ac6a4721ab58e898d014a21f2eff74b06John McCall return T->getStmtClass() == CXXDependentScopeMemberExprClass; 31131c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 31141c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 31151c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // Iterators 311663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 311763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 311863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 311963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 31204045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 31214045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 31224045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 31231c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor}; 31241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3125129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup 3126aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions. 3127aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 3128aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit: 3129aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// struct A { 3130aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int a, b; 3131aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int explicitAccess() { return this->a + this->A::b; } 3132aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int implicitAccess() { return a + A::b; } 3133aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// }; 3134aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 3135aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr. 3136aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a 3137aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static. 31387bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr { 3139129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether this member expression used the '->' operator or 3140129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// the '.' operator. 3141129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow : 1; 3142129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3143129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether the lookup results contain an unresolved using 3144129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// declaration. 3145129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool HasUnresolvedUsing : 1; 3146129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 31477bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The expression for the base pointer or class reference, 31487bb12da2b0749eeebb21854c77877736969e59f2John McCall /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 31497bb12da2b0749eeebb21854c77877736969e59f2John McCall /// member expression 31507bb12da2b0749eeebb21854c77877736969e59f2John McCall Stmt *Base; 31517bb12da2b0749eeebb21854c77877736969e59f2John McCall 31527bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The type of the base expression; never null. 31537bb12da2b0749eeebb21854c77877736969e59f2John McCall QualType BaseType; 3154129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3155129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief The location of the '->' or '.' operator. 3156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc; 3157129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3158bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3159aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3160129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 31614c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3162e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 31632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 31645a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 31655a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3166ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3167a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis UnresolvedMemberExpr(EmptyShell Empty) 3168a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3169a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis HasUnresolvedUsing(false), Base(0) { } 3170129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 31714c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 3172ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3173129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic: 3174129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static UnresolvedMemberExpr * 3175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Create(ASTContext &C, bool HasUnresolvedUsing, 3176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3177129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 31784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3179e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 31802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 31815a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 31825a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3183129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3184a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis static UnresolvedMemberExpr * 3185e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3186def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 3187a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3188aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 3189aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 3190aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 31914c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 3192aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3193129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the base object of this member expressions, 3194129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// e.g., the \c x in \c x.m. 3195aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() { 3196aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 3197aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 3198aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 31992f27bf854f0519810b34afd209089cc75536b757John McCall const Expr *getBase() const { 32002f27bf854f0519810b34afd209089cc75536b757John McCall assert(!isImplicitAccess()); 32012f27bf854f0519810b34afd209089cc75536b757John McCall return cast<Expr>(Base); 32022f27bf854f0519810b34afd209089cc75536b757John McCall } 3203129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3204aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 3205a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3206a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// \brief Determine whether the lookup results contain an unresolved using 3207a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// declaration. 3208a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3209aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3210129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Determine whether this member expression used the '->' 3211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// operator; otherwise, it used the '.' operator. 3212129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool isArrow() const { return IsArrow; } 3213129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3214129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the location of the '->' or '.' operator. 3215129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation getOperatorLoc() const { return OperatorLoc; } 3216129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3217c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// \brief Retrieves the naming class of this lookup. 3218c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const; 3219c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 32202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the full name info for the member that this expression 32212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 32222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 32232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3224129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the name of the member that this expression 3225129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// refers to. 32267bb12da2b0749eeebb21854c77877736969e59f2John McCall DeclarationName getMemberName() const { return getName(); } 3227129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // \brief Retrieve the location of the name of the member that this 3229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // expression refers to. 32307bb12da2b0749eeebb21854c77877736969e59f2John McCall SourceLocation getMemberLoc() const { return getNameLoc(); } 3231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3232aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 32332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range = getMemberNameInfo().getSourceRange(); 3234aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 3235aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 32364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor else if (getQualifierLoc()) 32374c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 3238aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3239129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (hasExplicitTemplateArgs()) 3240129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Range.setEnd(getRAngleLoc()); 3241129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return Range; 3242129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3243129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3244129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const Stmt *T) { 3245129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return T->getStmtClass() == UnresolvedMemberExprClass; 3246129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3247129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3248129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Iterators 324963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 325063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 325163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 325263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3253129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}; 3254129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 32552e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 32562e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// 32572e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its 32582e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant. 32592e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr { 32602e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool Value : 1; 32612e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Stmt *Operand; 32622e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceRange Range; 32632e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3264c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl friend class ASTStmtReader; 3265c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl 32662e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic: 32672e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 32682e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceLocation Keyword, SourceLocation RParen) 3269f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent*/false, 3271bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent*/Val == CT_Dependent, 3272561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Val == CT_Dependent || Operand->isInstantiationDependent(), 3273bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 32746b219d082434394c1ac401390ec1d1967727815aSebastian Redl Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 32756b219d082434394c1ac401390ec1d1967727815aSebastian Redl { } 32766b219d082434394c1ac401390ec1d1967727815aSebastian Redl 32776b219d082434394c1ac401390ec1d1967727815aSebastian Redl CXXNoexceptExpr(EmptyShell Empty) 32786b219d082434394c1ac401390ec1d1967727815aSebastian Redl : Expr(CXXNoexceptExprClass, Empty) 32792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl { } 32802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 32812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Expr *getOperand() const { return static_cast<Expr*>(Operand); } 32822e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3283aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 32842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 32852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool getValue() const { return Value; } 32862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 32872e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const Stmt *T) { 32882e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return T->getStmtClass() == CXXNoexceptExprClass; 32892e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 32902e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 32912e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl // Iterators 329263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Operand, &Operand + 1); } 32932e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}; 32942e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of 3296be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions. 3297be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3298be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an 3299be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example: 3300be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3301be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code 3302be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types> 3303be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) { 3304be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// f(static_cast<Types&&>(args)...); 3305be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// } 3306be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode 3307be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3308be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose 3309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3310be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or 3311be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f. 3312be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr { 3313be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation EllipsisLoc; 3314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 331567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// \brief The number of expansions that will be produced by this pack 331667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// expansion expression, if known. 331767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// 331867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// When zero, the number of expansions is not known. Otherwise, this value 331967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// is the number of expansions + 1. 332067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor unsigned NumExpansions; 3321ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3322be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Stmt *Pattern; 3323ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3324be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor friend class ASTStmtReader; 332567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor friend class ASTStmtWriter; 3326ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3327be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic: 332867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 332967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) 3330ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3331ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pattern->getObjectKind(), /*TypeDependent=*/true, 3332561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3333561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3334be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor EllipsisLoc(EllipsisLoc), 333567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3336be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Pattern(Pattern) { } 3337be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3338be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3339ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3340be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3341be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3342be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3343be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3344be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3345be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3346be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the location of the ellipsis that describes this pack 3347be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// expansion. 3348be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3349ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3350ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine the number of expansions that will be produced when 335167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// this pack expansion is instantiated, if already known. 335267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 335367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor if (NumExpansions) 335467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return NumExpansions - 1; 3355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 335667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return llvm::Optional<unsigned>(); 335767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor } 3358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3359aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 336063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(Pattern->getLocStart(), EllipsisLoc); 336163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3362be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3363be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const Stmt *T) { 3364be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor return T->getStmtClass() == PackExpansionExprClass; 3365be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor } 3366ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3367be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor // Iterators 336863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 336963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Pattern, &Pattern + 1); 337063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3371be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}; 3372ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 33757bb12da2b0749eeebb21854c77877736969e59f2John McCall if (isa<UnresolvedLookupExpr>(this)) 3376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedLookupExpr>(this) + 1); 33787bb12da2b0749eeebb21854c77877736969e59f2John McCall else 3379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3380e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedMemberExpr>(this) + 1); 33817bb12da2b0749eeebb21854c77877736969e59f2John McCall} 33827bb12da2b0749eeebb21854c77877736969e59f2John McCall 3383ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter 3384ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack. 3385ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// 3386ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code 3387ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types> 3388ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count { 3389ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// static const unsigned value = sizeof...(Types); 3390ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// }; 3391ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode 3392ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr { 3393ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the 'sizeof' keyword. 3394ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation OperatorLoc; 3395ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3396ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the name of the parameter pack. 3397ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc; 3398ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3399ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the closing parenthesis. 3400ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc; 3401ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3402ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The length of the parameter pack, if known. 3403ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3404ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// When this expression is value-dependent, the length of the parameter pack 3405ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// is unknown. When this expression is not value-dependent, the length is 3406ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// known. 3407ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length; 3408ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3409ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The parameter pack itself. 3410ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *Pack; 3411ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3412ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtReader; 3413ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtWriter; 3414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3415ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic: 3416ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates a value-dependent expression that computes the length of 3417ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack. 3418ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3419ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc) 3420ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3421ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/true, 3422561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3423ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3424ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3425ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(0), Pack(Pack) { } 3426ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3427ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates an expression that computes the length of 3428ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack, which is already known. 3429ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3430ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc, 3431ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) 3432ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3433ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3434561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3435ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3436ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3437ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(Length), Pack(Pack) { } 3438ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3439ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Create an empty expression. 3440ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3441ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3442ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the 'sizeof' keyword. 3443ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 3444ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3445ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the parameter pack. 3446ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getPackLoc() const { return PackLoc; } 3447ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3448ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the right parenthesis. 3449ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3450ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3451ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the parameter pack. 3452ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *getPack() const { return Pack; } 3453ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3454ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the length of the parameter pack. 3455ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This routine may only be invoked when the expression is not 3457c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// value-dependent. 3458ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned getPackLength() const { 3459ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!isValueDependent() && 3460ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor "Cannot get the length of a value-dependent pack size expression"); 3461ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return Length; 3462ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3463ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3464aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 346563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(OperatorLoc, RParenLoc); 346663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3467ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3468ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const Stmt *T) { 3469ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return T->getStmtClass() == SizeOfPackExprClass; 3470ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3471ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3472ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Iterators 347363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3474ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 3475c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 347691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter 347791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument. 347891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr { 347991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replaced parameter. 348091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *Param; 348191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 348291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replacement expression. 348391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Stmt *Replacement; 348491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 348591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The location of the non-type template parameter reference. 348691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation NameLoc; 348791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 34887110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 34897110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 3490ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 34917110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 34927110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 349391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic: 3494ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmExpr(QualType type, 349591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall ExprValueKind valueKind, 349691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation loc, 349791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *param, 349891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *replacement) 349991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 350091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isTypeDependent(), replacement->isValueDependent(), 350191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isInstantiationDependent(), 350291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->containsUnexpandedParameterPack()), 350391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Param(param), Replacement(replacement), NameLoc(loc) {} 350491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 350591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation getNameLoc() const { return NameLoc; } 3506aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; } 350791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 350891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *getReplacement() const { return cast<Expr>(Replacement); } 3509ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 351091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *getParameter() const { return Param; } 351191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 351291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall static bool classof(const Stmt *s) { 351391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 351491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3515ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 351691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Iterators 351791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall child_range children() { return child_range(&Replacement, &Replacement+1); } 351891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}; 351991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 3520c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that 3521c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack. 3522c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// 3523c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3524c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template 3525fb7669ee725ec699e2b49b8359c4652536949739Douglas Gregor/// parameter lists, this node is used to represent a non-type template 3526c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3527c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3528c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3529c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3530c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying 3531c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index. 3532c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr { 3533c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The non-type template parameter pack itself. 3534c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param; 3535ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3536c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief A pointer to the set of template arguments that this 3537c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// parameter pack is instantiated with. 3538c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument *Arguments; 3539ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3540c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3541c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor unsigned NumArguments; 3542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3543c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The location of the non-type template parameter pack reference. 3544c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc; 3545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 35467110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 3547c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor friend class ASTStmtReader; 3548ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 35497110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3550ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3551c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic: 3552ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmPackExpr(QualType T, 3553c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param, 3554c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc, 3555c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument &ArgPack); 3556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3557c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the non-type template parameter pack being substituted. 3558c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3559c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 3560c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the location of the parameter pack name. 3561c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation getParameterPackLocation() const { return NameLoc; } 3562ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3563c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the template argument pack containing the substituted 3564c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// template arguments. 3565c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor TemplateArgument getArgumentPack() const; 3566c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 3567aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; } 3568ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3569c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor static bool classof(const Stmt *T) { 3570c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3571c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3572ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3573c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Iterators 357463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3575c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}; 357603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 35779a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \brief Represents a reference to a function parameter pack that has been 35789a4db032ecd991626d236a502e770126db32bd31Richard Smith/// substituted but not yet expanded. 35799a4db032ecd991626d236a502e770126db32bd31Richard Smith/// 35809a4db032ecd991626d236a502e770126db32bd31Richard Smith/// When a pack expansion contains multiple parameter packs at different levels, 35819a4db032ecd991626d236a502e770126db32bd31Richard Smith/// this node is used to represent a function parameter pack at an outer level 35829a4db032ecd991626d236a502e770126db32bd31Richard Smith/// which we have already substituted to refer to expanded parameters, but where 35839a4db032ecd991626d236a502e770126db32bd31Richard Smith/// the containing pack expansion cannot yet be expanded. 35849a4db032ecd991626d236a502e770126db32bd31Richard Smith/// 35859a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \code 35869a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Ts> struct S { 35879a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 35889a4db032ecd991626d236a502e770126db32bd31Richard Smith/// }; 35899a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template struct S<int, int>; 35909a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \endcode 35919a4db032ecd991626d236a502e770126db32bd31Richard Smithclass FunctionParmPackExpr : public Expr { 35929a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The function parameter pack which was referenced. 35939a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *ParamPack; 35949a4db032ecd991626d236a502e770126db32bd31Richard Smith 35959a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The location of the function parameter pack reference. 35969a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc; 35979a4db032ecd991626d236a502e770126db32bd31Richard Smith 35989a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The number of expansions of this pack. 35999a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned NumParameters; 36009a4db032ecd991626d236a502e770126db32bd31Richard Smith 36019a4db032ecd991626d236a502e770126db32bd31Richard Smith FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 36029a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc, unsigned NumParams, 36039a4db032ecd991626d236a502e770126db32bd31Richard Smith Decl * const *Params); 36049a4db032ecd991626d236a502e770126db32bd31Richard Smith 36059a4db032ecd991626d236a502e770126db32bd31Richard Smith friend class ASTReader; 36069a4db032ecd991626d236a502e770126db32bd31Richard Smith friend class ASTStmtReader; 36079a4db032ecd991626d236a502e770126db32bd31Richard Smith 36089a4db032ecd991626d236a502e770126db32bd31Richard Smithpublic: 36099a4db032ecd991626d236a502e770126db32bd31Richard Smith static FunctionParmPackExpr *Create(ASTContext &Context, QualType T, 36109a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *ParamPack, 36119a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc, 36129a4db032ecd991626d236a502e770126db32bd31Richard Smith llvm::ArrayRef<Decl*> Params); 36139a4db032ecd991626d236a502e770126db32bd31Richard Smith static FunctionParmPackExpr *CreateEmpty(ASTContext &Context, 36149a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned NumParams); 36159a4db032ecd991626d236a502e770126db32bd31Richard Smith 36169a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the parameter pack which this expression refers to. 36179a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *getParameterPack() const { return ParamPack; } 36189a4db032ecd991626d236a502e770126db32bd31Richard Smith 36199a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the location of the parameter pack. 36209a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation getParameterPackLocation() const { return NameLoc; } 36219a4db032ecd991626d236a502e770126db32bd31Richard Smith 36229a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Iterators over the parameters which the parameter pack expanded 36239a4db032ecd991626d236a502e770126db32bd31Richard Smith /// into. 36249a4db032ecd991626d236a502e770126db32bd31Richard Smith typedef ParmVarDecl * const *iterator; 36259a4db032ecd991626d236a502e770126db32bd31Richard Smith iterator begin() const { return reinterpret_cast<iterator>(this+1); } 36269a4db032ecd991626d236a502e770126db32bd31Richard Smith iterator end() const { return begin() + NumParameters; } 36279a4db032ecd991626d236a502e770126db32bd31Richard Smith 36289a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the number of parameters in this parameter pack. 36299a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned getNumExpansions() const { return NumParameters; } 36309a4db032ecd991626d236a502e770126db32bd31Richard Smith 36319a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get an expansion of the parameter pack by index. 36329a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 36339a4db032ecd991626d236a502e770126db32bd31Richard Smith 36349a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; } 36359a4db032ecd991626d236a502e770126db32bd31Richard Smith 36369a4db032ecd991626d236a502e770126db32bd31Richard Smith static bool classof(const Stmt *T) { 36379a4db032ecd991626d236a502e770126db32bd31Richard Smith return T->getStmtClass() == FunctionParmPackExprClass; 36389a4db032ecd991626d236a502e770126db32bd31Richard Smith } 36399a4db032ecd991626d236a502e770126db32bd31Richard Smith 36409a4db032ecd991626d236a502e770126db32bd31Richard Smith child_range children() { return child_range(); } 36419a4db032ecd991626d236a502e770126db32bd31Richard Smith}; 36429a4db032ecd991626d236a502e770126db32bd31Richard Smith 364303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that 364403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it. 364503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 364603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address 364703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a 364803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g., 364903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 365003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code 365103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0; 365203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode 365303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 365403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 365503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference 365603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 365703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding 365803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues. 365903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr { 366003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief The temporary-generating expression whose value will be 366103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// materialized. 3662d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer Stmt *Temporary; 3663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 366403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtReader; 366503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtWriter; 3666ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 366703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic: 3668ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3669b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor bool BoundToLvalueReference) 3670b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor : Expr(MaterializeTemporaryExprClass, T, 367103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 367203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->isTypeDependent(), Temporary->isValueDependent(), 3673561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Temporary->isInstantiationDependent(), 367403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->containsUnexpandedParameterPack()), 367503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary(Temporary) { } 3676ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(EmptyShell Empty) 367803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor : Expr(MaterializeTemporaryExprClass, Empty) { } 3679ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 368003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Retrieve the temporary-generating subexpression whose value will 368103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// be materialized into a glvalue. 368203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 368403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Determine whether this materialized temporary is bound to an 368503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// lvalue reference; otherwise, it's bound to an rvalue reference. 3686ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isBoundToLvalueReference() const { 368703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getValueKind() == VK_LValue; 368803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3690aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 3691aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar return Temporary->getSourceRange(); 3692aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 3693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 369403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor static bool classof(const Stmt *T) { 369503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return T->getStmtClass() == MaterializeTemporaryExprClass; 369603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3697ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 369803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Iterators 369903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor child_range children() { return child_range(&Temporary, &Temporary + 1); } 370003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}; 3701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 37025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 37035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 37045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3705