ExprCXX.h revision 2333f7727f97018d6742e1e0938133bcfad967ab
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/Decl.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 /// getImplicitObjectArgument - Retrieves the implicit object 96 /// argument for the member call. For example, in "x.f(5)", this 97 /// operation would return "x". 98 Expr *getImplicitObjectArgument(); 99 100 virtual SourceRange getSourceRange() const; 101 102 static bool classof(const Stmt *T) { 103 return T->getStmtClass() == CXXMemberCallExprClass; 104 } 105 static bool classof(const CXXMemberCallExpr *) { return true; } 106}; 107 108/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 109/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 110/// const_cast. 111/// 112/// This abstract class is inherited by all of the classes 113/// representing "named" casts, e.g., CXXStaticCastExpr, 114/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 115class CXXNamedCastExpr : public ExplicitCastExpr { 116private: 117 SourceLocation Loc; // the location of the casting op 118 119protected: 120 CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op, 121 QualType writtenTy, SourceLocation l) 122 : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {} 123 124public: 125 const char *getCastName() const; 126 127 /// \brief Retrieve the location of the cast operator keyword, e.g., 128 /// "static_cast". 129 SourceLocation getOperatorLoc() const { return Loc; } 130 void setOperatorLoc(SourceLocation L) { Loc = L; } 131 132 virtual SourceRange getSourceRange() const { 133 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 134 } 135 static bool classof(const Stmt *T) { 136 switch (T->getStmtClass()) { 137 case CXXNamedCastExprClass: 138 case CXXStaticCastExprClass: 139 case CXXDynamicCastExprClass: 140 case CXXReinterpretCastExprClass: 141 case CXXConstCastExprClass: 142 return true; 143 default: 144 return false; 145 } 146 } 147 static bool classof(const CXXNamedCastExpr *) { return true; } 148}; 149 150/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 151/// 152/// This expression node represents a C++ static cast, e.g., 153/// @c static_cast<int>(1.0). 154class CXXStaticCastExpr : public CXXNamedCastExpr { 155public: 156 CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, 157 QualType writtenTy, SourceLocation l) 158 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {} 159 160 static bool classof(const Stmt *T) { 161 return T->getStmtClass() == CXXStaticCastExprClass; 162 } 163 static bool classof(const CXXStaticCastExpr *) { return true; } 164}; 165 166/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 167/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 168/// determine how to perform the type cast. 169/// 170/// This expression node represents a dynamic cast, e.g., 171/// @c dynamic_cast<Derived*>(BasePtr). 172class CXXDynamicCastExpr : public CXXNamedCastExpr { 173public: 174 CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy, 175 SourceLocation l) 176 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {} 177 178 static bool classof(const Stmt *T) { 179 return T->getStmtClass() == CXXDynamicCastExprClass; 180 } 181 static bool classof(const CXXDynamicCastExpr *) { return true; } 182}; 183 184/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 185/// [expr.reinterpret.cast]), which provides a differently-typed view 186/// of a value but performs no actual work at run time. 187/// 188/// This expression node represents a reinterpret cast, e.g., 189/// @c reinterpret_cast<int>(VoidPtr). 190class CXXReinterpretCastExpr : public CXXNamedCastExpr { 191public: 192 CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op, 193 QualType writtenTy, SourceLocation l) 194 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, 195 writtenTy, l) {} 196 197 static bool classof(const Stmt *T) { 198 return T->getStmtClass() == CXXReinterpretCastExprClass; 199 } 200 static bool classof(const CXXReinterpretCastExpr *) { return true; } 201}; 202 203/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 204/// which can remove type qualifiers but does not change the underlying value. 205/// 206/// This expression node represents a const cast, e.g., 207/// @c const_cast<char*>(PtrToConstChar). 208class CXXConstCastExpr : public CXXNamedCastExpr { 209public: 210 CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy, 211 SourceLocation l) 212 : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {} 213 214 static bool classof(const Stmt *T) { 215 return T->getStmtClass() == CXXConstCastExprClass; 216 } 217 static bool classof(const CXXConstCastExpr *) { return true; } 218}; 219 220/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 221/// 222class CXXBoolLiteralExpr : public Expr { 223 bool Value; 224 SourceLocation Loc; 225public: 226 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 227 Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {} 228 229 bool getValue() const { return Value; } 230 231 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 232 233 static bool classof(const Stmt *T) { 234 return T->getStmtClass() == CXXBoolLiteralExprClass; 235 } 236 static bool classof(const CXXBoolLiteralExpr *) { return true; } 237 238 // Iterators 239 virtual child_iterator child_begin(); 240 virtual child_iterator child_end(); 241}; 242 243/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal 244class CXXNullPtrLiteralExpr : public Expr { 245 SourceLocation Loc; 246public: 247 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : 248 Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {} 249 250 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 251 252 static bool classof(const Stmt *T) { 253 return T->getStmtClass() == CXXNullPtrLiteralExprClass; 254 } 255 static bool classof(const CXXNullPtrLiteralExpr *) { return true; } 256 257 virtual child_iterator child_begin(); 258 virtual child_iterator child_end(); 259}; 260 261/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 262/// the type_info that corresponds to the supplied type, or the (possibly 263/// dynamic) type of the supplied expression. 264/// 265/// This represents code like @c typeid(int) or @c typeid(*objPtr) 266class CXXTypeidExpr : public Expr { 267private: 268 bool isTypeOp : 1; 269 union { 270 void *Ty; 271 Stmt *Ex; 272 } Operand; 273 SourceRange Range; 274 275public: 276 CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) : 277 Expr(CXXTypeidExprClass, Ty, 278 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 279 false, 280 // typeid is value-dependent if the type or expression are dependent 281 (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType() 282 : static_cast<Expr*>(op)->isValueDependent())), 283 isTypeOp(isTypeOp), Range(r) { 284 if (isTypeOp) 285 Operand.Ty = op; 286 else 287 // op was an Expr*, so cast it back to that to be safe 288 Operand.Ex = static_cast<Expr*>(op); 289 } 290 291 bool isTypeOperand() const { return isTypeOp; } 292 QualType getTypeOperand() const { 293 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 294 return QualType::getFromOpaquePtr(Operand.Ty); 295 } 296 Expr* getExprOperand() const { 297 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 298 return static_cast<Expr*>(Operand.Ex); 299 } 300 301 virtual SourceRange getSourceRange() const { 302 return Range; 303 } 304 static bool classof(const Stmt *T) { 305 return T->getStmtClass() == CXXTypeidExprClass; 306 } 307 static bool classof(const CXXTypeidExpr *) { return true; } 308 309 // Iterators 310 virtual child_iterator child_begin(); 311 virtual child_iterator child_end(); 312}; 313 314/// CXXThisExpr - Represents the "this" expression in C++, which is a 315/// pointer to the object on which the current member function is 316/// executing (C++ [expr.prim]p3). Example: 317/// 318/// @code 319/// class Foo { 320/// public: 321/// void bar(); 322/// void test() { this->bar(); } 323/// }; 324/// @endcode 325class CXXThisExpr : public Expr { 326 SourceLocation Loc; 327 328public: 329 CXXThisExpr(SourceLocation L, QualType Type) 330 : Expr(CXXThisExprClass, Type, 331 // 'this' is type-dependent if the class type of the enclosing 332 // member function is dependent (C++ [temp.dep.expr]p2) 333 Type->isDependentType(), Type->isDependentType()), 334 Loc(L) { } 335 336 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 337 338 static bool classof(const Stmt *T) { 339 return T->getStmtClass() == CXXThisExprClass; 340 } 341 static bool classof(const CXXThisExpr *) { return true; } 342 343 // Iterators 344 virtual child_iterator child_begin(); 345 virtual child_iterator child_end(); 346}; 347 348/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 349/// 'throw' and 'throw' assignment-expression. When 350/// assignment-expression isn't present, Op will be null. 351/// 352class CXXThrowExpr : public Expr { 353 Stmt *Op; 354 SourceLocation ThrowLoc; 355public: 356 // Ty is the void type which is used as the result type of the 357 // exepression. The l is the location of the throw keyword. expr 358 // can by null, if the optional expression to throw isn't present. 359 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 360 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} 361 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 362 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 363 void setSubExpr(Expr *E) { Op = E; } 364 365 SourceLocation getThrowLoc() const { return ThrowLoc; } 366 void setThrowLoc(SourceLocation L) { ThrowLoc = L; } 367 368 virtual SourceRange getSourceRange() const { 369 if (getSubExpr() == 0) 370 return SourceRange(ThrowLoc, ThrowLoc); 371 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 372 } 373 374 static bool classof(const Stmt *T) { 375 return T->getStmtClass() == CXXThrowExprClass; 376 } 377 static bool classof(const CXXThrowExpr *) { return true; } 378 379 // Iterators 380 virtual child_iterator child_begin(); 381 virtual child_iterator child_end(); 382}; 383 384/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 385/// function call argument that was created from the corresponding 386/// parameter's default argument, when the call did not explicitly 387/// supply arguments for all of the parameters. 388class CXXDefaultArgExpr : public Expr { 389 /// \brief The parameter whose default is being used. 390 /// 391 /// When the bit is set, the subexpression is stored after the 392 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's 393 /// actual default expression is the subexpression. 394 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param; 395 396 /// \brief The location where the default argument expression was used. 397 SourceLocation Loc; 398 399protected: 400 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param) 401 : Expr(SC, 402 param->hasUnparsedDefaultArg() 403 ? param->getType().getNonReferenceType() 404 : param->getDefaultArg()->getType(), 405 false, false), 406 Param(param, false), Loc(Loc) { } 407 408 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param, 409 Expr *SubExpr) 410 : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) 411 { 412 *reinterpret_cast<Expr **>(this + 1) = SubExpr; 413 } 414 415protected: 416 virtual void DoDestroy(ASTContext &C); 417 418public: 419 // Param is the parameter whose default argument is used by this 420 // expression. 421 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc, 422 ParmVarDecl *Param) { 423 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param); 424 } 425 426 // Param is the parameter whose default argument is used by this 427 // expression, and SubExpr is the expression that will actually be used. 428 static CXXDefaultArgExpr *Create(ASTContext &C, 429 SourceLocation Loc, 430 ParmVarDecl *Param, 431 Expr *SubExpr); 432 433 // Retrieve the parameter that the argument was created from. 434 const ParmVarDecl *getParam() const { return Param.getPointer(); } 435 ParmVarDecl *getParam() { return Param.getPointer(); } 436 437 // Retrieve the actual argument to the function call. 438 const Expr *getExpr() const { 439 if (Param.getInt()) 440 return *reinterpret_cast<Expr const * const*> (this + 1); 441 return getParam()->getDefaultArg(); 442 } 443 Expr *getExpr() { 444 if (Param.getInt()) 445 return *reinterpret_cast<Expr **> (this + 1); 446 return getParam()->getDefaultArg(); 447 } 448 449 /// \brief Retrieve the location where this default argument was actually 450 /// used. 451 SourceLocation getUsedLocation() const { return Loc; } 452 453 virtual SourceRange getSourceRange() const { 454 // Default argument expressions have no representation in the 455 // source, so they have an empty source range. 456 return SourceRange(); 457 } 458 459 static bool classof(const Stmt *T) { 460 return T->getStmtClass() == CXXDefaultArgExprClass; 461 } 462 static bool classof(const CXXDefaultArgExpr *) { return true; } 463 464 // Iterators 465 virtual child_iterator child_begin(); 466 virtual child_iterator child_end(); 467}; 468 469/// CXXTemporary - Represents a C++ temporary. 470class CXXTemporary { 471 /// Destructor - The destructor that needs to be called. 472 const CXXDestructorDecl *Destructor; 473 474 CXXTemporary(const CXXDestructorDecl *destructor) 475 : Destructor(destructor) { } 476 ~CXXTemporary() { } 477 478public: 479 static CXXTemporary *Create(ASTContext &C, 480 const CXXDestructorDecl *Destructor); 481 482 void Destroy(ASTContext &Ctx); 483 484 const CXXDestructorDecl *getDestructor() const { return Destructor; } 485}; 486 487/// CXXBindTemporaryExpr - Represents binding an expression to a temporary, 488/// so its destructor can be called later. 489class CXXBindTemporaryExpr : public Expr { 490 CXXTemporary *Temp; 491 492 Stmt *SubExpr; 493 494 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr) 495 : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false), 496 Temp(temp), SubExpr(subexpr) { } 497 ~CXXBindTemporaryExpr() { } 498 499protected: 500 virtual void DoDestroy(ASTContext &C); 501 502public: 503 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp, 504 Expr* SubExpr); 505 506 CXXTemporary *getTemporary() { return Temp; } 507 const CXXTemporary *getTemporary() const { return Temp; } 508 509 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 510 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 511 void setSubExpr(Expr *E) { SubExpr = E; } 512 513 virtual SourceRange getSourceRange() const { 514 return SubExpr->getSourceRange(); 515 } 516 517 // Implement isa/cast/dyncast/etc. 518 static bool classof(const Stmt *T) { 519 return T->getStmtClass() == CXXBindTemporaryExprClass; 520 } 521 static bool classof(const CXXBindTemporaryExpr *) { return true; } 522 523 // Iterators 524 virtual child_iterator child_begin(); 525 virtual child_iterator child_end(); 526}; 527 528/// CXXConstructExpr - Represents a call to a C++ constructor. 529class CXXConstructExpr : public Expr { 530 CXXConstructorDecl *Constructor; 531 532 SourceLocation Loc; 533 bool Elidable : 1; 534 bool ZeroInitialization : 1; 535 Stmt **Args; 536 unsigned NumArgs; 537 538protected: 539 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, 540 SourceLocation Loc, 541 CXXConstructorDecl *d, bool elidable, 542 Expr **args, unsigned numargs, 543 bool ZeroInitialization = false); 544 ~CXXConstructExpr() { } 545 546 virtual void DoDestroy(ASTContext &C); 547 548public: 549 /// \brief Construct an empty C++ construction expression that will store 550 /// \p numargs arguments. 551 CXXConstructExpr(EmptyShell Empty, ASTContext &C, unsigned numargs); 552 553 static CXXConstructExpr *Create(ASTContext &C, QualType T, 554 SourceLocation Loc, 555 CXXConstructorDecl *D, bool Elidable, 556 Expr **Args, unsigned NumArgs, 557 bool ZeroInitialization = false); 558 559 560 CXXConstructorDecl* getConstructor() const { return Constructor; } 561 void setConstructor(CXXConstructorDecl *C) { Constructor = C; } 562 563 SourceLocation getLocation() const { return Loc; } 564 void setLocation(SourceLocation Loc) { this->Loc = Loc; } 565 566 /// \brief Whether this construction is elidable. 567 bool isElidable() const { return Elidable; } 568 void setElidable(bool E) { Elidable = E; } 569 570 /// \brief Whether this construction first requires 571 /// zero-initialization before the initializer is called. 572 bool requiresZeroInitialization() const { return ZeroInitialization; } 573 void setRequiresZeroInitialization(bool ZeroInit) { 574 ZeroInitialization = ZeroInit; 575 } 576 577 typedef ExprIterator arg_iterator; 578 typedef ConstExprIterator const_arg_iterator; 579 580 arg_iterator arg_begin() { return Args; } 581 arg_iterator arg_end() { return Args + NumArgs; } 582 const_arg_iterator arg_begin() const { return Args; } 583 const_arg_iterator arg_end() const { return Args + NumArgs; } 584 585 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); } 586 unsigned getNumArgs() const { return NumArgs; } 587 588 /// getArg - Return the specified argument. 589 Expr *getArg(unsigned Arg) { 590 assert(Arg < NumArgs && "Arg access out of range!"); 591 return cast<Expr>(Args[Arg]); 592 } 593 const Expr *getArg(unsigned Arg) const { 594 assert(Arg < NumArgs && "Arg access out of range!"); 595 return cast<Expr>(Args[Arg]); 596 } 597 598 /// setArg - Set the specified argument. 599 void setArg(unsigned Arg, Expr *ArgExpr) { 600 assert(Arg < NumArgs && "Arg access out of range!"); 601 Args[Arg] = ArgExpr; 602 } 603 604 virtual SourceRange getSourceRange() const; 605 606 static bool classof(const Stmt *T) { 607 return T->getStmtClass() == CXXConstructExprClass || 608 T->getStmtClass() == CXXTemporaryObjectExprClass; 609 } 610 static bool classof(const CXXConstructExpr *) { return true; } 611 612 // Iterators 613 virtual child_iterator child_begin(); 614 virtual child_iterator child_end(); 615}; 616 617/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 618/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 619/// x = int(0.5); 620class CXXFunctionalCastExpr : public ExplicitCastExpr { 621 SourceLocation TyBeginLoc; 622 SourceLocation RParenLoc; 623public: 624 CXXFunctionalCastExpr(QualType ty, QualType writtenTy, 625 SourceLocation tyBeginLoc, CastKind kind, 626 Expr *castExpr, SourceLocation rParenLoc) 627 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, 628 writtenTy), 629 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 630 631 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 632 SourceLocation getRParenLoc() const { return RParenLoc; } 633 634 virtual SourceRange getSourceRange() const { 635 return SourceRange(TyBeginLoc, RParenLoc); 636 } 637 static bool classof(const Stmt *T) { 638 return T->getStmtClass() == CXXFunctionalCastExprClass; 639 } 640 static bool classof(const CXXFunctionalCastExpr *) { return true; } 641}; 642 643/// @brief Represents a C++ functional cast expression that builds a 644/// temporary object. 645/// 646/// This expression type represents a C++ "functional" cast 647/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 648/// constructor to build a temporary object. If N == 0 but no 649/// constructor will be called (because the functional cast is 650/// performing a value-initialized an object whose class type has no 651/// user-declared constructors), CXXZeroInitValueExpr will represent 652/// the functional cast. Finally, with N == 1 arguments the functional 653/// cast expression will be represented by CXXFunctionalCastExpr. 654/// Example: 655/// @code 656/// struct X { X(int, float); } 657/// 658/// X create_X() { 659/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 660/// }; 661/// @endcode 662class CXXTemporaryObjectExpr : public CXXConstructExpr { 663 SourceLocation TyBeginLoc; 664 SourceLocation RParenLoc; 665 666public: 667 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons, 668 QualType writtenTy, SourceLocation tyBeginLoc, 669 Expr **Args,unsigned NumArgs, 670 SourceLocation rParenLoc); 671 672 ~CXXTemporaryObjectExpr() { } 673 674 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 675 SourceLocation getRParenLoc() const { return RParenLoc; } 676 677 virtual SourceRange getSourceRange() const { 678 return SourceRange(TyBeginLoc, RParenLoc); 679 } 680 static bool classof(const Stmt *T) { 681 return T->getStmtClass() == CXXTemporaryObjectExprClass; 682 } 683 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 684}; 685 686/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 687/// Expression "T()" which creates a value-initialized rvalue of type 688/// T, which is either a non-class type or a class type without any 689/// user-defined constructors. 690/// 691class CXXZeroInitValueExpr : public Expr { 692 SourceLocation TyBeginLoc; 693 SourceLocation RParenLoc; 694 695public: 696 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 697 SourceLocation rParenLoc ) : 698 Expr(CXXZeroInitValueExprClass, ty, false, false), 699 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 700 701 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 702 SourceLocation getRParenLoc() const { return RParenLoc; } 703 704 /// @brief Whether this initialization expression was 705 /// implicitly-generated. 706 bool isImplicit() const { 707 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 708 } 709 710 virtual SourceRange getSourceRange() const { 711 return SourceRange(TyBeginLoc, RParenLoc); 712 } 713 714 static bool classof(const Stmt *T) { 715 return T->getStmtClass() == CXXZeroInitValueExprClass; 716 } 717 static bool classof(const CXXZeroInitValueExpr *) { return true; } 718 719 // Iterators 720 virtual child_iterator child_begin(); 721 virtual child_iterator child_end(); 722}; 723 724/// CXXNewExpr - A new expression for memory allocation and constructor calls, 725/// e.g: "new CXXNewExpr(foo)". 726class CXXNewExpr : public Expr { 727 // Was the usage ::new, i.e. is the global new to be used? 728 bool GlobalNew : 1; 729 // Was the form (type-id) used? Otherwise, it was new-type-id. 730 bool ParenTypeId : 1; 731 // Is there an initializer? If not, built-ins are uninitialized, else they're 732 // value-initialized. 733 bool Initializer : 1; 734 // Do we allocate an array? If so, the first SubExpr is the size expression. 735 bool Array : 1; 736 // The number of placement new arguments. 737 unsigned NumPlacementArgs : 14; 738 // The number of constructor arguments. This may be 1 even for non-class 739 // types; use the pseudo copy constructor. 740 unsigned NumConstructorArgs : 14; 741 // Contains an optional array size expression, any number of optional 742 // placement arguments, and any number of optional constructor arguments, 743 // in that order. 744 Stmt **SubExprs; 745 // Points to the allocation function used. 746 FunctionDecl *OperatorNew; 747 // Points to the deallocation function used in case of error. May be null. 748 FunctionDecl *OperatorDelete; 749 // Points to the constructor used. Cannot be null if AllocType is a record; 750 // it would still point at the default constructor (even an implicit one). 751 // Must be null for all other types. 752 CXXConstructorDecl *Constructor; 753 754 SourceLocation StartLoc; 755 SourceLocation EndLoc; 756 757public: 758 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 759 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 760 CXXConstructorDecl *constructor, bool initializer, 761 Expr **constructorArgs, unsigned numConsArgs, 762 FunctionDecl *operatorDelete, QualType ty, 763 SourceLocation startLoc, SourceLocation endLoc); 764 ~CXXNewExpr() { 765 delete[] SubExprs; 766 } 767 768 QualType getAllocatedType() const { 769 assert(getType()->isPointerType()); 770 return getType()->getAs<PointerType>()->getPointeeType(); 771 } 772 773 FunctionDecl *getOperatorNew() const { return OperatorNew; } 774 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 775 CXXConstructorDecl *getConstructor() const { return Constructor; } 776 777 bool isArray() const { return Array; } 778 Expr *getArraySize() { 779 return Array ? cast<Expr>(SubExprs[0]) : 0; 780 } 781 const Expr *getArraySize() const { 782 return Array ? cast<Expr>(SubExprs[0]) : 0; 783 } 784 785 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 786 Expr *getPlacementArg(unsigned i) { 787 assert(i < NumPlacementArgs && "Index out of range"); 788 return cast<Expr>(SubExprs[Array + i]); 789 } 790 const Expr *getPlacementArg(unsigned i) const { 791 assert(i < NumPlacementArgs && "Index out of range"); 792 return cast<Expr>(SubExprs[Array + i]); 793 } 794 795 bool isGlobalNew() const { return GlobalNew; } 796 bool isParenTypeId() const { return ParenTypeId; } 797 bool hasInitializer() const { return Initializer; } 798 799 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 800 Expr *getConstructorArg(unsigned i) { 801 assert(i < NumConstructorArgs && "Index out of range"); 802 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 803 } 804 const Expr *getConstructorArg(unsigned i) const { 805 assert(i < NumConstructorArgs && "Index out of range"); 806 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 807 } 808 809 typedef ExprIterator arg_iterator; 810 typedef ConstExprIterator const_arg_iterator; 811 812 arg_iterator placement_arg_begin() { 813 return SubExprs + Array; 814 } 815 arg_iterator placement_arg_end() { 816 return SubExprs + Array + getNumPlacementArgs(); 817 } 818 const_arg_iterator placement_arg_begin() const { 819 return SubExprs + Array; 820 } 821 const_arg_iterator placement_arg_end() const { 822 return SubExprs + Array + getNumPlacementArgs(); 823 } 824 825 arg_iterator constructor_arg_begin() { 826 return SubExprs + Array + getNumPlacementArgs(); 827 } 828 arg_iterator constructor_arg_end() { 829 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 830 } 831 const_arg_iterator constructor_arg_begin() const { 832 return SubExprs + Array + getNumPlacementArgs(); 833 } 834 const_arg_iterator constructor_arg_end() const { 835 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 836 } 837 838 virtual SourceRange getSourceRange() const { 839 return SourceRange(StartLoc, EndLoc); 840 } 841 842 static bool classof(const Stmt *T) { 843 return T->getStmtClass() == CXXNewExprClass; 844 } 845 static bool classof(const CXXNewExpr *) { return true; } 846 847 // Iterators 848 virtual child_iterator child_begin(); 849 virtual child_iterator child_end(); 850}; 851 852/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 853/// calls, e.g. "delete[] pArray". 854class CXXDeleteExpr : public Expr { 855 // Is this a forced global delete, i.e. "::delete"? 856 bool GlobalDelete : 1; 857 // Is this the array form of delete, i.e. "delete[]"? 858 bool ArrayForm : 1; 859 // Points to the operator delete overload that is used. Could be a member. 860 FunctionDecl *OperatorDelete; 861 // The pointer expression to be deleted. 862 Stmt *Argument; 863 // Location of the expression. 864 SourceLocation Loc; 865public: 866 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 867 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 868 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 869 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 870 Loc(loc) { } 871 872 bool isGlobalDelete() const { return GlobalDelete; } 873 bool isArrayForm() const { return ArrayForm; } 874 875 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 876 877 Expr *getArgument() { return cast<Expr>(Argument); } 878 const Expr *getArgument() const { return cast<Expr>(Argument); } 879 880 virtual SourceRange getSourceRange() const { 881 return SourceRange(Loc, Argument->getLocEnd()); 882 } 883 884 static bool classof(const Stmt *T) { 885 return T->getStmtClass() == CXXDeleteExprClass; 886 } 887 static bool classof(const CXXDeleteExpr *) { return true; } 888 889 // Iterators 890 virtual child_iterator child_begin(); 891 virtual child_iterator child_end(); 892}; 893 894/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 895/// 896/// Example: 897/// 898/// \code 899/// template<typename T> 900/// void destroy(T* ptr) { 901/// ptr->~T(); 902/// } 903/// \endcode 904/// 905/// When the template is parsed, the expression \c ptr->~T will be stored as 906/// a member reference expression. If it then instantiated with a scalar type 907/// as a template argument for T, the resulting expression will be a 908/// pseudo-destructor expression. 909class CXXPseudoDestructorExpr : public Expr { 910 /// \brief The base expression (that is being destroyed). 911 Stmt *Base; 912 913 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 914 /// period ('.'). 915 bool IsArrow : 1; 916 917 /// \brief The location of the '.' or '->' operator. 918 SourceLocation OperatorLoc; 919 920 /// \brief The nested-name-specifier that follows the operator, if present. 921 NestedNameSpecifier *Qualifier; 922 923 /// \brief The source range that covers the nested-name-specifier, if 924 /// present. 925 SourceRange QualifierRange; 926 927 /// \brief The type being destroyed. 928 QualType DestroyedType; 929 930 /// \brief The location of the type after the '~'. 931 SourceLocation DestroyedTypeLoc; 932 933public: 934 CXXPseudoDestructorExpr(ASTContext &Context, 935 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 936 NestedNameSpecifier *Qualifier, 937 SourceRange QualifierRange, 938 QualType DestroyedType, 939 SourceLocation DestroyedTypeLoc) 940 : Expr(CXXPseudoDestructorExprClass, 941 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 942 false, 0)), 943 /*isTypeDependent=*/false, 944 /*isValueDependent=*/Base->isValueDependent()), 945 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 946 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 947 QualifierRange(QualifierRange), DestroyedType(DestroyedType), 948 DestroyedTypeLoc(DestroyedTypeLoc) { } 949 950 void setBase(Expr *E) { Base = E; } 951 Expr *getBase() const { return cast<Expr>(Base); } 952 953 /// \brief Determines whether this member expression actually had 954 /// a C++ nested-name-specifier prior to the name of the member, e.g., 955 /// x->Base::foo. 956 bool hasQualifier() const { return Qualifier != 0; } 957 958 /// \brief If the member name was qualified, retrieves the source range of 959 /// the nested-name-specifier that precedes the member name. Otherwise, 960 /// returns an empty source range. 961 SourceRange getQualifierRange() const { return QualifierRange; } 962 963 /// \brief If the member name was qualified, retrieves the 964 /// nested-name-specifier that precedes the member name. Otherwise, returns 965 /// NULL. 966 NestedNameSpecifier *getQualifier() const { return Qualifier; } 967 968 /// \brief Determine whether this pseudo-destructor expression was written 969 /// using an '->' (otherwise, it used a '.'). 970 bool isArrow() const { return IsArrow; } 971 void setArrow(bool A) { IsArrow = A; } 972 973 /// \brief Retrieve the location of the '.' or '->' operator. 974 SourceLocation getOperatorLoc() const { return OperatorLoc; } 975 976 /// \brief Retrieve the type that is being destroyed. 977 QualType getDestroyedType() const { return DestroyedType; } 978 979 /// \brief Retrieve the location of the type being destroyed. 980 SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; } 981 982 virtual SourceRange getSourceRange() const { 983 return SourceRange(Base->getLocStart(), DestroyedTypeLoc); 984 } 985 986 static bool classof(const Stmt *T) { 987 return T->getStmtClass() == CXXPseudoDestructorExprClass; 988 } 989 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 990 991 // Iterators 992 virtual child_iterator child_begin(); 993 virtual child_iterator child_end(); 994}; 995 996/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 997/// implementation of TR1/C++0x type trait templates. 998/// Example: 999/// __is_pod(int) == true 1000/// __is_enum(std::string) == false 1001class UnaryTypeTraitExpr : public Expr { 1002 /// UTT - The trait. 1003 UnaryTypeTrait UTT; 1004 1005 /// Loc - The location of the type trait keyword. 1006 SourceLocation Loc; 1007 1008 /// RParen - The location of the closing paren. 1009 SourceLocation RParen; 1010 1011 /// QueriedType - The type we're testing. 1012 QualType QueriedType; 1013 1014public: 1015 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 1016 SourceLocation rparen, QualType ty) 1017 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 1018 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 1019 1020 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1021 1022 UnaryTypeTrait getTrait() const { return UTT; } 1023 1024 QualType getQueriedType() const { return QueriedType; } 1025 1026 bool EvaluateTrait(ASTContext&) const; 1027 1028 static bool classof(const Stmt *T) { 1029 return T->getStmtClass() == UnaryTypeTraitExprClass; 1030 } 1031 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1032 1033 // Iterators 1034 virtual child_iterator child_begin(); 1035 virtual child_iterator child_end(); 1036}; 1037 1038/// \brief A reference to a name which we were able to look up during 1039/// parsing but could not resolve to a specific declaration. This 1040/// arises in several ways: 1041/// * we might be waiting for argument-dependent lookup 1042/// * the name might resolve to an overloaded function 1043/// and eventually: 1044/// * the lookup might have included a function template 1045/// These never include UnresolvedUsingValueDecls, which are always 1046/// class members and therefore appear only in 1047/// UnresolvedMemberLookupExprs. 1048class UnresolvedLookupExpr : public Expr { 1049 /// The results. These are undesugared, which is to say, they may 1050 /// include UsingShadowDecls. 1051 UnresolvedSet Results; 1052 1053 /// The name declared. 1054 DeclarationName Name; 1055 1056 /// The qualifier given, if any. 1057 NestedNameSpecifier *Qualifier; 1058 1059 /// The source range of the nested name specifier. 1060 SourceRange QualifierRange; 1061 1062 /// The location of the name. 1063 SourceLocation NameLoc; 1064 1065 /// True if these lookup results should be extended by 1066 /// argument-dependent lookup if this is the operand of a function 1067 /// call. 1068 bool RequiresADL; 1069 1070 /// True if these lookup results are overloaded. This is pretty 1071 /// trivially rederivable if we urgently need to kill this field. 1072 bool Overloaded; 1073 1074 /// True if the name looked up had explicit template arguments. 1075 /// This requires all the results to be function templates. 1076 bool HasExplicitTemplateArgs; 1077 1078 UnresolvedLookupExpr(QualType T, bool Dependent, 1079 NestedNameSpecifier *Qualifier, SourceRange QRange, 1080 DeclarationName Name, SourceLocation NameLoc, 1081 bool RequiresADL, bool Overloaded, bool HasTemplateArgs) 1082 : Expr(UnresolvedLookupExprClass, T, Dependent, Dependent), 1083 Name(Name), Qualifier(Qualifier), QualifierRange(QRange), 1084 NameLoc(NameLoc), RequiresADL(RequiresADL), Overloaded(Overloaded), 1085 HasExplicitTemplateArgs(HasTemplateArgs) 1086 {} 1087 1088public: 1089 static UnresolvedLookupExpr *Create(ASTContext &C, 1090 bool Dependent, 1091 NestedNameSpecifier *Qualifier, 1092 SourceRange QualifierRange, 1093 DeclarationName Name, 1094 SourceLocation NameLoc, 1095 bool ADL, bool Overloaded) { 1096 return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy, 1097 Dependent, Qualifier, QualifierRange, 1098 Name, NameLoc, ADL, Overloaded, false); 1099 } 1100 1101 static UnresolvedLookupExpr *Create(ASTContext &C, 1102 bool Dependent, 1103 NestedNameSpecifier *Qualifier, 1104 SourceRange QualifierRange, 1105 DeclarationName Name, 1106 SourceLocation NameLoc, 1107 bool ADL, 1108 const TemplateArgumentListInfo &Args); 1109 1110 /// Computes whether an unresolved lookup on the given declarations 1111 /// and optional template arguments is type- and value-dependent. 1112 static bool ComputeDependence(NamedDecl * const *Begin, 1113 NamedDecl * const *End, 1114 const TemplateArgumentListInfo *Args); 1115 1116 void addDecl(NamedDecl *Decl) { 1117 Results.addDecl(Decl); 1118 } 1119 1120 typedef UnresolvedSet::iterator decls_iterator; 1121 decls_iterator decls_begin() const { return Results.begin(); } 1122 decls_iterator decls_end() const { return Results.end(); } 1123 1124 /// True if this declaration should be extended by 1125 /// argument-dependent lookup. 1126 bool requiresADL() const { return RequiresADL; } 1127 1128 /// True if this lookup is overloaded. 1129 bool isOverloaded() const { return Overloaded; } 1130 1131 /// Fetches the name looked up. 1132 DeclarationName getName() const { return Name; } 1133 1134 /// Gets the location of the name. 1135 SourceLocation getNameLoc() const { return NameLoc; } 1136 1137 /// Fetches the nested-name qualifier, if one was given. 1138 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1139 1140 /// Fetches the range of the nested-name qualifier. 1141 SourceRange getQualifierRange() const { return QualifierRange; } 1142 1143 /// Determines whether this lookup had explicit template arguments. 1144 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1145 1146 // Note that, inconsistently with the explicit-template-argument AST 1147 // nodes, users are *forbidden* from calling these methods on objects 1148 // without explicit template arguments. 1149 1150 /// Gets a reference to the explicit template argument list. 1151 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1152 assert(hasExplicitTemplateArgs()); 1153 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1154 } 1155 1156 /// \brief Copies the template arguments (if present) into the given 1157 /// structure. 1158 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1159 getExplicitTemplateArgs().copyInto(List); 1160 } 1161 1162 SourceLocation getLAngleLoc() const { 1163 return getExplicitTemplateArgs().LAngleLoc; 1164 } 1165 1166 SourceLocation getRAngleLoc() const { 1167 return getExplicitTemplateArgs().RAngleLoc; 1168 } 1169 1170 TemplateArgumentLoc const *getTemplateArgs() const { 1171 return getExplicitTemplateArgs().getTemplateArgs(); 1172 } 1173 1174 unsigned getNumTemplateArgs() const { 1175 return getExplicitTemplateArgs().NumTemplateArgs; 1176 } 1177 1178 virtual SourceRange getSourceRange() const { 1179 SourceRange Range(NameLoc); 1180 if (Qualifier) Range.setBegin(QualifierRange.getBegin()); 1181 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1182 return Range; 1183 } 1184 1185 virtual StmtIterator child_begin(); 1186 virtual StmtIterator child_end(); 1187 1188 static bool classof(const Stmt *T) { 1189 return T->getStmtClass() == UnresolvedLookupExprClass; 1190 } 1191 static bool classof(const UnresolvedLookupExpr *) { return true; } 1192}; 1193 1194/// \brief A qualified reference to a name whose declaration cannot 1195/// yet be resolved. 1196/// 1197/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1198/// it expresses a reference to a declaration such as 1199/// X<T>::value. The difference, however, is that an 1200/// DependentScopeDeclRefExpr node is used only within C++ templates when 1201/// the qualification (e.g., X<T>::) refers to a dependent type. In 1202/// this case, X<T>::value cannot resolve to a declaration because the 1203/// declaration will differ from on instantiation of X<T> to the 1204/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1205/// qualifier (X<T>::) and the name of the entity being referenced 1206/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1207/// declaration can be found. 1208class DependentScopeDeclRefExpr : public Expr { 1209 /// The name of the entity we will be referencing. 1210 DeclarationName Name; 1211 1212 /// Location of the name of the declaration we're referencing. 1213 SourceLocation Loc; 1214 1215 /// QualifierRange - The source range that covers the 1216 /// nested-name-specifier. 1217 SourceRange QualifierRange; 1218 1219 /// \brief The nested-name-specifier that qualifies this unresolved 1220 /// declaration name. 1221 NestedNameSpecifier *Qualifier; 1222 1223 /// \brief Whether the name includes explicit template arguments. 1224 bool HasExplicitTemplateArgs; 1225 1226 DependentScopeDeclRefExpr(QualType T, 1227 NestedNameSpecifier *Qualifier, 1228 SourceRange QualifierRange, 1229 DeclarationName Name, 1230 SourceLocation NameLoc, 1231 bool HasExplicitTemplateArgs) 1232 : Expr(DependentScopeDeclRefExprClass, T, true, true), 1233 Name(Name), Loc(NameLoc), 1234 QualifierRange(QualifierRange), Qualifier(Qualifier), 1235 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 1236 {} 1237 1238public: 1239 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1240 NestedNameSpecifier *Qualifier, 1241 SourceRange QualifierRange, 1242 DeclarationName Name, 1243 SourceLocation NameLoc, 1244 const TemplateArgumentListInfo *TemplateArgs = 0); 1245 1246 /// \brief Retrieve the name that this expression refers to. 1247 DeclarationName getDeclName() const { return Name; } 1248 1249 /// \brief Retrieve the location of the name within the expression. 1250 SourceLocation getLocation() const { return Loc; } 1251 1252 /// \brief Retrieve the source range of the nested-name-specifier. 1253 SourceRange getQualifierRange() const { return QualifierRange; } 1254 1255 /// \brief Retrieve the nested-name-specifier that qualifies this 1256 /// declaration. 1257 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1258 1259 /// Determines whether this lookup had explicit template arguments. 1260 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1261 1262 // Note that, inconsistently with the explicit-template-argument AST 1263 // nodes, users are *forbidden* from calling these methods on objects 1264 // without explicit template arguments. 1265 1266 /// Gets a reference to the explicit template argument list. 1267 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1268 assert(hasExplicitTemplateArgs()); 1269 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1270 } 1271 1272 /// \brief Copies the template arguments (if present) into the given 1273 /// structure. 1274 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1275 getExplicitTemplateArgs().copyInto(List); 1276 } 1277 1278 SourceLocation getLAngleLoc() const { 1279 return getExplicitTemplateArgs().LAngleLoc; 1280 } 1281 1282 SourceLocation getRAngleLoc() const { 1283 return getExplicitTemplateArgs().RAngleLoc; 1284 } 1285 1286 TemplateArgumentLoc const *getTemplateArgs() const { 1287 return getExplicitTemplateArgs().getTemplateArgs(); 1288 } 1289 1290 unsigned getNumTemplateArgs() const { 1291 return getExplicitTemplateArgs().NumTemplateArgs; 1292 } 1293 1294 virtual SourceRange getSourceRange() const { 1295 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1296 if (hasExplicitTemplateArgs()) 1297 Range.setEnd(getRAngleLoc()); 1298 return Range; 1299 } 1300 1301 static bool classof(const Stmt *T) { 1302 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1303 } 1304 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1305 1306 virtual StmtIterator child_begin(); 1307 virtual StmtIterator child_end(); 1308}; 1309 1310class CXXExprWithTemporaries : public Expr { 1311 Stmt *SubExpr; 1312 1313 CXXTemporary **Temps; 1314 unsigned NumTemps; 1315 1316 CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 1317 unsigned NumTemps); 1318 ~CXXExprWithTemporaries(); 1319 1320protected: 1321 virtual void DoDestroy(ASTContext &C); 1322 1323public: 1324 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1325 CXXTemporary **Temps, 1326 unsigned NumTemps); 1327 1328 unsigned getNumTemporaries() const { return NumTemps; } 1329 CXXTemporary *getTemporary(unsigned i) { 1330 assert(i < NumTemps && "Index out of range"); 1331 return Temps[i]; 1332 } 1333 const CXXTemporary *getTemporary(unsigned i) const { 1334 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 1335 } 1336 1337 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1338 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1339 void setSubExpr(Expr *E) { SubExpr = E; } 1340 1341 virtual SourceRange getSourceRange() const { 1342 return SubExpr->getSourceRange(); 1343 } 1344 1345 // Implement isa/cast/dyncast/etc. 1346 static bool classof(const Stmt *T) { 1347 return T->getStmtClass() == CXXExprWithTemporariesClass; 1348 } 1349 static bool classof(const CXXExprWithTemporaries *) { return true; } 1350 1351 // Iterators 1352 virtual child_iterator child_begin(); 1353 virtual child_iterator child_end(); 1354}; 1355 1356/// \brief Describes an explicit type conversion that uses functional 1357/// notion but could not be resolved because one or more arguments are 1358/// type-dependent. 1359/// 1360/// The explicit type conversions expressed by 1361/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1362/// where \c T is some type and \c a1, a2, ..., aN are values, and 1363/// either \C T is a dependent type or one or more of the \c a's is 1364/// type-dependent. For example, this would occur in a template such 1365/// as: 1366/// 1367/// \code 1368/// template<typename T, typename A1> 1369/// inline T make_a(const A1& a1) { 1370/// return T(a1); 1371/// } 1372/// \endcode 1373/// 1374/// When the returned expression is instantiated, it may resolve to a 1375/// constructor call, conversion function call, or some kind of type 1376/// conversion. 1377class CXXUnresolvedConstructExpr : public Expr { 1378 /// \brief The starting location of the type 1379 SourceLocation TyBeginLoc; 1380 1381 /// \brief The type being constructed. 1382 QualType Type; 1383 1384 /// \brief The location of the left parentheses ('('). 1385 SourceLocation LParenLoc; 1386 1387 /// \brief The location of the right parentheses (')'). 1388 SourceLocation RParenLoc; 1389 1390 /// \brief The number of arguments used to construct the type. 1391 unsigned NumArgs; 1392 1393 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 1394 QualType T, 1395 SourceLocation LParenLoc, 1396 Expr **Args, 1397 unsigned NumArgs, 1398 SourceLocation RParenLoc); 1399 1400public: 1401 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1402 SourceLocation TyBegin, 1403 QualType T, 1404 SourceLocation LParenLoc, 1405 Expr **Args, 1406 unsigned NumArgs, 1407 SourceLocation RParenLoc); 1408 1409 /// \brief Retrieve the source location where the type begins. 1410 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1411 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1412 1413 /// \brief Retrieve the type that is being constructed, as specified 1414 /// in the source code. 1415 QualType getTypeAsWritten() const { return Type; } 1416 void setTypeAsWritten(QualType T) { Type = T; } 1417 1418 /// \brief Retrieve the location of the left parentheses ('(') that 1419 /// precedes the argument list. 1420 SourceLocation getLParenLoc() const { return LParenLoc; } 1421 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1422 1423 /// \brief Retrieve the location of the right parentheses (')') that 1424 /// follows the argument list. 1425 SourceLocation getRParenLoc() const { return RParenLoc; } 1426 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1427 1428 /// \brief Retrieve the number of arguments. 1429 unsigned arg_size() const { return NumArgs; } 1430 1431 typedef Expr** arg_iterator; 1432 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 1433 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1434 1435 Expr *getArg(unsigned I) { 1436 assert(I < NumArgs && "Argument index out-of-range"); 1437 return *(arg_begin() + I); 1438 } 1439 1440 virtual SourceRange getSourceRange() const { 1441 return SourceRange(TyBeginLoc, RParenLoc); 1442 } 1443 static bool classof(const Stmt *T) { 1444 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 1445 } 1446 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 1447 1448 // Iterators 1449 virtual child_iterator child_begin(); 1450 virtual child_iterator child_end(); 1451}; 1452 1453/// \brief Represents a C++ member access expression where the actual 1454/// member referenced could not be resolved because the base 1455/// expression or the member name was dependent. 1456/// 1457/// Like UnresolvedMemberExprs, these can be either implicit or 1458/// explicit accesses. It is only possible to get one of these with 1459/// an implicit access if a qualifier is provided. 1460class CXXDependentScopeMemberExpr : public Expr { 1461 /// \brief The expression for the base pointer or class reference, 1462 /// e.g., the \c x in x.f. Can be null in implicit accesses. 1463 Stmt *Base; 1464 1465 /// \brief The type of the base expression. Never null, even for 1466 /// implicit accesses. 1467 QualType BaseType; 1468 1469 /// \brief Whether this member expression used the '->' operator or 1470 /// the '.' operator. 1471 bool IsArrow : 1; 1472 1473 /// \brief Whether this member expression has explicitly-specified template 1474 /// arguments. 1475 bool HasExplicitTemplateArgs : 1; 1476 1477 /// \brief The location of the '->' or '.' operator. 1478 SourceLocation OperatorLoc; 1479 1480 /// \brief The nested-name-specifier that precedes the member name, if any. 1481 NestedNameSpecifier *Qualifier; 1482 1483 /// \brief The source range covering the nested name specifier. 1484 SourceRange QualifierRange; 1485 1486 /// \brief In a qualified member access expression such as t->Base::f, this 1487 /// member stores the resolves of name lookup in the context of the member 1488 /// access expression, to be used at instantiation time. 1489 /// 1490 /// FIXME: This member, along with the Qualifier and QualifierRange, could 1491 /// be stuck into a structure that is optionally allocated at the end of 1492 /// the CXXDependentScopeMemberExpr, to save space in the common case. 1493 NamedDecl *FirstQualifierFoundInScope; 1494 1495 /// \brief The member to which this member expression refers, which 1496 /// can be name, overloaded operator, or destructor. 1497 /// FIXME: could also be a template-id 1498 DeclarationName Member; 1499 1500 /// \brief The location of the member name. 1501 SourceLocation MemberLoc; 1502 1503 /// \brief Retrieve the explicit template argument list that followed the 1504 /// member template name, if any. 1505 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1506 assert(HasExplicitTemplateArgs); 1507 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1508 } 1509 1510 /// \brief Retrieve the explicit template argument list that followed the 1511 /// member template name, if any. 1512 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1513 return const_cast<CXXDependentScopeMemberExpr *>(this) 1514 ->getExplicitTemplateArgumentList(); 1515 } 1516 1517 CXXDependentScopeMemberExpr(ASTContext &C, 1518 Expr *Base, QualType BaseType, bool IsArrow, 1519 SourceLocation OperatorLoc, 1520 NestedNameSpecifier *Qualifier, 1521 SourceRange QualifierRange, 1522 NamedDecl *FirstQualifierFoundInScope, 1523 DeclarationName Member, 1524 SourceLocation MemberLoc, 1525 const TemplateArgumentListInfo *TemplateArgs); 1526 1527public: 1528 CXXDependentScopeMemberExpr(ASTContext &C, 1529 Expr *Base, QualType BaseType, 1530 bool IsArrow, 1531 SourceLocation OperatorLoc, 1532 NestedNameSpecifier *Qualifier, 1533 SourceRange QualifierRange, 1534 NamedDecl *FirstQualifierFoundInScope, 1535 DeclarationName Member, 1536 SourceLocation MemberLoc) 1537 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 1538 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 1539 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 1540 Qualifier(Qualifier), QualifierRange(QualifierRange), 1541 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1542 Member(Member), MemberLoc(MemberLoc) { } 1543 1544 static CXXDependentScopeMemberExpr * 1545 Create(ASTContext &C, 1546 Expr *Base, QualType BaseType, bool IsArrow, 1547 SourceLocation OperatorLoc, 1548 NestedNameSpecifier *Qualifier, 1549 SourceRange QualifierRange, 1550 NamedDecl *FirstQualifierFoundInScope, 1551 DeclarationName Member, 1552 SourceLocation MemberLoc, 1553 const TemplateArgumentListInfo *TemplateArgs); 1554 1555 /// \brief True if this is an implicit access, i.e. one in which the 1556 /// member being accessed was not written in the source. The source 1557 /// location of the operator is invalid in this case. 1558 bool isImplicitAccess() const { return Base == 0; } 1559 1560 /// \brief Retrieve the base object of this member expressions, 1561 /// e.g., the \c x in \c x.m. 1562 Expr *getBase() const { 1563 assert(!isImplicitAccess()); 1564 return cast<Expr>(Base); 1565 } 1566 void setBase(Expr *E) { Base = E; } 1567 1568 QualType getBaseType() const { return BaseType; } 1569 1570 /// \brief Determine whether this member expression used the '->' 1571 /// operator; otherwise, it used the '.' operator. 1572 bool isArrow() const { return IsArrow; } 1573 void setArrow(bool A) { IsArrow = A; } 1574 1575 /// \brief Retrieve the location of the '->' or '.' operator. 1576 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1577 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1578 1579 /// \brief Retrieve the nested-name-specifier that qualifies the member 1580 /// name. 1581 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1582 1583 /// \brief Retrieve the source range covering the nested-name-specifier 1584 /// that qualifies the member name. 1585 SourceRange getQualifierRange() const { return QualifierRange; } 1586 1587 /// \brief Retrieve the first part of the nested-name-specifier that was 1588 /// found in the scope of the member access expression when the member access 1589 /// was initially parsed. 1590 /// 1591 /// This function only returns a useful result when member access expression 1592 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 1593 /// returned by this function describes what was found by unqualified name 1594 /// lookup for the identifier "Base" within the scope of the member access 1595 /// expression itself. At template instantiation time, this information is 1596 /// combined with the results of name lookup into the type of the object 1597 /// expression itself (the class type of x). 1598 NamedDecl *getFirstQualifierFoundInScope() const { 1599 return FirstQualifierFoundInScope; 1600 } 1601 1602 /// \brief Retrieve the name of the member that this expression 1603 /// refers to. 1604 DeclarationName getMember() const { return Member; } 1605 void setMember(DeclarationName N) { Member = N; } 1606 1607 // \brief Retrieve the location of the name of the member that this 1608 // expression refers to. 1609 SourceLocation getMemberLoc() const { return MemberLoc; } 1610 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1611 1612 /// \brief Determines whether this member expression actually had a C++ 1613 /// template argument list explicitly specified, e.g., x.f<int>. 1614 bool hasExplicitTemplateArgs() const { 1615 return HasExplicitTemplateArgs; 1616 } 1617 1618 /// \brief Copies the template arguments (if present) into the given 1619 /// structure. 1620 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1621 assert(HasExplicitTemplateArgs); 1622 getExplicitTemplateArgumentList()->copyInto(List); 1623 } 1624 1625 /// \brief Retrieve the location of the left angle bracket following the 1626 /// member name ('<'), if any. 1627 SourceLocation getLAngleLoc() const { 1628 assert(HasExplicitTemplateArgs); 1629 return getExplicitTemplateArgumentList()->LAngleLoc; 1630 } 1631 1632 /// \brief Retrieve the template arguments provided as part of this 1633 /// template-id. 1634 const TemplateArgumentLoc *getTemplateArgs() const { 1635 assert(HasExplicitTemplateArgs); 1636 return getExplicitTemplateArgumentList()->getTemplateArgs(); 1637 } 1638 1639 /// \brief Retrieve the number of template arguments provided as part of this 1640 /// template-id. 1641 unsigned getNumTemplateArgs() const { 1642 assert(HasExplicitTemplateArgs); 1643 return getExplicitTemplateArgumentList()->NumTemplateArgs; 1644 } 1645 1646 /// \brief Retrieve the location of the right angle bracket following the 1647 /// template arguments ('>'). 1648 SourceLocation getRAngleLoc() const { 1649 assert(HasExplicitTemplateArgs); 1650 return getExplicitTemplateArgumentList()->RAngleLoc; 1651 } 1652 1653 virtual SourceRange getSourceRange() const { 1654 SourceRange Range; 1655 if (!isImplicitAccess()) 1656 Range.setBegin(Base->getSourceRange().getBegin()); 1657 else if (getQualifier()) 1658 Range.setBegin(getQualifierRange().getBegin()); 1659 else 1660 Range.setBegin(MemberLoc); 1661 1662 if (hasExplicitTemplateArgs()) 1663 Range.setEnd(getRAngleLoc()); 1664 else 1665 Range.setEnd(MemberLoc); 1666 return Range; 1667 } 1668 1669 static bool classof(const Stmt *T) { 1670 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 1671 } 1672 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 1673 1674 // Iterators 1675 virtual child_iterator child_begin(); 1676 virtual child_iterator child_end(); 1677}; 1678 1679/// \brief Represents a C++ member access expression for which lookup 1680/// produced a set of overloaded functions. 1681/// 1682/// The member access may be explicit or implicit: 1683/// struct A { 1684/// int a, b; 1685/// int explicitAccess() { return this->a + this->A::b; } 1686/// int implicitAccess() { return a + A::b; } 1687/// }; 1688/// 1689/// In the final AST, an explicit access always becomes a MemberExpr. 1690/// An implicit access may become either a MemberExpr or a 1691/// DeclRefExpr, depending on whether the member is static. 1692class UnresolvedMemberExpr : public Expr { 1693 /// The results. These are undesugared, which is to say, they may 1694 /// include UsingShadowDecls. 1695 UnresolvedSet Results; 1696 1697 /// \brief The expression for the base pointer or class reference, 1698 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 1699 /// member expression 1700 Stmt *Base; 1701 1702 /// \brief The type of the base expression; never null. 1703 QualType BaseType; 1704 1705 /// \brief Whether this member expression used the '->' operator or 1706 /// the '.' operator. 1707 bool IsArrow : 1; 1708 1709 /// \brief Whether the lookup results contain an unresolved using 1710 /// declaration. 1711 bool HasUnresolvedUsing : 1; 1712 1713 /// \brief Whether this member expression has explicitly-specified template 1714 /// arguments. 1715 bool HasExplicitTemplateArgs : 1; 1716 1717 /// \brief The location of the '->' or '.' operator. 1718 SourceLocation OperatorLoc; 1719 1720 /// \brief The nested-name-specifier that precedes the member name, if any. 1721 NestedNameSpecifier *Qualifier; 1722 1723 /// \brief The source range covering the nested name specifier. 1724 SourceRange QualifierRange; 1725 1726 /// \brief The member to which this member expression refers, which 1727 /// can be a name or an overloaded operator. 1728 DeclarationName MemberName; 1729 1730 /// \brief The location of the member name. 1731 SourceLocation MemberLoc; 1732 1733 /// \brief Retrieve the explicit template argument list that followed the 1734 /// member template name. 1735 ExplicitTemplateArgumentList *getExplicitTemplateArgs() { 1736 assert(HasExplicitTemplateArgs); 1737 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1738 } 1739 1740 /// \brief Retrieve the explicit template argument list that followed the 1741 /// member template name, if any. 1742 const ExplicitTemplateArgumentList *getExplicitTemplateArgs() const { 1743 return const_cast<UnresolvedMemberExpr*>(this)->getExplicitTemplateArgs(); 1744 } 1745 1746 UnresolvedMemberExpr(QualType T, bool Dependent, 1747 bool HasUnresolvedUsing, 1748 Expr *Base, QualType BaseType, bool IsArrow, 1749 SourceLocation OperatorLoc, 1750 NestedNameSpecifier *Qualifier, 1751 SourceRange QualifierRange, 1752 DeclarationName Member, 1753 SourceLocation MemberLoc, 1754 const TemplateArgumentListInfo *TemplateArgs); 1755 1756public: 1757 static UnresolvedMemberExpr * 1758 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 1759 Expr *Base, QualType BaseType, bool IsArrow, 1760 SourceLocation OperatorLoc, 1761 NestedNameSpecifier *Qualifier, 1762 SourceRange QualifierRange, 1763 DeclarationName Member, 1764 SourceLocation MemberLoc, 1765 const TemplateArgumentListInfo *TemplateArgs); 1766 1767 /// Adds a declaration to the unresolved set. By assumption, all of 1768 /// these happen at initialization time and properties like 1769 /// 'Dependent' and 'HasUnresolvedUsing' take them into account. 1770 void addDecl(NamedDecl *Decl) { 1771 Results.addDecl(Decl); 1772 } 1773 1774 typedef UnresolvedSet::iterator decls_iterator; 1775 decls_iterator decls_begin() const { return Results.begin(); } 1776 decls_iterator decls_end() const { return Results.end(); } 1777 1778 unsigned getNumDecls() const { return Results.size(); } 1779 1780 /// \brief True if this is an implicit access, i.e. one in which the 1781 /// member being accessed was not written in the source. The source 1782 /// location of the operator is invalid in this case. 1783 bool isImplicitAccess() const { return Base == 0; } 1784 1785 /// \brief Retrieve the base object of this member expressions, 1786 /// e.g., the \c x in \c x.m. 1787 Expr *getBase() { 1788 assert(!isImplicitAccess()); 1789 return cast<Expr>(Base); 1790 } 1791 void setBase(Expr *E) { Base = E; } 1792 1793 QualType getBaseType() const { return BaseType; } 1794 1795 /// \brief Determine whether this member expression used the '->' 1796 /// operator; otherwise, it used the '.' operator. 1797 bool isArrow() const { return IsArrow; } 1798 void setArrow(bool A) { IsArrow = A; } 1799 1800 /// \brief Retrieve the location of the '->' or '.' operator. 1801 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1802 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1803 1804 /// \brief Retrieve the nested-name-specifier that qualifies the member 1805 /// name. 1806 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1807 1808 /// \brief Retrieve the source range covering the nested-name-specifier 1809 /// that qualifies the member name. 1810 SourceRange getQualifierRange() const { return QualifierRange; } 1811 1812 /// \brief Retrieve the name of the member that this expression 1813 /// refers to. 1814 DeclarationName getMemberName() const { return MemberName; } 1815 void setMemberName(DeclarationName N) { MemberName = N; } 1816 1817 // \brief Retrieve the location of the name of the member that this 1818 // expression refers to. 1819 SourceLocation getMemberLoc() const { return MemberLoc; } 1820 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1821 1822 /// \brief Determines whether this member expression actually had a C++ 1823 /// template argument list explicitly specified, e.g., x.f<int>. 1824 bool hasExplicitTemplateArgs() const { 1825 return HasExplicitTemplateArgs; 1826 } 1827 1828 /// \brief Copies the template arguments into the given structure. 1829 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1830 getExplicitTemplateArgs()->copyInto(List); 1831 } 1832 1833 /// \brief Retrieve the location of the left angle bracket following 1834 /// the member name ('<'). 1835 SourceLocation getLAngleLoc() const { 1836 return getExplicitTemplateArgs()->LAngleLoc; 1837 } 1838 1839 /// \brief Retrieve the template arguments provided as part of this 1840 /// template-id. 1841 const TemplateArgumentLoc *getTemplateArgs() const { 1842 return getExplicitTemplateArgs()->getTemplateArgs(); 1843 } 1844 1845 /// \brief Retrieve the number of template arguments provided as 1846 /// part of this template-id. 1847 unsigned getNumTemplateArgs() const { 1848 return getExplicitTemplateArgs()->NumTemplateArgs; 1849 } 1850 1851 /// \brief Retrieve the location of the right angle bracket 1852 /// following the template arguments ('>'). 1853 SourceLocation getRAngleLoc() const { 1854 return getExplicitTemplateArgs()->RAngleLoc; 1855 } 1856 1857 virtual SourceRange getSourceRange() const { 1858 SourceRange Range; 1859 if (!isImplicitAccess()) 1860 Range.setBegin(Base->getSourceRange().getBegin()); 1861 else if (getQualifier()) 1862 Range.setBegin(getQualifierRange().getBegin()); 1863 else 1864 Range.setBegin(MemberLoc); 1865 1866 if (hasExplicitTemplateArgs()) 1867 Range.setEnd(getRAngleLoc()); 1868 else 1869 Range.setEnd(MemberLoc); 1870 return Range; 1871 } 1872 1873 static bool classof(const Stmt *T) { 1874 return T->getStmtClass() == UnresolvedMemberExprClass; 1875 } 1876 static bool classof(const UnresolvedMemberExpr *) { return true; } 1877 1878 // Iterators 1879 virtual child_iterator child_begin(); 1880 virtual child_iterator child_end(); 1881}; 1882 1883} // end namespace clang 1884 1885#endif 1886