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