ExprCXX.h revision 5b9cc5df25c2198f270dd1d5c438fdce70d4051d
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}; 740 741/// \brief Represents binding an expression to a temporary. 742/// 743/// This ensures the destructor is called for the temporary. It should only be 744/// needed for non-POD, non-trivially destructable class types. For example: 745/// 746/// \code 747/// struct S { 748/// S() { } // User defined constructor makes S non-POD. 749/// ~S() { } // User defined destructor makes it non-trivial. 750/// }; 751/// void test() { 752/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. 753/// } 754/// \endcode 755class CXXBindTemporaryExpr : public Expr { 756 CXXTemporary *Temp; 757 758 Stmt *SubExpr; 759 760 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr) 761 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), 762 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(), 763 SubExpr->isValueDependent(), 764 SubExpr->isInstantiationDependent(), 765 SubExpr->containsUnexpandedParameterPack()), 766 Temp(temp), SubExpr(SubExpr) { } 767 768public: 769 CXXBindTemporaryExpr(EmptyShell Empty) 770 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {} 771 772 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 773 Expr* SubExpr); 774 775 CXXTemporary *getTemporary() { return Temp; } 776 const CXXTemporary *getTemporary() const { return Temp; } 777 void setTemporary(CXXTemporary *T) { Temp = T; } 778 779 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 780 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 781 void setSubExpr(Expr *E) { SubExpr = E; } 782 783 SourceRange getSourceRange() const { 784 return SubExpr->getSourceRange(); 785 } 786 787 // Implement isa/cast/dyncast/etc. 788 static bool classof(const Stmt *T) { 789 return T->getStmtClass() == CXXBindTemporaryExprClass; 790 } 791 static bool classof(const CXXBindTemporaryExpr *) { return true; } 792 793 // Iterators 794 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 795}; 796 797/// CXXConstructExpr - Represents a call to a C++ constructor. 798class CXXConstructExpr : public Expr { 799public: 800 enum ConstructionKind { 801 CK_Complete, 802 CK_NonVirtualBase, 803 CK_VirtualBase, 804 CK_Delegating 805 }; 806 807private: 808 CXXConstructorDecl *Constructor; 809 810 SourceLocation Loc; 811 SourceRange ParenRange; 812 unsigned NumArgs : 16; 813 bool Elidable : 1; 814 bool HadMultipleCandidates : 1; 815 bool ListInitialization : 1; 816 bool ZeroInitialization : 1; 817 unsigned ConstructKind : 2; 818 Stmt **Args; 819 820protected: 821 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 822 SourceLocation Loc, 823 CXXConstructorDecl *d, bool elidable, 824 Expr **args, unsigned numargs, 825 bool HadMultipleCandidates, 826 bool ListInitialization, 827 bool ZeroInitialization, 828 ConstructionKind ConstructKind, 829 SourceRange ParenRange); 830 831 /// \brief Construct an empty C++ construction expression. 832 CXXConstructExpr(StmtClass SC, EmptyShell Empty) 833 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false), 834 HadMultipleCandidates(false), ListInitialization(false), 835 ZeroInitialization(false), ConstructKind(0), Args(0) 836 { } 837 838public: 839 /// \brief Construct an empty C++ construction expression. 840 explicit CXXConstructExpr(EmptyShell Empty) 841 : Expr(CXXConstructExprClass, Empty), Constructor(0), 842 NumArgs(0), Elidable(false), HadMultipleCandidates(false), 843 ListInitialization(false), ZeroInitialization(false), 844 ConstructKind(0), Args(0) 845 { } 846 847 static CXXConstructExpr *Create(ASTContext &C, QualType T, 848 SourceLocation Loc, 849 CXXConstructorDecl *D, bool Elidable, 850 Expr **Args, unsigned NumArgs, 851 bool HadMultipleCandidates, 852 bool ListInitialization, 853 bool ZeroInitialization, 854 ConstructionKind ConstructKind, 855 SourceRange ParenRange); 856 857 CXXConstructorDecl* getConstructor() const { return Constructor; } 858 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 859 860 SourceLocation getLocation() const { return Loc; } 861 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 862 863 /// \brief Whether this construction is elidable. 864 bool isElidable() const { return Elidable; } 865 void setElidable(bool E) { Elidable = E; } 866 867 /// \brief Whether the referred constructor was resolved from 868 /// an overloaded set having size greater than 1. 869 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 870 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 871 872 /// \brief Whether this constructor call was written as list-initialization. 873 bool isListInitialization() const { return ListInitialization; } 874 void setListInitialization(bool V) { ListInitialization = V; } 875 876 /// \brief Whether this construction first requires 877 /// zero-initialization before the initializer is called. 878 bool requiresZeroInitialization() const { return ZeroInitialization; } 879 void setRequiresZeroInitialization(bool ZeroInit) { 880 ZeroInitialization = ZeroInit; 881 } 882 883 /// \brief Determines whether this constructor is actually constructing 884 /// a base class (rather than a complete object). 885 ConstructionKind getConstructionKind() const { 886 return (ConstructionKind)ConstructKind; 887 } 888 void setConstructionKind(ConstructionKind CK) { 889 ConstructKind = CK; 890 } 891 892 typedef ExprIterator arg_iterator; 893 typedef ConstExprIterator const_arg_iterator; 894 895 arg_iterator arg_begin() { return Args; } 896 arg_iterator arg_end() { return Args + NumArgs; } 897 const_arg_iterator arg_begin() const { return Args; } 898 const_arg_iterator arg_end() const { return Args + NumArgs; } 899 900 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 901 unsigned getNumArgs() const { return NumArgs; } 902 903 /// getArg - Return the specified argument. 904 Expr *getArg(unsigned Arg) { 905 assert(Arg < NumArgs && "Arg access out of range!"); 906 return cast<Expr>(Args[Arg]); 907 } 908 const Expr *getArg(unsigned Arg) const { 909 assert(Arg < NumArgs && "Arg access out of range!"); 910 return cast<Expr>(Args[Arg]); 911 } 912 913 /// setArg - Set the specified argument. 914 void setArg(unsigned Arg, Expr *ArgExpr) { 915 assert(Arg < NumArgs && "Arg access out of range!"); 916 Args[Arg] = ArgExpr; 917 } 918 919 SourceRange getSourceRange() const; 920 SourceRange getParenRange() const { return ParenRange; } 921 922 static bool classof(const Stmt *T) { 923 return T->getStmtClass() == CXXConstructExprClass || 924 T->getStmtClass() == CXXTemporaryObjectExprClass; 925 } 926 static bool classof(const CXXConstructExpr *) { return true; } 927 928 // Iterators 929 child_range children() { 930 return child_range(&Args[0], &Args[0]+NumArgs); 931 } 932 933 friend class ASTStmtReader; 934}; 935 936/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 937/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 938/// x = int(0.5); 939class CXXFunctionalCastExpr : public ExplicitCastExpr { 940 SourceLocation TyBeginLoc; 941 SourceLocation RParenLoc; 942 943 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, 944 TypeSourceInfo *writtenTy, 945 SourceLocation tyBeginLoc, CastKind kind, 946 Expr *castExpr, unsigned pathSize, 947 SourceLocation rParenLoc) 948 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, 949 castExpr, pathSize, writtenTy), 950 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 951 952 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize) 953 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { } 954 955public: 956 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T, 957 ExprValueKind VK, 958 TypeSourceInfo *Written, 959 SourceLocation TyBeginLoc, 960 CastKind Kind, Expr *Op, 961 const CXXCastPath *Path, 962 SourceLocation RPLoc); 963 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context, 964 unsigned PathSize); 965 966 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 967 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 968 SourceLocation getRParenLoc() const { return RParenLoc; } 969 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 970 971 SourceRange getSourceRange() const { 972 return SourceRange(TyBeginLoc, RParenLoc); 973 } 974 static bool classof(const Stmt *T) { 975 return T->getStmtClass() == CXXFunctionalCastExprClass; 976 } 977 static bool classof(const CXXFunctionalCastExpr *) { return true; } 978}; 979 980/// @brief Represents a C++ functional cast expression that builds a 981/// temporary object. 982/// 983/// This expression type represents a C++ "functional" cast 984/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 985/// constructor to build a temporary object. With N == 1 arguments the 986/// functional cast expression will be represented by CXXFunctionalCastExpr. 987/// Example: 988/// @code 989/// struct X { X(int, float); } 990/// 991/// X create_X() { 992/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 993/// }; 994/// @endcode 995class CXXTemporaryObjectExpr : public CXXConstructExpr { 996 TypeSourceInfo *Type; 997 998public: 999 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 1000 TypeSourceInfo *Type, 1001 Expr **Args,unsigned NumArgs, 1002 SourceRange parenRange, 1003 bool HadMultipleCandidates, 1004 bool ZeroInitialization = false); 1005 explicit CXXTemporaryObjectExpr(EmptyShell Empty) 1006 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { } 1007 1008 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 1009 1010 SourceRange getSourceRange() const; 1011 1012 static bool classof(const Stmt *T) { 1013 return T->getStmtClass() == CXXTemporaryObjectExprClass; 1014 } 1015 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 1016 1017 friend class ASTStmtReader; 1018}; 1019 1020/// \brief A C++ lambda expression, which produces a function object 1021/// (of unspecified type) that can be invoked later. 1022/// 1023/// Example: 1024/// \code 1025/// void low_pass_filter(std::vector<double> &values, double cutoff) { 1026/// values.erase(std::remove_if(values.begin(), values.end(), 1027// [=](double value) { return value > cutoff; }); 1028/// } 1029/// \endcode 1030/// 1031/// Lambda expressions can capture local variables, either by copying 1032/// the values of those local variables at the time the function 1033/// object is constructed (not when it is called!) or by holding a 1034/// reference to the local variable. These captures can occur either 1035/// implicitly or can be written explicitly between the square 1036/// brackets ([...]) that start the lambda expression. 1037class LambdaExpr : public Expr { 1038 enum { 1039 /// \brief Flag used by the Capture class to indicate that the given 1040 /// capture was implicit. 1041 Capture_Implicit = 0x01, 1042 1043 /// \brief Flag used by the Capture class to indciate that the 1044 /// given capture was by-copy. 1045 Capture_ByCopy = 0x02 1046 }; 1047 1048 /// \brief The source range that covers the lambda introducer ([...]). 1049 SourceRange IntroducerRange; 1050 1051 /// \brief The number of captures in this lambda. 1052 unsigned NumCaptures : 16; 1053 1054 /// \brief The number of explicit captures in this lambda. 1055 unsigned NumExplicitCaptures : 13; 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 The location of the closing brace ('}') that completes 1066 /// the lambda. 1067 /// 1068 /// The location of the brace is also available by looking up the 1069 /// function call operator in the lambda class. However, it is 1070 /// stored here to improve the performance of getSourceRange(), and 1071 /// to avoid having to deserialize the function call operator from a 1072 /// module file just to determine the source range. 1073 SourceLocation ClosingBrace; 1074 1075 // Note: The Create method allocates storage after the LambdaExpr 1076 // object, which contains the captures, followed by the capture 1077 // initializers, and finally the body of the lambda. The capture 1078 // initializers and lambda body are placed next to each other so 1079 // that the children() function can visit all of them easily. 1080 1081public: 1082 /// \brief Describes the capture of either a variable or 'this'. 1083 class Capture { 1084 llvm::PointerIntPair<VarDecl *, 2> VarAndBits; 1085 SourceLocation Loc; 1086 SourceLocation EllipsisLoc; 1087 1088 friend class ASTStmtReader; 1089 friend class ASTStmtWriter; 1090 1091 public: 1092 /// \brief Create a new capture. 1093 /// 1094 /// \param Loc The source location associated with this capture. 1095 /// 1096 /// \param Kind The kind of capture (this, byref, bycopy). 1097 /// 1098 /// \param Implicit Whether the capture was implicit or explicit. 1099 /// 1100 /// \param Var The local variable being captured, or null if capturing this. 1101 /// 1102 /// \param EllipsisLoc The location of the ellipsis (...) for a 1103 /// capture that is a pack expansion, or an invalid source 1104 /// location to indicate that this is not a pack expansion. 1105 Capture(SourceLocation Loc, bool Implicit, 1106 LambdaCaptureKind Kind, VarDecl *Var = 0, 1107 SourceLocation EllipsisLoc = SourceLocation()); 1108 1109 /// \brief Determine the kind of capture. 1110 LambdaCaptureKind getCaptureKind() const; 1111 1112 /// \brief Determine whether this capture handles the C++ 'this' 1113 /// pointer. 1114 bool capturesThis() const { return VarAndBits.getPointer() == 0; } 1115 1116 /// \brief Determine whether this capture handles a variable. 1117 bool capturesVariable() const { return VarAndBits.getPointer() != 0; } 1118 1119 /// \brief Retrieve the declaration of the local variable being 1120 /// captured. 1121 /// 1122 /// This operation is only valid if this capture does not capture 1123 /// 'this'. 1124 VarDecl *getCapturedVar() const { 1125 assert(!capturesThis() && "No variable available for 'this' capture"); 1126 return VarAndBits.getPointer(); 1127 } 1128 1129 /// \brief Determine whether this was an implicit capture (not 1130 /// written between the square brackets introducing the lambda). 1131 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; } 1132 1133 /// \brief Determine whether this was an explicit capture, written 1134 /// between the square brackets introducing the lambda. 1135 bool isExplicit() const { return !isImplicit(); } 1136 1137 /// \brief Retrieve the source location of the capture. 1138 /// 1139 /// For an explicit capture, this returns the location of the 1140 /// explicit capture in the source. For an implicit capture, this 1141 /// returns the location at which the variable or 'this' was first 1142 /// used. 1143 SourceLocation getLocation() const { return Loc; } 1144 1145 /// \brief Determine whether this capture is a pack expansion, 1146 /// which captures a function parameter pack. 1147 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 1148 1149 /// \brief Retrieve the location of the ellipsis for a capture 1150 /// that is a pack expansion. 1151 SourceLocation getEllipsisLoc() const { 1152 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 1153 return EllipsisLoc; 1154 } 1155 }; 1156 1157private: 1158 /// \brief Construct a lambda expression. 1159 LambdaExpr(QualType T, SourceRange IntroducerRange, 1160 LambdaCaptureDefault CaptureDefault, 1161 ArrayRef<Capture> Captures, 1162 bool ExplicitParams, 1163 ArrayRef<Expr *> CaptureInits, 1164 SourceLocation ClosingBrace); 1165 1166 Stmt **getStoredStmts() const { 1167 LambdaExpr *This = const_cast<LambdaExpr *>(this); 1168 return reinterpret_cast<Stmt **>(reinterpret_cast<Capture *>(This + 1) 1169 + NumCaptures); 1170 } 1171 1172public: 1173 /// \brief Construct a new lambda expression. 1174 static LambdaExpr *Create(ASTContext &C, 1175 CXXRecordDecl *Class, 1176 SourceRange IntroducerRange, 1177 LambdaCaptureDefault CaptureDefault, 1178 ArrayRef<Capture> Captures, 1179 bool ExplicitParams, 1180 ArrayRef<Expr *> CaptureInits, 1181 SourceLocation ClosingBrace); 1182 1183 /// \brief Determine the default capture kind for this lambda. 1184 LambdaCaptureDefault getCaptureDefault() const { 1185 return static_cast<LambdaCaptureDefault>(CaptureDefault); 1186 } 1187 1188 /// \brief An iterator that walks over the captures of the lambda, 1189 /// both implicit and explicit. 1190 typedef const Capture *capture_iterator; 1191 1192 /// \brief Retrieve an iterator pointing to the first lambda capture. 1193 capture_iterator capture_begin() const { 1194 return reinterpret_cast<const Capture *>(this + 1); 1195 } 1196 1197 /// \brief Retrieve an iterator pointing past the end of the 1198 /// sequence of lambda captures. 1199 capture_iterator capture_end() const { 1200 return capture_begin() + NumCaptures; 1201 } 1202 1203 /// \brief Retrieve an iterator pointing to the first explicit 1204 /// lambda capture. 1205 capture_iterator explicit_capture_begin() const { 1206 return capture_begin(); 1207 } 1208 1209 /// \brief Retrieve an iterator pointing past the end of the sequence of 1210 /// explicit lambda captures. 1211 capture_iterator explicit_capture_end() const { 1212 return capture_begin() + NumExplicitCaptures; 1213 } 1214 1215 /// \brief Retrieve an iterator pointing to the first implicit 1216 /// lambda capture. 1217 capture_iterator implicit_capture_begin() const { 1218 return explicit_capture_end(); 1219 } 1220 1221 /// \brief Retrieve an iterator pointing past the end of the sequence of 1222 /// implicit lambda captures. 1223 capture_iterator implicit_capture_end() const { 1224 return capture_end(); 1225 } 1226 1227 /// \brief Iterator that walks over the capture initialization 1228 /// arguments. 1229 typedef Expr **capture_init_iterator; 1230 1231 /// \brief Retrieve the first initialization argument for this 1232 /// lambda expression (which initializes the first capture field). 1233 capture_init_iterator capture_init_begin() const { 1234 return reinterpret_cast<Expr **>(getStoredStmts()); 1235 } 1236 1237 /// \brief Retrieve the iterator pointing one past the last 1238 /// initialization argument for this lambda expression. 1239 capture_init_iterator capture_init_end() const { 1240 return capture_init_begin() + NumCaptures; 1241 } 1242 1243 /// \brief Retrieve the source range covering the lambda introducer, 1244 /// which contains the explicit capture list surrounded by square 1245 /// brackets ([...]). 1246 SourceRange getIntroducerRange() const { return IntroducerRange; } 1247 1248 /// \brief Retrieve the class that corresponds to the lambda, which 1249 /// stores the captures in its fields and provides the various 1250 /// operations permitted on a lambda (copying, calling). 1251 CXXRecordDecl *getLambdaClass() const; 1252 1253 /// \brief Retrieve the function call operator associated with this 1254 /// lambda expression. 1255 CXXMethodDecl *getCallOperator() const; 1256 1257 /// \brief Retrieve the body of the lambda. 1258 CompoundStmt *getBody() const { 1259 return reinterpret_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]); 1260 } 1261 1262 /// \brief Determine whether the lambda is mutable, meaning that any 1263 /// captures values can be modified. 1264 bool isMutable() const; 1265 1266 /// \brief Determine whether this lambda has an explicit parameter 1267 /// list vs. an implicit (empty) parameter list. 1268 bool hasExplicitParameters() const { return ExplicitParams; } 1269 1270 static bool classof(const Stmt *T) { 1271 return T->getStmtClass() == LambdaExprClass; 1272 } 1273 static bool classof(const LambdaExpr *) { return true; } 1274 1275 SourceRange getSourceRange() const { 1276 return SourceRange(IntroducerRange.getBegin(), ClosingBrace); 1277 } 1278 1279 child_range children() { 1280 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1); 1281 } 1282 1283 friend class ASTStmtReader; 1284 friend class ASTStmtWriter; 1285}; 1286 1287/// CXXScalarValueInitExpr - [C++ 5.2.3p2] 1288/// Expression "T()" which creates a value-initialized rvalue of type 1289/// T, which is a non-class type. 1290/// 1291class CXXScalarValueInitExpr : public Expr { 1292 SourceLocation RParenLoc; 1293 TypeSourceInfo *TypeInfo; 1294 1295 friend class ASTStmtReader; 1296 1297public: 1298 /// \brief Create an explicitly-written scalar-value initialization 1299 /// expression. 1300 CXXScalarValueInitExpr(QualType Type, 1301 TypeSourceInfo *TypeInfo, 1302 SourceLocation rParenLoc ) : 1303 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, 1304 false, false, Type->isInstantiationDependentType(), false), 1305 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {} 1306 1307 explicit CXXScalarValueInitExpr(EmptyShell Shell) 1308 : Expr(CXXScalarValueInitExprClass, Shell) { } 1309 1310 TypeSourceInfo *getTypeSourceInfo() const { 1311 return TypeInfo; 1312 } 1313 1314 SourceLocation getRParenLoc() const { return RParenLoc; } 1315 1316 SourceRange getSourceRange() const; 1317 1318 static bool classof(const Stmt *T) { 1319 return T->getStmtClass() == CXXScalarValueInitExprClass; 1320 } 1321 static bool classof(const CXXScalarValueInitExpr *) { return true; } 1322 1323 // Iterators 1324 child_range children() { return child_range(); } 1325}; 1326 1327/// CXXNewExpr - A new expression for memory allocation and constructor calls, 1328/// e.g: "new CXXNewExpr(foo)". 1329class CXXNewExpr : public Expr { 1330 // Was the usage ::new, i.e. is the global new to be used? 1331 bool GlobalNew : 1; 1332 // Is there an initializer? If not, built-ins are uninitialized, else they're 1333 // value-initialized. 1334 bool Initializer : 1; 1335 // Do we allocate an array? If so, the first SubExpr is the size expression. 1336 bool Array : 1; 1337 // If this is an array allocation, does the usual deallocation 1338 // function for the allocated type want to know the allocated size? 1339 bool UsualArrayDeleteWantsSize : 1; 1340 // Whether the referred constructor (if any) was resolved from an 1341 // overload set having size greater than 1. 1342 bool HadMultipleCandidates : 1; 1343 // The number of placement new arguments. 1344 unsigned NumPlacementArgs : 13; 1345 // The number of constructor arguments. This may be 1 even for non-class 1346 // types; use the pseudo copy constructor. 1347 unsigned NumConstructorArgs : 14; 1348 // Contains an optional array size expression, any number of optional 1349 // placement arguments, and any number of optional constructor arguments, 1350 // in that order. 1351 Stmt **SubExprs; 1352 // Points to the allocation function used. 1353 FunctionDecl *OperatorNew; 1354 // Points to the deallocation function used in case of error. May be null. 1355 FunctionDecl *OperatorDelete; 1356 // Points to the constructor used. Cannot be null if AllocType is a record; 1357 // it would still point at the default constructor (even an implicit one). 1358 // Must be null for all other types. 1359 CXXConstructorDecl *Constructor; 1360 1361 /// \brief The allocated type-source information, as written in the source. 1362 TypeSourceInfo *AllocatedTypeInfo; 1363 1364 /// \brief If the allocated type was expressed as a parenthesized type-id, 1365 /// the source range covering the parenthesized type-id. 1366 SourceRange TypeIdParens; 1367 1368 SourceLocation StartLoc; 1369 SourceLocation EndLoc; 1370 SourceLocation ConstructorLParen; 1371 SourceLocation ConstructorRParen; 1372 1373 friend class ASTStmtReader; 1374public: 1375 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 1376 Expr **placementArgs, unsigned numPlaceArgs, 1377 SourceRange TypeIdParens, 1378 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer, 1379 Expr **constructorArgs, unsigned numConsArgs, 1380 bool HadMultipleCandidates, 1381 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize, 1382 QualType ty, TypeSourceInfo *AllocatedTypeInfo, 1383 SourceLocation startLoc, SourceLocation endLoc, 1384 SourceLocation constructorLParen, 1385 SourceLocation constructorRParen); 1386 explicit CXXNewExpr(EmptyShell Shell) 1387 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 1388 1389 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 1390 unsigned numConsArgs); 1391 1392 QualType getAllocatedType() const { 1393 assert(getType()->isPointerType()); 1394 return getType()->getAs<PointerType>()->getPointeeType(); 1395 } 1396 1397 TypeSourceInfo *getAllocatedTypeSourceInfo() const { 1398 return AllocatedTypeInfo; 1399 } 1400 1401 /// \brief True if the allocation result needs to be null-checked. 1402 /// C++0x [expr.new]p13: 1403 /// If the allocation function returns null, initialization shall 1404 /// not be done, the deallocation function shall not be called, 1405 /// and the value of the new-expression shall be null. 1406 /// An allocation function is not allowed to return null unless it 1407 /// has a non-throwing exception-specification. The '03 rule is 1408 /// identical except that the definition of a non-throwing 1409 /// exception specification is just "is it throw()?". 1410 bool shouldNullCheckAllocation(ASTContext &Ctx) const; 1411 1412 FunctionDecl *getOperatorNew() const { return OperatorNew; } 1413 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 1414 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1415 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1416 CXXConstructorDecl *getConstructor() const { return Constructor; } 1417 void setConstructor(CXXConstructorDecl *D) { Constructor = D; } 1418 1419 bool isArray() const { return Array; } 1420 Expr *getArraySize() { 1421 return Array ? cast<Expr>(SubExprs[0]) : 0; 1422 } 1423 const Expr *getArraySize() const { 1424 return Array ? cast<Expr>(SubExprs[0]) : 0; 1425 } 1426 1427 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 1428 Expr **getPlacementArgs() { 1429 return reinterpret_cast<Expr **>(SubExprs + Array); 1430 } 1431 1432 Expr *getPlacementArg(unsigned i) { 1433 assert(i < NumPlacementArgs && "Index out of range"); 1434 return cast<Expr>(SubExprs[Array + i]); 1435 } 1436 const Expr *getPlacementArg(unsigned i) const { 1437 assert(i < NumPlacementArgs && "Index out of range"); 1438 return cast<Expr>(SubExprs[Array + i]); 1439 } 1440 1441 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1442 SourceRange getTypeIdParens() const { return TypeIdParens; } 1443 1444 bool isGlobalNew() const { return GlobalNew; } 1445 bool hasInitializer() const { return Initializer; } 1446 1447 /// Answers whether the usual array deallocation function for the 1448 /// allocated type expects the size of the allocation as a 1449 /// parameter. 1450 bool doesUsualArrayDeleteWantSize() const { 1451 return UsualArrayDeleteWantsSize; 1452 } 1453 1454 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 1455 1456 Expr **getConstructorArgs() { 1457 return reinterpret_cast<Expr **>(SubExprs + Array + NumPlacementArgs); 1458 } 1459 1460 Expr *getConstructorArg(unsigned i) { 1461 assert(i < NumConstructorArgs && "Index out of range"); 1462 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1463 } 1464 const Expr *getConstructorArg(unsigned i) const { 1465 assert(i < NumConstructorArgs && "Index out of range"); 1466 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1467 } 1468 1469 /// \brief Whether the new expression refers a constructor that was 1470 /// resolved from an overloaded set having size greater than 1. 1471 bool hadMultipleCandidates() const { return HadMultipleCandidates; } 1472 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; } 1473 1474 typedef ExprIterator arg_iterator; 1475 typedef ConstExprIterator const_arg_iterator; 1476 1477 arg_iterator placement_arg_begin() { 1478 return SubExprs + Array; 1479 } 1480 arg_iterator placement_arg_end() { 1481 return SubExprs + Array + getNumPlacementArgs(); 1482 } 1483 const_arg_iterator placement_arg_begin() const { 1484 return SubExprs + Array; 1485 } 1486 const_arg_iterator placement_arg_end() const { 1487 return SubExprs + Array + getNumPlacementArgs(); 1488 } 1489 1490 arg_iterator constructor_arg_begin() { 1491 return SubExprs + Array + getNumPlacementArgs(); 1492 } 1493 arg_iterator constructor_arg_end() { 1494 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1495 } 1496 const_arg_iterator constructor_arg_begin() const { 1497 return SubExprs + Array + getNumPlacementArgs(); 1498 } 1499 const_arg_iterator constructor_arg_end() const { 1500 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1501 } 1502 1503 typedef Stmt **raw_arg_iterator; 1504 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1505 raw_arg_iterator raw_arg_end() { 1506 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1507 } 1508 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1509 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } 1510 1511 SourceLocation getStartLoc() const { return StartLoc; } 1512 SourceLocation getEndLoc() const { return EndLoc; } 1513 1514 SourceLocation getConstructorLParen() const { return ConstructorLParen; } 1515 SourceLocation getConstructorRParen() const { return ConstructorRParen; } 1516 1517 SourceRange getSourceRange() const { 1518 return SourceRange(StartLoc, EndLoc); 1519 } 1520 1521 static bool classof(const Stmt *T) { 1522 return T->getStmtClass() == CXXNewExprClass; 1523 } 1524 static bool classof(const CXXNewExpr *) { return true; } 1525 1526 // Iterators 1527 child_range children() { 1528 return child_range(&SubExprs[0], 1529 &SubExprs[0] + Array + getNumPlacementArgs() 1530 + getNumConstructorArgs()); 1531 } 1532}; 1533 1534/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 1535/// calls, e.g. "delete[] pArray". 1536class CXXDeleteExpr : public Expr { 1537 // Is this a forced global delete, i.e. "::delete"? 1538 bool GlobalDelete : 1; 1539 // Is this the array form of delete, i.e. "delete[]"? 1540 bool ArrayForm : 1; 1541 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1542 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1543 // will be true). 1544 bool ArrayFormAsWritten : 1; 1545 // Does the usual deallocation function for the element type require 1546 // a size_t argument? 1547 bool UsualArrayDeleteWantsSize : 1; 1548 // Points to the operator delete overload that is used. Could be a member. 1549 FunctionDecl *OperatorDelete; 1550 // The pointer expression to be deleted. 1551 Stmt *Argument; 1552 // Location of the expression. 1553 SourceLocation Loc; 1554public: 1555 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1556 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize, 1557 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1558 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1559 arg->isInstantiationDependent(), 1560 arg->containsUnexpandedParameterPack()), 1561 GlobalDelete(globalDelete), 1562 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1563 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize), 1564 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 1565 explicit CXXDeleteExpr(EmptyShell Shell) 1566 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1567 1568 bool isGlobalDelete() const { return GlobalDelete; } 1569 bool isArrayForm() const { return ArrayForm; } 1570 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1571 1572 /// Answers whether the usual array deallocation function for the 1573 /// allocated type expects the size of the allocation as a 1574 /// parameter. This can be true even if the actual deallocation 1575 /// function that we're using doesn't want a size. 1576 bool doesUsualArrayDeleteWantSize() const { 1577 return UsualArrayDeleteWantsSize; 1578 } 1579 1580 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1581 1582 Expr *getArgument() { return cast<Expr>(Argument); } 1583 const Expr *getArgument() const { return cast<Expr>(Argument); } 1584 1585 /// \brief Retrieve the type being destroyed. If the type being 1586 /// destroyed is a dependent type which may or may not be a pointer, 1587 /// return an invalid type. 1588 QualType getDestroyedType() const; 1589 1590 SourceRange getSourceRange() const { 1591 return SourceRange(Loc, Argument->getLocEnd()); 1592 } 1593 1594 static bool classof(const Stmt *T) { 1595 return T->getStmtClass() == CXXDeleteExprClass; 1596 } 1597 static bool classof(const CXXDeleteExpr *) { return true; } 1598 1599 // Iterators 1600 child_range children() { return child_range(&Argument, &Argument+1); } 1601 1602 friend class ASTStmtReader; 1603}; 1604 1605/// \brief Structure used to store the type being destroyed by a 1606/// pseudo-destructor expression. 1607class PseudoDestructorTypeStorage { 1608 /// \brief Either the type source information or the name of the type, if 1609 /// it couldn't be resolved due to type-dependence. 1610 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1611 1612 /// \brief The starting source location of the pseudo-destructor type. 1613 SourceLocation Location; 1614 1615public: 1616 PseudoDestructorTypeStorage() { } 1617 1618 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1619 : Type(II), Location(Loc) { } 1620 1621 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1622 1623 TypeSourceInfo *getTypeSourceInfo() const { 1624 return Type.dyn_cast<TypeSourceInfo *>(); 1625 } 1626 1627 IdentifierInfo *getIdentifier() const { 1628 return Type.dyn_cast<IdentifierInfo *>(); 1629 } 1630 1631 SourceLocation getLocation() const { return Location; } 1632}; 1633 1634/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1635/// 1636/// A pseudo-destructor is an expression that looks like a member access to a 1637/// destructor of a scalar type, except that scalar types don't have 1638/// destructors. For example: 1639/// 1640/// \code 1641/// typedef int T; 1642/// void f(int *p) { 1643/// p->T::~T(); 1644/// } 1645/// \endcode 1646/// 1647/// Pseudo-destructors typically occur when instantiating templates such as: 1648/// 1649/// \code 1650/// template<typename T> 1651/// void destroy(T* ptr) { 1652/// ptr->T::~T(); 1653/// } 1654/// \endcode 1655/// 1656/// for scalar types. A pseudo-destructor expression has no run-time semantics 1657/// beyond evaluating the base expression. 1658class CXXPseudoDestructorExpr : public Expr { 1659 /// \brief The base expression (that is being destroyed). 1660 Stmt *Base; 1661 1662 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1663 /// period ('.'). 1664 bool IsArrow : 1; 1665 1666 /// \brief The location of the '.' or '->' operator. 1667 SourceLocation OperatorLoc; 1668 1669 /// \brief The nested-name-specifier that follows the operator, if present. 1670 NestedNameSpecifierLoc QualifierLoc; 1671 1672 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1673 /// expression. 1674 TypeSourceInfo *ScopeType; 1675 1676 /// \brief The location of the '::' in a qualified pseudo-destructor 1677 /// expression. 1678 SourceLocation ColonColonLoc; 1679 1680 /// \brief The location of the '~'. 1681 SourceLocation TildeLoc; 1682 1683 /// \brief The type being destroyed, or its name if we were unable to 1684 /// resolve the name. 1685 PseudoDestructorTypeStorage DestroyedType; 1686 1687 friend class ASTStmtReader; 1688 1689public: 1690 CXXPseudoDestructorExpr(ASTContext &Context, 1691 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1692 NestedNameSpecifierLoc QualifierLoc, 1693 TypeSourceInfo *ScopeType, 1694 SourceLocation ColonColonLoc, 1695 SourceLocation TildeLoc, 1696 PseudoDestructorTypeStorage DestroyedType); 1697 1698 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1699 : Expr(CXXPseudoDestructorExprClass, Shell), 1700 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { } 1701 1702 Expr *getBase() const { return cast<Expr>(Base); } 1703 1704 /// \brief Determines whether this member expression actually had 1705 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1706 /// x->Base::foo. 1707 bool hasQualifier() const { return QualifierLoc; } 1708 1709 /// \brief Retrieves the nested-name-specifier that qualifies the type name, 1710 /// with source-location information. 1711 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 1712 1713 /// \brief If the member name was qualified, retrieves the 1714 /// nested-name-specifier that precedes the member name. Otherwise, returns 1715 /// NULL. 1716 NestedNameSpecifier *getQualifier() const { 1717 return QualifierLoc.getNestedNameSpecifier(); 1718 } 1719 1720 /// \brief Determine whether this pseudo-destructor expression was written 1721 /// using an '->' (otherwise, it used a '.'). 1722 bool isArrow() const { return IsArrow; } 1723 1724 /// \brief Retrieve the location of the '.' or '->' operator. 1725 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1726 1727 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1728 /// expression. 1729 /// 1730 /// Pseudo-destructor expressions can have extra qualification within them 1731 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1732 /// Here, if the object type of the expression is (or may be) a scalar type, 1733 /// \p T may also be a scalar type and, therefore, cannot be part of a 1734 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1735 /// destructor expression. 1736 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1737 1738 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1739 /// expression. 1740 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1741 1742 /// \brief Retrieve the location of the '~'. 1743 SourceLocation getTildeLoc() const { return TildeLoc; } 1744 1745 /// \brief Retrieve the source location information for the type 1746 /// being destroyed. 1747 /// 1748 /// This type-source information is available for non-dependent 1749 /// pseudo-destructor expressions and some dependent pseudo-destructor 1750 /// expressions. Returns NULL if we only have the identifier for a 1751 /// dependent pseudo-destructor expression. 1752 TypeSourceInfo *getDestroyedTypeInfo() const { 1753 return DestroyedType.getTypeSourceInfo(); 1754 } 1755 1756 /// \brief In a dependent pseudo-destructor expression for which we do not 1757 /// have full type information on the destroyed type, provides the name 1758 /// of the destroyed type. 1759 IdentifierInfo *getDestroyedTypeIdentifier() const { 1760 return DestroyedType.getIdentifier(); 1761 } 1762 1763 /// \brief Retrieve the type being destroyed. 1764 QualType getDestroyedType() const; 1765 1766 /// \brief Retrieve the starting location of the type being destroyed. 1767 SourceLocation getDestroyedTypeLoc() const { 1768 return DestroyedType.getLocation(); 1769 } 1770 1771 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1772 /// expression. 1773 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1774 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1775 } 1776 1777 /// \brief Set the destroyed type. 1778 void setDestroyedType(TypeSourceInfo *Info) { 1779 DestroyedType = PseudoDestructorTypeStorage(Info); 1780 } 1781 1782 SourceRange getSourceRange() const; 1783 1784 static bool classof(const Stmt *T) { 1785 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1786 } 1787 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1788 1789 // Iterators 1790 child_range children() { return child_range(&Base, &Base + 1); } 1791}; 1792 1793/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1794/// implementation of TR1/C++0x type trait templates. 1795/// Example: 1796/// __is_pod(int) == true 1797/// __is_enum(std::string) == false 1798class UnaryTypeTraitExpr : public Expr { 1799 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1800 unsigned UTT : 31; 1801 /// The value of the type trait. Unspecified if dependent. 1802 bool Value : 1; 1803 1804 /// Loc - The location of the type trait keyword. 1805 SourceLocation Loc; 1806 1807 /// RParen - The location of the closing paren. 1808 SourceLocation RParen; 1809 1810 /// The type being queried. 1811 TypeSourceInfo *QueriedType; 1812 1813public: 1814 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 1815 TypeSourceInfo *queried, bool value, 1816 SourceLocation rparen, QualType ty) 1817 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1818 false, queried->getType()->isDependentType(), 1819 queried->getType()->isInstantiationDependentType(), 1820 queried->getType()->containsUnexpandedParameterPack()), 1821 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 1822 1823 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1824 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 1825 QueriedType() { } 1826 1827 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1828 1829 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 1830 1831 QualType getQueriedType() const { return QueriedType->getType(); } 1832 1833 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1834 1835 bool getValue() const { return Value; } 1836 1837 static bool classof(const Stmt *T) { 1838 return T->getStmtClass() == UnaryTypeTraitExprClass; 1839 } 1840 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1841 1842 // Iterators 1843 child_range children() { return child_range(); } 1844 1845 friend class ASTStmtReader; 1846}; 1847 1848/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the 1849/// implementation of TR1/C++0x type trait templates. 1850/// Example: 1851/// __is_base_of(Base, Derived) == true 1852class BinaryTypeTraitExpr : public Expr { 1853 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 1854 unsigned BTT : 8; 1855 1856 /// The value of the type trait. Unspecified if dependent. 1857 bool Value : 1; 1858 1859 /// Loc - The location of the type trait keyword. 1860 SourceLocation Loc; 1861 1862 /// RParen - The location of the closing paren. 1863 SourceLocation RParen; 1864 1865 /// The lhs type being queried. 1866 TypeSourceInfo *LhsType; 1867 1868 /// The rhs type being queried. 1869 TypeSourceInfo *RhsType; 1870 1871public: 1872 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1873 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 1874 bool value, SourceLocation rparen, QualType ty) 1875 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 1876 lhsType->getType()->isDependentType() || 1877 rhsType->getType()->isDependentType(), 1878 (lhsType->getType()->isInstantiationDependentType() || 1879 rhsType->getType()->isInstantiationDependentType()), 1880 (lhsType->getType()->containsUnexpandedParameterPack() || 1881 rhsType->getType()->containsUnexpandedParameterPack())), 1882 BTT(btt), Value(value), Loc(loc), RParen(rparen), 1883 LhsType(lhsType), RhsType(rhsType) { } 1884 1885 1886 explicit BinaryTypeTraitExpr(EmptyShell Empty) 1887 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1888 LhsType(), RhsType() { } 1889 1890 SourceRange getSourceRange() const { 1891 return SourceRange(Loc, RParen); 1892 } 1893 1894 BinaryTypeTrait getTrait() const { 1895 return static_cast<BinaryTypeTrait>(BTT); 1896 } 1897 1898 QualType getLhsType() const { return LhsType->getType(); } 1899 QualType getRhsType() const { return RhsType->getType(); } 1900 1901 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 1902 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 1903 1904 bool getValue() const { assert(!isTypeDependent()); return Value; } 1905 1906 static bool classof(const Stmt *T) { 1907 return T->getStmtClass() == BinaryTypeTraitExprClass; 1908 } 1909 static bool classof(const BinaryTypeTraitExpr *) { return true; } 1910 1911 // Iterators 1912 child_range children() { return child_range(); } 1913 1914 friend class ASTStmtReader; 1915}; 1916 1917/// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the 1918/// implementation of __array_rank and __array_extent. 1919/// Example: 1920/// __array_rank(int[10][20]) == 2 1921/// __array_extent(int, 1) == 20 1922class ArrayTypeTraitExpr : public Expr { 1923 virtual void anchor(); 1924 1925 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned. 1926 unsigned ATT : 2; 1927 1928 /// The value of the type trait. Unspecified if dependent. 1929 uint64_t Value; 1930 1931 /// The array dimension being queried, or -1 if not used 1932 Expr *Dimension; 1933 1934 /// Loc - The location of the type trait keyword. 1935 SourceLocation Loc; 1936 1937 /// RParen - The location of the closing paren. 1938 SourceLocation RParen; 1939 1940 /// The type being queried. 1941 TypeSourceInfo *QueriedType; 1942 1943public: 1944 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, 1945 TypeSourceInfo *queried, uint64_t value, 1946 Expr *dimension, SourceLocation rparen, QualType ty) 1947 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1948 false, queried->getType()->isDependentType(), 1949 (queried->getType()->isInstantiationDependentType() || 1950 (dimension && dimension->isInstantiationDependent())), 1951 queried->getType()->containsUnexpandedParameterPack()), 1952 ATT(att), Value(value), Dimension(dimension), 1953 Loc(loc), RParen(rparen), QueriedType(queried) { } 1954 1955 1956 explicit ArrayTypeTraitExpr(EmptyShell Empty) 1957 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false), 1958 QueriedType() { } 1959 1960 virtual ~ArrayTypeTraitExpr() { } 1961 1962 virtual SourceRange getSourceRange() const { 1963 return SourceRange(Loc, RParen); 1964 } 1965 1966 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } 1967 1968 QualType getQueriedType() const { return QueriedType->getType(); } 1969 1970 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1971 1972 uint64_t getValue() const { assert(!isTypeDependent()); return Value; } 1973 1974 Expr *getDimensionExpression() const { return Dimension; } 1975 1976 static bool classof(const Stmt *T) { 1977 return T->getStmtClass() == ArrayTypeTraitExprClass; 1978 } 1979 static bool classof(const ArrayTypeTraitExpr *) { return true; } 1980 1981 // Iterators 1982 child_range children() { return child_range(); } 1983 1984 friend class ASTStmtReader; 1985}; 1986 1987/// ExpressionTraitExpr - An expression trait intrinsic 1988/// Example: 1989/// __is_lvalue_expr(std::cout) == true 1990/// __is_lvalue_expr(1) == false 1991class ExpressionTraitExpr : public Expr { 1992 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned. 1993 unsigned ET : 31; 1994 /// The value of the type trait. Unspecified if dependent. 1995 bool Value : 1; 1996 1997 /// Loc - The location of the type trait keyword. 1998 SourceLocation Loc; 1999 2000 /// RParen - The location of the closing paren. 2001 SourceLocation RParen; 2002 2003 Expr* QueriedExpression; 2004public: 2005 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, 2006 Expr *queried, bool value, 2007 SourceLocation rparen, QualType resultType) 2008 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary, 2009 false, // Not type-dependent 2010 // Value-dependent if the argument is type-dependent. 2011 queried->isTypeDependent(), 2012 queried->isInstantiationDependent(), 2013 queried->containsUnexpandedParameterPack()), 2014 ET(et), Value(value), Loc(loc), RParen(rparen), 2015 QueriedExpression(queried) { } 2016 2017 explicit ExpressionTraitExpr(EmptyShell Empty) 2018 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false), 2019 QueriedExpression() { } 2020 2021 SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 2022 2023 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } 2024 2025 Expr *getQueriedExpression() const { return QueriedExpression; } 2026 2027 bool getValue() const { return Value; } 2028 2029 static bool classof(const Stmt *T) { 2030 return T->getStmtClass() == ExpressionTraitExprClass; 2031 } 2032 static bool classof(const ExpressionTraitExpr *) { return true; } 2033 2034 // Iterators 2035 child_range children() { return child_range(); } 2036 2037 friend class ASTStmtReader; 2038}; 2039 2040 2041/// \brief A reference to an overloaded function set, either an 2042/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 2043class OverloadExpr : public Expr { 2044 /// The results. These are undesugared, which is to say, they may 2045 /// include UsingShadowDecls. Access is relative to the naming 2046 /// class. 2047 // FIXME: Allocate this data after the OverloadExpr subclass. 2048 DeclAccessPair *Results; 2049 unsigned NumResults; 2050 2051 /// The common name of these declarations. 2052 DeclarationNameInfo NameInfo; 2053 2054 /// \brief The nested-name-specifier that qualifies the name, if any. 2055 NestedNameSpecifierLoc QualifierLoc; 2056 2057protected: 2058 /// \brief Whether the name includes info for explicit template 2059 /// keyword and arguments. 2060 bool HasTemplateKWAndArgsInfo; 2061 2062 /// \brief Return the optional template keyword and arguments info. 2063 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below. 2064 2065 /// \brief Return the optional template keyword and arguments info. 2066 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2067 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo(); 2068 } 2069 2070 OverloadExpr(StmtClass K, ASTContext &C, 2071 NestedNameSpecifierLoc QualifierLoc, 2072 SourceLocation TemplateKWLoc, 2073 const DeclarationNameInfo &NameInfo, 2074 const TemplateArgumentListInfo *TemplateArgs, 2075 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2076 bool KnownDependent, 2077 bool KnownInstantiationDependent, 2078 bool KnownContainsUnexpandedParameterPack); 2079 2080 OverloadExpr(StmtClass K, EmptyShell Empty) 2081 : Expr(K, Empty), Results(0), NumResults(0), 2082 QualifierLoc(), HasTemplateKWAndArgsInfo(false) { } 2083 2084 void initializeResults(ASTContext &C, 2085 UnresolvedSetIterator Begin, 2086 UnresolvedSetIterator End); 2087 2088public: 2089 struct FindResult { 2090 OverloadExpr *Expression; 2091 bool IsAddressOfOperand; 2092 bool HasFormOfMemberPointer; 2093 }; 2094 2095 /// Finds the overloaded expression in the given expression of 2096 /// OverloadTy. 2097 /// 2098 /// \return the expression (which must be there) and true if it has 2099 /// the particular form of a member pointer expression 2100 static FindResult find(Expr *E) { 2101 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 2102 2103 FindResult Result; 2104 2105 E = E->IgnoreParens(); 2106 if (isa<UnaryOperator>(E)) { 2107 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 2108 E = cast<UnaryOperator>(E)->getSubExpr(); 2109 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 2110 2111 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 2112 Result.IsAddressOfOperand = true; 2113 Result.Expression = Ovl; 2114 } else { 2115 Result.HasFormOfMemberPointer = false; 2116 Result.IsAddressOfOperand = false; 2117 Result.Expression = cast<OverloadExpr>(E); 2118 } 2119 2120 return Result; 2121 } 2122 2123 /// Gets the naming class of this lookup, if any. 2124 CXXRecordDecl *getNamingClass() const; 2125 2126 typedef UnresolvedSetImpl::iterator decls_iterator; 2127 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 2128 decls_iterator decls_end() const { 2129 return UnresolvedSetIterator(Results + NumResults); 2130 } 2131 2132 /// Gets the number of declarations in the unresolved set. 2133 unsigned getNumDecls() const { return NumResults; } 2134 2135 /// Gets the full name info. 2136 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2137 2138 /// Gets the name looked up. 2139 DeclarationName getName() const { return NameInfo.getName(); } 2140 2141 /// Gets the location of the name. 2142 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 2143 2144 /// Fetches the nested-name qualifier, if one was given. 2145 NestedNameSpecifier *getQualifier() const { 2146 return QualifierLoc.getNestedNameSpecifier(); 2147 } 2148 2149 /// Fetches the nested-name qualifier with source-location information, if 2150 /// one was given. 2151 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2152 2153 /// \brief Retrieve the location of the template keyword preceding 2154 /// this name, if any. 2155 SourceLocation getTemplateKeywordLoc() const { 2156 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2157 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2158 } 2159 2160 /// \brief Retrieve the location of the left angle bracket starting the 2161 /// explicit template argument list following the name, if any. 2162 SourceLocation getLAngleLoc() const { 2163 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2164 return getTemplateKWAndArgsInfo()->LAngleLoc; 2165 } 2166 2167 /// \brief Retrieve the location of the right angle bracket ending the 2168 /// explicit template argument list following the name, if any. 2169 SourceLocation getRAngleLoc() const { 2170 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2171 return getTemplateKWAndArgsInfo()->RAngleLoc; 2172 } 2173 2174 /// Determines whether the name was preceded by the template keyword. 2175 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2176 2177 /// Determines whether this expression had explicit template arguments. 2178 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2179 2180 // Note that, inconsistently with the explicit-template-argument AST 2181 // nodes, users are *forbidden* from calling these methods on objects 2182 // without explicit template arguments. 2183 2184 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2185 assert(hasExplicitTemplateArgs()); 2186 return *getTemplateKWAndArgsInfo(); 2187 } 2188 2189 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2190 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 2191 } 2192 2193 TemplateArgumentLoc const *getTemplateArgs() const { 2194 return getExplicitTemplateArgs().getTemplateArgs(); 2195 } 2196 2197 unsigned getNumTemplateArgs() const { 2198 return getExplicitTemplateArgs().NumTemplateArgs; 2199 } 2200 2201 /// Copies the template arguments into the given structure. 2202 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2203 getExplicitTemplateArgs().copyInto(List); 2204 } 2205 2206 /// \brief Retrieves the optional explicit template arguments. 2207 /// This points to the same data as getExplicitTemplateArgs(), but 2208 /// returns null if there are no explicit template arguments. 2209 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2210 if (!hasExplicitTemplateArgs()) return 0; 2211 return &getExplicitTemplateArgs(); 2212 } 2213 2214 static bool classof(const Stmt *T) { 2215 return T->getStmtClass() == UnresolvedLookupExprClass || 2216 T->getStmtClass() == UnresolvedMemberExprClass; 2217 } 2218 static bool classof(const OverloadExpr *) { return true; } 2219 2220 friend class ASTStmtReader; 2221 friend class ASTStmtWriter; 2222}; 2223 2224/// \brief A reference to a name which we were able to look up during 2225/// parsing but could not resolve to a specific declaration. This 2226/// arises in several ways: 2227/// * we might be waiting for argument-dependent lookup 2228/// * the name might resolve to an overloaded function 2229/// and eventually: 2230/// * the lookup might have included a function template 2231/// These never include UnresolvedUsingValueDecls, which are always 2232/// class members and therefore appear only in 2233/// UnresolvedMemberLookupExprs. 2234class UnresolvedLookupExpr : public OverloadExpr { 2235 /// True if these lookup results should be extended by 2236 /// argument-dependent lookup if this is the operand of a function 2237 /// call. 2238 bool RequiresADL; 2239 2240 /// True if namespace ::std should be considered an associated namespace 2241 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1. 2242 bool StdIsAssociatedNamespace; 2243 2244 /// True if these lookup results are overloaded. This is pretty 2245 /// trivially rederivable if we urgently need to kill this field. 2246 bool Overloaded; 2247 2248 /// The naming class (C++ [class.access.base]p5) of the lookup, if 2249 /// any. This can generally be recalculated from the context chain, 2250 /// but that can be fairly expensive for unqualified lookups. If we 2251 /// want to improve memory use here, this could go in a union 2252 /// against the qualified-lookup bits. 2253 CXXRecordDecl *NamingClass; 2254 2255 UnresolvedLookupExpr(ASTContext &C, 2256 CXXRecordDecl *NamingClass, 2257 NestedNameSpecifierLoc QualifierLoc, 2258 SourceLocation TemplateKWLoc, 2259 const DeclarationNameInfo &NameInfo, 2260 bool RequiresADL, bool Overloaded, 2261 const TemplateArgumentListInfo *TemplateArgs, 2262 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 2263 bool StdIsAssociatedNamespace) 2264 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc, 2265 NameInfo, TemplateArgs, Begin, End, false, false, false), 2266 RequiresADL(RequiresADL), 2267 StdIsAssociatedNamespace(StdIsAssociatedNamespace), 2268 Overloaded(Overloaded), NamingClass(NamingClass) 2269 {} 2270 2271 UnresolvedLookupExpr(EmptyShell Empty) 2272 : OverloadExpr(UnresolvedLookupExprClass, Empty), 2273 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false), 2274 NamingClass(0) 2275 {} 2276 2277 friend class ASTStmtReader; 2278 2279public: 2280 static UnresolvedLookupExpr *Create(ASTContext &C, 2281 CXXRecordDecl *NamingClass, 2282 NestedNameSpecifierLoc QualifierLoc, 2283 const DeclarationNameInfo &NameInfo, 2284 bool ADL, bool Overloaded, 2285 UnresolvedSetIterator Begin, 2286 UnresolvedSetIterator End, 2287 bool StdIsAssociatedNamespace = false) { 2288 assert((ADL || !StdIsAssociatedNamespace) && 2289 "std considered associated namespace when not performing ADL"); 2290 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc, 2291 SourceLocation(), NameInfo, 2292 ADL, Overloaded, 0, Begin, End, 2293 StdIsAssociatedNamespace); 2294 } 2295 2296 static UnresolvedLookupExpr *Create(ASTContext &C, 2297 CXXRecordDecl *NamingClass, 2298 NestedNameSpecifierLoc QualifierLoc, 2299 SourceLocation TemplateKWLoc, 2300 const DeclarationNameInfo &NameInfo, 2301 bool ADL, 2302 const TemplateArgumentListInfo *Args, 2303 UnresolvedSetIterator Begin, 2304 UnresolvedSetIterator End); 2305 2306 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 2307 bool HasTemplateKWAndArgsInfo, 2308 unsigned NumTemplateArgs); 2309 2310 /// True if this declaration should be extended by 2311 /// argument-dependent lookup. 2312 bool requiresADL() const { return RequiresADL; } 2313 2314 /// True if namespace ::std should be artificially added to the set of 2315 /// associated namespaecs for argument-dependent lookup purposes. 2316 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; } 2317 2318 /// True if this lookup is overloaded. 2319 bool isOverloaded() const { return Overloaded; } 2320 2321 /// Gets the 'naming class' (in the sense of C++0x 2322 /// [class.access.base]p5) of the lookup. This is the scope 2323 /// that was looked in to find these results. 2324 CXXRecordDecl *getNamingClass() const { return NamingClass; } 2325 2326 SourceRange getSourceRange() const { 2327 SourceRange Range(getNameInfo().getSourceRange()); 2328 if (getQualifierLoc()) 2329 Range.setBegin(getQualifierLoc().getBeginLoc()); 2330 if (hasExplicitTemplateArgs()) 2331 Range.setEnd(getRAngleLoc()); 2332 return Range; 2333 } 2334 2335 child_range children() { return child_range(); } 2336 2337 static bool classof(const Stmt *T) { 2338 return T->getStmtClass() == UnresolvedLookupExprClass; 2339 } 2340 static bool classof(const UnresolvedLookupExpr *) { return true; } 2341}; 2342 2343/// \brief A qualified reference to a name whose declaration cannot 2344/// yet be resolved. 2345/// 2346/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 2347/// it expresses a reference to a declaration such as 2348/// X<T>::value. The difference, however, is that an 2349/// DependentScopeDeclRefExpr node is used only within C++ templates when 2350/// the qualification (e.g., X<T>::) refers to a dependent type. In 2351/// this case, X<T>::value cannot resolve to a declaration because the 2352/// declaration will differ from on instantiation of X<T> to the 2353/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 2354/// qualifier (X<T>::) and the name of the entity being referenced 2355/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 2356/// declaration can be found. 2357class DependentScopeDeclRefExpr : public Expr { 2358 /// \brief The nested-name-specifier that qualifies this unresolved 2359 /// declaration name. 2360 NestedNameSpecifierLoc QualifierLoc; 2361 2362 /// The name of the entity we will be referencing. 2363 DeclarationNameInfo NameInfo; 2364 2365 /// \brief Whether the name includes info for explicit template 2366 /// keyword and arguments. 2367 bool HasTemplateKWAndArgsInfo; 2368 2369 /// \brief Return the optional template keyword and arguments info. 2370 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2371 if (!HasTemplateKWAndArgsInfo) return 0; 2372 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2373 } 2374 /// \brief Return the optional template keyword and arguments info. 2375 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2376 return const_cast<DependentScopeDeclRefExpr*>(this) 2377 ->getTemplateKWAndArgsInfo(); 2378 } 2379 2380 DependentScopeDeclRefExpr(QualType T, 2381 NestedNameSpecifierLoc QualifierLoc, 2382 SourceLocation TemplateKWLoc, 2383 const DeclarationNameInfo &NameInfo, 2384 const TemplateArgumentListInfo *Args); 2385 2386public: 2387 static DependentScopeDeclRefExpr *Create(ASTContext &C, 2388 NestedNameSpecifierLoc QualifierLoc, 2389 SourceLocation TemplateKWLoc, 2390 const DeclarationNameInfo &NameInfo, 2391 const TemplateArgumentListInfo *TemplateArgs); 2392 2393 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 2394 bool HasTemplateKWAndArgsInfo, 2395 unsigned NumTemplateArgs); 2396 2397 /// \brief Retrieve the name that this expression refers to. 2398 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 2399 2400 /// \brief Retrieve the name that this expression refers to. 2401 DeclarationName getDeclName() const { return NameInfo.getName(); } 2402 2403 /// \brief Retrieve the location of the name within the expression. 2404 SourceLocation getLocation() const { return NameInfo.getLoc(); } 2405 2406 /// \brief Retrieve the nested-name-specifier that qualifies the 2407 /// name, with source location information. 2408 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2409 2410 2411 /// \brief Retrieve the nested-name-specifier that qualifies this 2412 /// declaration. 2413 NestedNameSpecifier *getQualifier() const { 2414 return QualifierLoc.getNestedNameSpecifier(); 2415 } 2416 2417 /// \brief Retrieve the location of the template keyword preceding 2418 /// this name, if any. 2419 SourceLocation getTemplateKeywordLoc() const { 2420 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2421 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2422 } 2423 2424 /// \brief Retrieve the location of the left angle bracket starting the 2425 /// explicit template argument list following the name, if any. 2426 SourceLocation getLAngleLoc() const { 2427 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2428 return getTemplateKWAndArgsInfo()->LAngleLoc; 2429 } 2430 2431 /// \brief Retrieve the location of the right angle bracket ending the 2432 /// explicit template argument list following the name, if any. 2433 SourceLocation getRAngleLoc() const { 2434 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2435 return getTemplateKWAndArgsInfo()->RAngleLoc; 2436 } 2437 2438 /// Determines whether the name was preceded by the template keyword. 2439 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2440 2441 /// Determines whether this lookup had explicit template arguments. 2442 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2443 2444 // Note that, inconsistently with the explicit-template-argument AST 2445 // nodes, users are *forbidden* from calling these methods on objects 2446 // without explicit template arguments. 2447 2448 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2449 assert(hasExplicitTemplateArgs()); 2450 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1); 2451 } 2452 2453 /// Gets a reference to the explicit template argument list. 2454 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2455 assert(hasExplicitTemplateArgs()); 2456 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1); 2457 } 2458 2459 /// \brief Retrieves the optional explicit template arguments. 2460 /// This points to the same data as getExplicitTemplateArgs(), but 2461 /// returns null if there are no explicit template arguments. 2462 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2463 if (!hasExplicitTemplateArgs()) return 0; 2464 return &getExplicitTemplateArgs(); 2465 } 2466 2467 /// \brief Copies the template arguments (if present) into the given 2468 /// structure. 2469 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2470 getExplicitTemplateArgs().copyInto(List); 2471 } 2472 2473 TemplateArgumentLoc const *getTemplateArgs() const { 2474 return getExplicitTemplateArgs().getTemplateArgs(); 2475 } 2476 2477 unsigned getNumTemplateArgs() const { 2478 return getExplicitTemplateArgs().NumTemplateArgs; 2479 } 2480 2481 SourceRange getSourceRange() const { 2482 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation()); 2483 if (hasExplicitTemplateArgs()) 2484 Range.setEnd(getRAngleLoc()); 2485 return Range; 2486 } 2487 2488 static bool classof(const Stmt *T) { 2489 return T->getStmtClass() == DependentScopeDeclRefExprClass; 2490 } 2491 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 2492 2493 child_range children() { return child_range(); } 2494 2495 friend class ASTStmtReader; 2496 friend class ASTStmtWriter; 2497}; 2498 2499/// Represents an expression --- generally a full-expression --- which 2500/// introduces cleanups to be run at the end of the sub-expression's 2501/// evaluation. The most common source of expression-introduced 2502/// cleanups is temporary objects in C++, but several other kinds of 2503/// expressions can create cleanups, including basically every 2504/// call in ARC that returns an Objective-C pointer. 2505/// 2506/// This expression also tracks whether the sub-expression contains a 2507/// potentially-evaluated block literal. The lifetime of a block 2508/// literal is the extent of the enclosing scope. 2509class ExprWithCleanups : public Expr { 2510public: 2511 /// The type of objects that are kept in the cleanup. 2512 /// It's useful to remember the set of blocks; we could also 2513 /// remember the set of temporaries, but there's currently 2514 /// no need. 2515 typedef BlockDecl *CleanupObject; 2516 2517private: 2518 Stmt *SubExpr; 2519 2520 ExprWithCleanups(EmptyShell, unsigned NumObjects); 2521 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects); 2522 2523 CleanupObject *getObjectsBuffer() { 2524 return reinterpret_cast<CleanupObject*>(this + 1); 2525 } 2526 const CleanupObject *getObjectsBuffer() const { 2527 return reinterpret_cast<const CleanupObject*>(this + 1); 2528 } 2529 friend class ASTStmtReader; 2530 2531public: 2532 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty, 2533 unsigned numObjects); 2534 2535 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr, 2536 ArrayRef<CleanupObject> objects); 2537 2538 ArrayRef<CleanupObject> getObjects() const { 2539 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects()); 2540 } 2541 2542 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } 2543 2544 CleanupObject getObject(unsigned i) const { 2545 assert(i < getNumObjects() && "Index out of range"); 2546 return getObjects()[i]; 2547 } 2548 2549 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 2550 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 2551 2552 /// setSubExpr - As with any mutator of the AST, be very careful 2553 /// when modifying an existing AST to preserve its invariants. 2554 void setSubExpr(Expr *E) { SubExpr = E; } 2555 2556 SourceRange getSourceRange() const { 2557 return SubExpr->getSourceRange(); 2558 } 2559 2560 // Implement isa/cast/dyncast/etc. 2561 static bool classof(const Stmt *T) { 2562 return T->getStmtClass() == ExprWithCleanupsClass; 2563 } 2564 static bool classof(const ExprWithCleanups *) { return true; } 2565 2566 // Iterators 2567 child_range children() { return child_range(&SubExpr, &SubExpr + 1); } 2568}; 2569 2570/// \brief Describes an explicit type conversion that uses functional 2571/// notion but could not be resolved because one or more arguments are 2572/// type-dependent. 2573/// 2574/// The explicit type conversions expressed by 2575/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 2576/// where \c T is some type and \c a1, a2, ..., aN are values, and 2577/// either \C T is a dependent type or one or more of the \c a's is 2578/// type-dependent. For example, this would occur in a template such 2579/// as: 2580/// 2581/// \code 2582/// template<typename T, typename A1> 2583/// inline T make_a(const A1& a1) { 2584/// return T(a1); 2585/// } 2586/// \endcode 2587/// 2588/// When the returned expression is instantiated, it may resolve to a 2589/// constructor call, conversion function call, or some kind of type 2590/// conversion. 2591class CXXUnresolvedConstructExpr : public Expr { 2592 /// \brief The type being constructed. 2593 TypeSourceInfo *Type; 2594 2595 /// \brief The location of the left parentheses ('('). 2596 SourceLocation LParenLoc; 2597 2598 /// \brief The location of the right parentheses (')'). 2599 SourceLocation RParenLoc; 2600 2601 /// \brief The number of arguments used to construct the type. 2602 unsigned NumArgs; 2603 2604 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2605 SourceLocation LParenLoc, 2606 Expr **Args, 2607 unsigned NumArgs, 2608 SourceLocation RParenLoc); 2609 2610 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2611 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2612 2613 friend class ASTStmtReader; 2614 2615public: 2616 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2617 TypeSourceInfo *Type, 2618 SourceLocation LParenLoc, 2619 Expr **Args, 2620 unsigned NumArgs, 2621 SourceLocation RParenLoc); 2622 2623 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2624 unsigned NumArgs); 2625 2626 /// \brief Retrieve the type that is being constructed, as specified 2627 /// in the source code. 2628 QualType getTypeAsWritten() const { return Type->getType(); } 2629 2630 /// \brief Retrieve the type source information for the type being 2631 /// constructed. 2632 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2633 2634 /// \brief Retrieve the location of the left parentheses ('(') that 2635 /// precedes the argument list. 2636 SourceLocation getLParenLoc() const { return LParenLoc; } 2637 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2638 2639 /// \brief Retrieve the location of the right parentheses (')') that 2640 /// follows the argument list. 2641 SourceLocation getRParenLoc() const { return RParenLoc; } 2642 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2643 2644 /// \brief Retrieve the number of arguments. 2645 unsigned arg_size() const { return NumArgs; } 2646 2647 typedef Expr** arg_iterator; 2648 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2649 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2650 2651 typedef const Expr* const * const_arg_iterator; 2652 const_arg_iterator arg_begin() const { 2653 return reinterpret_cast<const Expr* const *>(this + 1); 2654 } 2655 const_arg_iterator arg_end() const { 2656 return arg_begin() + NumArgs; 2657 } 2658 2659 Expr *getArg(unsigned I) { 2660 assert(I < NumArgs && "Argument index out-of-range"); 2661 return *(arg_begin() + I); 2662 } 2663 2664 const Expr *getArg(unsigned I) const { 2665 assert(I < NumArgs && "Argument index out-of-range"); 2666 return *(arg_begin() + I); 2667 } 2668 2669 void setArg(unsigned I, Expr *E) { 2670 assert(I < NumArgs && "Argument index out-of-range"); 2671 *(arg_begin() + I) = E; 2672 } 2673 2674 SourceRange getSourceRange() const; 2675 2676 static bool classof(const Stmt *T) { 2677 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2678 } 2679 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2680 2681 // Iterators 2682 child_range children() { 2683 Stmt **begin = reinterpret_cast<Stmt**>(this+1); 2684 return child_range(begin, begin + NumArgs); 2685 } 2686}; 2687 2688/// \brief Represents a C++ member access expression where the actual 2689/// member referenced could not be resolved because the base 2690/// expression or the member name was dependent. 2691/// 2692/// Like UnresolvedMemberExprs, these can be either implicit or 2693/// explicit accesses. It is only possible to get one of these with 2694/// an implicit access if a qualifier is provided. 2695class CXXDependentScopeMemberExpr : public Expr { 2696 /// \brief The expression for the base pointer or class reference, 2697 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2698 Stmt *Base; 2699 2700 /// \brief The type of the base expression. Never null, even for 2701 /// implicit accesses. 2702 QualType BaseType; 2703 2704 /// \brief Whether this member expression used the '->' operator or 2705 /// the '.' operator. 2706 bool IsArrow : 1; 2707 2708 /// \brief Whether this member expression has info for explicit template 2709 /// keyword and arguments. 2710 bool HasTemplateKWAndArgsInfo : 1; 2711 2712 /// \brief The location of the '->' or '.' operator. 2713 SourceLocation OperatorLoc; 2714 2715 /// \brief The nested-name-specifier that precedes the member name, if any. 2716 NestedNameSpecifierLoc QualifierLoc; 2717 2718 /// \brief In a qualified member access expression such as t->Base::f, this 2719 /// member stores the resolves of name lookup in the context of the member 2720 /// access expression, to be used at instantiation time. 2721 /// 2722 /// FIXME: This member, along with the QualifierLoc, could 2723 /// be stuck into a structure that is optionally allocated at the end of 2724 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2725 NamedDecl *FirstQualifierFoundInScope; 2726 2727 /// \brief The member to which this member expression refers, which 2728 /// can be name, overloaded operator, or destructor. 2729 /// FIXME: could also be a template-id 2730 DeclarationNameInfo MemberNameInfo; 2731 2732 /// \brief Return the optional template keyword and arguments info. 2733 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2734 if (!HasTemplateKWAndArgsInfo) return 0; 2735 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1); 2736 } 2737 /// \brief Return the optional template keyword and arguments info. 2738 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2739 return const_cast<CXXDependentScopeMemberExpr*>(this) 2740 ->getTemplateKWAndArgsInfo(); 2741 } 2742 2743 CXXDependentScopeMemberExpr(ASTContext &C, 2744 Expr *Base, QualType BaseType, bool IsArrow, 2745 SourceLocation OperatorLoc, 2746 NestedNameSpecifierLoc QualifierLoc, 2747 SourceLocation TemplateKWLoc, 2748 NamedDecl *FirstQualifierFoundInScope, 2749 DeclarationNameInfo MemberNameInfo, 2750 const TemplateArgumentListInfo *TemplateArgs); 2751 2752public: 2753 CXXDependentScopeMemberExpr(ASTContext &C, 2754 Expr *Base, QualType BaseType, 2755 bool IsArrow, 2756 SourceLocation OperatorLoc, 2757 NestedNameSpecifierLoc QualifierLoc, 2758 NamedDecl *FirstQualifierFoundInScope, 2759 DeclarationNameInfo MemberNameInfo); 2760 2761 static CXXDependentScopeMemberExpr * 2762 Create(ASTContext &C, 2763 Expr *Base, QualType BaseType, bool IsArrow, 2764 SourceLocation OperatorLoc, 2765 NestedNameSpecifierLoc QualifierLoc, 2766 SourceLocation TemplateKWLoc, 2767 NamedDecl *FirstQualifierFoundInScope, 2768 DeclarationNameInfo MemberNameInfo, 2769 const TemplateArgumentListInfo *TemplateArgs); 2770 2771 static CXXDependentScopeMemberExpr * 2772 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 2773 unsigned NumTemplateArgs); 2774 2775 /// \brief True if this is an implicit access, i.e. one in which the 2776 /// member being accessed was not written in the source. The source 2777 /// location of the operator is invalid in this case. 2778 bool isImplicitAccess() const; 2779 2780 /// \brief Retrieve the base object of this member expressions, 2781 /// e.g., the \c x in \c x.m. 2782 Expr *getBase() const { 2783 assert(!isImplicitAccess()); 2784 return cast<Expr>(Base); 2785 } 2786 2787 QualType getBaseType() const { return BaseType; } 2788 2789 /// \brief Determine whether this member expression used the '->' 2790 /// operator; otherwise, it used the '.' operator. 2791 bool isArrow() const { return IsArrow; } 2792 2793 /// \brief Retrieve the location of the '->' or '.' operator. 2794 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2795 2796 /// \brief Retrieve the nested-name-specifier that qualifies the member 2797 /// name. 2798 NestedNameSpecifier *getQualifier() const { 2799 return QualifierLoc.getNestedNameSpecifier(); 2800 } 2801 2802 /// \brief Retrieve the nested-name-specifier that qualifies the member 2803 /// name, with source location information. 2804 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 2805 2806 2807 /// \brief Retrieve the first part of the nested-name-specifier that was 2808 /// found in the scope of the member access expression when the member access 2809 /// was initially parsed. 2810 /// 2811 /// This function only returns a useful result when member access expression 2812 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2813 /// returned by this function describes what was found by unqualified name 2814 /// lookup for the identifier "Base" within the scope of the member access 2815 /// expression itself. At template instantiation time, this information is 2816 /// combined with the results of name lookup into the type of the object 2817 /// expression itself (the class type of x). 2818 NamedDecl *getFirstQualifierFoundInScope() const { 2819 return FirstQualifierFoundInScope; 2820 } 2821 2822 /// \brief Retrieve the name of the member that this expression 2823 /// refers to. 2824 const DeclarationNameInfo &getMemberNameInfo() const { 2825 return MemberNameInfo; 2826 } 2827 2828 /// \brief Retrieve the name of the member that this expression 2829 /// refers to. 2830 DeclarationName getMember() const { return MemberNameInfo.getName(); } 2831 2832 // \brief Retrieve the location of the name of the member that this 2833 // expression refers to. 2834 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 2835 2836 /// \brief Retrieve the location of the template keyword preceding the 2837 /// member name, if any. 2838 SourceLocation getTemplateKeywordLoc() const { 2839 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2840 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2841 } 2842 2843 /// \brief Retrieve the location of the left angle bracket starting the 2844 /// explicit template argument list following the member name, if any. 2845 SourceLocation getLAngleLoc() const { 2846 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2847 return getTemplateKWAndArgsInfo()->LAngleLoc; 2848 } 2849 2850 /// \brief Retrieve the location of the right angle bracket ending the 2851 /// explicit template argument list following the member name, if any. 2852 SourceLocation getRAngleLoc() const { 2853 if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2854 return getTemplateKWAndArgsInfo()->RAngleLoc; 2855 } 2856 2857 /// Determines whether the member name was preceded by the template keyword. 2858 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2859 2860 /// \brief Determines whether this member expression actually had a C++ 2861 /// template argument list explicitly specified, e.g., x.f<int>. 2862 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2863 2864 /// \brief Retrieve the explicit template argument list that followed the 2865 /// member template name, if any. 2866 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2867 assert(hasExplicitTemplateArgs()); 2868 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 2869 } 2870 2871 /// \brief Retrieve the explicit template argument list that followed the 2872 /// member template name, if any. 2873 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2874 return const_cast<CXXDependentScopeMemberExpr *>(this) 2875 ->getExplicitTemplateArgs(); 2876 } 2877 2878 /// \brief Retrieves the optional explicit template arguments. 2879 /// This points to the same data as getExplicitTemplateArgs(), but 2880 /// returns null if there are no explicit template arguments. 2881 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() { 2882 if (!hasExplicitTemplateArgs()) return 0; 2883 return &getExplicitTemplateArgs(); 2884 } 2885 2886 /// \brief Copies the template arguments (if present) into the given 2887 /// structure. 2888 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2889 getExplicitTemplateArgs().copyInto(List); 2890 } 2891 2892 /// \brief Initializes the template arguments using the given structure. 2893 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2894 getExplicitTemplateArgs().initializeFrom(List); 2895 } 2896 2897 /// \brief Retrieve the template arguments provided as part of this 2898 /// template-id. 2899 const TemplateArgumentLoc *getTemplateArgs() const { 2900 return getExplicitTemplateArgs().getTemplateArgs(); 2901 } 2902 2903 /// \brief Retrieve the number of template arguments provided as part of this 2904 /// template-id. 2905 unsigned getNumTemplateArgs() const { 2906 return getExplicitTemplateArgs().NumTemplateArgs; 2907 } 2908 2909 SourceRange getSourceRange() const { 2910 SourceRange Range; 2911 if (!isImplicitAccess()) 2912 Range.setBegin(Base->getSourceRange().getBegin()); 2913 else if (getQualifier()) 2914 Range.setBegin(getQualifierLoc().getBeginLoc()); 2915 else 2916 Range.setBegin(MemberNameInfo.getBeginLoc()); 2917 2918 if (hasExplicitTemplateArgs()) 2919 Range.setEnd(getRAngleLoc()); 2920 else 2921 Range.setEnd(MemberNameInfo.getEndLoc()); 2922 return Range; 2923 } 2924 2925 static bool classof(const Stmt *T) { 2926 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2927 } 2928 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2929 2930 // Iterators 2931 child_range children() { 2932 if (isImplicitAccess()) return child_range(); 2933 return child_range(&Base, &Base + 1); 2934 } 2935 2936 friend class ASTStmtReader; 2937 friend class ASTStmtWriter; 2938}; 2939 2940/// \brief Represents a C++ member access expression for which lookup 2941/// produced a set of overloaded functions. 2942/// 2943/// The member access may be explicit or implicit: 2944/// struct A { 2945/// int a, b; 2946/// int explicitAccess() { return this->a + this->A::b; } 2947/// int implicitAccess() { return a + A::b; } 2948/// }; 2949/// 2950/// In the final AST, an explicit access always becomes a MemberExpr. 2951/// An implicit access may become either a MemberExpr or a 2952/// DeclRefExpr, depending on whether the member is static. 2953class UnresolvedMemberExpr : public OverloadExpr { 2954 /// \brief Whether this member expression used the '->' operator or 2955 /// the '.' operator. 2956 bool IsArrow : 1; 2957 2958 /// \brief Whether the lookup results contain an unresolved using 2959 /// declaration. 2960 bool HasUnresolvedUsing : 1; 2961 2962 /// \brief The expression for the base pointer or class reference, 2963 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2964 /// member expression 2965 Stmt *Base; 2966 2967 /// \brief The type of the base expression; never null. 2968 QualType BaseType; 2969 2970 /// \brief The location of the '->' or '.' operator. 2971 SourceLocation OperatorLoc; 2972 2973 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 2974 Expr *Base, QualType BaseType, bool IsArrow, 2975 SourceLocation OperatorLoc, 2976 NestedNameSpecifierLoc QualifierLoc, 2977 SourceLocation TemplateKWLoc, 2978 const DeclarationNameInfo &MemberNameInfo, 2979 const TemplateArgumentListInfo *TemplateArgs, 2980 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2981 2982 UnresolvedMemberExpr(EmptyShell Empty) 2983 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2984 HasUnresolvedUsing(false), Base(0) { } 2985 2986 friend class ASTStmtReader; 2987 2988public: 2989 static UnresolvedMemberExpr * 2990 Create(ASTContext &C, bool HasUnresolvedUsing, 2991 Expr *Base, QualType BaseType, bool IsArrow, 2992 SourceLocation OperatorLoc, 2993 NestedNameSpecifierLoc QualifierLoc, 2994 SourceLocation TemplateKWLoc, 2995 const DeclarationNameInfo &MemberNameInfo, 2996 const TemplateArgumentListInfo *TemplateArgs, 2997 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2998 2999 static UnresolvedMemberExpr * 3000 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo, 3001 unsigned NumTemplateArgs); 3002 3003 /// \brief True if this is an implicit access, i.e. one in which the 3004 /// member being accessed was not written in the source. The source 3005 /// location of the operator is invalid in this case. 3006 bool isImplicitAccess() const; 3007 3008 /// \brief Retrieve the base object of this member expressions, 3009 /// e.g., the \c x in \c x.m. 3010 Expr *getBase() { 3011 assert(!isImplicitAccess()); 3012 return cast<Expr>(Base); 3013 } 3014 const Expr *getBase() const { 3015 assert(!isImplicitAccess()); 3016 return cast<Expr>(Base); 3017 } 3018 3019 QualType getBaseType() const { return BaseType; } 3020 3021 /// \brief Determine whether the lookup results contain an unresolved using 3022 /// declaration. 3023 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 3024 3025 /// \brief Determine whether this member expression used the '->' 3026 /// operator; otherwise, it used the '.' operator. 3027 bool isArrow() const { return IsArrow; } 3028 3029 /// \brief Retrieve the location of the '->' or '.' operator. 3030 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3031 3032 /// \brief Retrieves the naming class of this lookup. 3033 CXXRecordDecl *getNamingClass() const; 3034 3035 /// \brief Retrieve the full name info for the member that this expression 3036 /// refers to. 3037 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 3038 3039 /// \brief Retrieve the name of the member that this expression 3040 /// refers to. 3041 DeclarationName getMemberName() const { return getName(); } 3042 3043 // \brief Retrieve the location of the name of the member that this 3044 // expression refers to. 3045 SourceLocation getMemberLoc() const { return getNameLoc(); } 3046 3047 SourceRange getSourceRange() const { 3048 SourceRange Range = getMemberNameInfo().getSourceRange(); 3049 if (!isImplicitAccess()) 3050 Range.setBegin(Base->getSourceRange().getBegin()); 3051 else if (getQualifierLoc()) 3052 Range.setBegin(getQualifierLoc().getBeginLoc()); 3053 3054 if (hasExplicitTemplateArgs()) 3055 Range.setEnd(getRAngleLoc()); 3056 return Range; 3057 } 3058 3059 static bool classof(const Stmt *T) { 3060 return T->getStmtClass() == UnresolvedMemberExprClass; 3061 } 3062 static bool classof(const UnresolvedMemberExpr *) { return true; } 3063 3064 // Iterators 3065 child_range children() { 3066 if (isImplicitAccess()) return child_range(); 3067 return child_range(&Base, &Base + 1); 3068 } 3069}; 3070 3071/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 3072/// 3073/// The noexcept expression tests whether a given expression might throw. Its 3074/// result is a boolean constant. 3075class CXXNoexceptExpr : public Expr { 3076 bool Value : 1; 3077 Stmt *Operand; 3078 SourceRange Range; 3079 3080 friend class ASTStmtReader; 3081 3082public: 3083 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 3084 SourceLocation Keyword, SourceLocation RParen) 3085 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 3086 /*TypeDependent*/false, 3087 /*ValueDependent*/Val == CT_Dependent, 3088 Val == CT_Dependent || Operand->isInstantiationDependent(), 3089 Operand->containsUnexpandedParameterPack()), 3090 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 3091 { } 3092 3093 CXXNoexceptExpr(EmptyShell Empty) 3094 : Expr(CXXNoexceptExprClass, Empty) 3095 { } 3096 3097 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 3098 3099 SourceRange getSourceRange() const { return Range; } 3100 3101 bool getValue() const { return Value; } 3102 3103 static bool classof(const Stmt *T) { 3104 return T->getStmtClass() == CXXNoexceptExprClass; 3105 } 3106 static bool classof(const CXXNoexceptExpr *) { return true; } 3107 3108 // Iterators 3109 child_range children() { return child_range(&Operand, &Operand + 1); } 3110}; 3111 3112/// \brief Represents a C++0x pack expansion that produces a sequence of 3113/// expressions. 3114/// 3115/// A pack expansion expression contains a pattern (which itself is an 3116/// expression) followed by an ellipsis. For example: 3117/// 3118/// \code 3119/// template<typename F, typename ...Types> 3120/// void forward(F f, Types &&...args) { 3121/// f(static_cast<Types&&>(args)...); 3122/// } 3123/// \endcode 3124/// 3125/// Here, the argument to the function object \c f is a pack expansion whose 3126/// pattern is \c static_cast<Types&&>(args). When the \c forward function 3127/// template is instantiated, the pack expansion will instantiate to zero or 3128/// or more function arguments to the function object \c f. 3129class PackExpansionExpr : public Expr { 3130 SourceLocation EllipsisLoc; 3131 3132 /// \brief The number of expansions that will be produced by this pack 3133 /// expansion expression, if known. 3134 /// 3135 /// When zero, the number of expansions is not known. Otherwise, this value 3136 /// is the number of expansions + 1. 3137 unsigned NumExpansions; 3138 3139 Stmt *Pattern; 3140 3141 friend class ASTStmtReader; 3142 friend class ASTStmtWriter; 3143 3144public: 3145 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, 3146 llvm::Optional<unsigned> NumExpansions) 3147 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 3148 Pattern->getObjectKind(), /*TypeDependent=*/true, 3149 /*ValueDependent=*/true, /*InstantiationDependent=*/true, 3150 /*ContainsUnexpandedParameterPack=*/false), 3151 EllipsisLoc(EllipsisLoc), 3152 NumExpansions(NumExpansions? *NumExpansions + 1 : 0), 3153 Pattern(Pattern) { } 3154 3155 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 3156 3157 /// \brief Retrieve the pattern of the pack expansion. 3158 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 3159 3160 /// \brief Retrieve the pattern of the pack expansion. 3161 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 3162 3163 /// \brief Retrieve the location of the ellipsis that describes this pack 3164 /// expansion. 3165 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 3166 3167 /// \brief Determine the number of expansions that will be produced when 3168 /// this pack expansion is instantiated, if already known. 3169 llvm::Optional<unsigned> getNumExpansions() const { 3170 if (NumExpansions) 3171 return NumExpansions - 1; 3172 3173 return llvm::Optional<unsigned>(); 3174 } 3175 3176 SourceRange getSourceRange() const { 3177 return SourceRange(Pattern->getLocStart(), EllipsisLoc); 3178 } 3179 3180 static bool classof(const Stmt *T) { 3181 return T->getStmtClass() == PackExpansionExprClass; 3182 } 3183 static bool classof(const PackExpansionExpr *) { return true; } 3184 3185 // Iterators 3186 child_range children() { 3187 return child_range(&Pattern, &Pattern + 1); 3188 } 3189}; 3190 3191inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() { 3192 if (!HasTemplateKWAndArgsInfo) return 0; 3193 if (isa<UnresolvedLookupExpr>(this)) 3194 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3195 (cast<UnresolvedLookupExpr>(this) + 1); 3196 else 3197 return reinterpret_cast<ASTTemplateKWAndArgsInfo*> 3198 (cast<UnresolvedMemberExpr>(this) + 1); 3199} 3200 3201/// \brief Represents an expression that computes the length of a parameter 3202/// pack. 3203/// 3204/// \code 3205/// template<typename ...Types> 3206/// struct count { 3207/// static const unsigned value = sizeof...(Types); 3208/// }; 3209/// \endcode 3210class SizeOfPackExpr : public Expr { 3211 /// \brief The location of the 'sizeof' keyword. 3212 SourceLocation OperatorLoc; 3213 3214 /// \brief The location of the name of the parameter pack. 3215 SourceLocation PackLoc; 3216 3217 /// \brief The location of the closing parenthesis. 3218 SourceLocation RParenLoc; 3219 3220 /// \brief The length of the parameter pack, if known. 3221 /// 3222 /// When this expression is value-dependent, the length of the parameter pack 3223 /// is unknown. When this expression is not value-dependent, the length is 3224 /// known. 3225 unsigned Length; 3226 3227 /// \brief The parameter pack itself. 3228 NamedDecl *Pack; 3229 3230 friend class ASTStmtReader; 3231 friend class ASTStmtWriter; 3232 3233public: 3234 /// \brief Creates a value-dependent expression that computes the length of 3235 /// the given parameter pack. 3236 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3237 SourceLocation PackLoc, SourceLocation RParenLoc) 3238 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3239 /*TypeDependent=*/false, /*ValueDependent=*/true, 3240 /*InstantiationDependent=*/true, 3241 /*ContainsUnexpandedParameterPack=*/false), 3242 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3243 Length(0), Pack(Pack) { } 3244 3245 /// \brief Creates an expression that computes the length of 3246 /// the given parameter pack, which is already known. 3247 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, 3248 SourceLocation PackLoc, SourceLocation RParenLoc, 3249 unsigned Length) 3250 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary, 3251 /*TypeDependent=*/false, /*ValueDependent=*/false, 3252 /*InstantiationDependent=*/false, 3253 /*ContainsUnexpandedParameterPack=*/false), 3254 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), 3255 Length(Length), Pack(Pack) { } 3256 3257 /// \brief Create an empty expression. 3258 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { } 3259 3260 /// \brief Determine the location of the 'sizeof' keyword. 3261 SourceLocation getOperatorLoc() const { return OperatorLoc; } 3262 3263 /// \brief Determine the location of the parameter pack. 3264 SourceLocation getPackLoc() const { return PackLoc; } 3265 3266 /// \brief Determine the location of the right parenthesis. 3267 SourceLocation getRParenLoc() const { return RParenLoc; } 3268 3269 /// \brief Retrieve the parameter pack. 3270 NamedDecl *getPack() const { return Pack; } 3271 3272 /// \brief Retrieve the length of the parameter pack. 3273 /// 3274 /// This routine may only be invoked when the expression is not 3275 /// value-dependent. 3276 unsigned getPackLength() const { 3277 assert(!isValueDependent() && 3278 "Cannot get the length of a value-dependent pack size expression"); 3279 return Length; 3280 } 3281 3282 SourceRange getSourceRange() const { 3283 return SourceRange(OperatorLoc, RParenLoc); 3284 } 3285 3286 static bool classof(const Stmt *T) { 3287 return T->getStmtClass() == SizeOfPackExprClass; 3288 } 3289 static bool classof(const SizeOfPackExpr *) { return true; } 3290 3291 // Iterators 3292 child_range children() { return child_range(); } 3293}; 3294 3295/// \brief Represents a reference to a non-type template parameter 3296/// that has been substituted with a template argument. 3297class SubstNonTypeTemplateParmExpr : public Expr { 3298 /// \brief The replaced parameter. 3299 NonTypeTemplateParmDecl *Param; 3300 3301 /// \brief The replacement expression. 3302 Stmt *Replacement; 3303 3304 /// \brief The location of the non-type template parameter reference. 3305 SourceLocation NameLoc; 3306 3307 friend class ASTReader; 3308 friend class ASTStmtReader; 3309 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) 3310 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { } 3311 3312public: 3313 SubstNonTypeTemplateParmExpr(QualType type, 3314 ExprValueKind valueKind, 3315 SourceLocation loc, 3316 NonTypeTemplateParmDecl *param, 3317 Expr *replacement) 3318 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary, 3319 replacement->isTypeDependent(), replacement->isValueDependent(), 3320 replacement->isInstantiationDependent(), 3321 replacement->containsUnexpandedParameterPack()), 3322 Param(param), Replacement(replacement), NameLoc(loc) {} 3323 3324 SourceLocation getNameLoc() const { return NameLoc; } 3325 SourceRange getSourceRange() const { return NameLoc; } 3326 3327 Expr *getReplacement() const { return cast<Expr>(Replacement); } 3328 3329 NonTypeTemplateParmDecl *getParameter() const { return Param; } 3330 3331 static bool classof(const Stmt *s) { 3332 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; 3333 } 3334 static bool classof(const SubstNonTypeTemplateParmExpr *) { 3335 return true; 3336 } 3337 3338 // Iterators 3339 child_range children() { return child_range(&Replacement, &Replacement+1); } 3340}; 3341 3342/// \brief Represents a reference to a non-type template parameter pack that 3343/// has been substituted with a non-template argument pack. 3344/// 3345/// When a pack expansion in the source code contains multiple parameter packs 3346/// and those parameter packs correspond to different levels of template 3347/// parameter lists, this node node is used to represent a non-type template 3348/// parameter pack from an outer level, which has already had its argument pack 3349/// substituted but that still lives within a pack expansion that itself 3350/// could not be instantiated. When actually performing a substitution into 3351/// that pack expansion (e.g., when all template parameters have corresponding 3352/// arguments), this type will be replaced with the appropriate underlying 3353/// expression at the current pack substitution index. 3354class SubstNonTypeTemplateParmPackExpr : public Expr { 3355 /// \brief The non-type template parameter pack itself. 3356 NonTypeTemplateParmDecl *Param; 3357 3358 /// \brief A pointer to the set of template arguments that this 3359 /// parameter pack is instantiated with. 3360 const TemplateArgument *Arguments; 3361 3362 /// \brief The number of template arguments in \c Arguments. 3363 unsigned NumArguments; 3364 3365 /// \brief The location of the non-type template parameter pack reference. 3366 SourceLocation NameLoc; 3367 3368 friend class ASTReader; 3369 friend class ASTStmtReader; 3370 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) 3371 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { } 3372 3373public: 3374 SubstNonTypeTemplateParmPackExpr(QualType T, 3375 NonTypeTemplateParmDecl *Param, 3376 SourceLocation NameLoc, 3377 const TemplateArgument &ArgPack); 3378 3379 /// \brief Retrieve the non-type template parameter pack being substituted. 3380 NonTypeTemplateParmDecl *getParameterPack() const { return Param; } 3381 3382 /// \brief Retrieve the location of the parameter pack name. 3383 SourceLocation getParameterPackLocation() const { return NameLoc; } 3384 3385 /// \brief Retrieve the template argument pack containing the substituted 3386 /// template arguments. 3387 TemplateArgument getArgumentPack() const; 3388 3389 SourceRange getSourceRange() const { return NameLoc; } 3390 3391 static bool classof(const Stmt *T) { 3392 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; 3393 } 3394 static bool classof(const SubstNonTypeTemplateParmPackExpr *) { 3395 return true; 3396 } 3397 3398 // Iterators 3399 child_range children() { return child_range(); } 3400}; 3401 3402/// \brief Represents a prvalue temporary that written into memory so that 3403/// a reference can bind to it. 3404/// 3405/// Prvalue expressions are materialized when they need to have an address 3406/// in memory for a reference to bind to. This happens when binding a 3407/// reference to the result of a conversion, e.g., 3408/// 3409/// \code 3410/// const int &r = 1.0; 3411/// \endcode 3412/// 3413/// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is 3414/// then materialized via a \c MaterializeTemporaryExpr, and the reference 3415/// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues 3416/// (either an lvalue or an xvalue, depending on the kind of reference binding 3417/// to it), maintaining the invariant that references always bind to glvalues. 3418class MaterializeTemporaryExpr : public Expr { 3419 /// \brief The temporary-generating expression whose value will be 3420 /// materialized. 3421 Stmt *Temporary; 3422 3423 friend class ASTStmtReader; 3424 friend class ASTStmtWriter; 3425 3426public: 3427 MaterializeTemporaryExpr(QualType T, Expr *Temporary, 3428 bool BoundToLvalueReference) 3429 : Expr(MaterializeTemporaryExprClass, T, 3430 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary, 3431 Temporary->isTypeDependent(), Temporary->isValueDependent(), 3432 Temporary->isInstantiationDependent(), 3433 Temporary->containsUnexpandedParameterPack()), 3434 Temporary(Temporary) { } 3435 3436 MaterializeTemporaryExpr(EmptyShell Empty) 3437 : Expr(MaterializeTemporaryExprClass, Empty) { } 3438 3439 /// \brief Retrieve the temporary-generating subexpression whose value will 3440 /// be materialized into a glvalue. 3441 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); } 3442 3443 /// \brief Determine whether this materialized temporary is bound to an 3444 /// lvalue reference; otherwise, it's bound to an rvalue reference. 3445 bool isBoundToLvalueReference() const { 3446 return getValueKind() == VK_LValue; 3447 } 3448 3449 SourceRange getSourceRange() const { return Temporary->getSourceRange(); } 3450 3451 static bool classof(const Stmt *T) { 3452 return T->getStmtClass() == MaterializeTemporaryExprClass; 3453 } 3454 static bool classof(const MaterializeTemporaryExpr *) { 3455 return true; 3456 } 3457 3458 // Iterators 3459 child_range children() { return child_range(&Temporary, &Temporary + 1); } 3460}; 3461 3462} // end namespace clang 3463 3464#endif 3465