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