ExprCXX.h revision 76da55d3a49e1805f51b1ced7c5da5bcd7f759d8
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; 3276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallclass MSPropertyDecl; 33aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo; 342fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass UuidAttr; 354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions. 381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator 413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax. 423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator 443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the 463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call. 473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever 493fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the 503fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and 513fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template 523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time. 53b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr { 54063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief The overloaded operator. 55063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind Operator; 564548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange Range; 57063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 58be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Record the FP_CONTRACT state that applies to this operator call. Only 59be9af1288881110e406b87914162eaa59f1e5918Lang Hames // meaningful for floating point types. For other types this value can be 60be9af1288881110e406b87914162eaa59f1e5918Lang Hames // set to false. 61be9af1288881110e406b87914162eaa59f1e5918Lang Hames unsigned FPContractable : 1; 62be9af1288881110e406b87914162eaa59f1e5918Lang Hames 634548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange getSourceRangeImpl() const LLVM_READONLY; 64b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic: 651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 663b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 67be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation operatorloc, bool fpContractable) 683b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK, 69f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall operatorloc), 70be9af1288881110e406b87914162eaa59f1e5918Lang Hames Operator(Op), FPContractable(fpContractable) { 714548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis Range = getSourceRangeImpl(); 724548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis } 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 74ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(C, CXXOperatorCallExprClass, Empty) { } 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 77b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator - Returns the kind of overloaded operator that this 78b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// expression refers to. 79063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind getOperator() const { return Operator; } 80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperatorLoc - Returns the location of the operator symbol in 82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// the expression. When @c getOperator()==OO_Call, this is the 83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// location of the right parentheses; when @c 84b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator()==OO_Subscript, this is the location of the right 85b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// bracket. 86b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SourceLocation getOperatorLoc() const { return getRParenLoc(); } 87b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 8865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 8965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 904548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis SourceRange getSourceRange() const { return Range; } 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXOperatorCallExprClass; 94b4609806e9232593ece09ce08b630836e825865cDouglas Gregor } 954548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis 96be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Set the FP contractability status of this operator. Only meaningful for 97be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 98be9af1288881110e406b87914162eaa59f1e5918Lang Hames void setFPContractable(bool FPC) { FPContractable = FPC; } 99be9af1288881110e406b87914162eaa59f1e5918Lang Hames 100be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Get the FP contractability status of this operator. Only meaningful for 101be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 102be9af1288881110e406b87914162eaa59f1e5918Lang Hames bool isFPContractable() const { return FPContractable; } 103be9af1288881110e406b87914162eaa59f1e5918Lang Hames 1044548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis friend class ASTStmtReader; 1054548ca2912e5f2b78a20e50c58d8a1a9c5e9e67cArgyrios Kyrtzidis friend class ASTStmtWriter; 106b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}; 107b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that 10988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()" 11088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax 11188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member 11288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains 11388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the 11488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including 11588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument). 11688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr { 11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic: 1183b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args, 119f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation RP) 1203b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {} 12188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 1221817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 1231817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1241817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner 12588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// getImplicitObjectArgument - Retrieves the implicit object 12688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// argument for the member call. For example, in "x.f(5)", this 12788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// operation would return "x". 128b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek Expr *getImplicitObjectArgument() const; 129ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 130b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek /// Retrieves the declaration of the called method. 131b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek CXXMethodDecl *getMethodDecl() const; 13288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 133007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 134007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// the implicit object argument. Note that this is may not be the same 135007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// declaration as that of the class context of the CXXMethodDecl which this 136007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// function is calling. 137007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// FIXME: Returns 0 for member pointer call exprs. 1380cf3c0eecbff007cea2750c113894b47d9e09f33David Blaikie CXXRecordDecl *getRecordDecl() const; 139007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth 1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor return T->getStmtClass() == CXXMemberCallExprClass; 14288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor } 14388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor}; 14488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr { 147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate: 148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne enum { CONFIG, END_PREARG }; 149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic: 151e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 1523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 1533b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation RP) 1543b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) { 155e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne setConfig(Config); 156e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 157e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 158e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 159e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 160e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 161e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne const CallExpr *getConfig() const { 162e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return cast_or_null<CallExpr>(getPreArg(CONFIG)); 163e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 164e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 165e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 166e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 167e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const Stmt *T) { 168e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return T->getStmtClass() == CUDAKernelCallExprClass; 169e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 170e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}; 171e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 17249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 17349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 17449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast. 17549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 17649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes 17749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr, 17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 17949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr { 1801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate: 1811060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; // the location of the casting op 1821d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc; // the location of the right parenthesis 183f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets; // range for '<' '>' 184ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 186f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 187f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 1881d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 189f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 190f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets) 1911d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 192f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} 19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(SC, Shell, PathSize) { } 196ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1971d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor friend class ASTStmtReader; 198ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor const char *getCastName() const; 20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 202a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// \brief Retrieve the location of the cast operator keyword, e.g., 203a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// "static_cast". 204a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor SourceLocation getOperatorLoc() const { return Loc; } 205a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor 2061d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor /// \brief Retrieve the location of the closing parenthesis. 2071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 21065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 211f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; } 21265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 2131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor switch (T->getStmtClass()) { 21549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXStaticCastExprClass: 21649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXDynamicCastExprClass: 21749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXReinterpretCastExprClass: 21849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXConstCastExprClass: 21949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 22049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor default: 22149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return false; 22249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 2231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 22449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 22549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 226ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression 227ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]). 2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g., 23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0). 23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr { 232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 233f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize, TypeSourceInfo *writtenTy, 234f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation l, SourceLocation RParenLoc, 235f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets) 236f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 237f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian writtenTy, l, RParenLoc, AngleBrackets) {} 23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 242f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 243f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 244f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 246ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 247f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 248f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets); 249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 251ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXStaticCastExprClass; 25449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 25549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 25649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 25749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 25949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast. 2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 26149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g., 26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr). 26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr { 264f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 265f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 266f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation l, SourceLocation RParenLoc, 267f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets) 268f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 269f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian writtenTy, l, RParenLoc, AngleBrackets) {} 27049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 271f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 272f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 273f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 274f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 275f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, Expr *Op, 277f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 278ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 279f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 280f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets); 281ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 284ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2850fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson bool isAlwaysNull() const; 2860fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXDynamicCastExprClass; 28949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 29049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 29149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 29249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 29349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view 29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time. 2951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g., 29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr). 29849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 299f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 300f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, 301ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 302f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 303f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets) 304f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 305f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian pathSize, writtenTy, l, RParenLoc, AngleBrackets) {} 30649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 307f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 308f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 309f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 310f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, 313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *Op, const CXXCastPath *Path, 314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 315f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 316f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets); 317f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 318f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 319ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 32149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXReinterpretCastExprClass; 32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 32549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 32649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value. 3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 32849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g., 32949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar). 33049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr { 331f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 332ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 333f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, SourceRange AngleBrackets) 334ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 335f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian 0, writtenTy, l, RParenLoc, AngleBrackets) {} 33649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 337ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig explicit CXXConstCastExpr(EmptyShell Empty) 338f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 339f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 340f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, Expr *Op, 343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 344f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceLocation RParenLoc, 345f799ae1afb897151a84a7170951e367d8307ae04Fariborz Jahanian SourceRange AngleBrackets); 346f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 347ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 34949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXConstCastExprClass; 35049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 3511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal]) 3549fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// written as a user-defined literal (C++11 [lit.ext]). 3559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// 3569fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this 3579fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// is semantically equivalent to a normal call, this AST node provides better 3589fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// information about the syntactic representation of the literal. 3599fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// 3609fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// Since literal operators are never found by ADL and can only be declared at 3619fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith/// namespace scope, a user-defined literal is never dependent. 3629fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithclass UserDefinedLiteral : public CallExpr { 3639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// \brief The location of a ud-suffix within the literal. 3649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith SourceLocation UDSuffixLoc; 3659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithpublic: 3673b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args, 3689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith QualType T, ExprValueKind VK, SourceLocation LitEndLoc, 3699fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith SourceLocation SuffixLoc) 3703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc), 3713b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer UDSuffixLoc(SuffixLoc) {} 3729fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty) 3739fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith : CallExpr(C, UserDefinedLiteralClass, Empty) {} 3749fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3759fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// The kind of literal operator which is invoked. 3769fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith enum LiteralOperatorKind { 3779fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Raw, ///< Raw form: operator "" X (const char *) 3789fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Template, ///< Raw form: operator "" X<cs...> () 3799fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Integer, ///< operator "" X (unsigned long long) 3809fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Floating, ///< operator "" X (long double) 3819fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_String, ///< operator "" X (const CharT *, size_t) 3829fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LOK_Character ///< operator "" X (CharT) 3839fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith }; 3849fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3859fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getLiteralOperatorKind - Returns the kind of literal operator invocation 3869fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// which this expression represents. 3879fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith LiteralOperatorKind getLiteralOperatorKind() const; 3889fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3899fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getCookedLiteral - If this is not a raw user-defined literal, get the 3909fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// underlying cooked literal (representing the literal with the suffix 3919fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// removed). 3929fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith Expr *getCookedLiteral(); 3939fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith const Expr *getCookedLiteral() const { 3949fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); 3959fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith } 3969fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 3970265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getLocStart() const { 3980265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara if (getLiteralOperatorKind() == LOK_Template) 3990265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara return getRParenLoc(); 4000265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara return getArg(0)->getLocStart(); 4010265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara } 4020265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getLocEnd() const { return getRParenLoc(); } 4030265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara 4040265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara 4059fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression. 4069fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// For a string literal, there may be multiple identical suffixes. This 4079fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// returns the first. 4080265555a0fec81102bfb3757cfc7f3d90dbbe409Abramo Bagnara SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } 4099fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4109fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith /// getUDSuffix - Returns the ud-suffix specified for this literal. 4119fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith const IdentifierInfo *getUDSuffix() const; 4129fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4139fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith static bool classof(const Stmt *S) { 4149fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return S->getStmtClass() == UserDefinedLiteralClass; 4159fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith } 4169fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4179fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith friend class ASTStmtReader; 4189fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith friend class ASTStmtWriter; 4199fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith}; 4209fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 4211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 4231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr { 4241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool Value; 4251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; 4261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 428bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 429561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 430f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(val), Loc(l) {} 4318b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 432eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXBoolLiteralExpr(EmptyShell Empty) 433eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXBoolLiteralExprClass, Empty) { } 434eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool getValue() const { return Value; } 436eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setValue(bool V) { Value = V; } 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 43865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 43965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 441eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 442eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 443eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 4451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXBoolLiteralExprClass; 4461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 4471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 44963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 4511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 4526e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 4536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr { 4546e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl SourceLocation Loc; 4556e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic: 4566e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 457bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 458561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 459f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) {} 4606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 461eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 462eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXNullPtrLiteralExprClass, Empty) { } 463eb7f96141f754150a92433286fa385910a22f494Sam Weinig 46465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 46565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 4666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 467eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 468eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 469eb7f96141f754150a92433286fa385910a22f494Sam Weinig 4706e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const Stmt *T) { 4716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return T->getStmtClass() == CXXNullPtrLiteralExprClass; 4726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl } 4736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 47463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 4756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl}; 4766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 477c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 478c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly 479c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression. 480c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 481c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr) 482c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr { 483c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate: 48457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 485c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SourceRange Range; 486c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 487c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic: 48857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 489f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 49057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 49157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor false, 49257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is value-dependent if the type or expression are dependent 493bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->isDependentType(), 494561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 495bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 49657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 497ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 49857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 499f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 5002850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is never type-dependent (C++ [temp.dep.expr]p4) 501bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, 5022850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is value-dependent if the type or expression are dependent 503bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->isTypeDependent() || Operand->isValueDependent(), 504561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 505bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 50657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 507c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 50814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner CXXTypeidExpr(EmptyShell Empty, bool isExpr) 50914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner : Expr(CXXTypeidExprClass, Empty) { 51014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner if (isExpr) 51114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (Expr*)0; 51214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner else 51314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (TypeSourceInfo*)0; 51414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 515ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5160d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith /// Determine whether this typeid has a type operand which is potentially 5170d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith /// evaluated, per C++11 [expr.typeid]p3. 5180d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith bool isPotentiallyEvaluated() const; 5190d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith 52057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 521ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 52257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieves the type operand of this typeid() expression after 52357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 52457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor QualType getTypeOperand() const; 52557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor 52657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieve source information for the type operand. 52757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *getTypeOperandSourceInfo() const { 528c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 52957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return Operand.get<TypeSourceInfo *>(); 530c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 53114ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner 53214ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 53314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 53414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = TSI; 53514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 536ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 53714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Expr *getExprOperand() const { 538c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 53957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 540c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 541ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 542030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner void setExprOperand(Expr *E) { 543030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 544030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner Operand = E; 545030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner } 546ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 54765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 54865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 549aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 55014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setSourceRange(SourceRange R) { Range = R; } 551ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 552c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const Stmt *T) { 553c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return T->getStmtClass() == CXXTypeidExprClass; 554c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 555c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 556c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Iterators 55763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 55863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 55963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 56063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 56163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 562c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl}; 563c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 56476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall/// A member reference to an MSPropertyDecl. This expression always 56576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall/// has pseudo-object type, and therefore it is typically not 56676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall/// encountered in a fully-typechecked expression except within the 56776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall/// syntactic form of a PseudoObjectExpr. 56876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallclass MSPropertyRefExpr : public Expr { 56976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall Expr *BaseExpr; 57076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall MSPropertyDecl *TheDecl; 57176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceLocation MemberLoc; 57276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall bool IsArrow; 57376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall NestedNameSpecifierLoc QualifierLoc; 57476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 57576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCallpublic: 57676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, 57776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall QualType ty, ExprValueKind VK, 57876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall NestedNameSpecifierLoc qualifierLoc, 57976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceLocation nameLoc) 58076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary, 58176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall /*type-dependent*/ false, baseExpr->isValueDependent(), 58276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall baseExpr->isInstantiationDependent(), 58376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall baseExpr->containsUnexpandedParameterPack()), 58476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall BaseExpr(baseExpr), TheDecl(decl), 58576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall MemberLoc(nameLoc), IsArrow(isArrow), 58676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall QualifierLoc(qualifierLoc) {} 58776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 58876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} 58976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 59076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceRange getSourceRange() const LLVM_READONLY { 59176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return SourceRange(getLocStart(), getLocEnd()); 59276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall } 59376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall bool isImplicitAccess() const { 59476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); 59576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall } 59676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceLocation getLocStart() const { 59776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall if (!isImplicitAccess()) 59876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return BaseExpr->getLocStart(); 59976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall else if (QualifierLoc) 60076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return QualifierLoc.getBeginLoc(); 60176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall else 60276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return MemberLoc; 60376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall } 60476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceLocation getLocEnd() const { return getMemberLoc(); } 60576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 60676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall child_range children() { 60776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); 60876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall } 60976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall static bool classof(const Stmt *T) { 61076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall return T->getStmtClass() == MSPropertyRefExprClass; 61176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall } 61276da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 61376da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall Expr *getBaseExpr() const { return BaseExpr; } 61476da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall MSPropertyDecl *getPropertyDecl() const { return TheDecl; } 61576da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall bool isArrow() const { return IsArrow; } 61676da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall SourceLocation getMemberLoc() const { return MemberLoc; } 61776da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 61876da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 61976da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall friend class ASTStmtReader; 62076da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall}; 62176da55d3a49e1805f51b1ced7c5da5bcd7f759d8John McCall 62201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 62301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression. 62401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 62501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 62601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr { 62701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate: 62801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 62901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceRange Range; 63001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 63101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic: 63201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 6332e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 634bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->getType()->isDependentType(), 635561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 636bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 63701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 638ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 63901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 6402e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 641bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->isTypeDependent(), 642561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 643bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 64401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 64501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 64601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(EmptyShell Empty, bool isExpr) 64701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet : Expr(CXXUuidofExprClass, Empty) { 64801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (isExpr) 64901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (Expr*)0; 65001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet else 65101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (TypeSourceInfo*)0; 65201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 65401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 655ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 65601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieves the type operand of this __uuidof() expression after 65701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// various required adjustments (removing reference types, cv-qualifiers). 65801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet QualType getTypeOperand() const; 65901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 66001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieve source information for the type operand. 66101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *getTypeOperandSourceInfo() const { 66201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 66301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return Operand.get<TypeSourceInfo *>(); 66401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 66501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 66601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 66701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 66801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = TSI; 66901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 670ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 67101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *getExprOperand() const { 67201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 67301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return static_cast<Expr*>(Operand.get<Stmt *>()); 67401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 675ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 67601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setExprOperand(Expr *E) { 67701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 67801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = E; 67901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 68001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 68165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 68265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 683aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 68401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setSourceRange(SourceRange R) { Range = R; } 685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 68601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const Stmt *T) { 68701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return T->getStmtClass() == CXXUuidofExprClass; 68801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 68901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 690c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none. 691c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber static UuidAttr *GetUuidAttrOfType(QualType QT); 692c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber 69301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Iterators 69463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 69563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 69663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 69763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 69863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 69901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}; 70001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 701796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a 702796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is 703796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example: 704796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// 705796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code 706796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo { 707796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public: 708796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void bar(); 709796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void test() { this->bar(); } 710796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// }; 711796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode 712796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr { 713796da18402f286b897782a298ae3b20c459c102eDouglas Gregor SourceLocation Loc; 714828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool Implicit : 1; 715ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 716796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic: 717828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 718f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 7192850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // 'this' is type-dependent if the class type of the enclosing 7202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // member function is dependent (C++ [temp.dep.expr]p2) 721bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 722561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 723bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 724828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor Loc(L), Implicit(isImplicit) { } 725796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 7262fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 7272fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 7282fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner SourceLocation getLocation() const { return Loc; } 7292fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 7302fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 73165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 73265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 733796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 734828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool isImplicit() const { return Implicit; } 735828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor void setImplicit(bool I) { Implicit = I; } 736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 738796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return T->getStmtClass() == CXXThisExprClass; 739796da18402f286b897782a298ae3b20c459c102eDouglas Gregor } 740796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 741796da18402f286b897782a298ae3b20c459c102eDouglas Gregor // Iterators 74263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 743796da18402f286b897782a298ae3b20c459c102eDouglas Gregor}; 744796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 7451060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 7461060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 'throw' and 'throw' assignment-expression. When 7471060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// assignment-expression isn't present, Op will be null. 7481060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 7491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr { 7501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Op; 7511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation ThrowLoc; 752bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Whether the thrown variable (if any) is in scope. 753bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned IsThrownVariableInScope : 1; 754ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 755bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor friend class ASTStmtReader; 756ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 7581060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Ty is the void type which is used as the result type of the 7591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // exepression. The l is the location of the throw keyword. expr 7601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // can by null, if the optional expression to throw isn't present. 761bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 762bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) : 763bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 764561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor expr && expr->isInstantiationDependent(), 765bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor expr && expr->containsUnexpandedParameterPack()), 766bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 7672fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 7682fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 7691060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 7701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 77142e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor 77242e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor SourceLocation getThrowLoc() const { return ThrowLoc; } 7731060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 774bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Determines whether the variable thrown by this expression (if any!) 775bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// is within the innermost try block. 776bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// 777bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// This information is required to determine whether the NRVO can apply to 778bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// this variable. 779bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 780ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 78165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; } 78265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 7831060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek if (getSubExpr() == 0) 78465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return ThrowLoc; 78565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSubExpr()->getLocEnd(); 7861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 7891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXThrowExprClass; 7901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7911060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 79363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 79463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Op, Op ? &Op+1 : &Op); 79563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 7961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 7971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 7991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding 8001060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly 8011060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters. 8021060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr { 80365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// \brief The parameter whose default is being used. 80465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// 805ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// When the bit is set, the subexpression is stored after the 80665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 80765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// actual default expression is the subexpression. 80865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 810036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// \brief The location where the default argument expression was used. 811036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc; 812ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 813036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(SC, 81565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor param->hasUnparsedDefaultArg() 81665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ? param->getType().getNonReferenceType() 8172333f7727f97018d6742e1e0938133bcfad967abEli Friedman : param->getDefaultArg()->getType(), 818dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall param->getDefaultArg()->getValueKind(), 819561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor param->getDefaultArg()->getObjectKind(), false, false, false, false), 820036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param(param, false), Loc(Loc) { } 82165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor 822ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 823036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Expr *SubExpr) 824dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall : Expr(SC, SubExpr->getType(), 825dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall SubExpr->getValueKind(), SubExpr->getObjectKind(), 826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false, false, false, false), 827bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Param(param, true), Loc(Loc) { 82865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor *reinterpret_cast<Expr **>(this + 1) = SubExpr; 82965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 830ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 832030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 833030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner 834ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Param is the parameter whose default argument is used by this 8361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // expression. 837036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 838036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 839036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 840f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson } 8411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 84265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // Param is the parameter whose default argument is used by this 84365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // expression, and SubExpr is the expression that will actually be used. 844ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static CXXDefaultArgExpr *Create(ASTContext &C, 845036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc, 846ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ParmVarDecl *Param, 84765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor Expr *SubExpr); 848ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8491060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the parameter that the argument was created from. 85065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor const ParmVarDecl *getParam() const { return Param.getPointer(); } 85165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ParmVarDecl *getParam() { return Param.getPointer(); } 852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8531060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the actual argument to the function call. 854ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const Expr *getExpr() const { 85565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 85665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr const * const*> (this + 1); 857ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 85865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getExpr() { 86065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 86165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr **> (this + 1); 862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 86365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 8641060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 865ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the location where this default argument was actually 866036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// used. 867036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation getUsedLocation() const { return Loc; } 868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 86965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen // Default argument expressions have no representation in the 87065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen // source, so they have an empty source range. 87165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 87265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 87363b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer 87463b6ebe4e732f20fa24ea0666ed438dd5004cc20Benjamin Kramer SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 8751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 8761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 8771060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXDefaultArgExprClass; 8781060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 8791060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 8801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 88163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 8828a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis 88360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 8843397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 8851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 886987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 887c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary. 888c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary { 889c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson /// Destructor - The destructor that needs to be called. 890b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor; 8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 892b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson CXXTemporary(const CXXDestructorDecl *destructor) 893c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson : Destructor(destructor) { } 894c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson 895c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic: 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXTemporary *Create(ASTContext &C, 897b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor); 8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 899f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXDestructorDecl *getDestructor() const { return Destructor; } 90076f3f69db1416425070177243e9f390122c553e0Richard Smith void setDestructor(const CXXDestructorDecl *Dtor) { 90176f3f69db1416425070177243e9f390122c553e0Richard Smith Destructor = Dtor; 90276f3f69db1416425070177243e9f390122c553e0Richard Smith } 903c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson}; 904fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 905ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary. 906ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 907ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be 908ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example: 909ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 910ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code 911ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// struct S { 912ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// S() { } // User defined constructor makes S non-POD. 913ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// ~S() { } // User defined destructor makes it non-trivial. 914ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// }; 915ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// void test() { 916ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 917ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// } 918ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode 919fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr { 920fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson CXXTemporary *Temp; 9211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 922fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Stmt *SubExpr; 923fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 924bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 925bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 926ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 927bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->isValueDependent(), 928561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SubExpr->isInstantiationDependent(), 929bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->containsUnexpandedParameterPack()), 930bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Temp(temp), SubExpr(SubExpr) { } 93188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson 932fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic: 933d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner CXXBindTemporaryExpr(EmptyShell Empty) 934d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 935ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 937fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr* SubExpr); 9381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 93988eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson CXXTemporary *getTemporary() { return Temp; } 940f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXTemporary *getTemporary() const { return Temp; } 941d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner void setTemporary(CXXTemporary *T) { Temp = T; } 942f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson 943fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 944fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 94588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 946fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 94765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 94865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExpr->getLocStart(); 94996be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 95065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 951fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 952fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Implement isa/cast/dyncast/etc. 953fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const Stmt *T) { 954fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson return T->getStmtClass() == CXXBindTemporaryExprClass; 955fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson } 956fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 957fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Iterators 95863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 959fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson}; 960fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 9610982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a call to a C++ constructor. 96215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr { 96372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic: 96472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson enum ConstructionKind { 96572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_Complete, 96672e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_NonVirtualBase, 967059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_VirtualBase, 968059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_Delegating 96972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson }; 970ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 97172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate: 97215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson CXXConstructorDecl *Constructor; 97315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 97499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc; 975428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange; 976a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor unsigned NumArgs : 16; 97716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool Elidable : 1; 9787cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 9795b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization : 1; 98016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool ZeroInitialization : 1; 98172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson unsigned ConstructKind : 2; 98215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson Stmt **Args; 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 984bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected: 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 98699a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 987bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson CXXConstructorDecl *d, bool elidable, 9883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 9897cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 9905b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 9915b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 9925b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 9935b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 994bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson 9956d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 9966d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis CXXConstructExpr(StmtClass SC, EmptyShell Empty) 9975b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 9985b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl HadMultipleCandidates(false), ListInitialization(false), 9995b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ZeroInitialization(false), ConstructKind(0), Args(0) 10005b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 10016d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 100215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic: 10036d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 10046d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXConstructExpr(EmptyShell Empty) 10056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis : Expr(CXXConstructExprClass, Empty), Constructor(0), 10065b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl NumArgs(0), Elidable(false), HadMultipleCandidates(false), 10075b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ListInitialization(false), ZeroInitialization(false), 10085b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructKind(0), Args(0) 10095b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 10106d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 10118e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson static CXXConstructExpr *Create(ASTContext &C, QualType T, 101299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 10131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructorDecl *D, bool Elidable, 10143b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 10157cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 10165b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 10175b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 10185b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 10195b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 10201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1021d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor CXXConstructorDecl* getConstructor() const { return Constructor; } 102239da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 1023ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 102499a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation getLocation() const { return Loc; } 102599a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor void setLocation(SourceLocation Loc) { this->Loc = Loc; } 1026ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1027d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor /// \brief Whether this construction is elidable. 1028d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor bool isElidable() const { return Elidable; } 102939da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setElidable(bool E) { Elidable = E; } 10307cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 10317cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Whether the referred constructor was resolved from 10327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// an overloaded set having size greater than 1. 10337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { return HadMultipleCandidates; } 10347cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 10357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 10365b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl /// \brief Whether this constructor call was written as list-initialization. 10375b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool isListInitialization() const { return ListInitialization; } 10385b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl void setListInitialization(bool V) { ListInitialization = V; } 10395b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl 104016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// \brief Whether this construction first requires 104116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// zero-initialization before the initializer is called. 104216006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool requiresZeroInitialization() const { return ZeroInitialization; } 104316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor void setRequiresZeroInitialization(bool ZeroInit) { 104416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor ZeroInitialization = ZeroInit; 104516006c901315fa12a108b4e571f187f4b676e426Douglas Gregor } 1046ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 10479db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// \brief Determines whether this constructor is actually constructing 10489db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// a base class (rather than a complete object). 104924eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson ConstructionKind getConstructionKind() const { 105024eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson return (ConstructionKind)ConstructKind; 105172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 1052ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setConstructionKind(ConstructionKind CK) { 105372e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson ConstructKind = CK; 105472e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 1055ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 105615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ExprIterator arg_iterator; 105715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ConstExprIterator const_arg_iterator; 10581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_begin() { return Args; } 106015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_end() { return Args + NumArgs; } 106115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_begin() const { return Args; } 106215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_end() const { return Args + NumArgs; } 106315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 1064a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 106515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson unsigned getNumArgs() const { return NumArgs; } 106615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 1067bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson /// getArg - Return the specified argument. 1068bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson Expr *getArg(unsigned Arg) { 1069bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 1070bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 1071bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 1072bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson const Expr *getArg(unsigned Arg) const { 1073bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 1074bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 1075bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10772eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian /// setArg - Set the specified argument. 10782eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian void setArg(unsigned Arg, Expr *ArgExpr) { 10792eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian assert(Arg < NumArgs && "Arg access out of range!"); 10802eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian Args[Arg] = ArgExpr; 10812eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian } 10822eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian 108365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 108465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY; 1085428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange getParenRange() const { return ParenRange; } 1086a770a4daf77037b5526dba1c447d61acf0aba01aDaniel Jasper void setParenRange(SourceRange Range) { ParenRange = Range; } 108715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1089524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson return T->getStmtClass() == CXXConstructExprClass || 1090524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson T->getStmtClass() == CXXTemporaryObjectExprClass; 109115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson } 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson // Iterators 109463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 109563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Args[0], &Args[0]+NumArgs); 109663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 10976d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 109860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 109915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson}; 110015ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 11010982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents an explicit C++ type conversion that uses "functional" 11020982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// notation (C++ [expr.type.conv]). 11030982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 11040982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// Example: 11050982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 11060982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// x = int(0.5); 11070982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 110849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr { 1109987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation TyBeginLoc; 1110987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1111f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1112f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1113f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy, 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation tyBeginLoc, CastKind kind, 1115f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *castExpr, unsigned pathSize, 1116ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation rParenLoc) 1117f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1118f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall castExpr, pathSize, writtenTy), 11190aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 11200aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson 1121f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1122f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1123f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 1124f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 1125f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 1126f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 1127f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *Written, 1128f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation TyBeginLoc, 1129f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Op, 1130f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 1131f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation RPLoc); 1132f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 1133f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 1134ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1135987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1136ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1137987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getRParenLoc() const { return RParenLoc; } 1138ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setRParenLoc(SourceLocation L) { RParenLoc = L; } 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; } 114165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 114265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXFunctionalCastExprClass; 1145987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1146987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1147987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1148506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a 1149506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object. 1150506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast 1152506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the 1154ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr. 1155506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example: 1156506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code 1157506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); } 1158506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 1159506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() { 1160506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1161506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// }; 1162506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode 1163524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr { 1164ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 1165506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1166506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic: 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1168ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 11693b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr *> Args, 1170428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange parenRange, 11717cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 1172c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith bool ListInitialization, 1173c83c2300e1946fea78ecd3c2e93d9c2dd2638a2bRichard Smith bool ZeroInitialization); 11746d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1175ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1176506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1177ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1178ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 117965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 118065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY; 1181ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1183506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor return T->getStmtClass() == CXXTemporaryObjectExprClass; 1184506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor } 11856d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 118660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 1187506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor}; 1188506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 118901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object 119001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later. 119101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 119201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example: 119301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code 119401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) { 119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// values.erase(std::remove_if(values.begin(), values.end(), 1196d9ffa0c39ff9c71e2729eac4cdcf32b377c1d3b6Dmitri Gribenko/// [=](double value) { return value > cutoff; }); 119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// } 119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode 119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying 120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function 120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a 120301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either 120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square 120501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression. 120601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr { 120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor enum { 120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indicate that the given 120901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture was implicit. 121001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_Implicit = 0x01, 121101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 121201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indciate that the 121301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// given capture was by-copy. 121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_ByCopy = 0x02 121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The source range that covers the lambda introducer ([...]). 121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange; 121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12207ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief The number of captures. 12217ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned NumCaptures : 16; 12227ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The default capture kind, which is a value of type 122401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// LambdaCaptureDefault. 122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned CaptureDefault : 2; 122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Whether this lambda had an explicit parameter list vs. an 122801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit (and empty) parameter list. 122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned ExplicitParams : 1; 123001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1231dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had the result type explicitly specified. 1232dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor unsigned ExplicitResultType : 1; 1233dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 1234dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether there are any array index variables stored at the end of 1235dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// this lambda expression. 12367ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned HasArrayIndexVars : 1; 12377ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The location of the closing brace ('}') that completes 123901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// the lambda. 124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 124101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// The location of the brace is also available by looking up the 124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// function call operator in the lambda class. However, it is 124301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stored here to improve the performance of getSourceRange(), and 124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// to avoid having to deserialize the function call operator from a 124501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// module file just to determine the source range. 124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace; 124701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12487ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // Note: The capture initializers are stored directly after the lambda 12497ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // expression, along with the index variables used to initialize by-copy 12507ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // array captures. 12517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Describes the capture of either a variable or 'this'. 125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor class Capture { 125501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 125601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation Loc; 125701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc; 12589daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 125901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 126001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 12619daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 126201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor public: 126301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Create a new capture. 126401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 126501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Loc The source location associated with this capture. 126601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 126701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Kind The kind of capture (this, byref, bycopy). 126801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 126901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Implicit Whether the capture was implicit or explicit. 127001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 127101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Var The local variable being captured, or null if capturing this. 127201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 127301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param EllipsisLoc The location of the ellipsis (...) for a 127401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture that is a pack expansion, or an invalid source 127501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// location to indicate that this is not a pack expansion. 127601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture(SourceLocation Loc, bool Implicit, 127701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind Kind, VarDecl *Var = 0, 127801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc = SourceLocation()); 127901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the kind of capture. 128101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind getCaptureKind() const; 128201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles the C++ 'this' 128401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// pointer. 128501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesThis() const { return VarAndBits.getPointer() == 0; } 128601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles a variable. 128801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 128901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the declaration of the local variable being 129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captured. 129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 129301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// This operation is only valid if this capture does not capture 129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 'this'. 129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor VarDecl *getCapturedVar() const { 129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(!capturesThis() && "No variable available for 'this' capture"); 129701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return VarAndBits.getPointer(); 129801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 129901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 130001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an implicit capture (not 130101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// written between the square brackets introducing the lambda). 130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 130401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an explicit capture, written 130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// between the square brackets introducing the lambda. 130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isExplicit() const { return !isImplicit(); } 130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source location of the capture. 130901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 131001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// For an explicit capture, this returns the location of the 131101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit capture in the source. For an implicit capture, this 131201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// returns the location at which the variable or 'this' was first 131301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// used. 131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getLocation() const { return Loc; } 131501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 131601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture is a pack expansion, 131701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which captures a function parameter pack. 131801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isPackExpansion() const { return EllipsisLoc.isValid(); } 131901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 132001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the location of the ellipsis for a capture 132101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// that is a pack expansion. 132201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getEllipsisLoc() const { 132301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 132401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return EllipsisLoc; 132501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 132601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 132701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 132801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate: 132901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a lambda expression. 133001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaExpr(QualType T, SourceRange IntroducerRange, 133101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 133201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 133301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1334dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 133501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 13369daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 13379daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 1338612409ece080e814f79e06772c690d603f45fbd6Richard Smith SourceLocation ClosingBrace, 1339612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool ContainsUnexpandedParameterPack); 134001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13419d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct an empty lambda expression. 13429d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 13439d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor : Expr(LambdaExprClass, Empty), 13449d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 13459d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor ExplicitResultType(false), HasArrayIndexVars(true) { 13469d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor getStoredStmts()[NumCaptures] = 0; 13479d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 13489d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 13497ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor Stmt **getStoredStmts() const { 13507ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 13517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 13527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 13537ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the mapping from captures to the first array index 13547ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// variable. 13557ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned *getArrayIndexStarts() const { 13567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 13577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 13587ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 13597ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the complete set of array-index variables. 13607ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor VarDecl **getArrayIndexVars() const { 1361a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith unsigned ArrayIndexSize = 1362a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1363a796b6c4b99116ca31e6e61d8765b321678d580eRichard Smith llvm::alignOf<VarDecl*>()); 13647ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<VarDecl **>( 136588d2f678e70ab9360f09f3534d9223e6ec20f129Richard Smith reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 13667ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 13677ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 136801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 136901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a new lambda expression. 137001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static LambdaExpr *Create(ASTContext &C, 137101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *Class, 137201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange, 137301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 137401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 137501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1376dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 137701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 13789daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 13799daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 1380612409ece080e814f79e06772c690d603f45fbd6Richard Smith SourceLocation ClosingBrace, 1381612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool ContainsUnexpandedParameterPack); 138201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13839d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct a new lambda expression that will be deserialized from 13849d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// an external source. 13859d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 13869d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor unsigned NumArrayIndexVars); 13879d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 138801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the default capture kind for this lambda. 138901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault getCaptureDefault() const { 139001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return static_cast<LambdaCaptureDefault>(CaptureDefault); 139101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 139201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 139301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief An iterator that walks over the captures of the lambda, 139401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// both implicit and explicit. 139501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef const Capture *capture_iterator; 139601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 139701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first lambda capture. 1398da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_begin() const; 139901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 140001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the 140101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// sequence of lambda captures. 1402da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_end() const; 140301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 14047ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Determine the number of captures in this lambda. 14057ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned capture_size() const { return NumCaptures; } 14067ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 140701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first explicit 140801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1409da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_begin() const; 141001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 141101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 141201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit lambda captures. 1413da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_end() const; 141401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 141501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first implicit 141601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1417da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_begin() const; 141801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 141901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 142001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit lambda captures. 1421da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_end() const; 142201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 142301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Iterator that walks over the capture initialization 142401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// arguments. 142501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef Expr **capture_init_iterator; 142601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 142701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the first initialization argument for this 142801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression (which initializes the first capture field). 14297ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_begin() const { 14307ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Expr **>(getStoredStmts()); 14317ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 143201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 143301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the iterator pointing one past the last 143476e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor /// initialization argument for this lambda expression. 14357ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_end() const { 14367ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return capture_init_begin() + NumCaptures; 14377ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 143801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 14399daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Retrieve the set of index variables used in the capture 14409daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// initializer of an array captured by copy. 14419daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// 14429daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \param Iter The iterator that points at the capture initializer for 14439daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// which we are extracting the corresponding index variables. 14449daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 14459daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 144601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source range covering the lambda introducer, 144701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which contains the explicit capture list surrounded by square 144801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// brackets ([...]). 144901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getIntroducerRange() const { return IntroducerRange; } 145001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 145101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the class that corresponds to the lambda, which 145201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stores the captures in its fields and provides the various 145301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// operations permitted on a lambda (copying, calling). 145401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *getLambdaClass() const; 145501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 145601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the function call operator associated with this 145701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression. 145801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXMethodDecl *getCallOperator() const; 145901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 146001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the body of the lambda. 14619d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor CompoundStmt *getBody() const; 146201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 146301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether the lambda is mutable, meaning that any 146401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captures values can be modified. 146501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isMutable() const; 146601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 146701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this lambda has an explicit parameter 146801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// list vs. an implicit (empty) parameter list. 146901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool hasExplicitParameters() const { return ExplicitParams; } 147001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1471dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had its result type explicitly specified. 1472dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool hasExplicitResultType() const { return ExplicitResultType; } 14739e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 147401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const Stmt *T) { 147501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return T->getStmtClass() == LambdaExprClass; 147601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 147701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 147865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 147965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return IntroducerRange.getBegin(); 148001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 148165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; } 148201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 14837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor child_range children() { 14847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 14857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 148601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 148701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 148801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 148901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor}; 149001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1491ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1492506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type 1493ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type. 1494987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1495ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr { 1496987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1497ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo; 1498987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1499ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 1500ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1501987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic: 1502ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Create an explicitly-written scalar-value initialization 1503ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// expression. 1504ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr(QualType Type, 1505ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo, 1506ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation rParenLoc ) : 1507f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1508561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, Type->isInstantiationDependentType(), false), 1509ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1510ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 1511ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor explicit CXXScalarValueInitExpr(EmptyShell Shell) 1512ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor : Expr(CXXScalarValueInitExprClass, Shell) { } 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1514ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 1515ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return TypeInfo; 15164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 1517ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1518ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 15194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 152065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 152165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1524ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor return T->getStmtClass() == CXXScalarValueInitExprClass; 1525987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1527987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // Iterators 152863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1529987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1530987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 15310982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @brief Represents a new-expression for memory allocation and constructor 15320982205bade2fb4fc984c27b2ab401e683963b10James Dennett// calls, e.g: "new CXXNewExpr(foo)". 15334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr { 15342aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Contains an optional array size expression, an optional initialization 15352aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // expression, and any number of optional placement arguments, in that order. 15364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt **SubExprs; 15370982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Points to the allocation function used. 15384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorNew; 15390982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Points to the deallocation function used in case of error. May be 15400982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// null. 15414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 15424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15431bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor /// \brief The allocated type-source information, as written in the source. 15441bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo; 1545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1546ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the allocated type was expressed as a parenthesized type-id, 15474bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor /// the source range covering the parenthesized type-id. 15484bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange TypeIdParens; 1549ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1550530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie /// \brief Range of the entire new expression. 1551530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceRange Range; 15522aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 15532aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Source-range of a paren-delimited initializer. 15542aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange DirectInitRange; 15554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1556d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Was the usage ::new, i.e. is the global new to be used? 1557d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool GlobalNew : 1; 1558d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Do we allocate an array? If so, the first SubExpr is the size expression. 1559d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool Array : 1; 1560d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // If this is an array allocation, does the usual deallocation 1561d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // function for the allocated type want to know the allocated size? 1562d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer bool UsualArrayDeleteWantsSize : 1; 1563d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // The number of placement new arguments. 1564d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer unsigned NumPlacementArgs : 13; 1565d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // What kind of initializer do we have? Could be none, parens, or braces. 1566d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // In storage, we distinguish between "none, and no initializer expr", and 1567d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // "none, but an implicit initializer expr". 1568d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer unsigned StoredInitializationStyle : 2; 1569d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 157060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 15712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl friend class ASTStmtWriter; 15724c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 15732aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl enum InitializationStyle { 15742aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NoInit, ///< New-expression has no initializer as written. 15752aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl CallInit, ///< New-expression has a C++98 paren-delimited initializer. 15762aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ListInit ///< New-expression has a C++11 list-initializer. 15772aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl }; 15782aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 1579ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 15801548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 15813b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> placementArgs, 15822aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange typeIdParens, Expr *arraySize, 15832aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle initializationStyle, Expr *initializer, 15846ec278d1a354517e20f13a877481453ee7940c78John McCall QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1585530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceRange Range, SourceRange directInitRange); 15865921863d8f24084797863b5df37842113bac4352Chris Lattner explicit CXXNewExpr(EmptyShell Shell) 15875921863d8f24084797863b5df37842113bac4352Chris Lattner : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 15885921863d8f24084797863b5df37842113bac4352Chris Lattner 15895921863d8f24084797863b5df37842113bac4352Chris Lattner void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 15902aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer); 1591ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1592cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl QualType getAllocatedType() const { 1593cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl assert(getType()->isPointerType()); 15946217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<PointerType>()->getPointeeType(); 1595cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 15964c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15971bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *getAllocatedTypeSourceInfo() const { 15981bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor return AllocatedTypeInfo; 15991bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor } 1600c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 1601c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// \brief True if the allocation result needs to be null-checked. 1602c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// C++0x [expr.new]p13: 1603c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// If the allocation function returns null, initialization shall 1604c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// not be done, the deallocation function shall not be called, 1605c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// and the value of the new-expression shall be null. 1606c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// An allocation function is not allowed to return null unless it 1607c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// has a non-throwing exception-specification. The '03 rule is 1608c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// identical except that the definition of a non-throwing 1609c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// exception specification is just "is it throw()?". 16108026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1611ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorNew() const { return OperatorNew; } 16135921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 16144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 16155921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 16164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1617cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool isArray() const { return Array; } 1618cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl Expr *getArraySize() { 1619cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1620cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1621cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl const Expr *getArraySize() const { 1622cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1623cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1624cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl 16254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1626ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr **getPlacementArgs() { 16272aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1628aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getPlacementArg(unsigned i) { 16314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 16322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return getPlacementArgs()[i]; 16334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getPlacementArg(unsigned i) const { 16354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 16362aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 16374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16394bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor bool isParenTypeId() const { return TypeIdParens.isValid(); } 16404bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange getTypeIdParens() const { return TypeIdParens; } 16414bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor 16424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalNew() const { return GlobalNew; } 16437cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 16442aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief Whether this new-expression has any initializer at all. 16452aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool hasInitializer() const { return StoredInitializationStyle > 0; } 16461548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 16472aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The kind of initializer this new-expression has. 16482aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl InitializationStyle getInitializationStyle() const { 16492aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (StoredInitializationStyle == 0) 16502aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return NoInit; 16512aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return static_cast<InitializationStyle>(StoredInitializationStyle-1); 16521548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 16531548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 16542aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// \brief The initializer of this new-expression. 16552aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *getInitializer() { 16562aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 16571548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 16582aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const Expr *getInitializer() const { 16592aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 16601548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 16611548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 1662feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay /// \brief Returns the CXXConstructExpr from this new-expression, or NULL. 166388920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky const CXXConstructExpr* getConstructExpr() const { 1664feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1665feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay } 1666feb1f4a0a71868a271fa284dadfda7a2beeaccffMatt Beaumont-Gay 16672aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// Answers whether the usual array deallocation function for the 16682aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// allocated type expects the size of the allocation as a 16692aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl /// parameter. 16702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl bool doesUsualArrayDeleteWantSize() const { 16712aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return UsualArrayDeleteWantsSize; 16722aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 16731548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 16744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ExprIterator arg_iterator; 16754c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ConstExprIterator const_arg_iterator; 16764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16774c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_begin() { 16782aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 16794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_end() { 16812aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_begin() const { 16842aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer(); 16854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16864c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_end() const { 16872aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 1689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16905921863d8f24084797863b5df37842113bac4352Chris Lattner typedef Stmt **raw_arg_iterator; 16915921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_begin() { return SubExprs; } 16925921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_end() { 16932aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16945921863d8f24084797863b5df37842113bac4352Chris Lattner } 16955921863d8f24084797863b5df37842113bac4352Chris Lattner const_arg_iterator raw_arg_begin() const { return SubExprs; } 16962aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl const_arg_iterator raw_arg_end() const { 16972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 16982aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl } 16994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1700530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceLocation getStartLoc() const { return Range.getBegin(); } 1701530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie SourceLocation getEndLoc() const { return Range.getEnd(); } 1702428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 17032aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange getDirectInitRange() const { return DirectInitRange; } 1704428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 1705aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1706530564196fe7e2e30fbc2b0edae45975447583e0David Blaikie return Range; 17074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 170865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); } 170965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 17104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 17124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXNewExprClass; 17134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 17144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 171663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 17172aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return child_range(raw_arg_begin(), raw_arg_end()); 171863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 17204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17210982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a \c delete expression for memory deallocation and 17220982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// destructor calls, e.g. "delete[] pArray". 17234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr { 1724d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Points to the operator delete overload that is used. Could be a member. 1725d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer FunctionDecl *OperatorDelete; 1726d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // The pointer expression to be deleted. 1727d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer Stmt *Argument; 1728d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer // Location of the expression. 1729d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer SourceLocation Loc; 17304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this a forced global delete, i.e. "::delete"? 17314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalDelete : 1; 17324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this the array form of delete, i.e. "delete[]"? 17334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool ArrayForm : 1; 17344076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 17354076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 17364076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // will be true). 17374076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool ArrayFormAsWritten : 1; 17386ec278d1a354517e20f13a877481453ee7940c78John McCall // Does the usual deallocation function for the element type require 17396ec278d1a354517e20f13a877481453ee7940c78John McCall // a size_t argument? 17406ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 17414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 17424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 17436ec278d1a354517e20f13a877481453ee7940c78John McCall bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 17446ec278d1a354517e20f13a877481453ee7940c78John McCall FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1745bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1746561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor arg->isInstantiationDependent(), 1747bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor arg->containsUnexpandedParameterPack()), 1748d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1749f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall GlobalDelete(globalDelete), 17504076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1751d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 175295fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis explicit CXXDeleteExpr(EmptyShell Shell) 175395fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 17544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalDelete() const { return GlobalDelete; } 17564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isArrayForm() const { return ArrayForm; } 17574076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 17584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17596ec278d1a354517e20f13a877481453ee7940c78John McCall /// Answers whether the usual array deallocation function for the 17606ec278d1a354517e20f13a877481453ee7940c78John McCall /// allocated type expects the size of the allocation as a 17616ec278d1a354517e20f13a877481453ee7940c78John McCall /// parameter. This can be true even if the actual deallocation 17626ec278d1a354517e20f13a877481453ee7940c78John McCall /// function that we're using doesn't want a size. 17636ec278d1a354517e20f13a877481453ee7940c78John McCall bool doesUsualArrayDeleteWantSize() const { 17646ec278d1a354517e20f13a877481453ee7940c78John McCall return UsualArrayDeleteWantsSize; 17656ec278d1a354517e20f13a877481453ee7940c78John McCall } 17666ec278d1a354517e20f13a877481453ee7940c78John McCall 17674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 17684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getArgument() { return cast<Expr>(Argument); } 17704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getArgument() const { return cast<Expr>(Argument); } 17714c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1772a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// \brief Retrieve the type being destroyed. If the type being 1773a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// destroyed is a dependent type which may or may not be a pointer, 1774a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// return an invalid type. 17755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType getDestroyedType() const; 1776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 177765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 177865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();} 17794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 17814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXDeleteExprClass; 17824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 17834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 178563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Argument, &Argument+1); } 1786f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis 1787f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis friend class ASTStmtReader; 17884c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 17894c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 17900982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1791a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage { 1792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Either the type source information or the name of the type, if 1793a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// it couldn't be resolved due to type-dependence. 1794a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1795ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1796a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief The starting source location of the pseudo-destructor type. 1797a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation Location; 1798ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1799a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic: 1800a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage() { } 1801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1802a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1803a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor : Type(II), Location(Loc) { } 1804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1805a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1807ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getTypeSourceInfo() const { 1808ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return Type.dyn_cast<TypeSourceInfo *>(); 1809a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1810ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1811a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getIdentifier() const { 1812a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return Type.dyn_cast<IdentifierInfo *>(); 1813a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1815a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation getLocation() const { return Location; } 1816a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor}; 1817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1818a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1819a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1820e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a 1821ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have 1822e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example: 1823e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// 1824e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code 1825e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T; 1826e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) { 1827e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// p->T::~T(); 1828e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// } 1829e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode 1830a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1831e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as: 1832ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// 1833a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code 18341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T> 1835a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) { 1836e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// ptr->T::~T(); 1837a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// } 1838a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode 1839a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1840e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics 1841e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression. 1842a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr { 1843a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The base expression (that is being destroyed). 1844a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Stmt *Base; 18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1846a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1847a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// period ('.'). 1848a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool IsArrow : 1; 18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1850a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The location of the '.' or '->' operator. 1851a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation OperatorLoc; 1852ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1853a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The nested-name-specifier that follows the operator, if present. 1854f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 18551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1856e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1857e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1858e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType; 1859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1860ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The location of the '::' in a qualified pseudo-destructor 1861e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1862e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc; 1863ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1864fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief The location of the '~'. 1865fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc; 1866ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1867ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The type being destroyed, or its name if we were unable to 1868a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// resolve the name. 1869a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage DestroyedType; 18701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1871f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor friend class ASTStmtReader; 1872ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1873a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic: 1874a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor CXXPseudoDestructorExpr(ASTContext &Context, 1875a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1876f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1877e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType, 1878e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc, 1879fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 1880e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall PseudoDestructorTypeStorage DestroyedType); 18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1882de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1883de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis : Expr(CXXPseudoDestructorExprClass, Shell), 1884f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1885de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1886a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *getBase() const { return cast<Expr>(Base); } 18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 1889a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 1890a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// x->Base::foo. 1891f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool hasQualifier() const { return QualifierLoc; } 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1893f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1894f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// with source-location information. 1895f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1896ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 1898a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 1899a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// NULL. 1900ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 1901ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 1902f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor } 19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1904a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Determine whether this pseudo-destructor expression was written 1905a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// using an '->' (otherwise, it used a '.'). 1906a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool isArrow() const { return IsArrow; } 1907a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor 1908a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Retrieve the location of the '.' or '->' operator. 1909a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 19101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1911ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the scope type in a qualified pseudo-destructor 1912e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1913e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// 1914e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Pseudo-destructor expressions can have extra qualification within them 1915e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1916e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Here, if the object type of the expression is (or may be) a scalar type, 1917ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \p T may also be a scalar type and, therefore, cannot be part of a 1918e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1919e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// destructor expression. 192026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1921ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1922e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1923e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1924e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1925ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1926fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief Retrieve the location of the '~'. 1927fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation getTildeLoc() const { return TildeLoc; } 1928ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 192926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// \brief Retrieve the source location information for the type 193026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// being destroyed. 1931a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// 1932ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This type-source information is available for non-dependent 1933a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// pseudo-destructor expressions and some dependent pseudo-destructor 1934a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// expressions. Returns NULL if we only have the identifier for a 1935a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// dependent pseudo-destructor expression. 1936ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getDestroyedTypeInfo() const { 1937ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getTypeSourceInfo(); 1938a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1939ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1940a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief In a dependent pseudo-destructor expression for which we do not 1941a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// have full type information on the destroyed type, provides the name 1942a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// of the destroyed type. 1943a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getDestroyedTypeIdentifier() const { 1944a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return DestroyedType.getIdentifier(); 1945a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1946ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1947a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the type being destroyed. 1948a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor QualType getDestroyedType() const; 1949ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1950a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the starting location of the type being destroyed. 1951ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation getDestroyedTypeLoc() const { 1952ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getLocation(); 1953a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 19541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1955de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1956de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// expression. 1957de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1958de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1959de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1960de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1961de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the destroyed type. 1962de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(TypeSourceInfo *Info) { 1963de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(Info); 1964de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1965de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 196665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();} 196765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY; 19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1970a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor return T->getStmtClass() == CXXPseudoDestructorExprClass; 1971a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1973a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor // Iterators 197463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base + 1); } 1975a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}; 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19770982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS unary type trait, as used in the 19780982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates. 19790982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 198064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example: 19810982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 19820982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_pod(int) == true 19830982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_enum(std::string) == false 19840982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 198564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr { 19860dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 19870dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl unsigned UTT : 31; 19880dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The value of the type trait. Unspecified if dependent. 19890dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool Value : 1; 199064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 199164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// Loc - The location of the type trait keyword. 199264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation Loc; 199364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 199464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// RParen - The location of the closing paren. 199564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation RParen; 199664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 19970dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The type being queried. 19983d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *QueriedType; 199964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 200064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic: 2001ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 20020dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl TypeSourceInfo *queried, bool value, 200364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation rparen, QualType ty) 2004f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2005bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, queried->getType()->isDependentType(), 2006561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->getType()->isInstantiationDependentType(), 2007bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor queried->getType()->containsUnexpandedParameterPack()), 20080dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 200964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 20106d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit UnaryTypeTraitExpr(EmptyShell Empty) 20110dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 20123d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QueriedType() { } 20136d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 201465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 201565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 201664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 20170dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 201864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 20193d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QualType getQueriedType() const { return QueriedType->getType(); } 202064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 20213d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2022ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20230dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool getValue() const { return Value; } 202464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 202564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const Stmt *T) { 202664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return T->getStmtClass() == UnaryTypeTraitExprClass; 202764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 202864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 202964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Iterators 203063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 20316d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 203260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 203364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl}; 203464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 20350982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief Represents a GCC or MS binary type trait, as used in the 20360982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// implementation of TR1/C++11 type trait templates. 20370982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 20386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example: 20390982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 20400982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_base_of(Base, Derived) == true 20410982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 20426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr { 20436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 20446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet unsigned BTT : 8; 20456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The value of the type trait. Unspecified if dependent. 20476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool Value : 1; 20486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Loc - The location of the type trait keyword. 20506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation Loc; 20516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// RParen - The location of the closing paren. 20536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParen; 20546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The lhs type being queried. 20566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsType; 20576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The rhs type being queried. 20596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsType; 20606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic: 2062ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 2063ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 20646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool value, SourceLocation rparen, QualType ty) 2065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 20666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet lhsType->getType()->isDependentType() || 2067bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->isDependentType(), 2068561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhsType->getType()->isInstantiationDependentType() || 2069561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhsType->getType()->isInstantiationDependentType()), 2070bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhsType->getType()->containsUnexpandedParameterPack() || 2071bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->containsUnexpandedParameterPack())), 20726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BTT(btt), Value(value), Loc(loc), RParen(rparen), 20736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsType(lhsType), RhsType(rhsType) { } 20746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet explicit BinaryTypeTraitExpr(EmptyShell Empty) 20776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 2078f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet LhsType(), RhsType() { } 20796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 208065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 208165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 20826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BinaryTypeTrait getTrait() const { 20846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return static_cast<BinaryTypeTrait>(BTT); 20856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getLhsType() const { return LhsType->getType(); } 20886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getRhsType() const { return RhsType->getType(); } 20896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 20916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2092ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool getValue() const { assert(!isTypeDependent()); return Value; } 20946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const Stmt *T) { 20966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return T->getStmtClass() == BinaryTypeTraitExprClass; 20976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet // Iterators 210063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 21016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 21026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet friend class ASTStmtReader; 21036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}; 21046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 21054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \brief A type trait used in the implementation of various C++11 and 21064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// Library TR1 trait templates. 21074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// 21084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \code 21094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// __is_trivially_constructible(vector<int>, int*, int*) 21104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor/// \endcode 21114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorclass TypeTraitExpr : public Expr { 21124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The location of the type trait keyword. 21134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation Loc; 21144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief The location of the closing parenthesis. 21164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc; 21174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Note: The TypeSourceInfos for the arguments are allocated after the 21194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // TypeTraitExpr. 21204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 21224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 21234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc, 21244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Value); 21254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 21274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 21294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo **getTypeSourceInfos() { 21304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return reinterpret_cast<TypeSourceInfo **>(this+1); 21314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 21344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo * const *getTypeSourceInfos() const { 21354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return reinterpret_cast<TypeSourceInfo * const*>(this+1); 21364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregorpublic: 21394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Create a new type trait expression. 21404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc, 21414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTrait Kind, 21424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 21434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc, 21444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Value); 21454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs); 21474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Determine which type trait this expression uses. 21494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeTrait getTrait() const { 21504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 21514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool getValue() const { 21544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor assert(!isValueDependent()); 21554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return TypeTraitExprBits.Value; 21564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Determine the number of arguments to this type trait. 21594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 21604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the Ith argument. 21624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo *getArg(unsigned I) const { 21634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor assert(I < getNumArgs() && "Argument out-of-range"); 21644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getArgs()[I]; 21654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Retrieve the argument types. 21684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> getArgs() const { 21694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 21704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor typedef TypeSourceInfo **arg_iterator; 21734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_iterator arg_begin() { 21744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos(); 21754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_iterator arg_end() { 21774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos() + getNumArgs(); 21784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor typedef TypeSourceInfo const * const *arg_const_iterator; 21814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 21824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor arg_const_iterator arg_end() const { 21834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getTypeSourceInfos() + getNumArgs(); 21844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 218665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 218765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 218865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 21894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor static bool classof(const Stmt *T) { 21904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return T->getStmtClass() == TypeTraitExprClass; 21914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 21924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Iterators 21944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor child_range children() { return child_range(); } 21954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtReader; 21974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor friend class ASTStmtWriter; 21984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 21994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor}; 22004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 22010982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An Embarcadero array type trait, as used in the implementation of 22020982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank and __array_extent. 22030982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 220421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example: 22050982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 22060982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_rank(int[10][20]) == 2 22070982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __array_extent(int, 1) == 20 22080982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 220921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr { 221099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 221199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 22120982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 221321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley unsigned ATT : 2; 221421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22150982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The value of the type trait. Unspecified if dependent. 221621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t Value; 221721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22180982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The array dimension being queried, or -1 if not used. 221921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *Dimension; 222021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22210982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the type trait keyword. 222221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation Loc; 222321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22240982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the closing paren. 222521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParen; 222621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22270982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The type being queried. 222821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *QueriedType; 222921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 223021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic: 223121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 223221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *queried, uint64_t value, 223321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *dimension, SourceLocation rparen, QualType ty) 223421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 223521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley false, queried->getType()->isDependentType(), 2236561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (queried->getType()->isInstantiationDependentType() || 2237561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (dimension && dimension->isInstantiationDependent())), 223821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley queried->getType()->containsUnexpandedParameterPack()), 223921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ATT(att), Value(value), Dimension(dimension), 224021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Loc(loc), RParen(rparen), QueriedType(queried) { } 224121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 224221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 224321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley explicit ArrayTypeTraitExpr(EmptyShell Empty) 224421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 224521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QueriedType() { } 224621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 224725aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek virtual ~ArrayTypeTraitExpr() { } 224825aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek 224965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 225065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 225121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 225221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 225321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 225421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QualType getQueriedType() const { return QueriedType->getType(); } 225521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 225621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 225721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 225821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 225921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 226021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *getDimensionExpression() const { return Dimension; } 226121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 226221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const Stmt *T) { 226321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return T->getStmtClass() == ArrayTypeTraitExprClass; 226421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 226521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 226621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Iterators 226721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley child_range children() { return child_range(); } 226821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 226921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley friend class ASTStmtReader; 227021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}; 227121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 22720982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// \brief An expression trait intrinsic. 22730982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 2274552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example: 22750982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @code 22760982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_lvalue_expr(std::cout) == true 22770982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// __is_lvalue_expr(1) == false 22780982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// @endcode 2279552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr { 22800982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned. 2281552622067dc45013d240f73952fece703f5e63bdJohn Wiegley unsigned ET : 31; 22820982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The value of the type trait. Unspecified if dependent. 2283552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool Value : 1; 2284552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22850982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the type trait keyword. 2286552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation Loc; 2287552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22880982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The location of the closing paren. 2289552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParen; 2290552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 22910982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The expression being queried. 2292552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr* QueriedExpression; 2293552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic: 2294ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2295552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *queried, bool value, 2296552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation rparen, QualType resultType) 2297552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2298552622067dc45013d240f73952fece703f5e63bdJohn Wiegley false, // Not type-dependent 2299552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Value-dependent if the argument is type-dependent. 2300552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->isTypeDependent(), 2301561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->isInstantiationDependent(), 2302552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->containsUnexpandedParameterPack()), 2303ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ET(et), Value(value), Loc(loc), RParen(rparen), 2304ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QueriedExpression(queried) { } 2305552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2306552622067dc45013d240f73952fece703f5e63bdJohn Wiegley explicit ExpressionTraitExpr(EmptyShell Empty) 2307552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2308552622067dc45013d240f73952fece703f5e63bdJohn Wiegley QueriedExpression() { } 2309552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 231065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 231165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2312552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2313552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2314552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2315552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *getQueriedExpression() const { return QueriedExpression; } 2316552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2317552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool getValue() const { return Value; } 2318552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2319552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const Stmt *T) { 2320552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return T->getStmtClass() == ExpressionTraitExprClass; 2321552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2322552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2323552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Iterators 2324552622067dc45013d240f73952fece703f5e63bdJohn Wiegley child_range children() { return child_range(); } 2325552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2326552622067dc45013d240f73952fece703f5e63bdJohn Wiegley friend class ASTStmtReader; 2327552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}; 2328552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2329552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 23307bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an 2331809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 23327bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr { 23330982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief The common name of these declarations. 2334d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer DeclarationNameInfo NameInfo; 2335d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 2336d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer /// \brief The nested-name-specifier that qualifies the name, if any. 2337d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer NestedNameSpecifierLoc QualifierLoc; 2338d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer 2339ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// The results. These are undesugared, which is to say, they may 23407bb12da2b0749eeebb21854c77877736969e59f2John McCall /// include UsingShadowDecls. Access is relative to the naming 23417bb12da2b0749eeebb21854c77877736969e59f2John McCall /// class. 2342928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor // FIXME: Allocate this data after the OverloadExpr subclass. 2343928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor DeclAccessPair *Results; 2344928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned NumResults; 2345ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2346a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected: 2347e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2348e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2349e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2350e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2353e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2354e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2355e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2356e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2357e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 23587bb12da2b0749eeebb21854c77877736969e59f2John McCall 2359bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor OverloadExpr(StmtClass K, ASTContext &C, 23604c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2361e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2363bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2364bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2365561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownDependent, 2366561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownInstantiationDependent, 2367561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownContainsUnexpandedParameterPack); 23687bb12da2b0749eeebb21854c77877736969e59f2John McCall 2369a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis OverloadExpr(StmtClass K, EmptyShell Empty) 2370d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2371d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer HasTemplateKWAndArgsInfo(false) { } 2372a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 2373bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeResults(ASTContext &C, 2374bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, 2375bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator End); 23767bb12da2b0749eeebb21854c77877736969e59f2John McCall 2377bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic: 23789c72c6088d591ace8503b842d39448c2040f3033John McCall struct FindResult { 23799c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Expression; 23809c72c6088d591ace8503b842d39448c2040f3033John McCall bool IsAddressOfOperand; 23819c72c6088d591ace8503b842d39448c2040f3033John McCall bool HasFormOfMemberPointer; 23829c72c6088d591ace8503b842d39448c2040f3033John McCall }; 23839c72c6088d591ace8503b842d39448c2040f3033John McCall 23847bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Finds the overloaded expression in the given expression of 23857bb12da2b0749eeebb21854c77877736969e59f2John McCall /// OverloadTy. 23867bb12da2b0749eeebb21854c77877736969e59f2John McCall /// 23879c72c6088d591ace8503b842d39448c2040f3033John McCall /// \return the expression (which must be there) and true if it has 23889c72c6088d591ace8503b842d39448c2040f3033John McCall /// the particular form of a member pointer expression 23899c72c6088d591ace8503b842d39448c2040f3033John McCall static FindResult find(Expr *E) { 23907bb12da2b0749eeebb21854c77877736969e59f2John McCall assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 23917bb12da2b0749eeebb21854c77877736969e59f2John McCall 23929c72c6088d591ace8503b842d39448c2040f3033John McCall FindResult Result; 23939c72c6088d591ace8503b842d39448c2040f3033John McCall 23947bb12da2b0749eeebb21854c77877736969e59f2John McCall E = E->IgnoreParens(); 23959c72c6088d591ace8503b842d39448c2040f3033John McCall if (isa<UnaryOperator>(E)) { 23969c72c6088d591ace8503b842d39448c2040f3033John McCall assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 23979c72c6088d591ace8503b842d39448c2040f3033John McCall E = cast<UnaryOperator>(E)->getSubExpr(); 23989c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 23999c72c6088d591ace8503b842d39448c2040f3033John McCall 24009c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 24019c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = true; 24029c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = Ovl; 24039c72c6088d591ace8503b842d39448c2040f3033John McCall } else { 24049c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = false; 24059c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = false; 24069c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = cast<OverloadExpr>(E); 24079c72c6088d591ace8503b842d39448c2040f3033John McCall } 24089c72c6088d591ace8503b842d39448c2040f3033John McCall 24099c72c6088d591ace8503b842d39448c2040f3033John McCall return Result; 24107bb12da2b0749eeebb21854c77877736969e59f2John McCall } 24117bb12da2b0749eeebb21854c77877736969e59f2John McCall 24120982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the naming class of this lookup, if any. 2413e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall CXXRecordDecl *getNamingClass() const; 2414e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall 24157bb12da2b0749eeebb21854c77877736969e59f2John McCall typedef UnresolvedSetImpl::iterator decls_iterator; 2416928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2417ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie decls_iterator decls_end() const { 2418928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor return UnresolvedSetIterator(Results + NumResults); 2419928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor } 2420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 24210982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the number of declarations in the unresolved set. 2422928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned getNumDecls() const { return NumResults; } 24237bb12da2b0749eeebb21854c77877736969e59f2John McCall 24240982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the full name info. 24252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 24262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 24270982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the name looked up. 24282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return NameInfo.getName(); } 24297bb12da2b0749eeebb21854c77877736969e59f2John McCall 24300982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Gets the location of the name. 24312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 24327bb12da2b0749eeebb21854c77877736969e59f2John McCall 24330982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Fetches the nested-name qualifier, if one was given. 2434ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 24364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor } 24377bb12da2b0749eeebb21854c77877736969e59f2John McCall 24380982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Fetches the nested-name qualifier with source-location 24390982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// information, if one was given. 24404c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 24417bb12da2b0749eeebb21854c77877736969e59f2John McCall 2442e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2443e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2444e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2445e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2446e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2447e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2448e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2450e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2451e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2452e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2453e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2454e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2455e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2456e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2457e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2458e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2459e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2460e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2461e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 24627bb12da2b0749eeebb21854c77877736969e59f2John McCall 24630982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Determines whether the name was preceded by the template keyword. 2464e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2465e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 24660982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Determines whether this expression had explicit template arguments. 2467e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2468e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2469e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // Note that, inconsistently with the explicit-template-argument AST 2470e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // nodes, users are *forbidden* from calling these methods on objects 2471e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // without explicit template arguments. 2472e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2473e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2474e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2475e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2476e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 24777bb12da2b0749eeebb21854c77877736969e59f2John McCall 2478b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 24797bb12da2b0749eeebb21854c77877736969e59f2John McCall return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 24807bb12da2b0749eeebb21854c77877736969e59f2John McCall } 24817bb12da2b0749eeebb21854c77877736969e59f2John McCall 2482e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgumentLoc const *getTemplateArgs() const { 2483e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().getTemplateArgs(); 2484e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2485e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2486e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned getNumTemplateArgs() const { 2487e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().NumTemplateArgs; 2488e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2489e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 24900982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// \brief Copies the template arguments into the given structure. 2491e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2492e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getExplicitTemplateArgs().copyInto(List); 2493e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2494e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2495096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 24960982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// 2497096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2498096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 24997d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2500096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2501096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 25027bb12da2b0749eeebb21854c77877736969e59f2John McCall } 25037bb12da2b0749eeebb21854c77877736969e59f2John McCall 25047bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const Stmt *T) { 25057bb12da2b0749eeebb21854c77877736969e59f2John McCall return T->getStmtClass() == UnresolvedLookupExprClass || 25067bb12da2b0749eeebb21854c77877736969e59f2John McCall T->getStmtClass() == UnresolvedMemberExprClass; 25077bb12da2b0749eeebb21854c77877736969e59f2John McCall } 25084045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 25094045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 25104045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 25117bb12da2b0749eeebb21854c77877736969e59f2John McCall}; 25127bb12da2b0749eeebb21854c77877736969e59f2John McCall 25137bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during 25140982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// parsing but could not resolve to a specific declaration. 25150982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// 25160982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// This arises in several ways: 25177bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * we might be waiting for argument-dependent lookup 25187bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the name might resolve to an overloaded function 25197bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually: 25207bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the lookup might have included a function template 25210982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// These never include UnresolvedUsingValueDecls, which are always class 25220982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// members and therefore appear only in UnresolvedMemberLookupExprs. 25237bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr { 2524ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if these lookup results should be extended by 2525ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup if this is the operand of a function 2526ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// call. 2527ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool RequiresADL; 2528ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 25297453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if these lookup results are overloaded. This is pretty 25307453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// trivially rederivable if we urgently need to kill this field. 25317453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool Overloaded; 25327453ed4cb2cab113de3378df371b1c6f1243d832John McCall 25337bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The naming class (C++ [class.access.base]p5) of the lookup, if 25347bb12da2b0749eeebb21854c77877736969e59f2John McCall /// any. This can generally be recalculated from the context chain, 25357bb12da2b0749eeebb21854c77877736969e59f2John McCall /// but that can be fairly expensive for unqualified lookups. If we 25367bb12da2b0749eeebb21854c77877736969e59f2John McCall /// want to improve memory use here, this could go in a union 25377bb12da2b0749eeebb21854c77877736969e59f2John McCall /// against the qualified-lookup bits. 25387bb12da2b0749eeebb21854c77877736969e59f2John McCall CXXRecordDecl *NamingClass; 2539f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2540ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedLookupExpr(ASTContext &C, 2541928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor CXXRecordDecl *NamingClass, 25424c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2543e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 25442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2545ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool RequiresADL, bool Overloaded, 2546bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2547b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2548e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2549e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara NameInfo, TemplateArgs, Begin, End, false, false, false), 2550ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(RequiresADL), 2551ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Overloaded(Overloaded), NamingClass(NamingClass) 2552ba13543329afac4a0d01304ec2ec4924d99306a6John McCall {} 2553ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2554bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis UnresolvedLookupExpr(EmptyShell Empty) 2555bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis : OverloadExpr(UnresolvedLookupExprClass, Empty), 2556b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith RequiresADL(false), Overloaded(false), NamingClass(0) 2557bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis {} 2558bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 25594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 2560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2561ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic: 2562ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2563c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 25644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 25652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 25665a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor bool ADL, bool Overloaded, 2567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 2568b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith UnresolvedSetIterator End) { 2569e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2570e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation(), NameInfo, 2571b1502bcd67fb593a95cbf73ec3814f4015666da0Richard Smith ADL, Overloaded, 0, Begin, End); 2572ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2573ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2574f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2575c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 25764c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2577e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 25782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2579f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool ADL, 25809d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *Args, 2581ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 25825a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator End); 2583f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2584bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2585e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 2586bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis unsigned NumTemplateArgs); 2587bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 2588ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if this declaration should be extended by 2589ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup. 2590ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool requiresADL() const { return RequiresADL; } 2591ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 25927453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if this lookup is overloaded. 25937453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool isOverloaded() const { return Overloaded; } 25947453ed4cb2cab113de3378df371b1c6f1243d832John McCall 2595c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// Gets the 'naming class' (in the sense of C++0x 2596c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// [class.access.base]p5) of the lookup. This is the scope 2597c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// that was looked in to find these results. 2598c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const { return NamingClass; } 2599c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 260065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 260165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (NestedNameSpecifierLoc l = getQualifierLoc()) 260265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return l.getBeginLoc(); 260365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getNameInfo().getLocStart(); 260465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 260565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 2606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (hasExplicitTemplateArgs()) 260765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRAngleLoc(); 260865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getNameInfo().getLocEnd(); 2609ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2610ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 261163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 2612ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2613ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const Stmt *T) { 2614ba13543329afac4a0d01304ec2ec4924d99306a6John McCall return T->getStmtClass() == UnresolvedLookupExprClass; 2615ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2616ba13543329afac4a0d01304ec2ec4924d99306a6John McCall}; 2617ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 26185953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot 26195953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved. 26205953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// 2621ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2622a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as 26235953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an 2624865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when 26255953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In 26265953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the 26275953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the 2628865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2629ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced 2630a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2631a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found. 2632865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr { 2633ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested-name-specifier that qualifies this unresolved 2634ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration name. 263500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 2636ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 263700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// The name of the entity we will be referencing. 263800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor DeclarationNameInfo NameInfo; 26395953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 2640e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2641e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2642e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2643e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2644e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2645e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2646e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2647e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2648e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2649e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2650e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2651e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DependentScopeDeclRefExpr*>(this) 2652e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2653e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 26541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2655f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall DependentScopeDeclRefExpr(QualType T, 265600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2657e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 26582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2659bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *Args); 2660f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2661f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic: 2662f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static DependentScopeDeclRefExpr *Create(ASTContext &C, 266300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2664e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 26652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2666e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs); 26675953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 266812dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2669e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 267012dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis unsigned NumTemplateArgs); 267112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 26725953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the name that this expression refers to. 26732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 26742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 26752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name that this expression refers to. 26762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getDeclName() const { return NameInfo.getName(); } 26775953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 26785953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the location of the name within the expression. 26792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLocation() const { return NameInfo.getLoc(); } 26805953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 268100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the 268200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// name, with source location information. 268300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2684ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2686ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies this 2687ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration. 2688ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2689ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 269000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor } 26911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2692e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2693e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2694e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2695e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2696e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2697e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2698e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2699e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2700e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2701e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2702e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2703e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2704e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2705e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2706e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2707e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2708e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2709e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2710e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2711e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2712e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2713e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2714e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2715e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2716f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Determines whether this lookup had explicit template arguments. 2717e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 27181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2719f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Note that, inconsistently with the explicit-template-argument AST 2720f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // nodes, users are *forbidden* from calling these methods on objects 2721f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // without explicit template arguments. 27221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2723b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 272412dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis assert(hasExplicitTemplateArgs()); 2725b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 272612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis } 272712dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 2728f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Gets a reference to the explicit template argument list. 2729b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2730f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall assert(hasExplicitTemplateArgs()); 2731b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2732f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 27331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2734096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2735096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2736096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 27377d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2738096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2739096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2740096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2741096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2742f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Copies the template arguments (if present) into the given 2743f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// structure. 2744f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2745f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall getExplicitTemplateArgs().copyInto(List); 2746f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 2747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2748f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentLoc const *getTemplateArgs() const { 2749f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2750d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2751d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2752f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall unsigned getNumTemplateArgs() const { 2753f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2754f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 275665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 275765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return QualifierLoc.getBeginLoc(); 275865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 275965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 2760f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (hasExplicitTemplateArgs()) 276165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRAngleLoc(); 276265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getLocation(); 2763edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 27641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2766f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return T->getStmtClass() == DependentScopeDeclRefExprClass; 2767edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 2768f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 276963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 27704045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 27714045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 27724045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 2773edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor}; 27741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27754765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which 27764765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's 27774765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation. The most common source of expression-introduced 277880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of 277980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every 278080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer. 278180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// 278280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a 278380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal. The lifetime of a block 278480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope. 27854765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr { 278680ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic: 278780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// The type of objects that are kept in the cleanup. 278880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// It's useful to remember the set of blocks; we could also 278980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// remember the set of temporaries, but there's currently 279080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// no need. 279180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall typedef BlockDecl *CleanupObject; 279280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 279380ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate: 279402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Stmt *SubExpr; 27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 279680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(EmptyShell, unsigned NumObjects); 279780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 279802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 279980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject *getObjectsBuffer() { 280080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<CleanupObject*>(this + 1); 280180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 280280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall const CleanupObject *getObjectsBuffer() const { 280380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<const CleanupObject*>(this + 1); 280480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 280580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; 2806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 280788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic: 280880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 280980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned numObjects); 28101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 281180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 281280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> objects); 2813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 281480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> getObjects() const { 281580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2816f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson } 281780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 281880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 281980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 282080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject getObject(unsigned i) const { 282180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall assert(i < getNumObjects() && "Index out of range"); 282280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return getObjects()[i]; 2823d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner } 28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 282502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2826f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 282780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 282880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// setSubExpr - As with any mutator of the AST, be very careful 282980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// when modifying an existing AST to preserve its invariants. 283088eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 283102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 283265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 283365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SubExpr->getLocStart(); 283496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 283565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 283602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 283702bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Implement isa/cast/dyncast/etc. 283802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson static bool classof(const Stmt *T) { 28394765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return T->getStmtClass() == ExprWithCleanupsClass; 284002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson } 284102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 284202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Iterators 284363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 284402bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson}; 284502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2846d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional 2847d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are 2848d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. 2849d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2850d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by 2851fe865f1f35d1b91f42f58f08a1399b961b71b3bcJames Dennett/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 28520982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 28530982205bade2fb4fc984c27b2ab401e683963b10James Dennett/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2854d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such 2855d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as: 2856d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2857d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code 2858d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// template<typename T, typename A1> 2859d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// inline T make_a(const A1& a1) { 2860d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// return T(a1); 2861d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// } 2862d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode 2863d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2864d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a 2865d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type 2866d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion. 2867d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr { 2868d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The type being constructed. 2869ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 2870ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2871d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the left parentheses ('('). 2872d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc; 2873d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2874d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the right parentheses (')'). 2875d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc; 2876d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2877d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The number of arguments used to construct the type. 2878d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs; 28791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2880ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2881d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 28823b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> Args, 2883d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2884d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 28858dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2886ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 28878dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2888ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 2889ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2890d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic: 28911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2892ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 2893d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 28943b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> Args, 2895d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2896d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 28978dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 28988dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis unsigned NumArgs); 28998dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2900d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the type that is being constructed, as specified 2901d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// in the source code. 2902ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor QualType getTypeAsWritten() const { return Type->getType(); } 2903d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2904ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the type source information for the type being 2905ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// constructed. 2906ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2907ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2908d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the left parentheses ('(') that 2909d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// precedes the argument list. 2910d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 2911d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2912d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2913d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the right parentheses (')') that 2914d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// follows the argument list. 2915d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2916d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2917d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2918d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the number of arguments. 2919d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned arg_size() const { return NumArgs; } 2920d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2921d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor typedef Expr** arg_iterator; 2922d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2923d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_end() { return arg_begin() + NumArgs; } 2924d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 29251dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall typedef const Expr* const * const_arg_iterator; 29261dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_begin() const { 29271dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return reinterpret_cast<const Expr* const *>(this + 1); 29281dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 29291dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_end() const { 29301dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return arg_begin() + NumArgs; 29311dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 29321dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 2933d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr *getArg(unsigned I) { 2934d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor assert(I < NumArgs && "Argument index out-of-range"); 2935d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return *(arg_begin() + I); 2936d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2937d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 29381dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const Expr *getArg(unsigned I) const { 29391dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall assert(I < NumArgs && "Argument index out-of-range"); 29401dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return *(arg_begin() + I); 29411dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 29421dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 29438dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void setArg(unsigned I, Expr *E) { 29448dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis assert(I < NumArgs && "Argument index out-of-range"); 29458dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis *(arg_begin() + I) = E; 29468dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 29478dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 294865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 294965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2950ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2952d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2953d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2954d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2955d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor // Iterators 295663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 295763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this+1); 295863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumArgs); 295963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2960d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor}; 2961d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2962ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual 2963ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base 2964ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent. 2965aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2966aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or 2967aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses. It is only possible to get one of these with 2968aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided. 2969865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr { 29701c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The expression for the base pointer or class reference, 2971aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// e.g., the \c x in x.f. Can be null in implicit accesses. 29721c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor Stmt *Base; 29731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief The type of the base expression. Never null, even for 2975aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// implicit accesses. 2976aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 2977aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 29781c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Whether this member expression used the '->' operator or 29791c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// the '.' operator. 29803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor bool IsArrow : 1; 29811c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2982e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether this member expression has info for explicit template 2983e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2984e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 29851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29861c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The location of the '->' or '.' operator. 29871c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation OperatorLoc; 29881c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2989a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief The nested-name-specifier that precedes the member name, if any. 29907c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 29911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2992c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief In a qualified member access expression such as t->Base::f, this 29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// member stores the resolves of name lookup in the context of the member 2994c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// access expression, to be used at instantiation time. 2995c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 299646bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor /// FIXME: This member, along with the QualifierLoc, could 2997c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// be stuck into a structure that is optionally allocated at the end of 2998865d447ac6a4721ab58e898d014a21f2eff74b06John McCall /// the CXXDependentScopeMemberExpr, to save space in the common case. 2999c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierFoundInScope; 30001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The member to which this member expression refers, which 30021c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// can be name, overloaded operator, or destructor. 3003a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// FIXME: could also be a template-id 30042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo; 30051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3006e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 3007e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 3008e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 3009e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 3010e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3011e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 3012e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 3013e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<CXXDependentScopeMemberExpr*>(this) 3014e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 3015e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3016e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3017865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 3018aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 30193b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 30207c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3021e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 30223b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 30232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 3024d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 30251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30261c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic: 3027865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 3028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr *Base, QualType BaseType, 3029bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool IsArrow, 3030bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation OperatorLoc, 30317c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3032bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 3033bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor DeclarationNameInfo MemberNameInfo); 30341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3035865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static CXXDependentScopeMemberExpr * 30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Create(ASTContext &C, 3037aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 30383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 30397c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3040e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 30413b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 30422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 3043d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30458dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXDependentScopeMemberExpr * 3046e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3047def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 30488dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 3049aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 3050aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 3051aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 30524c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 3053aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 30541c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the base object of this member expressions, 30551c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// e.g., the \c x in \c x.m. 3056aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() const { 3057aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 3058aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 3059aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 30601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3061aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 3062aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 30631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Determine whether this member expression used the '->' 30641c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// operator; otherwise, it used the '.' operator. 30651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor bool isArrow() const { return IsArrow; } 30661c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 30671c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the location of the '->' or '.' operator. 30681c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 30691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3070a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 3071a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// name. 3072ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 3073ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 30747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 30751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30767c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 30777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// name, with source location information. 30787c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3079ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3080ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3081c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief Retrieve the first part of the nested-name-specifier that was 3082c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// found in the scope of the member access expression when the member access 3083c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// was initially parsed. 3084c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 3085c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// This function only returns a useful result when member access expression 30861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 30871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returned by this function describes what was found by unqualified name 3088c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// lookup for the identifier "Base" within the scope of the member access 3089c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself. At template instantiation time, this information is 3090c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// combined with the results of name lookup into the type of the object 3091c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself (the class type of x). 30921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamedDecl *getFirstQualifierFoundInScope() const { 3093c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor return FirstQualifierFoundInScope; 3094c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor } 30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30961c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the name of the member that this expression 30971c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// refers to. 30982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { 30992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return MemberNameInfo; 31002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 31012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 31022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name of the member that this expression 31032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 31042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getMember() const { return MemberNameInfo.getName(); } 31051c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 31061c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // \brief Retrieve the location of the name of the member that this 31071c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // expression refers to. 31082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 31091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3110e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding the 3111e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member name, if any. 3112e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 3113e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3114e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3115e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3116e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3117e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 3118e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 3119e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 3120e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3121e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 3122e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3123e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3124e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 3125e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 3126e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 3127e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3128e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 3129e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 3130e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 3131e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 3132e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3133e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 31343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 31353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 3136e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 31371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 313936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 3140b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3141e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 3142b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 314336c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 314436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 314536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 314636c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 3147b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 314836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis return const_cast<CXXDependentScopeMemberExpr *>(this) 3149096832c5ed5b9106fa177ebc148489760c3bc496John McCall ->getExplicitTemplateArgs(); 3150096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 3151096832c5ed5b9106fa177ebc148489760c3bc496John McCall 3152096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 3153096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 3154096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 31557d9f07732b85f1b2989c640065512a6af9a0f49aDmitri Gribenko const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 3156096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 3157096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 315836c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 315936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 3160d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 3161d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 3162d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3163096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 3164d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 3165d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 31668dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis /// \brief Initializes the template arguments using the given structure. 31678dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3168096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(List); 31698dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 31708dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 31713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 31723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 3173833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 3174096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 31753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31773b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 31783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 3180096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 31813b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 318365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 3184aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 318565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Base->getLocStart(); 318665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (getQualifier()) 318765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getQualifierLoc().getBeginLoc(); 318865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return MemberNameInfo.getBeginLoc(); 31891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 319165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 3192aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (hasExplicitTemplateArgs()) 319365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRAngleLoc(); 319465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return MemberNameInfo.getEndLoc(); 31951c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3198865d447ac6a4721ab58e898d014a21f2eff74b06John McCall return T->getStmtClass() == CXXDependentScopeMemberExprClass; 31991c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 32001c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 32011c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // Iterators 320263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 320363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 320463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 320563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 32064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 32074045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 32084045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 32091c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor}; 32101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 3211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup 3212aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions. 3213aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 3214aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit: 3215aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// struct A { 3216aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int a, b; 3217aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int explicitAccess() { return this->a + this->A::b; } 3218aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int implicitAccess() { return a + A::b; } 3219aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// }; 3220aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 3221aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr. 3222aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a 3223aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static. 32247bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr { 3225129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether this member expression used the '->' operator or 3226129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// the '.' operator. 3227129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow : 1; 3228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether the lookup results contain an unresolved using 3230129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// declaration. 3231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool HasUnresolvedUsing : 1; 3232129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 32337bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The expression for the base pointer or class reference, 32347bb12da2b0749eeebb21854c77877736969e59f2John McCall /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 32357bb12da2b0749eeebb21854c77877736969e59f2John McCall /// member expression 32367bb12da2b0749eeebb21854c77877736969e59f2John McCall Stmt *Base; 32377bb12da2b0749eeebb21854c77877736969e59f2John McCall 32387bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The type of the base expression; never null. 32397bb12da2b0749eeebb21854c77877736969e59f2John McCall QualType BaseType; 3240129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3241129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief The location of the '->' or '.' operator. 3242129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc; 3243129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3244bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3245aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3246129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 32474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3248e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 32492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 32505a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 32515a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3252ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3253a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis UnresolvedMemberExpr(EmptyShell Empty) 3254a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3255a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis HasUnresolvedUsing(false), Base(0) { } 3256129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 32574c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 3258ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3259129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic: 3260129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static UnresolvedMemberExpr * 3261bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Create(ASTContext &C, bool HasUnresolvedUsing, 3262aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3263129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 32644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3265e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 32662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 32675a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 32685a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3269129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3270a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis static UnresolvedMemberExpr * 3271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3272def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 3273a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3274aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 3275aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 3276aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 32774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 3278aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3279129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the base object of this member expressions, 3280129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// e.g., the \c x in \c x.m. 3281aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() { 3282aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 3283aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 3284aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 32852f27bf854f0519810b34afd209089cc75536b757John McCall const Expr *getBase() const { 32862f27bf854f0519810b34afd209089cc75536b757John McCall assert(!isImplicitAccess()); 32872f27bf854f0519810b34afd209089cc75536b757John McCall return cast<Expr>(Base); 32882f27bf854f0519810b34afd209089cc75536b757John McCall } 3289129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3290aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 3291a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3292a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// \brief Determine whether the lookup results contain an unresolved using 3293a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// declaration. 3294a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3295aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3296129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Determine whether this member expression used the '->' 3297129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// operator; otherwise, it used the '.' operator. 3298129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool isArrow() const { return IsArrow; } 3299129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3300129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the location of the '->' or '.' operator. 3301129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation getOperatorLoc() const { return OperatorLoc; } 3302129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3303c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// \brief Retrieves the naming class of this lookup. 3304c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const; 3305c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 33062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the full name info for the member that this expression 33072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 33082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 33092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3310129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the name of the member that this expression 3311129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// refers to. 33127bb12da2b0749eeebb21854c77877736969e59f2John McCall DeclarationName getMemberName() const { return getName(); } 3313129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3314129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // \brief Retrieve the location of the name of the member that this 3315129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // expression refers to. 33167bb12da2b0749eeebb21854c77877736969e59f2John McCall SourceLocation getMemberLoc() const { return getNameLoc(); } 3317129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 331865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 3319aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 332065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Base->getLocStart(); 332165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (NestedNameSpecifierLoc l = getQualifierLoc()) 332265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return l.getBeginLoc(); 332365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getMemberNameInfo().getLocStart(); 332465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 332565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 3326129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (hasExplicitTemplateArgs()) 332765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRAngleLoc(); 332865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getMemberNameInfo().getLocEnd(); 3329129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3330129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3331129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const Stmt *T) { 3332129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return T->getStmtClass() == UnresolvedMemberExprClass; 3333129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3334129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3335129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Iterators 333663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 333763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 333863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 333963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3340129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}; 3341129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 33422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 33432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// 33442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its 33452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant. 33462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr { 33472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool Value : 1; 33482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Stmt *Operand; 33492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceRange Range; 33502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3351c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl friend class ASTStmtReader; 3352c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl 33532e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic: 33542e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 33552e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceLocation Keyword, SourceLocation RParen) 3356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent*/false, 3358bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent*/Val == CT_Dependent, 3359561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Val == CT_Dependent || Operand->isInstantiationDependent(), 3360bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 33616b219d082434394c1ac401390ec1d1967727815aSebastian Redl Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 33626b219d082434394c1ac401390ec1d1967727815aSebastian Redl { } 33636b219d082434394c1ac401390ec1d1967727815aSebastian Redl 33646b219d082434394c1ac401390ec1d1967727815aSebastian Redl CXXNoexceptExpr(EmptyShell Empty) 33656b219d082434394c1ac401390ec1d1967727815aSebastian Redl : Expr(CXXNoexceptExprClass, Empty) 33662e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl { } 33672e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 33682e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Expr *getOperand() const { return static_cast<Expr*>(Operand); } 33692e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 337065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 337165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3372aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 33732e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 33742e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool getValue() const { return Value; } 33752e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 33762e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const Stmt *T) { 33772e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return T->getStmtClass() == CXXNoexceptExprClass; 33782e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 33792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 33802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl // Iterators 338163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Operand, &Operand + 1); } 33822e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}; 33832e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3384ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of 3385be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions. 3386be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3387be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an 3388be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example: 3389be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3390be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code 3391be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types> 3392be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) { 3393be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// f(static_cast<Types&&>(args)...); 3394be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// } 3395be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode 3396be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3397be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose 3398ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3399be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or 3400be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f. 3401be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr { 3402be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation EllipsisLoc; 3403ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 340467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// \brief The number of expansions that will be produced by this pack 340567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// expansion expression, if known. 340667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// 340767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// When zero, the number of expansions is not known. Otherwise, this value 340867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// is the number of expansions + 1. 340967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor unsigned NumExpansions; 3410ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3411be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Stmt *Pattern; 3412ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3413be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor friend class ASTStmtReader; 341467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor friend class ASTStmtWriter; 3415ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3416be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic: 341767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3418dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie Optional<unsigned> NumExpansions) 3419ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pattern->getObjectKind(), /*TypeDependent=*/true, 3421561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3422561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3423be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor EllipsisLoc(EllipsisLoc), 342467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3425be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Pattern(Pattern) { } 3426be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3427be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3428ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3429be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3430be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3431be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3432be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3433be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3434be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3435be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the location of the ellipsis that describes this pack 3436be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// expansion. 3437be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine the number of expansions that will be produced when 344067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// this pack expansion is instantiated, if already known. 3441dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie Optional<unsigned> getNumExpansions() const { 344267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor if (NumExpansions) 344367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return NumExpansions - 1; 3444ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 344566874fb18afbffb8b2ca05576851a64534be3352David Blaikie return None; 344667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor } 3447ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 344865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 344965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Pattern->getLocStart(); 345063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 345165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3452be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3453be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const Stmt *T) { 3454be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor return T->getStmtClass() == PackExpansionExprClass; 3455be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor } 3456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3457be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor // Iterators 345863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 345963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Pattern, &Pattern + 1); 346063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3461be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}; 3462ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3463e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3464e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 34657bb12da2b0749eeebb21854c77877736969e59f2John McCall if (isa<UnresolvedLookupExpr>(this)) 3466e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3467e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedLookupExpr>(this) + 1); 34687bb12da2b0749eeebb21854c77877736969e59f2John McCall else 3469e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3470e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedMemberExpr>(this) + 1); 34717bb12da2b0749eeebb21854c77877736969e59f2John McCall} 34727bb12da2b0749eeebb21854c77877736969e59f2John McCall 3473ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter 3474ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack. 3475ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// 3476ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code 3477ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types> 3478ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count { 3479ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// static const unsigned value = sizeof...(Types); 3480ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// }; 3481ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode 3482ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr { 3483ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the 'sizeof' keyword. 3484ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation OperatorLoc; 3485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3486ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the name of the parameter pack. 3487ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc; 3488ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3489ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the closing parenthesis. 3490ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc; 3491ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3492ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The length of the parameter pack, if known. 3493ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3494ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// When this expression is value-dependent, the length of the parameter pack 3495ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// is unknown. When this expression is not value-dependent, the length is 3496ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// known. 3497ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length; 3498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3499ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The parameter pack itself. 3500ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *Pack; 3501ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3502ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtReader; 3503ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtWriter; 3504ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3505ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic: 3506ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates a value-dependent expression that computes the length of 3507ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack. 3508ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3509ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc) 3510ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3511ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/true, 3512561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3513ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3514ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3515ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(0), Pack(Pack) { } 3516ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3517ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates an expression that computes the length of 3518ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack, which is already known. 3519ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3520ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc, 3521ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) 3522ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3523ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3524561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3525ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3526ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3527ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(Length), Pack(Pack) { } 3528ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3529ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Create an empty expression. 3530ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3531ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3532ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the 'sizeof' keyword. 3533ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 3534ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3535ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the parameter pack. 3536ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getPackLoc() const { return PackLoc; } 3537ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3538ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the right parenthesis. 3539ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3540ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3541ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the parameter pack. 3542ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *getPack() const { return Pack; } 3543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3544ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the length of the parameter pack. 3545ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3546ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This routine may only be invoked when the expression is not 3547c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// value-dependent. 3548ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned getPackLength() const { 3549ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!isValueDependent() && 3550ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor "Cannot get the length of a value-dependent pack size expression"); 3551ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return Length; 3552ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3553ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 355465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 355565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3557ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const Stmt *T) { 3558ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return T->getStmtClass() == SizeOfPackExprClass; 3559ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3561ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Iterators 356263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3563ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 3564c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 356591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter 356691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument. 356791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr { 356891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replaced parameter. 356991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *Param; 357091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 357191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replacement expression. 357291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Stmt *Replacement; 357391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 357491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The location of the non-type template parameter reference. 357591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation NameLoc; 357691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 35777110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 35787110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 3579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 35807110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 35817110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 358291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic: 3583ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmExpr(QualType type, 358491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall ExprValueKind valueKind, 358591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation loc, 358691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *param, 358791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *replacement) 358891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 358991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isTypeDependent(), replacement->isValueDependent(), 359091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isInstantiationDependent(), 359191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->containsUnexpandedParameterPack()), 359291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Param(param), Replacement(replacement), NameLoc(loc) {} 359391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 359491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation getNameLoc() const { return NameLoc; } 359565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 359665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 359791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 359891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *getReplacement() const { return cast<Expr>(Replacement); } 3599ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 360091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *getParameter() const { return Param; } 360191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 360291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall static bool classof(const Stmt *s) { 360391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 360491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3605ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 360691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Iterators 360791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall child_range children() { return child_range(&Replacement, &Replacement+1); } 360891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}; 360991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 3610c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that 3611c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack. 3612c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// 3613c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3614c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template 3615fb7669ee725ec699e2b49b8359c4652536949739Douglas Gregor/// parameter lists, this node is used to represent a non-type template 3616c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3617c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3618c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3619c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3620c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying 3621c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index. 3622c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr { 3623c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The non-type template parameter pack itself. 3624c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param; 3625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3626c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief A pointer to the set of template arguments that this 3627c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// parameter pack is instantiated with. 3628c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument *Arguments; 3629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3630c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3631c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor unsigned NumArguments; 3632ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3633c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The location of the non-type template parameter pack reference. 3634c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc; 3635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 36367110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 3637c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor friend class ASTStmtReader; 3638ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 36397110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3641c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic: 3642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmPackExpr(QualType T, 3643c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param, 3644c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc, 3645c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument &ArgPack); 3646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3647c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the non-type template parameter pack being substituted. 3648c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3649c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 3650c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the location of the parameter pack name. 3651c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation getParameterPackLocation() const { return NameLoc; } 3652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3653c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the template argument pack containing the substituted 3654c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// template arguments. 3655c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor TemplateArgument getArgumentPack() const; 3656c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 365765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 365865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3659ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3660c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor static bool classof(const Stmt *T) { 3661c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3662c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3664c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Iterators 366563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3666c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}; 366703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 36689a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \brief Represents a reference to a function parameter pack that has been 36699a4db032ecd991626d236a502e770126db32bd31Richard Smith/// substituted but not yet expanded. 36709a4db032ecd991626d236a502e770126db32bd31Richard Smith/// 36719a4db032ecd991626d236a502e770126db32bd31Richard Smith/// When a pack expansion contains multiple parameter packs at different levels, 36729a4db032ecd991626d236a502e770126db32bd31Richard Smith/// this node is used to represent a function parameter pack at an outer level 36739a4db032ecd991626d236a502e770126db32bd31Richard Smith/// which we have already substituted to refer to expanded parameters, but where 36749a4db032ecd991626d236a502e770126db32bd31Richard Smith/// the containing pack expansion cannot yet be expanded. 36759a4db032ecd991626d236a502e770126db32bd31Richard Smith/// 36769a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \code 36779a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Ts> struct S { 36789a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 36799a4db032ecd991626d236a502e770126db32bd31Richard Smith/// }; 36809a4db032ecd991626d236a502e770126db32bd31Richard Smith/// template struct S<int, int>; 36819a4db032ecd991626d236a502e770126db32bd31Richard Smith/// \endcode 36829a4db032ecd991626d236a502e770126db32bd31Richard Smithclass FunctionParmPackExpr : public Expr { 36839a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The function parameter pack which was referenced. 36849a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *ParamPack; 36859a4db032ecd991626d236a502e770126db32bd31Richard Smith 36869a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The location of the function parameter pack reference. 36879a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc; 36889a4db032ecd991626d236a502e770126db32bd31Richard Smith 36899a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief The number of expansions of this pack. 36909a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned NumParameters; 36919a4db032ecd991626d236a502e770126db32bd31Richard Smith 36929a4db032ecd991626d236a502e770126db32bd31Richard Smith FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 36939a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc, unsigned NumParams, 36949a4db032ecd991626d236a502e770126db32bd31Richard Smith Decl * const *Params); 36959a4db032ecd991626d236a502e770126db32bd31Richard Smith 36969a4db032ecd991626d236a502e770126db32bd31Richard Smith friend class ASTReader; 36979a4db032ecd991626d236a502e770126db32bd31Richard Smith friend class ASTStmtReader; 36989a4db032ecd991626d236a502e770126db32bd31Richard Smith 36999a4db032ecd991626d236a502e770126db32bd31Richard Smithpublic: 37009a4db032ecd991626d236a502e770126db32bd31Richard Smith static FunctionParmPackExpr *Create(ASTContext &Context, QualType T, 37019a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *ParamPack, 37029a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation NameLoc, 3703cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<Decl *> Params); 37049a4db032ecd991626d236a502e770126db32bd31Richard Smith static FunctionParmPackExpr *CreateEmpty(ASTContext &Context, 37059a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned NumParams); 37069a4db032ecd991626d236a502e770126db32bd31Richard Smith 37079a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the parameter pack which this expression refers to. 37089a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *getParameterPack() const { return ParamPack; } 37099a4db032ecd991626d236a502e770126db32bd31Richard Smith 37109a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the location of the parameter pack. 37119a4db032ecd991626d236a502e770126db32bd31Richard Smith SourceLocation getParameterPackLocation() const { return NameLoc; } 37129a4db032ecd991626d236a502e770126db32bd31Richard Smith 37139a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Iterators over the parameters which the parameter pack expanded 37149a4db032ecd991626d236a502e770126db32bd31Richard Smith /// into. 37159a4db032ecd991626d236a502e770126db32bd31Richard Smith typedef ParmVarDecl * const *iterator; 37169a4db032ecd991626d236a502e770126db32bd31Richard Smith iterator begin() const { return reinterpret_cast<iterator>(this+1); } 37179a4db032ecd991626d236a502e770126db32bd31Richard Smith iterator end() const { return begin() + NumParameters; } 37189a4db032ecd991626d236a502e770126db32bd31Richard Smith 37199a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get the number of parameters in this parameter pack. 37209a4db032ecd991626d236a502e770126db32bd31Richard Smith unsigned getNumExpansions() const { return NumParameters; } 37219a4db032ecd991626d236a502e770126db32bd31Richard Smith 37229a4db032ecd991626d236a502e770126db32bd31Richard Smith /// \brief Get an expansion of the parameter pack by index. 37239a4db032ecd991626d236a502e770126db32bd31Richard Smith ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 37249a4db032ecd991626d236a502e770126db32bd31Richard Smith 372565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 372665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 37279a4db032ecd991626d236a502e770126db32bd31Richard Smith 37289a4db032ecd991626d236a502e770126db32bd31Richard Smith static bool classof(const Stmt *T) { 37299a4db032ecd991626d236a502e770126db32bd31Richard Smith return T->getStmtClass() == FunctionParmPackExprClass; 37309a4db032ecd991626d236a502e770126db32bd31Richard Smith } 37319a4db032ecd991626d236a502e770126db32bd31Richard Smith 37329a4db032ecd991626d236a502e770126db32bd31Richard Smith child_range children() { return child_range(); } 37339a4db032ecd991626d236a502e770126db32bd31Richard Smith}; 37349a4db032ecd991626d236a502e770126db32bd31Richard Smith 373503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that 373603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it. 373703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 373803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address 373903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a 374003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g., 374103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 374203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code 374303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0; 374403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode 374503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 374603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 374703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference 374803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 374903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding 375003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues. 375103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr { 375203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief The temporary-generating expression whose value will be 375303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// materialized. 3754d162cf102449d817a35ae6755b102edcf9d4583bBenjamin Kramer Stmt *Temporary; 3755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 375603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtReader; 375703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtWriter; 3758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 375903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic: 3760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3761b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor bool BoundToLvalueReference) 3762b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor : Expr(MaterializeTemporaryExprClass, T, 376303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 376403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->isTypeDependent(), Temporary->isValueDependent(), 3765561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Temporary->isInstantiationDependent(), 376603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->containsUnexpandedParameterPack()), 376703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary(Temporary) { } 3768ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(EmptyShell Empty) 377003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor : Expr(MaterializeTemporaryExprClass, Empty) { } 3771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 377203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Retrieve the temporary-generating subexpression whose value will 377303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// be materialized into a glvalue. 377403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3775ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 377603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Determine whether this materialized temporary is bound to an 377703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// lvalue reference; otherwise, it's bound to an rvalue reference. 3778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isBoundToLvalueReference() const { 377903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getValueKind() == VK_LValue; 378003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3781ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 378265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 378365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Temporary->getLocStart(); 378465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 378565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 378665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Temporary->getLocEnd(); 3787aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 3788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 378903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor static bool classof(const Stmt *T) { 379003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return T->getStmtClass() == MaterializeTemporaryExprClass; 379103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 379303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Iterators 379403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor child_range children() { return child_range(&Temporary, &Temporary + 1); } 379503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}; 3796ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 37975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 37985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 37995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3800