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