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