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