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