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