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