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