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