ExprCXX.h revision 6d00c1365dd3601f6d93bbda9162913c57ae788f
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 // Was the form (type-id) used? Otherwise, it was new-type-id. 926 bool ParenTypeId : 1; 927 // Is there an initializer? If not, built-ins are uninitialized, else they're 928 // value-initialized. 929 bool Initializer : 1; 930 // Do we allocate an array? If so, the first SubExpr is the size expression. 931 bool Array : 1; 932 // The number of placement new arguments. 933 unsigned NumPlacementArgs : 14; 934 // The number of constructor arguments. This may be 1 even for non-class 935 // types; use the pseudo copy constructor. 936 unsigned NumConstructorArgs : 14; 937 // Contains an optional array size expression, any number of optional 938 // placement arguments, and any number of optional constructor arguments, 939 // in that order. 940 Stmt **SubExprs; 941 // Points to the allocation function used. 942 FunctionDecl *OperatorNew; 943 // Points to the deallocation function used in case of error. May be null. 944 FunctionDecl *OperatorDelete; 945 // Points to the constructor used. Cannot be null if AllocType is a record; 946 // it would still point at the default constructor (even an implicit one). 947 // Must be null for all other types. 948 CXXConstructorDecl *Constructor; 949 950 SourceLocation StartLoc; 951 SourceLocation EndLoc; 952 953public: 954 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, 955 Expr **placementArgs, unsigned numPlaceArgs, bool ParenTypeId, 956 Expr *arraySize, CXXConstructorDecl *constructor, bool initializer, 957 Expr **constructorArgs, unsigned numConsArgs, 958 FunctionDecl *operatorDelete, QualType ty, 959 SourceLocation startLoc, SourceLocation endLoc); 960 explicit CXXNewExpr(EmptyShell Shell) 961 : Expr(CXXNewExprClass, Shell), SubExprs(0) { } 962 963 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs, 964 unsigned numConsArgs); 965 966 virtual void DoDestroy(ASTContext &C); 967 968 QualType getAllocatedType() const { 969 assert(getType()->isPointerType()); 970 return getType()->getAs<PointerType>()->getPointeeType(); 971 } 972 973 FunctionDecl *getOperatorNew() const { return OperatorNew; } 974 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } 975 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 976 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 977 CXXConstructorDecl *getConstructor() const { return Constructor; } 978 void setConstructor(CXXConstructorDecl *D) { Constructor = D; } 979 980 bool isArray() const { return Array; } 981 Expr *getArraySize() { 982 return Array ? cast<Expr>(SubExprs[0]) : 0; 983 } 984 const Expr *getArraySize() const { 985 return Array ? cast<Expr>(SubExprs[0]) : 0; 986 } 987 988 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 989 Expr *getPlacementArg(unsigned i) { 990 assert(i < NumPlacementArgs && "Index out of range"); 991 return cast<Expr>(SubExprs[Array + i]); 992 } 993 const Expr *getPlacementArg(unsigned i) const { 994 assert(i < NumPlacementArgs && "Index out of range"); 995 return cast<Expr>(SubExprs[Array + i]); 996 } 997 998 bool isGlobalNew() const { return GlobalNew; } 999 void setGlobalNew(bool V) { GlobalNew = V; } 1000 bool isParenTypeId() const { return ParenTypeId; } 1001 void setParenTypeId(bool V) { ParenTypeId = V; } 1002 bool hasInitializer() const { return Initializer; } 1003 void setHasInitializer(bool V) { Initializer = V; } 1004 1005 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 1006 Expr *getConstructorArg(unsigned i) { 1007 assert(i < NumConstructorArgs && "Index out of range"); 1008 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1009 } 1010 const Expr *getConstructorArg(unsigned i) const { 1011 assert(i < NumConstructorArgs && "Index out of range"); 1012 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1013 } 1014 1015 typedef ExprIterator arg_iterator; 1016 typedef ConstExprIterator const_arg_iterator; 1017 1018 arg_iterator placement_arg_begin() { 1019 return SubExprs + Array; 1020 } 1021 arg_iterator placement_arg_end() { 1022 return SubExprs + Array + getNumPlacementArgs(); 1023 } 1024 const_arg_iterator placement_arg_begin() const { 1025 return SubExprs + Array; 1026 } 1027 const_arg_iterator placement_arg_end() const { 1028 return SubExprs + Array + getNumPlacementArgs(); 1029 } 1030 1031 arg_iterator constructor_arg_begin() { 1032 return SubExprs + Array + getNumPlacementArgs(); 1033 } 1034 arg_iterator constructor_arg_end() { 1035 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1036 } 1037 const_arg_iterator constructor_arg_begin() const { 1038 return SubExprs + Array + getNumPlacementArgs(); 1039 } 1040 const_arg_iterator constructor_arg_end() const { 1041 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1042 } 1043 1044 typedef Stmt **raw_arg_iterator; 1045 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1046 raw_arg_iterator raw_arg_end() { 1047 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1048 } 1049 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1050 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } 1051 1052 1053 SourceLocation getStartLoc() const { return StartLoc; } 1054 void setStartLoc(SourceLocation L) { StartLoc = L; } 1055 SourceLocation getEndLoc() const { return EndLoc; } 1056 void setEndLoc(SourceLocation L) { EndLoc = L; } 1057 1058 virtual SourceRange getSourceRange() const { 1059 return SourceRange(StartLoc, EndLoc); 1060 } 1061 1062 static bool classof(const Stmt *T) { 1063 return T->getStmtClass() == CXXNewExprClass; 1064 } 1065 static bool classof(const CXXNewExpr *) { return true; } 1066 1067 // Iterators 1068 virtual child_iterator child_begin(); 1069 virtual child_iterator child_end(); 1070}; 1071 1072/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 1073/// calls, e.g. "delete[] pArray". 1074class CXXDeleteExpr : public Expr { 1075 // Is this a forced global delete, i.e. "::delete"? 1076 bool GlobalDelete : 1; 1077 // Is this the array form of delete, i.e. "delete[]"? 1078 bool ArrayForm : 1; 1079 // Points to the operator delete overload that is used. Could be a member. 1080 FunctionDecl *OperatorDelete; 1081 // The pointer expression to be deleted. 1082 Stmt *Argument; 1083 // Location of the expression. 1084 SourceLocation Loc; 1085public: 1086 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1087 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 1088 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 1089 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 1090 Loc(loc) { } 1091 explicit CXXDeleteExpr(EmptyShell Shell) 1092 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1093 1094 bool isGlobalDelete() const { return GlobalDelete; } 1095 bool isArrayForm() const { return ArrayForm; } 1096 1097 void setGlobalDelete(bool V) { GlobalDelete = V; } 1098 void setArrayForm(bool V) { ArrayForm = V; } 1099 1100 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1101 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } 1102 1103 Expr *getArgument() { return cast<Expr>(Argument); } 1104 const Expr *getArgument() const { return cast<Expr>(Argument); } 1105 void setArgument(Expr *E) { Argument = E; } 1106 1107 virtual SourceRange getSourceRange() const { 1108 return SourceRange(Loc, Argument->getLocEnd()); 1109 } 1110 void setStartLoc(SourceLocation L) { Loc = L; } 1111 1112 static bool classof(const Stmt *T) { 1113 return T->getStmtClass() == CXXDeleteExprClass; 1114 } 1115 static bool classof(const CXXDeleteExpr *) { return true; } 1116 1117 // Iterators 1118 virtual child_iterator child_begin(); 1119 virtual child_iterator child_end(); 1120}; 1121 1122/// \brief Structure used to store the type being destroyed by a 1123/// pseudo-destructor expression. 1124class PseudoDestructorTypeStorage { 1125 /// \brief Either the type source information or the name of the type, if 1126 /// it couldn't be resolved due to type-dependence. 1127 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1128 1129 /// \brief The starting source location of the pseudo-destructor type. 1130 SourceLocation Location; 1131 1132public: 1133 PseudoDestructorTypeStorage() { } 1134 1135 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1136 : Type(II), Location(Loc) { } 1137 1138 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1139 1140 TypeSourceInfo *getTypeSourceInfo() const { 1141 return Type.dyn_cast<TypeSourceInfo *>(); 1142 } 1143 1144 IdentifierInfo *getIdentifier() const { 1145 return Type.dyn_cast<IdentifierInfo *>(); 1146 } 1147 1148 SourceLocation getLocation() const { return Location; } 1149}; 1150 1151/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1152/// 1153/// A pseudo-destructor is an expression that looks like a member access to a 1154/// destructor of a scalar type, except that scalar types don't have 1155/// destructors. For example: 1156/// 1157/// \code 1158/// typedef int T; 1159/// void f(int *p) { 1160/// p->T::~T(); 1161/// } 1162/// \endcode 1163/// 1164/// Pseudo-destructors typically occur when instantiating templates such as: 1165/// 1166/// \code 1167/// template<typename T> 1168/// void destroy(T* ptr) { 1169/// ptr->T::~T(); 1170/// } 1171/// \endcode 1172/// 1173/// for scalar types. A pseudo-destructor expression has no run-time semantics 1174/// beyond evaluating the base expression. 1175class CXXPseudoDestructorExpr : public Expr { 1176 /// \brief The base expression (that is being destroyed). 1177 Stmt *Base; 1178 1179 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1180 /// period ('.'). 1181 bool IsArrow : 1; 1182 1183 /// \brief The location of the '.' or '->' operator. 1184 SourceLocation OperatorLoc; 1185 1186 /// \brief The nested-name-specifier that follows the operator, if present. 1187 NestedNameSpecifier *Qualifier; 1188 1189 /// \brief The source range that covers the nested-name-specifier, if 1190 /// present. 1191 SourceRange QualifierRange; 1192 1193 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1194 /// expression. 1195 TypeSourceInfo *ScopeType; 1196 1197 /// \brief The location of the '::' in a qualified pseudo-destructor 1198 /// expression. 1199 SourceLocation ColonColonLoc; 1200 1201 /// \brief The location of the '~'. 1202 SourceLocation TildeLoc; 1203 1204 /// \brief The type being destroyed, or its name if we were unable to 1205 /// resolve the name. 1206 PseudoDestructorTypeStorage DestroyedType; 1207 1208public: 1209 CXXPseudoDestructorExpr(ASTContext &Context, 1210 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1211 NestedNameSpecifier *Qualifier, 1212 SourceRange QualifierRange, 1213 TypeSourceInfo *ScopeType, 1214 SourceLocation ColonColonLoc, 1215 SourceLocation TildeLoc, 1216 PseudoDestructorTypeStorage DestroyedType) 1217 : Expr(CXXPseudoDestructorExprClass, 1218 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 1219 false, 0, false, 1220 false, 0, 0, 1221 FunctionType::ExtInfo())), 1222 /*isTypeDependent=*/(Base->isTypeDependent() || 1223 (DestroyedType.getTypeSourceInfo() && 1224 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())), 1225 /*isValueDependent=*/Base->isValueDependent()), 1226 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 1227 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 1228 QualifierRange(QualifierRange), 1229 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc), 1230 DestroyedType(DestroyedType) { } 1231 1232 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1233 : Expr(CXXPseudoDestructorExprClass, Shell), 1234 Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { } 1235 1236 void setBase(Expr *E) { Base = E; } 1237 Expr *getBase() const { return cast<Expr>(Base); } 1238 1239 /// \brief Determines whether this member expression actually had 1240 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1241 /// x->Base::foo. 1242 bool hasQualifier() const { return Qualifier != 0; } 1243 1244 /// \brief If the member name was qualified, retrieves the source range of 1245 /// the nested-name-specifier that precedes the member name. Otherwise, 1246 /// returns an empty source range. 1247 SourceRange getQualifierRange() const { return QualifierRange; } 1248 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1249 1250 /// \brief If the member name was qualified, retrieves the 1251 /// nested-name-specifier that precedes the member name. Otherwise, returns 1252 /// NULL. 1253 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1254 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1255 1256 /// \brief Determine whether this pseudo-destructor expression was written 1257 /// using an '->' (otherwise, it used a '.'). 1258 bool isArrow() const { return IsArrow; } 1259 void setArrow(bool A) { IsArrow = A; } 1260 1261 /// \brief Retrieve the location of the '.' or '->' operator. 1262 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1263 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1264 1265 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1266 /// expression. 1267 /// 1268 /// Pseudo-destructor expressions can have extra qualification within them 1269 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1270 /// Here, if the object type of the expression is (or may be) a scalar type, 1271 /// \p T may also be a scalar type and, therefore, cannot be part of a 1272 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1273 /// destructor expression. 1274 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1275 void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; } 1276 1277 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1278 /// expression. 1279 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1280 void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; } 1281 1282 /// \brief Retrieve the location of the '~'. 1283 SourceLocation getTildeLoc() const { return TildeLoc; } 1284 void setTildeLoc(SourceLocation L) { TildeLoc = L; } 1285 1286 /// \brief Retrieve the source location information for the type 1287 /// being destroyed. 1288 /// 1289 /// This type-source information is available for non-dependent 1290 /// pseudo-destructor expressions and some dependent pseudo-destructor 1291 /// expressions. Returns NULL if we only have the identifier for a 1292 /// dependent pseudo-destructor expression. 1293 TypeSourceInfo *getDestroyedTypeInfo() const { 1294 return DestroyedType.getTypeSourceInfo(); 1295 } 1296 1297 /// \brief In a dependent pseudo-destructor expression for which we do not 1298 /// have full type information on the destroyed type, provides the name 1299 /// of the destroyed type. 1300 IdentifierInfo *getDestroyedTypeIdentifier() const { 1301 return DestroyedType.getIdentifier(); 1302 } 1303 1304 /// \brief Retrieve the type being destroyed. 1305 QualType getDestroyedType() const; 1306 1307 /// \brief Retrieve the starting location of the type being destroyed. 1308 SourceLocation getDestroyedTypeLoc() const { 1309 return DestroyedType.getLocation(); 1310 } 1311 1312 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1313 /// expression. 1314 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1315 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1316 } 1317 1318 /// \brief Set the destroyed type. 1319 void setDestroyedType(TypeSourceInfo *Info) { 1320 DestroyedType = PseudoDestructorTypeStorage(Info); 1321 } 1322 1323 virtual SourceRange getSourceRange() const; 1324 1325 static bool classof(const Stmt *T) { 1326 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1327 } 1328 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1329 1330 // Iterators 1331 virtual child_iterator child_begin(); 1332 virtual child_iterator child_end(); 1333}; 1334 1335/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1336/// implementation of TR1/C++0x type trait templates. 1337/// Example: 1338/// __is_pod(int) == true 1339/// __is_enum(std::string) == false 1340class UnaryTypeTraitExpr : public Expr { 1341 /// UTT - The trait. 1342 UnaryTypeTrait UTT; 1343 1344 /// Loc - The location of the type trait keyword. 1345 SourceLocation Loc; 1346 1347 /// RParen - The location of the closing paren. 1348 SourceLocation RParen; 1349 1350 /// QueriedType - The type we're testing. 1351 QualType QueriedType; 1352 1353public: 1354 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 1355 SourceLocation rparen, QualType ty) 1356 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 1357 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 1358 1359 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1360 : Expr(UnaryTypeTraitExprClass, Empty), UTT((UnaryTypeTrait)0) { } 1361 1362 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1363 1364 UnaryTypeTrait getTrait() const { return UTT; } 1365 1366 QualType getQueriedType() const { return QueriedType; } 1367 1368 bool EvaluateTrait(ASTContext&) const; 1369 1370 static bool classof(const Stmt *T) { 1371 return T->getStmtClass() == UnaryTypeTraitExprClass; 1372 } 1373 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1374 1375 // Iterators 1376 virtual child_iterator child_begin(); 1377 virtual child_iterator child_end(); 1378 1379 friend class PCHStmtReader; 1380}; 1381 1382/// \brief A reference to an overloaded function set, either an 1383/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 1384class OverloadExpr : public Expr { 1385 /// The results. These are undesugared, which is to say, they may 1386 /// include UsingShadowDecls. Access is relative to the naming 1387 /// class. 1388 // FIXME: Allocate this data after the OverloadExpr subclass. 1389 DeclAccessPair *Results; 1390 unsigned NumResults; 1391 1392 /// The common name of these declarations. 1393 DeclarationName Name; 1394 1395 /// The scope specifier, if any. 1396 NestedNameSpecifier *Qualifier; 1397 1398 /// The source range of the scope specifier. 1399 SourceRange QualifierRange; 1400 1401 /// The location of the name. 1402 SourceLocation NameLoc; 1403 1404protected: 1405 /// True if the name was a template-id. 1406 bool HasExplicitTemplateArgs; 1407 1408 OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent, 1409 NestedNameSpecifier *Qualifier, SourceRange QRange, 1410 DeclarationName Name, SourceLocation NameLoc, 1411 bool HasTemplateArgs, 1412 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 1413 1414 OverloadExpr(StmtClass K, EmptyShell Empty) 1415 : Expr(K, Empty), Results(0), NumResults(0), 1416 Qualifier(0), HasExplicitTemplateArgs(false) { } 1417 1418public: 1419 /// Computes whether an unresolved lookup on the given declarations 1420 /// and optional template arguments is type- and value-dependent. 1421 static bool ComputeDependence(UnresolvedSetIterator Begin, 1422 UnresolvedSetIterator End, 1423 const TemplateArgumentListInfo *Args); 1424 1425 /// Finds the overloaded expression in the given expression of 1426 /// OverloadTy. 1427 /// 1428 /// \return the expression (which must be there) and true if it is 1429 /// within an address-of operator. 1430 static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) { 1431 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 1432 1433 bool op = false; 1434 E = E->IgnoreParens(); 1435 if (isa<UnaryOperator>(E)) 1436 op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens(); 1437 return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op); 1438 } 1439 1440 /// Gets the naming class of this lookup, if any. 1441 CXXRecordDecl *getNamingClass() const; 1442 1443 typedef UnresolvedSetImpl::iterator decls_iterator; 1444 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 1445 decls_iterator decls_end() const { 1446 return UnresolvedSetIterator(Results + NumResults); 1447 } 1448 1449 void initializeResults(ASTContext &C, 1450 UnresolvedSetIterator Begin,UnresolvedSetIterator End); 1451 1452 /// Gets the number of declarations in the unresolved set. 1453 unsigned getNumDecls() const { return NumResults; } 1454 1455 /// Gets the name looked up. 1456 DeclarationName getName() const { return Name; } 1457 void setName(DeclarationName N) { Name = N; } 1458 1459 /// Gets the location of the name. 1460 SourceLocation getNameLoc() const { return NameLoc; } 1461 void setNameLoc(SourceLocation Loc) { NameLoc = Loc; } 1462 1463 /// Fetches the nested-name qualifier, if one was given. 1464 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1465 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1466 1467 /// Fetches the range of the nested-name qualifier. 1468 SourceRange getQualifierRange() const { return QualifierRange; } 1469 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1470 1471 /// \brief Determines whether this expression had an explicit 1472 /// template argument list, e.g. f<int>. 1473 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1474 1475 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 1476 1477 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1478 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 1479 } 1480 1481 ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1482 if (hasExplicitTemplateArgs()) 1483 return &getExplicitTemplateArgs(); 1484 return 0; 1485 } 1486 1487 static bool classof(const Stmt *T) { 1488 return T->getStmtClass() == UnresolvedLookupExprClass || 1489 T->getStmtClass() == UnresolvedMemberExprClass; 1490 } 1491 static bool classof(const OverloadExpr *) { return true; } 1492}; 1493 1494/// \brief A reference to a name which we were able to look up during 1495/// parsing but could not resolve to a specific declaration. This 1496/// arises in several ways: 1497/// * we might be waiting for argument-dependent lookup 1498/// * the name might resolve to an overloaded function 1499/// and eventually: 1500/// * the lookup might have included a function template 1501/// These never include UnresolvedUsingValueDecls, which are always 1502/// class members and therefore appear only in 1503/// UnresolvedMemberLookupExprs. 1504class UnresolvedLookupExpr : public OverloadExpr { 1505 /// True if these lookup results should be extended by 1506 /// argument-dependent lookup if this is the operand of a function 1507 /// call. 1508 bool RequiresADL; 1509 1510 /// True if these lookup results are overloaded. This is pretty 1511 /// trivially rederivable if we urgently need to kill this field. 1512 bool Overloaded; 1513 1514 /// The naming class (C++ [class.access.base]p5) of the lookup, if 1515 /// any. This can generally be recalculated from the context chain, 1516 /// but that can be fairly expensive for unqualified lookups. If we 1517 /// want to improve memory use here, this could go in a union 1518 /// against the qualified-lookup bits. 1519 CXXRecordDecl *NamingClass; 1520 1521 UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent, 1522 CXXRecordDecl *NamingClass, 1523 NestedNameSpecifier *Qualifier, SourceRange QRange, 1524 DeclarationName Name, SourceLocation NameLoc, 1525 bool RequiresADL, bool Overloaded, bool HasTemplateArgs, 1526 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 1527 : OverloadExpr(UnresolvedLookupExprClass, C, T, Dependent, Qualifier, 1528 QRange, Name, NameLoc, HasTemplateArgs, Begin, End), 1529 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 1530 {} 1531 1532 UnresolvedLookupExpr(EmptyShell Empty) 1533 : OverloadExpr(UnresolvedLookupExprClass, Empty), 1534 RequiresADL(false), Overloaded(false), NamingClass(0) 1535 {} 1536 1537public: 1538 static UnresolvedLookupExpr *Create(ASTContext &C, 1539 bool Dependent, 1540 CXXRecordDecl *NamingClass, 1541 NestedNameSpecifier *Qualifier, 1542 SourceRange QualifierRange, 1543 DeclarationName Name, 1544 SourceLocation NameLoc, 1545 bool ADL, bool Overloaded, 1546 UnresolvedSetIterator Begin, 1547 UnresolvedSetIterator End) { 1548 return new(C) UnresolvedLookupExpr(C, 1549 Dependent ? C.DependentTy : C.OverloadTy, 1550 Dependent, NamingClass, 1551 Qualifier, QualifierRange, 1552 Name, NameLoc, ADL, Overloaded, false, 1553 Begin, End); 1554 } 1555 1556 static UnresolvedLookupExpr *Create(ASTContext &C, 1557 bool Dependent, 1558 CXXRecordDecl *NamingClass, 1559 NestedNameSpecifier *Qualifier, 1560 SourceRange QualifierRange, 1561 DeclarationName Name, 1562 SourceLocation NameLoc, 1563 bool ADL, 1564 const TemplateArgumentListInfo &Args, 1565 UnresolvedSetIterator Begin, 1566 UnresolvedSetIterator End); 1567 1568 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 1569 unsigned NumTemplateArgs); 1570 1571 /// True if this declaration should be extended by 1572 /// argument-dependent lookup. 1573 bool requiresADL() const { return RequiresADL; } 1574 void setRequiresADL(bool V) { RequiresADL = V; } 1575 1576 /// True if this lookup is overloaded. 1577 bool isOverloaded() const { return Overloaded; } 1578 void setOverloaded(bool V) { Overloaded = V; } 1579 1580 /// Gets the 'naming class' (in the sense of C++0x 1581 /// [class.access.base]p5) of the lookup. This is the scope 1582 /// that was looked in to find these results. 1583 CXXRecordDecl *getNamingClass() const { return NamingClass; } 1584 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; } 1585 1586 // Note that, inconsistently with the explicit-template-argument AST 1587 // nodes, users are *forbidden* from calling these methods on objects 1588 // without explicit template arguments. 1589 1590 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1591 assert(hasExplicitTemplateArgs()); 1592 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1593 } 1594 1595 /// Gets a reference to the explicit template argument list. 1596 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1597 assert(hasExplicitTemplateArgs()); 1598 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1599 } 1600 1601 /// \brief Copies the template arguments (if present) into the given 1602 /// structure. 1603 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1604 getExplicitTemplateArgs().copyInto(List); 1605 } 1606 1607 SourceLocation getLAngleLoc() const { 1608 return getExplicitTemplateArgs().LAngleLoc; 1609 } 1610 1611 SourceLocation getRAngleLoc() const { 1612 return getExplicitTemplateArgs().RAngleLoc; 1613 } 1614 1615 TemplateArgumentLoc const *getTemplateArgs() const { 1616 return getExplicitTemplateArgs().getTemplateArgs(); 1617 } 1618 1619 unsigned getNumTemplateArgs() const { 1620 return getExplicitTemplateArgs().NumTemplateArgs; 1621 } 1622 1623 virtual SourceRange getSourceRange() const { 1624 SourceRange Range(getNameLoc()); 1625 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 1626 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1627 return Range; 1628 } 1629 1630 virtual StmtIterator child_begin(); 1631 virtual StmtIterator child_end(); 1632 1633 static bool classof(const Stmt *T) { 1634 return T->getStmtClass() == UnresolvedLookupExprClass; 1635 } 1636 static bool classof(const UnresolvedLookupExpr *) { return true; } 1637}; 1638 1639/// \brief A qualified reference to a name whose declaration cannot 1640/// yet be resolved. 1641/// 1642/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1643/// it expresses a reference to a declaration such as 1644/// X<T>::value. The difference, however, is that an 1645/// DependentScopeDeclRefExpr node is used only within C++ templates when 1646/// the qualification (e.g., X<T>::) refers to a dependent type. In 1647/// this case, X<T>::value cannot resolve to a declaration because the 1648/// declaration will differ from on instantiation of X<T> to the 1649/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1650/// qualifier (X<T>::) and the name of the entity being referenced 1651/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1652/// declaration can be found. 1653class DependentScopeDeclRefExpr : public Expr { 1654 /// The name of the entity we will be referencing. 1655 DeclarationName Name; 1656 1657 /// Location of the name of the declaration we're referencing. 1658 SourceLocation Loc; 1659 1660 /// QualifierRange - The source range that covers the 1661 /// nested-name-specifier. 1662 SourceRange QualifierRange; 1663 1664 /// \brief The nested-name-specifier that qualifies this unresolved 1665 /// declaration name. 1666 NestedNameSpecifier *Qualifier; 1667 1668 /// \brief Whether the name includes explicit template arguments. 1669 bool HasExplicitTemplateArgs; 1670 1671 DependentScopeDeclRefExpr(QualType T, 1672 NestedNameSpecifier *Qualifier, 1673 SourceRange QualifierRange, 1674 DeclarationName Name, 1675 SourceLocation NameLoc, 1676 bool HasExplicitTemplateArgs) 1677 : Expr(DependentScopeDeclRefExprClass, T, true, true), 1678 Name(Name), Loc(NameLoc), 1679 QualifierRange(QualifierRange), Qualifier(Qualifier), 1680 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 1681 {} 1682 1683public: 1684 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1685 NestedNameSpecifier *Qualifier, 1686 SourceRange QualifierRange, 1687 DeclarationName Name, 1688 SourceLocation NameLoc, 1689 const TemplateArgumentListInfo *TemplateArgs = 0); 1690 1691 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 1692 unsigned NumTemplateArgs); 1693 1694 /// \brief Retrieve the name that this expression refers to. 1695 DeclarationName getDeclName() const { return Name; } 1696 void setDeclName(DeclarationName N) { Name = N; } 1697 1698 /// \brief Retrieve the location of the name within the expression. 1699 SourceLocation getLocation() const { return Loc; } 1700 void setLocation(SourceLocation L) { Loc = L; } 1701 1702 /// \brief Retrieve the source range of the nested-name-specifier. 1703 SourceRange getQualifierRange() const { return QualifierRange; } 1704 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1705 1706 /// \brief Retrieve the nested-name-specifier that qualifies this 1707 /// declaration. 1708 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1709 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1710 1711 /// Determines whether this lookup had explicit template arguments. 1712 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1713 1714 // Note that, inconsistently with the explicit-template-argument AST 1715 // nodes, users are *forbidden* from calling these methods on objects 1716 // without explicit template arguments. 1717 1718 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1719 assert(hasExplicitTemplateArgs()); 1720 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1721 } 1722 1723 /// Gets a reference to the explicit template argument list. 1724 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1725 assert(hasExplicitTemplateArgs()); 1726 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1727 } 1728 1729 /// \brief Copies the template arguments (if present) into the given 1730 /// structure. 1731 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1732 getExplicitTemplateArgs().copyInto(List); 1733 } 1734 1735 SourceLocation getLAngleLoc() const { 1736 return getExplicitTemplateArgs().LAngleLoc; 1737 } 1738 1739 SourceLocation getRAngleLoc() const { 1740 return getExplicitTemplateArgs().RAngleLoc; 1741 } 1742 1743 TemplateArgumentLoc const *getTemplateArgs() const { 1744 return getExplicitTemplateArgs().getTemplateArgs(); 1745 } 1746 1747 unsigned getNumTemplateArgs() const { 1748 return getExplicitTemplateArgs().NumTemplateArgs; 1749 } 1750 1751 virtual SourceRange getSourceRange() const { 1752 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1753 if (hasExplicitTemplateArgs()) 1754 Range.setEnd(getRAngleLoc()); 1755 return Range; 1756 } 1757 1758 static bool classof(const Stmt *T) { 1759 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1760 } 1761 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1762 1763 virtual StmtIterator child_begin(); 1764 virtual StmtIterator child_end(); 1765}; 1766 1767class CXXExprWithTemporaries : public Expr { 1768 Stmt *SubExpr; 1769 1770 CXXTemporary **Temps; 1771 unsigned NumTemps; 1772 1773 CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps, 1774 unsigned NumTemps); 1775 ~CXXExprWithTemporaries(); 1776 1777protected: 1778 virtual void DoDestroy(ASTContext &C); 1779 1780public: 1781 CXXExprWithTemporaries(EmptyShell Empty) 1782 : Expr(CXXExprWithTemporariesClass, Empty), 1783 SubExpr(0), Temps(0), NumTemps(0) {} 1784 1785 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1786 CXXTemporary **Temps, 1787 unsigned NumTemps); 1788 1789 unsigned getNumTemporaries() const { return NumTemps; } 1790 void setNumTemporaries(ASTContext &C, unsigned N); 1791 1792 CXXTemporary *getTemporary(unsigned i) { 1793 assert(i < NumTemps && "Index out of range"); 1794 return Temps[i]; 1795 } 1796 const CXXTemporary *getTemporary(unsigned i) const { 1797 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 1798 } 1799 void setTemporary(unsigned i, CXXTemporary *T) { 1800 assert(i < NumTemps && "Index out of range"); 1801 Temps[i] = T; 1802 } 1803 1804 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1805 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1806 void setSubExpr(Expr *E) { SubExpr = E; } 1807 1808 virtual SourceRange getSourceRange() const { 1809 return SubExpr->getSourceRange(); 1810 } 1811 1812 // Implement isa/cast/dyncast/etc. 1813 static bool classof(const Stmt *T) { 1814 return T->getStmtClass() == CXXExprWithTemporariesClass; 1815 } 1816 static bool classof(const CXXExprWithTemporaries *) { return true; } 1817 1818 // Iterators 1819 virtual child_iterator child_begin(); 1820 virtual child_iterator child_end(); 1821}; 1822 1823/// \brief Describes an explicit type conversion that uses functional 1824/// notion but could not be resolved because one or more arguments are 1825/// type-dependent. 1826/// 1827/// The explicit type conversions expressed by 1828/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1829/// where \c T is some type and \c a1, a2, ..., aN are values, and 1830/// either \C T is a dependent type or one or more of the \c a's is 1831/// type-dependent. For example, this would occur in a template such 1832/// as: 1833/// 1834/// \code 1835/// template<typename T, typename A1> 1836/// inline T make_a(const A1& a1) { 1837/// return T(a1); 1838/// } 1839/// \endcode 1840/// 1841/// When the returned expression is instantiated, it may resolve to a 1842/// constructor call, conversion function call, or some kind of type 1843/// conversion. 1844class CXXUnresolvedConstructExpr : public Expr { 1845 /// \brief The starting location of the type 1846 SourceLocation TyBeginLoc; 1847 1848 /// \brief The type being constructed. 1849 QualType Type; 1850 1851 /// \brief The location of the left parentheses ('('). 1852 SourceLocation LParenLoc; 1853 1854 /// \brief The location of the right parentheses (')'). 1855 SourceLocation RParenLoc; 1856 1857 /// \brief The number of arguments used to construct the type. 1858 unsigned NumArgs; 1859 1860 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 1861 QualType T, 1862 SourceLocation LParenLoc, 1863 Expr **Args, 1864 unsigned NumArgs, 1865 SourceLocation RParenLoc); 1866 1867 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 1868 : Expr(CXXUnresolvedConstructExprClass, Empty), NumArgs(NumArgs) { } 1869 1870public: 1871 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1872 SourceLocation TyBegin, 1873 QualType T, 1874 SourceLocation LParenLoc, 1875 Expr **Args, 1876 unsigned NumArgs, 1877 SourceLocation RParenLoc); 1878 1879 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 1880 unsigned NumArgs); 1881 1882 /// \brief Retrieve the source location where the type begins. 1883 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1884 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1885 1886 /// \brief Retrieve the type that is being constructed, as specified 1887 /// in the source code. 1888 QualType getTypeAsWritten() const { return Type; } 1889 void setTypeAsWritten(QualType T) { Type = T; } 1890 1891 /// \brief Retrieve the location of the left parentheses ('(') that 1892 /// precedes the argument list. 1893 SourceLocation getLParenLoc() const { return LParenLoc; } 1894 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1895 1896 /// \brief Retrieve the location of the right parentheses (')') that 1897 /// follows the argument list. 1898 SourceLocation getRParenLoc() const { return RParenLoc; } 1899 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1900 1901 /// \brief Retrieve the number of arguments. 1902 unsigned arg_size() const { return NumArgs; } 1903 1904 typedef Expr** arg_iterator; 1905 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 1906 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1907 1908 typedef const Expr* const * const_arg_iterator; 1909 const_arg_iterator arg_begin() const { 1910 return reinterpret_cast<const Expr* const *>(this + 1); 1911 } 1912 const_arg_iterator arg_end() const { 1913 return arg_begin() + NumArgs; 1914 } 1915 1916 Expr *getArg(unsigned I) { 1917 assert(I < NumArgs && "Argument index out-of-range"); 1918 return *(arg_begin() + I); 1919 } 1920 1921 const Expr *getArg(unsigned I) const { 1922 assert(I < NumArgs && "Argument index out-of-range"); 1923 return *(arg_begin() + I); 1924 } 1925 1926 void setArg(unsigned I, Expr *E) { 1927 assert(I < NumArgs && "Argument index out-of-range"); 1928 *(arg_begin() + I) = E; 1929 } 1930 1931 virtual SourceRange getSourceRange() const { 1932 return SourceRange(TyBeginLoc, RParenLoc); 1933 } 1934 static bool classof(const Stmt *T) { 1935 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 1936 } 1937 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 1938 1939 // Iterators 1940 virtual child_iterator child_begin(); 1941 virtual child_iterator child_end(); 1942}; 1943 1944/// \brief Represents a C++ member access expression where the actual 1945/// member referenced could not be resolved because the base 1946/// expression or the member name was dependent. 1947/// 1948/// Like UnresolvedMemberExprs, these can be either implicit or 1949/// explicit accesses. It is only possible to get one of these with 1950/// an implicit access if a qualifier is provided. 1951class CXXDependentScopeMemberExpr : public Expr { 1952 /// \brief The expression for the base pointer or class reference, 1953 /// e.g., the \c x in x.f. Can be null in implicit accesses. 1954 Stmt *Base; 1955 1956 /// \brief The type of the base expression. Never null, even for 1957 /// implicit accesses. 1958 QualType BaseType; 1959 1960 /// \brief Whether this member expression used the '->' operator or 1961 /// the '.' operator. 1962 bool IsArrow : 1; 1963 1964 /// \brief Whether this member expression has explicitly-specified template 1965 /// arguments. 1966 bool HasExplicitTemplateArgs : 1; 1967 1968 /// \brief The location of the '->' or '.' operator. 1969 SourceLocation OperatorLoc; 1970 1971 /// \brief The nested-name-specifier that precedes the member name, if any. 1972 NestedNameSpecifier *Qualifier; 1973 1974 /// \brief The source range covering the nested name specifier. 1975 SourceRange QualifierRange; 1976 1977 /// \brief In a qualified member access expression such as t->Base::f, this 1978 /// member stores the resolves of name lookup in the context of the member 1979 /// access expression, to be used at instantiation time. 1980 /// 1981 /// FIXME: This member, along with the Qualifier and QualifierRange, could 1982 /// be stuck into a structure that is optionally allocated at the end of 1983 /// the CXXDependentScopeMemberExpr, to save space in the common case. 1984 NamedDecl *FirstQualifierFoundInScope; 1985 1986 /// \brief The member to which this member expression refers, which 1987 /// can be name, overloaded operator, or destructor. 1988 /// FIXME: could also be a template-id 1989 DeclarationName Member; 1990 1991 /// \brief The location of the member name. 1992 SourceLocation MemberLoc; 1993 1994 CXXDependentScopeMemberExpr(ASTContext &C, 1995 Expr *Base, QualType BaseType, bool IsArrow, 1996 SourceLocation OperatorLoc, 1997 NestedNameSpecifier *Qualifier, 1998 SourceRange QualifierRange, 1999 NamedDecl *FirstQualifierFoundInScope, 2000 DeclarationName Member, 2001 SourceLocation MemberLoc, 2002 const TemplateArgumentListInfo *TemplateArgs); 2003 2004public: 2005 CXXDependentScopeMemberExpr(ASTContext &C, 2006 Expr *Base, QualType BaseType, 2007 bool IsArrow, 2008 SourceLocation OperatorLoc, 2009 NestedNameSpecifier *Qualifier, 2010 SourceRange QualifierRange, 2011 NamedDecl *FirstQualifierFoundInScope, 2012 DeclarationName Member, 2013 SourceLocation MemberLoc) 2014 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 2015 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 2016 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 2017 Qualifier(Qualifier), QualifierRange(QualifierRange), 2018 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 2019 Member(Member), MemberLoc(MemberLoc) { } 2020 2021 static CXXDependentScopeMemberExpr * 2022 Create(ASTContext &C, 2023 Expr *Base, QualType BaseType, bool IsArrow, 2024 SourceLocation OperatorLoc, 2025 NestedNameSpecifier *Qualifier, 2026 SourceRange QualifierRange, 2027 NamedDecl *FirstQualifierFoundInScope, 2028 DeclarationName Member, 2029 SourceLocation MemberLoc, 2030 const TemplateArgumentListInfo *TemplateArgs); 2031 2032 static CXXDependentScopeMemberExpr * 2033 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2034 2035 /// \brief True if this is an implicit access, i.e. one in which the 2036 /// member being accessed was not written in the source. The source 2037 /// location of the operator is invalid in this case. 2038 bool isImplicitAccess() const { return Base == 0; } 2039 2040 /// \brief Retrieve the base object of this member expressions, 2041 /// e.g., the \c x in \c x.m. 2042 Expr *getBase() const { 2043 assert(!isImplicitAccess()); 2044 return cast<Expr>(Base); 2045 } 2046 void setBase(Expr *E) { Base = E; } 2047 2048 QualType getBaseType() const { return BaseType; } 2049 void setBaseType(QualType T) { BaseType = T; } 2050 2051 /// \brief Determine whether this member expression used the '->' 2052 /// operator; otherwise, it used the '.' operator. 2053 bool isArrow() const { return IsArrow; } 2054 void setArrow(bool A) { IsArrow = A; } 2055 2056 /// \brief Retrieve the location of the '->' or '.' operator. 2057 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2058 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2059 2060 /// \brief Retrieve the nested-name-specifier that qualifies the member 2061 /// name. 2062 NestedNameSpecifier *getQualifier() const { return Qualifier; } 2063 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 2064 2065 /// \brief Retrieve the source range covering the nested-name-specifier 2066 /// that qualifies the member name. 2067 SourceRange getQualifierRange() const { return QualifierRange; } 2068 void setQualifierRange(SourceRange R) { QualifierRange = R; } 2069 2070 /// \brief Retrieve the first part of the nested-name-specifier that was 2071 /// found in the scope of the member access expression when the member access 2072 /// was initially parsed. 2073 /// 2074 /// This function only returns a useful result when member access expression 2075 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2076 /// returned by this function describes what was found by unqualified name 2077 /// lookup for the identifier "Base" within the scope of the member access 2078 /// expression itself. At template instantiation time, this information is 2079 /// combined with the results of name lookup into the type of the object 2080 /// expression itself (the class type of x). 2081 NamedDecl *getFirstQualifierFoundInScope() const { 2082 return FirstQualifierFoundInScope; 2083 } 2084 void setFirstQualifierFoundInScope(NamedDecl *D) { 2085 FirstQualifierFoundInScope = D; 2086 } 2087 2088 /// \brief Retrieve the name of the member that this expression 2089 /// refers to. 2090 DeclarationName getMember() const { return Member; } 2091 void setMember(DeclarationName N) { Member = N; } 2092 2093 // \brief Retrieve the location of the name of the member that this 2094 // expression refers to. 2095 SourceLocation getMemberLoc() const { return MemberLoc; } 2096 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 2097 2098 /// \brief Determines whether this member expression actually had a C++ 2099 /// template argument list explicitly specified, e.g., x.f<int>. 2100 bool hasExplicitTemplateArgs() const { 2101 return HasExplicitTemplateArgs; 2102 } 2103 2104 /// \brief Retrieve the explicit template argument list that followed the 2105 /// member template name, if any. 2106 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 2107 assert(HasExplicitTemplateArgs); 2108 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2109 } 2110 2111 /// \brief Retrieve the explicit template argument list that followed the 2112 /// member template name, if any. 2113 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 2114 return const_cast<CXXDependentScopeMemberExpr *>(this) 2115 ->getExplicitTemplateArgumentList(); 2116 } 2117 2118 /// \brief Copies the template arguments (if present) into the given 2119 /// structure. 2120 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2121 assert(HasExplicitTemplateArgs); 2122 getExplicitTemplateArgumentList()->copyInto(List); 2123 } 2124 2125 /// \brief Initializes the template arguments using the given structure. 2126 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2127 assert(HasExplicitTemplateArgs); 2128 getExplicitTemplateArgumentList()->initializeFrom(List); 2129 } 2130 2131 /// \brief Retrieve the location of the left angle bracket following the 2132 /// member name ('<'), if any. 2133 SourceLocation getLAngleLoc() const { 2134 assert(HasExplicitTemplateArgs); 2135 return getExplicitTemplateArgumentList()->LAngleLoc; 2136 } 2137 2138 /// \brief Retrieve the template arguments provided as part of this 2139 /// template-id. 2140 const TemplateArgumentLoc *getTemplateArgs() const { 2141 assert(HasExplicitTemplateArgs); 2142 return getExplicitTemplateArgumentList()->getTemplateArgs(); 2143 } 2144 2145 /// \brief Retrieve the number of template arguments provided as part of this 2146 /// template-id. 2147 unsigned getNumTemplateArgs() const { 2148 assert(HasExplicitTemplateArgs); 2149 return getExplicitTemplateArgumentList()->NumTemplateArgs; 2150 } 2151 2152 /// \brief Retrieve the location of the right angle bracket following the 2153 /// template arguments ('>'). 2154 SourceLocation getRAngleLoc() const { 2155 assert(HasExplicitTemplateArgs); 2156 return getExplicitTemplateArgumentList()->RAngleLoc; 2157 } 2158 2159 virtual SourceRange getSourceRange() const { 2160 SourceRange Range; 2161 if (!isImplicitAccess()) 2162 Range.setBegin(Base->getSourceRange().getBegin()); 2163 else if (getQualifier()) 2164 Range.setBegin(getQualifierRange().getBegin()); 2165 else 2166 Range.setBegin(MemberLoc); 2167 2168 if (hasExplicitTemplateArgs()) 2169 Range.setEnd(getRAngleLoc()); 2170 else 2171 Range.setEnd(MemberLoc); 2172 return Range; 2173 } 2174 2175 static bool classof(const Stmt *T) { 2176 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2177 } 2178 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2179 2180 // Iterators 2181 virtual child_iterator child_begin(); 2182 virtual child_iterator child_end(); 2183}; 2184 2185/// \brief Represents a C++ member access expression for which lookup 2186/// produced a set of overloaded functions. 2187/// 2188/// The member access may be explicit or implicit: 2189/// struct A { 2190/// int a, b; 2191/// int explicitAccess() { return this->a + this->A::b; } 2192/// int implicitAccess() { return a + A::b; } 2193/// }; 2194/// 2195/// In the final AST, an explicit access always becomes a MemberExpr. 2196/// An implicit access may become either a MemberExpr or a 2197/// DeclRefExpr, depending on whether the member is static. 2198class UnresolvedMemberExpr : public OverloadExpr { 2199 /// \brief Whether this member expression used the '->' operator or 2200 /// the '.' operator. 2201 bool IsArrow : 1; 2202 2203 /// \brief Whether the lookup results contain an unresolved using 2204 /// declaration. 2205 bool HasUnresolvedUsing : 1; 2206 2207 /// \brief The expression for the base pointer or class reference, 2208 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2209 /// member expression 2210 Stmt *Base; 2211 2212 /// \brief The type of the base expression; never null. 2213 QualType BaseType; 2214 2215 /// \brief The location of the '->' or '.' operator. 2216 SourceLocation OperatorLoc; 2217 2218 UnresolvedMemberExpr(ASTContext &C, QualType T, bool Dependent, 2219 bool HasUnresolvedUsing, 2220 Expr *Base, QualType BaseType, bool IsArrow, 2221 SourceLocation OperatorLoc, 2222 NestedNameSpecifier *Qualifier, 2223 SourceRange QualifierRange, 2224 DeclarationName Member, 2225 SourceLocation MemberLoc, 2226 const TemplateArgumentListInfo *TemplateArgs, 2227 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2228 2229 UnresolvedMemberExpr(EmptyShell Empty) 2230 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2231 HasUnresolvedUsing(false), Base(0) { } 2232 2233public: 2234 static UnresolvedMemberExpr * 2235 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 2236 Expr *Base, QualType BaseType, bool IsArrow, 2237 SourceLocation OperatorLoc, 2238 NestedNameSpecifier *Qualifier, 2239 SourceRange QualifierRange, 2240 DeclarationName Member, 2241 SourceLocation MemberLoc, 2242 const TemplateArgumentListInfo *TemplateArgs, 2243 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2244 2245 static UnresolvedMemberExpr * 2246 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2247 2248 /// \brief True if this is an implicit access, i.e. one in which the 2249 /// member being accessed was not written in the source. The source 2250 /// location of the operator is invalid in this case. 2251 bool isImplicitAccess() const { return Base == 0; } 2252 2253 /// \brief Retrieve the base object of this member expressions, 2254 /// e.g., the \c x in \c x.m. 2255 Expr *getBase() { 2256 assert(!isImplicitAccess()); 2257 return cast<Expr>(Base); 2258 } 2259 const Expr *getBase() const { 2260 assert(!isImplicitAccess()); 2261 return cast<Expr>(Base); 2262 } 2263 void setBase(Expr *E) { Base = E; } 2264 2265 QualType getBaseType() const { return BaseType; } 2266 void setBaseType(QualType T) { BaseType = T; } 2267 2268 /// \brief Determine whether the lookup results contain an unresolved using 2269 /// declaration. 2270 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 2271 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; } 2272 2273 /// \brief Determine whether this member expression used the '->' 2274 /// operator; otherwise, it used the '.' operator. 2275 bool isArrow() const { return IsArrow; } 2276 void setArrow(bool A) { IsArrow = A; } 2277 2278 /// \brief Retrieve the location of the '->' or '.' operator. 2279 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2280 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2281 2282 /// \brief Retrieves the naming class of this lookup. 2283 CXXRecordDecl *getNamingClass() const; 2284 2285 /// \brief Retrieve the name of the member that this expression 2286 /// refers to. 2287 DeclarationName getMemberName() const { return getName(); } 2288 void setMemberName(DeclarationName N) { setName(N); } 2289 2290 // \brief Retrieve the location of the name of the member that this 2291 // expression refers to. 2292 SourceLocation getMemberLoc() const { return getNameLoc(); } 2293 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 2294 2295 /// \brief Retrieve the explicit template argument list that followed the 2296 /// member template name. 2297 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2298 assert(hasExplicitTemplateArgs()); 2299 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2300 } 2301 2302 /// \brief Retrieve the explicit template argument list that followed the 2303 /// member template name, if any. 2304 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2305 assert(hasExplicitTemplateArgs()); 2306 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 2307 } 2308 2309 /// \brief Copies the template arguments into the given structure. 2310 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2311 getExplicitTemplateArgs().copyInto(List); 2312 } 2313 2314 /// \brief Retrieve the location of the left angle bracket following 2315 /// the member name ('<'). 2316 SourceLocation getLAngleLoc() const { 2317 return getExplicitTemplateArgs().LAngleLoc; 2318 } 2319 2320 /// \brief Retrieve the template arguments provided as part of this 2321 /// template-id. 2322 const TemplateArgumentLoc *getTemplateArgs() const { 2323 return getExplicitTemplateArgs().getTemplateArgs(); 2324 } 2325 2326 /// \brief Retrieve the number of template arguments provided as 2327 /// part of this template-id. 2328 unsigned getNumTemplateArgs() const { 2329 return getExplicitTemplateArgs().NumTemplateArgs; 2330 } 2331 2332 /// \brief Retrieve the location of the right angle bracket 2333 /// following the template arguments ('>'). 2334 SourceLocation getRAngleLoc() const { 2335 return getExplicitTemplateArgs().RAngleLoc; 2336 } 2337 2338 virtual SourceRange getSourceRange() const { 2339 SourceRange Range; 2340 if (!isImplicitAccess()) 2341 Range.setBegin(Base->getSourceRange().getBegin()); 2342 else if (getQualifier()) 2343 Range.setBegin(getQualifierRange().getBegin()); 2344 else 2345 Range.setBegin(getMemberLoc()); 2346 2347 if (hasExplicitTemplateArgs()) 2348 Range.setEnd(getRAngleLoc()); 2349 else 2350 Range.setEnd(getMemberLoc()); 2351 return Range; 2352 } 2353 2354 static bool classof(const Stmt *T) { 2355 return T->getStmtClass() == UnresolvedMemberExprClass; 2356 } 2357 static bool classof(const UnresolvedMemberExpr *) { return true; } 2358 2359 // Iterators 2360 virtual child_iterator child_begin(); 2361 virtual child_iterator child_end(); 2362}; 2363 2364inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 2365 if (isa<UnresolvedLookupExpr>(this)) 2366 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 2367 else 2368 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 2369} 2370 2371} // end namespace clang 2372 2373#endif 2374