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