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