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