ExprCXX.h revision ce056bcaa1c97b89a4b2de2112c62d060863be2b
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/// Example: 1003/// 1004/// \code 1005/// template<typename T> 1006/// void destroy(T* ptr) { 1007/// ptr->~T(); 1008/// } 1009/// \endcode 1010/// 1011/// When the template is parsed, the expression \c ptr->~T will be stored as 1012/// a member reference expression. If it then instantiated with a scalar type 1013/// as a template argument for T, the resulting expression will be a 1014/// pseudo-destructor expression. 1015class CXXPseudoDestructorExpr : public Expr { 1016 /// \brief The base expression (that is being destroyed). 1017 Stmt *Base; 1018 1019 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1020 /// period ('.'). 1021 bool IsArrow : 1; 1022 1023 /// \brief The location of the '.' or '->' operator. 1024 SourceLocation OperatorLoc; 1025 1026 /// \brief The nested-name-specifier that follows the operator, if present. 1027 NestedNameSpecifier *Qualifier; 1028 1029 /// \brief The source range that covers the nested-name-specifier, if 1030 /// present. 1031 SourceRange QualifierRange; 1032 1033 /// \brief The type being destroyed. 1034 QualType DestroyedType; 1035 1036 /// \brief The location of the type after the '~'. 1037 SourceLocation DestroyedTypeLoc; 1038 1039public: 1040 CXXPseudoDestructorExpr(ASTContext &Context, 1041 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1042 NestedNameSpecifier *Qualifier, 1043 SourceRange QualifierRange, 1044 QualType DestroyedType, 1045 SourceLocation DestroyedTypeLoc) 1046 : Expr(CXXPseudoDestructorExprClass, 1047 Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0, 1048 false, 0, false, 1049 false, 0, 0, false, 1050 CC_Default)), 1051 /*isTypeDependent=*/false, 1052 /*isValueDependent=*/Base->isValueDependent()), 1053 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow), 1054 OperatorLoc(OperatorLoc), Qualifier(Qualifier), 1055 QualifierRange(QualifierRange), DestroyedType(DestroyedType), 1056 DestroyedTypeLoc(DestroyedTypeLoc) { } 1057 1058 void setBase(Expr *E) { Base = E; } 1059 Expr *getBase() const { return cast<Expr>(Base); } 1060 1061 /// \brief Determines whether this member expression actually had 1062 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1063 /// x->Base::foo. 1064 bool hasQualifier() const { return Qualifier != 0; } 1065 1066 /// \brief If the member name was qualified, retrieves the source range of 1067 /// the nested-name-specifier that precedes the member name. Otherwise, 1068 /// returns an empty source range. 1069 SourceRange getQualifierRange() const { return QualifierRange; } 1070 1071 /// \brief If the member name was qualified, retrieves the 1072 /// nested-name-specifier that precedes the member name. Otherwise, returns 1073 /// NULL. 1074 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1075 1076 /// \brief Determine whether this pseudo-destructor expression was written 1077 /// using an '->' (otherwise, it used a '.'). 1078 bool isArrow() const { return IsArrow; } 1079 void setArrow(bool A) { IsArrow = A; } 1080 1081 /// \brief Retrieve the location of the '.' or '->' operator. 1082 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1083 1084 /// \brief Retrieve the type that is being destroyed. 1085 QualType getDestroyedType() const { return DestroyedType; } 1086 1087 /// \brief Retrieve the location of the type being destroyed. 1088 SourceLocation getDestroyedTypeLoc() const { return DestroyedTypeLoc; } 1089 1090 virtual SourceRange getSourceRange() const { 1091 return SourceRange(Base->getLocStart(), DestroyedTypeLoc); 1092 } 1093 1094 static bool classof(const Stmt *T) { 1095 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1096 } 1097 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1098 1099 // Iterators 1100 virtual child_iterator child_begin(); 1101 virtual child_iterator child_end(); 1102}; 1103 1104/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1105/// implementation of TR1/C++0x type trait templates. 1106/// Example: 1107/// __is_pod(int) == true 1108/// __is_enum(std::string) == false 1109class UnaryTypeTraitExpr : public Expr { 1110 /// UTT - The trait. 1111 UnaryTypeTrait UTT; 1112 1113 /// Loc - The location of the type trait keyword. 1114 SourceLocation Loc; 1115 1116 /// RParen - The location of the closing paren. 1117 SourceLocation RParen; 1118 1119 /// QueriedType - The type we're testing. 1120 QualType QueriedType; 1121 1122public: 1123 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 1124 SourceLocation rparen, QualType ty) 1125 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 1126 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 1127 1128 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1129 1130 UnaryTypeTrait getTrait() const { return UTT; } 1131 1132 QualType getQueriedType() const { return QueriedType; } 1133 1134 bool EvaluateTrait(ASTContext&) const; 1135 1136 static bool classof(const Stmt *T) { 1137 return T->getStmtClass() == UnaryTypeTraitExprClass; 1138 } 1139 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1140 1141 // Iterators 1142 virtual child_iterator child_begin(); 1143 virtual child_iterator child_end(); 1144}; 1145 1146/// \brief A reference to an overloaded function set, either an 1147/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 1148class OverloadExpr : public Expr { 1149 /// The results. These are undesugared, which is to say, they may 1150 /// include UsingShadowDecls. Access is relative to the naming 1151 /// class. 1152 UnresolvedSet<4> Results; 1153 1154 /// The common name of these declarations. 1155 DeclarationName Name; 1156 1157 /// The scope specifier, if any. 1158 NestedNameSpecifier *Qualifier; 1159 1160 /// The source range of the scope specifier. 1161 SourceRange QualifierRange; 1162 1163 /// The location of the name. 1164 SourceLocation NameLoc; 1165 1166 /// True if the name was a template-id. 1167 bool HasExplicitTemplateArgs; 1168 1169protected: 1170 OverloadExpr(StmtClass K, QualType T, bool Dependent, 1171 NestedNameSpecifier *Qualifier, SourceRange QRange, 1172 DeclarationName Name, SourceLocation NameLoc, 1173 bool HasTemplateArgs) 1174 : Expr(K, T, Dependent, Dependent), 1175 Name(Name), Qualifier(Qualifier), QualifierRange(QRange), 1176 NameLoc(NameLoc), HasExplicitTemplateArgs(HasTemplateArgs) 1177 {} 1178 1179public: 1180 /// Computes whether an unresolved lookup on the given declarations 1181 /// and optional template arguments is type- and value-dependent. 1182 static bool ComputeDependence(UnresolvedSetIterator Begin, 1183 UnresolvedSetIterator End, 1184 const TemplateArgumentListInfo *Args); 1185 1186 /// Finds the overloaded expression in the given expression of 1187 /// OverloadTy. 1188 /// 1189 /// \return the expression (which must be there) and true if it is 1190 /// within an address-of operator. 1191 static llvm::PointerIntPair<OverloadExpr*,1> find(Expr *E) { 1192 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 1193 1194 bool op = false; 1195 E = E->IgnoreParens(); 1196 if (isa<UnaryOperator>(E)) 1197 op = true, E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens(); 1198 return llvm::PointerIntPair<OverloadExpr*,1>(cast<OverloadExpr>(E), op); 1199 } 1200 1201 void addDecls(UnresolvedSetIterator Begin, UnresolvedSetIterator End) { 1202 Results.append(Begin, End); 1203 } 1204 1205 typedef UnresolvedSetImpl::iterator decls_iterator; 1206 decls_iterator decls_begin() const { return Results.begin(); } 1207 decls_iterator decls_end() const { return Results.end(); } 1208 1209 /// Gets the decls as an unresolved set. 1210 const UnresolvedSetImpl &getDecls() { return Results; } 1211 1212 /// Gets the number of declarations in the unresolved set. 1213 unsigned getNumDecls() const { return Results.size(); } 1214 1215 /// Gets the name looked up. 1216 DeclarationName getName() const { return Name; } 1217 void setName(DeclarationName N) { Name = N; } 1218 1219 /// Gets the location of the name. 1220 SourceLocation getNameLoc() const { return NameLoc; } 1221 void setNameLoc(SourceLocation Loc) { NameLoc = Loc; } 1222 1223 /// Fetches the nested-name qualifier, if one was given. 1224 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1225 1226 /// Fetches the range of the nested-name qualifier. 1227 SourceRange getQualifierRange() const { return QualifierRange; } 1228 1229 /// \brief Determines whether this expression had an explicit 1230 /// template argument list, e.g. f<int>. 1231 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1232 1233 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 1234 1235 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1236 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 1237 } 1238 1239 ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1240 if (hasExplicitTemplateArgs()) 1241 return &getExplicitTemplateArgs(); 1242 return 0; 1243 } 1244 1245 static bool classof(const Stmt *T) { 1246 return T->getStmtClass() == UnresolvedLookupExprClass || 1247 T->getStmtClass() == UnresolvedMemberExprClass; 1248 } 1249 static bool classof(const OverloadExpr *) { return true; } 1250}; 1251 1252/// \brief A reference to a name which we were able to look up during 1253/// parsing but could not resolve to a specific declaration. This 1254/// arises in several ways: 1255/// * we might be waiting for argument-dependent lookup 1256/// * the name might resolve to an overloaded function 1257/// and eventually: 1258/// * the lookup might have included a function template 1259/// These never include UnresolvedUsingValueDecls, which are always 1260/// class members and therefore appear only in 1261/// UnresolvedMemberLookupExprs. 1262class UnresolvedLookupExpr : public OverloadExpr { 1263 /// True if these lookup results should be extended by 1264 /// argument-dependent lookup if this is the operand of a function 1265 /// call. 1266 bool RequiresADL; 1267 1268 /// True if these lookup results are overloaded. This is pretty 1269 /// trivially rederivable if we urgently need to kill this field. 1270 bool Overloaded; 1271 1272 /// The naming class (C++ [class.access.base]p5) of the lookup, if 1273 /// any. This can generally be recalculated from the context chain, 1274 /// but that can be fairly expensive for unqualified lookups. If we 1275 /// want to improve memory use here, this could go in a union 1276 /// against the qualified-lookup bits. 1277 CXXRecordDecl *NamingClass; 1278 1279 UnresolvedLookupExpr(QualType T, bool Dependent, CXXRecordDecl *NamingClass, 1280 NestedNameSpecifier *Qualifier, SourceRange QRange, 1281 DeclarationName Name, SourceLocation NameLoc, 1282 bool RequiresADL, bool Overloaded, bool HasTemplateArgs) 1283 : OverloadExpr(UnresolvedLookupExprClass, T, Dependent, Qualifier, QRange, 1284 Name, NameLoc, HasTemplateArgs), 1285 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 1286 {} 1287 1288public: 1289 static UnresolvedLookupExpr *Create(ASTContext &C, 1290 bool Dependent, 1291 CXXRecordDecl *NamingClass, 1292 NestedNameSpecifier *Qualifier, 1293 SourceRange QualifierRange, 1294 DeclarationName Name, 1295 SourceLocation NameLoc, 1296 bool ADL, bool Overloaded) { 1297 return new(C) UnresolvedLookupExpr(Dependent ? C.DependentTy : C.OverloadTy, 1298 Dependent, NamingClass, 1299 Qualifier, QualifierRange, 1300 Name, NameLoc, ADL, Overloaded, false); 1301 } 1302 1303 static UnresolvedLookupExpr *Create(ASTContext &C, 1304 bool Dependent, 1305 CXXRecordDecl *NamingClass, 1306 NestedNameSpecifier *Qualifier, 1307 SourceRange QualifierRange, 1308 DeclarationName Name, 1309 SourceLocation NameLoc, 1310 bool ADL, 1311 const TemplateArgumentListInfo &Args); 1312 1313 /// True if this declaration should be extended by 1314 /// argument-dependent lookup. 1315 bool requiresADL() const { return RequiresADL; } 1316 1317 /// True if this lookup is overloaded. 1318 bool isOverloaded() const { return Overloaded; } 1319 1320 /// Gets the 'naming class' (in the sense of C++0x 1321 /// [class.access.base]p5) of the lookup. This is the scope 1322 /// that was looked in to find these results. 1323 CXXRecordDecl *getNamingClass() const { return NamingClass; } 1324 1325 // Note that, inconsistently with the explicit-template-argument AST 1326 // nodes, users are *forbidden* from calling these methods on objects 1327 // without explicit template arguments. 1328 1329 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1330 assert(hasExplicitTemplateArgs()); 1331 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1332 } 1333 1334 /// Gets a reference to the explicit template argument list. 1335 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1336 assert(hasExplicitTemplateArgs()); 1337 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1338 } 1339 1340 /// \brief Copies the template arguments (if present) into the given 1341 /// structure. 1342 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1343 getExplicitTemplateArgs().copyInto(List); 1344 } 1345 1346 SourceLocation getLAngleLoc() const { 1347 return getExplicitTemplateArgs().LAngleLoc; 1348 } 1349 1350 SourceLocation getRAngleLoc() const { 1351 return getExplicitTemplateArgs().RAngleLoc; 1352 } 1353 1354 TemplateArgumentLoc const *getTemplateArgs() const { 1355 return getExplicitTemplateArgs().getTemplateArgs(); 1356 } 1357 1358 unsigned getNumTemplateArgs() const { 1359 return getExplicitTemplateArgs().NumTemplateArgs; 1360 } 1361 1362 virtual SourceRange getSourceRange() const { 1363 SourceRange Range(getNameLoc()); 1364 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 1365 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1366 return Range; 1367 } 1368 1369 virtual StmtIterator child_begin(); 1370 virtual StmtIterator child_end(); 1371 1372 static bool classof(const Stmt *T) { 1373 return T->getStmtClass() == UnresolvedLookupExprClass; 1374 } 1375 static bool classof(const UnresolvedLookupExpr *) { return true; } 1376}; 1377 1378/// \brief A qualified reference to a name whose declaration cannot 1379/// yet be resolved. 1380/// 1381/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1382/// it expresses a reference to a declaration such as 1383/// X<T>::value. The difference, however, is that an 1384/// DependentScopeDeclRefExpr node is used only within C++ templates when 1385/// the qualification (e.g., X<T>::) refers to a dependent type. In 1386/// this case, X<T>::value cannot resolve to a declaration because the 1387/// declaration will differ from on instantiation of X<T> to the 1388/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1389/// qualifier (X<T>::) and the name of the entity being referenced 1390/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1391/// declaration can be found. 1392class DependentScopeDeclRefExpr : public Expr { 1393 /// The name of the entity we will be referencing. 1394 DeclarationName Name; 1395 1396 /// Location of the name of the declaration we're referencing. 1397 SourceLocation Loc; 1398 1399 /// QualifierRange - The source range that covers the 1400 /// nested-name-specifier. 1401 SourceRange QualifierRange; 1402 1403 /// \brief The nested-name-specifier that qualifies this unresolved 1404 /// declaration name. 1405 NestedNameSpecifier *Qualifier; 1406 1407 /// \brief Whether the name includes explicit template arguments. 1408 bool HasExplicitTemplateArgs; 1409 1410 DependentScopeDeclRefExpr(QualType T, 1411 NestedNameSpecifier *Qualifier, 1412 SourceRange QualifierRange, 1413 DeclarationName Name, 1414 SourceLocation NameLoc, 1415 bool HasExplicitTemplateArgs) 1416 : Expr(DependentScopeDeclRefExprClass, T, true, true), 1417 Name(Name), Loc(NameLoc), 1418 QualifierRange(QualifierRange), Qualifier(Qualifier), 1419 HasExplicitTemplateArgs(HasExplicitTemplateArgs) 1420 {} 1421 1422public: 1423 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1424 NestedNameSpecifier *Qualifier, 1425 SourceRange QualifierRange, 1426 DeclarationName Name, 1427 SourceLocation NameLoc, 1428 const TemplateArgumentListInfo *TemplateArgs = 0); 1429 1430 /// \brief Retrieve the name that this expression refers to. 1431 DeclarationName getDeclName() const { return Name; } 1432 1433 /// \brief Retrieve the location of the name within the expression. 1434 SourceLocation getLocation() const { return Loc; } 1435 1436 /// \brief Retrieve the source range of the nested-name-specifier. 1437 SourceRange getQualifierRange() const { return QualifierRange; } 1438 1439 /// \brief Retrieve the nested-name-specifier that qualifies this 1440 /// declaration. 1441 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1442 1443 /// Determines whether this lookup had explicit template arguments. 1444 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1445 1446 // Note that, inconsistently with the explicit-template-argument AST 1447 // nodes, users are *forbidden* from calling these methods on objects 1448 // without explicit template arguments. 1449 1450 /// Gets a reference to the explicit template argument list. 1451 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1452 assert(hasExplicitTemplateArgs()); 1453 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1454 } 1455 1456 /// \brief Copies the template arguments (if present) into the given 1457 /// structure. 1458 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1459 getExplicitTemplateArgs().copyInto(List); 1460 } 1461 1462 SourceLocation getLAngleLoc() const { 1463 return getExplicitTemplateArgs().LAngleLoc; 1464 } 1465 1466 SourceLocation getRAngleLoc() const { 1467 return getExplicitTemplateArgs().RAngleLoc; 1468 } 1469 1470 TemplateArgumentLoc const *getTemplateArgs() const { 1471 return getExplicitTemplateArgs().getTemplateArgs(); 1472 } 1473 1474 unsigned getNumTemplateArgs() const { 1475 return getExplicitTemplateArgs().NumTemplateArgs; 1476 } 1477 1478 virtual SourceRange getSourceRange() const { 1479 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1480 if (hasExplicitTemplateArgs()) 1481 Range.setEnd(getRAngleLoc()); 1482 return Range; 1483 } 1484 1485 static bool classof(const Stmt *T) { 1486 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1487 } 1488 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1489 1490 virtual StmtIterator child_begin(); 1491 virtual StmtIterator child_end(); 1492}; 1493 1494class CXXExprWithTemporaries : public Expr { 1495 Stmt *SubExpr; 1496 1497 CXXTemporary **Temps; 1498 unsigned NumTemps; 1499 1500 CXXExprWithTemporaries(Expr *SubExpr, CXXTemporary **Temps, 1501 unsigned NumTemps); 1502 ~CXXExprWithTemporaries(); 1503 1504protected: 1505 virtual void DoDestroy(ASTContext &C); 1506 1507public: 1508 static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr, 1509 CXXTemporary **Temps, 1510 unsigned NumTemps); 1511 1512 unsigned getNumTemporaries() const { return NumTemps; } 1513 CXXTemporary *getTemporary(unsigned i) { 1514 assert(i < NumTemps && "Index out of range"); 1515 return Temps[i]; 1516 } 1517 const CXXTemporary *getTemporary(unsigned i) const { 1518 return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i); 1519 } 1520 1521 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1522 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1523 void setSubExpr(Expr *E) { SubExpr = E; } 1524 1525 virtual SourceRange getSourceRange() const { 1526 return SubExpr->getSourceRange(); 1527 } 1528 1529 // Implement isa/cast/dyncast/etc. 1530 static bool classof(const Stmt *T) { 1531 return T->getStmtClass() == CXXExprWithTemporariesClass; 1532 } 1533 static bool classof(const CXXExprWithTemporaries *) { return true; } 1534 1535 // Iterators 1536 virtual child_iterator child_begin(); 1537 virtual child_iterator child_end(); 1538}; 1539 1540/// \brief Describes an explicit type conversion that uses functional 1541/// notion but could not be resolved because one or more arguments are 1542/// type-dependent. 1543/// 1544/// The explicit type conversions expressed by 1545/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1546/// where \c T is some type and \c a1, a2, ..., aN are values, and 1547/// either \C T is a dependent type or one or more of the \c a's is 1548/// type-dependent. For example, this would occur in a template such 1549/// as: 1550/// 1551/// \code 1552/// template<typename T, typename A1> 1553/// inline T make_a(const A1& a1) { 1554/// return T(a1); 1555/// } 1556/// \endcode 1557/// 1558/// When the returned expression is instantiated, it may resolve to a 1559/// constructor call, conversion function call, or some kind of type 1560/// conversion. 1561class CXXUnresolvedConstructExpr : public Expr { 1562 /// \brief The starting location of the type 1563 SourceLocation TyBeginLoc; 1564 1565 /// \brief The type being constructed. 1566 QualType Type; 1567 1568 /// \brief The location of the left parentheses ('('). 1569 SourceLocation LParenLoc; 1570 1571 /// \brief The location of the right parentheses (')'). 1572 SourceLocation RParenLoc; 1573 1574 /// \brief The number of arguments used to construct the type. 1575 unsigned NumArgs; 1576 1577 CXXUnresolvedConstructExpr(SourceLocation TyBegin, 1578 QualType T, 1579 SourceLocation LParenLoc, 1580 Expr **Args, 1581 unsigned NumArgs, 1582 SourceLocation RParenLoc); 1583 1584public: 1585 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 1586 SourceLocation TyBegin, 1587 QualType T, 1588 SourceLocation LParenLoc, 1589 Expr **Args, 1590 unsigned NumArgs, 1591 SourceLocation RParenLoc); 1592 1593 /// \brief Retrieve the source location where the type begins. 1594 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 1595 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; } 1596 1597 /// \brief Retrieve the type that is being constructed, as specified 1598 /// in the source code. 1599 QualType getTypeAsWritten() const { return Type; } 1600 void setTypeAsWritten(QualType T) { Type = T; } 1601 1602 /// \brief Retrieve the location of the left parentheses ('(') that 1603 /// precedes the argument list. 1604 SourceLocation getLParenLoc() const { return LParenLoc; } 1605 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1606 1607 /// \brief Retrieve the location of the right parentheses (')') that 1608 /// follows the argument list. 1609 SourceLocation getRParenLoc() const { return RParenLoc; } 1610 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1611 1612 /// \brief Retrieve the number of arguments. 1613 unsigned arg_size() const { return NumArgs; } 1614 1615 typedef Expr** arg_iterator; 1616 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 1617 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1618 1619 typedef const Expr* const * const_arg_iterator; 1620 const_arg_iterator arg_begin() const { 1621 return reinterpret_cast<const Expr* const *>(this + 1); 1622 } 1623 const_arg_iterator arg_end() const { 1624 return arg_begin() + NumArgs; 1625 } 1626 1627 Expr *getArg(unsigned I) { 1628 assert(I < NumArgs && "Argument index out-of-range"); 1629 return *(arg_begin() + I); 1630 } 1631 1632 const Expr *getArg(unsigned I) const { 1633 assert(I < NumArgs && "Argument index out-of-range"); 1634 return *(arg_begin() + I); 1635 } 1636 1637 virtual SourceRange getSourceRange() const { 1638 return SourceRange(TyBeginLoc, RParenLoc); 1639 } 1640 static bool classof(const Stmt *T) { 1641 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 1642 } 1643 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 1644 1645 // Iterators 1646 virtual child_iterator child_begin(); 1647 virtual child_iterator child_end(); 1648}; 1649 1650/// \brief Represents a C++ member access expression where the actual 1651/// member referenced could not be resolved because the base 1652/// expression or the member name was dependent. 1653/// 1654/// Like UnresolvedMemberExprs, these can be either implicit or 1655/// explicit accesses. It is only possible to get one of these with 1656/// an implicit access if a qualifier is provided. 1657class CXXDependentScopeMemberExpr : public Expr { 1658 /// \brief The expression for the base pointer or class reference, 1659 /// e.g., the \c x in x.f. Can be null in implicit accesses. 1660 Stmt *Base; 1661 1662 /// \brief The type of the base expression. Never null, even for 1663 /// implicit accesses. 1664 QualType BaseType; 1665 1666 /// \brief Whether this member expression used the '->' operator or 1667 /// the '.' operator. 1668 bool IsArrow : 1; 1669 1670 /// \brief Whether this member expression has explicitly-specified template 1671 /// arguments. 1672 bool HasExplicitTemplateArgs : 1; 1673 1674 /// \brief The location of the '->' or '.' operator. 1675 SourceLocation OperatorLoc; 1676 1677 /// \brief The nested-name-specifier that precedes the member name, if any. 1678 NestedNameSpecifier *Qualifier; 1679 1680 /// \brief The source range covering the nested name specifier. 1681 SourceRange QualifierRange; 1682 1683 /// \brief In a qualified member access expression such as t->Base::f, this 1684 /// member stores the resolves of name lookup in the context of the member 1685 /// access expression, to be used at instantiation time. 1686 /// 1687 /// FIXME: This member, along with the Qualifier and QualifierRange, could 1688 /// be stuck into a structure that is optionally allocated at the end of 1689 /// the CXXDependentScopeMemberExpr, to save space in the common case. 1690 NamedDecl *FirstQualifierFoundInScope; 1691 1692 /// \brief The member to which this member expression refers, which 1693 /// can be name, overloaded operator, or destructor. 1694 /// FIXME: could also be a template-id 1695 DeclarationName Member; 1696 1697 /// \brief The location of the member name. 1698 SourceLocation MemberLoc; 1699 1700 /// \brief Retrieve the explicit template argument list that followed the 1701 /// member template name, if any. 1702 ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() { 1703 assert(HasExplicitTemplateArgs); 1704 return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1705 } 1706 1707 /// \brief Retrieve the explicit template argument list that followed the 1708 /// member template name, if any. 1709 const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const { 1710 return const_cast<CXXDependentScopeMemberExpr *>(this) 1711 ->getExplicitTemplateArgumentList(); 1712 } 1713 1714 CXXDependentScopeMemberExpr(ASTContext &C, 1715 Expr *Base, QualType BaseType, bool IsArrow, 1716 SourceLocation OperatorLoc, 1717 NestedNameSpecifier *Qualifier, 1718 SourceRange QualifierRange, 1719 NamedDecl *FirstQualifierFoundInScope, 1720 DeclarationName Member, 1721 SourceLocation MemberLoc, 1722 const TemplateArgumentListInfo *TemplateArgs); 1723 1724public: 1725 CXXDependentScopeMemberExpr(ASTContext &C, 1726 Expr *Base, QualType BaseType, 1727 bool IsArrow, 1728 SourceLocation OperatorLoc, 1729 NestedNameSpecifier *Qualifier, 1730 SourceRange QualifierRange, 1731 NamedDecl *FirstQualifierFoundInScope, 1732 DeclarationName Member, 1733 SourceLocation MemberLoc) 1734 : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true), 1735 Base(Base), BaseType(BaseType), IsArrow(IsArrow), 1736 HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc), 1737 Qualifier(Qualifier), QualifierRange(QualifierRange), 1738 FirstQualifierFoundInScope(FirstQualifierFoundInScope), 1739 Member(Member), MemberLoc(MemberLoc) { } 1740 1741 static CXXDependentScopeMemberExpr * 1742 Create(ASTContext &C, 1743 Expr *Base, QualType BaseType, bool IsArrow, 1744 SourceLocation OperatorLoc, 1745 NestedNameSpecifier *Qualifier, 1746 SourceRange QualifierRange, 1747 NamedDecl *FirstQualifierFoundInScope, 1748 DeclarationName Member, 1749 SourceLocation MemberLoc, 1750 const TemplateArgumentListInfo *TemplateArgs); 1751 1752 /// \brief True if this is an implicit access, i.e. one in which the 1753 /// member being accessed was not written in the source. The source 1754 /// location of the operator is invalid in this case. 1755 bool isImplicitAccess() const { return Base == 0; } 1756 1757 /// \brief Retrieve the base object of this member expressions, 1758 /// e.g., the \c x in \c x.m. 1759 Expr *getBase() const { 1760 assert(!isImplicitAccess()); 1761 return cast<Expr>(Base); 1762 } 1763 void setBase(Expr *E) { Base = E; } 1764 1765 QualType getBaseType() const { return BaseType; } 1766 1767 /// \brief Determine whether this member expression used the '->' 1768 /// operator; otherwise, it used the '.' operator. 1769 bool isArrow() const { return IsArrow; } 1770 void setArrow(bool A) { IsArrow = A; } 1771 1772 /// \brief Retrieve the location of the '->' or '.' operator. 1773 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1774 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1775 1776 /// \brief Retrieve the nested-name-specifier that qualifies the member 1777 /// name. 1778 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1779 1780 /// \brief Retrieve the source range covering the nested-name-specifier 1781 /// that qualifies the member name. 1782 SourceRange getQualifierRange() const { return QualifierRange; } 1783 1784 /// \brief Retrieve the first part of the nested-name-specifier that was 1785 /// found in the scope of the member access expression when the member access 1786 /// was initially parsed. 1787 /// 1788 /// This function only returns a useful result when member access expression 1789 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 1790 /// returned by this function describes what was found by unqualified name 1791 /// lookup for the identifier "Base" within the scope of the member access 1792 /// expression itself. At template instantiation time, this information is 1793 /// combined with the results of name lookup into the type of the object 1794 /// expression itself (the class type of x). 1795 NamedDecl *getFirstQualifierFoundInScope() const { 1796 return FirstQualifierFoundInScope; 1797 } 1798 1799 /// \brief Retrieve the name of the member that this expression 1800 /// refers to. 1801 DeclarationName getMember() const { return Member; } 1802 void setMember(DeclarationName N) { Member = N; } 1803 1804 // \brief Retrieve the location of the name of the member that this 1805 // expression refers to. 1806 SourceLocation getMemberLoc() const { return MemberLoc; } 1807 void setMemberLoc(SourceLocation L) { MemberLoc = L; } 1808 1809 /// \brief Determines whether this member expression actually had a C++ 1810 /// template argument list explicitly specified, e.g., x.f<int>. 1811 bool hasExplicitTemplateArgs() const { 1812 return HasExplicitTemplateArgs; 1813 } 1814 1815 /// \brief Copies the template arguments (if present) into the given 1816 /// structure. 1817 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1818 assert(HasExplicitTemplateArgs); 1819 getExplicitTemplateArgumentList()->copyInto(List); 1820 } 1821 1822 /// \brief Retrieve the location of the left angle bracket following the 1823 /// member name ('<'), if any. 1824 SourceLocation getLAngleLoc() const { 1825 assert(HasExplicitTemplateArgs); 1826 return getExplicitTemplateArgumentList()->LAngleLoc; 1827 } 1828 1829 /// \brief Retrieve the template arguments provided as part of this 1830 /// template-id. 1831 const TemplateArgumentLoc *getTemplateArgs() const { 1832 assert(HasExplicitTemplateArgs); 1833 return getExplicitTemplateArgumentList()->getTemplateArgs(); 1834 } 1835 1836 /// \brief Retrieve the number of template arguments provided as part of this 1837 /// template-id. 1838 unsigned getNumTemplateArgs() const { 1839 assert(HasExplicitTemplateArgs); 1840 return getExplicitTemplateArgumentList()->NumTemplateArgs; 1841 } 1842 1843 /// \brief Retrieve the location of the right angle bracket following the 1844 /// template arguments ('>'). 1845 SourceLocation getRAngleLoc() const { 1846 assert(HasExplicitTemplateArgs); 1847 return getExplicitTemplateArgumentList()->RAngleLoc; 1848 } 1849 1850 virtual SourceRange getSourceRange() const { 1851 SourceRange Range; 1852 if (!isImplicitAccess()) 1853 Range.setBegin(Base->getSourceRange().getBegin()); 1854 else if (getQualifier()) 1855 Range.setBegin(getQualifierRange().getBegin()); 1856 else 1857 Range.setBegin(MemberLoc); 1858 1859 if (hasExplicitTemplateArgs()) 1860 Range.setEnd(getRAngleLoc()); 1861 else 1862 Range.setEnd(MemberLoc); 1863 return Range; 1864 } 1865 1866 static bool classof(const Stmt *T) { 1867 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 1868 } 1869 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 1870 1871 // Iterators 1872 virtual child_iterator child_begin(); 1873 virtual child_iterator child_end(); 1874}; 1875 1876/// \brief Represents a C++ member access expression for which lookup 1877/// produced a set of overloaded functions. 1878/// 1879/// The member access may be explicit or implicit: 1880/// struct A { 1881/// int a, b; 1882/// int explicitAccess() { return this->a + this->A::b; } 1883/// int implicitAccess() { return a + A::b; } 1884/// }; 1885/// 1886/// In the final AST, an explicit access always becomes a MemberExpr. 1887/// An implicit access may become either a MemberExpr or a 1888/// DeclRefExpr, depending on whether the member is static. 1889class UnresolvedMemberExpr : public OverloadExpr { 1890 /// \brief Whether this member expression used the '->' operator or 1891 /// the '.' operator. 1892 bool IsArrow : 1; 1893 1894 /// \brief Whether the lookup results contain an unresolved using 1895 /// declaration. 1896 bool HasUnresolvedUsing : 1; 1897 1898 /// \brief The expression for the base pointer or class reference, 1899 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 1900 /// member expression 1901 Stmt *Base; 1902 1903 /// \brief The type of the base expression; never null. 1904 QualType BaseType; 1905 1906 /// \brief The location of the '->' or '.' operator. 1907 SourceLocation OperatorLoc; 1908 1909 UnresolvedMemberExpr(QualType T, bool Dependent, 1910 bool HasUnresolvedUsing, 1911 Expr *Base, QualType BaseType, bool IsArrow, 1912 SourceLocation OperatorLoc, 1913 NestedNameSpecifier *Qualifier, 1914 SourceRange QualifierRange, 1915 DeclarationName Member, 1916 SourceLocation MemberLoc, 1917 const TemplateArgumentListInfo *TemplateArgs); 1918 1919public: 1920 static UnresolvedMemberExpr * 1921 Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing, 1922 Expr *Base, QualType BaseType, bool IsArrow, 1923 SourceLocation OperatorLoc, 1924 NestedNameSpecifier *Qualifier, 1925 SourceRange QualifierRange, 1926 DeclarationName Member, 1927 SourceLocation MemberLoc, 1928 const TemplateArgumentListInfo *TemplateArgs); 1929 1930 /// \brief True if this is an implicit access, i.e. one in which the 1931 /// member being accessed was not written in the source. The source 1932 /// location of the operator is invalid in this case. 1933 bool isImplicitAccess() const { return Base == 0; } 1934 1935 /// \brief Retrieve the base object of this member expressions, 1936 /// e.g., the \c x in \c x.m. 1937 Expr *getBase() { 1938 assert(!isImplicitAccess()); 1939 return cast<Expr>(Base); 1940 } 1941 const Expr *getBase() const { 1942 assert(!isImplicitAccess()); 1943 return cast<Expr>(Base); 1944 } 1945 void setBase(Expr *E) { Base = E; } 1946 1947 QualType getBaseType() const { return BaseType; } 1948 1949 /// \brief Determine whether this member expression used the '->' 1950 /// operator; otherwise, it used the '.' operator. 1951 bool isArrow() const { return IsArrow; } 1952 void setArrow(bool A) { IsArrow = A; } 1953 1954 /// \brief Retrieve the location of the '->' or '.' operator. 1955 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1956 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1957 1958 /// \brief Retrieves the naming class of this lookup. 1959 CXXRecordDecl *getNamingClass() const; 1960 1961 /// \brief Retrieve the name of the member that this expression 1962 /// refers to. 1963 DeclarationName getMemberName() const { return getName(); } 1964 void setMemberName(DeclarationName N) { setName(N); } 1965 1966 // \brief Retrieve the location of the name of the member that this 1967 // expression refers to. 1968 SourceLocation getMemberLoc() const { return getNameLoc(); } 1969 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 1970 1971 /// \brief Retrieve the explicit template argument list that followed the 1972 /// member template name. 1973 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1974 assert(hasExplicitTemplateArgs()); 1975 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 1976 } 1977 1978 /// \brief Retrieve the explicit template argument list that followed the 1979 /// member template name, if any. 1980 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1981 assert(hasExplicitTemplateArgs()); 1982 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 1983 } 1984 1985 /// \brief Copies the template arguments into the given structure. 1986 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1987 getExplicitTemplateArgs().copyInto(List); 1988 } 1989 1990 /// \brief Retrieve the location of the left angle bracket following 1991 /// the member name ('<'). 1992 SourceLocation getLAngleLoc() const { 1993 return getExplicitTemplateArgs().LAngleLoc; 1994 } 1995 1996 /// \brief Retrieve the template arguments provided as part of this 1997 /// template-id. 1998 const TemplateArgumentLoc *getTemplateArgs() const { 1999 return getExplicitTemplateArgs().getTemplateArgs(); 2000 } 2001 2002 /// \brief Retrieve the number of template arguments provided as 2003 /// part of this template-id. 2004 unsigned getNumTemplateArgs() const { 2005 return getExplicitTemplateArgs().NumTemplateArgs; 2006 } 2007 2008 /// \brief Retrieve the location of the right angle bracket 2009 /// following the template arguments ('>'). 2010 SourceLocation getRAngleLoc() const { 2011 return getExplicitTemplateArgs().RAngleLoc; 2012 } 2013 2014 virtual SourceRange getSourceRange() const { 2015 SourceRange Range; 2016 if (!isImplicitAccess()) 2017 Range.setBegin(Base->getSourceRange().getBegin()); 2018 else if (getQualifier()) 2019 Range.setBegin(getQualifierRange().getBegin()); 2020 else 2021 Range.setBegin(getMemberLoc()); 2022 2023 if (hasExplicitTemplateArgs()) 2024 Range.setEnd(getRAngleLoc()); 2025 else 2026 Range.setEnd(getMemberLoc()); 2027 return Range; 2028 } 2029 2030 static bool classof(const Stmt *T) { 2031 return T->getStmtClass() == UnresolvedMemberExprClass; 2032 } 2033 static bool classof(const UnresolvedMemberExpr *) { return true; } 2034 2035 // Iterators 2036 virtual child_iterator child_begin(); 2037 virtual child_iterator child_end(); 2038}; 2039 2040inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 2041 if (isa<UnresolvedLookupExpr>(this)) 2042 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 2043 else 2044 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 2045} 2046 2047} // end namespace clang 2048 2049#endif 2050