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