ExprCXX.h revision 76f3f69db1416425070177243e9f390122c553e0
14b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 24b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 34b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// The LLVM Compiler Infrastructure 44b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 54b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// This file is distributed under the University of Illinois Open Source 64b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// License. See LICENSE.TXT for details. 74b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 84b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 94b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 104b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// This file defines the Expr interface and subclasses for C++ expressions. 114b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis// 124b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 134b562cf889bc59e1914dd2c5d9fbd7e7bfa1ad77Argyrios Kyrtzidis 140853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#ifndef LLVM_CLANG_AST_EXPRCXX_H 150853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis#define LLVM_CLANG_AST_EXPRCXX_H 160853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 17eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor#include "clang/AST/Expr.h" 1805a07605322dfef2b017781042043a261c5a89cdSebastian Redl#include "clang/AST/UnresolvedSet.h" 19914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor#include "clang/AST/TemplateBase.h" 200a2c5e256abb4dc031c21fe4dc92c4f3afe9947cJohn McCall#include "clang/Basic/ExpressionTraits.h" 214ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#include "clang/Basic/Lambda.h" 2231b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar#include "clang/Basic/TypeTraits.h" 23eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 24389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidisnamespace clang { 2587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 2628019772db70d4547be05a042eb950bc910f134fDouglas Gregorclass CXXConstructorDecl; 270853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidisclass CXXDestructorDecl; 28a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorclass CXXMethodDecl; 29cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregorclass CXXTemporary; 3003013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencerclass TemplateArgumentListInfo; 31788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 320853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis//===--------------------------------------------------------------------===// 33f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar// C++ Expressions. 34f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar//===--------------------------------------------------------------------===// 354db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor 36cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor/// \brief A call to an overloaded operator written using operator 374db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// syntax. 384db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// 394db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// Represents a call to an overloaded operator written using operator 404db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 410853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis/// normal call, this AST node provides better information about the 420853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis/// syntactic representation of the call. 43521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar/// 441abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor/// In a C++ template, this expression node kind will be used whenever 45521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar/// any of the arguments are type-dependent. In this case, the 46521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar/// function itself will be a (possibly empty) set of functions and 47521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar/// function templates that were found by name lookup at template 48521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar/// definition time. 49521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarclass CXXOperatorCallExpr : public CallExpr { 50521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar /// \brief The overloaded operator. 51521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar OverloadedOperatorKind Operator; 52521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 53521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarpublic: 54d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 550853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis Expr **args, unsigned numargs, QualType t, 56f96b524306ccfa623235d375deee79637bd38f29Steve Naroff ExprValueKind VK, SourceLocation operatorloc) 5744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK, 5848601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor operatorloc), 5948601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor Operator(Op) {} 6048601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 6148601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor CallExpr(C, CXXOperatorCallExprClass, Empty) { } 6248601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor 6348601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor 6448601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor /// getOperator - Returns the kind of overloaded operator that this 6548601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor /// expression refers to. 663c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl OverloadedOperatorKind getOperator() const { return Operator; } 670853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; } 680853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 69788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// getOperatorLoc - Returns the location of the operator symbol in 70788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// the expression. When @c getOperator()==OO_Call, this is the 71788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// location of the right parentheses; when @c 72bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor /// getOperator()==OO_Subscript, this is the location of the right 73788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// bracket. 7428019772db70d4547be05a042eb950bc910f134fDouglas Gregor SourceLocation getOperatorLoc() const { return getRParenLoc(); } 754f32786ac45210143654390177105eb749b614e9Ted Kremenek 764f32786ac45210143654390177105eb749b614e9Ted Kremenek SourceRange getSourceRange() const; 770853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 784f32786ac45210143654390177105eb749b614e9Ted Kremenek static bool classof(const Stmt *T) { 794f32786ac45210143654390177105eb749b614e9Ted Kremenek return T->getStmtClass() == CXXOperatorCallExprClass; 804f32786ac45210143654390177105eb749b614e9Ted Kremenek } 81389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis static bool classof(const CXXOperatorCallExpr *) { return true; } 82389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis}; 83389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis 84914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// CXXMemberCallExpr - Represents a call to a member function that 85914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// may be written either with member call syntax (e.g., "obj.func()" 86914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// or "objptr->func()") or with normal function-call syntax 87914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// ("func()") within a member function that ends up calling a member 88914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// function. The callee in either case is a MemberExpr that contains 89914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// both the object argument and the member function, while the 90914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// arguments are the arguments within the parentheses (not including 91914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor/// the object argument). 92807b06157a1a5c050520fc194d32f16d22d423a8Daniel Dunbarclass CXXMemberCallExpr : public CallExpr { 93807b06157a1a5c050520fc194d32f16d22d423a8Daniel Dunbarpublic: 944f32786ac45210143654390177105eb749b614e9Ted Kremenek CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs, 95914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor QualType t, ExprValueKind VK, SourceLocation RP) 961aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {} 971aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor 981aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 991aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1001aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor 1011aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// getImplicitObjectArgument - Retrieves the implicit object 1021aa27307c462baaa9e5fda14ff6797dd39fe8b84Douglas Gregor /// argument for the member call. For example, in "x.f(5)", this 1037d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// operation would return "x". 1047d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor Expr *getImplicitObjectArgument() const; 1057d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 1067d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// Retrieves the declaration of the called method. 107c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar CXXMethodDecl *getMethodDecl() const; 108abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 109abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 110e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor /// the implicit object argument. Note that this is may not be the same 111df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// declaration as that of the class context of the CXXMethodDecl which this 112c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar /// function is calling. 113c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar /// FIXME: Returns 0 for member pointer call exprs. 114df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor CXXRecordDecl *getRecordDecl(); 115df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor 116df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor static bool classof(const Stmt *T) { 117213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor return T->getStmtClass() == CXXMemberCallExprClass; 118213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor } 11915727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis static bool classof(const CXXMemberCallExpr *) { return true; } 12015727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis}; 12115727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis 122213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 123f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbarclass CUDAKernelCallExpr : public CallExpr { 124f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbarprivate: 125f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar enum { CONFIG, END_PREARG }; 126f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 127f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbarpublic: 128f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 129f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar Expr **args, unsigned numargs, QualType t, 130f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar ExprValueKind VK, SourceLocation RP) 131f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK, 13289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor RP) { 13389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor setConfig(Config); 13489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor } 13589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 13689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 13789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 13889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 13989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor const CallExpr *getConfig() const { 14068d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar return cast_or_null<CallExpr>(getPreArg(CONFIG)); 14168d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar } 14268d40e2d16b9fadba386853d6bbb60089291fdc5Daniel Dunbar CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 143f96b524306ccfa623235d375deee79637bd38f29Steve Naroff void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 144f96b524306ccfa623235d375deee79637bd38f29Steve Naroff 145f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar static bool classof(const Stmt *T) { 146a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor return T->getStmtClass() == CUDAKernelCallExprClass; 147a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor } 148405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor static bool classof(const CUDAKernelCallExpr *) { return true; } 149a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor}; 1504cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 1514cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 1524cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 1534cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// const_cast. 1544cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// 1554cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// This abstract class is inherited by all of the classes 1564cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor/// representing "named" casts, e.g., CXXStaticCastExpr, 157313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 158313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregorclass CXXNamedCastExpr : public ExplicitCastExpr { 159313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregorprivate: 160bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor SourceLocation Loc; // the location of the casting op 161788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor SourceLocation RParenLoc; // the location of the right parenthesis 162788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 163788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregorprotected: 164788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 165788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor CastKind kind, Expr *op, unsigned PathSize, 166788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 167788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor SourceLocation RParenLoc) 168788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 169788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor RParenLoc(RParenLoc) {} 170bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 171bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 172bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor : ExplicitCastExpr(SC, Shell, PathSize) { } 173bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 174bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor friend class ASTStmtReader; 175bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 176bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregorpublic: 177bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor const char *getCastName() const; 178bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 179175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor /// \brief Retrieve the location of the cast operator keyword, e.g., 180eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// "static_cast". 181eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor SourceLocation getOperatorLoc() const { return Loc; } 182eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor 183eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor /// \brief Retrieve the location of the closing parenthesis. 184eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 185eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor 186eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor SourceRange getSourceRange() const { 187eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor return SourceRange(Loc, RParenLoc); 188eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor } 189eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor static bool classof(const Stmt *T) { 190eababfbddb74d186f78783a9731a78ad371c9800Douglas Gregor switch (T->getStmtClass()) { 191175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor case CXXStaticCastExprClass: 192385103b79c5338a2be5da0ca70652400bc267371Douglas Gregor case CXXDynamicCastExprClass: 193175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor case CXXReinterpretCastExprClass: 194175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor case CXXConstCastExprClass: 195175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor return true; 196175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor default: 197175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor return false; 198f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor } 199f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor } 200f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor static bool classof(const CXXNamedCastExpr *) { return true; } 201f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor}; 202f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 203f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor/// CXXStaticCastExpr - A C++ @c static_cast expression 204175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor/// (C++ [expr.static.cast]). 205175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor/// 206175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor/// This expression node represents a C++ static cast, e.g., 207cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor/// @c static_cast<int>(1.0). 208cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregorclass CXXStaticCastExpr : public CXXNamedCastExpr { 209cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 210cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor unsigned pathSize, TypeSourceInfo *writtenTy, 211cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor SourceLocation l, SourceLocation RParenLoc) 212cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 213cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor writtenTy, l, RParenLoc) {} 214cc5888d833caf90ebda37f24da40d2cd06b4d820Douglas Gregor 21528233428da1ebec20c893d6297ae3191318940ddDouglas Gregor explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 21628233428da1ebec20c893d6297ae3191318940ddDouglas Gregor : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 21728233428da1ebec20c893d6297ae3191318940ddDouglas Gregor 21828233428da1ebec20c893d6297ae3191318940ddDouglas Gregorpublic: 219c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 220671947b18dba342f9aba022ee992babef325a833Douglas Gregor ExprValueKind VK, CastKind K, Expr *Op, 221671947b18dba342f9aba022ee992babef325a833Douglas Gregor const CXXCastPath *Path, 222671947b18dba342f9aba022ee992babef325a833Douglas Gregor TypeSourceInfo *Written, SourceLocation L, 223671947b18dba342f9aba022ee992babef325a833Douglas Gregor SourceLocation RParenLoc); 224671947b18dba342f9aba022ee992babef325a833Douglas Gregor static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 225c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor unsigned PathSize); 226c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 227c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor static bool classof(const Stmt *T) { 228c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor return T->getStmtClass() == CXXStaticCastExprClass; 229c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor } 230c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor static bool classof(const CXXStaticCastExpr *) { return true; } 231c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor}; 232c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 233c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 234c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 235c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// determine how to perform the type cast. 236c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// 237c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// This expression node represents a dynamic cast, e.g., 238c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor/// @c dynamic_cast<Derived*>(BasePtr). 239c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregorclass CXXDynamicCastExpr : public CXXNamedCastExpr { 240c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 2413c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 242eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor SourceLocation l, SourceLocation RParenLoc) 2438538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 244eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor writtenTy, l, RParenLoc) {} 24589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 24689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 24789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 24889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 24987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregorpublic: 25087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 25187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor ExprValueKind VK, CastKind Kind, Expr *Op, 252e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor const CXXCastPath *Path, 2530b53cf834346d78985aaa9e7300445a39c245614Douglas Gregor TypeSourceInfo *Written, SourceLocation L, 254e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor SourceLocation RParenLoc); 255e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor 25687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 25787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor unsigned pathSize); 25887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 25987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor bool isAlwaysNull() const; 26087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 26187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static bool classof(const Stmt *T) { 26287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return T->getStmtClass() == CXXDynamicCastExprClass; 26387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 26487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static bool classof(const CXXDynamicCastExpr *) { return true; } 26587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor}; 26687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 26787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 26887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// [expr.reinterpret.cast]), which provides a differently-typed view 26987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// of a value but performs no actual work at run time. 27087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// 27187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// This expression node represents a reinterpret cast, e.g., 27287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor/// @c reinterpret_cast<int>(VoidPtr). 27387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregorclass CXXReinterpretCastExpr : public CXXNamedCastExpr { 27487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 27587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor Expr *op, unsigned pathSize, 27687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 27787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor SourceLocation RParenLoc) 27887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 27987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor pathSize, writtenTy, l, RParenLoc) {} 2801827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregor 28158ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 28258ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 28358ddb60f409125eda5436c4a1f070f7fa4744295Douglas Gregor 2841827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregorpublic: 2851827e10051638770ad9ccf3e285caf95f995afd1Douglas Gregor static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 286f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor ExprValueKind VK, CastKind Kind, 287f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor Expr *Op, const CXXCastPath *Path, 288f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor TypeSourceInfo *WrittenTy, SourceLocation L, 289f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor SourceLocation RParenLoc); 290f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 291f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor unsigned pathSize); 292f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 293f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static bool classof(const Stmt *T) { 29487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return T->getStmtClass() == CXXReinterpretCastExprClass; 29587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 296f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static bool classof(const CXXReinterpretCastExpr *) { return true; } 297f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor}; 298f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 299f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 300f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor/// which can remove type qualifiers but does not change the underlying value. 301f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor/// 30248601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor/// This expression node represents a const cast, e.g., 30348601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor/// @c const_cast<char*>(PtrToConstChar). 30448601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregorclass CXXConstCastExpr : public CXXNamedCastExpr { 30548601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 30648601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor TypeSourceInfo *writtenTy, SourceLocation l, 30748601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor SourceLocation RParenLoc) 30887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 309218937c13ef5b0625a70aad41ca7a92da9278bd2Douglas Gregor 0, writtenTy, l, RParenLoc) {} 31048601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor 31148601b32321496b07a18fb6631f8563275d8c5fbDouglas Gregor explicit CXXConstCastExpr(EmptyShell Empty) 312218937c13ef5b0625a70aad41ca7a92da9278bd2Douglas Gregor : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 31387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 31487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregorpublic: 31587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 316f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor ExprValueKind VK, Expr *Op, 317f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor TypeSourceInfo *WrittenTy, SourceLocation L, 318f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor SourceLocation RParenLoc); 319f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 3209b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor 3219b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor static bool classof(const Stmt *T) { 322727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregor return T->getStmtClass() == CXXConstCastExprClass; 3239b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor } 3249b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor static bool classof(const CXXConstCastExpr *) { return true; } 3259b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor}; 326727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregor 3279b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 3289b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor/// 329727d93ef49e18147149354fadd10e86b13bc4ab0Douglas Gregorclass CXXBoolLiteralExpr : public Expr { 3309b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor bool Value; 3319b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor SourceLocation Loc; 3329b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregorpublic: 333ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 3349b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 3359b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor false, false), 3369b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor Value(val), Loc(l) {} 3379b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor 338ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar explicit CXXBoolLiteralExpr(EmptyShell Empty) 339ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar : Expr(CXXBoolLiteralExprClass, Empty) { } 340ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar 341ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar bool getValue() const { return Value; } 342c4421e966d77a18f815284175b3fcbb46f36fa39Douglas Gregor void setValue(bool V) { Value = V; } 343c4421e966d77a18f815284175b3fcbb46f36fa39Douglas Gregor 34487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor SourceRange getSourceRange() const { return SourceRange(Loc); } 34587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 34687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor SourceLocation getLocation() const { return Loc; } 34787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 34887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 34931b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar static bool classof(const Stmt *T) { 35031b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbar return T->getStmtClass() == CXXBoolLiteralExprClass; 351bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor } 3523687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor static bool classof(const CXXBoolLiteralExpr *) { return true; } 3538b96253907c47141af0b7b2a44a368748d006a87Douglas Gregor 354abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor // Iterators 355754f3490c5b0f5d83361f001bc87944f23644abbDouglas Gregor child_range children() { return child_range(); } 356175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor}; 357f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 358df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 359df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregorclass CXXNullPtrLiteralExpr : public Expr { 360175c4a9aa61f4449f27b729737e4438684ac6d92Douglas Gregor SourceLocation Loc; 361df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregorpublic: 3622283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 363df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 364df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor false, false), 365eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor Loc(l) {} 36689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 36789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 3680853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis : Expr(CXXNullPtrLiteralExprClass, Empty) { } 369bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 370bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor SourceRange getSourceRange() const { return SourceRange(Loc); } 371bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 372bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor SourceLocation getLocation() const { return Loc; } 373bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 374bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 375bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor static bool classof(const Stmt *T) { 376bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor return T->getStmtClass() == CXXNullPtrLiteralExprClass; 377bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor } 378bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 379bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 380bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor child_range children() { return child_range(); } 381bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor}; 382bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor 383bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 384bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor/// the type_info that corresponds to the supplied type, or the (possibly 385bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor/// dynamic) type of the supplied expression. 386bdf6062bc10aa3b73b16402b440b8073310acd06Douglas Gregor/// 3870853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis/// This represents code like @c typeid(int) or @c typeid(*objPtr) 3880853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidisclass CXXTypeidExpr : public Expr { 389c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbarprivate: 390c7822dbf3c01a2a5f837cff82ba7889ea755dacaDaniel Dunbar llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 391ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar SourceRange Range; 392ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbar 393ea94bbc4769697143e717df9b0310f874102b6c1Daniel Dunbarpublic: 3943687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 3953687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 3963687e9d3a5dbfa9963af02a49a2b139d91310813Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 397405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor false, 398405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor // typeid is value-dependent if the type or expression are dependent 3990853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis Operand->getType()->isDependentType(), 4004f32786ac45210143654390177105eb749b614e9Ted Kremenek Operand->getType()->isInstantiationDependentType(), 4014f32786ac45210143654390177105eb749b614e9Ted Kremenek Operand->getType()->containsUnexpandedParameterPack()), 4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Operand(Operand), Range(R) { } 4034f32786ac45210143654390177105eb749b614e9Ted Kremenek 4044f32786ac45210143654390177105eb749b614e9Ted Kremenek CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 4050853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 406914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor // typeid is never type-dependent (C++ [temp.dep.expr]p4) 407914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor false, 408914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor // typeid is value-dependent if the type or expression are dependent 409914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor Operand->isTypeDependent() || Operand->isValueDependent(), 410914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor Operand->isInstantiationDependent(), 411914ed9d30e9abf829a62aa996b083b1e47c19ff6Douglas Gregor Operand->containsUnexpandedParameterPack()), 412405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor Operand(Operand), Range(R) { } 413405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor 414f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar CXXTypeidExpr(EmptyShell Empty, bool isExpr) 415389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis : Expr(CXXTypeidExprClass, Empty) { 416389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis if (isExpr) 41777accc11f04ed4ff9afd4e27d430144d4714be56Steve Naroff Operand = (Expr*)0; 4183c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl else 419b85bca2676b433ae555db09de4dd2823ff13b856Zhongxing Xu Operand = (TypeSourceInfo*)0; 420313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor } 421313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor 422313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 423313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor 424313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// \brief Retrieves the type operand of this typeid() expression after 425313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 426313e26c4e81f0e467490a530548450f4c824a6c4Douglas Gregor QualType getTypeOperand() const; 4277d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor 428f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar /// \brief Retrieve source information for the type operand. 42915727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis TypeSourceInfo *getTypeOperandSourceInfo() const { 43015727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 43115727ddb11405c45372150b5bfb07dbfa4c9960bArgyrios Kyrtzidis return Operand.get<TypeSourceInfo *>(); 432eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 433eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 434eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 435eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 436f96b524306ccfa623235d375deee79637bd38f29Steve Naroff Operand = TSI; 437f96b524306ccfa623235d375deee79637bd38f29Steve Naroff } 438f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar 439213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor Expr *getExprOperand() const { 440213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 441213f18b3d654de7d1c7cf4a329ea9d3db1c50b6aDouglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 442eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 443eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 444eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor void setExprOperand(Expr *E) { 445f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 446eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor Operand = E; 447eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 448eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 449f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar SourceRange getSourceRange() const { return Range; } 450eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor void setSourceRange(SourceRange R) { Range = R; } 451eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 452f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar static bool classof(const Stmt *T) { 453eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return T->getStmtClass() == CXXTypeidExprClass; 454eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 455eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor static bool classof(const CXXTypeidExpr *) { return true; } 456eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 457eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor // Iterators 458eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor child_range children() { 459eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor if (isTypeOperand()) return child_range(); 460eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 461eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor return child_range(begin, begin + 1); 462eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor } 463eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor}; 464eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 465eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 466eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor/// the _GUID that corresponds to the supplied type or expression. 467eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor/// 468eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 469eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregorclass CXXUuidofExpr : public Expr { 470eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregorprivate: 471eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 472eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor SourceRange Range; 473eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor 474eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregorpublic: 4758538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 476eb8837b88c18631c69ac75f64ab1853762063180Douglas Gregor : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 477f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar false, Operand->getType()->isDependentType(), 478f772d1e2a5688572d07f42896a50ac57a4a41fe8Daniel Dunbar Operand->getType()->isInstantiationDependentType(), 4799b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor Operand->getType()->containsUnexpandedParameterPack()), 4809b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor Operand(Operand), Range(R) { } 4819b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor 4829b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 4839b7db6200d366e4964d63ae1f33c7b9d7b9831cbDouglas Gregor : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 48489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor false, Operand->isTypeDependent(), 48589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor Operand->isInstantiationDependent(), 48689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor Operand->containsUnexpandedParameterPack()), 48789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor Operand(Operand), Range(R) { } 48889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor 48989d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor CXXUuidofExpr(EmptyShell Empty, bool isExpr) 49089d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor : Expr(CXXUuidofExprClass, Empty) { 49189d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor if (isExpr) 49289d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor Operand = (Expr*)0; 49389d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor else 49489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor Operand = (TypeSourceInfo*)0; 495788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor } 496788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 497788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 498788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor 499788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// \brief Retrieves the type operand of this __uuidof() expression after 500788f5a1242c04762f91eaa7565c07b9865846d88Douglas Gregor /// various required adjustments (removing reference types, cv-qualifiers). 501a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor QualType getTypeOperand() const; 502405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor 503405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor /// \brief Retrieve source information for the type operand. 504405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor TypeSourceInfo *getTypeOperandSourceInfo() const { 505405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 506405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor return Operand.get<TypeSourceInfo *>(); 507405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor } 508405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor 509405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 510405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 511405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor Operand = TSI; 512405634b215f19eec7183bd8005e34aa5a02f64a1Douglas Gregor } 513a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 514a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor Expr *getExprOperand() const { 51587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 51687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return static_cast<Expr*>(Operand.get<Stmt *>()); 51787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 51887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 51987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor void setExprOperand(Expr *E) { 52087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 52187c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor Operand = E; 52287c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor } 52387c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 52487c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor SourceRange getSourceRange() const { return Range; } 52587c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor void setSourceRange(SourceRange R) { Range = R; } 52687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 52787c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor static bool classof(const Stmt *T) { 52887c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor return T->getStmtClass() == CXXUuidofExprClass; 529389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis } 530389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis static bool classof(const CXXUuidofExpr *) { return true; } 53175dfb65c38d51772df9a00ce2d2feeefd55667adChris Lattner 532389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis // Iterators 533df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor child_range children() { 534df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor if (isTypeOperand()) return child_range(); 535df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 536df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor return child_range(begin, begin + 1); 537df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor } 538df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor}; 539b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis 540b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis/// CXXThisExpr - Represents the "this" expression in C++, which is a 5414db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// pointer to the object on which the current member function is 5424db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor/// executing (C++ [expr.prim]p3). Example: 543b1c86492f9a9bef01a4567408c22f961bbd604feArgyrios Kyrtzidis/// 544b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis/// @code 545b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis/// class Foo { 546b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis/// public: 547b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis/// void bar(); 548b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis/// void test() { this->bar(); } 5493c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl/// }; 5500853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis/// @endcode 5513c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redlclass CXXThisExpr : public Expr { 5520853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis SourceLocation Loc; 5535262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar bool Implicit : 1; 5545262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar 55531b87d8006d4863dd9b17e515ac720941efc38e3Daniel Dunbarpublic: 5563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 5573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 55828019772db70d4547be05a042eb950bc910f134fDouglas Gregor // 'this' is type-dependent if the class type of the enclosing 559389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis // member function is dependent (C++ [temp.dep.expr]p2) 5605cf48766d626ff6b223acc9d4b7e415ca8480836Ted Kremenek Type->isDependentType(), Type->isDependentType(), 5614db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor Type->isInstantiationDependentType(), 562a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 563a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor Loc(L), Implicit(isImplicit) { } 564521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 5654cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 5664cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 5674cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor SourceLocation getLocation() const { return Loc; } 5684cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 5694cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 5704cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor SourceRange getSourceRange() const { return SourceRange(Loc); } 5714cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 5724cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor bool isImplicit() const { return Implicit; } 5734cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor void setImplicit(bool I) { Implicit = I; } 5744cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor 5754cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor static bool classof(const Stmt *T) { 5764cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor return T->getStmtClass() == CXXThisExprClass; 5774cd912aa94656697a44c3ebb159f05060300524eDouglas Gregor } 578d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis static bool classof(const CXXThisExpr *) { return true; } 579d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis 580d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis // Iterators 581d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis child_range children() { return child_range(); } 582d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis}; 583d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis 584d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 585d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis/// 'throw' and 'throw' assignment-expression. When 586d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis/// assignment-expression isn't present, Op will be null. 587d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis/// 588d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidisclass CXXThrowExpr : public Expr { 589d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis Stmt *Op; 590d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis SourceLocation ThrowLoc; 591d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis /// \brief Whether the thrown variable (if any) is in scope. 592d808bd2978bd4ac95a92b309b038452b533fd7a0Argyrios Kyrtzidis unsigned IsThrownVariableInScope : 1; 593521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 594521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar friend class ASTStmtReader; 595521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar 596521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbarpublic: 597f7acc37450d59ef751df73acb91de73850cc6517Daniel Dunbar // Ty is the void type which is used as the result type of the 598521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar // exepression. The l is the location of the throw keyword. expr 5995262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar // can by null, if the optional expression to throw isn't present. 6005262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 601521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar bool IsThrownVariableInScope) : 602521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 603521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar expr && expr->isInstantiationDependent(), 604f7acc37450d59ef751df73acb91de73850cc6517Daniel Dunbar expr && expr->containsUnexpandedParameterPack()), 60528019772db70d4547be05a042eb950bc910f134fDouglas Gregor Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 606a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 60744c181aec37789f25f6c15543c164416f72e562aDouglas Gregor 608df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 60987c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 61087c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 611521bf9c529e653ab28896d027352d3e16e2672d5Daniel Dunbar SourceLocation getThrowLoc() const { return ThrowLoc; } 6127b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar 6137b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// \brief Determines whether the variable thrown by this expression (if any!) 6147b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// is within the innermost try block. 6157b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// 6167b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// This information is required to determine whether the NRVO can apply to 6177b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar /// this variable. 6187b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 6195262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar 6205262fda30b876c8aae95f2eb92e349418d6b14bbDaniel Dunbar SourceRange getSourceRange() const { 6217b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar if (getSubExpr() == 0) 622869824e87940f97b87064db2df2861e82e08a8c6Daniel Dunbar return SourceRange(ThrowLoc, ThrowLoc); 6237b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 6247b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar } 6257b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar 6267b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar static bool classof(const Stmt *T) { 6277b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar return T->getStmtClass() == CXXThrowExprClass; 62828019772db70d4547be05a042eb950bc910f134fDouglas Gregor } 629869824e87940f97b87064db2df2861e82e08a8c6Daniel Dunbar static bool classof(const CXXThrowExpr *) { return true; } 6307b55668db7618334cc40011d3c1e128524d89462Daniel Dunbar 631e47be3e9682e82da15059006f43c7f3c021e4fffDouglas Gregor // Iterators 6324db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor child_range children() { 633a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor return child_range(&Op, Op ? &Op+1 : &Op); 634299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis } 635df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor}; 63687c08a5d6b9e1e44ae6f554df40139d3a6f60b33Douglas Gregor 63799ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 63899ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor/// function call argument that was created from the corresponding 63999ba202f659e1885fa5ee114f97c97cf6a857491Douglas Gregor/// parameter's default argument, when the call did not explicitly 640abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor/// supply arguments for all of the parameters. 641abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregorclass CXXDefaultArgExpr : public Expr { 642abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// \brief The parameter whose default is being used. 643abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// 644abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// When the bit is set, the subexpression is stored after the 645abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 646abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// actual default expression is the subexpression. 647abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 6481abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor 6491abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor /// \brief The location where the default argument expression was used. 6501abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor SourceLocation Loc; 6511abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor 652cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 653cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor : Expr(SC, 654cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor param->hasUnparsedDefaultArg() 655cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor ? param->getType().getNonReferenceType() 656cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor : param->getDefaultArg()->getType(), 657cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor param->getDefaultArg()->getValueKind(), 658cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor param->getDefaultArg()->getObjectKind(), false, false, false, false), 659cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor Param(param, false), Loc(Loc) { } 660cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor 661cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 662cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor Expr *SubExpr) 6631abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor : Expr(SC, SubExpr->getType(), 6642283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor SubExpr->getValueKind(), SubExpr->getObjectKind(), 6652283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor false, false, false, false), 6661abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor Param(param, true), Loc(Loc) { 6671abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor *reinterpret_cast<Expr **>(this + 1) = SubExpr; 668cee235cdf0b8047761ffac598c4c3a32ab7411a2Douglas Gregor } 6691abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor 6701abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregorpublic: 6711abc6bca3d7fb0e7b1e40fbcad6cfb5e10594548Douglas Gregor CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 6722283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor 6732283d79155a3e82442fce124ce5fd704ca138801Douglas Gregor 6747ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor // Param is the parameter whose default argument is used by this 6757ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor // expression. 6767ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 6777ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor ParmVarDecl *Param) { 6787ae2faafd30524ef5f863bb3b8701977888839bbDouglas Gregor return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 679b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis } 680b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis 681b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis // Param is the parameter whose default argument is used by this 682b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis // expression, and SubExpr is the expression that will actually be used. 683b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis static CXXDefaultArgExpr *Create(ASTContext &C, 6840853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis SourceLocation Loc, 6850853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis ParmVarDecl *Param, 6860853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis Expr *SubExpr); 6870853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis 6880853a02c3b04d96a3c432b883e403175c954cd81Argyrios Kyrtzidis // Retrieve the parameter that the argument was created from. 689 const ParmVarDecl *getParam() const { return Param.getPointer(); } 690 ParmVarDecl *getParam() { return Param.getPointer(); } 691 692 // Retrieve the actual argument to the function call. 693 const Expr *getExpr() const { 694 if (Param.getInt()) 695 return *reinterpret_cast<Expr const * const*> (this + 1); 696 return getParam()->getDefaultArg(); 697 } 698 Expr *getExpr() { 699 if (Param.getInt()) 700 return *reinterpret_cast<Expr **> (this + 1); 701 return getParam()->getDefaultArg(); 702 } 703 704 /// \brief Retrieve the location where this default argument was actually 705 /// used. 706 SourceLocation getUsedLocation() const { return Loc; } 707 708 SourceRange getSourceRange() const { 709 // Default argument expressions have no representation in the 710 // source, so they have an empty source range. 711 return SourceRange(); 712 } 713 714 static bool classof(const Stmt *T) { 715 return T->getStmtClass() == CXXDefaultArgExprClass; 716 } 717 static bool classof(const CXXDefaultArgExpr *) { return true; } 718 719 // Iterators 720 child_range children() { return child_range(); } 721 722 friend class ASTStmtReader; 723 friend class ASTStmtWriter; 724}; 725 726/// CXXTemporary - Represents a C++ temporary. 727class CXXTemporary { 728 /// Destructor - The destructor that needs to be called. 729 const CXXDestructorDecl *Destructor; 730 731 CXXTemporary(const CXXDestructorDecl *destructor) 732 : Destructor(destructor) { } 733 734public: 735 static CXXTemporary *Create(ASTContext &C, 736 const CXXDestructorDecl *Destructor); 737 738 const CXXDestructorDecl *getDestructor() const { return Destructor; } 739 void setDestructor(const CXXDestructorDecl *Dtor) { 740 Destructor = Dtor; 741 } 742}; 743 744/// \brief Represents binding an expression to a temporary. 745/// 746/// This ensures the destructor is called for the temporary. It should only be 747/// needed for non-POD, non-trivially destructable class types. For example: 748/// 749/// \code 750/// struct S { 751/// S() { } // User defined constructor makes S non-POD. 752/// ~S() { } // User defined destructor makes it non-trivial. 753/// }; 754/// void test() { 755/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 756/// } 757/// \endcode 758class CXXBindTemporaryExpr : public Expr { 759 CXXTemporary *Temp; 760 761 Stmt *SubExpr; 762 763 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 764 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 765 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 766 SubExpr->isValueDependent(), 767 SubExpr->isInstantiationDependent(), 768 SubExpr->containsUnexpandedParameterPack()), 769 Temp(temp), SubExpr(SubExpr) { } 770 771public: 772 CXXBindTemporaryExpr(EmptyShell Empty) 773 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 774 775 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 776 Expr* SubExpr); 777 778 CXXTemporary *getTemporary() { return Temp; } 779 const CXXTemporary *getTemporary() const { return Temp; } 780 void setTemporary(CXXTemporary *T) { Temp = T; } 781 782 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 783 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 784 void setSubExpr(Expr *E) { SubExpr = E; } 785 786 SourceRange getSourceRange() const { 787 return SubExpr->getSourceRange(); 788 } 789 790 // Implement isa/cast/dyncast/etc. 791 static bool classof(const Stmt *T) { 792 return T->getStmtClass() == CXXBindTemporaryExprClass; 793 } 794 static bool classof(const CXXBindTemporaryExpr *) { return true; } 795 796 // Iterators 797 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 798}; 799 800/// CXXConstructExpr - Represents a call to a C++ constructor. 801class CXXConstructExpr : public Expr { 802public: 803 enum ConstructionKind { 804 CK_Complete, 805 CK_NonVirtualBase, 806 CK_VirtualBase, 807 CK_Delegating 808 }; 809 810private: 811 CXXConstructorDecl *Constructor; 812 813 SourceLocation Loc; 814 SourceRange ParenRange; 815 unsigned NumArgs : 16; 816 bool Elidable : 1; 817 bool HadMultipleCandidates : 1; 818 bool ListInitialization : 1; 819 bool ZeroInitialization : 1; 820 unsigned ConstructKind : 2; 821 Stmt **Args; 822 823protected: 824 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 825 SourceLocation Loc, 826 CXXConstructorDecl *d, bool elidable, 827 Expr **args, unsigned numargs, 828 bool HadMultipleCandidates, 829 bool ListInitialization, 830 bool ZeroInitialization, 831 ConstructionKind ConstructKind, 832 SourceRange ParenRange); 833 834 /// \brief Construct an empty C++ construction expression. 835 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 836 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 837 HadMultipleCandidates(false), ListInitialization(false), 838 ZeroInitialization(false), ConstructKind(0), Args(0) 839 { } 840 841public: 842 /// \brief Construct an empty C++ construction expression. 843 explicit CXXConstructExpr(EmptyShell Empty) 844 : Expr(CXXConstructExprClass, Empty), Constructor(0), 845 NumArgs(0), Elidable(false), HadMultipleCandidates(false), 846 ListInitialization(false), ZeroInitialization(false), 847 ConstructKind(0), Args(0) 848 { } 849 850 static CXXConstructExpr *Create(ASTContext &C, QualType T, 851 SourceLocation Loc, 852 CXXConstructorDecl *D, bool Elidable, 853 Expr **Args, unsigned NumArgs, 854 bool HadMultipleCandidates, 855 bool ListInitialization, 856 bool ZeroInitialization, 857 ConstructionKind ConstructKind, 858 SourceRange ParenRange); 859 860 CXXConstructorDecl* getConstructor() const { return Constructor; } 861 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 862 863 SourceLocation getLocation() const { return Loc; } 864 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 865 866 /// \brief Whether this construction is elidable. 867 bool isElidable() const { return Elidable; } 868 void setElidable(bool E) { Elidable = E; } 869 870 /// \brief Whether the referred constructor was resolved from 871 /// an overloaded set having size greater than 1. 872 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 873 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 874 875 /// \brief Whether this constructor call was written as list-initialization. 876 bool isListInitialization() const { return ListInitialization; } 877 void setListInitialization(bool V) { ListInitialization = V; } 878 879 /// \brief Whether this construction first requires 880 /// zero-initialization before the initializer is called. 881 bool requiresZeroInitialization() const { return ZeroInitialization; } 882 void setRequiresZeroInitialization(bool ZeroInit) { 883 ZeroInitialization = ZeroInit; 884 } 885 886 /// \brief Determines whether this constructor is actually constructing 887 /// a base class (rather than a complete object). 888 ConstructionKind getConstructionKind() const { 889 return (ConstructionKind)ConstructKind; 890 } 891 void setConstructionKind(ConstructionKind CK) { 892 ConstructKind = CK; 893 } 894 895 typedef ExprIterator arg_iterator; 896 typedef ConstExprIterator const_arg_iterator; 897 898 arg_iterator arg_begin() { return Args; } 899 arg_iterator arg_end() { return Args + NumArgs; } 900 const_arg_iterator arg_begin() const { return Args; } 901 const_arg_iterator arg_end() const { return Args + NumArgs; } 902 903 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 904 unsigned getNumArgs() const { return NumArgs; } 905 906 /// getArg - Return the specified argument. 907 Expr *getArg(unsigned Arg) { 908 assert(Arg < NumArgs && "Arg access out of range!"); 909 return cast<Expr>(Args[Arg]); 910 } 911 const Expr *getArg(unsigned Arg) const { 912 assert(Arg < NumArgs && "Arg access out of range!"); 913 return cast<Expr>(Args[Arg]); 914 } 915 916 /// setArg - Set the specified argument. 917 void setArg(unsigned Arg, Expr *ArgExpr) { 918 assert(Arg < NumArgs && "Arg access out of range!"); 919 Args[Arg] = ArgExpr; 920 } 921 922 SourceRange getSourceRange() const; 923 SourceRange getParenRange() const { return ParenRange; } 924 925 static bool classof(const Stmt *T) { 926 return T->getStmtClass() == CXXConstructExprClass || 927 T->getStmtClass() == CXXTemporaryObjectExprClass; 928 } 929 static bool classof(const CXXConstructExpr *) { return true; } 930 931 // Iterators 932 child_range children() { 933 return child_range(&Args[0], &Args[0]+NumArgs); 934 } 935 936 friend class ASTStmtReader; 937}; 938 939/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 940/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 941/// x = int(0.5); 942class CXXFunctionalCastExpr : public ExplicitCastExpr { 943 SourceLocation TyBeginLoc; 944 SourceLocation RParenLoc; 945 946 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 947 TypeSourceInfo *writtenTy, 948 SourceLocation tyBeginLoc, CastKind kind, 949 Expr *castExpr, unsigned pathSize, 950 SourceLocation rParenLoc) 951 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 952 castExpr, pathSize, writtenTy), 953 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 954 955 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 956 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 957 958public: 959 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 960 ExprValueKind VK, 961 TypeSourceInfo *Written, 962 SourceLocation TyBeginLoc, 963 CastKind Kind, Expr *Op, 964 const CXXCastPath *Path, 965 SourceLocation RPLoc); 966 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 967 unsigned PathSize); 968 969 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 970 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 971 SourceLocation getRParenLoc() const { return RParenLoc; } 972 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 973 974 SourceRange getSourceRange() const { 975 return SourceRange(TyBeginLoc, RParenLoc); 976 } 977 static bool classof(const Stmt *T) { 978 return T->getStmtClass() == CXXFunctionalCastExprClass; 979 } 980 static bool classof(const CXXFunctionalCastExpr *) { return true; } 981}; 982 983/// @brief Represents a C++ functional cast expression that builds a 984/// temporary object. 985/// 986/// This expression type represents a C++ "functional" cast 987/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 988/// constructor to build a temporary object. With N == 1 arguments the 989/// functional cast expression will be represented by CXXFunctionalCastExpr. 990/// Example: 991/// @code 992/// struct X { X(int, float); } 993/// 994/// X create_X() { 995/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 996/// }; 997/// @endcode 998class CXXTemporaryObjectExpr : public CXXConstructExpr { 999 TypeSourceInfo *Type; 1000 1001public: 1002 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1003 TypeSourceInfo *Type, 1004 Expr **Args,unsigned NumArgs, 1005 SourceRange parenRange, 1006 bool HadMultipleCandidates, 1007 bool ZeroInitialization = false); 1008 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1009 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1010 1011 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1012 1013 SourceRange getSourceRange() const; 1014 1015 static bool classof(const Stmt *T) { 1016 return T->getStmtClass() == CXXTemporaryObjectExprClass; 1017 } 1018 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 1019 1020 friend class ASTStmtReader; 1021}; 1022 1023/// \brief A C++ lambda expression, which produces a function object 1024/// (of unspecified type) that can be invoked later. 1025/// 1026/// Example: 1027/// \code 1028/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1029/// values.erase(std::remove_if(values.begin(), values.end(), 1030// [=](double value) { return value > cutoff; }); 1031/// } 1032/// \endcode 1033/// 1034/// Lambda expressions can capture local variables, either by copying 1035/// the values of those local variables at the time the function 1036/// object is constructed (not when it is called!) or by holding a 1037/// reference to the local variable. These captures can occur either 1038/// implicitly or can be written explicitly between the square 1039/// brackets ([...]) that start the lambda expression. 1040class LambdaExpr : public Expr { 1041 enum { 1042 /// \brief Flag used by the Capture class to indicate that the given 1043 /// capture was implicit. 1044 Capture_Implicit = 0x01, 1045 1046 /// \brief Flag used by the Capture class to indciate that the 1047 /// given capture was by-copy. 1048 Capture_ByCopy = 0x02 1049 }; 1050 1051 /// \brief The source range that covers the lambda introducer ([...]). 1052 SourceRange IntroducerRange; 1053 1054 /// \brief The number of captures. 1055 unsigned NumCaptures : 16; 1056 1057 /// \brief The default capture kind, which is a value of type 1058 /// LambdaCaptureDefault. 1059 unsigned CaptureDefault : 2; 1060 1061 /// \brief Whether this lambda had an explicit parameter list vs. an 1062 /// implicit (and empty) parameter list. 1063 unsigned ExplicitParams : 1; 1064 1065 /// \brief Whether this lambda had the result type explicitly specified. 1066 unsigned ExplicitResultType : 1; 1067 1068 /// \brief Whether there are any array index variables stored at the end of 1069 /// this lambda expression. 1070 unsigned HasArrayIndexVars : 1; 1071 1072 /// \brief The location of the closing brace ('}') that completes 1073 /// the lambda. 1074 /// 1075 /// The location of the brace is also available by looking up the 1076 /// function call operator in the lambda class. However, it is 1077 /// stored here to improve the performance of getSourceRange(), and 1078 /// to avoid having to deserialize the function call operator from a 1079 /// module file just to determine the source range. 1080 SourceLocation ClosingBrace; 1081 1082 // Note: The capture initializers are stored directly after the lambda 1083 // expression, along with the index variables used to initialize by-copy 1084 // array captures. 1085 1086public: 1087 /// \brief Describes the capture of either a variable or 'this'. 1088 class Capture { 1089 llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 1090 SourceLocation Loc; 1091 SourceLocation EllipsisLoc; 1092 1093 friend class ASTStmtReader; 1094 friend class ASTStmtWriter; 1095 1096 public: 1097 /// \brief Create a new capture. 1098 /// 1099 /// \param Loc The source location associated with this capture. 1100 /// 1101 /// \param Kind The kind of capture (this, byref, bycopy). 1102 /// 1103 /// \param Implicit Whether the capture was implicit or explicit. 1104 /// 1105 /// \param Var The local variable being captured, or null if capturing this. 1106 /// 1107 /// \param EllipsisLoc The location of the ellipsis (...) for a 1108 /// capture that is a pack expansion, or an invalid source 1109 /// location to indicate that this is not a pack expansion. 1110 Capture(SourceLocation Loc, bool Implicit, 1111 LambdaCaptureKind Kind, VarDecl *Var = 0, 1112 SourceLocation EllipsisLoc = SourceLocation()); 1113 1114 /// \brief Determine the kind of capture. 1115 LambdaCaptureKind getCaptureKind() const; 1116 1117 /// \brief Determine whether this capture handles the C++ 'this' 1118 /// pointer. 1119 bool capturesThis() const { return VarAndBits.getPointer() == 0; } 1120 1121 /// \brief Determine whether this capture handles a variable. 1122 bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 1123 1124 /// \brief Retrieve the declaration of the local variable being 1125 /// captured. 1126 /// 1127 /// This operation is only valid if this capture does not capture 1128 /// 'this'. 1129 VarDecl *getCapturedVar() const { 1130 assert(!capturesThis() && "No variable available for 'this' capture"); 1131 return VarAndBits.getPointer(); 1132 } 1133 1134 /// \brief Determine whether this was an implicit capture (not 1135 /// written between the square brackets introducing the lambda). 1136 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 1137 1138 /// \brief Determine whether this was an explicit capture, written 1139 /// between the square brackets introducing the lambda. 1140 bool isExplicit() const { return !isImplicit(); } 1141 1142 /// \brief Retrieve the source location of the capture. 1143 /// 1144 /// For an explicit capture, this returns the location of the 1145 /// explicit capture in the source. For an implicit capture, this 1146 /// returns the location at which the variable or 'this' was first 1147 /// used. 1148 SourceLocation getLocation() const { return Loc; } 1149 1150 /// \brief Determine whether this capture is a pack expansion, 1151 /// which captures a function parameter pack. 1152 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1153 1154 /// \brief Retrieve the location of the ellipsis for a capture 1155 /// that is a pack expansion. 1156 SourceLocation getEllipsisLoc() const { 1157 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1158 return EllipsisLoc; 1159 } 1160 }; 1161 1162private: 1163 /// \brief Construct a lambda expression. 1164 LambdaExpr(QualType T, SourceRange IntroducerRange, 1165 LambdaCaptureDefault CaptureDefault, 1166 ArrayRef<Capture> Captures, 1167 bool ExplicitParams, 1168 bool ExplicitResultType, 1169 ArrayRef<Expr *> CaptureInits, 1170 ArrayRef<VarDecl *> ArrayIndexVars, 1171 ArrayRef<unsigned> ArrayIndexStarts, 1172 SourceLocation ClosingBrace, 1173 unsigned ManglingNumber, 1174 Decl *ContextDecl); 1175 1176 /// \brief Construct an empty lambda expression. 1177 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1178 : Expr(LambdaExprClass, Empty), 1179 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1180 ExplicitResultType(false), HasArrayIndexVars(true) { 1181 getStoredStmts()[NumCaptures] = 0; 1182 } 1183 1184 Stmt **getStoredStmts() const { 1185 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1186 } 1187 1188 /// \brief Retrieve the mapping from captures to the first array index 1189 /// variable. 1190 unsigned *getArrayIndexStarts() const { 1191 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1192 } 1193 1194 /// \brief Retrieve the complete set of array-index variables. 1195 VarDecl **getArrayIndexVars() const { 1196 return reinterpret_cast<VarDecl **>( 1197 getArrayIndexStarts() + NumCaptures + 1); 1198 } 1199 1200public: 1201 /// \brief Construct a new lambda expression. 1202 static LambdaExpr *Create(ASTContext &C, 1203 CXXRecordDecl *Class, 1204 SourceRange IntroducerRange, 1205 LambdaCaptureDefault CaptureDefault, 1206 ArrayRef<Capture> Captures, 1207 bool ExplicitParams, 1208 bool ExplicitResultType, 1209 ArrayRef<Expr *> CaptureInits, 1210 ArrayRef<VarDecl *> ArrayIndexVars, 1211 ArrayRef<unsigned> ArrayIndexStarts, 1212 SourceLocation ClosingBrace, 1213 unsigned ManglingNumber, 1214 Decl *ContextDecl); 1215 1216 /// \brief Construct a new lambda expression that will be deserialized from 1217 /// an external source. 1218 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 1219 unsigned NumArrayIndexVars); 1220 1221 /// \brief Determine the default capture kind for this lambda. 1222 LambdaCaptureDefault getCaptureDefault() const { 1223 return static_cast<LambdaCaptureDefault>(CaptureDefault); 1224 } 1225 1226 /// \brief An iterator that walks over the captures of the lambda, 1227 /// both implicit and explicit. 1228 typedef const Capture *capture_iterator; 1229 1230 /// \brief Retrieve an iterator pointing to the first lambda capture. 1231 capture_iterator capture_begin() const; 1232 1233 /// \brief Retrieve an iterator pointing past the end of the 1234 /// sequence of lambda captures. 1235 capture_iterator capture_end() const; 1236 1237 /// \brief Determine the number of captures in this lambda. 1238 unsigned capture_size() const { return NumCaptures; } 1239 1240 /// \brief Retrieve an iterator pointing to the first explicit 1241 /// lambda capture. 1242 capture_iterator explicit_capture_begin() const; 1243 1244 /// \brief Retrieve an iterator pointing past the end of the sequence of 1245 /// explicit lambda captures. 1246 capture_iterator explicit_capture_end() const; 1247 1248 /// \brief Retrieve an iterator pointing to the first implicit 1249 /// lambda capture. 1250 capture_iterator implicit_capture_begin() const; 1251 1252 /// \brief Retrieve an iterator pointing past the end of the sequence of 1253 /// implicit lambda captures. 1254 capture_iterator implicit_capture_end() const; 1255 1256 /// \brief Iterator that walks over the capture initialization 1257 /// arguments. 1258 typedef Expr **capture_init_iterator; 1259 1260 /// \brief Retrieve the first initialization argument for this 1261 /// lambda expression (which initializes the first capture field). 1262 capture_init_iterator capture_init_begin() const { 1263 return reinterpret_cast<Expr **>(getStoredStmts()); 1264 } 1265 1266 /// \brief Retrieve the iterator pointing one past the last 1267 /// initialization argument for this lambda expression. 1268 capture_init_iterator capture_init_end() const { 1269 return capture_init_begin() + NumCaptures; 1270 } 1271 1272 /// \brief Retrieve the set of index variables used in the capture 1273 /// initializer of an array captured by copy. 1274 /// 1275 /// \param Iter The iterator that points at the capture initializer for 1276 /// which we are extracting the corresponding index variables. 1277 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 1278 1279 /// \brief Retrieve the source range covering the lambda introducer, 1280 /// which contains the explicit capture list surrounded by square 1281 /// brackets ([...]). 1282 SourceRange getIntroducerRange() const { return IntroducerRange; } 1283 1284 /// \brief Retrieve the class that corresponds to the lambda, which 1285 /// stores the captures in its fields and provides the various 1286 /// operations permitted on a lambda (copying, calling). 1287 CXXRecordDecl *getLambdaClass() const; 1288 1289 /// \brief Retrieve the function call operator associated with this 1290 /// lambda expression. 1291 CXXMethodDecl *getCallOperator() const; 1292 1293 /// \brief Retrieve the body of the lambda. 1294 CompoundStmt *getBody() const; 1295 1296 /// \brief Determine whether the lambda is mutable, meaning that any 1297 /// captures values can be modified. 1298 bool isMutable() const; 1299 1300 /// \brief Determine whether this lambda has an explicit parameter 1301 /// list vs. an implicit (empty) parameter list. 1302 bool hasExplicitParameters() const { return ExplicitParams; } 1303 1304 /// \brief Whether this lambda had its result type explicitly specified. 1305 bool hasExplicitResultType() const { return ExplicitResultType; } 1306 1307 static bool classof(const Stmt *T) { 1308 return T->getStmtClass() == LambdaExprClass; 1309 } 1310 static bool classof(const LambdaExpr *) { return true; } 1311 1312 SourceRange getSourceRange() const { 1313 return SourceRange(IntroducerRange.getBegin(), ClosingBrace); 1314 } 1315 1316 child_range children() { 1317 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1318 } 1319 1320 friend class ASTStmtReader; 1321 friend class ASTStmtWriter; 1322}; 1323 1324/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1325/// Expression "T()" which creates a value-initialized rvalue of type 1326/// T, which is a non-class type. 1327/// 1328class CXXScalarValueInitExpr : public Expr { 1329 SourceLocation RParenLoc; 1330 TypeSourceInfo *TypeInfo; 1331 1332 friend class ASTStmtReader; 1333 1334public: 1335 /// \brief Create an explicitly-written scalar-value initialization 1336 /// expression. 1337 CXXScalarValueInitExpr(QualType Type, 1338 TypeSourceInfo *TypeInfo, 1339 SourceLocation rParenLoc ) : 1340 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1341 false, false, Type->isInstantiationDependentType(), false), 1342 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1343 1344 explicit CXXScalarValueInitExpr(EmptyShell Shell) 1345 : Expr(CXXScalarValueInitExprClass, Shell) { } 1346 1347 TypeSourceInfo *getTypeSourceInfo() const { 1348 return TypeInfo; 1349 } 1350 1351 SourceLocation getRParenLoc() const { return RParenLoc; } 1352 1353 SourceRange getSourceRange() const; 1354 1355 static bool classof(const Stmt *T) { 1356 return T->getStmtClass() == CXXScalarValueInitExprClass; 1357 } 1358 static bool classof(const CXXScalarValueInitExpr *) { return true; } 1359 1360 // Iterators 1361 child_range children() { return child_range(); } 1362}; 1363 1364/// CXXNewExpr - A new expression for memory allocation and constructor calls, 1365/// e.g: "new CXXNewExpr(foo)". 1366class CXXNewExpr : public Expr { 1367 // Was the usage ::new, i.e. is the global new to be used? 1368 bool GlobalNew : 1; 1369 // Do we allocate an array? If so, the first SubExpr is the size expression. 1370 bool Array : 1; 1371 // If this is an array allocation, does the usual deallocation 1372 // function for the allocated type want to know the allocated size? 1373 bool UsualArrayDeleteWantsSize : 1; 1374 // The number of placement new arguments. 1375 unsigned NumPlacementArgs : 13; 1376 // What kind of initializer do we have? Could be none, parens, or braces. 1377 // In storage, we distinguish between "none, and no initializer expr", and 1378 // "none, but an implicit initializer expr". 1379 unsigned StoredInitializationStyle : 2; 1380 // Contains an optional array size expression, an optional initialization 1381 // expression, and any number of optional placement arguments, in that order. 1382 Stmt **SubExprs; 1383 // Points to the allocation function used. 1384 FunctionDecl *OperatorNew; 1385 // Points to the deallocation function used in case of error. May be null. 1386 FunctionDecl *OperatorDelete; 1387 1388 /// \brief The allocated type-source information, as written in the source. 1389 TypeSourceInfo *AllocatedTypeInfo; 1390 1391 /// \brief If the allocated type was expressed as a parenthesized type-id, 1392 /// the source range covering the parenthesized type-id. 1393 SourceRange TypeIdParens; 1394 1395 /// \brief Location of the first token. 1396 SourceLocation StartLoc; 1397 1398 /// \brief Source-range of a paren-delimited initializer. 1399 SourceRange DirectInitRange; 1400 1401 friend class ASTStmtReader; 1402 friend class ASTStmtWriter; 1403public: 1404 enum InitializationStyle { 1405 NoInit, ///< New-expression has no initializer as written. 1406 CallInit, ///< New-expression has a C++98 paren-delimited initializer. 1407 ListInit ///< New-expression has a C++11 list-initializer. 1408 }; 1409 1410 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1411 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1412 Expr **placementArgs, unsigned numPlaceArgs, 1413 SourceRange typeIdParens, Expr *arraySize, 1414 InitializationStyle initializationStyle, Expr *initializer, 1415 QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1416 SourceLocation startLoc, SourceRange directInitRange); 1417 explicit CXXNewExpr(EmptyShell Shell) 1418 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1419 1420 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1421 bool hasInitializer); 1422 1423 QualType getAllocatedType() const { 1424 assert(getType()->isPointerType()); 1425 return getType()->getAs<PointerType>()->getPointeeType(); 1426 } 1427 1428 TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1429 return AllocatedTypeInfo; 1430 } 1431 1432 /// \brief True if the allocation result needs to be null-checked. 1433 /// C++0x [expr.new]p13: 1434 /// If the allocation function returns null, initialization shall 1435 /// not be done, the deallocation function shall not be called, 1436 /// and the value of the new-expression shall be null. 1437 /// An allocation function is not allowed to return null unless it 1438 /// has a non-throwing exception-specification. The '03 rule is 1439 /// identical except that the definition of a non-throwing 1440 /// exception specification is just "is it throw()?". 1441 bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1442 1443 FunctionDecl *getOperatorNew() const { return OperatorNew; } 1444 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1445 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1446 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1447 1448 bool isArray() const { return Array; } 1449 Expr *getArraySize() { 1450 return Array ? cast<Expr>(SubExprs[0]) : 0; 1451 } 1452 const Expr *getArraySize() const { 1453 return Array ? cast<Expr>(SubExprs[0]) : 0; 1454 } 1455 1456 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1457 Expr **getPlacementArgs() { 1458 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1459 } 1460 1461 Expr *getPlacementArg(unsigned i) { 1462 assert(i < NumPlacementArgs && "Index out of range"); 1463 return getPlacementArgs()[i]; 1464 } 1465 const Expr *getPlacementArg(unsigned i) const { 1466 assert(i < NumPlacementArgs && "Index out of range"); 1467 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 1468 } 1469 1470 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1471 SourceRange getTypeIdParens() const { return TypeIdParens; } 1472 1473 bool isGlobalNew() const { return GlobalNew; } 1474 1475 /// \brief Whether this new-expression has any initializer at all. 1476 bool hasInitializer() const { return StoredInitializationStyle > 0; } 1477 1478 /// \brief The kind of initializer this new-expression has. 1479 InitializationStyle getInitializationStyle() const { 1480 if (StoredInitializationStyle == 0) 1481 return NoInit; 1482 return static_cast<InitializationStyle>(StoredInitializationStyle-1); 1483 } 1484 1485 /// \brief The initializer of this new-expression. 1486 Expr *getInitializer() { 1487 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1488 } 1489 const Expr *getInitializer() const { 1490 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1491 } 1492 1493 /// Answers whether the usual array deallocation function for the 1494 /// allocated type expects the size of the allocation as a 1495 /// parameter. 1496 bool doesUsualArrayDeleteWantSize() const { 1497 return UsualArrayDeleteWantsSize; 1498 } 1499 1500 typedef ExprIterator arg_iterator; 1501 typedef ConstExprIterator const_arg_iterator; 1502 1503 arg_iterator placement_arg_begin() { 1504 return SubExprs + Array + hasInitializer(); 1505 } 1506 arg_iterator placement_arg_end() { 1507 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1508 } 1509 const_arg_iterator placement_arg_begin() const { 1510 return SubExprs + Array + hasInitializer(); 1511 } 1512 const_arg_iterator placement_arg_end() const { 1513 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1514 } 1515 1516 typedef Stmt **raw_arg_iterator; 1517 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1518 raw_arg_iterator raw_arg_end() { 1519 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1520 } 1521 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1522 const_arg_iterator raw_arg_end() const { 1523 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1524 } 1525 1526 SourceLocation getStartLoc() const { return StartLoc; } 1527 SourceLocation getEndLoc() const; 1528 1529 SourceRange getDirectInitRange() const { return DirectInitRange; } 1530 1531 SourceRange getSourceRange() const { 1532 return SourceRange(getStartLoc(), getEndLoc()); 1533 } 1534 1535 static bool classof(const Stmt *T) { 1536 return T->getStmtClass() == CXXNewExprClass; 1537 } 1538 static bool classof(const CXXNewExpr *) { return true; } 1539 1540 // Iterators 1541 child_range children() { 1542 return child_range(raw_arg_begin(), raw_arg_end()); 1543 } 1544}; 1545 1546/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 1547/// calls, e.g. "delete[] pArray". 1548class CXXDeleteExpr : public Expr { 1549 // Is this a forced global delete, i.e. "::delete"? 1550 bool GlobalDelete : 1; 1551 // Is this the array form of delete, i.e. "delete[]"? 1552 bool ArrayForm : 1; 1553 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1554 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1555 // will be true). 1556 bool ArrayFormAsWritten : 1; 1557 // Does the usual deallocation function for the element type require 1558 // a size_t argument? 1559 bool UsualArrayDeleteWantsSize : 1; 1560 // Points to the operator delete overload that is used. Could be a member. 1561 FunctionDecl *OperatorDelete; 1562 // The pointer expression to be deleted. 1563 Stmt *Argument; 1564 // Location of the expression. 1565 SourceLocation Loc; 1566public: 1567 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1568 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1569 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1570 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1571 arg->isInstantiationDependent(), 1572 arg->containsUnexpandedParameterPack()), 1573 GlobalDelete(globalDelete), 1574 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1575 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), 1576 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 1577 explicit CXXDeleteExpr(EmptyShell Shell) 1578 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1579 1580 bool isGlobalDelete() const { return GlobalDelete; } 1581 bool isArrayForm() const { return ArrayForm; } 1582 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1583 1584 /// Answers whether the usual array deallocation function for the 1585 /// allocated type expects the size of the allocation as a 1586 /// parameter. This can be true even if the actual deallocation 1587 /// function that we're using doesn't want a size. 1588 bool doesUsualArrayDeleteWantSize() const { 1589 return UsualArrayDeleteWantsSize; 1590 } 1591 1592 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1593 1594 Expr *getArgument() { return cast<Expr>(Argument); } 1595 const Expr *getArgument() const { return cast<Expr>(Argument); } 1596 1597 /// \brief Retrieve the type being destroyed. If the type being 1598 /// destroyed is a dependent type which may or may not be a pointer, 1599 /// return an invalid type. 1600 QualType getDestroyedType() const; 1601 1602 SourceRange getSourceRange() const { 1603 return SourceRange(Loc, Argument->getLocEnd()); 1604 } 1605 1606 static bool classof(const Stmt *T) { 1607 return T->getStmtClass() == CXXDeleteExprClass; 1608 } 1609 static bool classof(const CXXDeleteExpr *) { return true; } 1610 1611 // Iterators 1612 child_range children() { return child_range(&Argument, &Argument+1); } 1613 1614 friend class ASTStmtReader; 1615}; 1616 1617/// \brief Structure used to store the type being destroyed by a 1618/// pseudo-destructor expression. 1619class PseudoDestructorTypeStorage { 1620 /// \brief Either the type source information or the name of the type, if 1621 /// it couldn't be resolved due to type-dependence. 1622 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1623 1624 /// \brief The starting source location of the pseudo-destructor type. 1625 SourceLocation Location; 1626 1627public: 1628 PseudoDestructorTypeStorage() { } 1629 1630 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1631 : Type(II), Location(Loc) { } 1632 1633 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1634 1635 TypeSourceInfo *getTypeSourceInfo() const { 1636 return Type.dyn_cast<TypeSourceInfo *>(); 1637 } 1638 1639 IdentifierInfo *getIdentifier() const { 1640 return Type.dyn_cast<IdentifierInfo *>(); 1641 } 1642 1643 SourceLocation getLocation() const { return Location; } 1644}; 1645 1646/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1647/// 1648/// A pseudo-destructor is an expression that looks like a member access to a 1649/// destructor of a scalar type, except that scalar types don't have 1650/// destructors. For example: 1651/// 1652/// \code 1653/// typedef int T; 1654/// void f(int *p) { 1655/// p->T::~T(); 1656/// } 1657/// \endcode 1658/// 1659/// Pseudo-destructors typically occur when instantiating templates such as: 1660/// 1661/// \code 1662/// template<typename T> 1663/// void destroy(T* ptr) { 1664/// ptr->T::~T(); 1665/// } 1666/// \endcode 1667/// 1668/// for scalar types. A pseudo-destructor expression has no run-time semantics 1669/// beyond evaluating the base expression. 1670class CXXPseudoDestructorExpr : public Expr { 1671 /// \brief The base expression (that is being destroyed). 1672 Stmt *Base; 1673 1674 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1675 /// period ('.'). 1676 bool IsArrow : 1; 1677 1678 /// \brief The location of the '.' or '->' operator. 1679 SourceLocation OperatorLoc; 1680 1681 /// \brief The nested-name-specifier that follows the operator, if present. 1682 NestedNameSpecifierLoc QualifierLoc; 1683 1684 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1685 /// expression. 1686 TypeSourceInfo *ScopeType; 1687 1688 /// \brief The location of the '::' in a qualified pseudo-destructor 1689 /// expression. 1690 SourceLocation ColonColonLoc; 1691 1692 /// \brief The location of the '~'. 1693 SourceLocation TildeLoc; 1694 1695 /// \brief The type being destroyed, or its name if we were unable to 1696 /// resolve the name. 1697 PseudoDestructorTypeStorage DestroyedType; 1698 1699 friend class ASTStmtReader; 1700 1701public: 1702 CXXPseudoDestructorExpr(ASTContext &Context, 1703 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1704 NestedNameSpecifierLoc QualifierLoc, 1705 TypeSourceInfo *ScopeType, 1706 SourceLocation ColonColonLoc, 1707 SourceLocation TildeLoc, 1708 PseudoDestructorTypeStorage DestroyedType); 1709 1710 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1711 : Expr(CXXPseudoDestructorExprClass, Shell), 1712 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1713 1714 Expr *getBase() const { return cast<Expr>(Base); } 1715 1716 /// \brief Determines whether this member expression actually had 1717 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1718 /// x->Base::foo. 1719 bool hasQualifier() const { return QualifierLoc; } 1720 1721 /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1722 /// with source-location information. 1723 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1724 1725 /// \brief If the member name was qualified, retrieves the 1726 /// nested-name-specifier that precedes the member name. Otherwise, returns 1727 /// NULL. 1728 NestedNameSpecifier *getQualifier() const { 1729 return QualifierLoc.getNestedNameSpecifier(); 1730 } 1731 1732 /// \brief Determine whether this pseudo-destructor expression was written 1733 /// using an '->' (otherwise, it used a '.'). 1734 bool isArrow() const { return IsArrow; } 1735 1736 /// \brief Retrieve the location of the '.' or '->' operator. 1737 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1738 1739 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1740 /// expression. 1741 /// 1742 /// Pseudo-destructor expressions can have extra qualification within them 1743 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1744 /// Here, if the object type of the expression is (or may be) a scalar type, 1745 /// \p T may also be a scalar type and, therefore, cannot be part of a 1746 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1747 /// destructor expression. 1748 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1749 1750 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1751 /// expression. 1752 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1753 1754 /// \brief Retrieve the location of the '~'. 1755 SourceLocation getTildeLoc() const { return TildeLoc; } 1756 1757 /// \brief Retrieve the source location information for the type 1758 /// being destroyed. 1759 /// 1760 /// This type-source information is available for non-dependent 1761 /// pseudo-destructor expressions and some dependent pseudo-destructor 1762 /// expressions. Returns NULL if we only have the identifier for a 1763 /// dependent pseudo-destructor expression. 1764 TypeSourceInfo *getDestroyedTypeInfo() const { 1765 return DestroyedType.getTypeSourceInfo(); 1766 } 1767 1768 /// \brief In a dependent pseudo-destructor expression for which we do not 1769 /// have full type information on the destroyed type, provides the name 1770 /// of the destroyed type. 1771 IdentifierInfo *getDestroyedTypeIdentifier() const { 1772 return DestroyedType.getIdentifier(); 1773 } 1774 1775 /// \brief Retrieve the type being destroyed. 1776 QualType getDestroyedType() const; 1777 1778 /// \brief Retrieve the starting location of the type being destroyed. 1779 SourceLocation getDestroyedTypeLoc() const { 1780 return DestroyedType.getLocation(); 1781 } 1782 1783 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1784 /// expression. 1785 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1786 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1787 } 1788 1789 /// \brief Set the destroyed type. 1790 void setDestroyedType(TypeSourceInfo *Info) { 1791 DestroyedType = PseudoDestructorTypeStorage(Info); 1792 } 1793 1794 SourceRange getSourceRange() const; 1795 1796 static bool classof(const Stmt *T) { 1797 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1798 } 1799 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1800 1801 // Iterators 1802 child_range children() { return child_range(&Base, &Base + 1); } 1803}; 1804 1805/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1806/// implementation of TR1/C++0x type trait templates. 1807/// Example: 1808/// __is_pod(int) == true 1809/// __is_enum(std::string) == false 1810class UnaryTypeTraitExpr : public Expr { 1811 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1812 unsigned UTT : 31; 1813 /// The value of the type trait. Unspecified if dependent. 1814 bool Value : 1; 1815 1816 /// Loc - The location of the type trait keyword. 1817 SourceLocation Loc; 1818 1819 /// RParen - The location of the closing paren. 1820 SourceLocation RParen; 1821 1822 /// The type being queried. 1823 TypeSourceInfo *QueriedType; 1824 1825public: 1826 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 1827 TypeSourceInfo *queried, bool value, 1828 SourceLocation rparen, QualType ty) 1829 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1830 false, queried->getType()->isDependentType(), 1831 queried->getType()->isInstantiationDependentType(), 1832 queried->getType()->containsUnexpandedParameterPack()), 1833 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 1834 1835 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1836 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 1837 QueriedType() { } 1838 1839 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1840 1841 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 1842 1843 QualType getQueriedType() const { return QueriedType->getType(); } 1844 1845 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1846 1847 bool getValue() const { return Value; } 1848 1849 static bool classof(const Stmt *T) { 1850 return T->getStmtClass() == UnaryTypeTraitExprClass; 1851 } 1852 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1853 1854 // Iterators 1855 child_range children() { return child_range(); } 1856 1857 friend class ASTStmtReader; 1858}; 1859 1860/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the 1861/// implementation of TR1/C++0x type trait templates. 1862/// Example: 1863/// __is_base_of(Base, Derived) == true 1864class BinaryTypeTraitExpr : public Expr { 1865 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 1866 unsigned BTT : 8; 1867 1868 /// The value of the type trait. Unspecified if dependent. 1869 bool Value : 1; 1870 1871 /// Loc - The location of the type trait keyword. 1872 SourceLocation Loc; 1873 1874 /// RParen - The location of the closing paren. 1875 SourceLocation RParen; 1876 1877 /// The lhs type being queried. 1878 TypeSourceInfo *LhsType; 1879 1880 /// The rhs type being queried. 1881 TypeSourceInfo *RhsType; 1882 1883public: 1884 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1885 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 1886 bool value, SourceLocation rparen, QualType ty) 1887 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 1888 lhsType->getType()->isDependentType() || 1889 rhsType->getType()->isDependentType(), 1890 (lhsType->getType()->isInstantiationDependentType() || 1891 rhsType->getType()->isInstantiationDependentType()), 1892 (lhsType->getType()->containsUnexpandedParameterPack() || 1893 rhsType->getType()->containsUnexpandedParameterPack())), 1894 BTT(btt), Value(value), Loc(loc), RParen(rparen), 1895 LhsType(lhsType), RhsType(rhsType) { } 1896 1897 1898 explicit BinaryTypeTraitExpr(EmptyShell Empty) 1899 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1900 LhsType(), RhsType() { } 1901 1902 SourceRange getSourceRange() const { 1903 return SourceRange(Loc, RParen); 1904 } 1905 1906 BinaryTypeTrait getTrait() const { 1907 return static_cast<BinaryTypeTrait>(BTT); 1908 } 1909 1910 QualType getLhsType() const { return LhsType->getType(); } 1911 QualType getRhsType() const { return RhsType->getType(); } 1912 1913 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 1914 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 1915 1916 bool getValue() const { assert(!isTypeDependent()); return Value; } 1917 1918 static bool classof(const Stmt *T) { 1919 return T->getStmtClass() == BinaryTypeTraitExprClass; 1920 } 1921 static bool classof(const BinaryTypeTraitExpr *) { return true; } 1922 1923 // Iterators 1924 child_range children() { return child_range(); } 1925 1926 friend class ASTStmtReader; 1927}; 1928 1929/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the 1930/// implementation of __array_rank and __array_extent. 1931/// Example: 1932/// __array_rank(int[10][20]) == 2 1933/// __array_extent(int, 1) == 20 1934class ArrayTypeTraitExpr : public Expr { 1935 virtual void anchor(); 1936 1937 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 1938 unsigned ATT : 2; 1939 1940 /// The value of the type trait. Unspecified if dependent. 1941 uint64_t Value; 1942 1943 /// The array dimension being queried, or -1 if not used 1944 Expr *Dimension; 1945 1946 /// Loc - The location of the type trait keyword. 1947 SourceLocation Loc; 1948 1949 /// RParen - The location of the closing paren. 1950 SourceLocation RParen; 1951 1952 /// The type being queried. 1953 TypeSourceInfo *QueriedType; 1954 1955public: 1956 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 1957 TypeSourceInfo *queried, uint64_t value, 1958 Expr *dimension, SourceLocation rparen, QualType ty) 1959 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1960 false, queried->getType()->isDependentType(), 1961 (queried->getType()->isInstantiationDependentType() || 1962 (dimension && dimension->isInstantiationDependent())), 1963 queried->getType()->containsUnexpandedParameterPack()), 1964 ATT(att), Value(value), Dimension(dimension), 1965 Loc(loc), RParen(rparen), QueriedType(queried) { } 1966 1967 1968 explicit ArrayTypeTraitExpr(EmptyShell Empty) 1969 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 1970 QueriedType() { } 1971 1972 virtual ~ArrayTypeTraitExpr() { } 1973 1974 virtual SourceRange getSourceRange() const { 1975 return SourceRange(Loc, RParen); 1976 } 1977 1978 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 1979 1980 QualType getQueriedType() const { return QueriedType->getType(); } 1981 1982 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1983 1984 uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 1985 1986 Expr *getDimensionExpression() const { return Dimension; } 1987 1988 static bool classof(const Stmt *T) { 1989 return T->getStmtClass() == ArrayTypeTraitExprClass; 1990 } 1991 static bool classof(const ArrayTypeTraitExpr *) { return true; } 1992 1993 // Iterators 1994 child_range children() { return child_range(); } 1995 1996 friend class ASTStmtReader; 1997}; 1998 1999/// ExpressionTraitExpr - An expression trait intrinsic 2000/// Example: 2001/// __is_lvalue_expr(std::cout) == true 2002/// __is_lvalue_expr(1) == false 2003class ExpressionTraitExpr : public Expr { 2004 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned. 2005 unsigned ET : 31; 2006 /// The value of the type trait. Unspecified if dependent. 2007 bool Value : 1; 2008 2009 /// Loc - The location of the type trait keyword. 2010 SourceLocation Loc; 2011 2012 /// RParen - The location of the closing paren. 2013 SourceLocation RParen; 2014 2015 Expr* QueriedExpression; 2016public: 2017 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2018 Expr *queried, bool value, 2019 SourceLocation rparen, QualType resultType) 2020 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2021 false, // Not type-dependent 2022 // Value-dependent if the argument is type-dependent. 2023 queried->isTypeDependent(), 2024 queried->isInstantiationDependent(), 2025 queried->containsUnexpandedParameterPack()), 2026 ET(et), Value(value), Loc(loc), RParen(rparen), 2027 QueriedExpression(queried) { } 2028 2029 explicit ExpressionTraitExpr(EmptyShell Empty) 2030 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2031 QueriedExpression() { } 2032 2033 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 2034 2035 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2036 2037 Expr *getQueriedExpression() const { return QueriedExpression; } 2038 2039 bool getValue() const { return Value; } 2040 2041 static bool classof(const Stmt *T) { 2042 return T->getStmtClass() == ExpressionTraitExprClass; 2043 } 2044 static bool classof(const ExpressionTraitExpr *) { return true; } 2045 2046 // Iterators 2047 child_range children() { return child_range(); } 2048 2049 friend class ASTStmtReader; 2050}; 2051 2052 2053/// \brief A reference to an overloaded function set, either an 2054/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 2055class OverloadExpr : public Expr { 2056 /// The results. These are undesugared, which is to say, they may 2057 /// include UsingShadowDecls. Access is relative to the naming 2058 /// class. 2059 // FIXME: Allocate this data after the OverloadExpr subclass. 2060 DeclAccessPair *Results; 2061 unsigned NumResults; 2062 2063 /// The common name of these declarations. 2064 DeclarationNameInfo NameInfo; 2065 2066 /// \brief The nested-name-specifier that qualifies the name, if any. 2067 NestedNameSpecifierLoc QualifierLoc; 2068 2069protected: 2070 /// \brief Whether the name includes info for explicit template 2071 /// keyword and arguments. 2072 bool HasTemplateKWAndArgsInfo; 2073 2074 /// \brief Return the optional template keyword and arguments info. 2075 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2076 2077 /// \brief Return the optional template keyword and arguments info. 2078 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2079 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2080 } 2081 2082 OverloadExpr(StmtClass K, ASTContext &C, 2083 NestedNameSpecifierLoc QualifierLoc, 2084 SourceLocation TemplateKWLoc, 2085 const DeclarationNameInfo &NameInfo, 2086 const TemplateArgumentListInfo *TemplateArgs, 2087 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2088 bool KnownDependent, 2089 bool KnownInstantiationDependent, 2090 bool KnownContainsUnexpandedParameterPack); 2091 2092 OverloadExpr(StmtClass K, EmptyShell Empty) 2093 : Expr(K, Empty), Results(0), NumResults(0), 2094 QualifierLoc(), HasTemplateKWAndArgsInfo(false) { } 2095 2096 void initializeResults(ASTContext &C, 2097 UnresolvedSetIterator Begin, 2098 UnresolvedSetIterator End); 2099 2100public: 2101 struct FindResult { 2102 OverloadExpr *Expression; 2103 bool IsAddressOfOperand; 2104 bool HasFormOfMemberPointer; 2105 }; 2106 2107 /// Finds the overloaded expression in the given expression of 2108 /// OverloadTy. 2109 /// 2110 /// \return the expression (which must be there) and true if it has 2111 /// the particular form of a member pointer expression 2112 static FindResult find(Expr *E) { 2113 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2114 2115 FindResult Result; 2116 2117 E = E->IgnoreParens(); 2118 if (isa<UnaryOperator>(E)) { 2119 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2120 E = cast<UnaryOperator>(E)->getSubExpr(); 2121 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2122 2123 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2124 Result.IsAddressOfOperand = true; 2125 Result.Expression = Ovl; 2126 } else { 2127 Result.HasFormOfMemberPointer = false; 2128 Result.IsAddressOfOperand = false; 2129 Result.Expression = cast<OverloadExpr>(E); 2130 } 2131 2132 return Result; 2133 } 2134 2135 /// Gets the naming class of this lookup, if any. 2136 CXXRecordDecl *getNamingClass() const; 2137 2138 typedef UnresolvedSetImpl::iterator decls_iterator; 2139 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2140 decls_iterator decls_end() const { 2141 return UnresolvedSetIterator(Results + NumResults); 2142 } 2143 2144 /// Gets the number of declarations in the unresolved set. 2145 unsigned getNumDecls() const { return NumResults; } 2146 2147 /// Gets the full name info. 2148 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2149 2150 /// Gets the name looked up. 2151 DeclarationName getName() const { return NameInfo.getName(); } 2152 2153 /// Gets the location of the name. 2154 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2155 2156 /// Fetches the nested-name qualifier, if one was given. 2157 NestedNameSpecifier *getQualifier() const { 2158 return QualifierLoc.getNestedNameSpecifier(); 2159 } 2160 2161 /// Fetches the nested-name qualifier with source-location information, if 2162 /// one was given. 2163 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2164 2165 /// \brief Retrieve the location of the template keyword preceding 2166 /// this name, if any. 2167 SourceLocation getTemplateKeywordLoc() const { 2168 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2169 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2170 } 2171 2172 /// \brief Retrieve the location of the left angle bracket starting the 2173 /// explicit template argument list following the name, if any. 2174 SourceLocation getLAngleLoc() const { 2175 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2176 return getTemplateKWAndArgsInfo()->LAngleLoc; 2177 } 2178 2179 /// \brief Retrieve the location of the right angle bracket ending the 2180 /// explicit template argument list following the name, if any. 2181 SourceLocation getRAngleLoc() const { 2182 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2183 return getTemplateKWAndArgsInfo()->RAngleLoc; 2184 } 2185 2186 /// Determines whether the name was preceded by the template keyword. 2187 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2188 2189 /// Determines whether this expression had explicit template arguments. 2190 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2191 2192 // Note that, inconsistently with the explicit-template-argument AST 2193 // nodes, users are *forbidden* from calling these methods on objects 2194 // without explicit template arguments. 2195 2196 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2197 assert(hasExplicitTemplateArgs()); 2198 return *getTemplateKWAndArgsInfo(); 2199 } 2200 2201 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2202 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2203 } 2204 2205 TemplateArgumentLoc const *getTemplateArgs() const { 2206 return getExplicitTemplateArgs().getTemplateArgs(); 2207 } 2208 2209 unsigned getNumTemplateArgs() const { 2210 return getExplicitTemplateArgs().NumTemplateArgs; 2211 } 2212 2213 /// Copies the template arguments into the given structure. 2214 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2215 getExplicitTemplateArgs().copyInto(List); 2216 } 2217 2218 /// \brief Retrieves the optional explicit template arguments. 2219 /// This points to the same data as getExplicitTemplateArgs(), but 2220 /// returns null if there are no explicit template arguments. 2221 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2222 if (!hasExplicitTemplateArgs()) return 0; 2223 return &getExplicitTemplateArgs(); 2224 } 2225 2226 static bool classof(const Stmt *T) { 2227 return T->getStmtClass() == UnresolvedLookupExprClass || 2228 T->getStmtClass() == UnresolvedMemberExprClass; 2229 } 2230 static bool classof(const OverloadExpr *) { return true; } 2231 2232 friend class ASTStmtReader; 2233 friend class ASTStmtWriter; 2234}; 2235 2236/// \brief A reference to a name which we were able to look up during 2237/// parsing but could not resolve to a specific declaration. This 2238/// arises in several ways: 2239/// * we might be waiting for argument-dependent lookup 2240/// * the name might resolve to an overloaded function 2241/// and eventually: 2242/// * the lookup might have included a function template 2243/// These never include UnresolvedUsingValueDecls, which are always 2244/// class members and therefore appear only in 2245/// UnresolvedMemberLookupExprs. 2246class UnresolvedLookupExpr : public OverloadExpr { 2247 /// True if these lookup results should be extended by 2248 /// argument-dependent lookup if this is the operand of a function 2249 /// call. 2250 bool RequiresADL; 2251 2252 /// True if namespace ::std should be considered an associated namespace 2253 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1. 2254 bool StdIsAssociatedNamespace; 2255 2256 /// True if these lookup results are overloaded. This is pretty 2257 /// trivially rederivable if we urgently need to kill this field. 2258 bool Overloaded; 2259 2260 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2261 /// any. This can generally be recalculated from the context chain, 2262 /// but that can be fairly expensive for unqualified lookups. If we 2263 /// want to improve memory use here, this could go in a union 2264 /// against the qualified-lookup bits. 2265 CXXRecordDecl *NamingClass; 2266 2267 UnresolvedLookupExpr(ASTContext &C, 2268 CXXRecordDecl *NamingClass, 2269 NestedNameSpecifierLoc QualifierLoc, 2270 SourceLocation TemplateKWLoc, 2271 const DeclarationNameInfo &NameInfo, 2272 bool RequiresADL, bool Overloaded, 2273 const TemplateArgumentListInfo *TemplateArgs, 2274 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2275 bool StdIsAssociatedNamespace) 2276 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2277 NameInfo, TemplateArgs, Begin, End, false, false, false), 2278 RequiresADL(RequiresADL), 2279 StdIsAssociatedNamespace(StdIsAssociatedNamespace), 2280 Overloaded(Overloaded), NamingClass(NamingClass) 2281 {} 2282 2283 UnresolvedLookupExpr(EmptyShell Empty) 2284 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2285 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false), 2286 NamingClass(0) 2287 {} 2288 2289 friend class ASTStmtReader; 2290 2291public: 2292 static UnresolvedLookupExpr *Create(ASTContext &C, 2293 CXXRecordDecl *NamingClass, 2294 NestedNameSpecifierLoc QualifierLoc, 2295 const DeclarationNameInfo &NameInfo, 2296 bool ADL, bool Overloaded, 2297 UnresolvedSetIterator Begin, 2298 UnresolvedSetIterator End, 2299 bool StdIsAssociatedNamespace = false) { 2300 assert((ADL || !StdIsAssociatedNamespace) && 2301 "std considered associated namespace when not performing ADL"); 2302 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2303 SourceLocation(), NameInfo, 2304 ADL, Overloaded, 0, Begin, End, 2305 StdIsAssociatedNamespace); 2306 } 2307 2308 static UnresolvedLookupExpr *Create(ASTContext &C, 2309 CXXRecordDecl *NamingClass, 2310 NestedNameSpecifierLoc QualifierLoc, 2311 SourceLocation TemplateKWLoc, 2312 const DeclarationNameInfo &NameInfo, 2313 bool ADL, 2314 const TemplateArgumentListInfo *Args, 2315 UnresolvedSetIterator Begin, 2316 UnresolvedSetIterator End); 2317 2318 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2319 bool HasTemplateKWAndArgsInfo, 2320 unsigned NumTemplateArgs); 2321 2322 /// True if this declaration should be extended by 2323 /// argument-dependent lookup. 2324 bool requiresADL() const { return RequiresADL; } 2325 2326 /// True if namespace ::std should be artificially added to the set of 2327 /// associated namespaecs for argument-dependent lookup purposes. 2328 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; } 2329 2330 /// True if this lookup is overloaded. 2331 bool isOverloaded() const { return Overloaded; } 2332 2333 /// Gets the 'naming class' (in the sense of C++0x 2334 /// [class.access.base]p5) of the lookup. This is the scope 2335 /// that was looked in to find these results. 2336 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2337 2338 SourceRange getSourceRange() const { 2339 SourceRange Range(getNameInfo().getSourceRange()); 2340 if (getQualifierLoc()) 2341 Range.setBegin(getQualifierLoc().getBeginLoc()); 2342 if (hasExplicitTemplateArgs()) 2343 Range.setEnd(getRAngleLoc()); 2344 return Range; 2345 } 2346 2347 child_range children() { return child_range(); } 2348 2349 static bool classof(const Stmt *T) { 2350 return T->getStmtClass() == UnresolvedLookupExprClass; 2351 } 2352 static bool classof(const UnresolvedLookupExpr *) { return true; } 2353}; 2354 2355/// \brief A qualified reference to a name whose declaration cannot 2356/// yet be resolved. 2357/// 2358/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2359/// it expresses a reference to a declaration such as 2360/// X<T>::value. The difference, however, is that an 2361/// DependentScopeDeclRefExpr node is used only within C++ templates when 2362/// the qualification (e.g., X<T>::) refers to a dependent type. In 2363/// this case, X<T>::value cannot resolve to a declaration because the 2364/// declaration will differ from on instantiation of X<T> to the 2365/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2366/// qualifier (X<T>::) and the name of the entity being referenced 2367/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2368/// declaration can be found. 2369class DependentScopeDeclRefExpr : public Expr { 2370 /// \brief The nested-name-specifier that qualifies this unresolved 2371 /// declaration name. 2372 NestedNameSpecifierLoc QualifierLoc; 2373 2374 /// The name of the entity we will be referencing. 2375 DeclarationNameInfo NameInfo; 2376 2377 /// \brief Whether the name includes info for explicit template 2378 /// keyword and arguments. 2379 bool HasTemplateKWAndArgsInfo; 2380 2381 /// \brief Return the optional template keyword and arguments info. 2382 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2383 if (!HasTemplateKWAndArgsInfo) return 0; 2384 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2385 } 2386 /// \brief Return the optional template keyword and arguments info. 2387 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2388 return const_cast<DependentScopeDeclRefExpr*>(this) 2389 ->getTemplateKWAndArgsInfo(); 2390 } 2391 2392 DependentScopeDeclRefExpr(QualType T, 2393 NestedNameSpecifierLoc QualifierLoc, 2394 SourceLocation TemplateKWLoc, 2395 const DeclarationNameInfo &NameInfo, 2396 const TemplateArgumentListInfo *Args); 2397 2398public: 2399 static DependentScopeDeclRefExpr *Create(ASTContext &C, 2400 NestedNameSpecifierLoc QualifierLoc, 2401 SourceLocation TemplateKWLoc, 2402 const DeclarationNameInfo &NameInfo, 2403 const TemplateArgumentListInfo *TemplateArgs); 2404 2405 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2406 bool HasTemplateKWAndArgsInfo, 2407 unsigned NumTemplateArgs); 2408 2409 /// \brief Retrieve the name that this expression refers to. 2410 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2411 2412 /// \brief Retrieve the name that this expression refers to. 2413 DeclarationName getDeclName() const { return NameInfo.getName(); } 2414 2415 /// \brief Retrieve the location of the name within the expression. 2416 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2417 2418 /// \brief Retrieve the nested-name-specifier that qualifies the 2419 /// name, with source location information. 2420 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2421 2422 2423 /// \brief Retrieve the nested-name-specifier that qualifies this 2424 /// declaration. 2425 NestedNameSpecifier *getQualifier() const { 2426 return QualifierLoc.getNestedNameSpecifier(); 2427 } 2428 2429 /// \brief Retrieve the location of the template keyword preceding 2430 /// this name, if any. 2431 SourceLocation getTemplateKeywordLoc() const { 2432 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2433 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2434 } 2435 2436 /// \brief Retrieve the location of the left angle bracket starting the 2437 /// explicit template argument list following the name, if any. 2438 SourceLocation getLAngleLoc() const { 2439 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2440 return getTemplateKWAndArgsInfo()->LAngleLoc; 2441 } 2442 2443 /// \brief Retrieve the location of the right angle bracket ending the 2444 /// explicit template argument list following the name, if any. 2445 SourceLocation getRAngleLoc() const { 2446 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2447 return getTemplateKWAndArgsInfo()->RAngleLoc; 2448 } 2449 2450 /// Determines whether the name was preceded by the template keyword. 2451 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2452 2453 /// Determines whether this lookup had explicit template arguments. 2454 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2455 2456 // Note that, inconsistently with the explicit-template-argument AST 2457 // nodes, users are *forbidden* from calling these methods on objects 2458 // without explicit template arguments. 2459 2460 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2461 assert(hasExplicitTemplateArgs()); 2462 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2463 } 2464 2465 /// Gets a reference to the explicit template argument list. 2466 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2467 assert(hasExplicitTemplateArgs()); 2468 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2469 } 2470 2471 /// \brief Retrieves the optional explicit template arguments. 2472 /// This points to the same data as getExplicitTemplateArgs(), but 2473 /// returns null if there are no explicit template arguments. 2474 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2475 if (!hasExplicitTemplateArgs()) return 0; 2476 return &getExplicitTemplateArgs(); 2477 } 2478 2479 /// \brief Copies the template arguments (if present) into the given 2480 /// structure. 2481 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2482 getExplicitTemplateArgs().copyInto(List); 2483 } 2484 2485 TemplateArgumentLoc const *getTemplateArgs() const { 2486 return getExplicitTemplateArgs().getTemplateArgs(); 2487 } 2488 2489 unsigned getNumTemplateArgs() const { 2490 return getExplicitTemplateArgs().NumTemplateArgs; 2491 } 2492 2493 SourceRange getSourceRange() const { 2494 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 2495 if (hasExplicitTemplateArgs()) 2496 Range.setEnd(getRAngleLoc()); 2497 return Range; 2498 } 2499 2500 static bool classof(const Stmt *T) { 2501 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2502 } 2503 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 2504 2505 child_range children() { return child_range(); } 2506 2507 friend class ASTStmtReader; 2508 friend class ASTStmtWriter; 2509}; 2510 2511/// Represents an expression --- generally a full-expression --- which 2512/// introduces cleanups to be run at the end of the sub-expression's 2513/// evaluation. The most common source of expression-introduced 2514/// cleanups is temporary objects in C++, but several other kinds of 2515/// expressions can create cleanups, including basically every 2516/// call in ARC that returns an Objective-C pointer. 2517/// 2518/// This expression also tracks whether the sub-expression contains a 2519/// potentially-evaluated block literal. The lifetime of a block 2520/// literal is the extent of the enclosing scope. 2521class ExprWithCleanups : public Expr { 2522public: 2523 /// The type of objects that are kept in the cleanup. 2524 /// It's useful to remember the set of blocks; we could also 2525 /// remember the set of temporaries, but there's currently 2526 /// no need. 2527 typedef BlockDecl *CleanupObject; 2528 2529private: 2530 Stmt *SubExpr; 2531 2532 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2533 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2534 2535 CleanupObject *getObjectsBuffer() { 2536 return reinterpret_cast<CleanupObject*>(this + 1); 2537 } 2538 const CleanupObject *getObjectsBuffer() const { 2539 return reinterpret_cast<const CleanupObject*>(this + 1); 2540 } 2541 friend class ASTStmtReader; 2542 2543public: 2544 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 2545 unsigned numObjects); 2546 2547 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 2548 ArrayRef<CleanupObject> objects); 2549 2550 ArrayRef<CleanupObject> getObjects() const { 2551 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2552 } 2553 2554 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2555 2556 CleanupObject getObject(unsigned i) const { 2557 assert(i < getNumObjects() && "Index out of range"); 2558 return getObjects()[i]; 2559 } 2560 2561 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2562 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2563 2564 /// setSubExpr - As with any mutator of the AST, be very careful 2565 /// when modifying an existing AST to preserve its invariants. 2566 void setSubExpr(Expr *E) { SubExpr = E; } 2567 2568 SourceRange getSourceRange() const { 2569 return SubExpr->getSourceRange(); 2570 } 2571 2572 // Implement isa/cast/dyncast/etc. 2573 static bool classof(const Stmt *T) { 2574 return T->getStmtClass() == ExprWithCleanupsClass; 2575 } 2576 static bool classof(const ExprWithCleanups *) { return true; } 2577 2578 // Iterators 2579 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2580}; 2581 2582/// \brief Describes an explicit type conversion that uses functional 2583/// notion but could not be resolved because one or more arguments are 2584/// type-dependent. 2585/// 2586/// The explicit type conversions expressed by 2587/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 2588/// where \c T is some type and \c a1, a2, ..., aN are values, and 2589/// either \C T is a dependent type or one or more of the \c a's is 2590/// type-dependent. For example, this would occur in a template such 2591/// as: 2592/// 2593/// \code 2594/// template<typename T, typename A1> 2595/// inline T make_a(const A1& a1) { 2596/// return T(a1); 2597/// } 2598/// \endcode 2599/// 2600/// When the returned expression is instantiated, it may resolve to a 2601/// constructor call, conversion function call, or some kind of type 2602/// conversion. 2603class CXXUnresolvedConstructExpr : public Expr { 2604 /// \brief The type being constructed. 2605 TypeSourceInfo *Type; 2606 2607 /// \brief The location of the left parentheses ('('). 2608 SourceLocation LParenLoc; 2609 2610 /// \brief The location of the right parentheses (')'). 2611 SourceLocation RParenLoc; 2612 2613 /// \brief The number of arguments used to construct the type. 2614 unsigned NumArgs; 2615 2616 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2617 SourceLocation LParenLoc, 2618 Expr **Args, 2619 unsigned NumArgs, 2620 SourceLocation RParenLoc); 2621 2622 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2623 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2624 2625 friend class ASTStmtReader; 2626 2627public: 2628 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2629 TypeSourceInfo *Type, 2630 SourceLocation LParenLoc, 2631 Expr **Args, 2632 unsigned NumArgs, 2633 SourceLocation RParenLoc); 2634 2635 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2636 unsigned NumArgs); 2637 2638 /// \brief Retrieve the type that is being constructed, as specified 2639 /// in the source code. 2640 QualType getTypeAsWritten() const { return Type->getType(); } 2641 2642 /// \brief Retrieve the type source information for the type being 2643 /// constructed. 2644 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2645 2646 /// \brief Retrieve the location of the left parentheses ('(') that 2647 /// precedes the argument list. 2648 SourceLocation getLParenLoc() const { return LParenLoc; } 2649 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2650 2651 /// \brief Retrieve the location of the right parentheses (')') that 2652 /// follows the argument list. 2653 SourceLocation getRParenLoc() const { return RParenLoc; } 2654 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2655 2656 /// \brief Retrieve the number of arguments. 2657 unsigned arg_size() const { return NumArgs; } 2658 2659 typedef Expr** arg_iterator; 2660 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2661 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2662 2663 typedef const Expr* const * const_arg_iterator; 2664 const_arg_iterator arg_begin() const { 2665 return reinterpret_cast<const Expr* const *>(this + 1); 2666 } 2667 const_arg_iterator arg_end() const { 2668 return arg_begin() + NumArgs; 2669 } 2670 2671 Expr *getArg(unsigned I) { 2672 assert(I < NumArgs && "Argument index out-of-range"); 2673 return *(arg_begin() + I); 2674 } 2675 2676 const Expr *getArg(unsigned I) const { 2677 assert(I < NumArgs && "Argument index out-of-range"); 2678 return *(arg_begin() + I); 2679 } 2680 2681 void setArg(unsigned I, Expr *E) { 2682 assert(I < NumArgs && "Argument index out-of-range"); 2683 *(arg_begin() + I) = E; 2684 } 2685 2686 SourceRange getSourceRange() const; 2687 2688 static bool classof(const Stmt *T) { 2689 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2690 } 2691 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2692 2693 // Iterators 2694 child_range children() { 2695 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 2696 return child_range(begin, begin + NumArgs); 2697 } 2698}; 2699 2700/// \brief Represents a C++ member access expression where the actual 2701/// member referenced could not be resolved because the base 2702/// expression or the member name was dependent. 2703/// 2704/// Like UnresolvedMemberExprs, these can be either implicit or 2705/// explicit accesses. It is only possible to get one of these with 2706/// an implicit access if a qualifier is provided. 2707class CXXDependentScopeMemberExpr : public Expr { 2708 /// \brief The expression for the base pointer or class reference, 2709 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2710 Stmt *Base; 2711 2712 /// \brief The type of the base expression. Never null, even for 2713 /// implicit accesses. 2714 QualType BaseType; 2715 2716 /// \brief Whether this member expression used the '->' operator or 2717 /// the '.' operator. 2718 bool IsArrow : 1; 2719 2720 /// \brief Whether this member expression has info for explicit template 2721 /// keyword and arguments. 2722 bool HasTemplateKWAndArgsInfo : 1; 2723 2724 /// \brief The location of the '->' or '.' operator. 2725 SourceLocation OperatorLoc; 2726 2727 /// \brief The nested-name-specifier that precedes the member name, if any. 2728 NestedNameSpecifierLoc QualifierLoc; 2729 2730 /// \brief In a qualified member access expression such as t->Base::f, this 2731 /// member stores the resolves of name lookup in the context of the member 2732 /// access expression, to be used at instantiation time. 2733 /// 2734 /// FIXME: This member, along with the QualifierLoc, could 2735 /// be stuck into a structure that is optionally allocated at the end of 2736 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2737 NamedDecl *FirstQualifierFoundInScope; 2738 2739 /// \brief The member to which this member expression refers, which 2740 /// can be name, overloaded operator, or destructor. 2741 /// FIXME: could also be a template-id 2742 DeclarationNameInfo MemberNameInfo; 2743 2744 /// \brief Return the optional template keyword and arguments info. 2745 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2746 if (!HasTemplateKWAndArgsInfo) return 0; 2747 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2748 } 2749 /// \brief Return the optional template keyword and arguments info. 2750 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2751 return const_cast<CXXDependentScopeMemberExpr*>(this) 2752 ->getTemplateKWAndArgsInfo(); 2753 } 2754 2755 CXXDependentScopeMemberExpr(ASTContext &C, 2756 Expr *Base, QualType BaseType, bool IsArrow, 2757 SourceLocation OperatorLoc, 2758 NestedNameSpecifierLoc QualifierLoc, 2759 SourceLocation TemplateKWLoc, 2760 NamedDecl *FirstQualifierFoundInScope, 2761 DeclarationNameInfo MemberNameInfo, 2762 const TemplateArgumentListInfo *TemplateArgs); 2763 2764public: 2765 CXXDependentScopeMemberExpr(ASTContext &C, 2766 Expr *Base, QualType BaseType, 2767 bool IsArrow, 2768 SourceLocation OperatorLoc, 2769 NestedNameSpecifierLoc QualifierLoc, 2770 NamedDecl *FirstQualifierFoundInScope, 2771 DeclarationNameInfo MemberNameInfo); 2772 2773 static CXXDependentScopeMemberExpr * 2774 Create(ASTContext &C, 2775 Expr *Base, QualType BaseType, bool IsArrow, 2776 SourceLocation OperatorLoc, 2777 NestedNameSpecifierLoc QualifierLoc, 2778 SourceLocation TemplateKWLoc, 2779 NamedDecl *FirstQualifierFoundInScope, 2780 DeclarationNameInfo MemberNameInfo, 2781 const TemplateArgumentListInfo *TemplateArgs); 2782 2783 static CXXDependentScopeMemberExpr * 2784 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2785 unsigned NumTemplateArgs); 2786 2787 /// \brief True if this is an implicit access, i.e. one in which the 2788 /// member being accessed was not written in the source. The source 2789 /// location of the operator is invalid in this case. 2790 bool isImplicitAccess() const; 2791 2792 /// \brief Retrieve the base object of this member expressions, 2793 /// e.g., the \c x in \c x.m. 2794 Expr *getBase() const { 2795 assert(!isImplicitAccess()); 2796 return cast<Expr>(Base); 2797 } 2798 2799 QualType getBaseType() const { return BaseType; } 2800 2801 /// \brief Determine whether this member expression used the '->' 2802 /// operator; otherwise, it used the '.' operator. 2803 bool isArrow() const { return IsArrow; } 2804 2805 /// \brief Retrieve the location of the '->' or '.' operator. 2806 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2807 2808 /// \brief Retrieve the nested-name-specifier that qualifies the member 2809 /// name. 2810 NestedNameSpecifier *getQualifier() const { 2811 return QualifierLoc.getNestedNameSpecifier(); 2812 } 2813 2814 /// \brief Retrieve the nested-name-specifier that qualifies the member 2815 /// name, with source location information. 2816 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2817 2818 2819 /// \brief Retrieve the first part of the nested-name-specifier that was 2820 /// found in the scope of the member access expression when the member access 2821 /// was initially parsed. 2822 /// 2823 /// This function only returns a useful result when member access expression 2824 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2825 /// returned by this function describes what was found by unqualified name 2826 /// lookup for the identifier "Base" within the scope of the member access 2827 /// expression itself. At template instantiation time, this information is 2828 /// combined with the results of name lookup into the type of the object 2829 /// expression itself (the class type of x). 2830 NamedDecl *getFirstQualifierFoundInScope() const { 2831 return FirstQualifierFoundInScope; 2832 } 2833 2834 /// \brief Retrieve the name of the member that this expression 2835 /// refers to. 2836 const DeclarationNameInfo &getMemberNameInfo() const { 2837 return MemberNameInfo; 2838 } 2839 2840 /// \brief Retrieve the name of the member that this expression 2841 /// refers to. 2842 DeclarationName getMember() const { return MemberNameInfo.getName(); } 2843 2844 // \brief Retrieve the location of the name of the member that this 2845 // expression refers to. 2846 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 2847 2848 /// \brief Retrieve the location of the template keyword preceding the 2849 /// member name, if any. 2850 SourceLocation getTemplateKeywordLoc() const { 2851 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2852 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2853 } 2854 2855 /// \brief Retrieve the location of the left angle bracket starting the 2856 /// explicit template argument list following the member name, if any. 2857 SourceLocation getLAngleLoc() const { 2858 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2859 return getTemplateKWAndArgsInfo()->LAngleLoc; 2860 } 2861 2862 /// \brief Retrieve the location of the right angle bracket ending the 2863 /// explicit template argument list following the member name, if any. 2864 SourceLocation getRAngleLoc() const { 2865 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2866 return getTemplateKWAndArgsInfo()->RAngleLoc; 2867 } 2868 2869 /// Determines whether the member name was preceded by the template keyword. 2870 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2871 2872 /// \brief Determines whether this member expression actually had a C++ 2873 /// template argument list explicitly specified, e.g., x.f<int>. 2874 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2875 2876 /// \brief Retrieve the explicit template argument list that followed the 2877 /// member template name, if any. 2878 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2879 assert(hasExplicitTemplateArgs()); 2880 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 2881 } 2882 2883 /// \brief Retrieve the explicit template argument list that followed the 2884 /// member template name, if any. 2885 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2886 return const_cast<CXXDependentScopeMemberExpr *>(this) 2887 ->getExplicitTemplateArgs(); 2888 } 2889 2890 /// \brief Retrieves the optional explicit template arguments. 2891 /// This points to the same data as getExplicitTemplateArgs(), but 2892 /// returns null if there are no explicit template arguments. 2893 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2894 if (!hasExplicitTemplateArgs()) return 0; 2895 return &getExplicitTemplateArgs(); 2896 } 2897 2898 /// \brief Copies the template arguments (if present) into the given 2899 /// structure. 2900 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2901 getExplicitTemplateArgs().copyInto(List); 2902 } 2903 2904 /// \brief Initializes the template arguments using the given structure. 2905 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2906 getExplicitTemplateArgs().initializeFrom(List); 2907 } 2908 2909 /// \brief Retrieve the template arguments provided as part of this 2910 /// template-id. 2911 const TemplateArgumentLoc *getTemplateArgs() const { 2912 return getExplicitTemplateArgs().getTemplateArgs(); 2913 } 2914 2915 /// \brief Retrieve the number of template arguments provided as part of this 2916 /// template-id. 2917 unsigned getNumTemplateArgs() const { 2918 return getExplicitTemplateArgs().NumTemplateArgs; 2919 } 2920 2921 SourceRange getSourceRange() const { 2922 SourceRange Range; 2923 if (!isImplicitAccess()) 2924 Range.setBegin(Base->getSourceRange().getBegin()); 2925 else if (getQualifier()) 2926 Range.setBegin(getQualifierLoc().getBeginLoc()); 2927 else 2928 Range.setBegin(MemberNameInfo.getBeginLoc()); 2929 2930 if (hasExplicitTemplateArgs()) 2931 Range.setEnd(getRAngleLoc()); 2932 else 2933 Range.setEnd(MemberNameInfo.getEndLoc()); 2934 return Range; 2935 } 2936 2937 static bool classof(const Stmt *T) { 2938 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2939 } 2940 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2941 2942 // Iterators 2943 child_range children() { 2944 if (isImplicitAccess()) return child_range(); 2945 return child_range(&Base, &Base + 1); 2946 } 2947 2948 friend class ASTStmtReader; 2949 friend class ASTStmtWriter; 2950}; 2951 2952/// \brief Represents a C++ member access expression for which lookup 2953/// produced a set of overloaded functions. 2954/// 2955/// The member access may be explicit or implicit: 2956/// struct A { 2957/// int a, b; 2958/// int explicitAccess() { return this->a + this->A::b; } 2959/// int implicitAccess() { return a + A::b; } 2960/// }; 2961/// 2962/// In the final AST, an explicit access always becomes a MemberExpr. 2963/// An implicit access may become either a MemberExpr or a 2964/// DeclRefExpr, depending on whether the member is static. 2965class UnresolvedMemberExpr : public OverloadExpr { 2966 /// \brief Whether this member expression used the '->' operator or 2967 /// the '.' operator. 2968 bool IsArrow : 1; 2969 2970 /// \brief Whether the lookup results contain an unresolved using 2971 /// declaration. 2972 bool HasUnresolvedUsing : 1; 2973 2974 /// \brief The expression for the base pointer or class reference, 2975 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2976 /// member expression 2977 Stmt *Base; 2978 2979 /// \brief The type of the base expression; never null. 2980 QualType BaseType; 2981 2982 /// \brief The location of the '->' or '.' operator. 2983 SourceLocation OperatorLoc; 2984 2985 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 2986 Expr *Base, QualType BaseType, bool IsArrow, 2987 SourceLocation OperatorLoc, 2988 NestedNameSpecifierLoc QualifierLoc, 2989 SourceLocation TemplateKWLoc, 2990 const DeclarationNameInfo &MemberNameInfo, 2991 const TemplateArgumentListInfo *TemplateArgs, 2992 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2993 2994 UnresolvedMemberExpr(EmptyShell Empty) 2995 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2996 HasUnresolvedUsing(false), Base(0) { } 2997 2998 friend class ASTStmtReader; 2999 3000public: 3001 static UnresolvedMemberExpr * 3002 Create(ASTContext &C, bool HasUnresolvedUsing, 3003 Expr *Base, QualType BaseType, bool IsArrow, 3004 SourceLocation OperatorLoc, 3005 NestedNameSpecifierLoc QualifierLoc, 3006 SourceLocation TemplateKWLoc, 3007 const DeclarationNameInfo &MemberNameInfo, 3008 const TemplateArgumentListInfo *TemplateArgs, 3009 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3010 3011 static UnresolvedMemberExpr * 3012 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3013 unsigned NumTemplateArgs); 3014 3015 /// \brief True if this is an implicit access, i.e. one in which the 3016 /// member being accessed was not written in the source. The source 3017 /// location of the operator is invalid in this case. 3018 bool isImplicitAccess() const; 3019 3020 /// \brief Retrieve the base object of this member expressions, 3021 /// e.g., the \c x in \c x.m. 3022 Expr *getBase() { 3023 assert(!isImplicitAccess()); 3024 return cast<Expr>(Base); 3025 } 3026 const Expr *getBase() const { 3027 assert(!isImplicitAccess()); 3028 return cast<Expr>(Base); 3029 } 3030 3031 QualType getBaseType() const { return BaseType; } 3032 3033 /// \brief Determine whether the lookup results contain an unresolved using 3034 /// declaration. 3035 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3036 3037 /// \brief Determine whether this member expression used the '->' 3038 /// operator; otherwise, it used the '.' operator. 3039 bool isArrow() const { return IsArrow; } 3040 3041 /// \brief Retrieve the location of the '->' or '.' operator. 3042 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3043 3044 /// \brief Retrieves the naming class of this lookup. 3045 CXXRecordDecl *getNamingClass() const; 3046 3047 /// \brief Retrieve the full name info for the member that this expression 3048 /// refers to. 3049 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3050 3051 /// \brief Retrieve the name of the member that this expression 3052 /// refers to. 3053 DeclarationName getMemberName() const { return getName(); } 3054 3055 // \brief Retrieve the location of the name of the member that this 3056 // expression refers to. 3057 SourceLocation getMemberLoc() const { return getNameLoc(); } 3058 3059 SourceRange getSourceRange() const { 3060 SourceRange Range = getMemberNameInfo().getSourceRange(); 3061 if (!isImplicitAccess()) 3062 Range.setBegin(Base->getSourceRange().getBegin()); 3063 else if (getQualifierLoc()) 3064 Range.setBegin(getQualifierLoc().getBeginLoc()); 3065 3066 if (hasExplicitTemplateArgs()) 3067 Range.setEnd(getRAngleLoc()); 3068 return Range; 3069 } 3070 3071 static bool classof(const Stmt *T) { 3072 return T->getStmtClass() == UnresolvedMemberExprClass; 3073 } 3074 static bool classof(const UnresolvedMemberExpr *) { return true; } 3075 3076 // Iterators 3077 child_range children() { 3078 if (isImplicitAccess()) return child_range(); 3079 return child_range(&Base, &Base + 1); 3080 } 3081}; 3082 3083/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 3084/// 3085/// The noexcept expression tests whether a given expression might throw. Its 3086/// result is a boolean constant. 3087class CXXNoexceptExpr : public Expr { 3088 bool Value : 1; 3089 Stmt *Operand; 3090 SourceRange Range; 3091 3092 friend class ASTStmtReader; 3093 3094public: 3095 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3096 SourceLocation Keyword, SourceLocation RParen) 3097 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3098 /*TypeDependent*/false, 3099 /*ValueDependent*/Val == CT_Dependent, 3100 Val == CT_Dependent || Operand->isInstantiationDependent(), 3101 Operand->containsUnexpandedParameterPack()), 3102 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3103 { } 3104 3105 CXXNoexceptExpr(EmptyShell Empty) 3106 : Expr(CXXNoexceptExprClass, Empty) 3107 { } 3108 3109 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3110 3111 SourceRange getSourceRange() const { return Range; } 3112 3113 bool getValue() const { return Value; } 3114 3115 static bool classof(const Stmt *T) { 3116 return T->getStmtClass() == CXXNoexceptExprClass; 3117 } 3118 static bool classof(const CXXNoexceptExpr *) { return true; } 3119 3120 // Iterators 3121 child_range children() { return child_range(&Operand, &Operand + 1); } 3122}; 3123 3124/// \brief Represents a C++0x pack expansion that produces a sequence of 3125/// expressions. 3126/// 3127/// A pack expansion expression contains a pattern (which itself is an 3128/// expression) followed by an ellipsis. For example: 3129/// 3130/// \code 3131/// template<typename F, typename ...Types> 3132/// void forward(F f, Types &&...args) { 3133/// f(static_cast<Types&&>(args)...); 3134/// } 3135/// \endcode 3136/// 3137/// Here, the argument to the function object \c f is a pack expansion whose 3138/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3139/// template is instantiated, the pack expansion will instantiate to zero or 3140/// or more function arguments to the function object \c f. 3141class PackExpansionExpr : public Expr { 3142 SourceLocation EllipsisLoc; 3143 3144 /// \brief The number of expansions that will be produced by this pack 3145 /// expansion expression, if known. 3146 /// 3147 /// When zero, the number of expansions is not known. Otherwise, this value 3148 /// is the number of expansions + 1. 3149 unsigned NumExpansions; 3150 3151 Stmt *Pattern; 3152 3153 friend class ASTStmtReader; 3154 friend class ASTStmtWriter; 3155 3156public: 3157 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3158 llvm::Optional<unsigned> NumExpansions) 3159 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3160 Pattern->getObjectKind(), /*TypeDependent=*/true, 3161 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3162 /*ContainsUnexpandedParameterPack=*/false), 3163 EllipsisLoc(EllipsisLoc), 3164 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3165 Pattern(Pattern) { } 3166 3167 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3168 3169 /// \brief Retrieve the pattern of the pack expansion. 3170 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3171 3172 /// \brief Retrieve the pattern of the pack expansion. 3173 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3174 3175 /// \brief Retrieve the location of the ellipsis that describes this pack 3176 /// expansion. 3177 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3178 3179 /// \brief Determine the number of expansions that will be produced when 3180 /// this pack expansion is instantiated, if already known. 3181 llvm::Optional<unsigned> getNumExpansions() const { 3182 if (NumExpansions) 3183 return NumExpansions - 1; 3184 3185 return llvm::Optional<unsigned>(); 3186 } 3187 3188 SourceRange getSourceRange() const { 3189 return SourceRange(Pattern->getLocStart(), EllipsisLoc); 3190 } 3191 3192 static bool classof(const Stmt *T) { 3193 return T->getStmtClass() == PackExpansionExprClass; 3194 } 3195 static bool classof(const PackExpansionExpr *) { return true; } 3196 3197 // Iterators 3198 child_range children() { 3199 return child_range(&Pattern, &Pattern + 1); 3200 } 3201}; 3202 3203inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3204 if (!HasTemplateKWAndArgsInfo) return 0; 3205 if (isa<UnresolvedLookupExpr>(this)) 3206 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3207 (cast<UnresolvedLookupExpr>(this) + 1); 3208 else 3209 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3210 (cast<UnresolvedMemberExpr>(this) + 1); 3211} 3212 3213/// \brief Represents an expression that computes the length of a parameter 3214/// pack. 3215/// 3216/// \code 3217/// template<typename ...Types> 3218/// struct count { 3219/// static const unsigned value = sizeof...(Types); 3220/// }; 3221/// \endcode 3222class SizeOfPackExpr : public Expr { 3223 /// \brief The location of the 'sizeof' keyword. 3224 SourceLocation OperatorLoc; 3225 3226 /// \brief The location of the name of the parameter pack. 3227 SourceLocation PackLoc; 3228 3229 /// \brief The location of the closing parenthesis. 3230 SourceLocation RParenLoc; 3231 3232 /// \brief The length of the parameter pack, if known. 3233 /// 3234 /// When this expression is value-dependent, the length of the parameter pack 3235 /// is unknown. When this expression is not value-dependent, the length is 3236 /// known. 3237 unsigned Length; 3238 3239 /// \brief The parameter pack itself. 3240 NamedDecl *Pack; 3241 3242 friend class ASTStmtReader; 3243 friend class ASTStmtWriter; 3244 3245public: 3246 /// \brief Creates a value-dependent expression that computes the length of 3247 /// the given parameter pack. 3248 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3249 SourceLocation PackLoc, SourceLocation RParenLoc) 3250 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3251 /*TypeDependent=*/false, /*ValueDependent=*/true, 3252 /*InstantiationDependent=*/true, 3253 /*ContainsUnexpandedParameterPack=*/false), 3254 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3255 Length(0), Pack(Pack) { } 3256 3257 /// \brief Creates an expression that computes the length of 3258 /// the given parameter pack, which is already known. 3259 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3260 SourceLocation PackLoc, SourceLocation RParenLoc, 3261 unsigned Length) 3262 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3263 /*TypeDependent=*/false, /*ValueDependent=*/false, 3264 /*InstantiationDependent=*/false, 3265 /*ContainsUnexpandedParameterPack=*/false), 3266 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3267 Length(Length), Pack(Pack) { } 3268 3269 /// \brief Create an empty expression. 3270 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3271 3272 /// \brief Determine the location of the 'sizeof' keyword. 3273 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3274 3275 /// \brief Determine the location of the parameter pack. 3276 SourceLocation getPackLoc() const { return PackLoc; } 3277 3278 /// \brief Determine the location of the right parenthesis. 3279 SourceLocation getRParenLoc() const { return RParenLoc; } 3280 3281 /// \brief Retrieve the parameter pack. 3282 NamedDecl *getPack() const { return Pack; } 3283 3284 /// \brief Retrieve the length of the parameter pack. 3285 /// 3286 /// This routine may only be invoked when the expression is not 3287 /// value-dependent. 3288 unsigned getPackLength() const { 3289 assert(!isValueDependent() && 3290 "Cannot get the length of a value-dependent pack size expression"); 3291 return Length; 3292 } 3293 3294 SourceRange getSourceRange() const { 3295 return SourceRange(OperatorLoc, RParenLoc); 3296 } 3297 3298 static bool classof(const Stmt *T) { 3299 return T->getStmtClass() == SizeOfPackExprClass; 3300 } 3301 static bool classof(const SizeOfPackExpr *) { return true; } 3302 3303 // Iterators 3304 child_range children() { return child_range(); } 3305}; 3306 3307/// \brief Represents a reference to a non-type template parameter 3308/// that has been substituted with a template argument. 3309class SubstNonTypeTemplateParmExpr : public Expr { 3310 /// \brief The replaced parameter. 3311 NonTypeTemplateParmDecl *Param; 3312 3313 /// \brief The replacement expression. 3314 Stmt *Replacement; 3315 3316 /// \brief The location of the non-type template parameter reference. 3317 SourceLocation NameLoc; 3318 3319 friend class ASTReader; 3320 friend class ASTStmtReader; 3321 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3322 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3323 3324public: 3325 SubstNonTypeTemplateParmExpr(QualType type, 3326 ExprValueKind valueKind, 3327 SourceLocation loc, 3328 NonTypeTemplateParmDecl *param, 3329 Expr *replacement) 3330 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3331 replacement->isTypeDependent(), replacement->isValueDependent(), 3332 replacement->isInstantiationDependent(), 3333 replacement->containsUnexpandedParameterPack()), 3334 Param(param), Replacement(replacement), NameLoc(loc) {} 3335 3336 SourceLocation getNameLoc() const { return NameLoc; } 3337 SourceRange getSourceRange() const { return NameLoc; } 3338 3339 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3340 3341 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3342 3343 static bool classof(const Stmt *s) { 3344 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3345 } 3346 static bool classof(const SubstNonTypeTemplateParmExpr *) { 3347 return true; 3348 } 3349 3350 // Iterators 3351 child_range children() { return child_range(&Replacement, &Replacement+1); } 3352}; 3353 3354/// \brief Represents a reference to a non-type template parameter pack that 3355/// has been substituted with a non-template argument pack. 3356/// 3357/// When a pack expansion in the source code contains multiple parameter packs 3358/// and those parameter packs correspond to different levels of template 3359/// parameter lists, this node node is used to represent a non-type template 3360/// parameter pack from an outer level, which has already had its argument pack 3361/// substituted but that still lives within a pack expansion that itself 3362/// could not be instantiated. When actually performing a substitution into 3363/// that pack expansion (e.g., when all template parameters have corresponding 3364/// arguments), this type will be replaced with the appropriate underlying 3365/// expression at the current pack substitution index. 3366class SubstNonTypeTemplateParmPackExpr : public Expr { 3367 /// \brief The non-type template parameter pack itself. 3368 NonTypeTemplateParmDecl *Param; 3369 3370 /// \brief A pointer to the set of template arguments that this 3371 /// parameter pack is instantiated with. 3372 const TemplateArgument *Arguments; 3373 3374 /// \brief The number of template arguments in \c Arguments. 3375 unsigned NumArguments; 3376 3377 /// \brief The location of the non-type template parameter pack reference. 3378 SourceLocation NameLoc; 3379 3380 friend class ASTReader; 3381 friend class ASTStmtReader; 3382 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3383 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3384 3385public: 3386 SubstNonTypeTemplateParmPackExpr(QualType T, 3387 NonTypeTemplateParmDecl *Param, 3388 SourceLocation NameLoc, 3389 const TemplateArgument &ArgPack); 3390 3391 /// \brief Retrieve the non-type template parameter pack being substituted. 3392 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3393 3394 /// \brief Retrieve the location of the parameter pack name. 3395 SourceLocation getParameterPackLocation() const { return NameLoc; } 3396 3397 /// \brief Retrieve the template argument pack containing the substituted 3398 /// template arguments. 3399 TemplateArgument getArgumentPack() const; 3400 3401 SourceRange getSourceRange() const { return NameLoc; } 3402 3403 static bool classof(const Stmt *T) { 3404 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3405 } 3406 static bool classof(const SubstNonTypeTemplateParmPackExpr *) { 3407 return true; 3408 } 3409 3410 // Iterators 3411 child_range children() { return child_range(); } 3412}; 3413 3414/// \brief Represents a prvalue temporary that written into memory so that 3415/// a reference can bind to it. 3416/// 3417/// Prvalue expressions are materialized when they need to have an address 3418/// in memory for a reference to bind to. This happens when binding a 3419/// reference to the result of a conversion, e.g., 3420/// 3421/// \code 3422/// const int &r = 1.0; 3423/// \endcode 3424/// 3425/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3426/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3427/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3428/// (either an lvalue or an xvalue, depending on the kind of reference binding 3429/// to it), maintaining the invariant that references always bind to glvalues. 3430class MaterializeTemporaryExpr : public Expr { 3431 /// \brief The temporary-generating expression whose value will be 3432 /// materialized. 3433 Stmt *Temporary; 3434 3435 friend class ASTStmtReader; 3436 friend class ASTStmtWriter; 3437 3438public: 3439 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3440 bool BoundToLvalueReference) 3441 : Expr(MaterializeTemporaryExprClass, T, 3442 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3443 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3444 Temporary->isInstantiationDependent(), 3445 Temporary->containsUnexpandedParameterPack()), 3446 Temporary(Temporary) { } 3447 3448 MaterializeTemporaryExpr(EmptyShell Empty) 3449 : Expr(MaterializeTemporaryExprClass, Empty) { } 3450 3451 /// \brief Retrieve the temporary-generating subexpression whose value will 3452 /// be materialized into a glvalue. 3453 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3454 3455 /// \brief Determine whether this materialized temporary is bound to an 3456 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3457 bool isBoundToLvalueReference() const { 3458 return getValueKind() == VK_LValue; 3459 } 3460 3461 SourceRange getSourceRange() const { return Temporary->getSourceRange(); } 3462 3463 static bool classof(const Stmt *T) { 3464 return T->getStmtClass() == MaterializeTemporaryExprClass; 3465 } 3466 static bool classof(const MaterializeTemporaryExpr *) { 3467 return true; 3468 } 3469 3470 // Iterators 3471 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3472}; 3473 3474} // end namespace clang 3475 3476#endif 3477