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