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