ExprCXX.h revision 65d78312ce026092cb6e7b1d4d06f05e18d02aa0
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// The LLVM Compiler Infrastructure 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// License. See LICENSE.TXT for details. 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//===----------------------------------------------------------------------===// 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This file defines the Expr interface and subclasses for C++ expressions. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//===----------------------------------------------------------------------===// 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPRCXX_H 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define LLVM_CLANG_AST_EXPRCXX_H 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/AST/Decl.h" 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/AST/Expr.h" 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/AST/TemplateBase.h" 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/AST/UnresolvedSet.h" 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/Basic/ExpressionTraits.h" 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/Basic/Lambda.h" 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "clang/Basic/TypeTraits.h" 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "llvm/Support/Compiler.h" 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace clang { 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXConstructorDecl; 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXDestructorDecl; 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXMethodDecl; 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXTemporary; 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class TemplateArgumentListInfo; 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class UuidAttr; 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)//===--------------------------------------------------------------------===// 3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// C++ Expressions. 377242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci//===--------------------------------------------------------------------===// 38c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 3906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)/// \brief A call to an overloaded operator written using operator 4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/// syntax. 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// 42c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)/// Represents a call to an overloaded operator written using operator 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// normal call, this AST node provides better information about the 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// syntactic representation of the call. 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// 47df95704c49daea886ddad70775bda23618d6274dBen Murdoch/// In a C++ template, this expression node kind will be used whenever 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// any of the arguments are type-dependent. In this case, the 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// function itself will be a (possibly empty) set of functions and 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// function templates that were found by name lookup at template 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// definition time. 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXOperatorCallExpr : public CallExpr { 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// \brief The overloaded operator. 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OverloadedOperatorKind Operator; 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceRange Range; 56c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 57c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) // Record the FP_CONTRACT state that applies to this operator call. Only 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // meaningful for floating point types. For other types this value can be 59323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // set to false. 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) unsigned FPContractable : 1; 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 62323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) SourceRange getSourceRangeImpl() const LLVM_READONLY; 63323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)public: 648abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation operatorloc, bool fpContractable) 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, t, VK, 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) operatorloc), 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Operator(Op), FPContractable(fpContractable) { 705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Range = getSourceRangeImpl(); 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) : 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CallExpr(C, CXXOperatorCallExprClass, Empty) { } 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// getOperator - Returns the kind of overloaded operator that this 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// expression refers to. 78bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) OverloadedOperatorKind getOperator() const { return Operator; } 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// getOperatorLoc - Returns the location of the operator symbol in 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// the expression. When @c getOperator()==OO_Call, this is the 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// location of the right parentheses; when @c 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// getOperator()==OO_Subscript, this is the location of the right 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// bracket. 855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation getOperatorLoc() const { return getRParenLoc(); } 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 89bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) SourceRange getSourceRange() const { return Range; } 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static bool classof(const Stmt *T) { 925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return T->getStmtClass() == CXXOperatorCallExprClass; 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Set the FP contractability status of this operator. Only meaningful for 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // operations on floating point types. 97df95704c49daea886ddad70775bda23618d6274dBen Murdoch void setFPContractable(bool FPC) { FPContractable = FPC; } 985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 99df95704c49daea886ddad70775bda23618d6274dBen Murdoch // Get the FP contractability status of this operator. Only meaningful for 100df95704c49daea886ddad70775bda23618d6274dBen Murdoch // operations on floating point types. 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isFPContractable() const { return FPContractable; } 1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) friend class ASTStmtReader; 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) friend class ASTStmtWriter; 1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// CXXMemberCallExpr - Represents a call to a member function that 1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// may be written either with member call syntax (e.g., "obj.func()" 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// or "objptr->func()") or with normal function-call syntax 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// ("func()") within a member function that ends up calling a member 1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// function. The callee in either case is a MemberExpr that contains 112926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/// both the object argument and the member function, while the 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// arguments are the arguments within the parentheses (not including 1147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci/// the object argument). 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXMemberCallExpr : public CallExpr { 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXMemberCallExpr(ASTContext &C, Expr *fn, ArrayRef<Expr*> args, 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) QualType t, ExprValueKind VK, SourceLocation RP) 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, t, VK, RP) {} 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXMemberCallExpr(ASTContext &C, EmptyShell Empty) 1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CallExpr(C, CXXMemberCallExprClass, Empty) { } 1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// getImplicitObjectArgument - Retrieves the implicit object 125df95704c49daea886ddad70775bda23618d6274dBen Murdoch /// argument for the member call. For example, in "x.f(5)", this 1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// operation would return "x". 127926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) Expr *getImplicitObjectArgument() const; 12806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 12906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) /// Retrieves the declaration of the called method. 1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXMethodDecl *getMethodDecl() const; 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of 1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// the implicit object argument. Note that this is may not be the same 1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// declaration as that of the class context of the CXXMethodDecl which this 1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// function is calling. 1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// FIXME: Returns 0 for member pointer call exprs. 1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXRecordDecl *getRecordDecl() const; 138e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) 1397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci static bool classof(const Stmt *T) { 1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return T->getStmtClass() == CXXMemberCallExprClass; 141f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles) } 142591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}; 143e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) 144e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)/// CUDAKernelCallExpr - Represents a call to a CUDA kernel function. 1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CUDAKernelCallExpr : public CallExpr { 1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private: 1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) enum { CONFIG, END_PREARG }; 1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config, 151e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 152e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) SourceLocation RP) 1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, t, VK, RP) { 1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) setConfig(Config); 155d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } 1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty) 1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { } 1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) const CallExpr *getConfig() const { 1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return cast_or_null<CallExpr>(getPreArg(CONFIG)); 1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } 1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void setConfig(CallExpr *E) { setPreArg(CONFIG, E); } 1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static bool classof(const Stmt *T) { 1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return T->getStmtClass() == CUDAKernelCallExprClass; 1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1717242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 173926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/// const_cast. 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// 1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/// This abstract class is inherited by all of the classes 1769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)/// representing "named" casts, e.g., CXXStaticCastExpr, 17743e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 17843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)class CXXNamedCastExpr : public ExplicitCastExpr { 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private: 1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation Loc; // the location of the casting op 1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation RParenLoc; // the location of the right parenthesis 1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)protected: 1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CastKind kind, Expr *op, unsigned PathSize, 1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) TypeSourceInfo *writtenTy, SourceLocation l, 1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation RParenLoc) 1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l), 1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) RParenLoc(RParenLoc) {} 1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : ExplicitCastExpr(SC, Shell, PathSize) { } 193e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch 194e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch friend class ASTStmtReader; 1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) const char *getCastName() const; 1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// \brief Retrieve the location of the cast operator keyword, e.g., 2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) /// "static_cast". 2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation getOperatorLoc() const { return Loc; } 202c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 203c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) /// \brief Retrieve the location of the closing parenthesis. 2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation getRParenLoc() const { return RParenLoc; } 2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 206c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 207c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 208c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 209c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) static bool classof(const Stmt *T) { 210323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) switch (T->getStmtClass()) { 211323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) case CXXStaticCastExprClass: 2127242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci case CXXDynamicCastExprClass: 2137242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci case CXXReinterpretCastExprClass: 2147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci case CXXConstCastExprClass: 2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return true; 216bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) default: 2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return false; 2189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 220f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)}; 2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 222a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/// CXXStaticCastExpr - A C++ @c static_cast expression 223a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/// (C++ [expr.static.cast]). 224a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/// 22509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/// This expression node represents a C++ static cast, e.g., 22609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/// @c static_cast<int>(1.0). 2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CXXStaticCastExpr : public CXXNamedCastExpr { 2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, 22909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) unsigned pathSize, TypeSourceInfo *writtenTy, 2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) SourceLocation l, SourceLocation RParenLoc) 2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, 232c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) writtenTy, l, RParenLoc) {} 2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 234 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize) 235 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { } 236 237public: 238 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T, 239 ExprValueKind VK, CastKind K, Expr *Op, 240 const CXXCastPath *Path, 241 TypeSourceInfo *Written, SourceLocation L, 242 SourceLocation RParenLoc); 243 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context, 244 unsigned PathSize); 245 246 static bool classof(const Stmt *T) { 247 return T->getStmtClass() == CXXStaticCastExprClass; 248 } 249}; 250 251/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 252/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 253/// determine how to perform the type cast. 254/// 255/// This expression node represents a dynamic cast, e.g., 256/// @c dynamic_cast<Derived*>(BasePtr). 257class CXXDynamicCastExpr : public CXXNamedCastExpr { 258 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, 259 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy, 260 SourceLocation l, SourceLocation RParenLoc) 261 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, 262 writtenTy, l, RParenLoc) {} 263 264 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) 265 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { } 266 267public: 268 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T, 269 ExprValueKind VK, CastKind Kind, Expr *Op, 270 const CXXCastPath *Path, 271 TypeSourceInfo *Written, SourceLocation L, 272 SourceLocation RParenLoc); 273 274 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context, 275 unsigned pathSize); 276 277 bool isAlwaysNull() const; 278 279 static bool classof(const Stmt *T) { 280 return T->getStmtClass() == CXXDynamicCastExprClass; 281 } 282}; 283 284/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 285/// [expr.reinterpret.cast]), which provides a differently-typed view 286/// of a value but performs no actual work at run time. 287/// 288/// This expression node represents a reinterpret cast, e.g., 289/// @c reinterpret_cast<int>(VoidPtr). 290class CXXReinterpretCastExpr : public CXXNamedCastExpr { 291 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, 292 Expr *op, unsigned pathSize, 293 TypeSourceInfo *writtenTy, SourceLocation l, 294 SourceLocation RParenLoc) 295 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, 296 pathSize, writtenTy, l, RParenLoc) {} 297 298 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) 299 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { } 300 301public: 302 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T, 303 ExprValueKind VK, CastKind Kind, 304 Expr *Op, const CXXCastPath *Path, 305 TypeSourceInfo *WrittenTy, SourceLocation L, 306 SourceLocation RParenLoc); 307 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context, 308 unsigned pathSize); 309 310 static bool classof(const Stmt *T) { 311 return T->getStmtClass() == CXXReinterpretCastExprClass; 312 } 313}; 314 315/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 316/// which can remove type qualifiers but does not change the underlying value. 317/// 318/// This expression node represents a const cast, e.g., 319/// @c const_cast<char*>(PtrToConstChar). 320class CXXConstCastExpr : public CXXNamedCastExpr { 321 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, 322 TypeSourceInfo *writtenTy, SourceLocation l, 323 SourceLocation RParenLoc) 324 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 325 0, writtenTy, l, RParenLoc) {} 326 327 explicit CXXConstCastExpr(EmptyShell Empty) 328 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { } 329 330public: 331 static CXXConstCastExpr *Create(ASTContext &Context, QualType T, 332 ExprValueKind VK, Expr *Op, 333 TypeSourceInfo *WrittenTy, SourceLocation L, 334 SourceLocation RParenLoc); 335 static CXXConstCastExpr *CreateEmpty(ASTContext &Context); 336 337 static bool classof(const Stmt *T) { 338 return T->getStmtClass() == CXXConstCastExprClass; 339 } 340}; 341 342/// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal]) 343/// written as a user-defined literal (C++11 [lit.ext]). 344/// 345/// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this 346/// is semantically equivalent to a normal call, this AST node provides better 347/// information about the syntactic representation of the literal. 348/// 349/// Since literal operators are never found by ADL and can only be declared at 350/// namespace scope, a user-defined literal is never dependent. 351class UserDefinedLiteral : public CallExpr { 352 /// \brief The location of a ud-suffix within the literal. 353 SourceLocation UDSuffixLoc; 354 355public: 356 UserDefinedLiteral(ASTContext &C, Expr *Fn, ArrayRef<Expr*> Args, 357 QualType T, ExprValueKind VK, SourceLocation LitEndLoc, 358 SourceLocation SuffixLoc) 359 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, T, VK, LitEndLoc), 360 UDSuffixLoc(SuffixLoc) {} 361 explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty) 362 : CallExpr(C, UserDefinedLiteralClass, Empty) {} 363 364 /// The kind of literal operator which is invoked. 365 enum LiteralOperatorKind { 366 LOK_Raw, ///< Raw form: operator "" X (const char *) 367 LOK_Template, ///< Raw form: operator "" X<cs...> () 368 LOK_Integer, ///< operator "" X (unsigned long long) 369 LOK_Floating, ///< operator "" X (long double) 370 LOK_String, ///< operator "" X (const CharT *, size_t) 371 LOK_Character ///< operator "" X (CharT) 372 }; 373 374 /// getLiteralOperatorKind - Returns the kind of literal operator invocation 375 /// which this expression represents. 376 LiteralOperatorKind getLiteralOperatorKind() const; 377 378 /// getCookedLiteral - If this is not a raw user-defined literal, get the 379 /// underlying cooked literal (representing the literal with the suffix 380 /// removed). 381 Expr *getCookedLiteral(); 382 const Expr *getCookedLiteral() const { 383 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); 384 } 385 386 SourceLocation getLocStart() const { 387 if (getLiteralOperatorKind() == LOK_Template) 388 return getRParenLoc(); 389 return getArg(0)->getLocStart(); 390 } 391 SourceLocation getLocEnd() const { return getRParenLoc(); } 392 393 394 /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression. 395 /// For a string literal, there may be multiple identical suffixes. This 396 /// returns the first. 397 SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } 398 399 /// getUDSuffix - Returns the ud-suffix specified for this literal. 400 const IdentifierInfo *getUDSuffix() const; 401 402 static bool classof(const Stmt *S) { 403 return S->getStmtClass() == UserDefinedLiteralClass; 404 } 405 406 friend class ASTStmtReader; 407 friend class ASTStmtWriter; 408}; 409 410/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 411/// 412class CXXBoolLiteralExpr : public Expr { 413 bool Value; 414 SourceLocation Loc; 415public: 416 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 417 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 418 false, false), 419 Value(val), Loc(l) {} 420 421 explicit CXXBoolLiteralExpr(EmptyShell Empty) 422 : Expr(CXXBoolLiteralExprClass, Empty) { } 423 424 bool getValue() const { return Value; } 425 void setValue(bool V) { Value = V; } 426 427 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 428 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 429 430 SourceLocation getLocation() const { return Loc; } 431 void setLocation(SourceLocation L) { Loc = L; } 432 433 static bool classof(const Stmt *T) { 434 return T->getStmtClass() == CXXBoolLiteralExprClass; 435 } 436 437 // Iterators 438 child_range children() { return child_range(); } 439}; 440 441/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 442class CXXNullPtrLiteralExpr : public Expr { 443 SourceLocation Loc; 444public: 445 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 446 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 447 false, false), 448 Loc(l) {} 449 450 explicit CXXNullPtrLiteralExpr(EmptyShell Empty) 451 : Expr(CXXNullPtrLiteralExprClass, Empty) { } 452 453 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 454 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 455 456 SourceLocation getLocation() const { return Loc; } 457 void setLocation(SourceLocation L) { Loc = L; } 458 459 static bool classof(const Stmt *T) { 460 return T->getStmtClass() == CXXNullPtrLiteralExprClass; 461 } 462 463 child_range children() { return child_range(); } 464}; 465 466/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 467/// the type_info that corresponds to the supplied type, or the (possibly 468/// dynamic) type of the supplied expression. 469/// 470/// This represents code like @c typeid(int) or @c typeid(*objPtr) 471class CXXTypeidExpr : public Expr { 472private: 473 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 474 SourceRange Range; 475 476public: 477 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 478 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 479 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 480 false, 481 // typeid is value-dependent if the type or expression are dependent 482 Operand->getType()->isDependentType(), 483 Operand->getType()->isInstantiationDependentType(), 484 Operand->getType()->containsUnexpandedParameterPack()), 485 Operand(Operand), Range(R) { } 486 487 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) 488 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary, 489 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 490 false, 491 // typeid is value-dependent if the type or expression are dependent 492 Operand->isTypeDependent() || Operand->isValueDependent(), 493 Operand->isInstantiationDependent(), 494 Operand->containsUnexpandedParameterPack()), 495 Operand(Operand), Range(R) { } 496 497 CXXTypeidExpr(EmptyShell Empty, bool isExpr) 498 : Expr(CXXTypeidExprClass, Empty) { 499 if (isExpr) 500 Operand = (Expr*)0; 501 else 502 Operand = (TypeSourceInfo*)0; 503 } 504 505 /// Determine whether this typeid has a type operand which is potentially 506 /// evaluated, per C++11 [expr.typeid]p3. 507 bool isPotentiallyEvaluated() const; 508 509 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 510 511 /// \brief Retrieves the type operand of this typeid() expression after 512 /// various required adjustments (removing reference types, cv-qualifiers). 513 QualType getTypeOperand() const; 514 515 /// \brief Retrieve source information for the type operand. 516 TypeSourceInfo *getTypeOperandSourceInfo() const { 517 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 518 return Operand.get<TypeSourceInfo *>(); 519 } 520 521 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 522 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 523 Operand = TSI; 524 } 525 526 Expr *getExprOperand() const { 527 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 528 return static_cast<Expr*>(Operand.get<Stmt *>()); 529 } 530 531 void setExprOperand(Expr *E) { 532 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 533 Operand = E; 534 } 535 536 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 537 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 538 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 539 void setSourceRange(SourceRange R) { Range = R; } 540 541 static bool classof(const Stmt *T) { 542 return T->getStmtClass() == CXXTypeidExprClass; 543 } 544 545 // Iterators 546 child_range children() { 547 if (isTypeOperand()) return child_range(); 548 Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 549 return child_range(begin, begin + 1); 550 } 551}; 552 553/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets 554/// the _GUID that corresponds to the supplied type or expression. 555/// 556/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) 557class CXXUuidofExpr : public Expr { 558private: 559 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; 560 SourceRange Range; 561 562public: 563 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) 564 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 565 false, Operand->getType()->isDependentType(), 566 Operand->getType()->isInstantiationDependentType(), 567 Operand->getType()->containsUnexpandedParameterPack()), 568 Operand(Operand), Range(R) { } 569 570 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R) 571 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary, 572 false, Operand->isTypeDependent(), 573 Operand->isInstantiationDependent(), 574 Operand->containsUnexpandedParameterPack()), 575 Operand(Operand), Range(R) { } 576 577 CXXUuidofExpr(EmptyShell Empty, bool isExpr) 578 : Expr(CXXUuidofExprClass, Empty) { 579 if (isExpr) 580 Operand = (Expr*)0; 581 else 582 Operand = (TypeSourceInfo*)0; 583 } 584 585 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } 586 587 /// \brief Retrieves the type operand of this __uuidof() expression after 588 /// various required adjustments (removing reference types, cv-qualifiers). 589 QualType getTypeOperand() const; 590 591 /// \brief Retrieve source information for the type operand. 592 TypeSourceInfo *getTypeOperandSourceInfo() const { 593 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 594 return Operand.get<TypeSourceInfo *>(); 595 } 596 597 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) { 598 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); 599 Operand = TSI; 600 } 601 602 Expr *getExprOperand() const { 603 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 604 return static_cast<Expr*>(Operand.get<Stmt *>()); 605 } 606 607 void setExprOperand(Expr *E) { 608 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); 609 Operand = E; 610 } 611 612 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 613 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 614 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 615 void setSourceRange(SourceRange R) { Range = R; } 616 617 static bool classof(const Stmt *T) { 618 return T->getStmtClass() == CXXUuidofExprClass; 619 } 620 621 /// Grabs __declspec(uuid()) off a type, or returns 0 if there is none. 622 static UuidAttr *GetUuidAttrOfType(QualType QT); 623 624 // Iterators 625 child_range children() { 626 if (isTypeOperand()) return child_range(); 627 Stmt **begin = reinterpret_cast<Stmt**>(&Operand); 628 return child_range(begin, begin + 1); 629 } 630}; 631 632/// CXXThisExpr - Represents the "this" expression in C++, which is a 633/// pointer to the object on which the current member function is 634/// executing (C++ [expr.prim]p3). Example: 635/// 636/// @code 637/// class Foo { 638/// public: 639/// void bar(); 640/// void test() { this->bar(); } 641/// }; 642/// @endcode 643class CXXThisExpr : public Expr { 644 SourceLocation Loc; 645 bool Implicit : 1; 646 647public: 648 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit) 649 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary, 650 // 'this' is type-dependent if the class type of the enclosing 651 // member function is dependent (C++ [temp.dep.expr]p2) 652 Type->isDependentType(), Type->isDependentType(), 653 Type->isInstantiationDependentType(), 654 /*ContainsUnexpandedParameterPack=*/false), 655 Loc(L), Implicit(isImplicit) { } 656 657 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} 658 659 SourceLocation getLocation() const { return Loc; } 660 void setLocation(SourceLocation L) { Loc = L; } 661 662 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 663 SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 664 665 bool isImplicit() const { return Implicit; } 666 void setImplicit(bool I) { Implicit = I; } 667 668 static bool classof(const Stmt *T) { 669 return T->getStmtClass() == CXXThisExprClass; 670 } 671 672 // Iterators 673 child_range children() { return child_range(); } 674}; 675 676/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 677/// 'throw' and 'throw' assignment-expression. When 678/// assignment-expression isn't present, Op will be null. 679/// 680class CXXThrowExpr : public Expr { 681 Stmt *Op; 682 SourceLocation ThrowLoc; 683 /// \brief Whether the thrown variable (if any) is in scope. 684 unsigned IsThrownVariableInScope : 1; 685 686 friend class ASTStmtReader; 687 688public: 689 // Ty is the void type which is used as the result type of the 690 // exepression. The l is the location of the throw keyword. expr 691 // can by null, if the optional expression to throw isn't present. 692 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l, 693 bool IsThrownVariableInScope) : 694 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false, 695 expr && expr->isInstantiationDependent(), 696 expr && expr->containsUnexpandedParameterPack()), 697 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {} 698 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} 699 700 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 701 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 702 703 SourceLocation getThrowLoc() const { return ThrowLoc; } 704 705 /// \brief Determines whether the variable thrown by this expression (if any!) 706 /// is within the innermost try block. 707 /// 708 /// This information is required to determine whether the NRVO can apply to 709 /// this variable. 710 bool isThrownVariableInScope() const { return IsThrownVariableInScope; } 711 712 SourceLocation getLocStart() const LLVM_READONLY { return ThrowLoc; } 713 SourceLocation getLocEnd() const LLVM_READONLY { 714 if (getSubExpr() == 0) 715 return ThrowLoc; 716 return getSubExpr()->getLocEnd(); 717 } 718 719 static bool classof(const Stmt *T) { 720 return T->getStmtClass() == CXXThrowExprClass; 721 } 722 723 // Iterators 724 child_range children() { 725 return child_range(&Op, Op ? &Op+1 : &Op); 726 } 727}; 728 729/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 730/// function call argument that was created from the corresponding 731/// parameter's default argument, when the call did not explicitly 732/// supply arguments for all of the parameters. 733class CXXDefaultArgExpr : public Expr { 734 /// \brief The parameter whose default is being used. 735 /// 736 /// When the bit is set, the subexpression is stored after the 737 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 738 /// actual default expression is the subexpression. 739 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 740 741 /// \brief The location where the default argument expression was used. 742 SourceLocation Loc; 743 744 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 745 : Expr(SC, 746 param->hasUnparsedDefaultArg() 747 ? param->getType().getNonReferenceType() 748 : param->getDefaultArg()->getType(), 749 param->getDefaultArg()->getValueKind(), 750 param->getDefaultArg()->getObjectKind(), false, false, false, false), 751 Param(param, false), Loc(Loc) { } 752 753 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 754 Expr *SubExpr) 755 : Expr(SC, SubExpr->getType(), 756 SubExpr->getValueKind(), SubExpr->getObjectKind(), 757 false, false, false, false), 758 Param(param, true), Loc(Loc) { 759 *reinterpret_cast<Expr **>(this + 1) = SubExpr; 760 } 761 762public: 763 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} 764 765 766 // Param is the parameter whose default argument is used by this 767 // expression. 768 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 769 ParmVarDecl *Param) { 770 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 771 } 772 773 // Param is the parameter whose default argument is used by this 774 // expression, and SubExpr is the expression that will actually be used. 775 static CXXDefaultArgExpr *Create(ASTContext &C, 776 SourceLocation Loc, 777 ParmVarDecl *Param, 778 Expr *SubExpr); 779 780 // Retrieve the parameter that the argument was created from. 781 const ParmVarDecl *getParam() const { return Param.getPointer(); } 782 ParmVarDecl *getParam() { return Param.getPointer(); } 783 784 // Retrieve the actual argument to the function call. 785 const Expr *getExpr() const { 786 if (Param.getInt()) 787 return *reinterpret_cast<Expr const * const*> (this + 1); 788 return getParam()->getDefaultArg(); 789 } 790 Expr *getExpr() { 791 if (Param.getInt()) 792 return *reinterpret_cast<Expr **> (this + 1); 793 return getParam()->getDefaultArg(); 794 } 795 796 /// \brief Retrieve the location where this default argument was actually 797 /// used. 798 SourceLocation getUsedLocation() const { return Loc; } 799 800 // Default argument expressions have no representation in the 801 // source, so they have an empty source range. 802 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 803 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 804 805 SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 806 807 static bool classof(const Stmt *T) { 808 return T->getStmtClass() == CXXDefaultArgExprClass; 809 } 810 811 // Iterators 812 child_range children() { return child_range(); } 813 814 friend class ASTStmtReader; 815 friend class ASTStmtWriter; 816}; 817 818/// CXXTemporary - Represents a C++ temporary. 819class CXXTemporary { 820 /// Destructor - The destructor that needs to be called. 821 const CXXDestructorDecl *Destructor; 822 823 CXXTemporary(const CXXDestructorDecl *destructor) 824 : Destructor(destructor) { } 825 826public: 827 static CXXTemporary *Create(ASTContext &C, 828 const CXXDestructorDecl *Destructor); 829 830 const CXXDestructorDecl *getDestructor() const { return Destructor; } 831 void setDestructor(const CXXDestructorDecl *Dtor) { 832 Destructor = Dtor; 833 } 834}; 835 836/// \brief Represents binding an expression to a temporary. 837/// 838/// This ensures the destructor is called for the temporary. It should only be 839/// needed for non-POD, non-trivially destructable class types. For example: 840/// 841/// \code 842/// struct S { 843/// S() { } // User defined constructor makes S non-POD. 844/// ~S() { } // User defined destructor makes it non-trivial. 845/// }; 846/// void test() { 847/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 848/// } 849/// \endcode 850class CXXBindTemporaryExpr : public Expr { 851 CXXTemporary *Temp; 852 853 Stmt *SubExpr; 854 855 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 856 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 857 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 858 SubExpr->isValueDependent(), 859 SubExpr->isInstantiationDependent(), 860 SubExpr->containsUnexpandedParameterPack()), 861 Temp(temp), SubExpr(SubExpr) { } 862 863public: 864 CXXBindTemporaryExpr(EmptyShell Empty) 865 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 866 867 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 868 Expr* SubExpr); 869 870 CXXTemporary *getTemporary() { return Temp; } 871 const CXXTemporary *getTemporary() const { return Temp; } 872 void setTemporary(CXXTemporary *T) { Temp = T; } 873 874 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 875 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 876 void setSubExpr(Expr *E) { SubExpr = E; } 877 878 SourceLocation getLocStart() const LLVM_READONLY { 879 return SubExpr->getLocStart(); 880 } 881 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 882 883 // Implement isa/cast/dyncast/etc. 884 static bool classof(const Stmt *T) { 885 return T->getStmtClass() == CXXBindTemporaryExprClass; 886 } 887 888 // Iterators 889 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 890}; 891 892/// \brief Represents a call to a C++ constructor. 893class CXXConstructExpr : public Expr { 894public: 895 enum ConstructionKind { 896 CK_Complete, 897 CK_NonVirtualBase, 898 CK_VirtualBase, 899 CK_Delegating 900 }; 901 902private: 903 CXXConstructorDecl *Constructor; 904 905 SourceLocation Loc; 906 SourceRange ParenRange; 907 unsigned NumArgs : 16; 908 bool Elidable : 1; 909 bool HadMultipleCandidates : 1; 910 bool ListInitialization : 1; 911 bool ZeroInitialization : 1; 912 unsigned ConstructKind : 2; 913 Stmt **Args; 914 915protected: 916 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 917 SourceLocation Loc, 918 CXXConstructorDecl *d, bool elidable, 919 ArrayRef<Expr *> Args, 920 bool HadMultipleCandidates, 921 bool ListInitialization, 922 bool ZeroInitialization, 923 ConstructionKind ConstructKind, 924 SourceRange ParenRange); 925 926 /// \brief Construct an empty C++ construction expression. 927 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 928 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 929 HadMultipleCandidates(false), ListInitialization(false), 930 ZeroInitialization(false), ConstructKind(0), Args(0) 931 { } 932 933public: 934 /// \brief Construct an empty C++ construction expression. 935 explicit CXXConstructExpr(EmptyShell Empty) 936 : Expr(CXXConstructExprClass, Empty), Constructor(0), 937 NumArgs(0), Elidable(false), HadMultipleCandidates(false), 938 ListInitialization(false), ZeroInitialization(false), 939 ConstructKind(0), Args(0) 940 { } 941 942 static CXXConstructExpr *Create(ASTContext &C, QualType T, 943 SourceLocation Loc, 944 CXXConstructorDecl *D, bool Elidable, 945 ArrayRef<Expr *> Args, 946 bool HadMultipleCandidates, 947 bool ListInitialization, 948 bool ZeroInitialization, 949 ConstructionKind ConstructKind, 950 SourceRange ParenRange); 951 952 CXXConstructorDecl* getConstructor() const { return Constructor; } 953 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 954 955 SourceLocation getLocation() const { return Loc; } 956 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 957 958 /// \brief Whether this construction is elidable. 959 bool isElidable() const { return Elidable; } 960 void setElidable(bool E) { Elidable = E; } 961 962 /// \brief Whether the referred constructor was resolved from 963 /// an overloaded set having size greater than 1. 964 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 965 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 966 967 /// \brief Whether this constructor call was written as list-initialization. 968 bool isListInitialization() const { return ListInitialization; } 969 void setListInitialization(bool V) { ListInitialization = V; } 970 971 /// \brief Whether this construction first requires 972 /// zero-initialization before the initializer is called. 973 bool requiresZeroInitialization() const { return ZeroInitialization; } 974 void setRequiresZeroInitialization(bool ZeroInit) { 975 ZeroInitialization = ZeroInit; 976 } 977 978 /// \brief Determines whether this constructor is actually constructing 979 /// a base class (rather than a complete object). 980 ConstructionKind getConstructionKind() const { 981 return (ConstructionKind)ConstructKind; 982 } 983 void setConstructionKind(ConstructionKind CK) { 984 ConstructKind = CK; 985 } 986 987 typedef ExprIterator arg_iterator; 988 typedef ConstExprIterator const_arg_iterator; 989 990 arg_iterator arg_begin() { return Args; } 991 arg_iterator arg_end() { return Args + NumArgs; } 992 const_arg_iterator arg_begin() const { return Args; } 993 const_arg_iterator arg_end() const { return Args + NumArgs; } 994 995 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 996 unsigned getNumArgs() const { return NumArgs; } 997 998 /// getArg - Return the specified argument. 999 Expr *getArg(unsigned Arg) { 1000 assert(Arg < NumArgs && "Arg access out of range!"); 1001 return cast<Expr>(Args[Arg]); 1002 } 1003 const Expr *getArg(unsigned Arg) const { 1004 assert(Arg < NumArgs && "Arg access out of range!"); 1005 return cast<Expr>(Args[Arg]); 1006 } 1007 1008 /// setArg - Set the specified argument. 1009 void setArg(unsigned Arg, Expr *ArgExpr) { 1010 assert(Arg < NumArgs && "Arg access out of range!"); 1011 Args[Arg] = ArgExpr; 1012 } 1013 1014 SourceLocation getLocStart() const LLVM_READONLY; 1015 SourceLocation getLocEnd() const LLVM_READONLY; 1016 SourceRange getParenRange() const { return ParenRange; } 1017 void setParenRange(SourceRange Range) { ParenRange = Range; } 1018 1019 static bool classof(const Stmt *T) { 1020 return T->getStmtClass() == CXXConstructExprClass || 1021 T->getStmtClass() == CXXTemporaryObjectExprClass; 1022 } 1023 1024 // Iterators 1025 child_range children() { 1026 return child_range(&Args[0], &Args[0]+NumArgs); 1027 } 1028 1029 friend class ASTStmtReader; 1030}; 1031 1032/// \brief Represents an explicit C++ type conversion that uses "functional" 1033/// notation (C++ [expr.type.conv]). 1034/// 1035/// Example: 1036/// @code 1037/// x = int(0.5); 1038/// @endcode 1039class CXXFunctionalCastExpr : public ExplicitCastExpr { 1040 SourceLocation TyBeginLoc; 1041 SourceLocation RParenLoc; 1042 1043 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 1044 TypeSourceInfo *writtenTy, 1045 SourceLocation tyBeginLoc, CastKind kind, 1046 Expr *castExpr, unsigned pathSize, 1047 SourceLocation rParenLoc) 1048 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 1049 castExpr, pathSize, writtenTy), 1050 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 1051 1052 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 1053 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 1054 1055public: 1056 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 1057 ExprValueKind VK, 1058 TypeSourceInfo *Written, 1059 SourceLocation TyBeginLoc, 1060 CastKind Kind, Expr *Op, 1061 const CXXCastPath *Path, 1062 SourceLocation RPLoc); 1063 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 1064 unsigned PathSize); 1065 1066 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1067 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1068 SourceLocation getRParenLoc() const { return RParenLoc; } 1069 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1070 1071 SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; } 1072 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1073 1074 static bool classof(const Stmt *T) { 1075 return T->getStmtClass() == CXXFunctionalCastExprClass; 1076 } 1077}; 1078 1079/// @brief Represents a C++ functional cast expression that builds a 1080/// temporary object. 1081/// 1082/// This expression type represents a C++ "functional" cast 1083/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 1084/// constructor to build a temporary object. With N == 1 arguments the 1085/// functional cast expression will be represented by CXXFunctionalCastExpr. 1086/// Example: 1087/// @code 1088/// struct X { X(int, float); } 1089/// 1090/// X create_X() { 1091/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 1092/// }; 1093/// @endcode 1094class CXXTemporaryObjectExpr : public CXXConstructExpr { 1095 TypeSourceInfo *Type; 1096 1097public: 1098 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1099 TypeSourceInfo *Type, 1100 ArrayRef<Expr *> Args, 1101 SourceRange parenRange, 1102 bool HadMultipleCandidates, 1103 bool ListInitialization, 1104 bool ZeroInitialization); 1105 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1106 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1107 1108 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1109 1110 SourceLocation getLocStart() const LLVM_READONLY; 1111 SourceLocation getLocEnd() const LLVM_READONLY; 1112 1113 static bool classof(const Stmt *T) { 1114 return T->getStmtClass() == CXXTemporaryObjectExprClass; 1115 } 1116 1117 friend class ASTStmtReader; 1118}; 1119 1120/// \brief A C++ lambda expression, which produces a function object 1121/// (of unspecified type) that can be invoked later. 1122/// 1123/// Example: 1124/// \code 1125/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1126/// values.erase(std::remove_if(values.begin(), values.end(), 1127/// [=](double value) { return value > cutoff; }); 1128/// } 1129/// \endcode 1130/// 1131/// Lambda expressions can capture local variables, either by copying 1132/// the values of those local variables at the time the function 1133/// object is constructed (not when it is called!) or by holding a 1134/// reference to the local variable. These captures can occur either 1135/// implicitly or can be written explicitly between the square 1136/// brackets ([...]) that start the lambda expression. 1137class LambdaExpr : public Expr { 1138 enum { 1139 /// \brief Flag used by the Capture class to indicate that the given 1140 /// capture was implicit. 1141 Capture_Implicit = 0x01, 1142 1143 /// \brief Flag used by the Capture class to indciate that the 1144 /// given capture was by-copy. 1145 Capture_ByCopy = 0x02 1146 }; 1147 1148 /// \brief The source range that covers the lambda introducer ([...]). 1149 SourceRange IntroducerRange; 1150 1151 /// \brief The number of captures. 1152 unsigned NumCaptures : 16; 1153 1154 /// \brief The default capture kind, which is a value of type 1155 /// LambdaCaptureDefault. 1156 unsigned CaptureDefault : 2; 1157 1158 /// \brief Whether this lambda had an explicit parameter list vs. an 1159 /// implicit (and empty) parameter list. 1160 unsigned ExplicitParams : 1; 1161 1162 /// \brief Whether this lambda had the result type explicitly specified. 1163 unsigned ExplicitResultType : 1; 1164 1165 /// \brief Whether there are any array index variables stored at the end of 1166 /// this lambda expression. 1167 unsigned HasArrayIndexVars : 1; 1168 1169 /// \brief The location of the closing brace ('}') that completes 1170 /// the lambda. 1171 /// 1172 /// The location of the brace is also available by looking up the 1173 /// function call operator in the lambda class. However, it is 1174 /// stored here to improve the performance of getSourceRange(), and 1175 /// to avoid having to deserialize the function call operator from a 1176 /// module file just to determine the source range. 1177 SourceLocation ClosingBrace; 1178 1179 // Note: The capture initializers are stored directly after the lambda 1180 // expression, along with the index variables used to initialize by-copy 1181 // array captures. 1182 1183public: 1184 /// \brief Describes the capture of either a variable or 'this'. 1185 class Capture { 1186 llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 1187 SourceLocation Loc; 1188 SourceLocation EllipsisLoc; 1189 1190 friend class ASTStmtReader; 1191 friend class ASTStmtWriter; 1192 1193 public: 1194 /// \brief Create a new capture. 1195 /// 1196 /// \param Loc The source location associated with this capture. 1197 /// 1198 /// \param Kind The kind of capture (this, byref, bycopy). 1199 /// 1200 /// \param Implicit Whether the capture was implicit or explicit. 1201 /// 1202 /// \param Var The local variable being captured, or null if capturing this. 1203 /// 1204 /// \param EllipsisLoc The location of the ellipsis (...) for a 1205 /// capture that is a pack expansion, or an invalid source 1206 /// location to indicate that this is not a pack expansion. 1207 Capture(SourceLocation Loc, bool Implicit, 1208 LambdaCaptureKind Kind, VarDecl *Var = 0, 1209 SourceLocation EllipsisLoc = SourceLocation()); 1210 1211 /// \brief Determine the kind of capture. 1212 LambdaCaptureKind getCaptureKind() const; 1213 1214 /// \brief Determine whether this capture handles the C++ 'this' 1215 /// pointer. 1216 bool capturesThis() const { return VarAndBits.getPointer() == 0; } 1217 1218 /// \brief Determine whether this capture handles a variable. 1219 bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 1220 1221 /// \brief Retrieve the declaration of the local variable being 1222 /// captured. 1223 /// 1224 /// This operation is only valid if this capture does not capture 1225 /// 'this'. 1226 VarDecl *getCapturedVar() const { 1227 assert(!capturesThis() && "No variable available for 'this' capture"); 1228 return VarAndBits.getPointer(); 1229 } 1230 1231 /// \brief Determine whether this was an implicit capture (not 1232 /// written between the square brackets introducing the lambda). 1233 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 1234 1235 /// \brief Determine whether this was an explicit capture, written 1236 /// between the square brackets introducing the lambda. 1237 bool isExplicit() const { return !isImplicit(); } 1238 1239 /// \brief Retrieve the source location of the capture. 1240 /// 1241 /// For an explicit capture, this returns the location of the 1242 /// explicit capture in the source. For an implicit capture, this 1243 /// returns the location at which the variable or 'this' was first 1244 /// used. 1245 SourceLocation getLocation() const { return Loc; } 1246 1247 /// \brief Determine whether this capture is a pack expansion, 1248 /// which captures a function parameter pack. 1249 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1250 1251 /// \brief Retrieve the location of the ellipsis for a capture 1252 /// that is a pack expansion. 1253 SourceLocation getEllipsisLoc() const { 1254 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1255 return EllipsisLoc; 1256 } 1257 }; 1258 1259private: 1260 /// \brief Construct a lambda expression. 1261 LambdaExpr(QualType T, SourceRange IntroducerRange, 1262 LambdaCaptureDefault CaptureDefault, 1263 ArrayRef<Capture> Captures, 1264 bool ExplicitParams, 1265 bool ExplicitResultType, 1266 ArrayRef<Expr *> CaptureInits, 1267 ArrayRef<VarDecl *> ArrayIndexVars, 1268 ArrayRef<unsigned> ArrayIndexStarts, 1269 SourceLocation ClosingBrace, 1270 bool ContainsUnexpandedParameterPack); 1271 1272 /// \brief Construct an empty lambda expression. 1273 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars) 1274 : Expr(LambdaExprClass, Empty), 1275 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false), 1276 ExplicitResultType(false), HasArrayIndexVars(true) { 1277 getStoredStmts()[NumCaptures] = 0; 1278 } 1279 1280 Stmt **getStoredStmts() const { 1281 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1); 1282 } 1283 1284 /// \brief Retrieve the mapping from captures to the first array index 1285 /// variable. 1286 unsigned *getArrayIndexStarts() const { 1287 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1); 1288 } 1289 1290 /// \brief Retrieve the complete set of array-index variables. 1291 VarDecl **getArrayIndexVars() const { 1292 unsigned ArrayIndexSize = 1293 llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1), 1294 llvm::alignOf<VarDecl*>()); 1295 return reinterpret_cast<VarDecl **>( 1296 reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize); 1297 } 1298 1299public: 1300 /// \brief Construct a new lambda expression. 1301 static LambdaExpr *Create(ASTContext &C, 1302 CXXRecordDecl *Class, 1303 SourceRange IntroducerRange, 1304 LambdaCaptureDefault CaptureDefault, 1305 ArrayRef<Capture> Captures, 1306 bool ExplicitParams, 1307 bool ExplicitResultType, 1308 ArrayRef<Expr *> CaptureInits, 1309 ArrayRef<VarDecl *> ArrayIndexVars, 1310 ArrayRef<unsigned> ArrayIndexStarts, 1311 SourceLocation ClosingBrace, 1312 bool ContainsUnexpandedParameterPack); 1313 1314 /// \brief Construct a new lambda expression that will be deserialized from 1315 /// an external source. 1316 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures, 1317 unsigned NumArrayIndexVars); 1318 1319 /// \brief Determine the default capture kind for this lambda. 1320 LambdaCaptureDefault getCaptureDefault() const { 1321 return static_cast<LambdaCaptureDefault>(CaptureDefault); 1322 } 1323 1324 /// \brief An iterator that walks over the captures of the lambda, 1325 /// both implicit and explicit. 1326 typedef const Capture *capture_iterator; 1327 1328 /// \brief Retrieve an iterator pointing to the first lambda capture. 1329 capture_iterator capture_begin() const; 1330 1331 /// \brief Retrieve an iterator pointing past the end of the 1332 /// sequence of lambda captures. 1333 capture_iterator capture_end() const; 1334 1335 /// \brief Determine the number of captures in this lambda. 1336 unsigned capture_size() const { return NumCaptures; } 1337 1338 /// \brief Retrieve an iterator pointing to the first explicit 1339 /// lambda capture. 1340 capture_iterator explicit_capture_begin() const; 1341 1342 /// \brief Retrieve an iterator pointing past the end of the sequence of 1343 /// explicit lambda captures. 1344 capture_iterator explicit_capture_end() const; 1345 1346 /// \brief Retrieve an iterator pointing to the first implicit 1347 /// lambda capture. 1348 capture_iterator implicit_capture_begin() const; 1349 1350 /// \brief Retrieve an iterator pointing past the end of the sequence of 1351 /// implicit lambda captures. 1352 capture_iterator implicit_capture_end() const; 1353 1354 /// \brief Iterator that walks over the capture initialization 1355 /// arguments. 1356 typedef Expr **capture_init_iterator; 1357 1358 /// \brief Retrieve the first initialization argument for this 1359 /// lambda expression (which initializes the first capture field). 1360 capture_init_iterator capture_init_begin() const { 1361 return reinterpret_cast<Expr **>(getStoredStmts()); 1362 } 1363 1364 /// \brief Retrieve the iterator pointing one past the last 1365 /// initialization argument for this lambda expression. 1366 capture_init_iterator capture_init_end() const { 1367 return capture_init_begin() + NumCaptures; 1368 } 1369 1370 /// \brief Retrieve the set of index variables used in the capture 1371 /// initializer of an array captured by copy. 1372 /// 1373 /// \param Iter The iterator that points at the capture initializer for 1374 /// which we are extracting the corresponding index variables. 1375 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const; 1376 1377 /// \brief Retrieve the source range covering the lambda introducer, 1378 /// which contains the explicit capture list surrounded by square 1379 /// brackets ([...]). 1380 SourceRange getIntroducerRange() const { return IntroducerRange; } 1381 1382 /// \brief Retrieve the class that corresponds to the lambda, which 1383 /// stores the captures in its fields and provides the various 1384 /// operations permitted on a lambda (copying, calling). 1385 CXXRecordDecl *getLambdaClass() const; 1386 1387 /// \brief Retrieve the function call operator associated with this 1388 /// lambda expression. 1389 CXXMethodDecl *getCallOperator() const; 1390 1391 /// \brief Retrieve the body of the lambda. 1392 CompoundStmt *getBody() const; 1393 1394 /// \brief Determine whether the lambda is mutable, meaning that any 1395 /// captures values can be modified. 1396 bool isMutable() const; 1397 1398 /// \brief Determine whether this lambda has an explicit parameter 1399 /// list vs. an implicit (empty) parameter list. 1400 bool hasExplicitParameters() const { return ExplicitParams; } 1401 1402 /// \brief Whether this lambda had its result type explicitly specified. 1403 bool hasExplicitResultType() const { return ExplicitResultType; } 1404 1405 static bool classof(const Stmt *T) { 1406 return T->getStmtClass() == LambdaExprClass; 1407 } 1408 1409 SourceLocation getLocStart() const LLVM_READONLY { 1410 return IntroducerRange.getBegin(); 1411 } 1412 SourceLocation getLocEnd() const LLVM_READONLY { return ClosingBrace; } 1413 1414 child_range children() { 1415 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1416 } 1417 1418 friend class ASTStmtReader; 1419 friend class ASTStmtWriter; 1420}; 1421 1422/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1423/// Expression "T()" which creates a value-initialized rvalue of type 1424/// T, which is a non-class type. 1425/// 1426class CXXScalarValueInitExpr : public Expr { 1427 SourceLocation RParenLoc; 1428 TypeSourceInfo *TypeInfo; 1429 1430 friend class ASTStmtReader; 1431 1432public: 1433 /// \brief Create an explicitly-written scalar-value initialization 1434 /// expression. 1435 CXXScalarValueInitExpr(QualType Type, 1436 TypeSourceInfo *TypeInfo, 1437 SourceLocation rParenLoc ) : 1438 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1439 false, false, Type->isInstantiationDependentType(), false), 1440 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1441 1442 explicit CXXScalarValueInitExpr(EmptyShell Shell) 1443 : Expr(CXXScalarValueInitExprClass, Shell) { } 1444 1445 TypeSourceInfo *getTypeSourceInfo() const { 1446 return TypeInfo; 1447 } 1448 1449 SourceLocation getRParenLoc() const { return RParenLoc; } 1450 1451 SourceLocation getLocStart() const LLVM_READONLY; 1452 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 1453 1454 static bool classof(const Stmt *T) { 1455 return T->getStmtClass() == CXXScalarValueInitExprClass; 1456 } 1457 1458 // Iterators 1459 child_range children() { return child_range(); } 1460}; 1461 1462/// @brief Represents a new-expression for memory allocation and constructor 1463// calls, e.g: "new CXXNewExpr(foo)". 1464class CXXNewExpr : public Expr { 1465 // Contains an optional array size expression, an optional initialization 1466 // expression, and any number of optional placement arguments, in that order. 1467 Stmt **SubExprs; 1468 /// \brief Points to the allocation function used. 1469 FunctionDecl *OperatorNew; 1470 /// \brief Points to the deallocation function used in case of error. May be 1471 /// null. 1472 FunctionDecl *OperatorDelete; 1473 1474 /// \brief The allocated type-source information, as written in the source. 1475 TypeSourceInfo *AllocatedTypeInfo; 1476 1477 /// \brief If the allocated type was expressed as a parenthesized type-id, 1478 /// the source range covering the parenthesized type-id. 1479 SourceRange TypeIdParens; 1480 1481 /// \brief Range of the entire new expression. 1482 SourceRange Range; 1483 1484 /// \brief Source-range of a paren-delimited initializer. 1485 SourceRange DirectInitRange; 1486 1487 // Was the usage ::new, i.e. is the global new to be used? 1488 bool GlobalNew : 1; 1489 // Do we allocate an array? If so, the first SubExpr is the size expression. 1490 bool Array : 1; 1491 // If this is an array allocation, does the usual deallocation 1492 // function for the allocated type want to know the allocated size? 1493 bool UsualArrayDeleteWantsSize : 1; 1494 // The number of placement new arguments. 1495 unsigned NumPlacementArgs : 13; 1496 // What kind of initializer do we have? Could be none, parens, or braces. 1497 // In storage, we distinguish between "none, and no initializer expr", and 1498 // "none, but an implicit initializer expr". 1499 unsigned StoredInitializationStyle : 2; 1500 1501 friend class ASTStmtReader; 1502 friend class ASTStmtWriter; 1503public: 1504 enum InitializationStyle { 1505 NoInit, ///< New-expression has no initializer as written. 1506 CallInit, ///< New-expression has a C++98 paren-delimited initializer. 1507 ListInit ///< New-expression has a C++11 list-initializer. 1508 }; 1509 1510 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1511 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1512 ArrayRef<Expr*> placementArgs, 1513 SourceRange typeIdParens, Expr *arraySize, 1514 InitializationStyle initializationStyle, Expr *initializer, 1515 QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1516 SourceRange Range, SourceRange directInitRange); 1517 explicit CXXNewExpr(EmptyShell Shell) 1518 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1519 1520 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1521 bool hasInitializer); 1522 1523 QualType getAllocatedType() const { 1524 assert(getType()->isPointerType()); 1525 return getType()->getAs<PointerType>()->getPointeeType(); 1526 } 1527 1528 TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1529 return AllocatedTypeInfo; 1530 } 1531 1532 /// \brief True if the allocation result needs to be null-checked. 1533 /// C++0x [expr.new]p13: 1534 /// If the allocation function returns null, initialization shall 1535 /// not be done, the deallocation function shall not be called, 1536 /// and the value of the new-expression shall be null. 1537 /// An allocation function is not allowed to return null unless it 1538 /// has a non-throwing exception-specification. The '03 rule is 1539 /// identical except that the definition of a non-throwing 1540 /// exception specification is just "is it throw()?". 1541 bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1542 1543 FunctionDecl *getOperatorNew() const { return OperatorNew; } 1544 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1545 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1546 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1547 1548 bool isArray() const { return Array; } 1549 Expr *getArraySize() { 1550 return Array ? cast<Expr>(SubExprs[0]) : 0; 1551 } 1552 const Expr *getArraySize() const { 1553 return Array ? cast<Expr>(SubExprs[0]) : 0; 1554 } 1555 1556 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1557 Expr **getPlacementArgs() { 1558 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer()); 1559 } 1560 1561 Expr *getPlacementArg(unsigned i) { 1562 assert(i < NumPlacementArgs && "Index out of range"); 1563 return getPlacementArgs()[i]; 1564 } 1565 const Expr *getPlacementArg(unsigned i) const { 1566 assert(i < NumPlacementArgs && "Index out of range"); 1567 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i); 1568 } 1569 1570 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1571 SourceRange getTypeIdParens() const { return TypeIdParens; } 1572 1573 bool isGlobalNew() const { return GlobalNew; } 1574 1575 /// \brief Whether this new-expression has any initializer at all. 1576 bool hasInitializer() const { return StoredInitializationStyle > 0; } 1577 1578 /// \brief The kind of initializer this new-expression has. 1579 InitializationStyle getInitializationStyle() const { 1580 if (StoredInitializationStyle == 0) 1581 return NoInit; 1582 return static_cast<InitializationStyle>(StoredInitializationStyle-1); 1583 } 1584 1585 /// \brief The initializer of this new-expression. 1586 Expr *getInitializer() { 1587 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1588 } 1589 const Expr *getInitializer() const { 1590 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0; 1591 } 1592 1593 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL. 1594 const CXXConstructExpr* getConstructExpr() const { 1595 return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); 1596 } 1597 1598 /// Answers whether the usual array deallocation function for the 1599 /// allocated type expects the size of the allocation as a 1600 /// parameter. 1601 bool doesUsualArrayDeleteWantSize() const { 1602 return UsualArrayDeleteWantsSize; 1603 } 1604 1605 typedef ExprIterator arg_iterator; 1606 typedef ConstExprIterator const_arg_iterator; 1607 1608 arg_iterator placement_arg_begin() { 1609 return SubExprs + Array + hasInitializer(); 1610 } 1611 arg_iterator placement_arg_end() { 1612 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1613 } 1614 const_arg_iterator placement_arg_begin() const { 1615 return SubExprs + Array + hasInitializer(); 1616 } 1617 const_arg_iterator placement_arg_end() const { 1618 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1619 } 1620 1621 typedef Stmt **raw_arg_iterator; 1622 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1623 raw_arg_iterator raw_arg_end() { 1624 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1625 } 1626 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1627 const_arg_iterator raw_arg_end() const { 1628 return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); 1629 } 1630 1631 SourceLocation getStartLoc() const { return Range.getBegin(); } 1632 SourceLocation getEndLoc() const { return Range.getEnd(); } 1633 1634 SourceRange getDirectInitRange() const { return DirectInitRange; } 1635 1636 SourceRange getSourceRange() const LLVM_READONLY { 1637 return Range; 1638 } 1639 SourceLocation getLocStart() const LLVM_READONLY { return getStartLoc(); } 1640 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } 1641 1642 static bool classof(const Stmt *T) { 1643 return T->getStmtClass() == CXXNewExprClass; 1644 } 1645 1646 // Iterators 1647 child_range children() { 1648 return child_range(raw_arg_begin(), raw_arg_end()); 1649 } 1650}; 1651 1652/// \brief Represents a \c delete expression for memory deallocation and 1653/// destructor calls, e.g. "delete[] pArray". 1654class CXXDeleteExpr : public Expr { 1655 // Points to the operator delete overload that is used. Could be a member. 1656 FunctionDecl *OperatorDelete; 1657 // The pointer expression to be deleted. 1658 Stmt *Argument; 1659 // Location of the expression. 1660 SourceLocation Loc; 1661 // Is this a forced global delete, i.e. "::delete"? 1662 bool GlobalDelete : 1; 1663 // Is this the array form of delete, i.e. "delete[]"? 1664 bool ArrayForm : 1; 1665 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1666 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1667 // will be true). 1668 bool ArrayFormAsWritten : 1; 1669 // Does the usual deallocation function for the element type require 1670 // a size_t argument? 1671 bool UsualArrayDeleteWantsSize : 1; 1672public: 1673 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1674 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1675 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1676 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1677 arg->isInstantiationDependent(), 1678 arg->containsUnexpandedParameterPack()), 1679 OperatorDelete(operatorDelete), Argument(arg), Loc(loc), 1680 GlobalDelete(globalDelete), 1681 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1682 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { } 1683 explicit CXXDeleteExpr(EmptyShell Shell) 1684 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1685 1686 bool isGlobalDelete() const { return GlobalDelete; } 1687 bool isArrayForm() const { return ArrayForm; } 1688 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1689 1690 /// Answers whether the usual array deallocation function for the 1691 /// allocated type expects the size of the allocation as a 1692 /// parameter. This can be true even if the actual deallocation 1693 /// function that we're using doesn't want a size. 1694 bool doesUsualArrayDeleteWantSize() const { 1695 return UsualArrayDeleteWantsSize; 1696 } 1697 1698 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1699 1700 Expr *getArgument() { return cast<Expr>(Argument); } 1701 const Expr *getArgument() const { return cast<Expr>(Argument); } 1702 1703 /// \brief Retrieve the type being destroyed. If the type being 1704 /// destroyed is a dependent type which may or may not be a pointer, 1705 /// return an invalid type. 1706 QualType getDestroyedType() const; 1707 1708 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 1709 SourceLocation getLocEnd() const LLVM_READONLY {return Argument->getLocEnd();} 1710 1711 static bool classof(const Stmt *T) { 1712 return T->getStmtClass() == CXXDeleteExprClass; 1713 } 1714 1715 // Iterators 1716 child_range children() { return child_range(&Argument, &Argument+1); } 1717 1718 friend class ASTStmtReader; 1719}; 1720 1721/// \brief Stores the type being destroyed by a pseudo-destructor expression. 1722class PseudoDestructorTypeStorage { 1723 /// \brief Either the type source information or the name of the type, if 1724 /// it couldn't be resolved due to type-dependence. 1725 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1726 1727 /// \brief The starting source location of the pseudo-destructor type. 1728 SourceLocation Location; 1729 1730public: 1731 PseudoDestructorTypeStorage() { } 1732 1733 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1734 : Type(II), Location(Loc) { } 1735 1736 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1737 1738 TypeSourceInfo *getTypeSourceInfo() const { 1739 return Type.dyn_cast<TypeSourceInfo *>(); 1740 } 1741 1742 IdentifierInfo *getIdentifier() const { 1743 return Type.dyn_cast<IdentifierInfo *>(); 1744 } 1745 1746 SourceLocation getLocation() const { return Location; } 1747}; 1748 1749/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1750/// 1751/// A pseudo-destructor is an expression that looks like a member access to a 1752/// destructor of a scalar type, except that scalar types don't have 1753/// destructors. For example: 1754/// 1755/// \code 1756/// typedef int T; 1757/// void f(int *p) { 1758/// p->T::~T(); 1759/// } 1760/// \endcode 1761/// 1762/// Pseudo-destructors typically occur when instantiating templates such as: 1763/// 1764/// \code 1765/// template<typename T> 1766/// void destroy(T* ptr) { 1767/// ptr->T::~T(); 1768/// } 1769/// \endcode 1770/// 1771/// for scalar types. A pseudo-destructor expression has no run-time semantics 1772/// beyond evaluating the base expression. 1773class CXXPseudoDestructorExpr : public Expr { 1774 /// \brief The base expression (that is being destroyed). 1775 Stmt *Base; 1776 1777 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1778 /// period ('.'). 1779 bool IsArrow : 1; 1780 1781 /// \brief The location of the '.' or '->' operator. 1782 SourceLocation OperatorLoc; 1783 1784 /// \brief The nested-name-specifier that follows the operator, if present. 1785 NestedNameSpecifierLoc QualifierLoc; 1786 1787 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1788 /// expression. 1789 TypeSourceInfo *ScopeType; 1790 1791 /// \brief The location of the '::' in a qualified pseudo-destructor 1792 /// expression. 1793 SourceLocation ColonColonLoc; 1794 1795 /// \brief The location of the '~'. 1796 SourceLocation TildeLoc; 1797 1798 /// \brief The type being destroyed, or its name if we were unable to 1799 /// resolve the name. 1800 PseudoDestructorTypeStorage DestroyedType; 1801 1802 friend class ASTStmtReader; 1803 1804public: 1805 CXXPseudoDestructorExpr(ASTContext &Context, 1806 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1807 NestedNameSpecifierLoc QualifierLoc, 1808 TypeSourceInfo *ScopeType, 1809 SourceLocation ColonColonLoc, 1810 SourceLocation TildeLoc, 1811 PseudoDestructorTypeStorage DestroyedType); 1812 1813 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1814 : Expr(CXXPseudoDestructorExprClass, Shell), 1815 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1816 1817 Expr *getBase() const { return cast<Expr>(Base); } 1818 1819 /// \brief Determines whether this member expression actually had 1820 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1821 /// x->Base::foo. 1822 bool hasQualifier() const { return QualifierLoc; } 1823 1824 /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1825 /// with source-location information. 1826 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1827 1828 /// \brief If the member name was qualified, retrieves the 1829 /// nested-name-specifier that precedes the member name. Otherwise, returns 1830 /// NULL. 1831 NestedNameSpecifier *getQualifier() const { 1832 return QualifierLoc.getNestedNameSpecifier(); 1833 } 1834 1835 /// \brief Determine whether this pseudo-destructor expression was written 1836 /// using an '->' (otherwise, it used a '.'). 1837 bool isArrow() const { return IsArrow; } 1838 1839 /// \brief Retrieve the location of the '.' or '->' operator. 1840 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1841 1842 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1843 /// expression. 1844 /// 1845 /// Pseudo-destructor expressions can have extra qualification within them 1846 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1847 /// Here, if the object type of the expression is (or may be) a scalar type, 1848 /// \p T may also be a scalar type and, therefore, cannot be part of a 1849 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1850 /// destructor expression. 1851 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1852 1853 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1854 /// expression. 1855 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1856 1857 /// \brief Retrieve the location of the '~'. 1858 SourceLocation getTildeLoc() const { return TildeLoc; } 1859 1860 /// \brief Retrieve the source location information for the type 1861 /// being destroyed. 1862 /// 1863 /// This type-source information is available for non-dependent 1864 /// pseudo-destructor expressions and some dependent pseudo-destructor 1865 /// expressions. Returns NULL if we only have the identifier for a 1866 /// dependent pseudo-destructor expression. 1867 TypeSourceInfo *getDestroyedTypeInfo() const { 1868 return DestroyedType.getTypeSourceInfo(); 1869 } 1870 1871 /// \brief In a dependent pseudo-destructor expression for which we do not 1872 /// have full type information on the destroyed type, provides the name 1873 /// of the destroyed type. 1874 IdentifierInfo *getDestroyedTypeIdentifier() const { 1875 return DestroyedType.getIdentifier(); 1876 } 1877 1878 /// \brief Retrieve the type being destroyed. 1879 QualType getDestroyedType() const; 1880 1881 /// \brief Retrieve the starting location of the type being destroyed. 1882 SourceLocation getDestroyedTypeLoc() const { 1883 return DestroyedType.getLocation(); 1884 } 1885 1886 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1887 /// expression. 1888 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1889 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1890 } 1891 1892 /// \brief Set the destroyed type. 1893 void setDestroyedType(TypeSourceInfo *Info) { 1894 DestroyedType = PseudoDestructorTypeStorage(Info); 1895 } 1896 1897 SourceLocation getLocStart() const LLVM_READONLY {return Base->getLocStart();} 1898 SourceLocation getLocEnd() const LLVM_READONLY; 1899 1900 static bool classof(const Stmt *T) { 1901 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1902 } 1903 1904 // Iterators 1905 child_range children() { return child_range(&Base, &Base + 1); } 1906}; 1907 1908/// \brief Represents a GCC or MS unary type trait, as used in the 1909/// implementation of TR1/C++11 type trait templates. 1910/// 1911/// Example: 1912/// @code 1913/// __is_pod(int) == true 1914/// __is_enum(std::string) == false 1915/// @endcode 1916class UnaryTypeTraitExpr : public Expr { 1917 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1918 unsigned UTT : 31; 1919 /// The value of the type trait. Unspecified if dependent. 1920 bool Value : 1; 1921 1922 /// Loc - The location of the type trait keyword. 1923 SourceLocation Loc; 1924 1925 /// RParen - The location of the closing paren. 1926 SourceLocation RParen; 1927 1928 /// The type being queried. 1929 TypeSourceInfo *QueriedType; 1930 1931public: 1932 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 1933 TypeSourceInfo *queried, bool value, 1934 SourceLocation rparen, QualType ty) 1935 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1936 false, queried->getType()->isDependentType(), 1937 queried->getType()->isInstantiationDependentType(), 1938 queried->getType()->containsUnexpandedParameterPack()), 1939 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 1940 1941 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1942 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 1943 QueriedType() { } 1944 1945 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 1946 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 1947 1948 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 1949 1950 QualType getQueriedType() const { return QueriedType->getType(); } 1951 1952 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1953 1954 bool getValue() const { return Value; } 1955 1956 static bool classof(const Stmt *T) { 1957 return T->getStmtClass() == UnaryTypeTraitExprClass; 1958 } 1959 1960 // Iterators 1961 child_range children() { return child_range(); } 1962 1963 friend class ASTStmtReader; 1964}; 1965 1966/// \brief Represents a GCC or MS binary type trait, as used in the 1967/// implementation of TR1/C++11 type trait templates. 1968/// 1969/// Example: 1970/// @code 1971/// __is_base_of(Base, Derived) == true 1972/// @endcode 1973class BinaryTypeTraitExpr : public Expr { 1974 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 1975 unsigned BTT : 8; 1976 1977 /// The value of the type trait. Unspecified if dependent. 1978 bool Value : 1; 1979 1980 /// Loc - The location of the type trait keyword. 1981 SourceLocation Loc; 1982 1983 /// RParen - The location of the closing paren. 1984 SourceLocation RParen; 1985 1986 /// The lhs type being queried. 1987 TypeSourceInfo *LhsType; 1988 1989 /// The rhs type being queried. 1990 TypeSourceInfo *RhsType; 1991 1992public: 1993 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1994 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 1995 bool value, SourceLocation rparen, QualType ty) 1996 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 1997 lhsType->getType()->isDependentType() || 1998 rhsType->getType()->isDependentType(), 1999 (lhsType->getType()->isInstantiationDependentType() || 2000 rhsType->getType()->isInstantiationDependentType()), 2001 (lhsType->getType()->containsUnexpandedParameterPack() || 2002 rhsType->getType()->containsUnexpandedParameterPack())), 2003 BTT(btt), Value(value), Loc(loc), RParen(rparen), 2004 LhsType(lhsType), RhsType(rhsType) { } 2005 2006 2007 explicit BinaryTypeTraitExpr(EmptyShell Empty) 2008 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 2009 LhsType(), RhsType() { } 2010 2011 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2012 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2013 2014 BinaryTypeTrait getTrait() const { 2015 return static_cast<BinaryTypeTrait>(BTT); 2016 } 2017 2018 QualType getLhsType() const { return LhsType->getType(); } 2019 QualType getRhsType() const { return RhsType->getType(); } 2020 2021 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 2022 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 2023 2024 bool getValue() const { assert(!isTypeDependent()); return Value; } 2025 2026 static bool classof(const Stmt *T) { 2027 return T->getStmtClass() == BinaryTypeTraitExprClass; 2028 } 2029 2030 // Iterators 2031 child_range children() { return child_range(); } 2032 2033 friend class ASTStmtReader; 2034}; 2035 2036/// \brief A type trait used in the implementation of various C++11 and 2037/// Library TR1 trait templates. 2038/// 2039/// \code 2040/// __is_trivially_constructible(vector<int>, int*, int*) 2041/// \endcode 2042class TypeTraitExpr : public Expr { 2043 /// \brief The location of the type trait keyword. 2044 SourceLocation Loc; 2045 2046 /// \brief The location of the closing parenthesis. 2047 SourceLocation RParenLoc; 2048 2049 // Note: The TypeSourceInfos for the arguments are allocated after the 2050 // TypeTraitExpr. 2051 2052 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, 2053 ArrayRef<TypeSourceInfo *> Args, 2054 SourceLocation RParenLoc, 2055 bool Value); 2056 2057 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { } 2058 2059 /// \brief Retrieve the argument types. 2060 TypeSourceInfo **getTypeSourceInfos() { 2061 return reinterpret_cast<TypeSourceInfo **>(this+1); 2062 } 2063 2064 /// \brief Retrieve the argument types. 2065 TypeSourceInfo * const *getTypeSourceInfos() const { 2066 return reinterpret_cast<TypeSourceInfo * const*>(this+1); 2067 } 2068 2069public: 2070 /// \brief Create a new type trait expression. 2071 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc, 2072 TypeTrait Kind, 2073 ArrayRef<TypeSourceInfo *> Args, 2074 SourceLocation RParenLoc, 2075 bool Value); 2076 2077 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs); 2078 2079 /// \brief Determine which type trait this expression uses. 2080 TypeTrait getTrait() const { 2081 return static_cast<TypeTrait>(TypeTraitExprBits.Kind); 2082 } 2083 2084 bool getValue() const { 2085 assert(!isValueDependent()); 2086 return TypeTraitExprBits.Value; 2087 } 2088 2089 /// \brief Determine the number of arguments to this type trait. 2090 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } 2091 2092 /// \brief Retrieve the Ith argument. 2093 TypeSourceInfo *getArg(unsigned I) const { 2094 assert(I < getNumArgs() && "Argument out-of-range"); 2095 return getArgs()[I]; 2096 } 2097 2098 /// \brief Retrieve the argument types. 2099 ArrayRef<TypeSourceInfo *> getArgs() const { 2100 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs()); 2101 } 2102 2103 typedef TypeSourceInfo **arg_iterator; 2104 arg_iterator arg_begin() { 2105 return getTypeSourceInfos(); 2106 } 2107 arg_iterator arg_end() { 2108 return getTypeSourceInfos() + getNumArgs(); 2109 } 2110 2111 typedef TypeSourceInfo const * const *arg_const_iterator; 2112 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); } 2113 arg_const_iterator arg_end() const { 2114 return getTypeSourceInfos() + getNumArgs(); 2115 } 2116 2117 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2118 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2119 2120 static bool classof(const Stmt *T) { 2121 return T->getStmtClass() == TypeTraitExprClass; 2122 } 2123 2124 // Iterators 2125 child_range children() { return child_range(); } 2126 2127 friend class ASTStmtReader; 2128 friend class ASTStmtWriter; 2129 2130}; 2131 2132/// \brief An Embarcadero array type trait, as used in the implementation of 2133/// __array_rank and __array_extent. 2134/// 2135/// Example: 2136/// @code 2137/// __array_rank(int[10][20]) == 2 2138/// __array_extent(int, 1) == 20 2139/// @endcode 2140class ArrayTypeTraitExpr : public Expr { 2141 virtual void anchor(); 2142 2143 /// \brief The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 2144 unsigned ATT : 2; 2145 2146 /// \brief The value of the type trait. Unspecified if dependent. 2147 uint64_t Value; 2148 2149 /// \brief The array dimension being queried, or -1 if not used. 2150 Expr *Dimension; 2151 2152 /// \brief The location of the type trait keyword. 2153 SourceLocation Loc; 2154 2155 /// \brief The location of the closing paren. 2156 SourceLocation RParen; 2157 2158 /// \brief The type being queried. 2159 TypeSourceInfo *QueriedType; 2160 2161public: 2162 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 2163 TypeSourceInfo *queried, uint64_t value, 2164 Expr *dimension, SourceLocation rparen, QualType ty) 2165 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 2166 false, queried->getType()->isDependentType(), 2167 (queried->getType()->isInstantiationDependentType() || 2168 (dimension && dimension->isInstantiationDependent())), 2169 queried->getType()->containsUnexpandedParameterPack()), 2170 ATT(att), Value(value), Dimension(dimension), 2171 Loc(loc), RParen(rparen), QueriedType(queried) { } 2172 2173 2174 explicit ArrayTypeTraitExpr(EmptyShell Empty) 2175 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 2176 QueriedType() { } 2177 2178 virtual ~ArrayTypeTraitExpr() { } 2179 2180 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2181 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2182 2183 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 2184 2185 QualType getQueriedType() const { return QueriedType->getType(); } 2186 2187 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 2188 2189 uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 2190 2191 Expr *getDimensionExpression() const { return Dimension; } 2192 2193 static bool classof(const Stmt *T) { 2194 return T->getStmtClass() == ArrayTypeTraitExprClass; 2195 } 2196 2197 // Iterators 2198 child_range children() { return child_range(); } 2199 2200 friend class ASTStmtReader; 2201}; 2202 2203/// \brief An expression trait intrinsic. 2204/// 2205/// Example: 2206/// @code 2207/// __is_lvalue_expr(std::cout) == true 2208/// __is_lvalue_expr(1) == false 2209/// @endcode 2210class ExpressionTraitExpr : public Expr { 2211 /// \brief The trait. A ExpressionTrait enum in MSVC compat unsigned. 2212 unsigned ET : 31; 2213 /// \brief The value of the type trait. Unspecified if dependent. 2214 bool Value : 1; 2215 2216 /// \brief The location of the type trait keyword. 2217 SourceLocation Loc; 2218 2219 /// \brief The location of the closing paren. 2220 SourceLocation RParen; 2221 2222 /// \brief The expression being queried. 2223 Expr* QueriedExpression; 2224public: 2225 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2226 Expr *queried, bool value, 2227 SourceLocation rparen, QualType resultType) 2228 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2229 false, // Not type-dependent 2230 // Value-dependent if the argument is type-dependent. 2231 queried->isTypeDependent(), 2232 queried->isInstantiationDependent(), 2233 queried->containsUnexpandedParameterPack()), 2234 ET(et), Value(value), Loc(loc), RParen(rparen), 2235 QueriedExpression(queried) { } 2236 2237 explicit ExpressionTraitExpr(EmptyShell Empty) 2238 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2239 QueriedExpression() { } 2240 2241 SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 2242 SourceLocation getLocEnd() const LLVM_READONLY { return RParen; } 2243 2244 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2245 2246 Expr *getQueriedExpression() const { return QueriedExpression; } 2247 2248 bool getValue() const { return Value; } 2249 2250 static bool classof(const Stmt *T) { 2251 return T->getStmtClass() == ExpressionTraitExprClass; 2252 } 2253 2254 // Iterators 2255 child_range children() { return child_range(); } 2256 2257 friend class ASTStmtReader; 2258}; 2259 2260 2261/// \brief A reference to an overloaded function set, either an 2262/// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. 2263class OverloadExpr : public Expr { 2264 /// \brief The common name of these declarations. 2265 DeclarationNameInfo NameInfo; 2266 2267 /// \brief The nested-name-specifier that qualifies the name, if any. 2268 NestedNameSpecifierLoc QualifierLoc; 2269 2270 /// The results. These are undesugared, which is to say, they may 2271 /// include UsingShadowDecls. Access is relative to the naming 2272 /// class. 2273 // FIXME: Allocate this data after the OverloadExpr subclass. 2274 DeclAccessPair *Results; 2275 unsigned NumResults; 2276 2277protected: 2278 /// \brief Whether the name includes info for explicit template 2279 /// keyword and arguments. 2280 bool HasTemplateKWAndArgsInfo; 2281 2282 /// \brief Return the optional template keyword and arguments info. 2283 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2284 2285 /// \brief Return the optional template keyword and arguments info. 2286 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2287 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2288 } 2289 2290 OverloadExpr(StmtClass K, ASTContext &C, 2291 NestedNameSpecifierLoc QualifierLoc, 2292 SourceLocation TemplateKWLoc, 2293 const DeclarationNameInfo &NameInfo, 2294 const TemplateArgumentListInfo *TemplateArgs, 2295 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2296 bool KnownDependent, 2297 bool KnownInstantiationDependent, 2298 bool KnownContainsUnexpandedParameterPack); 2299 2300 OverloadExpr(StmtClass K, EmptyShell Empty) 2301 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0), 2302 HasTemplateKWAndArgsInfo(false) { } 2303 2304 void initializeResults(ASTContext &C, 2305 UnresolvedSetIterator Begin, 2306 UnresolvedSetIterator End); 2307 2308public: 2309 struct FindResult { 2310 OverloadExpr *Expression; 2311 bool IsAddressOfOperand; 2312 bool HasFormOfMemberPointer; 2313 }; 2314 2315 /// Finds the overloaded expression in the given expression of 2316 /// OverloadTy. 2317 /// 2318 /// \return the expression (which must be there) and true if it has 2319 /// the particular form of a member pointer expression 2320 static FindResult find(Expr *E) { 2321 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2322 2323 FindResult Result; 2324 2325 E = E->IgnoreParens(); 2326 if (isa<UnaryOperator>(E)) { 2327 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2328 E = cast<UnaryOperator>(E)->getSubExpr(); 2329 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2330 2331 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2332 Result.IsAddressOfOperand = true; 2333 Result.Expression = Ovl; 2334 } else { 2335 Result.HasFormOfMemberPointer = false; 2336 Result.IsAddressOfOperand = false; 2337 Result.Expression = cast<OverloadExpr>(E); 2338 } 2339 2340 return Result; 2341 } 2342 2343 /// \brief Gets the naming class of this lookup, if any. 2344 CXXRecordDecl *getNamingClass() const; 2345 2346 typedef UnresolvedSetImpl::iterator decls_iterator; 2347 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2348 decls_iterator decls_end() const { 2349 return UnresolvedSetIterator(Results + NumResults); 2350 } 2351 2352 /// \brief Gets the number of declarations in the unresolved set. 2353 unsigned getNumDecls() const { return NumResults; } 2354 2355 /// \brief Gets the full name info. 2356 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2357 2358 /// \brief Gets the name looked up. 2359 DeclarationName getName() const { return NameInfo.getName(); } 2360 2361 /// \brief Gets the location of the name. 2362 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2363 2364 /// \brief Fetches the nested-name qualifier, if one was given. 2365 NestedNameSpecifier *getQualifier() const { 2366 return QualifierLoc.getNestedNameSpecifier(); 2367 } 2368 2369 /// \brief Fetches the nested-name qualifier with source-location 2370 /// information, if one was given. 2371 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2372 2373 /// \brief Retrieve the location of the template keyword preceding 2374 /// this name, if any. 2375 SourceLocation getTemplateKeywordLoc() const { 2376 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2377 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2378 } 2379 2380 /// \brief Retrieve the location of the left angle bracket starting the 2381 /// explicit template argument list following the name, if any. 2382 SourceLocation getLAngleLoc() const { 2383 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2384 return getTemplateKWAndArgsInfo()->LAngleLoc; 2385 } 2386 2387 /// \brief Retrieve the location of the right angle bracket ending the 2388 /// explicit template argument list following the name, if any. 2389 SourceLocation getRAngleLoc() const { 2390 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2391 return getTemplateKWAndArgsInfo()->RAngleLoc; 2392 } 2393 2394 /// \brief Determines whether the name was preceded by the template keyword. 2395 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2396 2397 /// \brief Determines whether this expression had explicit template arguments. 2398 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2399 2400 // Note that, inconsistently with the explicit-template-argument AST 2401 // nodes, users are *forbidden* from calling these methods on objects 2402 // without explicit template arguments. 2403 2404 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2405 assert(hasExplicitTemplateArgs()); 2406 return *getTemplateKWAndArgsInfo(); 2407 } 2408 2409 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2410 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2411 } 2412 2413 TemplateArgumentLoc const *getTemplateArgs() const { 2414 return getExplicitTemplateArgs().getTemplateArgs(); 2415 } 2416 2417 unsigned getNumTemplateArgs() const { 2418 return getExplicitTemplateArgs().NumTemplateArgs; 2419 } 2420 2421 /// \brief Copies the template arguments into the given structure. 2422 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2423 getExplicitTemplateArgs().copyInto(List); 2424 } 2425 2426 /// \brief Retrieves the optional explicit template arguments. 2427 /// 2428 /// This points to the same data as getExplicitTemplateArgs(), but 2429 /// returns null if there are no explicit template arguments. 2430 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2431 if (!hasExplicitTemplateArgs()) return 0; 2432 return &getExplicitTemplateArgs(); 2433 } 2434 2435 static bool classof(const Stmt *T) { 2436 return T->getStmtClass() == UnresolvedLookupExprClass || 2437 T->getStmtClass() == UnresolvedMemberExprClass; 2438 } 2439 2440 friend class ASTStmtReader; 2441 friend class ASTStmtWriter; 2442}; 2443 2444/// \brief A reference to a name which we were able to look up during 2445/// parsing but could not resolve to a specific declaration. 2446/// 2447/// This arises in several ways: 2448/// * we might be waiting for argument-dependent lookup 2449/// * the name might resolve to an overloaded function 2450/// and eventually: 2451/// * the lookup might have included a function template 2452/// These never include UnresolvedUsingValueDecls, which are always class 2453/// members and therefore appear only in UnresolvedMemberLookupExprs. 2454class UnresolvedLookupExpr : public OverloadExpr { 2455 /// True if these lookup results should be extended by 2456 /// argument-dependent lookup if this is the operand of a function 2457 /// call. 2458 bool RequiresADL; 2459 2460 /// True if these lookup results are overloaded. This is pretty 2461 /// trivially rederivable if we urgently need to kill this field. 2462 bool Overloaded; 2463 2464 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2465 /// any. This can generally be recalculated from the context chain, 2466 /// but that can be fairly expensive for unqualified lookups. If we 2467 /// want to improve memory use here, this could go in a union 2468 /// against the qualified-lookup bits. 2469 CXXRecordDecl *NamingClass; 2470 2471 UnresolvedLookupExpr(ASTContext &C, 2472 CXXRecordDecl *NamingClass, 2473 NestedNameSpecifierLoc QualifierLoc, 2474 SourceLocation TemplateKWLoc, 2475 const DeclarationNameInfo &NameInfo, 2476 bool RequiresADL, bool Overloaded, 2477 const TemplateArgumentListInfo *TemplateArgs, 2478 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 2479 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2480 NameInfo, TemplateArgs, Begin, End, false, false, false), 2481 RequiresADL(RequiresADL), 2482 Overloaded(Overloaded), NamingClass(NamingClass) 2483 {} 2484 2485 UnresolvedLookupExpr(EmptyShell Empty) 2486 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2487 RequiresADL(false), Overloaded(false), NamingClass(0) 2488 {} 2489 2490 friend class ASTStmtReader; 2491 2492public: 2493 static UnresolvedLookupExpr *Create(ASTContext &C, 2494 CXXRecordDecl *NamingClass, 2495 NestedNameSpecifierLoc QualifierLoc, 2496 const DeclarationNameInfo &NameInfo, 2497 bool ADL, bool Overloaded, 2498 UnresolvedSetIterator Begin, 2499 UnresolvedSetIterator End) { 2500 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2501 SourceLocation(), NameInfo, 2502 ADL, Overloaded, 0, Begin, End); 2503 } 2504 2505 static UnresolvedLookupExpr *Create(ASTContext &C, 2506 CXXRecordDecl *NamingClass, 2507 NestedNameSpecifierLoc QualifierLoc, 2508 SourceLocation TemplateKWLoc, 2509 const DeclarationNameInfo &NameInfo, 2510 bool ADL, 2511 const TemplateArgumentListInfo *Args, 2512 UnresolvedSetIterator Begin, 2513 UnresolvedSetIterator End); 2514 2515 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2516 bool HasTemplateKWAndArgsInfo, 2517 unsigned NumTemplateArgs); 2518 2519 /// True if this declaration should be extended by 2520 /// argument-dependent lookup. 2521 bool requiresADL() const { return RequiresADL; } 2522 2523 /// True if this lookup is overloaded. 2524 bool isOverloaded() const { return Overloaded; } 2525 2526 /// Gets the 'naming class' (in the sense of C++0x 2527 /// [class.access.base]p5) of the lookup. This is the scope 2528 /// that was looked in to find these results. 2529 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2530 2531 SourceLocation getLocStart() const LLVM_READONLY { 2532 if (NestedNameSpecifierLoc l = getQualifierLoc()) 2533 return l.getBeginLoc(); 2534 return getNameInfo().getLocStart(); 2535 } 2536 SourceLocation getLocEnd() const LLVM_READONLY { 2537 if (hasExplicitTemplateArgs()) 2538 return getRAngleLoc(); 2539 return getNameInfo().getLocEnd(); 2540 } 2541 2542 child_range children() { return child_range(); } 2543 2544 static bool classof(const Stmt *T) { 2545 return T->getStmtClass() == UnresolvedLookupExprClass; 2546 } 2547}; 2548 2549/// \brief A qualified reference to a name whose declaration cannot 2550/// yet be resolved. 2551/// 2552/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2553/// it expresses a reference to a declaration such as 2554/// X<T>::value. The difference, however, is that an 2555/// DependentScopeDeclRefExpr node is used only within C++ templates when 2556/// the qualification (e.g., X<T>::) refers to a dependent type. In 2557/// this case, X<T>::value cannot resolve to a declaration because the 2558/// declaration will differ from on instantiation of X<T> to the 2559/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2560/// qualifier (X<T>::) and the name of the entity being referenced 2561/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2562/// declaration can be found. 2563class DependentScopeDeclRefExpr : public Expr { 2564 /// \brief The nested-name-specifier that qualifies this unresolved 2565 /// declaration name. 2566 NestedNameSpecifierLoc QualifierLoc; 2567 2568 /// The name of the entity we will be referencing. 2569 DeclarationNameInfo NameInfo; 2570 2571 /// \brief Whether the name includes info for explicit template 2572 /// keyword and arguments. 2573 bool HasTemplateKWAndArgsInfo; 2574 2575 /// \brief Return the optional template keyword and arguments info. 2576 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2577 if (!HasTemplateKWAndArgsInfo) return 0; 2578 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2579 } 2580 /// \brief Return the optional template keyword and arguments info. 2581 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2582 return const_cast<DependentScopeDeclRefExpr*>(this) 2583 ->getTemplateKWAndArgsInfo(); 2584 } 2585 2586 DependentScopeDeclRefExpr(QualType T, 2587 NestedNameSpecifierLoc QualifierLoc, 2588 SourceLocation TemplateKWLoc, 2589 const DeclarationNameInfo &NameInfo, 2590 const TemplateArgumentListInfo *Args); 2591 2592public: 2593 static DependentScopeDeclRefExpr *Create(ASTContext &C, 2594 NestedNameSpecifierLoc QualifierLoc, 2595 SourceLocation TemplateKWLoc, 2596 const DeclarationNameInfo &NameInfo, 2597 const TemplateArgumentListInfo *TemplateArgs); 2598 2599 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2600 bool HasTemplateKWAndArgsInfo, 2601 unsigned NumTemplateArgs); 2602 2603 /// \brief Retrieve the name that this expression refers to. 2604 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2605 2606 /// \brief Retrieve the name that this expression refers to. 2607 DeclarationName getDeclName() const { return NameInfo.getName(); } 2608 2609 /// \brief Retrieve the location of the name within the expression. 2610 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2611 2612 /// \brief Retrieve the nested-name-specifier that qualifies the 2613 /// name, with source location information. 2614 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2615 2616 2617 /// \brief Retrieve the nested-name-specifier that qualifies this 2618 /// declaration. 2619 NestedNameSpecifier *getQualifier() const { 2620 return QualifierLoc.getNestedNameSpecifier(); 2621 } 2622 2623 /// \brief Retrieve the location of the template keyword preceding 2624 /// this name, if any. 2625 SourceLocation getTemplateKeywordLoc() const { 2626 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2627 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2628 } 2629 2630 /// \brief Retrieve the location of the left angle bracket starting the 2631 /// explicit template argument list following the name, if any. 2632 SourceLocation getLAngleLoc() const { 2633 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2634 return getTemplateKWAndArgsInfo()->LAngleLoc; 2635 } 2636 2637 /// \brief Retrieve the location of the right angle bracket ending the 2638 /// explicit template argument list following the name, if any. 2639 SourceLocation getRAngleLoc() const { 2640 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2641 return getTemplateKWAndArgsInfo()->RAngleLoc; 2642 } 2643 2644 /// Determines whether the name was preceded by the template keyword. 2645 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2646 2647 /// Determines whether this lookup had explicit template arguments. 2648 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2649 2650 // Note that, inconsistently with the explicit-template-argument AST 2651 // nodes, users are *forbidden* from calling these methods on objects 2652 // without explicit template arguments. 2653 2654 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2655 assert(hasExplicitTemplateArgs()); 2656 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2657 } 2658 2659 /// Gets a reference to the explicit template argument list. 2660 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2661 assert(hasExplicitTemplateArgs()); 2662 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2663 } 2664 2665 /// \brief Retrieves the optional explicit template arguments. 2666 /// This points to the same data as getExplicitTemplateArgs(), but 2667 /// returns null if there are no explicit template arguments. 2668 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2669 if (!hasExplicitTemplateArgs()) return 0; 2670 return &getExplicitTemplateArgs(); 2671 } 2672 2673 /// \brief Copies the template arguments (if present) into the given 2674 /// structure. 2675 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2676 getExplicitTemplateArgs().copyInto(List); 2677 } 2678 2679 TemplateArgumentLoc const *getTemplateArgs() const { 2680 return getExplicitTemplateArgs().getTemplateArgs(); 2681 } 2682 2683 unsigned getNumTemplateArgs() const { 2684 return getExplicitTemplateArgs().NumTemplateArgs; 2685 } 2686 2687 SourceLocation getLocStart() const LLVM_READONLY { 2688 return QualifierLoc.getBeginLoc(); 2689 } 2690 SourceLocation getLocEnd() const LLVM_READONLY { 2691 if (hasExplicitTemplateArgs()) 2692 return getRAngleLoc(); 2693 return getLocation(); 2694 } 2695 2696 static bool classof(const Stmt *T) { 2697 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2698 } 2699 2700 child_range children() { return child_range(); } 2701 2702 friend class ASTStmtReader; 2703 friend class ASTStmtWriter; 2704}; 2705 2706/// Represents an expression --- generally a full-expression --- which 2707/// introduces cleanups to be run at the end of the sub-expression's 2708/// evaluation. The most common source of expression-introduced 2709/// cleanups is temporary objects in C++, but several other kinds of 2710/// expressions can create cleanups, including basically every 2711/// call in ARC that returns an Objective-C pointer. 2712/// 2713/// This expression also tracks whether the sub-expression contains a 2714/// potentially-evaluated block literal. The lifetime of a block 2715/// literal is the extent of the enclosing scope. 2716class ExprWithCleanups : public Expr { 2717public: 2718 /// The type of objects that are kept in the cleanup. 2719 /// It's useful to remember the set of blocks; we could also 2720 /// remember the set of temporaries, but there's currently 2721 /// no need. 2722 typedef BlockDecl *CleanupObject; 2723 2724private: 2725 Stmt *SubExpr; 2726 2727 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2728 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2729 2730 CleanupObject *getObjectsBuffer() { 2731 return reinterpret_cast<CleanupObject*>(this + 1); 2732 } 2733 const CleanupObject *getObjectsBuffer() const { 2734 return reinterpret_cast<const CleanupObject*>(this + 1); 2735 } 2736 friend class ASTStmtReader; 2737 2738public: 2739 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 2740 unsigned numObjects); 2741 2742 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 2743 ArrayRef<CleanupObject> objects); 2744 2745 ArrayRef<CleanupObject> getObjects() const { 2746 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2747 } 2748 2749 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2750 2751 CleanupObject getObject(unsigned i) const { 2752 assert(i < getNumObjects() && "Index out of range"); 2753 return getObjects()[i]; 2754 } 2755 2756 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2757 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2758 2759 /// setSubExpr - As with any mutator of the AST, be very careful 2760 /// when modifying an existing AST to preserve its invariants. 2761 void setSubExpr(Expr *E) { SubExpr = E; } 2762 2763 SourceLocation getLocStart() const LLVM_READONLY { 2764 return SubExpr->getLocStart(); 2765 } 2766 SourceLocation getLocEnd() const LLVM_READONLY { return SubExpr->getLocEnd();} 2767 2768 // Implement isa/cast/dyncast/etc. 2769 static bool classof(const Stmt *T) { 2770 return T->getStmtClass() == ExprWithCleanupsClass; 2771 } 2772 2773 // Iterators 2774 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2775}; 2776 2777/// \brief Describes an explicit type conversion that uses functional 2778/// notion but could not be resolved because one or more arguments are 2779/// type-dependent. 2780/// 2781/// The explicit type conversions expressed by 2782/// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, 2783/// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and 2784/// either \c T is a dependent type or one or more of the <tt>a</tt>'s is 2785/// type-dependent. For example, this would occur in a template such 2786/// as: 2787/// 2788/// \code 2789/// template<typename T, typename A1> 2790/// inline T make_a(const A1& a1) { 2791/// return T(a1); 2792/// } 2793/// \endcode 2794/// 2795/// When the returned expression is instantiated, it may resolve to a 2796/// constructor call, conversion function call, or some kind of type 2797/// conversion. 2798class CXXUnresolvedConstructExpr : public Expr { 2799 /// \brief The type being constructed. 2800 TypeSourceInfo *Type; 2801 2802 /// \brief The location of the left parentheses ('('). 2803 SourceLocation LParenLoc; 2804 2805 /// \brief The location of the right parentheses (')'). 2806 SourceLocation RParenLoc; 2807 2808 /// \brief The number of arguments used to construct the type. 2809 unsigned NumArgs; 2810 2811 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2812 SourceLocation LParenLoc, 2813 ArrayRef<Expr*> Args, 2814 SourceLocation RParenLoc); 2815 2816 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2817 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2818 2819 friend class ASTStmtReader; 2820 2821public: 2822 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2823 TypeSourceInfo *Type, 2824 SourceLocation LParenLoc, 2825 ArrayRef<Expr*> Args, 2826 SourceLocation RParenLoc); 2827 2828 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2829 unsigned NumArgs); 2830 2831 /// \brief Retrieve the type that is being constructed, as specified 2832 /// in the source code. 2833 QualType getTypeAsWritten() const { return Type->getType(); } 2834 2835 /// \brief Retrieve the type source information for the type being 2836 /// constructed. 2837 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2838 2839 /// \brief Retrieve the location of the left parentheses ('(') that 2840 /// precedes the argument list. 2841 SourceLocation getLParenLoc() const { return LParenLoc; } 2842 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2843 2844 /// \brief Retrieve the location of the right parentheses (')') that 2845 /// follows the argument list. 2846 SourceLocation getRParenLoc() const { return RParenLoc; } 2847 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2848 2849 /// \brief Retrieve the number of arguments. 2850 unsigned arg_size() const { return NumArgs; } 2851 2852 typedef Expr** arg_iterator; 2853 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2854 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2855 2856 typedef const Expr* const * const_arg_iterator; 2857 const_arg_iterator arg_begin() const { 2858 return reinterpret_cast<const Expr* const *>(this + 1); 2859 } 2860 const_arg_iterator arg_end() const { 2861 return arg_begin() + NumArgs; 2862 } 2863 2864 Expr *getArg(unsigned I) { 2865 assert(I < NumArgs && "Argument index out-of-range"); 2866 return *(arg_begin() + I); 2867 } 2868 2869 const Expr *getArg(unsigned I) const { 2870 assert(I < NumArgs && "Argument index out-of-range"); 2871 return *(arg_begin() + I); 2872 } 2873 2874 void setArg(unsigned I, Expr *E) { 2875 assert(I < NumArgs && "Argument index out-of-range"); 2876 *(arg_begin() + I) = E; 2877 } 2878 2879 SourceLocation getLocStart() const LLVM_READONLY; 2880 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 2881 2882 static bool classof(const Stmt *T) { 2883 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2884 } 2885 2886 // Iterators 2887 child_range children() { 2888 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 2889 return child_range(begin, begin + NumArgs); 2890 } 2891}; 2892 2893/// \brief Represents a C++ member access expression where the actual 2894/// member referenced could not be resolved because the base 2895/// expression or the member name was dependent. 2896/// 2897/// Like UnresolvedMemberExprs, these can be either implicit or 2898/// explicit accesses. It is only possible to get one of these with 2899/// an implicit access if a qualifier is provided. 2900class CXXDependentScopeMemberExpr : public Expr { 2901 /// \brief The expression for the base pointer or class reference, 2902 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2903 Stmt *Base; 2904 2905 /// \brief The type of the base expression. Never null, even for 2906 /// implicit accesses. 2907 QualType BaseType; 2908 2909 /// \brief Whether this member expression used the '->' operator or 2910 /// the '.' operator. 2911 bool IsArrow : 1; 2912 2913 /// \brief Whether this member expression has info for explicit template 2914 /// keyword and arguments. 2915 bool HasTemplateKWAndArgsInfo : 1; 2916 2917 /// \brief The location of the '->' or '.' operator. 2918 SourceLocation OperatorLoc; 2919 2920 /// \brief The nested-name-specifier that precedes the member name, if any. 2921 NestedNameSpecifierLoc QualifierLoc; 2922 2923 /// \brief In a qualified member access expression such as t->Base::f, this 2924 /// member stores the resolves of name lookup in the context of the member 2925 /// access expression, to be used at instantiation time. 2926 /// 2927 /// FIXME: This member, along with the QualifierLoc, could 2928 /// be stuck into a structure that is optionally allocated at the end of 2929 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2930 NamedDecl *FirstQualifierFoundInScope; 2931 2932 /// \brief The member to which this member expression refers, which 2933 /// can be name, overloaded operator, or destructor. 2934 /// FIXME: could also be a template-id 2935 DeclarationNameInfo MemberNameInfo; 2936 2937 /// \brief Return the optional template keyword and arguments info. 2938 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2939 if (!HasTemplateKWAndArgsInfo) return 0; 2940 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2941 } 2942 /// \brief Return the optional template keyword and arguments info. 2943 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2944 return const_cast<CXXDependentScopeMemberExpr*>(this) 2945 ->getTemplateKWAndArgsInfo(); 2946 } 2947 2948 CXXDependentScopeMemberExpr(ASTContext &C, 2949 Expr *Base, QualType BaseType, bool IsArrow, 2950 SourceLocation OperatorLoc, 2951 NestedNameSpecifierLoc QualifierLoc, 2952 SourceLocation TemplateKWLoc, 2953 NamedDecl *FirstQualifierFoundInScope, 2954 DeclarationNameInfo MemberNameInfo, 2955 const TemplateArgumentListInfo *TemplateArgs); 2956 2957public: 2958 CXXDependentScopeMemberExpr(ASTContext &C, 2959 Expr *Base, QualType BaseType, 2960 bool IsArrow, 2961 SourceLocation OperatorLoc, 2962 NestedNameSpecifierLoc QualifierLoc, 2963 NamedDecl *FirstQualifierFoundInScope, 2964 DeclarationNameInfo MemberNameInfo); 2965 2966 static CXXDependentScopeMemberExpr * 2967 Create(ASTContext &C, 2968 Expr *Base, QualType BaseType, bool IsArrow, 2969 SourceLocation OperatorLoc, 2970 NestedNameSpecifierLoc QualifierLoc, 2971 SourceLocation TemplateKWLoc, 2972 NamedDecl *FirstQualifierFoundInScope, 2973 DeclarationNameInfo MemberNameInfo, 2974 const TemplateArgumentListInfo *TemplateArgs); 2975 2976 static CXXDependentScopeMemberExpr * 2977 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2978 unsigned NumTemplateArgs); 2979 2980 /// \brief True if this is an implicit access, i.e. one in which the 2981 /// member being accessed was not written in the source. The source 2982 /// location of the operator is invalid in this case. 2983 bool isImplicitAccess() const; 2984 2985 /// \brief Retrieve the base object of this member expressions, 2986 /// e.g., the \c x in \c x.m. 2987 Expr *getBase() const { 2988 assert(!isImplicitAccess()); 2989 return cast<Expr>(Base); 2990 } 2991 2992 QualType getBaseType() const { return BaseType; } 2993 2994 /// \brief Determine whether this member expression used the '->' 2995 /// operator; otherwise, it used the '.' operator. 2996 bool isArrow() const { return IsArrow; } 2997 2998 /// \brief Retrieve the location of the '->' or '.' operator. 2999 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3000 3001 /// \brief Retrieve the nested-name-specifier that qualifies the member 3002 /// name. 3003 NestedNameSpecifier *getQualifier() const { 3004 return QualifierLoc.getNestedNameSpecifier(); 3005 } 3006 3007 /// \brief Retrieve the nested-name-specifier that qualifies the member 3008 /// name, with source location information. 3009 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 3010 3011 3012 /// \brief Retrieve the first part of the nested-name-specifier that was 3013 /// found in the scope of the member access expression when the member access 3014 /// was initially parsed. 3015 /// 3016 /// This function only returns a useful result when member access expression 3017 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 3018 /// returned by this function describes what was found by unqualified name 3019 /// lookup for the identifier "Base" within the scope of the member access 3020 /// expression itself. At template instantiation time, this information is 3021 /// combined with the results of name lookup into the type of the object 3022 /// expression itself (the class type of x). 3023 NamedDecl *getFirstQualifierFoundInScope() const { 3024 return FirstQualifierFoundInScope; 3025 } 3026 3027 /// \brief Retrieve the name of the member that this expression 3028 /// refers to. 3029 const DeclarationNameInfo &getMemberNameInfo() const { 3030 return MemberNameInfo; 3031 } 3032 3033 /// \brief Retrieve the name of the member that this expression 3034 /// refers to. 3035 DeclarationName getMember() const { return MemberNameInfo.getName(); } 3036 3037 // \brief Retrieve the location of the name of the member that this 3038 // expression refers to. 3039 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 3040 3041 /// \brief Retrieve the location of the template keyword preceding the 3042 /// member name, if any. 3043 SourceLocation getTemplateKeywordLoc() const { 3044 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3045 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 3046 } 3047 3048 /// \brief Retrieve the location of the left angle bracket starting the 3049 /// explicit template argument list following the member name, if any. 3050 SourceLocation getLAngleLoc() const { 3051 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3052 return getTemplateKWAndArgsInfo()->LAngleLoc; 3053 } 3054 3055 /// \brief Retrieve the location of the right angle bracket ending the 3056 /// explicit template argument list following the member name, if any. 3057 SourceLocation getRAngleLoc() const { 3058 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 3059 return getTemplateKWAndArgsInfo()->RAngleLoc; 3060 } 3061 3062 /// Determines whether the member name was preceded by the template keyword. 3063 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 3064 3065 /// \brief Determines whether this member expression actually had a C++ 3066 /// template argument list explicitly specified, e.g., x.f<int>. 3067 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 3068 3069 /// \brief Retrieve the explicit template argument list that followed the 3070 /// member template name, if any. 3071 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 3072 assert(hasExplicitTemplateArgs()); 3073 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 3074 } 3075 3076 /// \brief Retrieve the explicit template argument list that followed the 3077 /// member template name, if any. 3078 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 3079 return const_cast<CXXDependentScopeMemberExpr *>(this) 3080 ->getExplicitTemplateArgs(); 3081 } 3082 3083 /// \brief Retrieves the optional explicit template arguments. 3084 /// This points to the same data as getExplicitTemplateArgs(), but 3085 /// returns null if there are no explicit template arguments. 3086 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 3087 if (!hasExplicitTemplateArgs()) return 0; 3088 return &getExplicitTemplateArgs(); 3089 } 3090 3091 /// \brief Copies the template arguments (if present) into the given 3092 /// structure. 3093 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 3094 getExplicitTemplateArgs().copyInto(List); 3095 } 3096 3097 /// \brief Initializes the template arguments using the given structure. 3098 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 3099 getExplicitTemplateArgs().initializeFrom(List); 3100 } 3101 3102 /// \brief Retrieve the template arguments provided as part of this 3103 /// template-id. 3104 const TemplateArgumentLoc *getTemplateArgs() const { 3105 return getExplicitTemplateArgs().getTemplateArgs(); 3106 } 3107 3108 /// \brief Retrieve the number of template arguments provided as part of this 3109 /// template-id. 3110 unsigned getNumTemplateArgs() const { 3111 return getExplicitTemplateArgs().NumTemplateArgs; 3112 } 3113 3114 SourceLocation getLocStart() const LLVM_READONLY { 3115 if (!isImplicitAccess()) 3116 return Base->getLocStart(); 3117 if (getQualifier()) 3118 return getQualifierLoc().getBeginLoc(); 3119 return MemberNameInfo.getBeginLoc(); 3120 3121 } 3122 SourceLocation getLocEnd() const LLVM_READONLY { 3123 if (hasExplicitTemplateArgs()) 3124 return getRAngleLoc(); 3125 return MemberNameInfo.getEndLoc(); 3126 } 3127 3128 static bool classof(const Stmt *T) { 3129 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 3130 } 3131 3132 // Iterators 3133 child_range children() { 3134 if (isImplicitAccess()) return child_range(); 3135 return child_range(&Base, &Base + 1); 3136 } 3137 3138 friend class ASTStmtReader; 3139 friend class ASTStmtWriter; 3140}; 3141 3142/// \brief Represents a C++ member access expression for which lookup 3143/// produced a set of overloaded functions. 3144/// 3145/// The member access may be explicit or implicit: 3146/// struct A { 3147/// int a, b; 3148/// int explicitAccess() { return this->a + this->A::b; } 3149/// int implicitAccess() { return a + A::b; } 3150/// }; 3151/// 3152/// In the final AST, an explicit access always becomes a MemberExpr. 3153/// An implicit access may become either a MemberExpr or a 3154/// DeclRefExpr, depending on whether the member is static. 3155class UnresolvedMemberExpr : public OverloadExpr { 3156 /// \brief Whether this member expression used the '->' operator or 3157 /// the '.' operator. 3158 bool IsArrow : 1; 3159 3160 /// \brief Whether the lookup results contain an unresolved using 3161 /// declaration. 3162 bool HasUnresolvedUsing : 1; 3163 3164 /// \brief The expression for the base pointer or class reference, 3165 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 3166 /// member expression 3167 Stmt *Base; 3168 3169 /// \brief The type of the base expression; never null. 3170 QualType BaseType; 3171 3172 /// \brief The location of the '->' or '.' operator. 3173 SourceLocation OperatorLoc; 3174 3175 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 3176 Expr *Base, QualType BaseType, bool IsArrow, 3177 SourceLocation OperatorLoc, 3178 NestedNameSpecifierLoc QualifierLoc, 3179 SourceLocation TemplateKWLoc, 3180 const DeclarationNameInfo &MemberNameInfo, 3181 const TemplateArgumentListInfo *TemplateArgs, 3182 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3183 3184 UnresolvedMemberExpr(EmptyShell Empty) 3185 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 3186 HasUnresolvedUsing(false), Base(0) { } 3187 3188 friend class ASTStmtReader; 3189 3190public: 3191 static UnresolvedMemberExpr * 3192 Create(ASTContext &C, bool HasUnresolvedUsing, 3193 Expr *Base, QualType BaseType, bool IsArrow, 3194 SourceLocation OperatorLoc, 3195 NestedNameSpecifierLoc QualifierLoc, 3196 SourceLocation TemplateKWLoc, 3197 const DeclarationNameInfo &MemberNameInfo, 3198 const TemplateArgumentListInfo *TemplateArgs, 3199 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 3200 3201 static UnresolvedMemberExpr * 3202 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3203 unsigned NumTemplateArgs); 3204 3205 /// \brief True if this is an implicit access, i.e. one in which the 3206 /// member being accessed was not written in the source. The source 3207 /// location of the operator is invalid in this case. 3208 bool isImplicitAccess() const; 3209 3210 /// \brief Retrieve the base object of this member expressions, 3211 /// e.g., the \c x in \c x.m. 3212 Expr *getBase() { 3213 assert(!isImplicitAccess()); 3214 return cast<Expr>(Base); 3215 } 3216 const Expr *getBase() const { 3217 assert(!isImplicitAccess()); 3218 return cast<Expr>(Base); 3219 } 3220 3221 QualType getBaseType() const { return BaseType; } 3222 3223 /// \brief Determine whether the lookup results contain an unresolved using 3224 /// declaration. 3225 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3226 3227 /// \brief Determine whether this member expression used the '->' 3228 /// operator; otherwise, it used the '.' operator. 3229 bool isArrow() const { return IsArrow; } 3230 3231 /// \brief Retrieve the location of the '->' or '.' operator. 3232 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3233 3234 /// \brief Retrieves the naming class of this lookup. 3235 CXXRecordDecl *getNamingClass() const; 3236 3237 /// \brief Retrieve the full name info for the member that this expression 3238 /// refers to. 3239 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3240 3241 /// \brief Retrieve the name of the member that this expression 3242 /// refers to. 3243 DeclarationName getMemberName() const { return getName(); } 3244 3245 // \brief Retrieve the location of the name of the member that this 3246 // expression refers to. 3247 SourceLocation getMemberLoc() const { return getNameLoc(); } 3248 3249 SourceLocation getLocStart() const LLVM_READONLY { 3250 if (!isImplicitAccess()) 3251 return Base->getLocStart(); 3252 if (NestedNameSpecifierLoc l = getQualifierLoc()) 3253 return l.getBeginLoc(); 3254 return getMemberNameInfo().getLocStart(); 3255 } 3256 SourceLocation getLocEnd() const LLVM_READONLY { 3257 if (hasExplicitTemplateArgs()) 3258 return getRAngleLoc(); 3259 return getMemberNameInfo().getLocEnd(); 3260 } 3261 3262 static bool classof(const Stmt *T) { 3263 return T->getStmtClass() == UnresolvedMemberExprClass; 3264 } 3265 3266 // Iterators 3267 child_range children() { 3268 if (isImplicitAccess()) return child_range(); 3269 return child_range(&Base, &Base + 1); 3270 } 3271}; 3272 3273/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 3274/// 3275/// The noexcept expression tests whether a given expression might throw. Its 3276/// result is a boolean constant. 3277class CXXNoexceptExpr : public Expr { 3278 bool Value : 1; 3279 Stmt *Operand; 3280 SourceRange Range; 3281 3282 friend class ASTStmtReader; 3283 3284public: 3285 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3286 SourceLocation Keyword, SourceLocation RParen) 3287 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3288 /*TypeDependent*/false, 3289 /*ValueDependent*/Val == CT_Dependent, 3290 Val == CT_Dependent || Operand->isInstantiationDependent(), 3291 Operand->containsUnexpandedParameterPack()), 3292 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3293 { } 3294 3295 CXXNoexceptExpr(EmptyShell Empty) 3296 : Expr(CXXNoexceptExprClass, Empty) 3297 { } 3298 3299 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3300 3301 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 3302 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 3303 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 3304 3305 bool getValue() const { return Value; } 3306 3307 static bool classof(const Stmt *T) { 3308 return T->getStmtClass() == CXXNoexceptExprClass; 3309 } 3310 3311 // Iterators 3312 child_range children() { return child_range(&Operand, &Operand + 1); } 3313}; 3314 3315/// \brief Represents a C++0x pack expansion that produces a sequence of 3316/// expressions. 3317/// 3318/// A pack expansion expression contains a pattern (which itself is an 3319/// expression) followed by an ellipsis. For example: 3320/// 3321/// \code 3322/// template<typename F, typename ...Types> 3323/// void forward(F f, Types &&...args) { 3324/// f(static_cast<Types&&>(args)...); 3325/// } 3326/// \endcode 3327/// 3328/// Here, the argument to the function object \c f is a pack expansion whose 3329/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3330/// template is instantiated, the pack expansion will instantiate to zero or 3331/// or more function arguments to the function object \c f. 3332class PackExpansionExpr : public Expr { 3333 SourceLocation EllipsisLoc; 3334 3335 /// \brief The number of expansions that will be produced by this pack 3336 /// expansion expression, if known. 3337 /// 3338 /// When zero, the number of expansions is not known. Otherwise, this value 3339 /// is the number of expansions + 1. 3340 unsigned NumExpansions; 3341 3342 Stmt *Pattern; 3343 3344 friend class ASTStmtReader; 3345 friend class ASTStmtWriter; 3346 3347public: 3348 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3349 llvm::Optional<unsigned> NumExpansions) 3350 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3351 Pattern->getObjectKind(), /*TypeDependent=*/true, 3352 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3353 /*ContainsUnexpandedParameterPack=*/false), 3354 EllipsisLoc(EllipsisLoc), 3355 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3356 Pattern(Pattern) { } 3357 3358 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3359 3360 /// \brief Retrieve the pattern of the pack expansion. 3361 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3362 3363 /// \brief Retrieve the pattern of the pack expansion. 3364 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3365 3366 /// \brief Retrieve the location of the ellipsis that describes this pack 3367 /// expansion. 3368 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3369 3370 /// \brief Determine the number of expansions that will be produced when 3371 /// this pack expansion is instantiated, if already known. 3372 llvm::Optional<unsigned> getNumExpansions() const { 3373 if (NumExpansions) 3374 return NumExpansions - 1; 3375 3376 return llvm::Optional<unsigned>(); 3377 } 3378 3379 SourceLocation getLocStart() const LLVM_READONLY { 3380 return Pattern->getLocStart(); 3381 } 3382 SourceLocation getLocEnd() const LLVM_READONLY { return EllipsisLoc; } 3383 3384 static bool classof(const Stmt *T) { 3385 return T->getStmtClass() == PackExpansionExprClass; 3386 } 3387 3388 // Iterators 3389 child_range children() { 3390 return child_range(&Pattern, &Pattern + 1); 3391 } 3392}; 3393 3394inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3395 if (!HasTemplateKWAndArgsInfo) return 0; 3396 if (isa<UnresolvedLookupExpr>(this)) 3397 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3398 (cast<UnresolvedLookupExpr>(this) + 1); 3399 else 3400 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3401 (cast<UnresolvedMemberExpr>(this) + 1); 3402} 3403 3404/// \brief Represents an expression that computes the length of a parameter 3405/// pack. 3406/// 3407/// \code 3408/// template<typename ...Types> 3409/// struct count { 3410/// static const unsigned value = sizeof...(Types); 3411/// }; 3412/// \endcode 3413class SizeOfPackExpr : public Expr { 3414 /// \brief The location of the 'sizeof' keyword. 3415 SourceLocation OperatorLoc; 3416 3417 /// \brief The location of the name of the parameter pack. 3418 SourceLocation PackLoc; 3419 3420 /// \brief The location of the closing parenthesis. 3421 SourceLocation RParenLoc; 3422 3423 /// \brief The length of the parameter pack, if known. 3424 /// 3425 /// When this expression is value-dependent, the length of the parameter pack 3426 /// is unknown. When this expression is not value-dependent, the length is 3427 /// known. 3428 unsigned Length; 3429 3430 /// \brief The parameter pack itself. 3431 NamedDecl *Pack; 3432 3433 friend class ASTStmtReader; 3434 friend class ASTStmtWriter; 3435 3436public: 3437 /// \brief Creates a value-dependent expression that computes the length of 3438 /// the given parameter pack. 3439 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3440 SourceLocation PackLoc, SourceLocation RParenLoc) 3441 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3442 /*TypeDependent=*/false, /*ValueDependent=*/true, 3443 /*InstantiationDependent=*/true, 3444 /*ContainsUnexpandedParameterPack=*/false), 3445 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3446 Length(0), Pack(Pack) { } 3447 3448 /// \brief Creates an expression that computes the length of 3449 /// the given parameter pack, which is already known. 3450 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3451 SourceLocation PackLoc, SourceLocation RParenLoc, 3452 unsigned Length) 3453 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3454 /*TypeDependent=*/false, /*ValueDependent=*/false, 3455 /*InstantiationDependent=*/false, 3456 /*ContainsUnexpandedParameterPack=*/false), 3457 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3458 Length(Length), Pack(Pack) { } 3459 3460 /// \brief Create an empty expression. 3461 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3462 3463 /// \brief Determine the location of the 'sizeof' keyword. 3464 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3465 3466 /// \brief Determine the location of the parameter pack. 3467 SourceLocation getPackLoc() const { return PackLoc; } 3468 3469 /// \brief Determine the location of the right parenthesis. 3470 SourceLocation getRParenLoc() const { return RParenLoc; } 3471 3472 /// \brief Retrieve the parameter pack. 3473 NamedDecl *getPack() const { return Pack; } 3474 3475 /// \brief Retrieve the length of the parameter pack. 3476 /// 3477 /// This routine may only be invoked when the expression is not 3478 /// value-dependent. 3479 unsigned getPackLength() const { 3480 assert(!isValueDependent() && 3481 "Cannot get the length of a value-dependent pack size expression"); 3482 return Length; 3483 } 3484 3485 SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 3486 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3487 3488 static bool classof(const Stmt *T) { 3489 return T->getStmtClass() == SizeOfPackExprClass; 3490 } 3491 3492 // Iterators 3493 child_range children() { return child_range(); } 3494}; 3495 3496/// \brief Represents a reference to a non-type template parameter 3497/// that has been substituted with a template argument. 3498class SubstNonTypeTemplateParmExpr : public Expr { 3499 /// \brief The replaced parameter. 3500 NonTypeTemplateParmDecl *Param; 3501 3502 /// \brief The replacement expression. 3503 Stmt *Replacement; 3504 3505 /// \brief The location of the non-type template parameter reference. 3506 SourceLocation NameLoc; 3507 3508 friend class ASTReader; 3509 friend class ASTStmtReader; 3510 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3511 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3512 3513public: 3514 SubstNonTypeTemplateParmExpr(QualType type, 3515 ExprValueKind valueKind, 3516 SourceLocation loc, 3517 NonTypeTemplateParmDecl *param, 3518 Expr *replacement) 3519 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3520 replacement->isTypeDependent(), replacement->isValueDependent(), 3521 replacement->isInstantiationDependent(), 3522 replacement->containsUnexpandedParameterPack()), 3523 Param(param), Replacement(replacement), NameLoc(loc) {} 3524 3525 SourceLocation getNameLoc() const { return NameLoc; } 3526 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3527 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3528 3529 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3530 3531 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3532 3533 static bool classof(const Stmt *s) { 3534 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3535 } 3536 3537 // Iterators 3538 child_range children() { return child_range(&Replacement, &Replacement+1); } 3539}; 3540 3541/// \brief Represents a reference to a non-type template parameter pack that 3542/// has been substituted with a non-template argument pack. 3543/// 3544/// When a pack expansion in the source code contains multiple parameter packs 3545/// and those parameter packs correspond to different levels of template 3546/// parameter lists, this node is used to represent a non-type template 3547/// parameter pack from an outer level, which has already had its argument pack 3548/// substituted but that still lives within a pack expansion that itself 3549/// could not be instantiated. When actually performing a substitution into 3550/// that pack expansion (e.g., when all template parameters have corresponding 3551/// arguments), this type will be replaced with the appropriate underlying 3552/// expression at the current pack substitution index. 3553class SubstNonTypeTemplateParmPackExpr : public Expr { 3554 /// \brief The non-type template parameter pack itself. 3555 NonTypeTemplateParmDecl *Param; 3556 3557 /// \brief A pointer to the set of template arguments that this 3558 /// parameter pack is instantiated with. 3559 const TemplateArgument *Arguments; 3560 3561 /// \brief The number of template arguments in \c Arguments. 3562 unsigned NumArguments; 3563 3564 /// \brief The location of the non-type template parameter pack reference. 3565 SourceLocation NameLoc; 3566 3567 friend class ASTReader; 3568 friend class ASTStmtReader; 3569 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3570 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3571 3572public: 3573 SubstNonTypeTemplateParmPackExpr(QualType T, 3574 NonTypeTemplateParmDecl *Param, 3575 SourceLocation NameLoc, 3576 const TemplateArgument &ArgPack); 3577 3578 /// \brief Retrieve the non-type template parameter pack being substituted. 3579 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3580 3581 /// \brief Retrieve the location of the parameter pack name. 3582 SourceLocation getParameterPackLocation() const { return NameLoc; } 3583 3584 /// \brief Retrieve the template argument pack containing the substituted 3585 /// template arguments. 3586 TemplateArgument getArgumentPack() const; 3587 3588 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3589 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3590 3591 static bool classof(const Stmt *T) { 3592 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3593 } 3594 3595 // Iterators 3596 child_range children() { return child_range(); } 3597}; 3598 3599/// \brief Represents a reference to a function parameter pack that has been 3600/// substituted but not yet expanded. 3601/// 3602/// When a pack expansion contains multiple parameter packs at different levels, 3603/// this node is used to represent a function parameter pack at an outer level 3604/// which we have already substituted to refer to expanded parameters, but where 3605/// the containing pack expansion cannot yet be expanded. 3606/// 3607/// \code 3608/// template<typename...Ts> struct S { 3609/// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); 3610/// }; 3611/// template struct S<int, int>; 3612/// \endcode 3613class FunctionParmPackExpr : public Expr { 3614 /// \brief The function parameter pack which was referenced. 3615 ParmVarDecl *ParamPack; 3616 3617 /// \brief The location of the function parameter pack reference. 3618 SourceLocation NameLoc; 3619 3620 /// \brief The number of expansions of this pack. 3621 unsigned NumParameters; 3622 3623 FunctionParmPackExpr(QualType T, ParmVarDecl *ParamPack, 3624 SourceLocation NameLoc, unsigned NumParams, 3625 Decl * const *Params); 3626 3627 friend class ASTReader; 3628 friend class ASTStmtReader; 3629 3630public: 3631 static FunctionParmPackExpr *Create(ASTContext &Context, QualType T, 3632 ParmVarDecl *ParamPack, 3633 SourceLocation NameLoc, 3634 llvm::ArrayRef<Decl*> Params); 3635 static FunctionParmPackExpr *CreateEmpty(ASTContext &Context, 3636 unsigned NumParams); 3637 3638 /// \brief Get the parameter pack which this expression refers to. 3639 ParmVarDecl *getParameterPack() const { return ParamPack; } 3640 3641 /// \brief Get the location of the parameter pack. 3642 SourceLocation getParameterPackLocation() const { return NameLoc; } 3643 3644 /// \brief Iterators over the parameters which the parameter pack expanded 3645 /// into. 3646 typedef ParmVarDecl * const *iterator; 3647 iterator begin() const { return reinterpret_cast<iterator>(this+1); } 3648 iterator end() const { return begin() + NumParameters; } 3649 3650 /// \brief Get the number of parameters in this parameter pack. 3651 unsigned getNumExpansions() const { return NumParameters; } 3652 3653 /// \brief Get an expansion of the parameter pack by index. 3654 ParmVarDecl *getExpansion(unsigned I) const { return begin()[I]; } 3655 3656 SourceLocation getLocStart() const LLVM_READONLY { return NameLoc; } 3657 SourceLocation getLocEnd() const LLVM_READONLY { return NameLoc; } 3658 3659 static bool classof(const Stmt *T) { 3660 return T->getStmtClass() == FunctionParmPackExprClass; 3661 } 3662 3663 child_range children() { return child_range(); } 3664}; 3665 3666/// \brief Represents a prvalue temporary that written into memory so that 3667/// a reference can bind to it. 3668/// 3669/// Prvalue expressions are materialized when they need to have an address 3670/// in memory for a reference to bind to. This happens when binding a 3671/// reference to the result of a conversion, e.g., 3672/// 3673/// \code 3674/// const int &r = 1.0; 3675/// \endcode 3676/// 3677/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3678/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3679/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3680/// (either an lvalue or an xvalue, depending on the kind of reference binding 3681/// to it), maintaining the invariant that references always bind to glvalues. 3682class MaterializeTemporaryExpr : public Expr { 3683 /// \brief The temporary-generating expression whose value will be 3684 /// materialized. 3685 Stmt *Temporary; 3686 3687 friend class ASTStmtReader; 3688 friend class ASTStmtWriter; 3689 3690public: 3691 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3692 bool BoundToLvalueReference) 3693 : Expr(MaterializeTemporaryExprClass, T, 3694 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3695 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3696 Temporary->isInstantiationDependent(), 3697 Temporary->containsUnexpandedParameterPack()), 3698 Temporary(Temporary) { } 3699 3700 MaterializeTemporaryExpr(EmptyShell Empty) 3701 : Expr(MaterializeTemporaryExprClass, Empty) { } 3702 3703 /// \brief Retrieve the temporary-generating subexpression whose value will 3704 /// be materialized into a glvalue. 3705 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3706 3707 /// \brief Determine whether this materialized temporary is bound to an 3708 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3709 bool isBoundToLvalueReference() const { 3710 return getValueKind() == VK_LValue; 3711 } 3712 3713 SourceLocation getLocStart() const LLVM_READONLY { 3714 return Temporary->getLocStart(); 3715 } 3716 SourceLocation getLocEnd() const LLVM_READONLY { 3717 return Temporary->getLocEnd(); 3718 } 3719 3720 static bool classof(const Stmt *T) { 3721 return T->getStmtClass() == MaterializeTemporaryExprClass; 3722 } 3723 3724 // Iterators 3725 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3726}; 3727 3728} // end namespace clang 3729 3730#endif 3731