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