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