ExprCXX.h revision be230c36e32142cbdcdbe9c97511d097beeecbab
1//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Expr interface and subclasses for C++ expressions. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_EXPRCXX_H 15#define LLVM_CLANG_AST_EXPRCXX_H 16 17#include "clang/Basic/TypeTraits.h" 18#include "clang/AST/Expr.h" 19#include "clang/AST/UnresolvedSet.h" 20#include "clang/AST/TemplateBase.h" 21 22namespace clang { 23 24 class CXXConstructorDecl; 25 class CXXDestructorDecl; 26 class CXXMethodDecl; 27 class CXXTemporary; 28 class TemplateArgumentListInfo; 29 30//===--------------------------------------------------------------------===// 31// C++ Expressions. 32//===--------------------------------------------------------------------===// 33 34/// \brief A call to an overloaded operator written using operator 35/// syntax. 36/// 37/// Represents a call to an overloaded operator written using operator 38/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a 39/// normal call, this AST node provides better information about the 40/// syntactic representation of the call. 41/// 42/// In a C++ template, this expression node kind will be used whenever 43/// any of the arguments are type-dependent. In this case, the 44/// function itself will be a (possibly empty) set of functions and 45/// function templates that were found by name lookup at template 46/// definition time. 47class CXXOperatorCallExpr : public CallExpr { 48 /// \brief The overloaded operator. 49 OverloadedOperatorKind Operator; 50 51public: 52 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn, 53 Expr **args, unsigned numargs, QualType t, 54 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 *getPlacementArg(unsigned i) { 1056 assert(i < NumPlacementArgs && "Index out of range"); 1057 return cast<Expr>(SubExprs[Array + i]); 1058 } 1059 const Expr *getPlacementArg(unsigned i) const { 1060 assert(i < NumPlacementArgs && "Index out of range"); 1061 return cast<Expr>(SubExprs[Array + i]); 1062 } 1063 1064 bool isParenTypeId() const { return TypeIdParens.isValid(); } 1065 SourceRange getTypeIdParens() const { return TypeIdParens; } 1066 1067 bool isGlobalNew() const { return GlobalNew; } 1068 void setGlobalNew(bool V) { GlobalNew = V; } 1069 bool hasInitializer() const { return Initializer; } 1070 void setHasInitializer(bool V) { Initializer = V; } 1071 1072 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 1073 Expr *getConstructorArg(unsigned i) { 1074 assert(i < NumConstructorArgs && "Index out of range"); 1075 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1076 } 1077 const Expr *getConstructorArg(unsigned i) const { 1078 assert(i < NumConstructorArgs && "Index out of range"); 1079 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 1080 } 1081 1082 typedef ExprIterator arg_iterator; 1083 typedef ConstExprIterator const_arg_iterator; 1084 1085 arg_iterator placement_arg_begin() { 1086 return SubExprs + Array; 1087 } 1088 arg_iterator placement_arg_end() { 1089 return SubExprs + Array + getNumPlacementArgs(); 1090 } 1091 const_arg_iterator placement_arg_begin() const { 1092 return SubExprs + Array; 1093 } 1094 const_arg_iterator placement_arg_end() const { 1095 return SubExprs + Array + getNumPlacementArgs(); 1096 } 1097 1098 arg_iterator constructor_arg_begin() { 1099 return SubExprs + Array + getNumPlacementArgs(); 1100 } 1101 arg_iterator constructor_arg_end() { 1102 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1103 } 1104 const_arg_iterator constructor_arg_begin() const { 1105 return SubExprs + Array + getNumPlacementArgs(); 1106 } 1107 const_arg_iterator constructor_arg_end() const { 1108 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1109 } 1110 1111 typedef Stmt **raw_arg_iterator; 1112 raw_arg_iterator raw_arg_begin() { return SubExprs; } 1113 raw_arg_iterator raw_arg_end() { 1114 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 1115 } 1116 const_arg_iterator raw_arg_begin() const { return SubExprs; } 1117 const_arg_iterator raw_arg_end() const { return constructor_arg_end(); } 1118 1119 SourceLocation getStartLoc() const { return StartLoc; } 1120 SourceLocation getEndLoc() const { return EndLoc; } 1121 1122 SourceLocation getConstructorLParen() const { return ConstructorLParen; } 1123 SourceLocation getConstructorRParen() const { return ConstructorRParen; } 1124 1125 virtual SourceRange getSourceRange() const { 1126 return SourceRange(StartLoc, EndLoc); 1127 } 1128 1129 static bool classof(const Stmt *T) { 1130 return T->getStmtClass() == CXXNewExprClass; 1131 } 1132 static bool classof(const CXXNewExpr *) { return true; } 1133 1134 // Iterators 1135 virtual child_iterator child_begin(); 1136 virtual child_iterator child_end(); 1137}; 1138 1139/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 1140/// calls, e.g. "delete[] pArray". 1141class CXXDeleteExpr : public Expr { 1142 // Is this a forced global delete, i.e. "::delete"? 1143 bool GlobalDelete : 1; 1144 // Is this the array form of delete, i.e. "delete[]"? 1145 bool ArrayForm : 1; 1146 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied 1147 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm 1148 // will be true). 1149 bool ArrayFormAsWritten : 1; 1150 // Points to the operator delete overload that is used. Could be a member. 1151 FunctionDecl *OperatorDelete; 1152 // The pointer expression to be deleted. 1153 Stmt *Argument; 1154 // Location of the expression. 1155 SourceLocation Loc; 1156public: 1157 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 1158 bool arrayFormAsWritten, FunctionDecl *operatorDelete, 1159 Expr *arg, SourceLocation loc) 1160 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false, 1161 arg->containsUnexpandedParameterPack()), 1162 GlobalDelete(globalDelete), 1163 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten), 1164 OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } 1165 explicit CXXDeleteExpr(EmptyShell Shell) 1166 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } 1167 1168 bool isGlobalDelete() const { return GlobalDelete; } 1169 bool isArrayForm() const { return ArrayForm; } 1170 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; } 1171 1172 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 1173 1174 Expr *getArgument() { return cast<Expr>(Argument); } 1175 const Expr *getArgument() const { return cast<Expr>(Argument); } 1176 1177 /// \brief Retrieve the type being destroyed. If the type being 1178 /// destroyed is a dependent type which may or may not be a pointer, 1179 /// return an invalid type. 1180 QualType getDestroyedType() const; 1181 1182 virtual SourceRange getSourceRange() const { 1183 return SourceRange(Loc, Argument->getLocEnd()); 1184 } 1185 1186 static bool classof(const Stmt *T) { 1187 return T->getStmtClass() == CXXDeleteExprClass; 1188 } 1189 static bool classof(const CXXDeleteExpr *) { return true; } 1190 1191 // Iterators 1192 virtual child_iterator child_begin(); 1193 virtual child_iterator child_end(); 1194 1195 friend class ASTStmtReader; 1196}; 1197 1198/// \brief Structure used to store the type being destroyed by a 1199/// pseudo-destructor expression. 1200class PseudoDestructorTypeStorage { 1201 /// \brief Either the type source information or the name of the type, if 1202 /// it couldn't be resolved due to type-dependence. 1203 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; 1204 1205 /// \brief The starting source location of the pseudo-destructor type. 1206 SourceLocation Location; 1207 1208public: 1209 PseudoDestructorTypeStorage() { } 1210 1211 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) 1212 : Type(II), Location(Loc) { } 1213 1214 PseudoDestructorTypeStorage(TypeSourceInfo *Info); 1215 1216 TypeSourceInfo *getTypeSourceInfo() const { 1217 return Type.dyn_cast<TypeSourceInfo *>(); 1218 } 1219 1220 IdentifierInfo *getIdentifier() const { 1221 return Type.dyn_cast<IdentifierInfo *>(); 1222 } 1223 1224 SourceLocation getLocation() const { return Location; } 1225}; 1226 1227/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]). 1228/// 1229/// A pseudo-destructor is an expression that looks like a member access to a 1230/// destructor of a scalar type, except that scalar types don't have 1231/// destructors. For example: 1232/// 1233/// \code 1234/// typedef int T; 1235/// void f(int *p) { 1236/// p->T::~T(); 1237/// } 1238/// \endcode 1239/// 1240/// Pseudo-destructors typically occur when instantiating templates such as: 1241/// 1242/// \code 1243/// template<typename T> 1244/// void destroy(T* ptr) { 1245/// ptr->T::~T(); 1246/// } 1247/// \endcode 1248/// 1249/// for scalar types. A pseudo-destructor expression has no run-time semantics 1250/// beyond evaluating the base expression. 1251class CXXPseudoDestructorExpr : public Expr { 1252 /// \brief The base expression (that is being destroyed). 1253 Stmt *Base; 1254 1255 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a 1256 /// period ('.'). 1257 bool IsArrow : 1; 1258 1259 /// \brief The location of the '.' or '->' operator. 1260 SourceLocation OperatorLoc; 1261 1262 /// \brief The nested-name-specifier that follows the operator, if present. 1263 NestedNameSpecifier *Qualifier; 1264 1265 /// \brief The source range that covers the nested-name-specifier, if 1266 /// present. 1267 SourceRange QualifierRange; 1268 1269 /// \brief The type that precedes the '::' in a qualified pseudo-destructor 1270 /// expression. 1271 TypeSourceInfo *ScopeType; 1272 1273 /// \brief The location of the '::' in a qualified pseudo-destructor 1274 /// expression. 1275 SourceLocation ColonColonLoc; 1276 1277 /// \brief The location of the '~'. 1278 SourceLocation TildeLoc; 1279 1280 /// \brief The type being destroyed, or its name if we were unable to 1281 /// resolve the name. 1282 PseudoDestructorTypeStorage DestroyedType; 1283 1284public: 1285 CXXPseudoDestructorExpr(ASTContext &Context, 1286 Expr *Base, bool isArrow, SourceLocation OperatorLoc, 1287 NestedNameSpecifier *Qualifier, 1288 SourceRange QualifierRange, 1289 TypeSourceInfo *ScopeType, 1290 SourceLocation ColonColonLoc, 1291 SourceLocation TildeLoc, 1292 PseudoDestructorTypeStorage DestroyedType); 1293 1294 explicit CXXPseudoDestructorExpr(EmptyShell Shell) 1295 : Expr(CXXPseudoDestructorExprClass, Shell), 1296 Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { } 1297 1298 void setBase(Expr *E) { Base = E; } 1299 Expr *getBase() const { return cast<Expr>(Base); } 1300 1301 /// \brief Determines whether this member expression actually had 1302 /// a C++ nested-name-specifier prior to the name of the member, e.g., 1303 /// x->Base::foo. 1304 bool hasQualifier() const { return Qualifier != 0; } 1305 1306 /// \brief If the member name was qualified, retrieves the source range of 1307 /// the nested-name-specifier that precedes the member name. Otherwise, 1308 /// returns an empty source range. 1309 SourceRange getQualifierRange() const { return QualifierRange; } 1310 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1311 1312 /// \brief If the member name was qualified, retrieves the 1313 /// nested-name-specifier that precedes the member name. Otherwise, returns 1314 /// NULL. 1315 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1316 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1317 1318 /// \brief Determine whether this pseudo-destructor expression was written 1319 /// using an '->' (otherwise, it used a '.'). 1320 bool isArrow() const { return IsArrow; } 1321 void setArrow(bool A) { IsArrow = A; } 1322 1323 /// \brief Retrieve the location of the '.' or '->' operator. 1324 SourceLocation getOperatorLoc() const { return OperatorLoc; } 1325 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 1326 1327 /// \brief Retrieve the scope type in a qualified pseudo-destructor 1328 /// expression. 1329 /// 1330 /// Pseudo-destructor expressions can have extra qualification within them 1331 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). 1332 /// Here, if the object type of the expression is (or may be) a scalar type, 1333 /// \p T may also be a scalar type and, therefore, cannot be part of a 1334 /// nested-name-specifier. It is stored as the "scope type" of the pseudo- 1335 /// destructor expression. 1336 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } 1337 void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; } 1338 1339 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor 1340 /// expression. 1341 SourceLocation getColonColonLoc() const { return ColonColonLoc; } 1342 void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; } 1343 1344 /// \brief Retrieve the location of the '~'. 1345 SourceLocation getTildeLoc() const { return TildeLoc; } 1346 void setTildeLoc(SourceLocation L) { TildeLoc = L; } 1347 1348 /// \brief Retrieve the source location information for the type 1349 /// being destroyed. 1350 /// 1351 /// This type-source information is available for non-dependent 1352 /// pseudo-destructor expressions and some dependent pseudo-destructor 1353 /// expressions. Returns NULL if we only have the identifier for a 1354 /// dependent pseudo-destructor expression. 1355 TypeSourceInfo *getDestroyedTypeInfo() const { 1356 return DestroyedType.getTypeSourceInfo(); 1357 } 1358 1359 /// \brief In a dependent pseudo-destructor expression for which we do not 1360 /// have full type information on the destroyed type, provides the name 1361 /// of the destroyed type. 1362 IdentifierInfo *getDestroyedTypeIdentifier() const { 1363 return DestroyedType.getIdentifier(); 1364 } 1365 1366 /// \brief Retrieve the type being destroyed. 1367 QualType getDestroyedType() const; 1368 1369 /// \brief Retrieve the starting location of the type being destroyed. 1370 SourceLocation getDestroyedTypeLoc() const { 1371 return DestroyedType.getLocation(); 1372 } 1373 1374 /// \brief Set the name of destroyed type for a dependent pseudo-destructor 1375 /// expression. 1376 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { 1377 DestroyedType = PseudoDestructorTypeStorage(II, Loc); 1378 } 1379 1380 /// \brief Set the destroyed type. 1381 void setDestroyedType(TypeSourceInfo *Info) { 1382 DestroyedType = PseudoDestructorTypeStorage(Info); 1383 } 1384 1385 virtual SourceRange getSourceRange() const; 1386 1387 static bool classof(const Stmt *T) { 1388 return T->getStmtClass() == CXXPseudoDestructorExprClass; 1389 } 1390 static bool classof(const CXXPseudoDestructorExpr *) { return true; } 1391 1392 // Iterators 1393 virtual child_iterator child_begin(); 1394 virtual child_iterator child_end(); 1395}; 1396 1397/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 1398/// implementation of TR1/C++0x type trait templates. 1399/// Example: 1400/// __is_pod(int) == true 1401/// __is_enum(std::string) == false 1402class UnaryTypeTraitExpr : public Expr { 1403 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned. 1404 unsigned UTT : 31; 1405 /// The value of the type trait. Unspecified if dependent. 1406 bool Value : 1; 1407 1408 /// Loc - The location of the type trait keyword. 1409 SourceLocation Loc; 1410 1411 /// RParen - The location of the closing paren. 1412 SourceLocation RParen; 1413 1414 /// The type being queried. 1415 TypeSourceInfo *QueriedType; 1416 1417public: 1418 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, 1419 TypeSourceInfo *queried, bool value, 1420 SourceLocation rparen, QualType ty) 1421 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, 1422 false, queried->getType()->isDependentType(), 1423 queried->getType()->containsUnexpandedParameterPack()), 1424 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { } 1425 1426 explicit UnaryTypeTraitExpr(EmptyShell Empty) 1427 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false), 1428 QueriedType() { } 1429 1430 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 1431 1432 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); } 1433 1434 QualType getQueriedType() const { return QueriedType->getType(); } 1435 1436 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } 1437 1438 bool getValue() const { return Value; } 1439 1440 static bool classof(const Stmt *T) { 1441 return T->getStmtClass() == UnaryTypeTraitExprClass; 1442 } 1443 static bool classof(const UnaryTypeTraitExpr *) { return true; } 1444 1445 // Iterators 1446 virtual child_iterator child_begin(); 1447 virtual child_iterator child_end(); 1448 1449 friend class ASTStmtReader; 1450}; 1451 1452/// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the 1453/// implementation of TR1/C++0x type trait templates. 1454/// Example: 1455/// __is_base_of(Base, Derived) == true 1456class BinaryTypeTraitExpr : public Expr { 1457 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned. 1458 unsigned BTT : 8; 1459 1460 /// The value of the type trait. Unspecified if dependent. 1461 bool Value : 1; 1462 1463 /// Loc - The location of the type trait keyword. 1464 SourceLocation Loc; 1465 1466 /// RParen - The location of the closing paren. 1467 SourceLocation RParen; 1468 1469 /// The lhs type being queried. 1470 TypeSourceInfo *LhsType; 1471 1472 /// The rhs type being queried. 1473 TypeSourceInfo *RhsType; 1474 1475public: 1476 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt, 1477 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType, 1478 bool value, SourceLocation rparen, QualType ty) 1479 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false, 1480 lhsType->getType()->isDependentType() || 1481 rhsType->getType()->isDependentType(), 1482 (lhsType->getType()->containsUnexpandedParameterPack() || 1483 rhsType->getType()->containsUnexpandedParameterPack())), 1484 BTT(btt), Value(value), Loc(loc), RParen(rparen), 1485 LhsType(lhsType), RhsType(rhsType) { } 1486 1487 1488 explicit BinaryTypeTraitExpr(EmptyShell Empty) 1489 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false), 1490 LhsType(), RhsType() { } 1491 1492 virtual SourceRange getSourceRange() const { 1493 return SourceRange(Loc, RParen); 1494 } 1495 1496 BinaryTypeTrait getTrait() const { 1497 return static_cast<BinaryTypeTrait>(BTT); 1498 } 1499 1500 QualType getLhsType() const { return LhsType->getType(); } 1501 QualType getRhsType() const { return RhsType->getType(); } 1502 1503 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; } 1504 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; } 1505 1506 bool getValue() const { assert(!isTypeDependent()); return Value; } 1507 1508 static bool classof(const Stmt *T) { 1509 return T->getStmtClass() == BinaryTypeTraitExprClass; 1510 } 1511 static bool classof(const BinaryTypeTraitExpr *) { return true; } 1512 1513 // Iterators 1514 virtual child_iterator child_begin(); 1515 virtual child_iterator child_end(); 1516 1517 friend class ASTStmtReader; 1518}; 1519 1520/// \brief A reference to an overloaded function set, either an 1521/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr. 1522class OverloadExpr : public Expr { 1523 /// The results. These are undesugared, which is to say, they may 1524 /// include UsingShadowDecls. Access is relative to the naming 1525 /// class. 1526 // FIXME: Allocate this data after the OverloadExpr subclass. 1527 DeclAccessPair *Results; 1528 unsigned NumResults; 1529 1530 /// The common name of these declarations. 1531 DeclarationNameInfo NameInfo; 1532 1533 /// The scope specifier, if any. 1534 NestedNameSpecifier *Qualifier; 1535 1536 /// The source range of the scope specifier. 1537 SourceRange QualifierRange; 1538 1539protected: 1540 /// True if the name was a template-id. 1541 bool HasExplicitTemplateArgs; 1542 1543 OverloadExpr(StmtClass K, ASTContext &C, 1544 NestedNameSpecifier *Qualifier, SourceRange QRange, 1545 const DeclarationNameInfo &NameInfo, 1546 const TemplateArgumentListInfo *TemplateArgs, 1547 UnresolvedSetIterator Begin, UnresolvedSetIterator End, 1548 bool KnownDependent = false, 1549 bool KnownContainsUnexpandedParameterPack = false); 1550 1551 OverloadExpr(StmtClass K, EmptyShell Empty) 1552 : Expr(K, Empty), Results(0), NumResults(0), 1553 Qualifier(0), HasExplicitTemplateArgs(false) { } 1554 1555 void initializeResults(ASTContext &C, 1556 UnresolvedSetIterator Begin, 1557 UnresolvedSetIterator End); 1558 1559public: 1560 struct FindResult { 1561 OverloadExpr *Expression; 1562 bool IsAddressOfOperand; 1563 bool HasFormOfMemberPointer; 1564 }; 1565 1566 /// Finds the overloaded expression in the given expression of 1567 /// OverloadTy. 1568 /// 1569 /// \return the expression (which must be there) and true if it has 1570 /// the particular form of a member pointer expression 1571 static FindResult find(Expr *E) { 1572 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); 1573 1574 FindResult Result; 1575 1576 E = E->IgnoreParens(); 1577 if (isa<UnaryOperator>(E)) { 1578 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); 1579 E = cast<UnaryOperator>(E)->getSubExpr(); 1580 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens()); 1581 1582 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); 1583 Result.IsAddressOfOperand = true; 1584 Result.Expression = Ovl; 1585 } else { 1586 Result.HasFormOfMemberPointer = false; 1587 Result.IsAddressOfOperand = false; 1588 Result.Expression = cast<OverloadExpr>(E); 1589 } 1590 1591 return Result; 1592 } 1593 1594 /// Gets the naming class of this lookup, if any. 1595 CXXRecordDecl *getNamingClass() const; 1596 1597 typedef UnresolvedSetImpl::iterator decls_iterator; 1598 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); } 1599 decls_iterator decls_end() const { 1600 return UnresolvedSetIterator(Results + NumResults); 1601 } 1602 1603 /// Gets the number of declarations in the unresolved set. 1604 unsigned getNumDecls() const { return NumResults; } 1605 1606 /// Gets the full name info. 1607 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1608 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; } 1609 1610 /// Gets the name looked up. 1611 DeclarationName getName() const { return NameInfo.getName(); } 1612 void setName(DeclarationName N) { NameInfo.setName(N); } 1613 1614 /// Gets the location of the name. 1615 SourceLocation getNameLoc() const { return NameInfo.getLoc(); } 1616 void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); } 1617 1618 /// Fetches the nested-name qualifier, if one was given. 1619 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1620 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1621 1622 /// Fetches the range of the nested-name qualifier. 1623 SourceRange getQualifierRange() const { return QualifierRange; } 1624 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1625 1626 /// \brief Determines whether this expression had an explicit 1627 /// template argument list, e.g. f<int>. 1628 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1629 1630 ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below 1631 1632 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1633 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs(); 1634 } 1635 1636 /// \brief Retrieves the optional explicit template arguments. 1637 /// This points to the same data as getExplicitTemplateArgs(), but 1638 /// returns null if there are no explicit template arguments. 1639 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1640 if (!hasExplicitTemplateArgs()) return 0; 1641 return &getExplicitTemplateArgs(); 1642 } 1643 1644 static bool classof(const Stmt *T) { 1645 return T->getStmtClass() == UnresolvedLookupExprClass || 1646 T->getStmtClass() == UnresolvedMemberExprClass; 1647 } 1648 static bool classof(const OverloadExpr *) { return true; } 1649 1650 friend class ASTStmtReader; 1651 friend class ASTStmtWriter; 1652}; 1653 1654/// \brief A reference to a name which we were able to look up during 1655/// parsing but could not resolve to a specific declaration. This 1656/// arises in several ways: 1657/// * we might be waiting for argument-dependent lookup 1658/// * the name might resolve to an overloaded function 1659/// and eventually: 1660/// * the lookup might have included a function template 1661/// These never include UnresolvedUsingValueDecls, which are always 1662/// class members and therefore appear only in 1663/// UnresolvedMemberLookupExprs. 1664class UnresolvedLookupExpr : public OverloadExpr { 1665 /// True if these lookup results should be extended by 1666 /// argument-dependent lookup if this is the operand of a function 1667 /// call. 1668 bool RequiresADL; 1669 1670 /// True if these lookup results are overloaded. This is pretty 1671 /// trivially rederivable if we urgently need to kill this field. 1672 bool Overloaded; 1673 1674 /// The naming class (C++ [class.access.base]p5) of the lookup, if 1675 /// any. This can generally be recalculated from the context chain, 1676 /// but that can be fairly expensive for unqualified lookups. If we 1677 /// want to improve memory use here, this could go in a union 1678 /// against the qualified-lookup bits. 1679 CXXRecordDecl *NamingClass; 1680 1681 UnresolvedLookupExpr(ASTContext &C, 1682 CXXRecordDecl *NamingClass, 1683 NestedNameSpecifier *Qualifier, SourceRange QRange, 1684 const DeclarationNameInfo &NameInfo, 1685 bool RequiresADL, bool Overloaded, 1686 const TemplateArgumentListInfo *TemplateArgs, 1687 UnresolvedSetIterator Begin, UnresolvedSetIterator End) 1688 : OverloadExpr(UnresolvedLookupExprClass, C, Qualifier, QRange, NameInfo, 1689 TemplateArgs, Begin, End), 1690 RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass) 1691 {} 1692 1693 UnresolvedLookupExpr(EmptyShell Empty) 1694 : OverloadExpr(UnresolvedLookupExprClass, Empty), 1695 RequiresADL(false), Overloaded(false), NamingClass(0) 1696 {} 1697 1698public: 1699 static UnresolvedLookupExpr *Create(ASTContext &C, 1700 CXXRecordDecl *NamingClass, 1701 NestedNameSpecifier *Qualifier, 1702 SourceRange QualifierRange, 1703 const DeclarationNameInfo &NameInfo, 1704 bool ADL, bool Overloaded, 1705 UnresolvedSetIterator Begin, 1706 UnresolvedSetIterator End) { 1707 return new(C) UnresolvedLookupExpr(C, NamingClass, Qualifier, 1708 QualifierRange, NameInfo, ADL, 1709 Overloaded, 0, Begin, End); 1710 } 1711 1712 static UnresolvedLookupExpr *Create(ASTContext &C, 1713 CXXRecordDecl *NamingClass, 1714 NestedNameSpecifier *Qualifier, 1715 SourceRange QualifierRange, 1716 const DeclarationNameInfo &NameInfo, 1717 bool ADL, 1718 const TemplateArgumentListInfo &Args, 1719 UnresolvedSetIterator Begin, 1720 UnresolvedSetIterator End); 1721 1722 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C, 1723 unsigned NumTemplateArgs); 1724 1725 /// True if this declaration should be extended by 1726 /// argument-dependent lookup. 1727 bool requiresADL() const { return RequiresADL; } 1728 void setRequiresADL(bool V) { RequiresADL = V; } 1729 1730 /// True if this lookup is overloaded. 1731 bool isOverloaded() const { return Overloaded; } 1732 void setOverloaded(bool V) { Overloaded = V; } 1733 1734 /// Gets the 'naming class' (in the sense of C++0x 1735 /// [class.access.base]p5) of the lookup. This is the scope 1736 /// that was looked in to find these results. 1737 CXXRecordDecl *getNamingClass() const { return NamingClass; } 1738 void setNamingClass(CXXRecordDecl *D) { NamingClass = D; } 1739 1740 // Note that, inconsistently with the explicit-template-argument AST 1741 // nodes, users are *forbidden* from calling these methods on objects 1742 // without explicit template arguments. 1743 1744 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1745 assert(hasExplicitTemplateArgs()); 1746 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1747 } 1748 1749 /// Gets a reference to the explicit template argument list. 1750 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1751 assert(hasExplicitTemplateArgs()); 1752 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1753 } 1754 1755 /// \brief Retrieves the optional explicit template arguments. 1756 /// This points to the same data as getExplicitTemplateArgs(), but 1757 /// returns null if there are no explicit template arguments. 1758 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1759 if (!hasExplicitTemplateArgs()) return 0; 1760 return &getExplicitTemplateArgs(); 1761 } 1762 1763 /// \brief Copies the template arguments (if present) into the given 1764 /// structure. 1765 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1766 getExplicitTemplateArgs().copyInto(List); 1767 } 1768 1769 SourceLocation getLAngleLoc() const { 1770 return getExplicitTemplateArgs().LAngleLoc; 1771 } 1772 1773 SourceLocation getRAngleLoc() const { 1774 return getExplicitTemplateArgs().RAngleLoc; 1775 } 1776 1777 TemplateArgumentLoc const *getTemplateArgs() const { 1778 return getExplicitTemplateArgs().getTemplateArgs(); 1779 } 1780 1781 unsigned getNumTemplateArgs() const { 1782 return getExplicitTemplateArgs().NumTemplateArgs; 1783 } 1784 1785 virtual SourceRange getSourceRange() const { 1786 SourceRange Range(getNameInfo().getSourceRange()); 1787 if (getQualifier()) Range.setBegin(getQualifierRange().getBegin()); 1788 if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc()); 1789 return Range; 1790 } 1791 1792 virtual StmtIterator child_begin(); 1793 virtual StmtIterator child_end(); 1794 1795 static bool classof(const Stmt *T) { 1796 return T->getStmtClass() == UnresolvedLookupExprClass; 1797 } 1798 static bool classof(const UnresolvedLookupExpr *) { return true; } 1799}; 1800 1801/// \brief A qualified reference to a name whose declaration cannot 1802/// yet be resolved. 1803/// 1804/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that 1805/// it expresses a reference to a declaration such as 1806/// X<T>::value. The difference, however, is that an 1807/// DependentScopeDeclRefExpr node is used only within C++ templates when 1808/// the qualification (e.g., X<T>::) refers to a dependent type. In 1809/// this case, X<T>::value cannot resolve to a declaration because the 1810/// declaration will differ from on instantiation of X<T> to the 1811/// next. Therefore, DependentScopeDeclRefExpr keeps track of the 1812/// qualifier (X<T>::) and the name of the entity being referenced 1813/// ("value"). Such expressions will instantiate to a DeclRefExpr once the 1814/// declaration can be found. 1815class DependentScopeDeclRefExpr : public Expr { 1816 /// The name of the entity we will be referencing. 1817 DeclarationNameInfo NameInfo; 1818 1819 /// QualifierRange - The source range that covers the 1820 /// nested-name-specifier. 1821 SourceRange QualifierRange; 1822 1823 /// \brief The nested-name-specifier that qualifies this unresolved 1824 /// declaration name. 1825 NestedNameSpecifier *Qualifier; 1826 1827 /// \brief Whether the name includes explicit template arguments. 1828 bool HasExplicitTemplateArgs; 1829 1830 DependentScopeDeclRefExpr(QualType T, 1831 NestedNameSpecifier *Qualifier, 1832 SourceRange QualifierRange, 1833 const DeclarationNameInfo &NameInfo, 1834 const TemplateArgumentListInfo *Args); 1835 1836public: 1837 static DependentScopeDeclRefExpr *Create(ASTContext &C, 1838 NestedNameSpecifier *Qualifier, 1839 SourceRange QualifierRange, 1840 const DeclarationNameInfo &NameInfo, 1841 const TemplateArgumentListInfo *TemplateArgs = 0); 1842 1843 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C, 1844 unsigned NumTemplateArgs); 1845 1846 /// \brief Retrieve the name that this expression refers to. 1847 const DeclarationNameInfo &getNameInfo() const { return NameInfo; } 1848 void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; } 1849 1850 /// \brief Retrieve the name that this expression refers to. 1851 DeclarationName getDeclName() const { return NameInfo.getName(); } 1852 void setDeclName(DeclarationName N) { NameInfo.setName(N); } 1853 1854 /// \brief Retrieve the location of the name within the expression. 1855 SourceLocation getLocation() const { return NameInfo.getLoc(); } 1856 void setLocation(SourceLocation L) { NameInfo.setLoc(L); } 1857 1858 /// \brief Retrieve the source range of the nested-name-specifier. 1859 SourceRange getQualifierRange() const { return QualifierRange; } 1860 void setQualifierRange(SourceRange R) { QualifierRange = R; } 1861 1862 /// \brief Retrieve the nested-name-specifier that qualifies this 1863 /// declaration. 1864 NestedNameSpecifier *getQualifier() const { return Qualifier; } 1865 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 1866 1867 /// Determines whether this lookup had explicit template arguments. 1868 bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; } 1869 1870 // Note that, inconsistently with the explicit-template-argument AST 1871 // nodes, users are *forbidden* from calling these methods on objects 1872 // without explicit template arguments. 1873 1874 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 1875 assert(hasExplicitTemplateArgs()); 1876 return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1); 1877 } 1878 1879 /// Gets a reference to the explicit template argument list. 1880 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 1881 assert(hasExplicitTemplateArgs()); 1882 return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1); 1883 } 1884 1885 /// \brief Retrieves the optional explicit template arguments. 1886 /// This points to the same data as getExplicitTemplateArgs(), but 1887 /// returns null if there are no explicit template arguments. 1888 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 1889 if (!hasExplicitTemplateArgs()) return 0; 1890 return &getExplicitTemplateArgs(); 1891 } 1892 1893 /// \brief Copies the template arguments (if present) into the given 1894 /// structure. 1895 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1896 getExplicitTemplateArgs().copyInto(List); 1897 } 1898 1899 SourceLocation getLAngleLoc() const { 1900 return getExplicitTemplateArgs().LAngleLoc; 1901 } 1902 1903 SourceLocation getRAngleLoc() const { 1904 return getExplicitTemplateArgs().RAngleLoc; 1905 } 1906 1907 TemplateArgumentLoc const *getTemplateArgs() const { 1908 return getExplicitTemplateArgs().getTemplateArgs(); 1909 } 1910 1911 unsigned getNumTemplateArgs() const { 1912 return getExplicitTemplateArgs().NumTemplateArgs; 1913 } 1914 1915 virtual SourceRange getSourceRange() const { 1916 SourceRange Range(QualifierRange.getBegin(), getLocation()); 1917 if (hasExplicitTemplateArgs()) 1918 Range.setEnd(getRAngleLoc()); 1919 return Range; 1920 } 1921 1922 static bool classof(const Stmt *T) { 1923 return T->getStmtClass() == DependentScopeDeclRefExprClass; 1924 } 1925 static bool classof(const DependentScopeDeclRefExpr *) { return true; } 1926 1927 virtual StmtIterator child_begin(); 1928 virtual StmtIterator child_end(); 1929 1930 friend class ASTStmtReader; 1931 friend class ASTStmtWriter; 1932}; 1933 1934/// Represents an expression --- generally a full-expression --- which 1935/// introduces cleanups to be run at the end of the sub-expression's 1936/// evaluation. The most common source of expression-introduced 1937/// cleanups is temporary objects in C++, but several other C++ 1938/// expressions can create cleanups. 1939class ExprWithCleanups : public Expr { 1940 Stmt *SubExpr; 1941 1942 CXXTemporary **Temps; 1943 unsigned NumTemps; 1944 1945 ExprWithCleanups(ASTContext &C, Expr *SubExpr, 1946 CXXTemporary **Temps, unsigned NumTemps); 1947 1948public: 1949 ExprWithCleanups(EmptyShell Empty) 1950 : Expr(ExprWithCleanupsClass, Empty), 1951 SubExpr(0), Temps(0), NumTemps(0) {} 1952 1953 static ExprWithCleanups *Create(ASTContext &C, Expr *SubExpr, 1954 CXXTemporary **Temps, 1955 unsigned NumTemps); 1956 1957 unsigned getNumTemporaries() const { return NumTemps; } 1958 void setNumTemporaries(ASTContext &C, unsigned N); 1959 1960 CXXTemporary *getTemporary(unsigned i) { 1961 assert(i < NumTemps && "Index out of range"); 1962 return Temps[i]; 1963 } 1964 const CXXTemporary *getTemporary(unsigned i) const { 1965 return const_cast<ExprWithCleanups*>(this)->getTemporary(i); 1966 } 1967 void setTemporary(unsigned i, CXXTemporary *T) { 1968 assert(i < NumTemps && "Index out of range"); 1969 Temps[i] = T; 1970 } 1971 1972 Expr *getSubExpr() { return cast<Expr>(SubExpr); } 1973 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } 1974 void setSubExpr(Expr *E) { SubExpr = E; } 1975 1976 virtual SourceRange getSourceRange() const { 1977 return SubExpr->getSourceRange(); 1978 } 1979 1980 // Implement isa/cast/dyncast/etc. 1981 static bool classof(const Stmt *T) { 1982 return T->getStmtClass() == ExprWithCleanupsClass; 1983 } 1984 static bool classof(const ExprWithCleanups *) { return true; } 1985 1986 // Iterators 1987 virtual child_iterator child_begin(); 1988 virtual child_iterator child_end(); 1989}; 1990 1991/// \brief Describes an explicit type conversion that uses functional 1992/// notion but could not be resolved because one or more arguments are 1993/// type-dependent. 1994/// 1995/// The explicit type conversions expressed by 1996/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN), 1997/// where \c T is some type and \c a1, a2, ..., aN are values, and 1998/// either \C T is a dependent type or one or more of the \c a's is 1999/// type-dependent. For example, this would occur in a template such 2000/// as: 2001/// 2002/// \code 2003/// template<typename T, typename A1> 2004/// inline T make_a(const A1& a1) { 2005/// return T(a1); 2006/// } 2007/// \endcode 2008/// 2009/// When the returned expression is instantiated, it may resolve to a 2010/// constructor call, conversion function call, or some kind of type 2011/// conversion. 2012class CXXUnresolvedConstructExpr : public Expr { 2013 /// \brief The type being constructed. 2014 TypeSourceInfo *Type; 2015 2016 /// \brief The location of the left parentheses ('('). 2017 SourceLocation LParenLoc; 2018 2019 /// \brief The location of the right parentheses (')'). 2020 SourceLocation RParenLoc; 2021 2022 /// \brief The number of arguments used to construct the type. 2023 unsigned NumArgs; 2024 2025 CXXUnresolvedConstructExpr(TypeSourceInfo *Type, 2026 SourceLocation LParenLoc, 2027 Expr **Args, 2028 unsigned NumArgs, 2029 SourceLocation RParenLoc); 2030 2031 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) 2032 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { } 2033 2034 friend class ASTStmtReader; 2035 2036public: 2037 static CXXUnresolvedConstructExpr *Create(ASTContext &C, 2038 TypeSourceInfo *Type, 2039 SourceLocation LParenLoc, 2040 Expr **Args, 2041 unsigned NumArgs, 2042 SourceLocation RParenLoc); 2043 2044 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C, 2045 unsigned NumArgs); 2046 2047 /// \brief Retrieve the type that is being constructed, as specified 2048 /// in the source code. 2049 QualType getTypeAsWritten() const { return Type->getType(); } 2050 2051 /// \brief Retrieve the type source information for the type being 2052 /// constructed. 2053 TypeSourceInfo *getTypeSourceInfo() const { return Type; } 2054 2055 /// \brief Retrieve the location of the left parentheses ('(') that 2056 /// precedes the argument list. 2057 SourceLocation getLParenLoc() const { return LParenLoc; } 2058 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2059 2060 /// \brief Retrieve the location of the right parentheses (')') that 2061 /// follows the argument list. 2062 SourceLocation getRParenLoc() const { return RParenLoc; } 2063 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2064 2065 /// \brief Retrieve the number of arguments. 2066 unsigned arg_size() const { return NumArgs; } 2067 2068 typedef Expr** arg_iterator; 2069 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); } 2070 arg_iterator arg_end() { return arg_begin() + NumArgs; } 2071 2072 typedef const Expr* const * const_arg_iterator; 2073 const_arg_iterator arg_begin() const { 2074 return reinterpret_cast<const Expr* const *>(this + 1); 2075 } 2076 const_arg_iterator arg_end() const { 2077 return arg_begin() + NumArgs; 2078 } 2079 2080 Expr *getArg(unsigned I) { 2081 assert(I < NumArgs && "Argument index out-of-range"); 2082 return *(arg_begin() + I); 2083 } 2084 2085 const Expr *getArg(unsigned I) const { 2086 assert(I < NumArgs && "Argument index out-of-range"); 2087 return *(arg_begin() + I); 2088 } 2089 2090 void setArg(unsigned I, Expr *E) { 2091 assert(I < NumArgs && "Argument index out-of-range"); 2092 *(arg_begin() + I) = E; 2093 } 2094 2095 virtual SourceRange getSourceRange() const; 2096 2097 static bool classof(const Stmt *T) { 2098 return T->getStmtClass() == CXXUnresolvedConstructExprClass; 2099 } 2100 static bool classof(const CXXUnresolvedConstructExpr *) { return true; } 2101 2102 // Iterators 2103 virtual child_iterator child_begin(); 2104 virtual child_iterator child_end(); 2105}; 2106 2107/// \brief Represents a C++ member access expression where the actual 2108/// member referenced could not be resolved because the base 2109/// expression or the member name was dependent. 2110/// 2111/// Like UnresolvedMemberExprs, these can be either implicit or 2112/// explicit accesses. It is only possible to get one of these with 2113/// an implicit access if a qualifier is provided. 2114class CXXDependentScopeMemberExpr : public Expr { 2115 /// \brief The expression for the base pointer or class reference, 2116 /// e.g., the \c x in x.f. Can be null in implicit accesses. 2117 Stmt *Base; 2118 2119 /// \brief The type of the base expression. Never null, even for 2120 /// implicit accesses. 2121 QualType BaseType; 2122 2123 /// \brief Whether this member expression used the '->' operator or 2124 /// the '.' operator. 2125 bool IsArrow : 1; 2126 2127 /// \brief Whether this member expression has explicitly-specified template 2128 /// arguments. 2129 bool HasExplicitTemplateArgs : 1; 2130 2131 /// \brief The location of the '->' or '.' operator. 2132 SourceLocation OperatorLoc; 2133 2134 /// \brief The nested-name-specifier that precedes the member name, if any. 2135 NestedNameSpecifier *Qualifier; 2136 2137 /// \brief The source range covering the nested name specifier. 2138 SourceRange QualifierRange; 2139 2140 /// \brief In a qualified member access expression such as t->Base::f, this 2141 /// member stores the resolves of name lookup in the context of the member 2142 /// access expression, to be used at instantiation time. 2143 /// 2144 /// FIXME: This member, along with the Qualifier and QualifierRange, could 2145 /// be stuck into a structure that is optionally allocated at the end of 2146 /// the CXXDependentScopeMemberExpr, to save space in the common case. 2147 NamedDecl *FirstQualifierFoundInScope; 2148 2149 /// \brief The member to which this member expression refers, which 2150 /// can be name, overloaded operator, or destructor. 2151 /// FIXME: could also be a template-id 2152 DeclarationNameInfo MemberNameInfo; 2153 2154 CXXDependentScopeMemberExpr(ASTContext &C, 2155 Expr *Base, QualType BaseType, bool IsArrow, 2156 SourceLocation OperatorLoc, 2157 NestedNameSpecifier *Qualifier, 2158 SourceRange QualifierRange, 2159 NamedDecl *FirstQualifierFoundInScope, 2160 DeclarationNameInfo MemberNameInfo, 2161 const TemplateArgumentListInfo *TemplateArgs); 2162 2163public: 2164 CXXDependentScopeMemberExpr(ASTContext &C, 2165 Expr *Base, QualType BaseType, 2166 bool IsArrow, 2167 SourceLocation OperatorLoc, 2168 NestedNameSpecifier *Qualifier, 2169 SourceRange QualifierRange, 2170 NamedDecl *FirstQualifierFoundInScope, 2171 DeclarationNameInfo MemberNameInfo); 2172 2173 static CXXDependentScopeMemberExpr * 2174 Create(ASTContext &C, 2175 Expr *Base, QualType BaseType, bool IsArrow, 2176 SourceLocation OperatorLoc, 2177 NestedNameSpecifier *Qualifier, 2178 SourceRange QualifierRange, 2179 NamedDecl *FirstQualifierFoundInScope, 2180 DeclarationNameInfo MemberNameInfo, 2181 const TemplateArgumentListInfo *TemplateArgs); 2182 2183 static CXXDependentScopeMemberExpr * 2184 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2185 2186 /// \brief True if this is an implicit access, i.e. one in which the 2187 /// member being accessed was not written in the source. The source 2188 /// location of the operator is invalid in this case. 2189 bool isImplicitAccess() const { return Base == 0; } 2190 2191 /// \brief Retrieve the base object of this member expressions, 2192 /// e.g., the \c x in \c x.m. 2193 Expr *getBase() const { 2194 assert(!isImplicitAccess()); 2195 return cast<Expr>(Base); 2196 } 2197 void setBase(Expr *E) { Base = E; } 2198 2199 QualType getBaseType() const { return BaseType; } 2200 void setBaseType(QualType T) { BaseType = T; } 2201 2202 /// \brief Determine whether this member expression used the '->' 2203 /// operator; otherwise, it used the '.' operator. 2204 bool isArrow() const { return IsArrow; } 2205 void setArrow(bool A) { IsArrow = A; } 2206 2207 /// \brief Retrieve the location of the '->' or '.' operator. 2208 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2209 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2210 2211 /// \brief Retrieve the nested-name-specifier that qualifies the member 2212 /// name. 2213 NestedNameSpecifier *getQualifier() const { return Qualifier; } 2214 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } 2215 2216 /// \brief Retrieve the source range covering the nested-name-specifier 2217 /// that qualifies the member name. 2218 SourceRange getQualifierRange() const { return QualifierRange; } 2219 void setQualifierRange(SourceRange R) { QualifierRange = R; } 2220 2221 /// \brief Retrieve the first part of the nested-name-specifier that was 2222 /// found in the scope of the member access expression when the member access 2223 /// was initially parsed. 2224 /// 2225 /// This function only returns a useful result when member access expression 2226 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration 2227 /// returned by this function describes what was found by unqualified name 2228 /// lookup for the identifier "Base" within the scope of the member access 2229 /// expression itself. At template instantiation time, this information is 2230 /// combined with the results of name lookup into the type of the object 2231 /// expression itself (the class type of x). 2232 NamedDecl *getFirstQualifierFoundInScope() const { 2233 return FirstQualifierFoundInScope; 2234 } 2235 void setFirstQualifierFoundInScope(NamedDecl *D) { 2236 FirstQualifierFoundInScope = D; 2237 } 2238 2239 /// \brief Retrieve the name of the member that this expression 2240 /// refers to. 2241 const DeclarationNameInfo &getMemberNameInfo() const { 2242 return MemberNameInfo; 2243 } 2244 void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; } 2245 2246 /// \brief Retrieve the name of the member that this expression 2247 /// refers to. 2248 DeclarationName getMember() const { return MemberNameInfo.getName(); } 2249 void setMember(DeclarationName N) { MemberNameInfo.setName(N); } 2250 2251 // \brief Retrieve the location of the name of the member that this 2252 // expression refers to. 2253 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } 2254 void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); } 2255 2256 /// \brief Determines whether this member expression actually had a C++ 2257 /// template argument list explicitly specified, e.g., x.f<int>. 2258 bool hasExplicitTemplateArgs() const { 2259 return HasExplicitTemplateArgs; 2260 } 2261 2262 /// \brief Retrieve the explicit template argument list that followed the 2263 /// member template name, if any. 2264 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2265 assert(HasExplicitTemplateArgs); 2266 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2267 } 2268 2269 /// \brief Retrieve the explicit template argument list that followed the 2270 /// member template name, if any. 2271 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2272 return const_cast<CXXDependentScopeMemberExpr *>(this) 2273 ->getExplicitTemplateArgs(); 2274 } 2275 2276 /// \brief Retrieves the optional explicit template arguments. 2277 /// This points to the same data as getExplicitTemplateArgs(), but 2278 /// returns null if there are no explicit template arguments. 2279 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2280 if (!hasExplicitTemplateArgs()) return 0; 2281 return &getExplicitTemplateArgs(); 2282 } 2283 2284 /// \brief Copies the template arguments (if present) into the given 2285 /// structure. 2286 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2287 getExplicitTemplateArgs().copyInto(List); 2288 } 2289 2290 /// \brief Initializes the template arguments using the given structure. 2291 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) { 2292 getExplicitTemplateArgs().initializeFrom(List); 2293 } 2294 2295 /// \brief Retrieve the location of the left angle bracket following the 2296 /// member name ('<'), if any. 2297 SourceLocation getLAngleLoc() const { 2298 return getExplicitTemplateArgs().LAngleLoc; 2299 } 2300 2301 /// \brief Retrieve the template arguments provided as part of this 2302 /// template-id. 2303 const TemplateArgumentLoc *getTemplateArgs() const { 2304 return getExplicitTemplateArgs().getTemplateArgs(); 2305 } 2306 2307 /// \brief Retrieve the number of template arguments provided as part of this 2308 /// template-id. 2309 unsigned getNumTemplateArgs() const { 2310 return getExplicitTemplateArgs().NumTemplateArgs; 2311 } 2312 2313 /// \brief Retrieve the location of the right angle bracket following the 2314 /// template arguments ('>'). 2315 SourceLocation getRAngleLoc() const { 2316 return getExplicitTemplateArgs().RAngleLoc; 2317 } 2318 2319 virtual SourceRange getSourceRange() const { 2320 SourceRange Range; 2321 if (!isImplicitAccess()) 2322 Range.setBegin(Base->getSourceRange().getBegin()); 2323 else if (getQualifier()) 2324 Range.setBegin(getQualifierRange().getBegin()); 2325 else 2326 Range.setBegin(MemberNameInfo.getBeginLoc()); 2327 2328 if (hasExplicitTemplateArgs()) 2329 Range.setEnd(getRAngleLoc()); 2330 else 2331 Range.setEnd(MemberNameInfo.getEndLoc()); 2332 return Range; 2333 } 2334 2335 static bool classof(const Stmt *T) { 2336 return T->getStmtClass() == CXXDependentScopeMemberExprClass; 2337 } 2338 static bool classof(const CXXDependentScopeMemberExpr *) { return true; } 2339 2340 // Iterators 2341 virtual child_iterator child_begin(); 2342 virtual child_iterator child_end(); 2343 2344 friend class ASTStmtReader; 2345 friend class ASTStmtWriter; 2346}; 2347 2348/// \brief Represents a C++ member access expression for which lookup 2349/// produced a set of overloaded functions. 2350/// 2351/// The member access may be explicit or implicit: 2352/// struct A { 2353/// int a, b; 2354/// int explicitAccess() { return this->a + this->A::b; } 2355/// int implicitAccess() { return a + A::b; } 2356/// }; 2357/// 2358/// In the final AST, an explicit access always becomes a MemberExpr. 2359/// An implicit access may become either a MemberExpr or a 2360/// DeclRefExpr, depending on whether the member is static. 2361class UnresolvedMemberExpr : public OverloadExpr { 2362 /// \brief Whether this member expression used the '->' operator or 2363 /// the '.' operator. 2364 bool IsArrow : 1; 2365 2366 /// \brief Whether the lookup results contain an unresolved using 2367 /// declaration. 2368 bool HasUnresolvedUsing : 1; 2369 2370 /// \brief The expression for the base pointer or class reference, 2371 /// e.g., the \c x in x.f. This can be null if this is an 'unbased' 2372 /// member expression 2373 Stmt *Base; 2374 2375 /// \brief The type of the base expression; never null. 2376 QualType BaseType; 2377 2378 /// \brief The location of the '->' or '.' operator. 2379 SourceLocation OperatorLoc; 2380 2381 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing, 2382 Expr *Base, QualType BaseType, bool IsArrow, 2383 SourceLocation OperatorLoc, 2384 NestedNameSpecifier *Qualifier, 2385 SourceRange QualifierRange, 2386 const DeclarationNameInfo &MemberNameInfo, 2387 const TemplateArgumentListInfo *TemplateArgs, 2388 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2389 2390 UnresolvedMemberExpr(EmptyShell Empty) 2391 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false), 2392 HasUnresolvedUsing(false), Base(0) { } 2393 2394public: 2395 static UnresolvedMemberExpr * 2396 Create(ASTContext &C, bool HasUnresolvedUsing, 2397 Expr *Base, QualType BaseType, bool IsArrow, 2398 SourceLocation OperatorLoc, 2399 NestedNameSpecifier *Qualifier, 2400 SourceRange QualifierRange, 2401 const DeclarationNameInfo &MemberNameInfo, 2402 const TemplateArgumentListInfo *TemplateArgs, 2403 UnresolvedSetIterator Begin, UnresolvedSetIterator End); 2404 2405 static UnresolvedMemberExpr * 2406 CreateEmpty(ASTContext &C, unsigned NumTemplateArgs); 2407 2408 /// \brief True if this is an implicit access, i.e. one in which the 2409 /// member being accessed was not written in the source. The source 2410 /// location of the operator is invalid in this case. 2411 bool isImplicitAccess() const { return Base == 0; } 2412 2413 /// \brief Retrieve the base object of this member expressions, 2414 /// e.g., the \c x in \c x.m. 2415 Expr *getBase() { 2416 assert(!isImplicitAccess()); 2417 return cast<Expr>(Base); 2418 } 2419 const Expr *getBase() const { 2420 assert(!isImplicitAccess()); 2421 return cast<Expr>(Base); 2422 } 2423 void setBase(Expr *E) { Base = E; } 2424 2425 QualType getBaseType() const { return BaseType; } 2426 void setBaseType(QualType T) { BaseType = T; } 2427 2428 /// \brief Determine whether the lookup results contain an unresolved using 2429 /// declaration. 2430 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; } 2431 void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; } 2432 2433 /// \brief Determine whether this member expression used the '->' 2434 /// operator; otherwise, it used the '.' operator. 2435 bool isArrow() const { return IsArrow; } 2436 void setArrow(bool A) { IsArrow = A; } 2437 2438 /// \brief Retrieve the location of the '->' or '.' operator. 2439 SourceLocation getOperatorLoc() const { return OperatorLoc; } 2440 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 2441 2442 /// \brief Retrieves the naming class of this lookup. 2443 CXXRecordDecl *getNamingClass() const; 2444 2445 /// \brief Retrieve the full name info for the member that this expression 2446 /// refers to. 2447 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } 2448 void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); } 2449 2450 /// \brief Retrieve the name of the member that this expression 2451 /// refers to. 2452 DeclarationName getMemberName() const { return getName(); } 2453 void setMemberName(DeclarationName N) { setName(N); } 2454 2455 // \brief Retrieve the location of the name of the member that this 2456 // expression refers to. 2457 SourceLocation getMemberLoc() const { return getNameLoc(); } 2458 void setMemberLoc(SourceLocation L) { setNameLoc(L); } 2459 2460 /// \brief Retrieve the explicit template argument list that followed the 2461 /// member template name. 2462 ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2463 assert(hasExplicitTemplateArgs()); 2464 return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2465 } 2466 2467 /// \brief Retrieve the explicit template argument list that followed the 2468 /// member template name, if any. 2469 const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2470 assert(hasExplicitTemplateArgs()); 2471 return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1); 2472 } 2473 2474 /// \brief Retrieves the optional explicit template arguments. 2475 /// This points to the same data as getExplicitTemplateArgs(), but 2476 /// returns null if there are no explicit template arguments. 2477 const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() { 2478 if (!hasExplicitTemplateArgs()) return 0; 2479 return &getExplicitTemplateArgs(); 2480 } 2481 2482 /// \brief Copies the template arguments into the given structure. 2483 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2484 getExplicitTemplateArgs().copyInto(List); 2485 } 2486 2487 /// \brief Retrieve the location of the left angle bracket following 2488 /// the member name ('<'). 2489 SourceLocation getLAngleLoc() const { 2490 return getExplicitTemplateArgs().LAngleLoc; 2491 } 2492 2493 /// \brief Retrieve the template arguments provided as part of this 2494 /// template-id. 2495 const TemplateArgumentLoc *getTemplateArgs() const { 2496 return getExplicitTemplateArgs().getTemplateArgs(); 2497 } 2498 2499 /// \brief Retrieve the number of template arguments provided as 2500 /// part of this template-id. 2501 unsigned getNumTemplateArgs() const { 2502 return getExplicitTemplateArgs().NumTemplateArgs; 2503 } 2504 2505 /// \brief Retrieve the location of the right angle bracket 2506 /// following the template arguments ('>'). 2507 SourceLocation getRAngleLoc() const { 2508 return getExplicitTemplateArgs().RAngleLoc; 2509 } 2510 2511 virtual SourceRange getSourceRange() const { 2512 SourceRange Range = getMemberNameInfo().getSourceRange(); 2513 if (!isImplicitAccess()) 2514 Range.setBegin(Base->getSourceRange().getBegin()); 2515 else if (getQualifier()) 2516 Range.setBegin(getQualifierRange().getBegin()); 2517 2518 if (hasExplicitTemplateArgs()) 2519 Range.setEnd(getRAngleLoc()); 2520 return Range; 2521 } 2522 2523 static bool classof(const Stmt *T) { 2524 return T->getStmtClass() == UnresolvedMemberExprClass; 2525 } 2526 static bool classof(const UnresolvedMemberExpr *) { return true; } 2527 2528 // Iterators 2529 virtual child_iterator child_begin(); 2530 virtual child_iterator child_end(); 2531}; 2532 2533/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]). 2534/// 2535/// The noexcept expression tests whether a given expression might throw. Its 2536/// result is a boolean constant. 2537class CXXNoexceptExpr : public Expr { 2538 bool Value : 1; 2539 Stmt *Operand; 2540 SourceRange Range; 2541 2542 friend class ASTStmtReader; 2543 2544public: 2545 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, 2546 SourceLocation Keyword, SourceLocation RParen) 2547 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary, 2548 /*TypeDependent*/false, 2549 /*ValueDependent*/Val == CT_Dependent, 2550 Operand->containsUnexpandedParameterPack()), 2551 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) 2552 { } 2553 2554 CXXNoexceptExpr(EmptyShell Empty) 2555 : Expr(CXXNoexceptExprClass, Empty) 2556 { } 2557 2558 Expr *getOperand() const { return static_cast<Expr*>(Operand); } 2559 2560 virtual SourceRange getSourceRange() const { return Range; } 2561 2562 bool getValue() const { return Value; } 2563 2564 static bool classof(const Stmt *T) { 2565 return T->getStmtClass() == CXXNoexceptExprClass; 2566 } 2567 static bool classof(const CXXNoexceptExpr *) { return true; } 2568 2569 // Iterators 2570 virtual child_iterator child_begin(); 2571 virtual child_iterator child_end(); 2572}; 2573 2574/// \brief Represents a C++0x pack expansion that produces a sequence of 2575/// expressions. 2576/// 2577/// A pack expansion expression contains a pattern (which itself is an 2578/// expression) followed by an ellipsis. For example: 2579/// 2580/// \code 2581/// template<typename F, typename ...Types> 2582/// void forward(F f, Types &&...args) { 2583/// f(static_cast<Types&&>(args)...); 2584/// } 2585/// \endcode 2586/// 2587/// Here, the argument to the function object \c f is a pack expansion whose 2588/// pattern is \c static_cast<Types&&>(args). When the \c forward function 2589/// template is instantiated, the pack expansion will instantiate to zero or 2590/// or more function arguments to the function object \c f. 2591class PackExpansionExpr : public Expr { 2592 SourceLocation EllipsisLoc; 2593 Stmt *Pattern; 2594 2595 friend class ASTStmtReader; 2596 2597public: 2598 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc) 2599 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), 2600 Pattern->getObjectKind(), /*TypeDependent=*/true, 2601 /*ValueDependent=*/true, /*ContainsUnexpandedParameterPack=*/false), 2602 EllipsisLoc(EllipsisLoc), 2603 Pattern(Pattern) { } 2604 2605 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { } 2606 2607 /// \brief Retrieve the pattern of the pack expansion. 2608 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } 2609 2610 /// \brief Retrieve the pattern of the pack expansion. 2611 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } 2612 2613 /// \brief Retrieve the location of the ellipsis that describes this pack 2614 /// expansion. 2615 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 2616 2617 virtual SourceRange getSourceRange() const; 2618 2619 static bool classof(const Stmt *T) { 2620 return T->getStmtClass() == PackExpansionExprClass; 2621 } 2622 static bool classof(const PackExpansionExpr *) { return true; } 2623 2624 // Iterators 2625 virtual child_iterator child_begin(); 2626 virtual child_iterator child_end(); 2627}; 2628 2629inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() { 2630 if (isa<UnresolvedLookupExpr>(this)) 2631 return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs(); 2632 else 2633 return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs(); 2634} 2635 2636} // end namespace clang 2637 2638#endif 2639