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