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