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