ExprCXX.h revision 1548d14f4092a817f7d90ad3e7a65266dc85fbc5
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses for C++ expressions. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPRCXX_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPRCXX_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h" 18eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall#include "clang/AST/UnresolvedSet.h" 19d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall#include "clang/AST/TemplateBase.h" 2001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/ExpressionTraits.h" 2101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/Lambda.h" 2201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor#include "clang/Basic/TypeTraits.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXConstructorDecl; 27aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXDestructorDecl; 28aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXMethodDecl; 29aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass CXXTemporary; 30aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorclass TemplateArgumentListInfo; 314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 331060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek// C++ Expressions. 341060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek//===--------------------------------------------------------------------===// 351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A call to an overloaded operator written using operator 373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax. 383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// Represents a call to an overloaded operator written using operator 403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// normal call, this AST node provides better information about the 423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// syntactic representation of the call. 433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In a C++ template, this expression node kind will be used whenever 453fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// any of the arguments are type-dependent. In this case, the 463fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function itself will be a (possibly empty) set of functions and 473fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// function templates that were found by name lookup at template 483fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// definition time. 49b4609806e9232593ece09ce08b630836e825865cDouglas Gregorclass CXXOperatorCallExpr : public CallExpr { 50063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief The overloaded operator. 51063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind Operator; 52063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 53b4609806e9232593ece09ce08b630836e825865cDouglas Gregorpublic: 541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **args, unsigned numargs, QualType t, 56f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation operatorloc) 57cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK, 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall operatorloc), 59063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor Operator(Op) {} 601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 61ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(C, CXXOperatorCallExprClass, Empty) { } 621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 64b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator - Returns the kind of overloaded operator that this 65b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// expression refers to. 66063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OverloadedOperatorKind getOperator() const { return Operator; } 67ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 68b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 69b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperatorLoc - Returns the location of the operator symbol in 70b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// the expression. When @c getOperator()==OO_Call, this is the 71b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// location of the right parentheses; when @c 72b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// getOperator()==OO_Subscript, this is the location of the right 73b4609806e9232593ece09ce08b630836e825865cDouglas Gregor /// bracket. 74b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SourceLocation getOperatorLoc() const { return getRParenLoc(); } 75b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 7663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXOperatorCallExprClass; 80b4609806e9232593ece09ce08b630836e825865cDouglas Gregor } 81b4609806e9232593ece09ce08b630836e825865cDouglas Gregor static bool classof(const CXXOperatorCallExpr *) { return true; } 82b4609806e9232593ece09ce08b630836e825865cDouglas Gregor}; 83b4609806e9232593ece09ce08b630836e825865cDouglas Gregor 8488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that 8588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// may be written either with member call syntax (e.g., "obj.func()" 8688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// or "objptr->func()") or with normal function-call syntax 8788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// ("func()") within a member function that ends up calling a member 8888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// function. The callee in either case is a MemberExpr that contains 8988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// both the object argument and the member function, while the 9088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// arguments are the arguments within the parentheses (not including 9188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor/// the object argument). 9288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorclass CXXMemberCallExpr : public CallExpr { 9388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregorpublic: 941817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs, 95f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, SourceLocation RP) 96cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {} 9788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 981817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 991817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1001817bd483b538fd3f4530649f5cb900bad9e8a76Chris Lattner 10188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// getImplicitObjectArgument - Retrieves the implicit object 10288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// argument for the member call. For example, in "x.f(5)", this 10388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor /// operation would return "x". 104b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek Expr *getImplicitObjectArgument() const; 105ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 106b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek /// Retrieves the declaration of the called method. 107b277159055933e610bbc80262b600d3ad7e0595cTed Kremenek CXXMethodDecl *getMethodDecl() const; 10888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 109007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 110007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// the implicit object argument. Note that this is may not be the same 111007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// declaration as that of the class context of the CXXMethodDecl which this 112007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// function is calling. 113007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth /// FIXME: Returns 0 for member pointer call exprs. 114007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth CXXRecordDecl *getRecordDecl(); 115007a9b1c632bfaac20e41c60cbe07fdc6d0e647cChandler Carruth 1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor return T->getStmtClass() == CXXMemberCallExprClass; 11888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor } 11988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor static bool classof(const CXXMemberCallExpr *) { return true; } 12088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor}; 12188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 122e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 123e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneclass CUDAKernelCallExpr : public CallExpr { 124e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourneprivate: 125e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne enum { CONFIG, END_PREARG }; 126e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 127e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournepublic: 128e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 129e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr **args, unsigned numargs, QualType t, 130e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprValueKind VK, SourceLocation RP) 131e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK, 132e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne RP) { 133e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne setConfig(Config); 134e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 135e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 136e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 137e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 138e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 139e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne const CallExpr *getConfig() const { 140e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return cast_or_null<CallExpr>(getPreArg(CONFIG)); 141e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 142e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 143e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 144e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 145e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const Stmt *T) { 146e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return T->getStmtClass() == CUDAKernelCallExprClass; 147e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne } 148e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne static bool classof(const CUDAKernelCallExpr *) { return true; } 149e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne}; 150e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 15149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 15249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 15349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// const_cast. 15449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 15549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This abstract class is inherited by all of the classes 15649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr, 15749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 15849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr { 1591060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekprivate: 1601060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; // the location of the casting op 1611d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc; // the location of the right parenthesis 162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 165f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 1661d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 1671d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 1681d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 1691d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor RParenLoc(RParenLoc) {} 17049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 171f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 172f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(SC, Shell, PathSize) { } 173ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 1741d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor friend class ASTStmtReader; 175ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1761060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 17749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor const char *getCastName() const; 17849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 179a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// \brief Retrieve the location of the cast operator keyword, e.g., 180a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor /// "static_cast". 181a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor SourceLocation getOperatorLoc() const { return Loc; } 182a3a7b8eea87c90a5a257f685749222b212ddaf36Douglas Gregor 1831d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor /// \brief Retrieve the location of the closing parenthesis. 1841d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 185ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1871d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor return SourceRange(Loc, RParenLoc); 1881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor switch (T->getStmtClass()) { 19149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXStaticCastExprClass: 19249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXDynamicCastExprClass: 19349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXReinterpretCastExprClass: 19449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor case CXXConstCastExprClass: 19549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return true; 19649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor default: 19749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return false; 19849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 1991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 20049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXNamedCastExpr *) { return true; } 20149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 20249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 203ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// CXXStaticCastExpr - A C++ @c static_cast expression 204ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// (C++ [expr.static.cast]). 2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 20649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a C++ static cast, e.g., 20749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c static_cast<int>(1.0). 20849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr { 209f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 210f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize, TypeSourceInfo *writtenTy, 2111d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 212f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 2131d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 21449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 215f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 216f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 217f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 218f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 219f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 220f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, Expr *Op, 221f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 222ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2231d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 224f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 225f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 226ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXStaticCastExprClass; 22949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 23049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXStaticCastExpr *) { return true; } 23149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 23249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 23349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 2341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 23549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// determine how to perform the type cast. 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 23749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a dynamic cast, e.g., 23849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c dynamic_cast<Derived*>(BasePtr). 23949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr { 240f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 2421d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation l, SourceLocation RParenLoc) 243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 2441d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor writtenTy, l, RParenLoc) {} 24549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 249f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 251f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, Expr *Op, 252f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 253ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *Written, SourceLocation L, 2541d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 255ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 256f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 257f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 258ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2590fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson bool isAlwaysNull() const; 2600fee330f5754ca4b248e5bb7363e834668aff06dAnders Carlsson 2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXDynamicCastExprClass; 26349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 26449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXDynamicCastExpr *) { return true; } 26549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 26649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 26849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view 26949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// of a value but performs no actual work at run time. 2701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 27149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a reinterpret cast, e.g., 27249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr). 27349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 274f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *op, unsigned pathSize, 276ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 2771d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 278f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 2791d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor pathSize, writtenTy, l, RParenLoc) {} 28049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 281f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 282f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 283f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 284f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 285f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 286f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind Kind, 287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr *Op, const CXXCastPath *Path, 288ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 2891d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 290f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned pathSize); 292ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 2931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXReinterpretCastExprClass; 29549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 29649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXReinterpretCastExpr *) { return true; } 29749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 29849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 29949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 30049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// which can remove type qualifiers but does not change the underlying value. 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 30249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This expression node represents a const cast, e.g., 30349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// @c const_cast<char*>(PtrToConstChar). 30449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr { 305f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 306ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *writtenTy, SourceLocation l, 3071d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc) 308ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 3091d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor 0, writtenTy, l, RParenLoc) {} 31049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 311ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig explicit CXXConstCastExpr(EmptyShell Empty) 312f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 313f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 314f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, Expr *Op, 317ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *WrittenTy, SourceLocation L, 3181d5d0b9df6d2a3df338bc3e63000536406e7666cDouglas Gregor SourceLocation RParenLoc); 319f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 320ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 32249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor return T->getStmtClass() == CXXConstCastExprClass; 32349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 32449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const CXXConstCastExpr *) { return true; } 3251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 3291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXBoolLiteralExpr : public Expr { 3301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool Value; 3311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation Loc; 3321060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 3331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 334bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 335561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(val), Loc(l) {} 3378b0b475b3464b0f70b91ba7d679d23c424677d5eSebastian Redl 338eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXBoolLiteralExpr(EmptyShell Empty) 339eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXBoolLiteralExprClass, Empty) { } 340eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek bool getValue() const { return Value; } 342eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setValue(bool V) { Value = V; } 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 347eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 348eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 3501060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXBoolLiteralExprClass; 3511060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 3521060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXBoolLiteralExpr *) { return true; } 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3541060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 35563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3561060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 3571060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 3586e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 3596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlclass CXXNullPtrLiteralExpr : public Expr { 3606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl SourceLocation Loc; 3616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlpublic: 3626e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 363bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 364561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) {} 3666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 367eb7f96141f754150a92433286fa385910a22f494Sam Weinig explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 368eb7f96141f754150a92433286fa385910a22f494Sam Weinig : Expr(CXXNullPtrLiteralExprClass, Empty) { } 369eb7f96141f754150a92433286fa385910a22f494Sam Weinig 37063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 3716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 372eb7f96141f754150a92433286fa385910a22f494Sam Weinig SourceLocation getLocation() const { return Loc; } 373eb7f96141f754150a92433286fa385910a22f494Sam Weinig void setLocation(SourceLocation L) { Loc = L; } 374eb7f96141f754150a92433286fa385910a22f494Sam Weinig 3756e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const Stmt *T) { 3766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return T->getStmtClass() == CXXNullPtrLiteralExprClass; 3776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl } 3786e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 3796e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 38063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3816e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl}; 3826e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 383c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 384c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// the type_info that corresponds to the supplied type, or the (possibly 385c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// dynamic) type of the supplied expression. 386c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// 387c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl/// This represents code like @c typeid(int) or @c typeid(*objPtr) 388c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlclass CXXTypeidExpr : public Expr { 389c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlprivate: 39057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 391c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl SourceRange Range; 392c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 393c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redlpublic: 39457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 395f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 39657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 39757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor false, 39857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor // typeid is value-dependent if the type or expression are dependent 399bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->isDependentType(), 400561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 401bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 40257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 403ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 40457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 4062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is never type-dependent (C++ [temp.dep.expr]p4) 407bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, 4082850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // typeid is value-dependent if the type or expression are dependent 409bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->isTypeDependent() || Operand->isValueDependent(), 410561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 411bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 41257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor Operand(Operand), Range(R) { } 413c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 41414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner CXXTypeidExpr(EmptyShell Empty, bool isExpr) 41514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner : Expr(CXXTypeidExprClass, Empty) { 41614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner if (isExpr) 41714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (Expr*)0; 41814ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner else 41914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = (TypeSourceInfo*)0; 42014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 421ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 423ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieves the type operand of this typeid() expression after 42557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 42657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor QualType getTypeOperand() const; 42757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor 42857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor /// \brief Retrieve source information for the type operand. 42957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *getTypeOperandSourceInfo() const { 430c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 43157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return Operand.get<TypeSourceInfo *>(); 432c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 43314ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner 43414ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 43514ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 43614ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Operand = TSI; 43714ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner } 438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 43914ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner Expr *getExprOperand() const { 440c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 44157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 442c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 444030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner void setExprOperand(Expr *E) { 445030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 446030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner Operand = E; 447030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner } 448ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 44963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 45014ab24f01e36d495fce183aa67b41e45cdd54f39Chris Lattner void setSourceRange(SourceRange R) { Range = R; } 451ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 452c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const Stmt *T) { 453c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return T->getStmtClass() == CXXTypeidExprClass; 454c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl } 455c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl static bool classof(const CXXTypeidExpr *) { return true; } 456c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 457c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // Iterators 45863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 45963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 46063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 46163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 46263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 463c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl}; 464c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl 46501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 46601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// the _GUID that corresponds to the supplied type or expression. 46701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// 46801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 46901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetclass CXXUuidofExpr : public Expr { 47001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetprivate: 47101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 47201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceRange Range; 47301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 47401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichetpublic: 47501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 4762e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 477bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->getType()->isDependentType(), 478561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->getType()->isInstantiationDependentType(), 479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 48001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 481ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 48201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 4832e219b8d253dbb901206b14e5643cc9d0edd662bFrancois Pichet : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 484bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, Operand->isTypeDependent(), 485561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Operand->isInstantiationDependent(), 486bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 48701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand(Operand), Range(R) { } 48801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 48901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet CXXUuidofExpr(EmptyShell Empty, bool isExpr) 49001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet : Expr(CXXUuidofExprClass, Empty) { 49101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (isExpr) 49201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (Expr*)0; 49301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet else 49401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = (TypeSourceInfo*)0; 49501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 496ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 49701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 49901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieves the type operand of this __uuidof() expression after 50001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// various required adjustments (removing reference types, cv-qualifiers). 50101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet QualType getTypeOperand() const; 50201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 50301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Retrieve source information for the type operand. 50401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *getTypeOperandSourceInfo() const { 50501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 50601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return Operand.get<TypeSourceInfo *>(); 50701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 50801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 50901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 51001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 51101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = TSI; 51201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 513ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 51401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *getExprOperand() const { 51501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 51601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return static_cast<Expr*>(Operand.get<Stmt *>()); 51701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 518ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 51901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setExprOperand(Expr *E) { 52001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 52101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Operand = E; 52201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 52301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 52463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 52501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet void setSourceRange(SourceRange R) { Range = R; } 526ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 52701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const Stmt *T) { 52801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return T->getStmtClass() == CXXUuidofExprClass; 52901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 53001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet static bool classof(const CXXUuidofExpr *) { return true; } 53101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 53201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // Iterators 53363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 53463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isTypeOperand()) return child_range(); 53563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 53663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + 1); 53763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 53801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet}; 53901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 540796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// CXXThisExpr - Represents the "this" expression in C++, which is a 541796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// pointer to the object on which the current member function is 542796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// executing (C++ [expr.prim]p3). Example: 543796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// 544796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @code 545796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// class Foo { 546796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// public: 547796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void bar(); 548796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// void test() { this->bar(); } 549796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// }; 550796da18402f286b897782a298ae3b20c459c102eDouglas Gregor/// @endcode 551796da18402f286b897782a298ae3b20c459c102eDouglas Gregorclass CXXThisExpr : public Expr { 552796da18402f286b897782a298ae3b20c459c102eDouglas Gregor SourceLocation Loc; 553828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool Implicit : 1; 554ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 555796da18402f286b897782a298ae3b20c459c102eDouglas Gregorpublic: 556828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 557f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 5582850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // 'this' is type-dependent if the class type of the enclosing 5592850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // member function is dependent (C++ [temp.dep.expr]p2) 560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Type->isDependentType(), Type->isDependentType(), 561561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Type->isInstantiationDependentType(), 562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 563828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor Loc(L), Implicit(isImplicit) { } 564796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 5652fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 5662fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 5672fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner SourceLocation getLocation() const { return Loc; } 5682fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner void setLocation(SourceLocation L) { Loc = L; } 5692fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 57063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 571796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 572828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor bool isImplicit() const { return Implicit; } 573828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor void setImplicit(bool I) { Implicit = I; } 574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 576796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return T->getStmtClass() == CXXThisExprClass; 577796da18402f286b897782a298ae3b20c459c102eDouglas Gregor } 578796da18402f286b897782a298ae3b20c459c102eDouglas Gregor static bool classof(const CXXThisExpr *) { return true; } 579796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 580796da18402f286b897782a298ae3b20c459c102eDouglas Gregor // Iterators 58163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 582796da18402f286b897782a298ae3b20c459c102eDouglas Gregor}; 583796da18402f286b897782a298ae3b20c459c102eDouglas Gregor 5841060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 5851060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 'throw' and 'throw' assignment-expression. When 5861060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// assignment-expression isn't present, Op will be null. 5871060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// 5881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXThrowExpr : public Expr { 5891060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Stmt *Op; 5901060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek SourceLocation ThrowLoc; 591bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Whether the thrown variable (if any) is in scope. 592bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor unsigned IsThrownVariableInScope : 1; 593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 594bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor friend class ASTStmtReader; 595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 5961060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 5971060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Ty is the void type which is used as the result type of the 5981060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // exepression. The l is the location of the throw keyword. expr 5991060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // can by null, if the optional expression to throw isn't present. 600bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 601bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) : 602bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 603561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor expr && expr->isInstantiationDependent(), 604bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor expr && expr->containsUnexpandedParameterPack()), 605bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 6062fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 6072fbdfcdf3bbf7b941853d38b123930755e837437Chris Lattner 6081060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 6091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 61042e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor 61142e5b50f4dc897f252e0d476063a7f9846d96624Douglas Gregor SourceLocation getThrowLoc() const { return ThrowLoc; } 6121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 613bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// \brief Determines whether the variable thrown by this expression (if any!) 614bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// is within the innermost try block. 615bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// 616bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// This information is required to determine whether the NRVO can apply to 617bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor /// this variable. 618bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 62063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 6211060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek if (getSubExpr() == 0) 6221060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, ThrowLoc); 6231060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 6241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 6251060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6261060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 6271060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXThrowExprClass; 6281060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 6291060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXThrowExpr *) { return true; } 6301060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6311060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 63263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 63363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Op, Op ? &Op+1 : &Op); 63463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 6351060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 6361060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 6371060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 6381060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// function call argument that was created from the corresponding 6391060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// parameter's default argument, when the call did not explicitly 6401060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek/// supply arguments for all of the parameters. 6411060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekclass CXXDefaultArgExpr : public Expr { 64265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// \brief The parameter whose default is being used. 64365222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// 644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// When the bit is set, the subexpression is stored after the 64565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 64665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor /// actual default expression is the subexpression. 64765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 649036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// \brief The location where the default argument expression was used. 650036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc; 651ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 652036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(SC, 65465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor param->hasUnparsedDefaultArg() 65565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ? param->getType().getNonReferenceType() 6562333f7727f97018d6742e1e0938133bcfad967abEli Friedman : param->getDefaultArg()->getType(), 657dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall param->getDefaultArg()->getValueKind(), 658561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor param->getDefaultArg()->getObjectKind(), false, false, false, false), 659036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param(param, false), Loc(Loc) { } 66065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor 661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 662036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Expr *SubExpr) 663dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall : Expr(SC, SubExpr->getType(), 664dfa1edbebeda7ec3a7a9c45e4317de9241aa9883John McCall SubExpr->getValueKind(), SubExpr->getObjectKind(), 665ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false, false, false, false), 666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Param(param, true), Loc(Loc) { 66765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor *reinterpret_cast<Expr **>(this + 1) = SubExpr; 66865222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6701060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenekpublic: 671030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 672030854b95f7bfd86aaa8afd9ae1aff9768a37e9aChris Lattner 673ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6741060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Param is the parameter whose default argument is used by this 6751060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // expression. 676036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 677036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 678036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 679f1480eee38b59d15438fb7bc50865ac7c7e22403Anders Carlsson } 6801060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 68165222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // Param is the parameter whose default argument is used by this 68265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor // expression, and SubExpr is the expression that will actually be used. 683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static CXXDefaultArgExpr *Create(ASTContext &C, 684036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation Loc, 685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ParmVarDecl *Param, 68665222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor Expr *SubExpr); 687ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6881060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the parameter that the argument was created from. 68965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor const ParmVarDecl *getParam() const { return Param.getPointer(); } 69065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor ParmVarDecl *getParam() { return Param.getPointer(); } 691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 6921060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Retrieve the actual argument to the function call. 693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const Expr *getExpr() const { 69465222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 69565222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr const * const*> (this + 1); 696ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 69765222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr *getExpr() { 69965222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor if (Param.getInt()) 70065222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor return *reinterpret_cast<Expr **> (this + 1); 701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return getParam()->getDefaultArg(); 70265222e82d97af2120b3952d19cbd3cd923f4b43eDouglas Gregor } 7031060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the location where this default argument was actually 705036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor /// used. 706036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor SourceLocation getUsedLocation() const { return Loc; } 707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 70863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 7091060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Default argument expressions have no representation in the 7101060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // source, so they have an empty source range. 7111060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return SourceRange(); 7121060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7131060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7141060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const Stmt *T) { 7151060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek return T->getStmtClass() == CXXDefaultArgExprClass; 7161060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek } 7171060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek static bool classof(const CXXDefaultArgExpr *) { return true; } 7181060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek 7191060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek // Iterators 72063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 7218a50733034edd6a349b34e2b9f0c8d0a874846d3Argyrios Kyrtzidis 72260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 7233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 7241060aff23f72135f8b50034a1e80f16725ebc56cTed Kremenek}; 725987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 726c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson/// CXXTemporary - Represents a C++ temporary. 727c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonclass CXXTemporary { 728c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson /// Destructor - The destructor that needs to be called. 729b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor; 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 731b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson CXXTemporary(const CXXDestructorDecl *destructor) 732c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson : Destructor(destructor) { } 733c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson 734c1ce477119fed070299668aab24084b17ff5f14bAnders Carlssonpublic: 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXTemporary *Create(ASTContext &C, 736b859f35459ae3e1188d1e1b86df08d649695fd86Anders Carlsson const CXXDestructorDecl *Destructor); 7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 738f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXDestructorDecl *getDestructor() const { return Destructor; } 739c1ce477119fed070299668aab24084b17ff5f14bAnders Carlsson}; 740fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 741ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \brief Represents binding an expression to a temporary. 742ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 743ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// This ensures the destructor is called for the temporary. It should only be 744ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// needed for non-POD, non-trivially destructable class types. For example: 745ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// 746ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \code 747ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// struct S { 748ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// S() { } // User defined constructor makes S non-POD. 749ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// ~S() { } // User defined destructor makes it non-trivial. 750ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// }; 751ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// void test() { 752ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 753ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// } 754ddfe960d252a93525692b547945236d361d1929fChandler Carruth/// \endcode 755fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonclass CXXBindTemporaryExpr : public Expr { 756fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson CXXTemporary *Temp; 7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 758fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Stmt *SubExpr; 759fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 760bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 761bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 763bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->isValueDependent(), 764561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SubExpr->isInstantiationDependent(), 765bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SubExpr->containsUnexpandedParameterPack()), 766bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Temp(temp), SubExpr(SubExpr) { } 76788eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson 768fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlssonpublic: 769d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner CXXBindTemporaryExpr(EmptyShell Empty) 770d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 773fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr* SubExpr); 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77588eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson CXXTemporary *getTemporary() { return Temp; } 776f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const CXXTemporary *getTemporary() const { return Temp; } 777d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner void setTemporary(CXXTemporary *T) { Temp = T; } 778f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson 779fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 780fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 78188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 782fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceRange getSourceRange() const { 78496be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 78596be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 786fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 787fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Implement isa/cast/dyncast/etc. 788fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const Stmt *T) { 789fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson return T->getStmtClass() == CXXBindTemporaryExprClass; 790fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson } 791fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson static bool classof(const CXXBindTemporaryExpr *) { return true; } 792fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 793fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson // Iterators 79463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 795fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson}; 796fceb0a8adba9d25db99a4d73e9655c2831a96ecdAnders Carlsson 79715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson/// CXXConstructExpr - Represents a call to a C++ constructor. 79815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonclass CXXConstructExpr : public Expr { 79972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonpublic: 80072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson enum ConstructionKind { 80172e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_Complete, 80272e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson CK_NonVirtualBase, 803059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_VirtualBase, 804059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt CK_Delegating 80572e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson }; 806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 80772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlssonprivate: 80815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson CXXConstructorDecl *Constructor; 80915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 81099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc; 811428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange; 812a48e676a717309afa50ae06a3d4674acec025bf9Douglas Gregor unsigned NumArgs : 16; 81316006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool Elidable : 1; 8147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 8155b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization : 1; 81616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool ZeroInitialization : 1; 81772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson unsigned ConstructKind : 2; 81815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson Stmt **Args; 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 820bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlssonprotected: 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 82299a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 823bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson CXXConstructorDecl *d, bool elidable, 82416006c901315fa12a108b4e571f187f4b676e426Douglas Gregor Expr **args, unsigned numargs, 8257cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 8265b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 8275b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 8285b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 8295b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 830bd6734e5f6432ce0cc07171c490ffaa094796198Anders Carlsson 8316d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 8326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis CXXConstructExpr(StmtClass SC, EmptyShell Empty) 8335b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 8345b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl HadMultipleCandidates(false), ListInitialization(false), 8355b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ZeroInitialization(false), ConstructKind(0), Args(0) 8365b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 8376d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 83815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlssonpublic: 8396d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis /// \brief Construct an empty C++ construction expression. 8406d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXConstructExpr(EmptyShell Empty) 8416d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis : Expr(CXXConstructExprClass, Empty), Constructor(0), 8425b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl NumArgs(0), Elidable(false), HadMultipleCandidates(false), 8435b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ListInitialization(false), ZeroInitialization(false), 8445b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructKind(0), Args(0) 8455b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl { } 8466d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 8478e587a15da6d3457a418239d5eb4146fcbd209f3Anders Carlsson static CXXConstructExpr *Create(ASTContext &C, QualType T, 84899a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation Loc, 8491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXConstructorDecl *D, bool Elidable, 85016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor Expr **Args, unsigned NumArgs, 8517cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 8525b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ListInitialization, 8535b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool ZeroInitialization, 8545b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl ConstructionKind ConstructKind, 8555b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceRange ParenRange); 8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 857d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor CXXConstructorDecl* getConstructor() const { return Constructor; } 85839da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 859ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 86099a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor SourceLocation getLocation() const { return Loc; } 86199a2e600f9e2e51d3ce10fb6f27191677ac65b2aDouglas Gregor void setLocation(SourceLocation Loc) { this->Loc = Loc; } 862ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 863d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor /// \brief Whether this construction is elidable. 864d94546a0a1deef7286c13e49b9584621ae81cc9aDouglas Gregor bool isElidable() const { return Elidable; } 86539da0b8145eaec7da7004f9b3645c5c9f4f63b1dDouglas Gregor void setElidable(bool E) { Elidable = E; } 8667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 8677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Whether the referred constructor was resolved from 8687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// an overloaded set having size greater than 1. 8697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { return HadMultipleCandidates; } 8707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 8717cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 8725b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl /// \brief Whether this constructor call was written as list-initialization. 8735b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl bool isListInitialization() const { return ListInitialization; } 8745b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl void setListInitialization(bool V) { ListInitialization = V; } 8755b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl 87616006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// \brief Whether this construction first requires 87716006c901315fa12a108b4e571f187f4b676e426Douglas Gregor /// zero-initialization before the initializer is called. 87816006c901315fa12a108b4e571f187f4b676e426Douglas Gregor bool requiresZeroInitialization() const { return ZeroInitialization; } 87916006c901315fa12a108b4e571f187f4b676e426Douglas Gregor void setRequiresZeroInitialization(bool ZeroInit) { 88016006c901315fa12a108b4e571f187f4b676e426Douglas Gregor ZeroInitialization = ZeroInit; 88116006c901315fa12a108b4e571f187f4b676e426Douglas Gregor } 882ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 8839db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// \brief Determines whether this constructor is actually constructing 8849db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor /// a base class (rather than a complete object). 88524eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson ConstructionKind getConstructionKind() const { 88624eb78e38aba55c507bc3c05c37035a9ab2defa7Anders Carlsson return (ConstructionKind)ConstructKind; 88772e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 888ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setConstructionKind(ConstructionKind CK) { 88972e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson ConstructKind = CK; 89072e96fd181b19b8d01144a685cda6e955584c7eaAnders Carlsson } 891ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 89215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ExprIterator arg_iterator; 89315ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson typedef ConstExprIterator const_arg_iterator; 8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_begin() { return Args; } 89615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson arg_iterator arg_end() { return Args + NumArgs; } 89715ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_begin() const { return Args; } 89815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson const_arg_iterator arg_end() const { return Args + NumArgs; } 89915ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 900a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 90115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson unsigned getNumArgs() const { return NumArgs; } 90215ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 903bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson /// getArg - Return the specified argument. 904bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson Expr *getArg(unsigned Arg) { 905bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 906bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 907bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 908bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson const Expr *getArg(unsigned Arg) const { 909bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson assert(Arg < NumArgs && "Arg access out of range!"); 910bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson return cast<Expr>(Args[Arg]); 911bcb11d01c034f967503bd98f28bdf458c1ab8001Anders Carlsson } 9121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9132eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian /// setArg - Set the specified argument. 9142eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian void setArg(unsigned Arg, Expr *ArgExpr) { 9152eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian assert(Arg < NumArgs && "Arg access out of range!"); 9162eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian Args[Arg] = ArgExpr; 9172eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian } 9182eeed7bc4fd457ac57ff32ab3b02674588545f65Fariborz Jahanian 91963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 920428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange getParenRange() const { return ParenRange; } 92115ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 923524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson return T->getStmtClass() == CXXConstructExprClass || 924524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlsson T->getStmtClass() == CXXTemporaryObjectExprClass; 92515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson } 92615ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson static bool classof(const CXXConstructExpr *) { return true; } 9271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92815ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson // Iterators 92963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 93063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Args[0], &Args[0]+NumArgs); 93163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 9326d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 93360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 93415ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson}; 93515ef2b5820f9daccc44b9e847163b705b6f5863bAnders Carlsson 93649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 93749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 93849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// x = int(0.5); 93949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorclass CXXFunctionalCastExpr : public ExplicitCastExpr { 940987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation TyBeginLoc; 941987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 942f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 943f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 944f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy, 9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation tyBeginLoc, CastKind kind, 946f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *castExpr, unsigned pathSize, 947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation rParenLoc) 948f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 949f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall castExpr, pathSize, writtenTy), 9500aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 9510aebc81e02397a5987aaa8e8c7acbdb01a31d7c3Anders Carlsson 952f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 953f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 954f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 955f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 956f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 957f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, 958f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *Written, 959f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation TyBeginLoc, 960f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Op, 961f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *Path, 962f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation RPLoc); 963f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 964f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize); 965ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig 966987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 967ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 968987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation getRParenLoc() const { return RParenLoc; } 969ce757a7a1ee905f87551996a69da3e95e8afeeb7Sam Weinig void setRParenLoc(SourceLocation L) { RParenLoc = L; } 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 972987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis return SourceRange(TyBeginLoc, RParenLoc); 973987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 9741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CXXFunctionalCastExprClass; 976987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 977987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis static bool classof(const CXXFunctionalCastExpr *) { return true; } 978987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 979987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 980506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @brief Represents a C++ functional cast expression that builds a 981506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// temporary object. 982506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This expression type represents a C++ "functional" cast 984506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 985ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// constructor to build a temporary object. With N == 1 arguments the 986ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// functional cast expression will be represented by CXXFunctionalCastExpr. 987506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Example: 988506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @code 989506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// struct X { X(int, float); } 990506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// 991506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// X create_X() { 992506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 993506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// }; 994506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// @endcode 995524fa13fd81e88533c7a1d4b1232c0de2c97dc7cAnders Carlssonclass CXXTemporaryObjectExpr : public CXXConstructExpr { 996ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 997506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 998506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregorpublic: 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1000ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr **Args,unsigned NumArgs, 1002428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange parenRange, 10037cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 10041c63b9c15d48cb8c833a4b2d6fd6c496c0766e88Douglas Gregor bool ZeroInitialization = false); 10056d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1006ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1007506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 1008ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1009ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 101063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 1011ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1013506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor return T->getStmtClass() == CXXTemporaryObjectExprClass; 1014506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor } 1015506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor static bool classof(const CXXTemporaryObjectExpr *) { return true; } 10166d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 101760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 1018506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor}; 1019506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor 102001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \brief A C++ lambda expression, which produces a function object 102101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// (of unspecified type) that can be invoked later. 102201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 102301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Example: 102401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \code 102501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// void low_pass_filter(std::vector<double> &values, double cutoff) { 102601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// values.erase(std::remove_if(values.begin(), values.end(), 102701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor// [=](double value) { return value > cutoff; }); 102801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// } 102901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// \endcode 103001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// 103101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// Lambda expressions can capture local variables, either by copying 103201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// the values of those local variables at the time the function 103301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// object is constructed (not when it is called!) or by holding a 103401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// reference to the local variable. These captures can occur either 103501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// implicitly or can be written explicitly between the square 103601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor/// brackets ([...]) that start the lambda expression. 103701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorclass LambdaExpr : public Expr { 103801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor enum { 103901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indicate that the given 104001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture was implicit. 104101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_Implicit = 0x01, 104201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 104301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Flag used by the Capture class to indciate that the 104401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// given capture was by-copy. 104501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture_ByCopy = 0x02 104601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 104701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 104801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The source range that covers the lambda introducer ([...]). 104901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange; 105001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 10517ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief The number of captures. 10527ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned NumCaptures : 16; 10537ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 105401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The default capture kind, which is a value of type 105501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// LambdaCaptureDefault. 105601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned CaptureDefault : 2; 105701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 105801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Whether this lambda had an explicit parameter list vs. an 105901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit (and empty) parameter list. 106001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor unsigned ExplicitParams : 1; 106101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1062dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had the result type explicitly specified. 1063dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor unsigned ExplicitResultType : 1; 1064dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 1065dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether there are any array index variables stored at the end of 1066dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// this lambda expression. 10677ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned HasArrayIndexVars : 1; 10687ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 106901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief The location of the closing brace ('}') that completes 107001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// the lambda. 107101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 107201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// The location of the brace is also available by looking up the 107301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// function call operator in the lambda class. However, it is 107401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stored here to improve the performance of getSourceRange(), and 107501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// to avoid having to deserialize the function call operator from a 107601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// module file just to determine the source range. 107701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace; 107801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 10797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // Note: The capture initializers are stored directly after the lambda 10807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // expression, along with the index variables used to initialize by-copy 10817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor // array captures. 10827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 108301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 108401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Describes the capture of either a variable or 'this'. 108501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor class Capture { 108601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 108701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation Loc; 108801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc; 10899daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 109001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 109101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 10929daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 109301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor public: 109401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Create a new capture. 109501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 109601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Loc The source location associated with this capture. 109701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 109801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Kind The kind of capture (this, byref, bycopy). 109901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Implicit Whether the capture was implicit or explicit. 110101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param Var The local variable being captured, or null if capturing this. 110301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 110401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \param EllipsisLoc The location of the ellipsis (...) for a 110501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// capture that is a pack expansion, or an invalid source 110601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// location to indicate that this is not a pack expansion. 110701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor Capture(SourceLocation Loc, bool Implicit, 110801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind Kind, VarDecl *Var = 0, 110901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation EllipsisLoc = SourceLocation()); 111001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the kind of capture. 111201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureKind getCaptureKind() const; 111301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles the C++ 'this' 111501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// pointer. 111601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesThis() const { return VarAndBits.getPointer() == 0; } 111701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 111801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture handles a variable. 111901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 112001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 112101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the declaration of the local variable being 112201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captured. 112301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 112401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// This operation is only valid if this capture does not capture 112501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 'this'. 112601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor VarDecl *getCapturedVar() const { 112701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(!capturesThis() && "No variable available for 'this' capture"); 112801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return VarAndBits.getPointer(); 112901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 113001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an implicit capture (not 113201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// written between the square brackets introducing the lambda). 113301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 113401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this was an explicit capture, written 113601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// between the square brackets introducing the lambda. 113701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isExplicit() const { return !isImplicit(); } 113801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 113901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source location of the capture. 114001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// 114101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// For an explicit capture, this returns the location of the 114201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit capture in the source. For an implicit capture, this 114301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// returns the location at which the variable or 'this' was first 114401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// used. 114501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getLocation() const { return Loc; } 114601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 114701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this capture is a pack expansion, 114801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which captures a function parameter pack. 114901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isPackExpansion() const { return EllipsisLoc.isValid(); } 115001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 115101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the location of the ellipsis for a capture 115201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// that is a pack expansion. 115301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation getEllipsisLoc() const { 115401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 115501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return EllipsisLoc; 115601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 115701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor }; 115801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 115901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorprivate: 116001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a lambda expression. 116101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaExpr(QualType T, SourceRange IntroducerRange, 116201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 116301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 116401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1165dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 116601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 11679daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 11689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 116901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace); 117001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 11719d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct an empty lambda expression. 11729d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 11739d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor : Expr(LambdaExprClass, Empty), 11749d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 11759d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor ExplicitResultType(false), HasArrayIndexVars(true) { 11769d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor getStoredStmts()[NumCaptures] = 0; 11779d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor } 11789d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 11797ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor Stmt **getStoredStmts() const { 11807ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 11817ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11827ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 11837ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the mapping from captures to the first array index 11847ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// variable. 11857ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned *getArrayIndexStarts() const { 11867ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 11877ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11887ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 11897ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Retrieve the complete set of array-index variables. 11907ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor VarDecl **getArrayIndexVars() const { 11917ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<VarDecl **>( 11927ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor getArrayIndexStarts() + NumCaptures + 1); 11937ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 11947ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 119501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregorpublic: 119601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Construct a new lambda expression. 119701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static LambdaExpr *Create(ASTContext &C, 119801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *Class, 119901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange, 120001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault CaptureDefault, 120101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Capture> Captures, 120201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams, 1203dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool ExplicitResultType, 120401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor ArrayRef<Expr *> CaptureInits, 12059daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> ArrayIndexVars, 12069daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<unsigned> ArrayIndexStarts, 120701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceLocation ClosingBrace); 120801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12099d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// \brief Construct a new lambda expression that will be deserialized from 12109d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor /// an external source. 12119d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 12129d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor unsigned NumArrayIndexVars); 12139d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor 121401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine the default capture kind for this lambda. 121501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor LambdaCaptureDefault getCaptureDefault() const { 121601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return static_cast<LambdaCaptureDefault>(CaptureDefault); 121701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 121801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 121901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief An iterator that walks over the captures of the lambda, 122001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// both implicit and explicit. 122101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef const Capture *capture_iterator; 122201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first lambda capture. 1224da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_begin() const; 122501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 122601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the 122701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// sequence of lambda captures. 1228da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator capture_end() const; 122901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12307ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor /// \brief Determine the number of captures in this lambda. 12317ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor unsigned capture_size() const { return NumCaptures; } 12327ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor 123301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first explicit 123401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1235da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_begin() const; 123601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 123701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 123801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// explicit lambda captures. 1239da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator explicit_capture_end() const; 124001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing to the first implicit 124201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda capture. 1243da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_begin() const; 124401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve an iterator pointing past the end of the sequence of 124601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// implicit lambda captures. 1247da8962a6198bc4bf09a38209db99551b2b0a41a0Douglas Gregor capture_iterator implicit_capture_end() const; 124801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 124901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Iterator that walks over the capture initialization 125001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// arguments. 125101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor typedef Expr **capture_init_iterator; 125201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 125301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the first initialization argument for this 125401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression (which initializes the first capture field). 12557ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_begin() const { 12567ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return reinterpret_cast<Expr **>(getStoredStmts()); 12577ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 125801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 125901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the iterator pointing one past the last 126076e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor /// initialization argument for this lambda expression. 12617ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor capture_init_iterator capture_init_end() const { 12627ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return capture_init_begin() + NumCaptures; 12637ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 126401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 12659daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Retrieve the set of index variables used in the capture 12669daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// initializer of an array captured by copy. 12679daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// 12689daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \param Iter The iterator that points at the capture initializer for 12699daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// which we are extracting the corresponding index variables. 12709daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 12719daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 127201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the source range covering the lambda introducer, 127301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// which contains the explicit capture list surrounded by square 127401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// brackets ([...]). 127501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getIntroducerRange() const { return IntroducerRange; } 127601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 127701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the class that corresponds to the lambda, which 127801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// stores the captures in its fields and provides the various 127901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// operations permitted on a lambda (copying, calling). 128001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXRecordDecl *getLambdaClass() const; 128101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the function call operator associated with this 128301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// lambda expression. 128401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor CXXMethodDecl *getCallOperator() const; 128501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Retrieve the body of the lambda. 12879d36f5dc4121f0f931211ea2d0a74d299eb82b23Douglas Gregor CompoundStmt *getBody() const; 128801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 128901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether the lambda is mutable, meaning that any 129001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// captures values can be modified. 129101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool isMutable() const; 129201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 129301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Determine whether this lambda has an explicit parameter 129401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// list vs. an implicit (empty) parameter list. 129501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool hasExplicitParameters() const { return ExplicitParams; } 129601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1297dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Whether this lambda had its result type explicitly specified. 1298dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool hasExplicitResultType() const { return ExplicitResultType; } 1299dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 130001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const Stmt *T) { 130101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return T->getStmtClass() == LambdaExprClass; 130201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 130301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor static bool classof(const LambdaExpr *) { return true; } 130401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 130501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange getSourceRange() const { 130601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor return SourceRange(IntroducerRange.getBegin(), ClosingBrace); 130701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor } 130801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 13097ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor child_range children() { 13107ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 13117ae282fde0a12635893931ebf31b35b0d5d5cab3Douglas Gregor } 131201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 131301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtReader; 131401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor friend class ASTStmtWriter; 131501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor}; 131601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 1317ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1318506ae418eb171d072f2fb4f6bc46d258b52cbf97Douglas Gregor/// Expression "T()" which creates a value-initialized rvalue of type 1319ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor/// T, which is a non-class type. 1320987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis/// 1321ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregorclass CXXScalarValueInitExpr : public Expr { 1322987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis SourceLocation RParenLoc; 1323ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo; 1324987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 1325ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 1326ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1327987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidispublic: 1328ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Create an explicitly-written scalar-value initialization 1329ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// expression. 1330ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr(QualType Type, 1331ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *TypeInfo, 1332ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation rParenLoc ) : 1333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1334561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, Type->isInstantiationDependentType(), false), 1335ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1336ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 1337ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor explicit CXXScalarValueInitExpr(EmptyShell Shell) 1338ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor : Expr(CXXScalarValueInitExprClass, Shell) { } 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1340ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 1341ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return TypeInfo; 13424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 1343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1344ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 13454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 134663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1349ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor return T->getStmtClass() == CXXScalarValueInitExprClass; 1350987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis } 1351ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor static bool classof(const CXXScalarValueInitExpr *) { return true; } 13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1353987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis // Iterators 135463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1355987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis}; 1356987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis 13574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXNewExpr - A new expression for memory allocation and constructor calls, 13584c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// e.g: "new CXXNewExpr(foo)". 13594c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXNewExpr : public Expr { 13604c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Was the usage ::new, i.e. is the global new to be used? 13614c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalNew : 1; 13621548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // Is there an initializer? If not, built-ins are uninitialized, else they're 13631548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // value-initialized. 13641548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl bool Initializer : 1; 1365cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl // Do we allocate an array? If so, the first SubExpr is the size expression. 1366cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool Array : 1; 13676ec278d1a354517e20f13a877481453ee7940c78John McCall // If this is an array allocation, does the usual deallocation 13686ec278d1a354517e20f13a877481453ee7940c78John McCall // function for the allocated type want to know the allocated size? 13696ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 13701548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // Whether the referred constructor (if any) was resolved from an 13711548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // overload set having size greater than 1. 13721548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl bool HadMultipleCandidates : 1; 13734c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // The number of placement new arguments. 13747cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara unsigned NumPlacementArgs : 13; 13751548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // The number of constructor arguments. This may be 1 even for non-class 13761548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // types; use the pseudo copy constructor. 13771548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl unsigned NumConstructorArgs : 14; 13781548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // Contains an optional array size expression, any number of optional 13791548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // placement arguments, and any number of optional constructor arguments, 13801548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // in that order. 13814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt **SubExprs; 13824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the allocation function used. 13834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorNew; 13844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the deallocation function used in case of error. May be null. 13854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 13861548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // Points to the constructor used. Cannot be null if AllocType is a record; 13871548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // it would still point at the default constructor (even an implicit one). 13881548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl // Must be null for all other types. 13891548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl CXXConstructorDecl *Constructor; 13904c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 13911bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor /// \brief The allocated type-source information, as written in the source. 13921bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo; 1393ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1394ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the allocated type was expressed as a parenthesized type-id, 13954bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor /// the source range covering the parenthesized type-id. 13964bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange TypeIdParens; 1397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SourceLocation StartLoc; 13991548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation EndLoc; 14001548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation ConstructorLParen; 14011548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation ConstructorRParen; 14024c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 140360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 14044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 1405ad7fe864862305c2f71e047cdf6706ef43aebdc0Ted Kremenek CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 14065f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl Expr **placementArgs, unsigned numPlaceArgs, 14071548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceRange TypeIdParens, 14081548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl Expr *arraySize, CXXConstructorDecl *constructor, bool initializer, 14091548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl Expr **constructorArgs, unsigned numConsArgs, 14101548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl bool HadMultipleCandidates, 14111548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 14126ec278d1a354517e20f13a877481453ee7940c78John McCall QualType ty, TypeSourceInfo *AllocatedTypeInfo, 14131548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation startLoc, SourceLocation endLoc, 14141548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation constructorLParen, 14151548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation constructorRParen); 14165921863d8f24084797863b5df37842113bac4352Chris Lattner explicit CXXNewExpr(EmptyShell Shell) 14175921863d8f24084797863b5df37842113bac4352Chris Lattner : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 14185921863d8f24084797863b5df37842113bac4352Chris Lattner 14195921863d8f24084797863b5df37842113bac4352Chris Lattner void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 14201548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl unsigned numConsArgs); 1421ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1422cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl QualType getAllocatedType() const { 1423cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl assert(getType()->isPointerType()); 14246217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<PointerType>()->getPointeeType(); 1425cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 14264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *getAllocatedTypeSourceInfo() const { 14281bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor return AllocatedTypeInfo; 14291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor } 1430c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall 1431c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// \brief True if the allocation result needs to be null-checked. 1432c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// C++0x [expr.new]p13: 1433c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// If the allocation function returns null, initialization shall 1434c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// not be done, the deallocation function shall not be called, 1435c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// and the value of the new-expression shall be null. 1436c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// An allocation function is not allowed to return null unless it 1437c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// has a non-throwing exception-specification. The '03 rule is 1438c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// identical except that the definition of a non-throwing 1439c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall /// exception specification is just "is it throw()?". 14408026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1441ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorNew() const { return OperatorNew; } 14435921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 14444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 14455921863d8f24084797863b5df37842113bac4352Chris Lattner void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 14461548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl CXXConstructorDecl *getConstructor() const { return Constructor; } 14471548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl void setConstructor(CXXConstructorDecl *D) { Constructor = D; } 14484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1449cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl bool isArray() const { return Array; } 1450cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl Expr *getArraySize() { 1451cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1452cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1453cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl const Expr *getArraySize() const { 1454cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl return Array ? cast<Expr>(SubExprs[0]) : 0; 1455cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl } 1456cee63fbf0e64ac526582312bf8cf33263fc5c16eSebastian Redl 14574c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1458ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Expr **getPlacementArgs() { 14591548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return reinterpret_cast<Expr **>(SubExprs + Array); 1460aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 1461ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getPlacementArg(unsigned i) { 14634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 14641548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return cast<Expr>(SubExprs[Array + i]); 14654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 14664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getPlacementArg(unsigned i) const { 14674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl assert(i < NumPlacementArgs && "Index out of range"); 14681548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return cast<Expr>(SubExprs[Array + i]); 14694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 14704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14714bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor bool isParenTypeId() const { return TypeIdParens.isValid(); } 14724bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor SourceRange getTypeIdParens() const { return TypeIdParens; } 14734bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor 14744c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalNew() const { return GlobalNew; } 14751548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl bool hasInitializer() const { return Initializer; } 14764c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 14775f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl /// Answers whether the usual array deallocation function for the 14785f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl /// allocated type expects the size of the allocation as a 14795f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl /// parameter. 14805f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl bool doesUsualArrayDeleteWantSize() const { 14815f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl return UsualArrayDeleteWantsSize; 14825f688f4b15d02aa7ad159c46b1f78fe59d412f12Sebastian Redl } 14837cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 14841548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 14851548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14861548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl Expr **getConstructorArgs() { 14871548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs); 14881548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14891548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14901548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl Expr *getConstructorArg(unsigned i) { 14911548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl assert(i < NumConstructorArgs && "Index out of range"); 14921548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 14931548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14941548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl const Expr *getConstructorArg(unsigned i) const { 14951548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl assert(i < NumConstructorArgs && "Index out of range"); 14961548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 14971548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 14981548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 14991548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl /// \brief Whether the new expression refers a constructor that was 15001548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl /// resolved from an overloaded set having size greater than 1. 15011548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl bool hadMultipleCandidates() const { return HadMultipleCandidates; } 15021548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 15031548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 15044c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ExprIterator arg_iterator; 15054c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef ConstExprIterator const_arg_iterator; 15064c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15074c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_begin() { 15081548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array; 15094c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl arg_iterator placement_arg_end() { 15111548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs(); 15124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_begin() const { 15141548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array; 15154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const_arg_iterator placement_arg_end() const { 15171548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs(); 15181548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15191548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl 15201548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl arg_iterator constructor_arg_begin() { 15211548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs(); 15221548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15231548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl arg_iterator constructor_arg_end() { 15241548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 15251548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15261548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl const_arg_iterator constructor_arg_begin() const { 15271548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs(); 15281548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl } 15291548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl const_arg_iterator constructor_arg_end() const { 15301548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 15314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 1532ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15335921863d8f24084797863b5df37842113bac4352Chris Lattner typedef Stmt **raw_arg_iterator; 15345921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_begin() { return SubExprs; } 15355921863d8f24084797863b5df37842113bac4352Chris Lattner raw_arg_iterator raw_arg_end() { 15361548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 15375921863d8f24084797863b5df37842113bac4352Chris Lattner } 15385921863d8f24084797863b5df37842113bac4352Chris Lattner const_arg_iterator raw_arg_begin() const { return SubExprs; } 15391548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } 15404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15415921863d8f24084797863b5df37842113bac4352Chris Lattner SourceLocation getStartLoc() const { return StartLoc; } 15421548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation getEndLoc() const { return EndLoc; } 1543428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 15441548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation getConstructorLParen() const { return ConstructorLParen; } 15451548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl SourceLocation getConstructorRParen() const { return ConstructorRParen; } 1546428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth 154763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15481548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return SourceRange(StartLoc, EndLoc); 15494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 15524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXNewExprClass; 15534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 15544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const CXXNewExpr *) { return true; } 15554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 155763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 15581548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl return child_range(&SubExprs[0], 15591548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl &SubExprs[0] + Array + getNumPlacementArgs() 15601548d14f4092a817f7d90ad3e7a65266dc85fbc5Sebastian Redl + getNumConstructorArgs()); 156163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 15624c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 15634c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15644c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 15654c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl/// calls, e.g. "delete[] pArray". 15664c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlclass CXXDeleteExpr : public Expr { 15674c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this a forced global delete, i.e. "::delete"? 15684c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool GlobalDelete : 1; 15694c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Is this the array form of delete, i.e. "delete[]"? 15704c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool ArrayForm : 1; 15714076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 15724076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 15734076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis // will be true). 15744076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool ArrayFormAsWritten : 1; 15756ec278d1a354517e20f13a877481453ee7940c78John McCall // Does the usual deallocation function for the element type require 15766ec278d1a354517e20f13a877481453ee7940c78John McCall // a size_t argument? 15776ec278d1a354517e20f13a877481453ee7940c78John McCall bool UsualArrayDeleteWantsSize : 1; 15784c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Points to the operator delete overload that is used. Could be a member. 15794c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *OperatorDelete; 15804c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // The pointer expression to be deleted. 15814c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Stmt *Argument; 15824c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Location of the expression. 15834c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl SourceLocation Loc; 15844c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlpublic: 15854c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 15866ec278d1a354517e20f13a877481453ee7940c78John McCall bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 15876ec278d1a354517e20f13a877481453ee7940c78John McCall FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1588bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1589561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor arg->isInstantiationDependent(), 1590bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor arg->containsUnexpandedParameterPack()), 1591f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall GlobalDelete(globalDelete), 15924076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 15936ec278d1a354517e20f13a877481453ee7940c78John McCall UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), 15944076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 159595fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis explicit CXXDeleteExpr(EmptyShell Shell) 159695fc98ce95d4faa4f1bb2783384150530404ea6fArgyrios Kyrtzidis : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 15974c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 15984c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isGlobalDelete() const { return GlobalDelete; } 15994c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl bool isArrayForm() const { return ArrayForm; } 16004076dacf1497fb95cb298b9d964fbdbdaf9bde6cArgyrios Kyrtzidis bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 16014c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16026ec278d1a354517e20f13a877481453ee7940c78John McCall /// Answers whether the usual array deallocation function for the 16036ec278d1a354517e20f13a877481453ee7940c78John McCall /// allocated type expects the size of the allocation as a 16046ec278d1a354517e20f13a877481453ee7940c78John McCall /// parameter. This can be true even if the actual deallocation 16056ec278d1a354517e20f13a877481453ee7940c78John McCall /// function that we're using doesn't want a size. 16066ec278d1a354517e20f13a877481453ee7940c78John McCall bool doesUsualArrayDeleteWantSize() const { 16076ec278d1a354517e20f13a877481453ee7940c78John McCall return UsualArrayDeleteWantsSize; 16086ec278d1a354517e20f13a877481453ee7940c78John McCall } 16096ec278d1a354517e20f13a877481453ee7940c78John McCall 16104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 16114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl Expr *getArgument() { return cast<Expr>(Argument); } 16134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const Expr *getArgument() const { return cast<Expr>(Argument); } 16144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1615a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// \brief Retrieve the type being destroyed. If the type being 1616a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// destroyed is a dependent type which may or may not be a pointer, 1617a437ad3ec5b407ede394d74e6f9f463fa3657dbeCraig Silverstein /// return an invalid type. 16185833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType getDestroyedType() const; 1619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 162063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 16214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return SourceRange(Loc, Argument->getLocEnd()); 16224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const Stmt *T) { 16254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl return T->getStmtClass() == CXXDeleteExprClass; 16264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 16274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl static bool classof(const CXXDeleteExpr *) { return true; } 16284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 16294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Iterators 163063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Argument, &Argument+1); } 1631f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis 1632f1b8911d35bb2830a13267581d3cbde4b6b85db6Argyrios Kyrtzidis friend class ASTStmtReader; 16334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 16344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 1635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Structure used to store the type being destroyed by a 1636a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor/// pseudo-destructor expression. 1637a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorclass PseudoDestructorTypeStorage { 1638ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Either the type source information or the name of the type, if 1639a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// it couldn't be resolved due to type-dependence. 1640a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1641ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1642a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief The starting source location of the pseudo-destructor type. 1643a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation Location; 1644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1645a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregorpublic: 1646a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage() { } 1647ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1648a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1649a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor : Type(II), Location(Loc) { } 1650ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1651a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getTypeSourceInfo() const { 1654ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return Type.dyn_cast<TypeSourceInfo *>(); 1655a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1656ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1657a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getIdentifier() const { 1658a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return Type.dyn_cast<IdentifierInfo *>(); 1659a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1660ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1661a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SourceLocation getLocation() const { return Location; } 1662a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor}; 1663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1664a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1665a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1666e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// A pseudo-destructor is an expression that looks like a member access to a 1667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// destructor of a scalar type, except that scalar types don't have 1668e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// destructors. For example: 1669e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// 1670e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \code 1671e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// typedef int T; 1672e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// void f(int *p) { 1673e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// p->T::~T(); 1674e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// } 1675e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// \endcode 1676a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1677e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// Pseudo-destructors typically occur when instantiating templates such as: 1678ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// 1679a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \code 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T> 1681a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// void destroy(T* ptr) { 1682e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// ptr->T::~T(); 1683a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// } 1684a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// \endcode 1685a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor/// 1686e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// for scalar types. A pseudo-destructor expression has no run-time semantics 1687e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor/// beyond evaluating the base expression. 1688a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorclass CXXPseudoDestructorExpr : public Expr { 1689a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The base expression (that is being destroyed). 1690a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Stmt *Base; 16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1692a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1693a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// period ('.'). 1694a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool IsArrow : 1; 16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1696a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The location of the '.' or '->' operator. 1697a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation OperatorLoc; 1698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1699a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief The nested-name-specifier that follows the operator, if present. 1700f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 17011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1702e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1703e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1704e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType; 1705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1706ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The location of the '::' in a qualified pseudo-destructor 1707e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1708e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc; 1709ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1710fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief The location of the '~'. 1711fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc; 1712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief The type being destroyed, or its name if we were unable to 1714a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// resolve the name. 1715a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage DestroyedType; 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1717f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor friend class ASTStmtReader; 1718ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1719a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregorpublic: 1720a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor CXXPseudoDestructorExpr(ASTContext &Context, 1721a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1722f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1723e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor TypeSourceInfo *ScopeType, 1724e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation ColonColonLoc, 1725fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 1726e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall PseudoDestructorTypeStorage DestroyedType); 17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1728de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1729de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis : Expr(CXXPseudoDestructorExprClass, Shell), 1730f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1731de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1732a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Expr *getBase() const { return cast<Expr>(Base); } 17331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 1735a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 1736a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// x->Base::foo. 1737f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool hasQualifier() const { return QualifierLoc; } 17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1739f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1740f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor /// with source-location information. 1741f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 1744a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 1745a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// NULL. 1746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 1747ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 1748f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor } 17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1750a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Determine whether this pseudo-destructor expression was written 1751a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// using an '->' (otherwise, it used a '.'). 1752a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool isArrow() const { return IsArrow; } 1753a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor 1754a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Retrieve the location of the '.' or '->' operator. 1755a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 17561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the scope type in a qualified pseudo-destructor 1758e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1759e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// 1760e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Pseudo-destructor expressions can have extra qualification within them 1761e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1762e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// Here, if the object type of the expression is (or may be) a scalar type, 1763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \p T may also be a scalar type and, therefore, cannot be part of a 1764e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1765e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// destructor expression. 176626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1767ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1768e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1769e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor /// expression. 1770e0601ea1220348957dacec5f3dd0707837365290Douglas Gregor SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1772fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor /// \brief Retrieve the location of the '~'. 1773fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation getTildeLoc() const { return TildeLoc; } 1774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 177526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// \brief Retrieve the source location information for the type 177626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /// being destroyed. 1777a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// 1778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This type-source information is available for non-dependent 1779a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// pseudo-destructor expressions and some dependent pseudo-destructor 1780a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// expressions. Returns NULL if we only have the identifier for a 1781a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// dependent pseudo-destructor expression. 1782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *getDestroyedTypeInfo() const { 1783ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getTypeSourceInfo(); 1784a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1786a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief In a dependent pseudo-destructor expression for which we do not 1787a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// have full type information on the destroyed type, provides the name 1788a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// of the destroyed type. 1789a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor IdentifierInfo *getDestroyedTypeIdentifier() const { 1790a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor return DestroyedType.getIdentifier(); 1791a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 1792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1793a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the type being destroyed. 1794a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor QualType getDestroyedType() const; 1795ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1796a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /// \brief Retrieve the starting location of the type being destroyed. 1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation getDestroyedTypeLoc() const { 1798ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return DestroyedType.getLocation(); 1799a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1801de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1802de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// expression. 1803de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1804de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1805de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1806de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 1807de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis /// \brief Set the destroyed type. 1808de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis void setDestroyedType(TypeSourceInfo *Info) { 1809de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis DestroyedType = PseudoDestructorTypeStorage(Info); 1810de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis } 1811de4bd18bb45a1db68996cfb949db3015fc25d10dArgyrios Kyrtzidis 181263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 18131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1815a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor return T->getStmtClass() == CXXPseudoDestructorExprClass; 1816a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 1817a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor static bool classof(const CXXPseudoDestructorExpr *) { return true; } 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1819a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor // Iterators 182063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base + 1); } 1821a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor}; 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 182464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// implementation of TR1/C++0x type trait templates. 182564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// Example: 182664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_pod(int) == true 182764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// __is_enum(std::string) == false 182864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlclass UnaryTypeTraitExpr : public Expr { 18290dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 18300dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl unsigned UTT : 31; 18310dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The value of the type trait. Unspecified if dependent. 18320dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool Value : 1; 183364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 183464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// Loc - The location of the type trait keyword. 183564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation Loc; 183664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 183764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// RParen - The location of the closing paren. 183864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation RParen; 183964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18400dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl /// The type being queried. 18413d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *QueriedType; 184264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 184364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlpublic: 1844ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 18450dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl TypeSourceInfo *queried, bool value, 184664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl SourceLocation rparen, QualType ty) 1847f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1848bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor false, queried->getType()->isDependentType(), 1849561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->getType()->isInstantiationDependentType(), 1850bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor queried->getType()->containsUnexpandedParameterPack()), 18510dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 185264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18536d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis explicit UnaryTypeTraitExpr(EmptyShell Empty) 18540dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 18553d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QueriedType() { } 18566d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 185763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 185864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18590dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 186064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18613d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor QualType getQueriedType() const { return QueriedType->getType(); } 186264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18633d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18650dfd848fa4c9664852ba8c929a8bd3fce93ddca2Sebastian Redl bool getValue() const { return Value; } 186664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 186764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const Stmt *T) { 186864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return T->getStmtClass() == UnaryTypeTraitExprClass; 186964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 187064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl static bool classof(const UnaryTypeTraitExpr *) { return true; } 187164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 187264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Iterators 187363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 18746d00c1365dd3601f6d93bbda9162913c57ae788fArgyrios Kyrtzidis 187560adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 187664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl}; 187764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 18786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the 18796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// implementation of TR1/C++0x type trait templates. 18806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// Example: 18816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet/// __is_base_of(Base, Derived) == true 18826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetclass BinaryTypeTraitExpr : public Expr { 18836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 18846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet unsigned BTT : 8; 18856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The value of the type trait. Unspecified if dependent. 18876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool Value : 1; 18886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Loc - The location of the type trait keyword. 18906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation Loc; 18916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// RParen - The location of the closing paren. 18936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParen; 18946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The lhs type being queried. 18966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsType; 18976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 18986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// The rhs type being queried. 18996ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsType; 19006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichetpublic: 1902ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1903ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 19046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool value, SourceLocation rparen, QualType ty) 1905ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 19066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet lhsType->getType()->isDependentType() || 1907bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->isDependentType(), 1908561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhsType->getType()->isInstantiationDependentType() || 1909561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhsType->getType()->isInstantiationDependentType()), 1910bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhsType->getType()->containsUnexpandedParameterPack() || 1911bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhsType->getType()->containsUnexpandedParameterPack())), 19126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BTT(btt), Value(value), Loc(loc), RParen(rparen), 19136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsType(lhsType), RhsType(rhsType) { } 19146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet explicit BinaryTypeTraitExpr(EmptyShell Empty) 19176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1918f187237d916afa97c491ac32fe98be7d335c5b63Francois Pichet LhsType(), RhsType() { } 19196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 192063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 19216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SourceRange(Loc, RParen); 19226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19236ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19246ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet BinaryTypeTrait getTrait() const { 19256ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return static_cast<BinaryTypeTrait>(BTT); 19266ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19276ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getLhsType() const { return LhsType->getType(); } 19296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet QualType getRhsType() const { return RhsType->getType(); } 19306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 19326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 1933ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet bool getValue() const { assert(!isTypeDependent()); return Value; } 19356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const Stmt *T) { 19376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return T->getStmtClass() == BinaryTypeTraitExprClass; 19386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet static bool classof(const BinaryTypeTraitExpr *) { return true; } 19406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet // Iterators 194263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 19436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 19446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet friend class ASTStmtReader; 19456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet}; 19466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 194721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the 194821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// implementation of __array_rank and __array_extent. 194921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// Example: 195021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_rank(int[10][20]) == 2 195121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley/// __array_extent(int, 1) == 20 195221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleyclass ArrayTypeTraitExpr : public Expr { 195399ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 195499ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 195521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 195621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley unsigned ATT : 2; 195721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 195821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The value of the type trait. Unspecified if dependent. 195921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t Value; 196021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The array dimension being queried, or -1 if not used 196221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *Dimension; 196321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Loc - The location of the type trait keyword. 196521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation Loc; 196621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 196721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// RParen - The location of the closing paren. 196821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParen; 196921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// The type being queried. 197121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *QueriedType; 197221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 197321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleypublic: 197421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 197521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *queried, uint64_t value, 197621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *dimension, SourceLocation rparen, QualType ty) 197721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 197821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley false, queried->getType()->isDependentType(), 1979561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (queried->getType()->isInstantiationDependentType() || 1980561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (dimension && dimension->isInstantiationDependent())), 198121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley queried->getType()->containsUnexpandedParameterPack()), 198221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ATT(att), Value(value), Dimension(dimension), 198321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Loc(loc), RParen(rparen), QueriedType(queried) { } 198421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 198521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 198621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley explicit ArrayTypeTraitExpr(EmptyShell Empty) 198721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 198821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QueriedType() { } 198921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 199025aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek virtual ~ArrayTypeTraitExpr() { } 199125aaf28c5bec71d5d005df67ee78b908ba5940f4Manuel Klimek 1992ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie virtual SourceRange getSourceRange() const { 1993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return SourceRange(Loc, RParen); 1994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 199521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 199621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 199721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 199821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley QualType getQueriedType() const { return QueriedType->getType(); } 199921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 200021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 200121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 200221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 200321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 200421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *getDimensionExpression() const { return Dimension; } 200521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 200621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const Stmt *T) { 200721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return T->getStmtClass() == ArrayTypeTraitExprClass; 200821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 200921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley static bool classof(const ArrayTypeTraitExpr *) { return true; } 201021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 201121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley // Iterators 201221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley child_range children() { return child_range(); } 201321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 201421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley friend class ASTStmtReader; 201521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley}; 201621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2017552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// ExpressionTraitExpr - An expression trait intrinsic 2018552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// Example: 2019552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(std::cout) == true 2020552622067dc45013d240f73952fece703f5e63bdJohn Wiegley/// __is_lvalue_expr(1) == false 2021552622067dc45013d240f73952fece703f5e63bdJohn Wiegleyclass ExpressionTraitExpr : public Expr { 2022552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned. 2023552622067dc45013d240f73952fece703f5e63bdJohn Wiegley unsigned ET : 31; 2024552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// The value of the type trait. Unspecified if dependent. 2025552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool Value : 1; 2026552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2027552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Loc - The location of the type trait keyword. 2028552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation Loc; 2029552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2030552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// RParen - The location of the closing paren. 2031552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParen; 2032552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2033552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr* QueriedExpression; 2034552622067dc45013d240f73952fece703f5e63bdJohn Wiegleypublic: 2035ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2036552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *queried, bool value, 2037552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation rparen, QualType resultType) 2038552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2039552622067dc45013d240f73952fece703f5e63bdJohn Wiegley false, // Not type-dependent 2040552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Value-dependent if the argument is type-dependent. 2041552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->isTypeDependent(), 2042561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor queried->isInstantiationDependent(), 2043552622067dc45013d240f73952fece703f5e63bdJohn Wiegley queried->containsUnexpandedParameterPack()), 2044ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ET(et), Value(value), Loc(loc), RParen(rparen), 2045ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie QueriedExpression(queried) { } 2046552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2047552622067dc45013d240f73952fece703f5e63bdJohn Wiegley explicit ExpressionTraitExpr(EmptyShell Empty) 2048552622067dc45013d240f73952fece703f5e63bdJohn Wiegley : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2049552622067dc45013d240f73952fece703f5e63bdJohn Wiegley QueriedExpression() { } 2050552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2051552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 2052552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2053552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2054552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2055552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *getQueriedExpression() const { return QueriedExpression; } 2056552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2057552622067dc45013d240f73952fece703f5e63bdJohn Wiegley bool getValue() const { return Value; } 2058552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2059552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const Stmt *T) { 2060552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return T->getStmtClass() == ExpressionTraitExprClass; 2061552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2062552622067dc45013d240f73952fece703f5e63bdJohn Wiegley static bool classof(const ExpressionTraitExpr *) { return true; } 2063552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2064552622067dc45013d240f73952fece703f5e63bdJohn Wiegley // Iterators 2065552622067dc45013d240f73952fece703f5e63bdJohn Wiegley child_range children() { return child_range(); } 2066552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2067552622067dc45013d240f73952fece703f5e63bdJohn Wiegley friend class ASTStmtReader; 2068552622067dc45013d240f73952fece703f5e63bdJohn Wiegley}; 2069552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 2070552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20717bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to an overloaded function set, either an 20727bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 20737bb12da2b0749eeebb21854c77877736969e59f2John McCallclass OverloadExpr : public Expr { 2074ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// The results. These are undesugared, which is to say, they may 20757bb12da2b0749eeebb21854c77877736969e59f2John McCall /// include UsingShadowDecls. Access is relative to the naming 20767bb12da2b0749eeebb21854c77877736969e59f2John McCall /// class. 2077928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor // FIXME: Allocate this data after the OverloadExpr subclass. 2078928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor DeclAccessPair *Results; 2079928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned NumResults; 2080ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 20817bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The common name of these declarations. 20822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo; 2083ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 20844c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor /// \brief The nested-name-specifier that qualifies the name, if any. 20854c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 2086ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2087a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidisprotected: 2088e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2089e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2090e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2091e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2092e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2093e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2094e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2095e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2096e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2097e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2098e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 20997bb12da2b0749eeebb21854c77877736969e59f2John McCall 2100bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor OverloadExpr(StmtClass K, ASTContext &C, 21014c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2102e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 21032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2104bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2105bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2106561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownDependent, 2107561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownInstantiationDependent, 2108561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool KnownContainsUnexpandedParameterPack); 21097bb12da2b0749eeebb21854c77877736969e59f2John McCall 2110a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis OverloadExpr(StmtClass K, EmptyShell Empty) 2111a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : Expr(K, Empty), Results(0), NumResults(0), 2112e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara QualifierLoc(), HasTemplateKWAndArgsInfo(false) { } 2113a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 2114bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeResults(ASTContext &C, 2115bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator Begin, 2116bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedSetIterator End); 21177bb12da2b0749eeebb21854c77877736969e59f2John McCall 2118bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic: 21199c72c6088d591ace8503b842d39448c2040f3033John McCall struct FindResult { 21209c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Expression; 21219c72c6088d591ace8503b842d39448c2040f3033John McCall bool IsAddressOfOperand; 21229c72c6088d591ace8503b842d39448c2040f3033John McCall bool HasFormOfMemberPointer; 21239c72c6088d591ace8503b842d39448c2040f3033John McCall }; 21249c72c6088d591ace8503b842d39448c2040f3033John McCall 21257bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Finds the overloaded expression in the given expression of 21267bb12da2b0749eeebb21854c77877736969e59f2John McCall /// OverloadTy. 21277bb12da2b0749eeebb21854c77877736969e59f2John McCall /// 21289c72c6088d591ace8503b842d39448c2040f3033John McCall /// \return the expression (which must be there) and true if it has 21299c72c6088d591ace8503b842d39448c2040f3033John McCall /// the particular form of a member pointer expression 21309c72c6088d591ace8503b842d39448c2040f3033John McCall static FindResult find(Expr *E) { 21317bb12da2b0749eeebb21854c77877736969e59f2John McCall assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 21327bb12da2b0749eeebb21854c77877736969e59f2John McCall 21339c72c6088d591ace8503b842d39448c2040f3033John McCall FindResult Result; 21349c72c6088d591ace8503b842d39448c2040f3033John McCall 21357bb12da2b0749eeebb21854c77877736969e59f2John McCall E = E->IgnoreParens(); 21369c72c6088d591ace8503b842d39448c2040f3033John McCall if (isa<UnaryOperator>(E)) { 21379c72c6088d591ace8503b842d39448c2040f3033John McCall assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 21389c72c6088d591ace8503b842d39448c2040f3033John McCall E = cast<UnaryOperator>(E)->getSubExpr(); 21399c72c6088d591ace8503b842d39448c2040f3033John McCall OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 21409c72c6088d591ace8503b842d39448c2040f3033John McCall 21419c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 21429c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = true; 21439c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = Ovl; 21449c72c6088d591ace8503b842d39448c2040f3033John McCall } else { 21459c72c6088d591ace8503b842d39448c2040f3033John McCall Result.HasFormOfMemberPointer = false; 21469c72c6088d591ace8503b842d39448c2040f3033John McCall Result.IsAddressOfOperand = false; 21479c72c6088d591ace8503b842d39448c2040f3033John McCall Result.Expression = cast<OverloadExpr>(E); 21489c72c6088d591ace8503b842d39448c2040f3033John McCall } 21499c72c6088d591ace8503b842d39448c2040f3033John McCall 21509c72c6088d591ace8503b842d39448c2040f3033John McCall return Result; 21517bb12da2b0749eeebb21854c77877736969e59f2John McCall } 21527bb12da2b0749eeebb21854c77877736969e59f2John McCall 2153e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall /// Gets the naming class of this lookup, if any. 2154e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall CXXRecordDecl *getNamingClass() const; 2155e9ee23edd17c4bb7f271e67f8790792b4de677fcJohn McCall 21567bb12da2b0749eeebb21854c77877736969e59f2John McCall typedef UnresolvedSetImpl::iterator decls_iterator; 2157928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2158ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie decls_iterator decls_end() const { 2159928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor return UnresolvedSetIterator(Results + NumResults); 2160928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor } 2161ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21627bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the number of declarations in the unresolved set. 2163928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor unsigned getNumDecls() const { return NumResults; } 21647bb12da2b0749eeebb21854c77877736969e59f2John McCall 21652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Gets the full name info. 21662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 21672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 21687bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the name looked up. 21692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return NameInfo.getName(); } 21707bb12da2b0749eeebb21854c77877736969e59f2John McCall 21717bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Gets the location of the name. 21722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 21737bb12da2b0749eeebb21854c77877736969e59f2John McCall 21747bb12da2b0749eeebb21854c77877736969e59f2John McCall /// Fetches the nested-name qualifier, if one was given. 2175ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2176ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 21774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor } 21787bb12da2b0749eeebb21854c77877736969e59f2John McCall 2179ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// Fetches the nested-name qualifier with source-location information, if 21804c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor /// one was given. 21814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 21827bb12da2b0749eeebb21854c77877736969e59f2John McCall 2183e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2184e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2185e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2186e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2187e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2188e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2189e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2190e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2191e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2192e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2193e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2194e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2195e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2196e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2197e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2198e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2199e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2200e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2201e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2202e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 22037bb12da2b0749eeebb21854c77877736969e59f2John McCall 2204e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2205e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2206e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2207e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether this expression had explicit template arguments. 2208e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2209e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2210e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // Note that, inconsistently with the explicit-template-argument AST 2211e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // nodes, users are *forbidden* from calling these methods on objects 2212e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // without explicit template arguments. 2213e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2214e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2215e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2216e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2217e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 22187bb12da2b0749eeebb21854c77877736969e59f2John McCall 2219b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 22207bb12da2b0749eeebb21854c77877736969e59f2John McCall return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 22217bb12da2b0749eeebb21854c77877736969e59f2John McCall } 22227bb12da2b0749eeebb21854c77877736969e59f2John McCall 2223e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgumentLoc const *getTemplateArgs() const { 2224e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().getTemplateArgs(); 2225e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2226e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2227e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara unsigned getNumTemplateArgs() const { 2228e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getExplicitTemplateArgs().NumTemplateArgs; 2229e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2230e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2231e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Copies the template arguments into the given structure. 2232e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2233e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getExplicitTemplateArgs().copyInto(List); 2234e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2235e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2236096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2237096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2238096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2239b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2240096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2241096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 22427bb12da2b0749eeebb21854c77877736969e59f2John McCall } 22437bb12da2b0749eeebb21854c77877736969e59f2John McCall 22447bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const Stmt *T) { 22457bb12da2b0749eeebb21854c77877736969e59f2John McCall return T->getStmtClass() == UnresolvedLookupExprClass || 22467bb12da2b0749eeebb21854c77877736969e59f2John McCall T->getStmtClass() == UnresolvedMemberExprClass; 22477bb12da2b0749eeebb21854c77877736969e59f2John McCall } 22487bb12da2b0749eeebb21854c77877736969e59f2John McCall static bool classof(const OverloadExpr *) { return true; } 22494045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 22504045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 22514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 22527bb12da2b0749eeebb21854c77877736969e59f2John McCall}; 22537bb12da2b0749eeebb21854c77877736969e59f2John McCall 22547bb12da2b0749eeebb21854c77877736969e59f2John McCall/// \brief A reference to a name which we were able to look up during 22557bb12da2b0749eeebb21854c77877736969e59f2John McCall/// parsing but could not resolve to a specific declaration. This 22567bb12da2b0749eeebb21854c77877736969e59f2John McCall/// arises in several ways: 22577bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * we might be waiting for argument-dependent lookup 22587bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the name might resolve to an overloaded function 22597bb12da2b0749eeebb21854c77877736969e59f2John McCall/// and eventually: 22607bb12da2b0749eeebb21854c77877736969e59f2John McCall/// * the lookup might have included a function template 22617bb12da2b0749eeebb21854c77877736969e59f2John McCall/// These never include UnresolvedUsingValueDecls, which are always 22627bb12da2b0749eeebb21854c77877736969e59f2John McCall/// class members and therefore appear only in 22637bb12da2b0749eeebb21854c77877736969e59f2John McCall/// UnresolvedMemberLookupExprs. 22647bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedLookupExpr : public OverloadExpr { 2265ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if these lookup results should be extended by 2266ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup if this is the operand of a function 2267ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// call. 2268ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool RequiresADL; 2269ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2270ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// True if namespace ::std should be considered an associated namespace 2271ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1. 2272ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace; 2273ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 22747453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if these lookup results are overloaded. This is pretty 22757453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// trivially rederivable if we urgently need to kill this field. 22767453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool Overloaded; 22777453ed4cb2cab113de3378df371b1c6f1243d832John McCall 22787bb12da2b0749eeebb21854c77877736969e59f2John McCall /// The naming class (C++ [class.access.base]p5) of the lookup, if 22797bb12da2b0749eeebb21854c77877736969e59f2John McCall /// any. This can generally be recalculated from the context chain, 22807bb12da2b0749eeebb21854c77877736969e59f2John McCall /// but that can be fairly expensive for unqualified lookups. If we 22817bb12da2b0749eeebb21854c77877736969e59f2John McCall /// want to improve memory use here, this could go in a union 22827bb12da2b0749eeebb21854c77877736969e59f2John McCall /// against the qualified-lookup bits. 22837bb12da2b0749eeebb21854c77877736969e59f2John McCall CXXRecordDecl *NamingClass; 2284f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2285ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedLookupExpr(ASTContext &C, 2286928e6fcf66fc4f342bcf7cc96bf56986c9c2a833Douglas Gregor CXXRecordDecl *NamingClass, 22874c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2288e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 22892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2290ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool RequiresADL, bool Overloaded, 2291bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *TemplateArgs, 2292ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2293ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace) 2294e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2295e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara NameInfo, TemplateArgs, Begin, End, false, false, false), 2296ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(RequiresADL), 2297ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StdIsAssociatedNamespace(StdIsAssociatedNamespace), 2298ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Overloaded(Overloaded), NamingClass(NamingClass) 2299ba13543329afac4a0d01304ec2ec4924d99306a6John McCall {} 2300ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2301bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis UnresolvedLookupExpr(EmptyShell Empty) 2302bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis : OverloadExpr(UnresolvedLookupExprClass, Empty), 2303ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false), 2304ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NamingClass(0) 2305bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis {} 2306bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 23074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 2308ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2309ba13543329afac4a0d01304ec2ec4924d99306a6John McCallpublic: 2310ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2311c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 23124c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 23132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 23145a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor bool ADL, bool Overloaded, 2315ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 2316ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith UnresolvedSetIterator End, 2317ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool StdIsAssociatedNamespace = false) { 2318ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert((ADL || !StdIsAssociatedNamespace) && 2319ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith "std considered associated namespace when not performing ADL"); 2320e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation(), NameInfo, 2322ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ADL, Overloaded, 0, Begin, End, 2323ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StdIsAssociatedNamespace); 2324ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2325ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2326f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static UnresolvedLookupExpr *Create(ASTContext &C, 2327c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *NamingClass, 23284c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2329e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 23302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2331f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool ADL, 23329d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *Args, 2333ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie UnresolvedSetIterator Begin, 23345a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator End); 2335f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2336bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2337e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 2338bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis unsigned NumTemplateArgs); 2339bd65bb511c26549c96b829c1282e4c877588564aArgyrios Kyrtzidis 2340ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// True if this declaration should be extended by 2341ba13543329afac4a0d01304ec2ec4924d99306a6John McCall /// argument-dependent lookup. 2342ba13543329afac4a0d01304ec2ec4924d99306a6John McCall bool requiresADL() const { return RequiresADL; } 2343ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2344ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// True if namespace ::std should be artificially added to the set of 2345ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// associated namespaecs for argument-dependent lookup purposes. 2346ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; } 2347ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 23487453ed4cb2cab113de3378df371b1c6f1243d832John McCall /// True if this lookup is overloaded. 23497453ed4cb2cab113de3378df371b1c6f1243d832John McCall bool isOverloaded() const { return Overloaded; } 23507453ed4cb2cab113de3378df371b1c6f1243d832John McCall 2351c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// Gets the 'naming class' (in the sense of C++0x 2352c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// [class.access.base]p5) of the lookup. This is the scope 2353c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// that was looked in to find these results. 2354c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const { return NamingClass; } 2355c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 235663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range(getNameInfo().getSourceRange()); 2358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (getQualifierLoc()) 23594c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 2360ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie if (hasExplicitTemplateArgs()) 23614c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setEnd(getRAngleLoc()); 2362f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2363ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2364ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 236563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 2366ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 2367ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const Stmt *T) { 2368ba13543329afac4a0d01304ec2ec4924d99306a6John McCall return T->getStmtClass() == UnresolvedLookupExprClass; 2369ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 2370ba13543329afac4a0d01304ec2ec4924d99306a6John McCall static bool classof(const UnresolvedLookupExpr *) { return true; } 2371ba13543329afac4a0d01304ec2ec4924d99306a6John McCall}; 2372ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 23735953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// \brief A qualified reference to a name whose declaration cannot 23745953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// yet be resolved. 23755953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// 2376ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// it expresses a reference to a declaration such as 23785953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// X<T>::value. The difference, however, is that an 2379865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// DependentScopeDeclRefExpr node is used only within C++ templates when 23805953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// the qualification (e.g., X<T>::) refers to a dependent type. In 23815953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// this case, X<T>::value cannot resolve to a declaration because the 23825953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor/// declaration will differ from on instantiation of X<T> to the 2383865d447ac6a4721ab58e898d014a21f2eff74b06John McCall/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2384ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor/// qualifier (X<T>::) and the name of the entity being referenced 2385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2386a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// declaration can be found. 2387865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass DependentScopeDeclRefExpr : public Expr { 2388ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested-name-specifier that qualifies this unresolved 2389ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration name. 239000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 2391ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 239200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// The name of the entity we will be referencing. 239300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor DeclarationNameInfo NameInfo; 23945953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 2395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether the name includes info for explicit template 2396e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2397e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo; 2398e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2399e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2400e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2402e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2403e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2404e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2405e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2406e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DependentScopeDeclRefExpr*>(this) 2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2408e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 24091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2410f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall DependentScopeDeclRefExpr(QualType T, 241100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2412e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 24132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2414bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor const TemplateArgumentListInfo *Args); 2415f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2416f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCallpublic: 2417f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static DependentScopeDeclRefExpr *Create(ASTContext &C, 241800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2419e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 24202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2421e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs); 24225953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 242312dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 242512dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis unsigned NumTemplateArgs); 242612dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 24275953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the name that this expression refers to. 24282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 24292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 24302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name that this expression refers to. 24312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getDeclName() const { return NameInfo.getName(); } 24325953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 24335953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor /// \brief Retrieve the location of the name within the expression. 24342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLocation() const { return NameInfo.getLoc(); } 24355953d8b37f92f0cf548941f617c9b0a7703df33bDouglas Gregor 243600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the 243700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor /// name, with source location information. 243800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2440ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2441ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies this 2442ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// declaration. 2443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2444ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 244500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor } 24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2447e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2448e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 2449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2450e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2451e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2452e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2453e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2454e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2455e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2456e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2457e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2458e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2459e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2460e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2461e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2462e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 2463e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2464e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2465e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2466e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2467e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2468e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the name was preceded by the template keyword. 2469e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2470e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2471f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Determines whether this lookup had explicit template arguments. 2472e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2474f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Note that, inconsistently with the explicit-template-argument AST 2475f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // nodes, users are *forbidden* from calling these methods on objects 2476f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // without explicit template arguments. 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2478b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 247912dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis assert(hasExplicitTemplateArgs()); 2480b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 248112dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis } 248212dffcddb60380c5bed4f085a1f51534afda3b87Argyrios Kyrtzidis 2483f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Gets a reference to the explicit template argument list. 2484b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall assert(hasExplicitTemplateArgs()); 2486b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2487f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 24881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2489096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2490096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2491096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2492b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2493096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2494096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2495096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2496096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2497f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Copies the template arguments (if present) into the given 2498f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// structure. 2499f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2500f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall getExplicitTemplateArgs().copyInto(List); 2501f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 2502ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2503f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentLoc const *getTemplateArgs() const { 2504f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2505d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2506d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 2507f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall unsigned getNumTemplateArgs() const { 2508f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2509f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 25101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 251163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 251200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 2513f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (hasExplicitTemplateArgs()) 2514f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Range.setEnd(getRAngleLoc()); 2515f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return Range; 2516edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2519f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return T->getStmtClass() == DependentScopeDeclRefExprClass; 2520edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor } 2521f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall static bool classof(const DependentScopeDeclRefExpr *) { return true; } 2522f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 252363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 25244045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 25254045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 25264045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 2527edce4dd44732dfad69f28822dddcf2b8e92b4483Douglas Gregor}; 25281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25294765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Represents an expression --- generally a full-expression --- which 25304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// introduces cleanups to be run at the end of the sub-expression's 25314765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// evaluation. The most common source of expression-introduced 253280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// cleanups is temporary objects in C++, but several other kinds of 253380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// expressions can create cleanups, including basically every 253480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// call in ARC that returns an Objective-C pointer. 253580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// 253680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// This expression also tracks whether the sub-expression contains a 253780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// potentially-evaluated block literal. The lifetime of a block 253880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall/// literal is the extent of the enclosing scope. 25394765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallclass ExprWithCleanups : public Expr { 254080ee6e878a169e6255d4686a91bb696151ff229fJohn McCallpublic: 254180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// The type of objects that are kept in the cleanup. 254280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// It's useful to remember the set of blocks; we could also 254380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// remember the set of temporaries, but there's currently 254480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// no need. 254580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall typedef BlockDecl *CleanupObject; 254680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 254780ee6e878a169e6255d4686a91bb696151ff229fJohn McCallprivate: 254802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Stmt *SubExpr; 25491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 255080ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(EmptyShell, unsigned NumObjects); 255180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 255202bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 255380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject *getObjectsBuffer() { 255480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<CleanupObject*>(this + 1); 255580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 255680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall const CleanupObject *getObjectsBuffer() const { 255780ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return reinterpret_cast<const CleanupObject*>(this + 1); 255880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall } 255980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall friend class ASTStmtReader; 2560ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 256188eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlssonpublic: 256280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 256380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned numObjects); 25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 256580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 256680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> objects); 2567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 256880ee6e878a169e6255d4686a91bb696151ff229fJohn McCall ArrayRef<CleanupObject> getObjects() const { 256980ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2570f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson } 257180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 257280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 257380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 257480ee6e878a169e6255d4686a91bb696151ff229fJohn McCall CleanupObject getObject(unsigned i) const { 257580ee6e878a169e6255d4686a91bb696151ff229fJohn McCall assert(i < getNumObjects() && "Index out of range"); 257680ee6e878a169e6255d4686a91bb696151ff229fJohn McCall return getObjects()[i]; 2577d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner } 25781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 257902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2580f0721fe438d7e40c168e5d664970e7830bc138fbAnders Carlsson const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 258180ee6e878a169e6255d4686a91bb696151ff229fJohn McCall 258280ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// setSubExpr - As with any mutator of the AST, be very careful 258380ee6e878a169e6255d4686a91bb696151ff229fJohn McCall /// when modifying an existing AST to preserve its invariants. 258488eaf075c56672761b72cc50957db4a35bf24ebdAnders Carlsson void setSubExpr(Expr *E) { SubExpr = E; } 258502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2586ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceRange getSourceRange() const { 258796be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor return SubExpr->getSourceRange(); 258896be6917e1c4ba1f4435a14c9e7c6c139571d086Douglas Gregor } 258902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 259002bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Implement isa/cast/dyncast/etc. 259102bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson static bool classof(const Stmt *T) { 25924765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall return T->getStmtClass() == ExprWithCleanupsClass; 259302bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson } 25944765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall static bool classof(const ExprWithCleanups *) { return true; } 259502bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 259602bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson // Iterators 259763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 259802bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson}; 259902bbfa33590dfe3107e801fb526b7ab0bdfd00eeAnders Carlsson 2600d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \brief Describes an explicit type conversion that uses functional 2601d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// notion but could not be resolved because one or more arguments are 2602d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. 2603d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2604d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// The explicit type conversions expressed by 2605d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 2606d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// where \c T is some type and \c a1, a2, ..., aN are values, and 2607d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// either \C T is a dependent type or one or more of the \c a's is 2608d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// type-dependent. For example, this would occur in a template such 2609d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// as: 2610d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2611d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \code 2612d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// template<typename T, typename A1> 2613d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// inline T make_a(const A1& a1) { 2614d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// return T(a1); 2615d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// } 2616d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// \endcode 2617d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// 2618d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// When the returned expression is instantiated, it may resolve to a 2619d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// constructor call, conversion function call, or some kind of type 2620d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor/// conversion. 2621d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorclass CXXUnresolvedConstructExpr : public Expr { 2622d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The type being constructed. 2623ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type; 2624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2625d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the left parentheses ('('). 2626d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc; 2627d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2628d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The location of the right parentheses (')'). 2629d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc; 2630d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2631d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief The number of arguments used to construct the type. 2632d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs; 26331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2634ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2635d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 2636d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr **Args, 2637d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs, 2638d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2639d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26408dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2641ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 26428dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2643ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor friend class ASTStmtReader; 2644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2645d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregorpublic: 26461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2647ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *Type, 2648d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation LParenLoc, 2649d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr **Args, 2650d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned NumArgs, 2651d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation RParenLoc); 2652d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26538dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 26548dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis unsigned NumArgs); 26558dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2656d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the type that is being constructed, as specified 2657d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// in the source code. 2658ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor QualType getTypeAsWritten() const { return Type->getType(); } 2659d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2660ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Retrieve the type source information for the type being 2661ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /// constructed. 2662ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2664d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the left parentheses ('(') that 2665d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// precedes the argument list. 2666d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getLParenLoc() const { return LParenLoc; } 2667d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2668d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2669d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the location of the right parentheses (')') that 2670d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// follows the argument list. 2671d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 2672d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2673d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2674d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor /// \brief Retrieve the number of arguments. 2675d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor unsigned arg_size() const { return NumArgs; } 2676d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2677d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor typedef Expr** arg_iterator; 2678d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2679d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor arg_iterator arg_end() { return arg_begin() + NumArgs; } 2680d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26811dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall typedef const Expr* const * const_arg_iterator; 26821dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_begin() const { 26831dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return reinterpret_cast<const Expr* const *>(this + 1); 26841dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26851dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const_arg_iterator arg_end() const { 26861dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return arg_begin() + NumArgs; 26871dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26881dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 2689d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor Expr *getArg(unsigned I) { 2690d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor assert(I < NumArgs && "Argument index out-of-range"); 2691d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return *(arg_begin() + I); 2692d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2693d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 26941dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall const Expr *getArg(unsigned I) const { 26951dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall assert(I < NumArgs && "Argument index out-of-range"); 26961dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall return *(arg_begin() + I); 26971dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall } 26981dd7383dc48718c452e71a625b29531dd96fbb9dJohn McCall 26998dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void setArg(unsigned I, Expr *E) { 27008dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis assert(I < NumArgs && "Argument index out-of-range"); 27018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis *(arg_begin() + I) = E; 27028dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 27038dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 270463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 2705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 27061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2707d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2708d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor } 2709d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2710d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2711d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor // Iterators 271263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 271363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this+1); 271463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumArgs); 271563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 2716d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor}; 2717d81e6ca6e378c3996a139066a5c4b7fc1869630cDouglas Gregor 2718ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// \brief Represents a C++ member access expression where the actual 2719ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// member referenced could not be resolved because the base 2720ba13543329afac4a0d01304ec2ec4924d99306a6John McCall/// expression or the member name was dependent. 2721aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2722aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// Like UnresolvedMemberExprs, these can be either implicit or 2723aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// explicit accesses. It is only possible to get one of these with 2724aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// an implicit access if a qualifier is provided. 2725865d447ac6a4721ab58e898d014a21f2eff74b06John McCallclass CXXDependentScopeMemberExpr : public Expr { 27261c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The expression for the base pointer or class reference, 2727aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// e.g., the \c x in x.f. Can be null in implicit accesses. 27281c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor Stmt *Base; 27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2730aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief The type of the base expression. Never null, even for 2731aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// implicit accesses. 2732aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 2733aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 27341c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Whether this member expression used the '->' operator or 27351c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// the '.' operator. 27363b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor bool IsArrow : 1; 27371c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2738e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Whether this member expression has info for explicit template 2739e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// keyword and arguments. 2740e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27421c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The location of the '->' or '.' operator. 27431c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation OperatorLoc; 27441c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2745a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief The nested-name-specifier that precedes the member name, if any. 27467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2748c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief In a qualified member access expression such as t->Base::f, this 27491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// member stores the resolves of name lookup in the context of the member 2750c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// access expression, to be used at instantiation time. 2751c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 275246bb4f1a3ac9517406887939612eb8df4b7be006Douglas Gregor /// FIXME: This member, along with the QualifierLoc, could 2753c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// be stuck into a structure that is optionally allocated at the end of 2754865d447ac6a4721ab58e898d014a21f2eff74b06John McCall /// the CXXDependentScopeMemberExpr, to save space in the common case. 2755c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierFoundInScope; 27561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief The member to which this member expression refers, which 27581c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// can be name, overloaded operator, or destructor. 2759a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// FIXME: could also be a template-id 27602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo; 27611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2762e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2763e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2764e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 2765e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2766e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2767e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2768e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2769e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<CXXDependentScopeMemberExpr*>(this) 2770e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ->getTemplateKWAndArgsInfo(); 2771e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2772e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2773865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2774aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 27753b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 27767c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2777e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 27783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 27792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2780d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 27811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27821c0ca59416999129d0439c2661d137ef38e86209Douglas Gregorpublic: 2783865d447ac6a4721ab58e898d014a21f2eff74b06John McCall CXXDependentScopeMemberExpr(ASTContext &C, 2784bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Expr *Base, QualType BaseType, 2785bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool IsArrow, 2786bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation OperatorLoc, 27877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2788bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 2789bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor DeclarationNameInfo MemberNameInfo); 27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2791865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static CXXDependentScopeMemberExpr * 27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Create(ASTContext &C, 2793aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 27943b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SourceLocation OperatorLoc, 27957c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2796e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 27973b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor NamedDecl *FirstQualifierFoundInScope, 27982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2799d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *TemplateArgs); 28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28018dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static CXXDependentScopeMemberExpr * 2802e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2803def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 28048dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 2805aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 2806aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 2807aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 28084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 2809aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 28101c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the base object of this member expressions, 28111c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// e.g., the \c x in \c x.m. 2812aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() const { 2813aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 2814aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 2815aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 28161c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2817aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 2818aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 28191c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Determine whether this member expression used the '->' 28201c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// operator; otherwise, it used the '.' operator. 28211c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor bool isArrow() const { return IsArrow; } 28221c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 28231c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the location of the '->' or '.' operator. 28241c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 28251c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2826a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 2827a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor /// name. 2828ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie NestedNameSpecifier *getQualifier() const { 2829ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return QualifierLoc.getNestedNameSpecifier(); 28307c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28327c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// \brief Retrieve the nested-name-specifier that qualifies the member 28337c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor /// name, with source location information. 28347c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2835ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2836ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2837c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// \brief Retrieve the first part of the nested-name-specifier that was 2838c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// found in the scope of the member access expression when the member access 2839c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// was initially parsed. 2840c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// 2841c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// This function only returns a useful result when member access expression 28421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 28431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// returned by this function describes what was found by unqualified name 2844c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// lookup for the identifier "Base" within the scope of the member access 2845c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself. At template instantiation time, this information is 2846c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// combined with the results of name lookup into the type of the object 2847c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor /// expression itself (the class type of x). 28481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamedDecl *getFirstQualifierFoundInScope() const { 2849c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor return FirstQualifierFoundInScope; 2850c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor } 28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28521c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// \brief Retrieve the name of the member that this expression 28531c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor /// refers to. 28542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { 28552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return MemberNameInfo; 28562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 28582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the name of the member that this expression 28592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 28602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getMember() const { return MemberNameInfo.getName(); } 28611c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 28621c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // \brief Retrieve the location of the name of the member that this 28631c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // expression refers to. 28642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 28651c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2866e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding the 2867e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member name, if any. 2868e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2869e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2870e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2871e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2872e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2873e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2874e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2875e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2876e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2877e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2878e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2879e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2880e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2881e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2882e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2883e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2884e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2885e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2886e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2887e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 2888e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2889e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 28903b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 28913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2892e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 28931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 289436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 289536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 2896b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2897e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2898b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 289936c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 290036c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 290136c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// \brief Retrieve the explicit template argument list that followed the 290236c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis /// member template name, if any. 2903b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 290436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis return const_cast<CXXDependentScopeMemberExpr *>(this) 2905096832c5ed5b9106fa177ebc148489760c3bc496John McCall ->getExplicitTemplateArgs(); 2906096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2907096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2908096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2909096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2910096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2911b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2912096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2913096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 291436c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis } 291536c76f0bea0d3595a25a5362225c642019cc3176Argyrios Kyrtzidis 2916d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2917d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2918d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2919096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2920d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2921d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 29228dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis /// \brief Initializes the template arguments using the given structure. 29238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2924096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().initializeFrom(List); 29258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis } 29268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 29273b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 29283b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 2929833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2930096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 29313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29333b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 29343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// template-id. 29351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2936096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 29373b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 293963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2940aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall SourceRange Range; 2941aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 2942aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 2943aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else if (getQualifier()) 29447c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 2945aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 29462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setBegin(MemberNameInfo.getBeginLoc()); 29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2948aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (hasExplicitTemplateArgs()) 2949aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setEnd(getRAngleLoc()); 2950aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall else 29512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Range.setEnd(MemberNameInfo.getEndLoc()); 2952aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return Range; 29531c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2956865d447ac6a4721ab58e898d014a21f2eff74b06John McCall return T->getStmtClass() == CXXDependentScopeMemberExprClass; 29571c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor } 2958865d447ac6a4721ab58e898d014a21f2eff74b06John McCall static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 29591c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 29601c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor // Iterators 296163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 296263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 296363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 296463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 29654045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 29664045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtReader; 29674045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 29681c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor}; 29691c0ca59416999129d0439c2661d137ef38e86209Douglas Gregor 2970129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall/// \brief Represents a C++ member access expression for which lookup 2971aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// produced a set of overloaded functions. 2972aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2973aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// The member access may be explicit or implicit: 2974aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// struct A { 2975aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int a, b; 2976aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int explicitAccess() { return this->a + this->A::b; } 2977aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// int implicitAccess() { return a + A::b; } 2978aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// }; 2979aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// 2980aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// In the final AST, an explicit access always becomes a MemberExpr. 2981aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// An implicit access may become either a MemberExpr or a 2982aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall/// DeclRefExpr, depending on whether the member is static. 29837bb12da2b0749eeebb21854c77877736969e59f2John McCallclass UnresolvedMemberExpr : public OverloadExpr { 2984129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether this member expression used the '->' operator or 2985129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// the '.' operator. 2986129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow : 1; 2987129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 2988129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Whether the lookup results contain an unresolved using 2989129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// declaration. 2990129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool HasUnresolvedUsing : 1; 2991129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 29927bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The expression for the base pointer or class reference, 29937bb12da2b0749eeebb21854c77877736969e59f2John McCall /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 29947bb12da2b0749eeebb21854c77877736969e59f2John McCall /// member expression 29957bb12da2b0749eeebb21854c77877736969e59f2John McCall Stmt *Base; 29967bb12da2b0749eeebb21854c77877736969e59f2John McCall 29977bb12da2b0749eeebb21854c77877736969e59f2John McCall /// \brief The type of the base expression; never null. 29987bb12da2b0749eeebb21854c77877736969e59f2John McCall QualType BaseType; 2999129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3000129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief The location of the '->' or '.' operator. 3001129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc; 3002129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3003bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3004aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3005129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 30064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3007e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 30082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 30095a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 30105a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3011ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3012a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis UnresolvedMemberExpr(EmptyShell Empty) 3013a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3014a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis HasUnresolvedUsing(false), Base(0) { } 3015129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 30164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor friend class ASTStmtReader; 3017ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3018129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCallpublic: 3019129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static UnresolvedMemberExpr * 3020bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Create(ASTContext &C, bool HasUnresolvedUsing, 3021aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *Base, QualType BaseType, bool IsArrow, 3022129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 30234c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 3024e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 30252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 30265a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor const TemplateArgumentListInfo *TemplateArgs, 30275a84dec38cfa9e084377a3167b474c79283c82faDouglas Gregor UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3028129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3029a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis static UnresolvedMemberExpr * 3030e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3031def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 3032a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3033aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// \brief True if this is an implicit access, i.e. one in which the 3034aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// member being accessed was not written in the source. The source 3035aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall /// location of the operator is invalid in this case. 30364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor bool isImplicitAccess() const; 3037aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3038129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the base object of this member expressions, 3039129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// e.g., the \c x in \c x.m. 3040aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *getBase() { 3041aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall assert(!isImplicitAccess()); 3042aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall return cast<Expr>(Base); 3043aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 30442f27bf854f0519810b34afd209089cc75536b757John McCall const Expr *getBase() const { 30452f27bf854f0519810b34afd209089cc75536b757John McCall assert(!isImplicitAccess()); 30462f27bf854f0519810b34afd209089cc75536b757John McCall return cast<Expr>(Base); 30472f27bf854f0519810b34afd209089cc75536b757John McCall } 3048129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3049aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType getBaseType() const { return BaseType; } 3050a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis 3051a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// \brief Determine whether the lookup results contain an unresolved using 3052a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis /// declaration. 3053a77eb0862507b900a10fa352af1568e639ed10b1Argyrios Kyrtzidis bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3054aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3055129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Determine whether this member expression used the '->' 3056129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// operator; otherwise, it used the '.' operator. 3057129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool isArrow() const { return IsArrow; } 3058129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3059129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the location of the '->' or '.' operator. 3060129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation getOperatorLoc() const { return OperatorLoc; } 3061129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3062c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall /// \brief Retrieves the naming class of this lookup. 3063c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall CXXRecordDecl *getNamingClass() const; 3064c373d48502ca7683ab55385f5bd624d778eb288dJohn McCall 30652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the full name info for the member that this expression 30662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// refers to. 30672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 30682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3069129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Retrieve the name of the member that this expression 3070129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// refers to. 30717bb12da2b0749eeebb21854c77877736969e59f2John McCall DeclarationName getMemberName() const { return getName(); } 3072129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3073129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // \brief Retrieve the location of the name of the member that this 3074129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // expression refers to. 30757bb12da2b0749eeebb21854c77877736969e59f2John McCall SourceLocation getMemberLoc() const { return getNameLoc(); } 3076129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 307763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange Range = getMemberNameInfo().getSourceRange(); 3079aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!isImplicitAccess()) 3080aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Range.setBegin(Base->getSourceRange().getBegin()); 30814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor else if (getQualifierLoc()) 30824c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor Range.setBegin(getQualifierLoc().getBeginLoc()); 3083aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 3084129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (hasExplicitTemplateArgs()) 3085129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Range.setEnd(getRAngleLoc()); 3086129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return Range; 3087129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3088129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3089129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const Stmt *T) { 3090129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall return T->getStmtClass() == UnresolvedMemberExprClass; 3091129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 3092129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall static bool classof(const UnresolvedMemberExpr *) { return true; } 3093129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 3094129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Iterators 309563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 309663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (isImplicitAccess()) return child_range(); 309763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Base, &Base + 1); 309863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3099129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall}; 3100129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 31012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 31022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// 31032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// The noexcept expression tests whether a given expression might throw. Its 31042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl/// result is a boolean constant. 31052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlclass CXXNoexceptExpr : public Expr { 31062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool Value : 1; 31072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Stmt *Operand; 31082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceRange Range; 31092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3110c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl friend class ASTStmtReader; 3111c8aecc2dfb2e393d9eeaedeca22ff8cd7149af81Sebastian Redl 31122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redlpublic: 31132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 31142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl SourceLocation Keyword, SourceLocation RParen) 3115f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3116f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /*TypeDependent*/false, 3117bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ValueDependent*/Val == CT_Dependent, 3118561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Val == CT_Dependent || Operand->isInstantiationDependent(), 3119bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor Operand->containsUnexpandedParameterPack()), 31206b219d082434394c1ac401390ec1d1967727815aSebastian Redl Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 31216b219d082434394c1ac401390ec1d1967727815aSebastian Redl { } 31226b219d082434394c1ac401390ec1d1967727815aSebastian Redl 31236b219d082434394c1ac401390ec1d1967727815aSebastian Redl CXXNoexceptExpr(EmptyShell Empty) 31246b219d082434394c1ac401390ec1d1967727815aSebastian Redl : Expr(CXXNoexceptExprClass, Empty) 31252e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl { } 31262e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31272e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl Expr *getOperand() const { return static_cast<Expr*>(Operand); } 31282e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 312963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Range; } 31302e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31312e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl bool getValue() const { return Value; } 31322e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31332e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const Stmt *T) { 31342e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return T->getStmtClass() == CXXNoexceptExprClass; 31352e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 31362e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl static bool classof(const CXXNoexceptExpr *) { return true; } 31372e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 31382e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl // Iterators 313963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Operand, &Operand + 1); } 31402e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl}; 31412e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 3142ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents a C++0x pack expansion that produces a sequence of 3143be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expressions. 3144be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3145be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// A pack expansion expression contains a pattern (which itself is an 3146be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// expression) followed by an ellipsis. For example: 3147be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3148be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \code 3149be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template<typename F, typename ...Types> 3150be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// void forward(F f, Types &&...args) { 3151be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// f(static_cast<Types&&>(args)...); 3152be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// } 3153be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// \endcode 3154be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// 3155be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// Here, the argument to the function object \c f is a pack expansion whose 3156ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3157be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// template is instantiated, the pack expansion will instantiate to zero or 3158be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor/// or more function arguments to the function object \c f. 3159be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorclass PackExpansionExpr : public Expr { 3160be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation EllipsisLoc; 3161ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 316267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// \brief The number of expansions that will be produced by this pack 316367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// expansion expression, if known. 316467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// 316567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// When zero, the number of expansions is not known. Otherwise, this value 316667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// is the number of expansions + 1. 316767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor unsigned NumExpansions; 3168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3169be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Stmt *Pattern; 3170ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3171be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor friend class ASTStmtReader; 317267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor friend class ASTStmtWriter; 3173ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3174be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregorpublic: 317567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 317667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) 3177ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3178ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Pattern->getObjectKind(), /*TypeDependent=*/true, 3179561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3180561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3181be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor EllipsisLoc(EllipsisLoc), 318267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3183be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Pattern(Pattern) { } 3184be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3185be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3186ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3187be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3188be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3189be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3190be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the pattern of the pack expansion. 3191be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3192be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3193be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// \brief Retrieve the location of the ellipsis that describes this pack 3194be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor /// expansion. 3195be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3196ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3197ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief Determine the number of expansions that will be produced when 319867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor /// this pack expansion is instantiated, if already known. 319967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> getNumExpansions() const { 320067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor if (NumExpansions) 320167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return NumExpansions - 1; 3202ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 320367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return llvm::Optional<unsigned>(); 320467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor } 3205ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 320663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 320763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(Pattern->getLocStart(), EllipsisLoc); 320863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3209be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 3210be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const Stmt *T) { 3211be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor return T->getStmtClass() == PackExpansionExprClass; 3212be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor } 3213be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor static bool classof(const PackExpansionExpr *) { return true; } 3214ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3215be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor // Iterators 321663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 321763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Pattern, &Pattern + 1); 321863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3219be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor}; 3220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3221e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnarainline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3222e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return 0; 32237bb12da2b0749eeebb21854c77877736969e59f2John McCall if (isa<UnresolvedLookupExpr>(this)) 3224e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3225e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedLookupExpr>(this) + 1); 32267bb12da2b0749eeebb21854c77877736969e59f2John McCall else 3227e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3228e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara (cast<UnresolvedMemberExpr>(this) + 1); 32297bb12da2b0749eeebb21854c77877736969e59f2John McCall} 32307bb12da2b0749eeebb21854c77877736969e59f2John McCall 3231ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Represents an expression that computes the length of a parameter 3232ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// pack. 3233ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// 3234ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \code 3235ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// template<typename ...Types> 3236ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// struct count { 3237ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// static const unsigned value = sizeof...(Types); 3238ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// }; 3239ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor/// \endcode 3240ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorclass SizeOfPackExpr : public Expr { 3241ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the 'sizeof' keyword. 3242ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation OperatorLoc; 3243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3244ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the name of the parameter pack. 3245ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc; 3246ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3247ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The location of the closing parenthesis. 3248ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc; 3249ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3250ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The length of the parameter pack, if known. 3251ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3252ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// When this expression is value-dependent, the length of the parameter pack 3253ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// is unknown. When this expression is not value-dependent, the length is 3254ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// known. 3255ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length; 3256ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3257ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief The parameter pack itself. 3258ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *Pack; 3259ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3260ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtReader; 3261ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor friend class ASTStmtWriter; 3262ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3263ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregorpublic: 3264ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates a value-dependent expression that computes the length of 3265ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack. 3266ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3267ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc) 3268ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3269ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/true, 3270561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 3271ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3272ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3273ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(0), Pack(Pack) { } 3274ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3275ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Creates an expression that computes the length of 3276ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// the given parameter pack, which is already known. 3277ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3278ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, SourceLocation RParenLoc, 3279ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) 3280ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3281ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*TypeDependent=*/false, /*ValueDependent=*/false, 3282561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/false, 3283ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 3284ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3285ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor Length(Length), Pack(Pack) { } 3286ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3287ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Create an empty expression. 3288ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3289ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3290ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the 'sizeof' keyword. 3291ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 3292ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 3293ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the parameter pack. 3294ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getPackLoc() const { return PackLoc; } 3295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3296ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Determine the location of the right parenthesis. 3297ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3298ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3299ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the parameter pack. 3300ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NamedDecl *getPack() const { return Pack; } 3301ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3302ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Retrieve the length of the parameter pack. 3303ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// 3304ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This routine may only be invoked when the expression is not 3305c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// value-dependent. 3306ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned getPackLength() const { 3307ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie assert(!isValueDependent() && 3308ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor "Cannot get the length of a value-dependent pack size expression"); 3309ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return Length; 3310ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3311ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 331263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 331363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return SourceRange(OperatorLoc, RParenLoc); 331463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3315ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3316ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const Stmt *T) { 3317ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return T->getStmtClass() == SizeOfPackExprClass; 3318ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 3319ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor static bool classof(const SizeOfPackExpr *) { return true; } 3320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3321ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Iterators 332263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3323ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor}; 3324c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 332591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// \brief Represents a reference to a non-type template parameter 332691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall/// that has been substituted with a template argument. 332791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallclass SubstNonTypeTemplateParmExpr : public Expr { 332891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replaced parameter. 332991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *Param; 333091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 333191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The replacement expression. 333291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Stmt *Replacement; 333391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 333491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// \brief The location of the non-type template parameter reference. 333591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation NameLoc; 333691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 33377110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 33387110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTStmtReader; 3339ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 33407110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 33417110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall 334291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallpublic: 3343ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmExpr(QualType type, 334491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall ExprValueKind valueKind, 334591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation loc, 334691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *param, 334791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *replacement) 334891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 334991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isTypeDependent(), replacement->isValueDependent(), 335091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->isInstantiationDependent(), 335191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall replacement->containsUnexpandedParameterPack()), 335291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Param(param), Replacement(replacement), NameLoc(loc) {} 335391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 335491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceLocation getNameLoc() const { return NameLoc; } 335591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SourceRange getSourceRange() const { return NameLoc; } 335691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 335791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *getReplacement() const { return cast<Expr>(Replacement); } 3358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 335991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall NonTypeTemplateParmDecl *getParameter() const { return Param; } 336091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 336191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall static bool classof(const Stmt *s) { 336291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 336391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3364ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const SubstNonTypeTemplateParmExpr *) { 3365ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 336691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 3367ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 336891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Iterators 336991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall child_range children() { return child_range(&Replacement, &Replacement+1); } 337091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}; 337191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 3372c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// \brief Represents a reference to a non-type template parameter pack that 3373c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// has been substituted with a non-template argument pack. 3374c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// 3375c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs 3376c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// and those parameter packs correspond to different levels of template 3377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this node node is used to represent a non-type template 3378c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack 3379c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// substituted but that still lives within a pack expansion that itself 3380c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// could not be instantiated. When actually performing a substitution into 3381c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding 3382c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// arguments), this type will be replaced with the appropriate underlying 3383c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor/// expression at the current pack substitution index. 3384c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorclass SubstNonTypeTemplateParmPackExpr : public Expr { 3385c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The non-type template parameter pack itself. 3386c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param; 3387ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3388c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief A pointer to the set of template arguments that this 3389c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// parameter pack is instantiated with. 3390c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument *Arguments; 3391ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3392c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The number of template arguments in \c Arguments. 3393c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor unsigned NumArguments; 3394ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3395c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief The location of the non-type template parameter pack reference. 3396c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc; 3397ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 33987110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall friend class ASTReader; 3399c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor friend class ASTStmtReader; 3400ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 34017110fd6c32306b3feb97b9edb8064b1b68a54e6bJohn McCall : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3402ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3403c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregorpublic: 3404ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SubstNonTypeTemplateParmPackExpr(QualType T, 3405c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *Param, 3406c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation NameLoc, 3407c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor const TemplateArgument &ArgPack); 3408ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3409c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the non-type template parameter pack being substituted. 3410c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3411c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 3412c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the location of the parameter pack name. 3413c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SourceLocation getParameterPackLocation() const { return NameLoc; } 3414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3415c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// \brief Retrieve the template argument pack containing the substituted 3416c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor /// template arguments. 3417c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor TemplateArgument getArgumentPack() const; 3418c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 341963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return NameLoc; } 3420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3421c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor static bool classof(const Stmt *T) { 3422c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3423c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3424ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const SubstNonTypeTemplateParmPackExpr *) { 3425ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 3426c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor } 3427ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3428c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Iterators 342963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 3430c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor}; 343103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 343203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \brief Represents a prvalue temporary that written into memory so that 343303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// a reference can bind to it. 343403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 343503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Prvalue expressions are materialized when they need to have an address 343603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// in memory for a reference to bind to. This happens when binding a 343703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// reference to the result of a conversion, e.g., 343803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 343903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \code 344003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// const int &r = 1.0; 344103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// \endcode 344203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// 344303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 344403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// then materialized via a \c MaterializeTemporaryExpr, and the reference 344503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 344603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// (either an lvalue or an xvalue, depending on the kind of reference binding 344703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor/// to it), maintaining the invariant that references always bind to glvalues. 344803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorclass MaterializeTemporaryExpr : public Expr { 344903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief The temporary-generating expression whose value will be 345003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// materialized. 345103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Stmt *Temporary; 3452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 345303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtReader; 345403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor friend class ASTStmtWriter; 3455ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 345603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregorpublic: 3457ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3458b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor bool BoundToLvalueReference) 3459b4b7b5034bb8304ed03416635bf64c75c39889fcDouglas Gregor : Expr(MaterializeTemporaryExprClass, T, 346003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 346103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->isTypeDependent(), Temporary->isValueDependent(), 3462561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Temporary->isInstantiationDependent(), 346303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary->containsUnexpandedParameterPack()), 346403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Temporary(Temporary) { } 3465ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3466ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie MaterializeTemporaryExpr(EmptyShell Empty) 346703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor : Expr(MaterializeTemporaryExprClass, Empty) { } 3468ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 346903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Retrieve the temporary-generating subexpression whose value will 347003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// be materialized into a glvalue. 347103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3472ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 347303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// \brief Determine whether this materialized temporary is bound to an 347403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor /// lvalue reference; otherwise, it's bound to an rvalue reference. 3475ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isBoundToLvalueReference() const { 347603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getValueKind() == VK_LValue; 347703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3478ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 347903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor SourceRange getSourceRange() const { return Temporary->getSourceRange(); } 3480ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 348103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor static bool classof(const Stmt *T) { 348203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return T->getStmtClass() == MaterializeTemporaryExprClass; 348303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3484ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static bool classof(const MaterializeTemporaryExpr *) { 3485ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return true; 348603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor } 3487ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 348803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor // Iterators 348903e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor child_range children() { return child_range(&Temporary, &Temporary + 1); } 349003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor}; 3491ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 34925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 34935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3495